Bimba.git

commit c1cab2cf81b141980d6418c401f10ee2bc9cd2c9

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

creating trips graph

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


diff --git a/.idea/misc.xml b/.idea/misc.xml
index 635999df1e86791ad3787e455b4524e4d8879b93..ba7052b8197ddf8ba8756022d905d03055c7ad60 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -24,7 +24,7 @@         
       </value>
     </option>
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" 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 d550a190435c106500166077eb1efd1639c69a39..fbb618b2d978861b8efee2706476eb73e421ba5f 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
@@ -27,7 +27,6 @@ import ml.adamsprogs.bimba.collections.FavouriteStorage
 import ml.adamsprogs.bimba.models.adapters.FavouritesAdapter
 
 //todo<p:1> searchView integration
-//todo something devours RAM
 class DashActivity : AppCompatActivity(), MessageReceiver.OnTimetableDownloadListener,
         FavouritesAdapter.OnMenuItemClickListener, Favourite.OnVmPreparedListener,
         FavouritesAdapter.ViewHolder.OnClickListener {




diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/LineSpecifyActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/LineSpecifyActivity.kt
index ef4595bd7bdc8d5f17e5ab222d6724dbfb734beb..1ee842fbd7c26bb2252840839092772f092cc0e6 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/activities/LineSpecifyActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/activities/LineSpecifyActivity.kt
@@ -3,19 +3,15 @@
 import android.support.design.widget.TabLayout
 import android.support.v7.app.AppCompatActivity
 
-import android.support.v4.app.Fragment
-import android.support.v4.app.FragmentManager
-import android.support.v4.app.FragmentPagerAdapter
+import android.support.v4.app.*
 import android.os.Bundle
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
+import android.view.*
 
-import ml.adamsprogs.bimba.R
 import kotlinx.android.synthetic.main.activity_line_specify.*
 import kotlinx.android.synthetic.main.fragment_line_specify.view.*
+import ml.adamsprogs.bimba.R
 import ml.adamsprogs.bimba.models.Timetable
-import ml.adamsprogs.bimba.models.gtfs.AgencyAndId
+import ml.adamsprogs.bimba.models.gtfs.*
 
 class LineSpecifyActivity : AppCompatActivity() {
     companion object {
@@ -40,11 +36,15 @@         sectionsPagerAdapter = SectionsPagerAdapter(supportFragmentManager, graphs)
 
         container.adapter = sectionsPagerAdapter
 
+        for (i in 0 until tabs.tabCount) {
+            tabs.getTabAt(i)?.text = graphs[i].second
+        }
+
         container.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabs))
         tabs.addOnTabSelectedListener(TabLayout.ViewPagerOnTabSelectedListener(container))
     }
 
-    inner class SectionsPagerAdapter(fm: FragmentManager, private val graphs: List<Map<Int, List<Int>>>) : FragmentPagerAdapter(fm) {
+    inner class SectionsPagerAdapter(fm: FragmentManager, private val graphs: Array<Pair<HashMap<Int, HashSet<Int>>, String>>) : FragmentPagerAdapter(fm) {
 
         override fun getItem(position: Int): Fragment {
             return PlaceholderFragment.newInstance(position + 1, graphs[position])
@@ -65,11 +65,11 @@
         companion object {
             private const val ARG_SECTION_NUMBER = "section_number"
 
-            fun newInstance(sectionNumber: Int, graph: Map<Int, List<Int>>): PlaceholderFragment {
+            fun newInstance(sectionNumber: Int, graph: Pair<HashMap<Int, HashSet<Int>>, String>): PlaceholderFragment {
                 val fragment = PlaceholderFragment()
                 val args = Bundle()
                 args.putInt(ARG_SECTION_NUMBER, sectionNumber)
-                args.putString("graph", graph.map { "${it.key}: ${it.value.joinToString(", ")}" }.joinToString("\n"))
+                args.putString("graph", graph.first.map { "${it.key}: ${it.value.joinToString(", ")}" }.joinToString("\n"))
                 fragment.arguments = args
                 return fragment
             }




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 9cd3068c599490ec30d5f5788a98d57cbc67298e..de7311f4afc699144bab997b1efed17f81366798 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt
@@ -19,7 +19,6 @@ 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/models/Timetable.kt b/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt
index a4b88546cd37d9fb2df9f599cd53f2d23b851b61..6929b64e17b633457ffab55423a8a65880281973 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt
@@ -373,8 +373,52 @@         cursor.close()
         return plates
     }
 
-    fun getTripGraphs(id: AgencyAndId): List<Map<Int, List<Int>>> {
-        TODO("create graph")
+    fun getTripGraphs(id: AgencyAndId): Array<Pair<HashMap<Int, HashSet<Int>>, String>> {
+        val trips = arrayOf(HashMap<String, HashMap<Int, Int>>(), HashMap())
+        val headsigns = arrayOf("", "")
+        val cursor = db.rawQuery("select trip_id, trip_headsign, direction_id, stop_id, stop_sequence " +
+                "from trips natural join stop_times " +
+                "where route_id = ?", arrayOf(id.id))
+
+        while (cursor.moveToNext()) {
+            val trip = cursor.getString(0)
+            val headsign = cursor.getString(1)
+            val direction = cursor.getInt(2)
+            val stopId = cursor.getInt(3)
+            val sequence = cursor.getInt(4)
+            if (trips[direction][trip] == null)
+                trips[direction][trip] = HashMap()
+            trips[direction][trip]!![sequence] = stopId
+            if (trip[trip.length - 1] == '+')
+                headsigns[direction] = headsign
+        }
+
+        cursor.close()
+
+        val result = arrayOf(Pair<HashMap<Int, HashSet<Int>>, String>(HashMap(), headsigns[0]), Pair(HashMap(), headsigns[1]))
+
+        var tripNo = 0
+        trips.forEach {
+            it.forEach {
+                var i = 0
+                val size = it.value.size
+                val list = it.value
+                it.value.toSortedMap(
+                        Comparator { o1, o2 ->
+                            o1.compareTo(o2)
+                        }
+                ).values.forEach {
+                    if (i < size - 1) {
+                        if (result[tripNo].first[it] == null)
+                            result[tripNo].first[it] = HashSet()
+                        result[tripNo].first[it]!!.add(list[i + 1]!!)
+                    }
+                    i++
+                }
+            }
+            tripNo++
+        }
+        return result
     }
 }
 




diff --git a/app/src/main/res/layout/activity_stop.xml b/app/src/main/res/layout/activity_stop.xml
index 3fd9ff4d556f89b85a4509c2be916a7655673acb..04e0beca509e43a93d80462822865d8ce6693505 100644
--- a/app/src/main/res/layout/activity_stop.xml
+++ b/app/src/main/res/layout/activity_stop.xml
@@ -58,6 +58,7 @@         android:layout_width="match_parent"
         android:layout_height="match_parent"
         app:layout_behavior="@string/appbar_scrolling_view_behavior" />
 
+    <!-- todo behaviour -->
     <android.support.design.widget.FloatingActionButton
         android:id="@+id/fab"
         android:layout_width="wrap_content"