ref: b80c6886e9aef8312e571f34644bfaeb86f41200
app/src/main/java/ml/adamsprogs/bimba/activities/StopSpecifyActivity.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
package ml.adamsprogs.bimba.activities import android.content.Context import android.content.Intent import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import kotlinx.android.synthetic.main.activity_stop_specify.* import ml.adamsprogs.bimba.ProviderProxy import ml.adamsprogs.bimba.R class StopSpecifyActivity : AppCompatActivity() { companion object { const val EXTRA_STOP_NAME = "stopName" } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_stop_specify) val name = intent.getStringExtra(EXTRA_STOP_NAME) val providerProxy = ProviderProxy(this) providerProxy.getSheds(name) { progressBar.visibility = View.GONE val layoutManager = androidx.recyclerview.widget.LinearLayoutManager(this) val departuresList: androidx.recyclerview.widget.RecyclerView = list_view departuresList.adapter = ShedAdapter(this, it, name) departuresList.layoutManager = layoutManager } /*val timetable = Timetable.getTimetable(this) val headlines = timetable.getHeadlinesForStop(name)*/ setSupportActionBar(toolbar) supportActionBar?.title = name } class ShedAdapter(val context: Context, private val values: Map<String, Set<String>>, private val stopName: String) : androidx.recyclerview.widget.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) } override fun getItemCount(): Int = values.size override fun onBindViewHolder(holder: ViewHolder, position: Int) { holder.root.setOnClickListener { val code = values.keys.sorted()[position] val intent = Intent(context, StopActivity::class.java) intent.putExtra(StopActivity.SOURCE_TYPE, StopActivity.SOURCE_TYPE_STOP) intent.putExtra(StopActivity.EXTRA_STOP_CODE, code) intent.putExtra(StopActivity.EXTRA_STOP_NAME, stopName) context.startActivity(intent) } holder.stopCode.text = values.keys.sorted()[position] holder.stopHeadlines.text = values.entries.sortedBy { it.key }[position].value .sortedBy { it.split(" → ")[0].padStart(4, '0') } .joinToString() } inner class ViewHolder(itemView: View) : androidx.recyclerview.widget.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) } } } |