Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.jachyhm.sjrregiojet
- import android.annotation.SuppressLint
- import android.content.SharedPreferences
- import android.support.v7.app.AppCompatActivity
- import android.os.Bundle
- import android.os.Handler
- import android.support.v4.content.ContextCompat
- import android.view.Gravity
- import android.view.View
- import android.widget.*
- import java.io.File
- import java.io.InputStream
- import java.text.SimpleDateFormat
- import kotlin.math.roundToInt
- import android.graphics.Typeface
- import android.support.v4.view.AsyncLayoutInflater
- import android.view.LayoutInflater
- import android.view.WindowManager
- import android.widget.TextView
- import java.util.*
- import kotlin.math.round
- class displayTrain : AppCompatActivity() {
- private lateinit var contrast: Contrast
- private lateinit var settingsMenu: SettingsMenu
- private var recreated = false
- private var displayedTrain: String = ""
- private lateinit var sharedPref: SharedPreferences
- private val SETTINGS_PREFS_FILENAME = "com.jachyhm.sjrregiojet.settings"
- private var isShowAllChecked = false
- private lateinit var timetable: Timetable
- private lateinit var clockRunnable: Runnable
- val handler = Handler()
- fun reCreate() {
- val savedInstanceState = Bundle()
- //this is important to save all your open states/fragment states
- onSaveInstanceState(savedInstanceState)
- //this is needed to release the resources
- onDestroy()
- //call on create where new theme is applied
- recreated = true
- onCreate(savedInstanceState)
- }
- @SuppressLint("SimpleDateFormat")
- override fun onCreate(savedInstanceState: Bundle?) {
- sharedPref = this.getSharedPreferences(SETTINGS_PREFS_FILENAME,0)
- isShowAllChecked = sharedPref.getBoolean("showAll", false)
- contrast = Contrast(this, ::reCreate)
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_display_train)
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
- // Hide the status bar.
- window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
- actionBar?.hide()
- try {
- this.supportActionBar!!.hide()
- } catch (e: NullPointerException) {
- }
- findViewById<ProgressBar>(R.id.progressBar).visibility = View.VISIBLE
- val clock = findViewById<TextView>(R.id.clock)
- clockRunnable = object: Runnable {
- val formatter = SimpleDateFormat("HH:mm:ss")
- override fun run() {
- clock.text = formatter.format(java.util.Calendar.getInstance().time)
- handler.postDelayed(this, 1000)
- }
- }
- clockRunnable.run()
- displayedTrain = intent.getStringExtra("trainNumber")
- if (!recreated) {
- contrast.initialiseButtons(
- findViewById(R.id.dayButton),
- findViewById(R.id.nightButton),
- findViewById(R.id.autoContrastButtonWhite),
- findViewById(R.id.autoContrastButtonBlack),
- findViewById(R.id.appSettings_white),
- findViewById(R.id.appSettings_black),
- findViewById(R.id.main_layout),
- recreated
- )
- settingsMenu = SettingsMenu(
- this,
- this,
- findViewById(R.id.appSettings_white),
- findViewById(R.id.appSettings_black),
- findViewById(R.id.progressBar),
- true
- )
- }
- val load_thread = Thread {
- val _timetable = parseXML(File(displayedTrain).inputStream())
- if (_timetable != null) {
- timetable = _timetable
- /*findViewById<TextView>(R.id.heading).text = (
- checkNotNull(timetable.shared_attributes).train_types.joinToString(" ")+" "+
- checkNotNull(timetable.shared_attributes).train_kinds.joinToString(" / ")+" "+
- getTrainNumber(timetable)
- ).trim()
- findViewById<TextView>(R.id.routeDescription).text = getRouteDescriptions(timetable)*/
- if (savedInstanceState == null) {
- val trainNames = getTrainNames(timetable)
- val routeDescriptions = getRouteDescriptions(timetable)
- if (trainNames.size == routeDescriptions.size) {
- trainNames.forEachIndexed { i, element ->
- supportFragmentManager
- .beginTransaction()
- .add(
- R.id.descriptions_layout,
- TrainDescription.newInstance(
- element,
- routeDescriptions[i]
- )
- )
- .commit()
- }
- if (timetable.adHoc) {
- supportFragmentManager
- .beginTransaction()
- .add(
- R.id.descriptions_layout,
- TrainDescriptionNote.newInstance(
- getString(R.string.adhoc)
- )
- )
- .commit()
- }
- } else {
- Toast.makeText(
- this,
- "Kritická chyba při zpracovávání XML souboru, nesouhlasí počet tras ${routeDescriptions.size} a přiřazených čísel vlaků ${trainNames.size}!",
- Toast.LENGTH_SHORT
- ).show()
- finish()
- }
- }
- if (timetable.D3) {
- runOnUiThread {
- findViewById<TableLayout>(R.id.contentHeader).getChildAt(0).visibility = View.GONE
- findViewById<TableLayout>(R.id.contentHeader).getChildAt(1).visibility = View.VISIBLE
- }
- }
- else
- {
- runOnUiThread {
- findViewById<TableLayout>(R.id.contentHeader).getChildAt(0).visibility = View.VISIBLE
- findViewById<TableLayout>(R.id.contentHeader).getChildAt(1).visibility = View.GONE
- }
- }
- flushTimetableToTable(timetable)
- } else {
- Toast.makeText(
- this,
- "Kritická chyba při zpracovávání XML souboru, XMLParse vrátil null!",
- Toast.LENGTH_SHORT
- ).show()
- finish()
- }
- }
- Handler().postDelayed({
- load_thread.start()
- }, 500)
- }
- private fun flushTimetableToTable(timetable: Timetable) {
- val content_table = TableLayout(this)
- val table_params = TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,TableLayout.LayoutParams.WRAP_CONTENT)
- content_table.layoutParams = table_params
- generateRows(timetable).forEach {
- content_table.addView(it)
- }
- runOnUiThread {
- findViewById<ScrollView>(R.id.scrollView).addView(content_table)
- findViewById<ProgressBar>(R.id.progressBar).visibility = View.INVISIBLE
- }
- }
- private fun getTrainNumber(timetable: Timetable): List<Int> {
- val tn: MutableList<Int> = mutableListOf()
- checkNotNull(timetable.route).track_sections.forEach {
- it.timetable_entries.forEach {
- val number = it.train_number
- if (number !in tn) {
- tn.add(number)
- }
- }
- }
- return tn
- }
- private fun getTrainKindType(timetable: Timetable): MutableMap<Int,String> {
- data class TrainName(
- val kinds: MutableList<String>,
- val types: MutableList<String>
- )
- val _tn = mutableMapOf<Int,TrainName>()
- val tn = mutableMapOf<Int,String>()
- checkNotNull(timetable.route).track_sections.forEach {
- it.timetable_entries.forEach {
- val number = it.train_number
- val type = it.train_type.trim()
- val kind = it.train_kind.trim()
- if (number in _tn) {
- if (type !in checkNotNull(_tn[number]).types) {
- checkNotNull(_tn[number]).types.add(type)
- }
- if (kind !in checkNotNull(_tn[number]).kinds) {
- checkNotNull(_tn[number]).kinds.add(kind)
- }
- }
- else
- {
- _tn[number] = TrainName(mutableListOf(kind), mutableListOf(type))
- }
- }
- }
- _tn.forEach{
- tn[it.key] = "${it.value.types.joinToString(" ")} ${it.value.kinds.joinToString(" / ")}"
- }
- return tn
- }
- private fun getTrainNames(timetable: Timetable): List<String> {
- val tn = mutableListOf<String>()
- val tkt = getTrainKindType(timetable)
- getTrainNumber(timetable).forEach{
- tn.add("${tkt[it]} $it")
- }
- return tn
- }
- private fun getRouteDescriptions(timetable: Timetable): List<String> {
- data class Train(
- var number: Int,
- var type: String,
- var kind: String
- )
- val _trains: MutableMap<Int,MutableList<String>> = mutableMapOf()
- val trains: MutableList<String> = mutableListOf()
- val last_train = Train(0,"","")
- var first_station = ""
- var last_station = ""
- var last_train_number = 0
- checkNotNull(timetable.route).track_sections.forEach {
- it.timetable_entries.forEach {
- val actual_train = Train(
- it.train_number,
- it.train_type,
- it.train_kind
- )
- if (actual_train != last_train) {
- last_train.apply {
- this.number = actual_train.number
- this.type = actual_train.type
- this.kind = actual_train.kind
- }
- if(first_station.isNotEmpty()) {
- if(last_train_number in _trains) {
- checkNotNull(_trains[last_train_number]).add("$first_station - ${it.point_name}")
- }
- else {
- _trains[last_train_number] = mutableListOf()
- checkNotNull(_trains[last_train_number]).add("$first_station - ${it.point_name}")
- }
- }
- if(last_train_number > 0 && last_train_number != it.train_number) {
- val last_route = "$first_station - ${it.point_name}"
- if(last_route !in checkNotNull(_trains[last_train_number])) {
- checkNotNull(_trains[last_train_number]).add(last_route)
- }
- }
- last_train_number = it.train_number
- first_station = it.point_name
- }
- last_station = it.point_name
- }
- }
- val last_route = "$first_station - $last_station"
- if(last_train_number in _trains) {
- if (last_route !in checkNotNull(_trains[last_train_number])) {
- checkNotNull(_trains[last_train_number]).add(last_route)
- }
- }
- else
- {
- _trains[last_train_number] = mutableListOf()
- checkNotNull(_trains[last_train_number]).add(last_route)
- }
- _trains.forEach {
- trains.add(it.value.joinToString(" / "))
- }
- return(trains)
- }
- data class ColumnText (
- val col1: String,
- val col2: String,
- val col2a: String,
- val col3: String,
- val col3_up: String,
- val col5: String,
- val col5_up: String,
- val col6: String,
- val col6_up: String,
- val col7: String,
- val col7_up: String,
- val col8: String,
- val col8_up: String,
- val col8_bo: String,
- val col10: String
- )
- data class Strings (
- val symbol_pics: SymbolPics,
- val column_text: ColumnText
- )
- data class MakeStringResponse(
- val strings: Strings,
- val lastArrHour: Int,
- val lastDepHour: Int,
- val lastSpeed: Int
- )
- private fun calcTimeForMillis(millis: Long): TimetableTime {
- val sec = millis.toFloat()/1000f
- val seconds = round(sec%60).toInt()
- val minutes = round((sec/(60))%60).toInt()
- val hours = round((sec/(3600))%24).toInt()
- return TimetableTime(hours,minutes,seconds)
- }
- private fun makeStrings(timetableEntry: TimetableEntry, arr: Int, dep: Int, speed: Int): MakeStringResponse {
- var lastArrHour = arr
- var lastDepHour = dep
- var lastSpeed = speed
- var track_string = ""
- if (timetableEntry.track != null) {
- track_string = timetableEntry.track.toString()
- }
- var travel_time_string = ""
- var travel_time_up_string = ""
- if (timetableEntry.travel_time != null) {
- travel_time_string = (timetableEntry.travel_time.hours*60+timetableEntry.travel_time.minutes).toString()
- if (timetableEntry.travel_time.seconds > 0) {
- travel_time_up_string = ((timetableEntry.travel_time.seconds / 6f).roundToInt()).toString()
- }
- }
- var arrival_string = ""
- var arrival_up_string = ""
- if (timetableEntry.arrival != null) {
- var str_hours = timetableEntry.arrival.hours.toString()
- if (str_hours.length == 1) {
- str_hours = "0$str_hours"
- }
- var str_minutes = timetableEntry.arrival.minutes.toString()
- if (str_minutes.length == 1) {
- str_minutes = "0$str_minutes"
- }
- val hours = timetableEntry.arrival.hours
- if (hours != lastArrHour) {
- lastArrHour = hours
- arrival_string = "$str_hours $str_minutes"
- } else {
- arrival_string = str_minutes
- }
- if (timetableEntry.arrival.seconds > 0) {
- arrival_up_string = ((timetableEntry.arrival.seconds / 6f).roundToInt()).toString()
- }
- }
- var stay_string = ""
- var stay_up_string = ""
- if (timetableEntry.departure != null && timetableEntry.arrival != null) {
- val cal_arr = Calendar.getInstance()
- cal_arr.set(Calendar.HOUR, timetableEntry.arrival.hours)
- cal_arr.set(Calendar.MINUTE, timetableEntry.arrival.minutes)
- cal_arr.set(Calendar.SECOND, timetableEntry.arrival.seconds)
- val cal_dep = Calendar.getInstance()
- cal_dep.set(Calendar.HOUR, timetableEntry.departure.hours)
- cal_dep.set(Calendar.MINUTE, timetableEntry.departure.minutes)
- cal_dep.set(Calendar.SECOND, timetableEntry.departure.seconds)
- val diff = calcTimeForMillis(cal_dep.timeInMillis - cal_arr.timeInMillis)
- if (diff.hours != 0 || diff.minutes != 0 || diff.seconds != 0) {
- stay_string = "${diff.minutes}"
- if (diff.hours != 0) {
- stay_string = "${diff.hours} $stay_string"
- }
- if (diff.seconds != 0) {
- stay_up_string = ((diff.seconds / 6f).roundToInt()).toString()
- }
- }
- }
- var departure_string = ""
- var departure_up_string = ""
- if (timetableEntry.departure != null) {
- var str_hours = timetableEntry.departure.hours.toString()
- if (str_hours.length == 1) {
- str_hours = "0$str_hours"
- }
- var str_minutes = timetableEntry.departure.minutes.toString()
- if (str_minutes.length == 1) {
- str_minutes = "0$str_minutes"
- }
- val hours = timetableEntry.departure.hours
- if (hours != lastDepHour) {
- lastDepHour = hours
- departure_string = "$str_hours $str_minutes"
- } else {
- departure_string = str_minutes
- }
- if (timetableEntry.departure.seconds > 0) {
- departure_up_string = ((timetableEntry.departure.seconds / 6f).roundToInt()).toString()
- }
- }
- var speed_string = ""
- var brake_percent1 = ""
- var brake_percent2: String? = null
- var col8_up = ""
- var col8_bo = ""
- val speed = timetableEntry.maxSpeed
- if (lastSpeed != speed) {
- speed_string = "$speed/"
- val sa = timetable.shared_attributes
- if (sa != null) {
- val bp = sa.brake_percents[timetableEntry.brake_percents_id]
- if (bp != null) {
- brake_percent1 = bp.percent1.toString()
- if (bp.percent2 != null) {
- brake_percent2 = bp.percent2.toString()
- }
- }
- }
- if (brake_percent2 == null) {
- speed_string += brake_percent1
- } else {
- col8_up = brake_percent1
- col8_bo = brake_percent2
- }
- lastSpeed = speed
- }
- val col10 = timetableEntry.trains.joinToString(",")
- return MakeStringResponse(
- Strings(
- timetableEntry.symbol_pics,
- ColumnText(
- timetableEntry.point_name,
- "",
- track_string,
- travel_time_string,
- travel_time_up_string,
- arrival_string,
- arrival_up_string,
- stay_string,
- stay_up_string,
- departure_string,
- departure_up_string,
- speed_string,
- col8_up,
- col8_bo,
- col10
- )
- ),
- lastArrHour,
- lastDepHour,
- lastSpeed
- )
- }
- private fun getStringForSymbols(symbol: MutableList<Int>): String {
- var ret_str = ""
- return ret_str
- }
- private fun makeRowView(strings: Strings, hasD3cols: Boolean, isLastRow: Boolean): View {
- val row = TableRow(this)
- val rowParams = TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT)
- rowParams.gravity = Gravity.CENTER_HORIZONTAL
- row.layoutParams = rowParams
- val inflater = LayoutInflater.from(this)
- val lp = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- lp.gravity = Gravity.LEFT
- val c1 = inflater.inflate(R.layout.sjr_cell, null)
- c1.layoutParams = lp
- c1.findViewById<TextView>(R.id.main).text = strings.column_text.col1
- val div1 = View(this)
- div1.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- val c2 = inflater.inflate(R.layout.sjr_cell, null)
- c2.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- c2.findViewById<TextView>(R.id.main).text = strings.column_text.col2
- val c2_sb = c2.findViewById<TextView>(R.id.symbolBefore)
- c2_sb.visibility = View.VISIBLE
- c2_sb.text = getStringForSymbols(strings.symbol_pics.col2)
- val div2 = View(this)
- div2.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- val c2a = inflater.inflate(R.layout.sjr_cell, null)
- c2a.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- c2a.findViewById<TextView>(R.id.main).text = strings.column_text.col2a
- val c2a_sb = c2a.findViewById<TextView>(R.id.symbolBefore)
- c2a_sb.visibility = View.VISIBLE
- c2a_sb.text = getStringForSymbols(strings.symbol_pics.col2a)
- val div2a = View(this)
- div2a.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- val c3 = inflater.inflate(R.layout.sjr_cell, null)
- c3.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- val c3_main = c3.findViewById<TextView>(R.id.main)
- c3_main.text = strings.column_text.col3
- c3_main.setTypeface(c3_main.typeface, Typeface.BOLD)
- val c3_up = c3.findViewById<TextView>(R.id.up)
- if (strings.column_text.col3_up.isNotEmpty()) {
- c3_up.visibility = View.VISIBLE
- c3_up.text = strings.column_text.col3_up
- } else {
- c3_up.visibility = View.INVISIBLE
- c3_up.text = "5"
- }
- c3_up.setTypeface(c3_up.typeface, Typeface.BOLD)
- val div3 = View(this)
- div3.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- val c5 = inflater.inflate(R.layout.sjr_cell_time, null)
- c5.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- val c5_hh = c5.findViewById<TextView>(R.id.hh)
- val c5_mm = c5.findViewById<TextView>(R.id.mm)
- val c5_up = c5.findViewById<TextView>(R.id.up)
- val arr = strings.column_text.col5
- if (arr.split(" ").size > 1) {
- c5_hh.text = arr.split(" ")[0]
- c5_mm.text = arr.split(" ")[1]
- } else {
- c5_hh.text = "00"
- c5_hh.visibility = View.INVISIBLE
- c5_mm.text = arr
- }
- if (strings.column_text.col5_up.isNotEmpty()) {
- c5_up.text = strings.column_text.col5_up
- } else {
- c5_up.visibility = View.INVISIBLE
- c5_up.text = "5"
- }
- c5_hh.setTypeface(c5_hh.typeface, Typeface.BOLD)
- c5_mm.setTypeface(c5_mm.typeface, Typeface.BOLD)
- c5_up.setTypeface(c5_up.typeface, Typeface.BOLD)
- val c5_sb = c5.findViewById<TextView>(R.id.symbolBefore)
- c5_sb.text = getStringForSymbols(strings.symbol_pics.col5)
- c5_sb.visibility = View.VISIBLE
- val div5 = View(this)
- div5.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- val c6 = inflater.inflate(R.layout.sjr_cell, null)
- c6.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- val c6_symString = getStringForSymbols(strings.symbol_pics.col6)
- if (c6_symString.isNotEmpty()) {
- val sb = c6.findViewById<TextView>(R.id.symbolBefore)
- c6.findViewById<TextView>(R.id.main).visibility = View.GONE
- c6.findViewById<TextView>(R.id.up).visibility = View.GONE
- sb.visibility = View.VISIBLE
- sb.text = c6_symString
- } else {
- c6.findViewById<TextView>(R.id.main).text = strings.column_text.col6
- val up = c6.findViewById<TextView>(R.id.up)
- if (strings.column_text.col6_up.isNotEmpty()) {
- up.visibility = View.VISIBLE
- up.text = strings.column_text.col6_up
- } else {
- up.visibility = View.INVISIBLE
- up.text = "5"
- }
- }
- val div6 = View(this)
- div6.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- val c7 = inflater.inflate(R.layout.sjr_cell_time, null)
- c7.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- val c7_hh = c7.findViewById<TextView>(R.id.hh)
- val c7_mm = c7.findViewById<TextView>(R.id.mm)
- val c7_up = c7.findViewById<TextView>(R.id.up)
- val dep = strings.column_text.col7
- if (dep.split(" ").size > 1) {
- c7_hh.text = dep.split(" ")[0]
- c7_mm.text = dep.split(" ")[1]
- } else {
- c7_hh.text = "00"
- c7_hh.visibility = View.INVISIBLE
- c7_mm.text = dep
- }
- if (strings.column_text.col7_up.isNotEmpty()) {
- c7_up.text = strings.column_text.col7_up
- } else {
- c7_up.visibility = View.INVISIBLE
- c7_up.text = "5"
- }
- c7_hh.setTypeface(c7_hh.typeface, Typeface.BOLD)
- c7_mm.setTypeface(c7_mm.typeface, Typeface.BOLD)
- c7_up.setTypeface(c7_up.typeface, Typeface.BOLD)
- val c7_sb = c7.findViewById<TextView>(R.id.symbolBefore)
- c7_sb.visibility = View.VISIBLE
- c7_sb.text = getStringForSymbols(strings.symbol_pics.col7)
- val div7 = View(this)
- div7.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- val c8 = inflater.inflate(R.layout.sjr_cell, null)
- c8.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- val c8_main = c8.findViewById<TextView>(R.id.main)
- c8_main.text = strings.column_text.col8
- c8_main.setTypeface(c8_main.typeface, Typeface.BOLD)
- val c8_up = c8.findViewById<TextView>(R.id.up)
- c8_up.visibility = View.VISIBLE
- c8_up.text = strings.column_text.col8_up
- val c8_dn = c8.findViewById<TextView>(R.id.down)
- c8_dn.visibility = View.VISIBLE
- c8_dn.text = strings.column_text.col8_bo
- val c8_sa = c8.findViewById<TextView>(R.id.symbolAfter)
- c8_sa.visibility = View.VISIBLE
- c8_sa.text = getStringForSymbols(strings.symbol_pics.col8)
- val div8 = View(this)
- div8.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- val c10 = inflater.inflate(R.layout.sjr_cell, null)
- c10.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- c10.findViewById<TextView>(R.id.main).text = strings.column_text.col10
- c10.findViewById<TextView>(R.id.up).visibility = View.GONE
- val c10_sa = c10.findViewById<TextView>(R.id.symbolAfter)
- c10_sa.visibility = View.VISIBLE
- c10_sa.text = getStringForSymbols(strings.symbol_pics.col10)
- if (contrast.nightTheme) {
- val color = ContextCompat.getColor(this, R.color.colorPrimary)
- div1.setBackgroundColor(color)
- div2.setBackgroundColor(color)
- div2a.setBackgroundColor(color)
- div3.setBackgroundColor(color)
- div5.setBackgroundColor(color)
- div6.setBackgroundColor(color)
- div7.setBackgroundColor(color)
- div8.setBackgroundColor(color)
- }
- else
- {
- val color = ContextCompat.getColor(this, R.color.colorPrimaryDark)
- div1.setBackgroundColor(color)
- div2.setBackgroundColor(color)
- div2a.setBackgroundColor(color)
- div3.setBackgroundColor(color)
- div5.setBackgroundColor(color)
- div6.setBackgroundColor(color)
- div7.setBackgroundColor(color)
- div8.setBackgroundColor(color)
- }
- row.addView(c1)
- row.addView(div1)
- row.addView(c2)
- row.addView(div2)
- if (hasD3cols) {
- row.addView(c2a)
- row.addView(div2a)
- }
- row.addView(c3)
- row.addView(div3)
- row.addView(c5)
- row.addView(div5)
- row.addView(c6)
- row.addView(div6)
- row.addView(c7)
- row.addView(div7)
- row.addView(c8)
- row.addView(div8)
- if (hasD3cols) {
- row.addView(c10)
- }
- return row
- }
- private fun makeRowViewAsynchronnous(strings: Strings, hasD3cols: Boolean, isLastRow: Boolean): View {
- val row = TableRow(this)
- val rowParams = TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT)
- rowParams.gravity = Gravity.CENTER_HORIZONTAL
- row.layoutParams = rowParams
- runOnUiThread {
- val inflater = AsyncLayoutInflater(this)
- val lp = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- lp.gravity = Gravity.LEFT
- val c1 = inflater.inflate(R.layout.sjr_cell, row) { view, _, parent ->
- view.layoutParams = lp
- view.findViewById<TextView>(R.id.main).text = strings.column_text.col1
- checkNotNull(parent).addView(view)
- }
- val div1 = View(this)
- div1.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- val c2 = inflater.inflate(R.layout.sjr_cell, row) { view, _, parent ->
- view.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- view.findViewById<TextView>(R.id.main).text = strings.column_text.col2
- val sb = view.findViewById<TextView>(R.id.symbolBefore)
- sb.visibility = View.VISIBLE
- sb.text = getStringForSymbols(strings.symbol_pics.col2)
- checkNotNull(parent).addView(div1)
- checkNotNull(parent).addView(view)
- }
- val div2 = View(this)
- div2.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- if (hasD3cols) {
- val c2a = inflater.inflate(R.layout.sjr_cell, row) { view, _, parent ->
- view.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- view.findViewById<TextView>(R.id.main).text = strings.column_text.col2a
- val sb = view.findViewById<TextView>(R.id.symbolBefore)
- sb.visibility = View.VISIBLE
- sb.text = getStringForSymbols(strings.symbol_pics.col2a)
- checkNotNull(parent).addView(div2)
- checkNotNull(parent).addView(view)
- }
- }
- val div2a = View(this)
- div2a.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- val c3 = inflater.inflate(R.layout.sjr_cell, row) { view, _, parent ->
- view.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- val main = view.findViewById<TextView>(R.id.main)
- main.text = strings.column_text.col3
- main.setTypeface(main.typeface, Typeface.BOLD)
- val up = view.findViewById<TextView>(R.id.up)
- if (strings.column_text.col3_up.isNotEmpty()) {
- up.visibility = View.VISIBLE
- up.text = strings.column_text.col3_up
- } else {
- up.visibility = View.INVISIBLE
- up.text = "5"
- }
- up.setTypeface(up.typeface, Typeface.BOLD)
- if (hasD3cols) {
- checkNotNull(parent).addView(div2a)
- } else {
- checkNotNull(parent).addView(div2)
- }
- checkNotNull(parent).addView(view)
- }
- val div3 = View(this)
- div3.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- val c5 = inflater.inflate(R.layout.sjr_cell_time, row) { view, _, parent ->
- view.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- val hh = view.findViewById<TextView>(R.id.hh)
- val mm = view.findViewById<TextView>(R.id.mm)
- val up = view.findViewById<TextView>(R.id.up)
- val arr = strings.column_text.col5
- if (arr.split(" ").size > 1) {
- hh.text = arr.split(" ")[0]
- mm.text = arr.split(" ")[1]
- } else {
- hh.text = "00"
- hh.visibility = View.INVISIBLE
- mm.text = arr
- }
- if (strings.column_text.col5_up.isNotEmpty()) {
- up.text = strings.column_text.col5_up
- } else {
- up.visibility = View.INVISIBLE
- up.text = "5"
- }
- hh.setTypeface(hh.typeface, Typeface.BOLD)
- mm.setTypeface(mm.typeface, Typeface.BOLD)
- up.setTypeface(up.typeface, Typeface.BOLD)
- val sb = view.findViewById<TextView>(R.id.symbolBefore)
- sb.text = getStringForSymbols(strings.symbol_pics.col5)
- sb.visibility = View.VISIBLE
- checkNotNull(parent).addView(div3)
- checkNotNull(parent).addView(view)
- }
- val div5 = View(this)
- div5.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- val c6 = inflater.inflate(R.layout.sjr_cell, row) { view, _, parent ->
- view.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- val c6_symString = getStringForSymbols(strings.symbol_pics.col6)
- if (c6_symString.isNotEmpty()) {
- val sb = view.findViewById<TextView>(R.id.symbolBefore)
- view.findViewById<TextView>(R.id.main).visibility = View.GONE
- view.findViewById<TextView>(R.id.up).visibility = View.GONE
- sb.visibility = View.VISIBLE
- sb.text = c6_symString
- } else {
- view.findViewById<TextView>(R.id.main).text = strings.column_text.col6
- val up = view.findViewById<TextView>(R.id.up)
- if (strings.column_text.col6_up.isNotEmpty()) {
- up.visibility = View.VISIBLE
- up.text = strings.column_text.col6_up
- } else {
- up.visibility = View.INVISIBLE
- up.text = "5"
- }
- }
- checkNotNull(parent).addView(div5)
- checkNotNull(parent).addView(view)
- }
- val div6 = View(this)
- div6.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- val c7 = inflater.inflate(R.layout.sjr_cell_time, row) { view, _, parent ->
- view.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- val hh = view.findViewById<TextView>(R.id.hh)
- val mm = view.findViewById<TextView>(R.id.mm)
- val up = view.findViewById<TextView>(R.id.up)
- val dep = strings.column_text.col7
- if (dep.split(" ").size > 1) {
- hh.text = dep.split(" ")[0]
- mm.text = dep.split(" ")[1]
- } else {
- hh.text = "00"
- hh.visibility = View.INVISIBLE
- mm.text = dep
- }
- if (strings.column_text.col7_up.isNotEmpty()) {
- up.text = strings.column_text.col7_up
- } else {
- up.visibility = View.INVISIBLE
- up.text = "5"
- }
- hh.setTypeface(hh.typeface, Typeface.BOLD)
- mm.setTypeface(mm.typeface, Typeface.BOLD)
- up.setTypeface(up.typeface, Typeface.BOLD)
- val sb = view.findViewById<TextView>(R.id.symbolBefore)
- sb.visibility = View.VISIBLE
- sb.text = getStringForSymbols(strings.symbol_pics.col7)
- checkNotNull(parent).addView(div6)
- checkNotNull(parent).addView(view)
- }
- val div7 = View(this)
- div7.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- val c8 = inflater.inflate(R.layout.sjr_cell, row) { view, _, parent ->
- view.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- val main = view.findViewById<TextView>(R.id.main)
- main.text = strings.column_text.col8
- main.setTypeface(main.typeface, Typeface.BOLD)
- val up = view.findViewById<TextView>(R.id.up)
- up.visibility = View.VISIBLE
- up.text = strings.column_text.col8_up
- val dn = view.findViewById<TextView>(R.id.down)
- dn.visibility = View.VISIBLE
- dn.text = strings.column_text.col8_bo
- val sa = view.findViewById<TextView>(R.id.symbolAfter)
- sa.visibility = View.VISIBLE
- sa.text = getStringForSymbols(strings.symbol_pics.col8)
- checkNotNull(parent).addView(div7)
- checkNotNull(parent).addView(view)
- }
- val div8 = View(this)
- div8.layoutParams = TableRow.LayoutParams(
- 1,
- TableRow.LayoutParams.MATCH_PARENT
- )
- if (hasD3cols) {
- val c10 = inflater.inflate(R.layout.sjr_cell, row) { view, _, parent ->
- view.layoutParams = TableRow.LayoutParams(
- TableRow.LayoutParams.WRAP_CONTENT,
- TableRow.LayoutParams.WRAP_CONTENT,
- 1f
- )
- view.findViewById<TextView>(R.id.main).text = strings.column_text.col10
- view.findViewById<TextView>(R.id.up).visibility = View.GONE
- val sa = view.findViewById<TextView>(R.id.symbolAfter)
- sa.visibility = View.VISIBLE
- sa.text = getStringForSymbols(strings.symbol_pics.col10)
- checkNotNull(parent).addView(div8)
- checkNotNull(parent).addView(view)
- if (isLastRow) {
- findViewById<ProgressBar>(R.id.progressBar).visibility = View.INVISIBLE
- }
- }
- }
- if (contrast.nightTheme) {
- val color = ContextCompat.getColor(this, R.color.colorPrimary)
- div1.setBackgroundColor(color)
- div2.setBackgroundColor(color)
- div2a.setBackgroundColor(color)
- div3.setBackgroundColor(color)
- div5.setBackgroundColor(color)
- div6.setBackgroundColor(color)
- div7.setBackgroundColor(color)
- if (hasD3cols) {
- div8.setBackgroundColor(color)
- }
- }
- else
- {
- val color = ContextCompat.getColor(this, R.color.colorPrimaryDark)
- div1.setBackgroundColor(color)
- div2.setBackgroundColor(color)
- div2a.setBackgroundColor(color)
- div3.setBackgroundColor(color)
- div5.setBackgroundColor(color)
- div6.setBackgroundColor(color)
- div7.setBackgroundColor(color)
- if (hasD3cols) {
- div8.setBackgroundColor(color)
- }
- }
- }
- return row
- }
- private fun generateRows(timetable: Timetable): List<View> {
- val viewList: MutableList<View> = mutableListOf()
- var lastArrHour = -1
- var lastDepHour = -1
- var lastSpeed = -1
- checkNotNull(timetable.route).track_sections.forEachIndexed { tsIndex, trackSection ->
- if (trackSection.line_name != "?" || isShowAllChecked || tsIndex == checkNotNull(timetable.route).track_sections.size-1) {
- trackSection.timetable_entries.forEachIndexed { teIndex, timetableEntry ->
- if ((teIndex == trackSection.timetable_entries.size-1 || isShowAllChecked || timetableEntry.stopping) && timetableEntry.point_name.isNotEmpty()) {
- val response = makeStrings(timetableEntry, lastArrHour, lastDepHour, lastSpeed)
- lastArrHour = response.lastArrHour
- lastDepHour = response.lastDepHour
- lastSpeed = response.lastSpeed
- viewList.add(makeRowView(response.strings, timetable.D3, teIndex == trackSection.timetable_entries.size-1))
- }
- }
- }
- }
- return viewList
- }
- private fun parseXML(`is`: InputStream): Timetable? {
- val parser = TimetableXmlParser()
- return parser.parse(`is`)
- }
- override fun onBackPressed() {
- contrast.unregisterListener()
- handler.removeCallbacks(clockRunnable)
- finish()
- super.onBackPressed()
- //startActivity(Intent(this, landing_screen::class.java))
- }
- override fun onResume() {
- // Register a listener for the sensor.
- super.onResume()
- clockRunnable.run()
- contrast.onResume()
- }
- override fun onPause() {
- // Be sure to unregister the sensor when the activity pauses.
- contrast.unregisterListener()
- handler.removeCallbacks(clockRunnable)
- super.onPause()
- }
- override fun onStop() {
- // Be sure to unregister the sensor when the activity pauses.
- contrast.unregisterListener()
- handler.removeCallbacks(clockRunnable)
- super.onStop()
- }
- override fun onRestart() {
- contrast.onRestart()
- handler.removeCallbacks(clockRunnable)
- super.onRestart()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement