Add additional items in detail view

This commit is contained in:
Johan von Forstner
2020-03-28 19:42:40 +01:00
parent 9d139df1db
commit e460b52b1b
8 changed files with 173 additions and 24 deletions

View File

@@ -115,6 +115,13 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
}
}
}
binding.detailView.goingelectricButton.setOnClickListener {
val charger = binding.charger
if (charger != null) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https:${charger.url}"))
startActivity(intent)
}
}
}
private fun setupAdapters() {

View File

@@ -51,8 +51,12 @@ class ConnectorAdapter : DataBindingAdapter<Chargepoint>() {
}
class DetailAdapter : DataBindingAdapter<DetailAdapter.Detail>() {
data class Detail(val icon: Int, val contentDescription: Int, val text: CharSequence) :
Equatable
data class Detail(
val icon: Int,
val contentDescription: Int,
val text: CharSequence,
val detailText: CharSequence? = null
) : Equatable
override fun getItemViewType(position: Int): Int = R.layout.item_detail
}
@@ -61,7 +65,12 @@ fun buildDetails(loc: ChargeLocation?, ctx: Context): List<DetailAdapter.Detail>
if (loc == null) return emptyList()
return listOfNotNull(
DetailAdapter.Detail(R.drawable.ic_address, R.string.address, loc.address.toString()),
DetailAdapter.Detail(
R.drawable.ic_address,
R.string.address,
loc.address.toString(),
loc.locationDescription
),
if (loc.operator != null) DetailAdapter.Detail(
R.drawable.ic_operator,
R.string.operator,
@@ -76,7 +85,15 @@ fun buildDetails(loc: ChargeLocation?, ctx: Context): List<DetailAdapter.Detail>
if (loc.openinghours != null) DetailAdapter.Detail(
R.drawable.ic_hours,
R.string.hours,
loc.openinghours.getStatusText(ctx)
) else null
loc.openinghours.getStatusText(ctx),
loc.openinghours.description
) else null,
if (loc.cost != null) DetailAdapter.Detail(
R.drawable.ic_cost,
R.string.cost,
loc.cost.getStatusText(ctx),
loc.cost.descriptionLong ?: loc.cost.descriptionShort
)
else null
)
}

View File

@@ -31,10 +31,13 @@ data class ChargeLocation(
val verified: Boolean,
// only shown in details:
@JsonObjectOrFalse val operator: String?,
@Json(name = "general_information") @JsonObjectOrFalse val generalInformation: String?,
@JsonObjectOrFalse @Json(name = "general_information") val generalInformation: String?,
@JsonObjectOrFalse @Json(name = "ladeweile") val amenities: String?,
@JsonObjectOrFalse @Json(name = "location_description") val locationDescription: String?,
val photos: List<ChargerPhoto>?,
//val chargecards: Boolean?
val openinghours: OpeningHours?
val openinghours: OpeningHours?,
val cost: Cost?
) : ChargepointListItem() {
val maxPower: Double
get() {
@@ -48,6 +51,24 @@ data class ChargeLocation(
}
}
@JsonClass(generateAdapter = true)
data class Cost(
val freecharging: Boolean,
val freeparking: Boolean,
@JsonObjectOrFalse @Json(name = "description_short") val descriptionShort: String?,
@JsonObjectOrFalse @Json(name = "description_long") val descriptionLong: String?
) {
fun getStatusText(ctx: Context): CharSequence {
return HtmlCompat.fromHtml(
ctx.getString(
R.string.cost_detail,
if (freecharging) ctx.getString(R.string.free) else ctx.getString(R.string.paid),
if (freeparking) ctx.getString(R.string.free) else ctx.getString(R.string.paid)
), 0
)
}
}
@JsonClass(generateAdapter = true)
data class OpeningHours(
@Json(name = "24/7") val twentyfourSeven: Boolean,