ref: 7c62bb46c1b5597393d86720528d20fc6ef4c3dc
app/src/main/java/ml/adamsprogs/bimba/activities/LineSpecifyActivity.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 77 78 79 80 81 |
package ml.adamsprogs.bimba.activities import android.support.design.widget.TabLayout import android.support.v7.app.AppCompatActivity import android.support.v4.app.* import android.os.Bundle import android.view.* 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.* 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(line) sectionsPagerAdapter = SectionsPagerAdapter(supportFragmentManager, graphs) container.adapter = sectionsPagerAdapter for (i in 0 until tabs.tabCount) { tabs.getTabAt(i)?.text = graphs[i].headsign } container.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabs)) tabs.addOnTabSelectedListener(TabLayout.ViewPagerOnTabSelectedListener(container)) } inner class SectionsPagerAdapter(fm: FragmentManager, private val graphs: Array<Timetable.TripGraph>) : 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: Timetable.TripGraph): PlaceholderFragment { val fragment = PlaceholderFragment() val args = Bundle() args.putInt(ARG_SECTION_NUMBER, sectionNumber) //todo serialise graph // or draw and pass image //args.putString("graph", graph.first.map { "${it.key}: ${it.value.joinToString(", ")}" }.joinToString("\n")) fragment.arguments = args return fragment } } } } |