Skip to content

Commit

Permalink
Add Chargelocation.dataSourceUrl and make ChargeLocation.url optional
Browse files Browse the repository at this point in the history
Nobil has no suitable sites to individual charging stations so url needs
to be optional and then we use dataSourceUrl instead in "data source button".
  • Loading branch information
robho committed Dec 1, 2024
1 parent f793c62 commit 5cc8322
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ data class GEChargeLocation(
address.convert(),
chargepoints.map { it.convert() },
network,
"https://www.goingelectric.de/",
"https:${url}",
"https:${url}edit/",
faultReport?.convert(),
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/net/vonforst/evmap/api/nobil/NobilModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ data class NobilChargerStation(
),
chargepoints,
null,
"https://nobil.no",
"https://nobil.no/",
null,
when (chargerStationData.landCode) {
"SWE" -> "https://www.energimyndigheten.se/klimat/transporter/laddinfrastruktur/registrera-din-laddstation/elbilsagare/"
else -> "mailto:[email protected]?subject=" + URLEncoder.encode("Regarding charging station " + chargerStationData.internationalId, "UTF-8").replace("+", "%20")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ data class OCMChargepoint(
addressInfo.toAddress(refData),
connections.map { it.convert(refData) },
operatorInfo?.title ?: refData.operators.find { it.id == operatorId }?.title,
"https://openchargemap.org/",
"https://map.openchargemap.io/?id=$id",
"https://map.openchargemap.io/?id=$id",
convertFaultReport(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ data class OSMChargingStation(
null, // TODO: Can we determine this with overpass?
getChargepoints(),
tags["network"],
"https://www.openstreetmap.org/",
"https://www.openstreetmap.org/node/$id",
"https://www.openstreetmap.org/edit?node=$id",
null,
Expand Down
16 changes: 9 additions & 7 deletions app/src/main/java/net/vonforst/evmap/fragment/MapFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ class MapFragment : Fragment(), OnMapReadyCallback, MenuProvider {
binding.detailView.sourceButton.setOnClickListener {
val charger = vm.charger.value?.data
if (charger != null) {
(activity as? MapsActivity)?.openUrl(charger.url, binding.root, true)
(activity as? MapsActivity)?.openUrl(charger.url ?: charger.dataSourceUrl, binding.root, true)
}
}
binding.detailView.btnChargeprice.setOnClickListener {
Expand Down Expand Up @@ -473,7 +473,7 @@ class MapFragment : Fragment(), OnMapReadyCallback, MenuProvider {
}
R.id.menu_share -> {
val charger = vm.charger.value?.data
if (charger != null) {
if (charger != null && charger.url != null) {
(activity as? MapsActivity)?.shareUrl(charger.url)
}
true
Expand Down Expand Up @@ -851,11 +851,13 @@ class MapFragment : Fragment(), OnMapReadyCallback, MenuProvider {
(activity as? MapsActivity)?.showLocation(charger, binding.root)
}
R.drawable.ic_fault_report -> {
(activity as? MapsActivity)?.openUrl(
charger.url,
binding.root,
true
)
if (charger.url != null) {
(activity as? MapsActivity)?.openUrl(
charger.url,
binding.root,
true
)
}
}

R.drawable.ic_payment -> {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/net/vonforst/evmap/model/ChargersModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sealed class ChargepointListItem
* @param address The charge location address
* @param chargepoints List of chargepoints at this location
* @param network The charging network (Mobility Service Provider, MSP)
* @param dataSourceUrl A link to the data source website
* @param url A link to this charging site
* @param editUrl A link to a website where this charging site can be edited
* @param faultReport Set this if the charging site is reported to be out of service
Expand Down Expand Up @@ -62,7 +63,8 @@ data class ChargeLocation(
@Embedded val address: Address?,
val chargepoints: List<Chargepoint>,
val network: String?,
val url: String, // URL of this charger at the data source
val dataSourceUrl: String, // URL to the data source
val url: String?, // URL of this charger at the data source
val editUrl: String?, // URL to edit this charger at the data source
@Embedded(prefix = "fault_report_") val faultReport: FaultReport?,
val verified: Boolean,
Expand Down
20 changes: 18 additions & 2 deletions app/src/main/java/net/vonforst/evmap/storage/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import net.vonforst.evmap.model.*
OCMCountry::class,
OCMOperator::class,
SavedRegion::class
], version = 23
], version = 24
)
@TypeConverters(Converters::class, GeometryConverters::class)
abstract class AppDatabase : RoomDatabase() {
Expand Down Expand Up @@ -75,7 +75,7 @@ abstract class AppDatabase : RoomDatabase() {
MIGRATION_7, MIGRATION_8, MIGRATION_9, MIGRATION_10, MIGRATION_11,
MIGRATION_12, MIGRATION_13, MIGRATION_14, MIGRATION_15, MIGRATION_16,
MIGRATION_17, MIGRATION_18, MIGRATION_19, MIGRATION_20, MIGRATION_21,
MIGRATION_22, MIGRATION_23
MIGRATION_22, MIGRATION_23, MIGRATION_24
)
.addCallback(object : Callback() {
override fun onCreate(db: SupportSQLiteDatabase) {
Expand Down Expand Up @@ -467,6 +467,22 @@ abstract class AppDatabase : RoomDatabase() {
db.execSQL("INSERT INTO `FilterProfile` (`dataSource`, `name`, `id`, `order`) VALUES ('nobil', 'FILTERS_CUSTOM', $FILTERS_CUSTOM, 0)")
}
}

private val MIGRATION_24 = object : Migration(23, 24) {
override fun migrate(db: SupportSQLiteDatabase) {
// adding dataSourceUrl and making url optional
db.execSQL(
"CREATE TABLE `ChargeLocationNew` (`id` INTEGER NOT NULL, `dataSource` TEXT NOT NULL, `name` TEXT NOT NULL, `coordinates` BLOB NOT NULL, `chargepoints` TEXT NOT NULL, `network` TEXT, `dataSourceUrl` TEXT NOT NULL, `url` TEXT, `editUrl` TEXT, `verified` INTEGER NOT NULL, `barrierFree` INTEGER, `operator` TEXT, `generalInformation` TEXT, `amenities` TEXT, `locationDescription` TEXT, `photos` TEXT, `chargecards` TEXT, `license` TEXT, `timeRetrieved` INTEGER NOT NULL, `isDetailed` INTEGER NOT NULL, `city` TEXT, `country` TEXT, `postcode` TEXT, `street` TEXT, `fault_report_created` INTEGER, `fault_report_description` TEXT, `twentyfourSeven` INTEGER, `description` TEXT, `mostart` TEXT, `moend` TEXT, `tustart` TEXT, `tuend` TEXT, `westart` TEXT, `weend` TEXT, `thstart` TEXT, `thend` TEXT, `frstart` TEXT, `frend` TEXT, `sastart` TEXT, `saend` TEXT, `sustart` TEXT, `suend` TEXT, `hostart` TEXT, `hoend` TEXT, `freecharging` INTEGER, `freeparking` INTEGER, `descriptionShort` TEXT, `descriptionLong` TEXT, `chargepricecountry` TEXT, `chargepricenetwork` TEXT, `chargepriceplugTypes` TEXT, `networkUrl` TEXT, `chargerUrl` TEXT, PRIMARY KEY(`id`, `dataSource`))"
)

db.execSQL("INSERT INTO `ChargeLocationNew` SELECT `id`, `dataSource`, `name`, `coordinates`, `chargepoints`, `network`, '', `url`, `editUrl`, `verified`, `barrierFree`, `operator`, `generalInformation`, `amenities`, `locationDescription`, `photos`, `chargecards`, `license`, `timeRetrieved`, `isDetailed`, `city`, `country`, `postcode`, `street`, `fault_report_created`, `fault_report_description`, `twentyfourSeven`, `description`, `mostart`, `moend`, `tustart`, `tuend`, `westart`, `weend`, `thstart`, `thend`, `frstart`, `frend`, `sastart`, `saend`, `sustart`, `suend`, `hostart`, `hoend`, `freecharging`, `freeparking`, `descriptionShort`, `descriptionLong`, `chargepricecountry`, `chargepricenetwork`, `chargepriceplugTypes`, `networkUrl`, `chargerUrl` FROM `ChargeLocation`")
db.execSQL("UPDATE ChargeLocationNew SET `dataSourceUrl` = 'https://www.goingelectric.de/' WHERE `dataSource` = 'goingelectric'")
db.execSQL("UPDATE ChargeLocationNew SET `dataSourceUrl` = 'https://openchargemap.org/' WHERE `dataSource` = 'openchargemap'")
db.execSQL("UPDATE ChargeLocationNew SET `dataSourceUrl` = 'https://www.openstreetmap.org/' WHERE `dataSource` = 'openstreetmap'")
db.execSQL("DROP TABLE `ChargeLocation`")
db.execSQL("ALTER TABLE `ChargeLocationNew` RENAME TO `ChargeLocation`")
}
}
}

/**
Expand Down

0 comments on commit 5cc8322

Please sign in to comment.