Bimba.git

ref: c1db5ac8fc4a50eb6c9f311c14b04c65a2654a24

app/src/main/java/xyz/apiote/bimba/czwek/repo/Stop.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
// SPDX-FileCopyrightText: Adam Evyčędo
//
// SPDX-License-Identifier: GPL-3.0-or-later

package xyz.apiote.bimba.czwek.repo

import android.content.Context
import android.graphics.drawable.Drawable
import xyz.apiote.bimba.czwek.R
import xyz.apiote.bimba.czwek.api.StopV1
import xyz.apiote.bimba.czwek.api.StopV2

data class Stop(
	val code: String,
	val name: String,
	val nodeName: String,
	val zone: String,
	val feedID: String?,
	val position: Position,
	val changeOptions: List<ChangeOption>
) : Queryable, Locatable, StopAbstract {

	override fun icon(context: Context, scale: Float): Drawable {
		return super.icon(context, nodeName, scale)
	}

	override fun id(): String = code

	override fun location(): Position = position

	constructor(s: StopV1) : this(
		s.code,
		s.name,
		s.name,
		s.zone,
		null,
		Position(s.position),
		s.changeOptions.map { ChangeOption(it) })

	constructor(s: StopV2) : this(
		s.code,
		s.name,
		s.nodeName,
		s.zone,
		s.feedID,
		Position(s.position),
		s.changeOptions.map { ChangeOption(it) })

	fun changeOptions(context: Context): Pair<String, String> = Pair(changeOptions.groupBy { it.line }
		.map { Pair(it.key, it.value.joinToString { co -> co.headsign }) }.joinToString {
			context.getString(
				R.string.vehicle_headsign, it.first, it.second
			)
		},
		changeOptions.groupBy { it.line }
			.map { Pair(it.key, it.value.joinToString { co -> co.headsign }) }.joinToString {
				context.getString(
					R.string.vehicle_headsign_content_description, it.first, it.second
				)
			})

	override fun toString(): String {
		var result = "$name ($code) [$zone] $position\n"
		for (chOpt in changeOptions) result += "${chOpt.line}${chOpt.headsign}\n"
		return result
	}
}