Bimba.git

commit 83857f134ea7f4c384ae690eb138ac992c930956

Author: Adam Pioterek <adam.pioterek@protonmail.ch>

removing from favourite cache when removing plate

%!v(PANIC=String method: strings: negative Repeat count)


diff --git a/.idea/misc.xml b/.idea/misc.xml
index ba7052b8197ddf8ba8756022d905d03055c7ad60..635999df1e86791ad3787e455b4524e4d8879b93 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -24,7 +24,7 @@         
       </value>
     </option>
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   <component name="ProjectType">




diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
index 683b8373f85d34425892e6e9e46d403f01826df5..d550a190435c106500166077eb1efd1639c69a39 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
@@ -28,7 +28,6 @@ import ml.adamsprogs.bimba.models.adapters.FavouritesAdapter
 
 //todo<p:1> searchView integration
 //todo something devours RAM
-//todo onResume -> refresh favourites
 class DashActivity : AppCompatActivity(), MessageReceiver.OnTimetableDownloadListener,
         FavouritesAdapter.OnMenuItemClickListener, Favourite.OnVmPreparedListener,
         FavouritesAdapter.ViewHolder.OnClickListener {
@@ -302,7 +301,7 @@     }
 
     override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
         if (requestCode == REQUEST_EDIT_FAVOURITE) {
-            if (resultCode == Activity.RESULT_OK) { // todo change favourite content (shown) immediately [applies to other situations as well]
+            if (resultCode == Activity.RESULT_OK) {
                 val name = data.getStringExtra(EditFavouriteActivity.EXTRA_NEW_NAME)
                 val positionBefore = data.getIntExtra(EditFavouriteActivity.EXTRA_POSITION_BEFORE, -1)
                 //adapter.favourites = favourites.favouritesList




diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt
index de7311f4afc699144bab997b1efed17f81366798..9cd3068c599490ec30d5f5788a98d57cbc67298e 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt
@@ -19,6 +19,7 @@ import ml.adamsprogs.bimba.models.gtfs.AgencyAndId
 import ml.adamsprogs.bimba.models.*
 import ml.adamsprogs.bimba.models.adapters.DeparturesAdapter
 
+//todo fab hide when scrolling
 class StopActivity : AppCompatActivity(), MessageReceiver.OnTimetableDownloadListener, MessageReceiver.OnVmListener, Favourite.OnVmPreparedListener {
 
     private var sectionsPagerAdapter: SectionsPagerAdapter? = null




diff --git a/app/src/main/java/ml/adamsprogs/bimba/collections/FavouriteStorage.kt b/app/src/main/java/ml/adamsprogs/bimba/collections/FavouriteStorage.kt
index 83d651369fecf9bf9e7798cc12a262885ea6e2f1..1128cf7b5426f3806e85f28d6680668bd3022b28 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/collections/FavouriteStorage.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/collections/FavouriteStorage.kt
@@ -69,10 +69,8 @@             serialize()
         }
     }
 
-    private fun addIndex(name:String) {
-        positionIndex.apply {
-            this.add(name)
-        }
+    private fun addIndex(name: String) {
+        positionIndex.add(name)
     }
 
     fun delete(name: String) {




diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt b/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt
index dc521165db58723f1b2cb0833d052396f15caadd..f7251ffdfadd9cb15bd004a83788ed66aca34290 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt
@@ -100,6 +100,7 @@     fun delete(plateId: Plate.ID) {
         segments.forEach {
             it.remove(plateId)
         }
+        removeFromCache(plateId)
     }
 
     fun registerOnVm(receiver: MessageReceiver, context: Context) {
@@ -203,6 +204,15 @@         filterVmDepartures()
         onVmPreparedListeners.forEach {
             it.onVmPrepared()
         }
+    }
+
+    private fun removeFromCache(plate: Plate.ID) {
+        val map = HashMap<AgencyAndId, List<Departure>>()
+        fullDepartures
+        fullDepartures.forEach {
+            map[it.key] = it.value.filter { plate.line != it.line || plate.headsign != it.headsign }
+        }
+        fullDepartures = map
     }
 
     interface OnVmPreparedListener {




diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/adapters/FavouriteEditRowAdapter.kt b/app/src/main/java/ml/adamsprogs/bimba/models/adapters/FavouriteEditRowAdapter.kt
index 29ce0c2a7c8880ee71be0409fa4034ef5b16a6ad..6814ada2b4f7f4e9ff219337c1a4e1e03c643fae 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/models/adapters/FavouriteEditRowAdapter.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/models/adapters/FavouriteEditRowAdapter.kt
@@ -25,11 +25,6 @@         val id = favourite.segments.flatMap { it.plates!! }.sortedBy { "${it.line}${it.stop}"}[position]
         val plate = Plate(id, null)
         val favouriteElement = "${timetable.getStopName(plate.id.stop)} ( ${timetable.getStopCode(plate.id.stop)}):\n${plate.id.line} → ${plate.id.headsign}"
         holder.rowTextView.text = favouriteElement
-//        holder?.splitButton?.setOnClickListener {
-//            favourites.detach(favourite.name, id, favouriteElement)
-//            favourite = favourites.favourites[favourite.name]!!
-//            notifyDataSetChanged()
-//        }
         holder.deleteButton.setOnClickListener {
             favourites.delete(favourite.name, id)
             favourite = favourites.favourites[favourite.name]!!
@@ -47,7 +42,6 @@     }
 
     inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
         val rowTextView:TextView = itemView.findViewById(R.id.favourite_edit_row)
-//        val splitButton:ImageView = itemView.findViewById(R.id.favourite_edit_split)
         val deleteButton:ImageView = itemView.findViewById(R.id.favourite_edit_delete)
     }
 }
\ No newline at end of file




diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 2b67fb4ff0ade262f685a5d092a5d1ff26f8e4c2..b080dbe6b48f4fdd74ab4acaa120378f4bce0355 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip