From 5cc8322f37a15cf27a627b22e8c9bf85c041c90f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20H=C3=B6gberg?= Date: Sun, 1 Dec 2024 21:45:13 +0100 Subject: [PATCH] Add Chargelocation.dataSourceUrl and make ChargeLocation.url optional 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". --- .../api/goingelectric/GoingElectricModel.kt | 1 + .../vonforst/evmap/api/nobil/NobilModel.kt | 3 ++- .../api/openchargemap/OpenChargeMapModel.kt | 1 + .../api/openstreetmap/OpenStreetMapModel.kt | 1 + .../vonforst/evmap/fragment/MapFragment.kt | 16 ++++++++------- .../net/vonforst/evmap/model/ChargersModel.kt | 4 +++- .../net/vonforst/evmap/storage/Database.kt | 20 +++++++++++++++++-- 7 files changed, 35 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/net/vonforst/evmap/api/goingelectric/GoingElectricModel.kt b/app/src/main/java/net/vonforst/evmap/api/goingelectric/GoingElectricModel.kt index adc2c8539..baa7d07df 100644 --- a/app/src/main/java/net/vonforst/evmap/api/goingelectric/GoingElectricModel.kt +++ b/app/src/main/java/net/vonforst/evmap/api/goingelectric/GoingElectricModel.kt @@ -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(), diff --git a/app/src/main/java/net/vonforst/evmap/api/nobil/NobilModel.kt b/app/src/main/java/net/vonforst/evmap/api/nobil/NobilModel.kt index b9a72a0e6..06bb1cbb6 100644 --- a/app/src/main/java/net/vonforst/evmap/api/nobil/NobilModel.kt +++ b/app/src/main/java/net/vonforst/evmap/api/nobil/NobilModel.kt @@ -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:post@nobil.no?subject=" + URLEncoder.encode("Regarding charging station " + chargerStationData.internationalId, "UTF-8").replace("+", "%20") diff --git a/app/src/main/java/net/vonforst/evmap/api/openchargemap/OpenChargeMapModel.kt b/app/src/main/java/net/vonforst/evmap/api/openchargemap/OpenChargeMapModel.kt index 4657c31b2..c2d2c68fc 100644 --- a/app/src/main/java/net/vonforst/evmap/api/openchargemap/OpenChargeMapModel.kt +++ b/app/src/main/java/net/vonforst/evmap/api/openchargemap/OpenChargeMapModel.kt @@ -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(), diff --git a/app/src/main/java/net/vonforst/evmap/api/openstreetmap/OpenStreetMapModel.kt b/app/src/main/java/net/vonforst/evmap/api/openstreetmap/OpenStreetMapModel.kt index 2fc4c5cf8..67d23aa4c 100644 --- a/app/src/main/java/net/vonforst/evmap/api/openstreetmap/OpenStreetMapModel.kt +++ b/app/src/main/java/net/vonforst/evmap/api/openstreetmap/OpenStreetMapModel.kt @@ -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, diff --git a/app/src/main/java/net/vonforst/evmap/fragment/MapFragment.kt b/app/src/main/java/net/vonforst/evmap/fragment/MapFragment.kt index 02f318b89..a8f842960 100644 --- a/app/src/main/java/net/vonforst/evmap/fragment/MapFragment.kt +++ b/app/src/main/java/net/vonforst/evmap/fragment/MapFragment.kt @@ -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 { @@ -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 @@ -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 -> { diff --git a/app/src/main/java/net/vonforst/evmap/model/ChargersModel.kt b/app/src/main/java/net/vonforst/evmap/model/ChargersModel.kt index 96169fce3..970a253c9 100644 --- a/app/src/main/java/net/vonforst/evmap/model/ChargersModel.kt +++ b/app/src/main/java/net/vonforst/evmap/model/ChargersModel.kt @@ -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 @@ -62,7 +63,8 @@ data class ChargeLocation( @Embedded val address: Address?, val chargepoints: List, 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, diff --git a/app/src/main/java/net/vonforst/evmap/storage/Database.kt b/app/src/main/java/net/vonforst/evmap/storage/Database.kt index f57abe8fe..1a02c9414 100644 --- a/app/src/main/java/net/vonforst/evmap/storage/Database.kt +++ b/app/src/main/java/net/vonforst/evmap/storage/Database.kt @@ -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() { @@ -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) { @@ -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`") + } + } } /**