Bimba.git

commit 01e12130ebf9c8ff7c7a07249c087b7546aee0a1

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

line specify activity frame

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


diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 039e73a8a82d72abbf1d496d8b84d9f149739718..808dfeb20c84fae8d153425210df0bf6d6e19b6e 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -48,6 +48,15 @@                              android:name="android.support.PARENT_ACTIVITY"
                 android:value="ml.adamsprogs.bimba.activities.StopSpecifyActivity" />
         </activity>
+        <activity
+            android:name=".activities.LineSpecifyActivity"
+            android:label="@string/title_activity_main"
+            android:parentActivityName=".activities.DashActivity"
+            android:theme="@style/AppTheme">
+            <meta-data
+                android:name="android.support.PARENT_ACTIVITY"
+                android:value="ml.adamsprogs.bimba.activities.DashActivity" />
+        </activity>
     </application>
 
 </manifest>
\ No newline at end of file




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 0b7449ef86b932cab5ae027af8c017cd364a777f..cb15aee6ae6921f2590a7a42700164f5dde6ce70 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
@@ -23,9 +23,10 @@ import kotlinx.android.synthetic.main.activity_dash.*
 import ml.adamsprogs.bimba.datasources.TimetableDownloader
 import ml.adamsprogs.bimba.datasources.VmClient
 import ml.adamsprogs.bimba.models.suggestions.GtfsSuggestion
+import ml.adamsprogs.bimba.models.suggestions.LineSuggestion
 import ml.adamsprogs.bimba.models.suggestions.StopSuggestion
 
-//todo cards
+//todo cards https://enoent.fr/blog/2015/01/18/recyclerview-basics/
 class DashActivity : AppCompatActivity(), MessageReceiver.OnTimetableDownloadListener,
         FavouritesAdapter.OnMenuItemClickListener, Favourite.OnVmPreparedListener {
     val context: Context = this
@@ -110,11 +111,15 @@                     view = View(context)
                 }
                 imm.hideSoftInputFromWindow(view.windowToken, 0)
                 if (searchSuggestion is StopSuggestion) {
-                    intent = Intent(context, StopSpecifyActivity::class.java)
+                    val intent = Intent(context, StopSpecifyActivity::class.java)
                     intent.putExtra(StopSpecifyActivity.EXTRA_STOP_IDS, searchSuggestion.ids.joinToString(",") { it.id })
                     intent.putExtra(StopSpecifyActivity.EXTRA_STOP_NAME, searchSuggestion.name)
                     startActivity(intent)
-                } //todo if line
+                } else if (searchSuggestion is LineSuggestion){
+                    val intent = Intent(context, LineSpecifyActivity::class.java)
+                    intent.putExtra(LineSpecifyActivity.EXTRA_LINE_ID, searchSuggestion.name)
+                    startActivity(intent)
+                }
             }
 
             override fun onSearchAction(query: String) {




diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/LineSpecifyActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/LineSpecifyActivity.kt
new file mode 100644
index 0000000000000000000000000000000000000000..ef4595bd7bdc8d5f17e5ab222d6724dbfb734beb
--- /dev/null
+++ b/app/src/main/java/ml/adamsprogs/bimba/activities/LineSpecifyActivity.kt
@@ -0,0 +1,78 @@
+package ml.adamsprogs.bimba.activities
+
+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.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+
+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.models.Timetable
+import ml.adamsprogs.bimba.models.gtfs.AgencyAndId
+
+class LineSpecifyActivity : AppCompatActivity() {
+    companion object {
+        const val EXTRA_LINE_ID = "line_id"
+    }
+
+    private var sectionsPagerAdapter: SectionsPagerAdapter? = null
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        setContentView(R.layout.activity_line_specify)
+
+        setSupportActionBar(toolbar)
+        supportActionBar?.setDisplayHomeAsUpEnabled(true)
+
+        val line = intent.getStringExtra(EXTRA_LINE_ID)
+
+        val timetable = Timetable.getTimetable()
+        val graphs = timetable.getTripGraphs(AgencyAndId(line))
+
+        sectionsPagerAdapter = SectionsPagerAdapter(supportFragmentManager, graphs)
+
+        container.adapter = sectionsPagerAdapter
+
+        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) {
+
+        override fun getItem(position: Int): Fragment {
+            return PlaceholderFragment.newInstance(position + 1, graphs[position])
+        }
+
+        override fun getCount() = 2
+    }
+
+    class PlaceholderFragment : Fragment() {
+
+        override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
+                                  savedInstanceState: Bundle?): View? {
+            val rootView = inflater.inflate(R.layout.fragment_line_specify, container, false)
+            rootView.section_label.text = arguments?.getString("graph") //todo draw it + clickable
+            return rootView
+        }
+
+        companion object {
+            private const val ARG_SECTION_NUMBER = "section_number"
+
+            fun newInstance(sectionNumber: Int, graph: Map<Int, List<Int>>): 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"))
+                fragment.arguments = args
+                return fragment
+            }
+        }
+    }
+}




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 709d5f55a6c5d6ed3f1d82a16b67e58343d4412e..954d66484500ef5cf339dffa8f35cdd02d24df41 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt
@@ -231,7 +231,8 @@         parser.parseAll(file).forEach {
             departures[AgencyAndId(it[0])] = ArrayList()
         }
 
-        tripsInStop.forEach { //fixme this part is long --- cache is the only option
+        tripsInStop.forEach {
+            //fixme this part is long --- cache is the only option
             departures[trips[it.key]!!.serviceId]!!.add(Departure(trips[it.key]!!.routeId,
                     calendarToMode(trips[it.key]!!.serviceId),
                     it.value.first, trips[it.key]!!.wheelchairAccessible,
@@ -435,7 +436,7 @@         }
         return filteredTrips
     }
 
-    private fun tripFromCache(id: String):Trip {
+    private fun tripFromCache(id: String): Trip {
         return Trip(AgencyAndId(tripsCache[id]!![0]),
                 AgencyAndId(tripsCache[id]!![1]), createTripId(tripsCache[id]!![2]),
                 tripsCache[id]!![3], Integer.parseInt(tripsCache[id]!![4]),
@@ -571,6 +572,25 @@             filteredPlates.add(Plate.ID(AgencyAndId(tripsCache[it]!![0]), stop, tripsCache[it]!![3]))
         }
 
         return filteredPlates
+    }
+
+    fun getTripGraphs(id: AgencyAndId): List<Map<Int, List<Int>>> {
+        tripsCache.forEach {
+            if (it.value[0] == id.id) {
+                //todo needs stop_times.txt indexed by trips
+            }
+        }
+        val map = ArrayList<HashMap<Int, List<Int>>>()
+        val map0 = HashMap<Int, List<Int>>()
+        map0[0] = listOf(1, 2)
+        map0[1] = listOf(3, 4, 5)
+        map.add(map0)
+        val map1 = HashMap<Int, List<Int>>()
+        map1[0] = listOf(1)
+        map1[1] = listOf(2, 3, 4)
+        map1[2] = listOf(4, 5)
+        map.add(map1)
+        return map
     }
 }
 




diff --git a/app/src/main/res/layout/activity_line_specify.xml b/app/src/main/res/layout/activity_line_specify.xml
new file mode 100644
index 0000000000000000000000000000000000000000..12dfce96805bec6de2222a24fdb2c9c65d76c5e3
--- /dev/null
+++ b/app/src/main/res/layout/activity_line_specify.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/main_content"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:fitsSystemWindows="true"
+    tools:context="ml.adamsprogs.bimba.activities.LineSpecifyActivity">
+
+    <android.support.design.widget.AppBarLayout
+        android:id="@+id/appbar"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:paddingTop="@dimen/appbar_padding_top"
+        android:theme="@style/AppTheme.AppBarOverlay">
+
+        <android.support.v7.widget.Toolbar
+            android:id="@+id/toolbar"
+            android:layout_width="match_parent"
+            android:layout_height="?attr/actionBarSize"
+            android:layout_weight="1"
+            android:background="?attr/colorPrimary"
+            app:layout_scrollFlags="scroll|enterAlways"
+            app:popupTheme="@style/AppTheme.PopupOverlay"
+            app:title="@string/app_name">
+
+        </android.support.v7.widget.Toolbar>
+
+        <android.support.design.widget.TabLayout
+            android:id="@+id/tabs"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content">
+
+            <android.support.design.widget.TabItem
+                android:id="@+id/tabItem"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/tab_text_line_to" />
+
+            <android.support.design.widget.TabItem
+                android:id="@+id/tabItem2"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/tab_text_line_fro" />
+
+        </android.support.design.widget.TabLayout>
+    </android.support.design.widget.AppBarLayout>
+
+    <android.support.v4.view.ViewPager
+        android:id="@+id/container"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
+
+</android.support.design.widget.CoordinatorLayout>




diff --git a/app/src/main/res/layout/fragment_line_specify.xml b/app/src/main/res/layout/fragment_line_specify.xml
new file mode 100644
index 0000000000000000000000000000000000000000..c3ef48c574cb3df2b0a912cd50fb090b97b984d0
--- /dev/null
+++ b/app/src/main/res/layout/fragment_line_specify.xml
@@ -0,0 +1,22 @@
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/constraintLayout"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context="ml.adamsprogs.bimba.activities.LineSpecifyActivity$PlaceholderFragment">
+
+    <TextView
+        android:id="@+id/section_label"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginBottom="@dimen/activity_vertical_margin"
+        android:layout_marginEnd="@dimen/activity_horizontal_margin"
+        android:layout_marginStart="@dimen/activity_horizontal_margin"
+        android:layout_marginTop="@dimen/activity_vertical_margin"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintTop_toTopOf="@+id/constraintLayout"
+        tools:layout_constraintLeft_creator="1"
+        tools:layout_constraintTop_creator="1" />
+
+</android.support.constraint.ConstraintLayout>
\ No newline at end of file




diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 4c2aa3f1747ad8586be0a39eabe967f0247eb4df..40f23874094efba6388290beb57a1674cab3e452 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -75,4 +75,8 @@     Converting timetable…
 
     <string name="today">Today</string>
     <string name="no_departures">No departures</string>
+    <string name="title_activity_main" translatable="false">LineSpecifyActivity</string>
+    <string name="section_format">Hello World from section: %1$d</string>
+    <string name="tab_text_line_to">To</string>
+    <string name="tab_text_line_fro">Fro</string>
 </resources>