Author: Adam Pioterek <adam.pioterek@protonmail.ch>
stop scpecify (shed choose) activity
%!v(PANIC=String method: strings: negative Repeat count)
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 2632da43868d731ed9015939e0b71f027cea0408..6f9d1b16cef4ef12376f9ab104dfce3163653df4 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt @@ -107,9 +107,10 @@ if (view == null) { view = View(context) } imm.hideSoftInputFromWindow(view.windowToken, 0) - intent = Intent(context, StopSpecifyActivity::class.java) //todo mid activity choose shed + intent = Intent(context, StopSpecifyActivity::class.java) searchSuggestion as StopSuggestion intent.putExtra(StopSpecifyActivity.EXTRA_STOP_IDS, searchSuggestion.ids.joinToString(",") { it.id }) + intent.putExtra(StopSpecifyActivity.EXTRA_STOP_NAME, searchSuggestion.name) startActivity(intent) } diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/StopSpecifyActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/StopSpecifyActivity.kt index 14b2eb1488f25760892592baef1aa81f563ccc5b..d8cf258e3ae5b3ff20508948a1601ebf6f843770 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/activities/StopSpecifyActivity.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/activities/StopSpecifyActivity.kt @@ -3,34 +3,76 @@ import android.content.Intent import android.support.v7.app.AppCompatActivity import android.os.Bundle +import android.view.View +import android.view.ViewGroup +import kotlinx.android.synthetic.main.activity_stop_specify.* import ml.adamsprogs.bimba.R import ml.adamsprogs.bimba.gtfs.AgencyAndId import ml.adamsprogs.bimba.models.Timetable +import android.content.Context +import android.widget.TextView +import android.support.v7.widget.DividerItemDecoration +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater + class StopSpecifyActivity : AppCompatActivity() { companion object { const val EXTRA_STOP_IDS = "stopIds" + const val EXTRA_STOP_NAME = "stopName" } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_stop_specify) - val ids = intent.getStringExtra(EXTRA_STOP_IDS).split(",").map {AgencyAndId(it)}.toSet() - val headlines = Timetable.getTimetable().getHeadlinesForStop(ids) + val ids = intent.getStringExtra(EXTRA_STOP_IDS).split(",").map { AgencyAndId(it) }.toSet() + val name = intent.getStringExtra(EXTRA_STOP_NAME) + val timetable = Timetable.getTimetable() + val headlines = timetable.getHeadlinesForStop(ids) + + val layoutManager = LinearLayoutManager(this) + val departuresList: RecyclerView = list_view + + departuresList.adapter = ShedAdapter(this, headlines) + departuresList.layoutManager = layoutManager + + setSupportActionBar(toolbar) + supportActionBar?.title = name + } - headlines.forEach { - println(it) + class ShedAdapter(val context: Context, val values: Map<AgencyAndId, Pair<String, Set<String>>>) : + RecyclerView.Adapter<ShedAdapter.ViewHolder>() { + override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { + val context = parent?.context + val inflater = LayoutInflater.from(context) + + val rowView = inflater.inflate(R.layout.row_shed, parent, false) + return ViewHolder(rowView) } - //todo select shed + override fun getItemCount(): Int = values.size - val shed = AgencyAndId("1") + override fun onBindViewHolder(holder: ViewHolder?, position: Int) { + holder?.root?.setOnClickListener { + val id = values.entries.sortedBy { it.value.first }[position].key + val intent = Intent(context, StopActivity::class.java) + intent.putExtra(StopActivity.SOURCE_TYPE, StopActivity.SOURCE_TYPE_STOP) + intent.putExtra(StopActivity.EXTRA_STOP_ID, id) + context.startActivity(intent) + } + holder?.stopCode?.text = values.values.sortedBy { it.first }[position].first + holder?.stopHeadlines?.text = values.values.sortedBy { it.first }[position].second + .sortedBy { it } + .joinToString() + } - /*intent = Intent(this, StopActivity::class.java) - intent.putExtra(StopActivity.SOURCE_TYPE, StopActivity.SOURCE_TYPE_STOP) - intent.putExtra(StopActivity.EXTRA_STOP_ID, shed) - startActivity(intent)*/ + inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val root = itemView.findViewById<View>(R.id.shed_row)!! + val stopCode: TextView = itemView.findViewById(R.id.stop_code) + val stopHeadlines: TextView = itemView.findViewById(R.id.stop_headlines) + } } } diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/StopSuggestion.kt b/app/src/main/java/ml/adamsprogs/bimba/models/StopSuggestion.kt index 0df965d63f7486ce40a9f02ffe12bb55e57d0884..834be2d0c8ac3597c63979d1f775941b511c5465 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/models/StopSuggestion.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/models/StopSuggestion.kt @@ -5,7 +5,7 @@ import android.os.Parcelable import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion import ml.adamsprogs.bimba.gtfs.AgencyAndId -class StopSuggestion(val name: String, val ids: Set<AgencyAndId>, private val zone: String) : SearchSuggestion, Comparable<StopSuggestion> { +class StopSuggestion(val name: String, val ids: Set<AgencyAndId>, val zone: String) : SearchSuggestion, Comparable<StopSuggestion> { @Suppress("UNCHECKED_CAST") constructor(parcel: Parcel) : this(parcel.readString(), parcel.readString().split(",").map { AgencyAndId(it) }.toSet(), parcel.readString()) 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 bfa0eade27e6f02a16ba5814a10059df59919063..d1351d8d56a399e1ef17aa0959a036024fde5196 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt @@ -48,7 +48,6 @@ getStops(true) } fun getStops(force: Boolean = false): List<StopSuggestion> { - println("STOPS!") if (_stops != null && !force) return _stops!! @@ -73,12 +72,14 @@ return _stops!! } fun getHeadlinesForStop(stops: Set<AgencyAndId>): Map<AgencyAndId, Pair<String, Set<String>>> { + println(JCalendar.getInstance().timeInMillis) val trips = HashMap<String, HashSet<String>>() val routes = HashMap<String, Pair<String, String>>() val headsigns = HashMap<AgencyAndId, Pair<String, HashSet<String>>>() val settings = CsvParserSettings() settings.format.setLineSeparator("\r\n") settings.format.quote='"' + println(JCalendar.getInstance().timeInMillis) val parser = CsvParser(settings) stops.forEach { trips[it.id] = HashSet() @@ -90,24 +91,27 @@ trips[stop]!!.add(it[0]) } } } + println(JCalendar.getInstance().timeInMillis) - val allTrips = trips.flatMap { it.value } + //val allTrips = trips.flatMap { it.value } + println(JCalendar.getInstance().timeInMillis) val stopsFile = File(filesDir, "gtfs_files/trips.txt") parser.parseAll(stopsFile).forEach { - if (it[2] in allTrips) - routes[it[2]] = Pair(it[0], it[3]) + //if (it[2] in allTrips) + routes[it[2]] = Pair(it[0], it[3]) } + println(JCalendar.getInstance().timeInMillis) trips.forEach { val headsign = HashSet<String>() it.value.forEach { - println("adding: ${routes[it]}") headsign.add("${routes[it]!!.first} → ${routes[it]!!.second}") } headsigns[AgencyAndId(it.key)] = Pair(getStopCode(AgencyAndId(it.key)), headsign) } + println(JCalendar.getInstance().timeInMillis) return headsigns /* diff --git a/app/src/main/res/layout/activity_stop_specify.xml b/app/src/main/res/layout/activity_stop_specify.xml index 2993f069ddbe51de49f13ce80801ace483a86074..137b0aaee6804a4787c5368014545db621f99669 100644 --- a/app/src/main/res/layout/activity_stop_specify.xml +++ b/app/src/main/res/layout/activity_stop_specify.xml @@ -6,4 +6,31 @@ android:layout_width="match_parent" android:layout_height="match_parent" tools:context="ml.adamsprogs.bimba.activities.StopSpecifyActivity"> + <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"> + + <!--suppress AndroidDomInspection --> + <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="@color/colorPrimary" + app:popupTheme="@style/AppTheme.PopupOverlay" + app:title="@string/app_name" /> + </android.support.design.widget.AppBarLayout> + + <android.support.v7.widget.RecyclerView + android:id="@+id/list_view" + android:layout_width="0dp" + android:layout_height="0dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/appbar" /> + </android.support.constraint.ConstraintLayout> diff --git a/app/src/main/res/layout/row_shed.xml b/app/src/main/res/layout/row_shed.xml new file mode 100644 index 0000000000000000000000000000000000000000..2b7ab4e27c06321d0b51b6a6878928a6c4367ec7 --- /dev/null +++ b/app/src/main/res/layout/row_shed.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:id="@+id/shed_row" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + + <TextView + android:id="@+id/stop_code" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:layout_marginTop="8dp" + android:text="" + android:textAppearance="@style/TextAppearance.AppCompat.Headline" + android:textColor="@color/colorPrimary" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + <TextView + android:id="@+id/stop_headlines" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginBottom="6dp" + android:layout_marginEnd="8dp" + android:layout_marginStart="8dp" + android:layout_marginTop="6dp" + android:text="" + android:textColor="@color/colorPrimary" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/stop_code" /> +</android.support.constraint.ConstraintLayout> \ No newline at end of file