diff --git a/app/src/main/java/com/yacgroup/yacguide/ClimbingObject.kt b/app/src/main/java/com/yacgroup/yacguide/ClimbingObject.kt index 94ca96e4..8d1f8c56 100644 --- a/app/src/main/java/com/yacgroup/yacguide/ClimbingObject.kt +++ b/app/src/main/java/com/yacgroup/yacguide/ClimbingObject.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Axel Paetzold + * Copyright (C) 2021, 2023 Axel Paetzold * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,4 +32,6 @@ enum class ClimbingObjectLevel(val value: Int) { } } -class ClimbingObject(val level: ClimbingObjectLevel, val parentId: Int, val parentName: String) \ No newline at end of file +class ClimbingObjectUId(val id: Int, val name: String) + +class ClimbingObject(val level: ClimbingObjectLevel, val parentUId: ClimbingObjectUId) \ No newline at end of file diff --git a/app/src/main/java/com/yacgroup/yacguide/CountryActivity.kt b/app/src/main/java/com/yacgroup/yacguide/CountryActivity.kt index 0a055e42..0b0666d5 100644 --- a/app/src/main/java/com/yacgroup/yacguide/CountryActivity.kt +++ b/app/src/main/java/com/yacgroup/yacguide/CountryActivity.kt @@ -82,7 +82,10 @@ class CountryActivity : TableActivityWithOptionsMenu() { val countries = db.getCountries() val pinnedCountries = customSettings.getStringSet(getString(R.string.pinned_countries), emptySet()).orEmpty() _viewAdapter.submitList(countries.sortedBy { !pinnedCountries.contains(it.name) }) - _updateHandler.configureDownloadButton(countries.isEmpty()){ displayContent() } + _updateHandler.configureDownloadButton( + enabled = countries.isEmpty(), + climbingObjectUId = ClimbingObjectUId(0, getString(R.string.countries_and_regions)) + ){ displayContent() } } private fun _onCountrySelected(countryName: String) { diff --git a/app/src/main/java/com/yacgroup/yacguide/DescriptionActivity.kt b/app/src/main/java/com/yacgroup/yacguide/DescriptionActivity.kt index d046b1bf..5ec7e6ff 100644 --- a/app/src/main/java/com/yacgroup/yacguide/DescriptionActivity.kt +++ b/app/src/main/java/com/yacgroup/yacguide/DescriptionActivity.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019, 2022 Axel Paetzold + * Copyright (C) 2019, 2022, 2023 Axel Paetzold * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,7 +35,7 @@ class DescriptionActivity : TableActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - _route = db.getRoute(activityLevel.parentId)!! + _route = db.getRoute(activityLevel.parentUId.id)!! if (_route.statusId > 1) { findViewById(R.id.infoTextView).text = "${getString(R.string.route_restricted)} ${Route.STATUS[_route.statusId]}" @@ -55,7 +55,7 @@ class DescriptionActivity : TableActivity() { } override fun showComments(v: View) { - showRouteComments(activityLevel.parentId) + showRouteComments(activityLevel.parentUId.id) } @Suppress("UNUSED_PARAMETER") diff --git a/app/src/main/java/com/yacgroup/yacguide/LaunchActivity.kt b/app/src/main/java/com/yacgroup/yacguide/LaunchActivity.kt index 028e40e7..fe0b4069 100644 --- a/app/src/main/java/com/yacgroup/yacguide/LaunchActivity.kt +++ b/app/src/main/java/com/yacgroup/yacguide/LaunchActivity.kt @@ -51,7 +51,7 @@ class LaunchActivity : AppCompatActivity() { _customSettings = getSharedPreferences(getString(R.string.preferences_filename), Context.MODE_PRIVATE) _updateHandler = UpdateHandler(this, CountryAndRegionParser(_db)) - _updateHandler.update(isRecurring = false, isSilent = true) + _updateHandler.update(isSilent = true) Timer().start() } diff --git a/app/src/main/java/com/yacgroup/yacguide/RegionActivity.kt b/app/src/main/java/com/yacgroup/yacguide/RegionActivity.kt index 38e0a8d0..c3e808fe 100644 --- a/app/src/main/java/com/yacgroup/yacguide/RegionActivity.kt +++ b/app/src/main/java/com/yacgroup/yacguide/RegionActivity.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019, 2022 Axel Paetzold + * Copyright (C) 2019, 2022, 2023 Axel Paetzold * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -44,8 +44,8 @@ class RegionActivity : TableActivityWithOptionsMenu() { override fun getLayoutId() = R.layout.activity_table override fun displayContent() { - this.title = activityLevel.parentName - val regions = db.getRegions(activityLevel.parentName) + this.title = activityLevel.parentUId.name + val regions = db.getRegions(activityLevel.parentUId.name) _viewAdapter.submitList(regions) } diff --git a/app/src/main/java/com/yacgroup/yacguide/RegionManagerActivity.kt b/app/src/main/java/com/yacgroup/yacguide/RegionManagerActivity.kt index 45215d15..a35e74c4 100644 --- a/app/src/main/java/com/yacgroup/yacguide/RegionManagerActivity.kt +++ b/app/src/main/java/com/yacgroup/yacguide/RegionManagerActivity.kt @@ -49,7 +49,7 @@ class RegionManagerActivity : BaseNavigationActivity() { _db = DatabaseWrapper(this) _countryAndRegionParser = CountryAndRegionParser(_db) - _sectorParser = SectorParser(_db, 0) + _sectorParser = SectorParser(_db) _updateHandler = UpdateHandler(this, _sectorParser) _customSettings = getSharedPreferences(getString(R.string.preferences_filename), Context.MODE_PRIVATE) @@ -63,9 +63,7 @@ class RegionManagerActivity : BaseNavigationActivity() { ) { pos -> _updateRegionListAndDB(pos) { region -> _updateHandler.setJsonParser(_sectorParser) - _sectorParser.setRegionId(region.id) - _sectorParser.setRegionName(region.name.orEmpty()) - _updateHandler.update() + _updateHandler.update(ClimbingObjectUId(region.id, region.name.orEmpty())) } } val swipeLeftConfig = SwipeConfig( @@ -132,6 +130,7 @@ class RegionManagerActivity : BaseNavigationActivity() { // We need to update regions recursively since update() is asynchronous. _updateHandler.setJsonParser(_countryAndRegionParser) _updateHandler.update( + climbingObjectUId = ClimbingObjectUId(0, getString(R.string.countries_and_regions)), onUpdateFinished = { _updateHandler.setJsonParser(_sectorParser) _updateNextRegion(_db.getNonEmptyRegions().toMutableSet()) }, @@ -142,9 +141,8 @@ class RegionManagerActivity : BaseNavigationActivity() { try { val nextRegion = regions.first() regions.remove(nextRegion) - _sectorParser.setRegionId(nextRegion.id) - _sectorParser.setRegionName(nextRegion.name.orEmpty()) _updateHandler.update( + climbingObjectUId = ClimbingObjectUId(nextRegion.id, nextRegion.name.orEmpty()), onUpdateFinished = { _updateNextRegion(regions) }, isRecurring = true) } catch (e: NoSuchElementException) { diff --git a/app/src/main/java/com/yacgroup/yacguide/RockActivity.kt b/app/src/main/java/com/yacgroup/yacguide/RockActivity.kt index 3d794229..248dfbad 100644 --- a/app/src/main/java/com/yacgroup/yacguide/RockActivity.kt +++ b/app/src/main/java/com/yacgroup/yacguide/RockActivity.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019, 2022 Axel Paetzold + * Copyright (C) 2019, 2022, 2023 Axel Paetzold * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -60,19 +60,19 @@ class RockActivity : TableActivityWithOptionsMenu() { getByRelevance = { db.getRocksByRelevance(_filterMaxRelevanceId) } ), ClimbingObjectLevel.eRegion to RockGetter( - getAll = { db.getRocksForCountry(activityLevel.parentName) }, - getByName = { db.getRocksByNameForCountry(activityLevel.parentName, _filterName) }, - getByRelevance = { db.getRocksByRelevanceForCountry(activityLevel.parentName, _filterMaxRelevanceId) } + getAll = { db.getRocksForCountry(activityLevel.parentUId.name) }, + getByName = { db.getRocksByNameForCountry(activityLevel.parentUId.name, _filterName) }, + getByRelevance = { db.getRocksByRelevanceForCountry(activityLevel.parentUId.name, _filterMaxRelevanceId) } ), ClimbingObjectLevel.eSector to RockGetter( - getAll = { db.getRocksForRegion(activityLevel.parentId) }, - getByName = { db.getRocksByNameForRegion(activityLevel.parentId, _filterName) }, - getByRelevance = { db.getRocksByRelevanceForRegion(activityLevel.parentId, _filterMaxRelevanceId) } + getAll = { db.getRocksForRegion(activityLevel.parentUId.id) }, + getByName = { db.getRocksByNameForRegion(activityLevel.parentUId.id, _filterName) }, + getByRelevance = { db.getRocksByRelevanceForRegion(activityLevel.parentUId.id, _filterMaxRelevanceId) } ), ClimbingObjectLevel.eRock to RockGetter( - getAll = { db.getRocksForSector(activityLevel.parentId) }, - getByName = { db.getRocksByNameForSector(activityLevel.parentId, _filterName) }, - getByRelevance = { db.getRocksByRelevanceForSector(activityLevel.parentId, _filterMaxRelevanceId) } + getAll = { db.getRocksForSector(activityLevel.parentUId.id) }, + getByName = { db.getRocksByNameForSector(activityLevel.parentUId.id, _filterName) }, + getByRelevance = { db.getRocksByRelevanceForSector(activityLevel.parentUId.id, _filterMaxRelevanceId) } ) ) @@ -99,14 +99,14 @@ class RockActivity : TableActivityWithOptionsMenu() { override fun showComments(v: View) { when (activityLevel.level) { - ClimbingObjectLevel.eSector -> showRegionComments(activityLevel.parentId) - ClimbingObjectLevel.eRock -> showSectorComments(activityLevel.parentId) + ClimbingObjectLevel.eSector -> showRegionComments(activityLevel.parentUId.id) + ClimbingObjectLevel.eRock -> showSectorComments(activityLevel.parentUId.id) else -> showNoCommentToast() } } override fun displayContent() { - val levelName = ParserUtils.decodeObjectNames(activityLevel.parentName) + val levelName = ParserUtils.decodeObjectNames(activityLevel.parentUId.name) this.title = if (levelName.first.isNotEmpty()) levelName.first else levelName.second var rocks = _getAndFilterRocks() diff --git a/app/src/main/java/com/yacgroup/yacguide/RouteActivity.kt b/app/src/main/java/com/yacgroup/yacguide/RouteActivity.kt index 81fc5170..b278fd52 100644 --- a/app/src/main/java/com/yacgroup/yacguide/RouteActivity.kt +++ b/app/src/main/java/com/yacgroup/yacguide/RouteActivity.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019, 2022 Axel Paetzold + * Copyright (C) 2019, 2022, 2023 Axel Paetzold * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -81,44 +81,44 @@ class RouteActivity : TableActivityWithOptionsMenu() { getBotches = { db.getBotchedRoutes() } ), ClimbingObjectLevel.eRegion to RouteGetter( - getAll = { db.getRoutesForCountry(activityLevel.parentName) }, - getByName = { db.getRoutesByNameForCountry(activityLevel.parentName, _filterName) }, - getByGrade = { db.getRoutesByGradeForCountry(activityLevel.parentName, _filterMinGradeId, _filterMaxGradeId) }, - getByQuality = { db.getRoutesByQualityForCountry(activityLevel.parentName, _filterMaxQualityId) }, - getByProtection = { db.getRoutesByProtectionForCountry(activityLevel.parentName, _filterMaxProtectionId) }, - getByDrying = { db.getRoutesByDryingForCountry(activityLevel.parentName, _filterMaxDryingId) }, - getProjects = { db.getProjectedRoutesForCountry(activityLevel.parentName) }, - getBotches = { db.getBotchedRoutesForCountry(activityLevel.parentName) } + getAll = { db.getRoutesForCountry(activityLevel.parentUId.name) }, + getByName = { db.getRoutesByNameForCountry(activityLevel.parentUId.name, _filterName) }, + getByGrade = { db.getRoutesByGradeForCountry(activityLevel.parentUId.name, _filterMinGradeId, _filterMaxGradeId) }, + getByQuality = { db.getRoutesByQualityForCountry(activityLevel.parentUId.name, _filterMaxQualityId) }, + getByProtection = { db.getRoutesByProtectionForCountry(activityLevel.parentUId.name, _filterMaxProtectionId) }, + getByDrying = { db.getRoutesByDryingForCountry(activityLevel.parentUId.name, _filterMaxDryingId) }, + getProjects = { db.getProjectedRoutesForCountry(activityLevel.parentUId.name) }, + getBotches = { db.getBotchedRoutesForCountry(activityLevel.parentUId.name) } ), ClimbingObjectLevel.eSector to RouteGetter( - getAll = { db.getRoutesForRegion(activityLevel.parentId) }, - getByName = { db.getRoutesByNameForRegion(activityLevel.parentId, _filterName) }, - getByGrade = { db.getRoutesByGradeForRegion(activityLevel.parentId, _filterMinGradeId, _filterMaxGradeId) }, - getByQuality = { db.getRoutesByQualityForRegion(activityLevel.parentId, _filterMaxQualityId) }, - getByProtection = { db.getRoutesByProtectionForRegion(activityLevel.parentId, _filterMaxProtectionId) }, - getByDrying = { db.getRoutesByDryingForRegion(activityLevel.parentId, _filterMaxDryingId) }, - getProjects = { db.getProjectedRoutesForRegion(activityLevel.parentId) }, - getBotches = { db.getBotchedRoutesForRegion(activityLevel.parentId) } + getAll = { db.getRoutesForRegion(activityLevel.parentUId.id) }, + getByName = { db.getRoutesByNameForRegion(activityLevel.parentUId.id, _filterName) }, + getByGrade = { db.getRoutesByGradeForRegion(activityLevel.parentUId.id, _filterMinGradeId, _filterMaxGradeId) }, + getByQuality = { db.getRoutesByQualityForRegion(activityLevel.parentUId.id, _filterMaxQualityId) }, + getByProtection = { db.getRoutesByProtectionForRegion(activityLevel.parentUId.id, _filterMaxProtectionId) }, + getByDrying = { db.getRoutesByDryingForRegion(activityLevel.parentUId.id, _filterMaxDryingId) }, + getProjects = { db.getProjectedRoutesForRegion(activityLevel.parentUId.id) }, + getBotches = { db.getBotchedRoutesForRegion(activityLevel.parentUId.id) } ), ClimbingObjectLevel.eRock to RouteGetter( - getAll = { db.getRoutesForSector(activityLevel.parentId) }, - getByName = { db.getRoutesByNameForSector(activityLevel.parentId, _filterName) }, - getByGrade = { db.getRoutesByGradeForSector(activityLevel.parentId, _filterMinGradeId, _filterMaxGradeId) }, - getByQuality = { db.getRoutesByQualityForSector(activityLevel.parentId, _filterMaxQualityId) }, - getByProtection = { db.getRoutesByProtectionForSector(activityLevel.parentId, _filterMaxProtectionId) }, - getByDrying = { db.getRoutesByDryingForSector(activityLevel.parentId, _filterMaxDryingId) }, - getProjects = { db.getProjectedRoutesForSector(activityLevel.parentId) }, - getBotches = { db.getBotchedRoutesForSector(activityLevel.parentId) } + getAll = { db.getRoutesForSector(activityLevel.parentUId.id) }, + getByName = { db.getRoutesByNameForSector(activityLevel.parentUId.id, _filterName) }, + getByGrade = { db.getRoutesByGradeForSector(activityLevel.parentUId.id, _filterMinGradeId, _filterMaxGradeId) }, + getByQuality = { db.getRoutesByQualityForSector(activityLevel.parentUId.id, _filterMaxQualityId) }, + getByProtection = { db.getRoutesByProtectionForSector(activityLevel.parentUId.id, _filterMaxProtectionId) }, + getByDrying = { db.getRoutesByDryingForSector(activityLevel.parentUId.id, _filterMaxDryingId) }, + getProjects = { db.getProjectedRoutesForSector(activityLevel.parentUId.id) }, + getBotches = { db.getBotchedRoutesForSector(activityLevel.parentUId.id) } ), ClimbingObjectLevel.eRoute to RouteGetter( - getAll = { db.getRoutesForRock(activityLevel.parentId) }, - getByName = { db.getRoutesByNameForRock(activityLevel.parentId, _filterName) }, - getByGrade = { db.getRoutesByGradeForRock(activityLevel.parentId, _filterMinGradeId, _filterMaxGradeId) }, - getByQuality = { db.getRoutesByQualityForRock(activityLevel.parentId, _filterMaxQualityId) }, - getByProtection = { db.getRoutesByProtectionForRock(activityLevel.parentId, _filterMaxProtectionId) }, - getByDrying = { db.getRoutesByDryingForRock(activityLevel.parentId, _filterMaxDryingId) }, - getProjects = { db.getProjectedRoutesForRock(activityLevel.parentId) }, - getBotches = { db.getBotchedRoutesForRock(activityLevel.parentId) } + getAll = { db.getRoutesForRock(activityLevel.parentUId.id) }, + getByName = { db.getRoutesByNameForRock(activityLevel.parentUId.id, _filterName) }, + getByGrade = { db.getRoutesByGradeForRock(activityLevel.parentUId.id, _filterMinGradeId, _filterMaxGradeId) }, + getByQuality = { db.getRoutesByQualityForRock(activityLevel.parentUId.id, _filterMaxQualityId) }, + getByProtection = { db.getRoutesByProtectionForRock(activityLevel.parentUId.id, _filterMaxProtectionId) }, + getByDrying = { db.getRoutesByDryingForRock(activityLevel.parentUId.id, _filterMaxDryingId) }, + getProjects = { db.getProjectedRoutesForRock(activityLevel.parentUId.id) }, + getBotches = { db.getBotchedRoutesForRock(activityLevel.parentUId.id) } ) ) @@ -132,7 +132,7 @@ class RouteActivity : TableActivityWithOptionsMenu() { { routeNamePart, onlyOfficialRoutes -> _onSearchBarUpdate(routeNamePart, onlyOfficialRoutes) }) if (activityLevel.level == ClimbingObjectLevel.eRoute) { - _rock = db.getRock(activityLevel.parentId) + _rock = db.getRock(activityLevel.parentUId.id) } else { findViewById(R.id.mapButton).visibility = View.INVISIBLE } @@ -164,15 +164,15 @@ class RouteActivity : TableActivityWithOptionsMenu() { override fun showComments(v: View) { when (activityLevel.level) { - ClimbingObjectLevel.eSector -> showRegionComments(activityLevel.parentId) - ClimbingObjectLevel.eRock -> showSectorComments(activityLevel.parentId) - ClimbingObjectLevel.eRoute -> showRockComments(activityLevel.parentId) + ClimbingObjectLevel.eSector -> showRegionComments(activityLevel.parentUId.id) + ClimbingObjectLevel.eRock -> showSectorComments(activityLevel.parentUId.id) + ClimbingObjectLevel.eRoute -> showRockComments(activityLevel.parentUId.id) else -> showNoCommentToast() } } override fun displayContent() { - val levelName = ParserUtils.decodeObjectNames(activityLevel.parentName) + val levelName = ParserUtils.decodeObjectNames(activityLevel.parentUId.name) this.title = if (levelName.first.isNotEmpty()) levelName.first else levelName.second _displayRockInfo(findViewById(R.id.infoTextView)) diff --git a/app/src/main/java/com/yacgroup/yacguide/SectorActivity.kt b/app/src/main/java/com/yacgroup/yacguide/SectorActivity.kt index 594d8b4b..46e268ed 100644 --- a/app/src/main/java/com/yacgroup/yacguide/SectorActivity.kt +++ b/app/src/main/java/com/yacgroup/yacguide/SectorActivity.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019, 2022 Axel Paetzold + * Copyright (C) 2019, 2022, 2023 Axel Paetzold * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,7 +34,7 @@ class SectorActivity : TableActivityWithOptionsMenu() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - _updateHandler = UpdateHandler(this, SectorParser(db, activityLevel.parentId)) + _updateHandler = UpdateHandler(this, SectorParser(db)) properties = arrayListOf( RouteSearchable(this), RockSearchable(this), @@ -48,14 +48,17 @@ class SectorActivity : TableActivityWithOptionsMenu() { override fun getLayoutId() = R.layout.activity_sector override fun showComments(v: View) { - showRegionComments(activityLevel.parentId) + showRegionComments(activityLevel.parentUId.id) } override fun displayContent() { - this.title = activityLevel.parentName - val sectors = db.getSectors(activityLevel.parentId) + this.title = activityLevel.parentUId.name + val sectors = db.getSectors(activityLevel.parentUId.id) _viewAdapter.submitList(sectors) - _updateHandler.configureDownloadButton(sectors.isEmpty()) { displayContent() } + _updateHandler.configureDownloadButton( + enabled = sectors.isEmpty(), + climbingObjectUId = ClimbingObjectUId(activityLevel.parentUId.id, activityLevel.parentUId.name) + ) { displayContent() } } private fun _onSectorSelected(sectorId: Int, sectorName: String) { diff --git a/app/src/main/java/com/yacgroup/yacguide/TableActivity.kt b/app/src/main/java/com/yacgroup/yacguide/TableActivity.kt index 2742edb4..8c0771b8 100644 --- a/app/src/main/java/com/yacgroup/yacguide/TableActivity.kt +++ b/app/src/main/java/com/yacgroup/yacguide/TableActivity.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019, 2022 Axel Paetzold + * Copyright (C) 2019, 2022, 2023 Axel Paetzold * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,8 +45,10 @@ abstract class TableActivity : BaseNavigationActivity() { activityLevel = ClimbingObject( level = ClimbingObjectLevel.fromInt(intent.getIntExtra(IntentConstants.CLIMBING_OBJECT_LEVEL, ClimbingObjectLevel.eCountry.value)), - parentId = intent.getIntExtra(IntentConstants.CLIMBING_OBJECT_PARENT_ID, DatabaseWrapper.INVALID_ID), - parentName = intent.getStringExtra(IntentConstants.CLIMBING_OBJECT_PARENT_NAME).orEmpty() + parentUId = ClimbingObjectUId( + id = intent.getIntExtra(IntentConstants.CLIMBING_OBJECT_PARENT_ID, DatabaseWrapper.INVALID_ID), + name = intent.getStringExtra(IntentConstants.CLIMBING_OBJECT_PARENT_NAME).orEmpty() + ) ) db = DatabaseWrapper(this) customSettings = getSharedPreferences(getString(R.string.preferences_filename), Context.MODE_PRIVATE) diff --git a/app/src/main/java/com/yacgroup/yacguide/UpdateHandler.kt b/app/src/main/java/com/yacgroup/yacguide/UpdateHandler.kt index 5a349bc0..6d14dc8e 100644 --- a/app/src/main/java/com/yacgroup/yacguide/UpdateHandler.kt +++ b/app/src/main/java/com/yacgroup/yacguide/UpdateHandler.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021, 2022 Axel Paetzold + * Copyright (C) 2021, 2022, 2023 Axel Paetzold * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ import android.app.Dialog import android.view.View import android.widget.Button import android.widget.ImageButton +import android.widget.LinearLayout import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity @@ -32,9 +33,11 @@ import com.yacgroup.yacguide.utils.NetworkUtils class UpdateHandler(private val _activity: AppCompatActivity, private var _jsonParser: JSONWebParser): UpdateListener { + private val _failedRegionsNames: MutableSet = emptySet().toMutableSet() private var _updateDialog: Dialog private var _isRecurringUpdate: Boolean = false private var _isSilentUpdate: Boolean = false + private var _climbingObjectUId: ClimbingObjectUId = ClimbingObjectUId(0, "") private var _exitCode: ExitCode = ExitCode.SUCCESS private var _onUpdateFinished: () -> Unit = {} @@ -51,11 +54,15 @@ class UpdateHandler(private val _activity: AppCompatActivity, override fun onUpdateStatus(statusMessage: String) { if (!_isSilentUpdate) { _activity.runOnUiThread { - _updateDialog.findViewById(R.id.dialogText).text = statusMessage + _updateDialog.findViewById(R.id.dialogText).text = "${_climbingObjectUId.name} $statusMessage" } } } + override fun onUpdateError(errorMessage: String) { + _failedRegionsNames.add(errorMessage) + } + override fun onUpdateFinished(exitCode: ExitCode) { if (exitCode == ExitCode.ABORT) { _exitCode = ExitCode.ABORT @@ -76,7 +83,11 @@ class UpdateHandler(private val _activity: AppCompatActivity, _jsonParser.listener = this } - fun update(onUpdateFinished: () -> Unit = {}, isRecurring: Boolean = false, isSilent: Boolean = false) { + fun update(climbingObjectUId: ClimbingObjectUId = ClimbingObjectUId(0, ""), + onUpdateFinished: () -> Unit = {}, + isRecurring: Boolean = false, + isSilent: Boolean = false) { + _climbingObjectUId = climbingObjectUId _onUpdateFinished = onUpdateFinished _isRecurringUpdate = isRecurring _isSilentUpdate = isSilent @@ -84,7 +95,7 @@ class UpdateHandler(private val _activity: AppCompatActivity, Toast.makeText(_activity, R.string.no_internet_connection, Toast.LENGTH_LONG).show() return } - _jsonParser.fetchData() + _jsonParser.fetchData(climbingObjectUId) if (!_isSilentUpdate) { _updateDialog.show() } @@ -115,7 +126,10 @@ class UpdateHandler(private val _activity: AppCompatActivity, val finishMsgResource = when (_exitCode) { ExitCode.ABORT -> R.string.refresh_aborted - ExitCode.ERROR -> R.string.refresh_failed + ExitCode.ERROR -> { + _showErrorDialog() + R.string.refresh_failed + } else -> R.string.refresh_successful } Toast.makeText(_activity, finishMsgResource, Toast.LENGTH_SHORT).show() @@ -124,17 +138,36 @@ class UpdateHandler(private val _activity: AppCompatActivity, } _exitCode = ExitCode.SUCCESS + _failedRegionsNames.clear() } - fun configureDownloadButton(enabled: Boolean, onUpdateFinished: () -> Unit) { + fun configureDownloadButton(enabled: Boolean, climbingObjectUId: ClimbingObjectUId, onUpdateFinishedCallback: () -> Unit) { val button = _activity.findViewById(R.id.downloadButton) if (enabled) { button.visibility = View.VISIBLE button.setOnClickListener{ - update({ onUpdateFinished() }) + update( + climbingObjectUId = climbingObjectUId, + onUpdateFinished = onUpdateFinishedCallback) } } else { button.visibility = View.GONE } } + + private fun _showErrorDialog() { + val view = _activity.layoutInflater.inflate(R.layout.comment_dialog, null) + val dialog = DialogWidgetBuilder(_activity, R.string.dialog_text_failed_regions).apply { + setView(view) + setPositiveButton{ _, _ -> } + }.create() + val commentLayout = view.findViewById(R.id.commentLayout) + _failedRegionsNames.forEach { regionName -> + dialog.layoutInflater.inflate(R.layout.textview_info, commentLayout, false).let { + it.findViewById(R.id.infoTextView).text = regionName + commentLayout.addView(it) + } + } + dialog.show() + } } \ No newline at end of file diff --git a/app/src/main/java/com/yacgroup/yacguide/UpdateListener.kt b/app/src/main/java/com/yacgroup/yacguide/UpdateListener.kt index 123fb53f..fcea4777 100644 --- a/app/src/main/java/com/yacgroup/yacguide/UpdateListener.kt +++ b/app/src/main/java/com/yacgroup/yacguide/UpdateListener.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Axel Paetzold + * Copyright (C) 2019, 2023 Axel Paetzold * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,5 +22,6 @@ import com.yacgroup.yacguide.network.ExitCode interface UpdateListener { fun onUpdateStatus(statusMessage: String) + fun onUpdateError(errorMessage: String) fun onUpdateFinished(exitCode: ExitCode) } \ No newline at end of file diff --git a/app/src/main/java/com/yacgroup/yacguide/activity_properties/AscentFilterable.kt b/app/src/main/java/com/yacgroup/yacguide/activity_properties/AscentFilterable.kt index d3b6a671..f0150ac3 100644 --- a/app/src/main/java/com/yacgroup/yacguide/activity_properties/AscentFilterable.kt +++ b/app/src/main/java/com/yacgroup/yacguide/activity_properties/AscentFilterable.kt @@ -37,8 +37,8 @@ class AscentFilterable(private val _activity: TableActivityWithOptionsMenu) : Ac private fun _goToFilteredRoutesView(filterIntent: String) { val intent = Intent(_activity, RouteActivity::class.java) intent.putExtra(IntentConstants.CLIMBING_OBJECT_LEVEL, _activity.activityLevel.level.value) - intent.putExtra(IntentConstants.CLIMBING_OBJECT_PARENT_ID, _activity.activityLevel.parentId) - intent.putExtra(IntentConstants.CLIMBING_OBJECT_PARENT_NAME, _activity.activityLevel.parentName) + intent.putExtra(IntentConstants.CLIMBING_OBJECT_PARENT_ID, _activity.activityLevel.parentUId.id) + intent.putExtra(IntentConstants.CLIMBING_OBJECT_PARENT_NAME, _activity.activityLevel.parentUId.name) intent.putExtra(filterIntent, true) _activity.startActivity(intent) } diff --git a/app/src/main/java/com/yacgroup/yacguide/activity_properties/RockSearchable.kt b/app/src/main/java/com/yacgroup/yacguide/activity_properties/RockSearchable.kt index cc24828b..96b2a415 100644 --- a/app/src/main/java/com/yacgroup/yacguide/activity_properties/RockSearchable.kt +++ b/app/src/main/java/com/yacgroup/yacguide/activity_properties/RockSearchable.kt @@ -49,8 +49,8 @@ class RockSearchable(private val _activity: TableActivityWithOptionsMenu) : Acti } else { _activity.startActivity(Intent(_activity, RockActivity::class.java).apply { putExtra(IntentConstants.CLIMBING_OBJECT_LEVEL, _activity.activityLevel.level.value) - putExtra(IntentConstants.CLIMBING_OBJECT_PARENT_ID, _activity.activityLevel.parentId) - putExtra(IntentConstants.CLIMBING_OBJECT_PARENT_NAME, _activity.activityLevel.parentName) + putExtra(IntentConstants.CLIMBING_OBJECT_PARENT_ID, _activity.activityLevel.parentUId.id) + putExtra(IntentConstants.CLIMBING_OBJECT_PARENT_NAME, _activity.activityLevel.parentUId.name) putExtra(IntentConstants.FILTER_NAME, rockName) putExtra(IntentConstants.FILTER_RELEVANCE, _maxRelevanceId) }) diff --git a/app/src/main/java/com/yacgroup/yacguide/activity_properties/RouteSearchable.kt b/app/src/main/java/com/yacgroup/yacguide/activity_properties/RouteSearchable.kt index 25cd235d..cbcfd042 100644 --- a/app/src/main/java/com/yacgroup/yacguide/activity_properties/RouteSearchable.kt +++ b/app/src/main/java/com/yacgroup/yacguide/activity_properties/RouteSearchable.kt @@ -62,8 +62,8 @@ class RouteSearchable(private val _activity: TableActivityWithOptionsMenu) : Act } else { _activity.startActivity(Intent(_activity, RouteActivity::class.java).apply { putExtra(IntentConstants.CLIMBING_OBJECT_LEVEL, _activity.activityLevel.level.value) - putExtra(IntentConstants.CLIMBING_OBJECT_PARENT_ID, _activity.activityLevel.parentId) - putExtra(IntentConstants.CLIMBING_OBJECT_PARENT_NAME, _activity.activityLevel.parentName) + putExtra(IntentConstants.CLIMBING_OBJECT_PARENT_ID, _activity.activityLevel.parentUId.id) + putExtra(IntentConstants.CLIMBING_OBJECT_PARENT_NAME, _activity.activityLevel.parentUId.name) putExtra(IntentConstants.FILTER_NAME, routeName) putExtra(IntentConstants.FILTER_GRADE_FROM, _minGradeId) putExtra(IntentConstants.FILTER_GRADE_TO, _maxGradeId) diff --git a/app/src/main/java/com/yacgroup/yacguide/network/CountryAndRegionParser.kt b/app/src/main/java/com/yacgroup/yacguide/network/CountryAndRegionParser.kt index 7ee86b82..746072ae 100644 --- a/app/src/main/java/com/yacgroup/yacguide/network/CountryAndRegionParser.kt +++ b/app/src/main/java/com/yacgroup/yacguide/network/CountryAndRegionParser.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019, 2022 Axel Paetzold + * Copyright (C) 2019, 2022, 2023 Axel Paetzold * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,6 +17,7 @@ package com.yacgroup.yacguide.network +import com.yacgroup.yacguide.ClimbingObjectUId import com.yacgroup.yacguide.database.Country import com.yacgroup.yacguide.database.DatabaseWrapper import com.yacgroup.yacguide.database.Region @@ -33,19 +34,20 @@ class CountryAndRegionParser(private val _db: DatabaseWrapper) : JSONWebParser() private val _countries = mutableListOf() private val _regions = mutableListOf() - override fun initNetworkRequests() { + override fun initNetworkRequests(climbingObjectUId: ClimbingObjectUId) { networkRequests = LinkedList(listOf( NetworkRequest( - NetworkRequestUId(RequestType.COUNTRY_DATA, 0), - "${baseUrl}jsonland.php?app=yacguide") + uid = climbingObjectUId, + type = RequestType.COUNTRY_DATA, + url = "${baseUrl}jsonland.php?app=yacguide") )) } @Throws(JSONException::class) - override fun parseData(requestId: NetworkRequestUId, json: String) { - when (requestId.type) { + override fun parseData(request: NetworkRequest, json: String) { + when (request.type) { RequestType.COUNTRY_DATA -> _parseCountries(json) - RequestType.REGION_DATA -> _parseRegions(json, requestId.name) + RequestType.REGION_DATA -> _parseRegions(json, request.uid.name) else -> throw RuntimeException("Invalid request type") } } @@ -63,10 +65,11 @@ class CountryAndRegionParser(private val _db: DatabaseWrapper) : JSONWebParser() private fun _requestRegions(countryName: String) { val request = NetworkRequest( - NetworkRequestUId(RequestType.REGION_DATA, 0, countryName), - "${baseUrl}jsongebiet.php?app=yacguide&land=${NetworkUtils.encodeString2Url(countryName)}") + uid = ClimbingObjectUId(0, countryName), + type = RequestType.REGION_DATA, + url = "${baseUrl}jsongebiet.php?app=yacguide&land=${NetworkUtils.encodeString2Url(countryName)}") networkRequests.add(request) - NetworkTask(request.requestId, this).execute(request.url) + NetworkTask(request, this).execute() } private fun _parseRegions(json: String, countryName: String) { diff --git a/app/src/main/java/com/yacgroup/yacguide/network/JSONWebParser.kt b/app/src/main/java/com/yacgroup/yacguide/network/JSONWebParser.kt index e38a85ce..18f1a863 100644 --- a/app/src/main/java/com/yacgroup/yacguide/network/JSONWebParser.kt +++ b/app/src/main/java/com/yacgroup/yacguide/network/JSONWebParser.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019, 2022 Axel Paetzold + * Copyright (C) 2019, 2022, 2023 Axel Paetzold * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,6 +17,7 @@ package com.yacgroup.yacguide.network +import com.yacgroup.yacguide.ClimbingObjectUId import com.yacgroup.yacguide.UpdateListener import com.yacgroup.yacguide.utils.ParserUtils @@ -35,39 +36,42 @@ abstract class JSONWebParser : NetworkListener { var listener: UpdateListener? = null protected val baseUrl = "http://db-sandsteinklettern.gipfelbuch.de/" protected var networkRequests: LinkedList = LinkedList() + private var _climbingObjectUId: ClimbingObjectUId = ClimbingObjectUId(0, "") private var _exitCode: ExitCode = ExitCode.SUCCESS private var _processedRequestsCount: Int = 0 - override fun onNetworkTaskResolved(requestId: NetworkRequestUId, result: String) { - if (_exitCode == ExitCode.SUCCESS) { - try { - if (result.equals("null", ignoreCase = true)) { - // sandsteinklettern.de returns "null" string if there are no elements - throw IllegalArgumentException("") - } - // remove HTML-encoded characters - parseData( - requestId, + override fun onNetworkTaskResolved(request: NetworkRequest, result: String) { + when (_exitCode) { + ExitCode.ABORT -> return + ExitCode.ERROR -> _exitOnFinalTask() + ExitCode.SUCCESS -> { + try { + if (result.equals("null", ignoreCase = true)) { + // sandsteinklettern.de returns "null" string if there are no elements + throw IllegalArgumentException("") + } + // remove HTML-encoded characters + parseData( + request, ParserUtils.resolveToUtf8(result) - ) - } catch (e: JSONException) { - _exitCode = ExitCode.ERROR - onFinalTaskResolved(_exitCode) - return - } catch (e: IllegalArgumentException) { - } - if (++_processedRequestsCount == networkRequests.size) { - onFinalTaskResolved(_exitCode) + ) + } catch (e: JSONException) { + _exitCode = ExitCode.ERROR + listener?.onUpdateError(_climbingObjectUId.name) + } catch (e: IllegalArgumentException) { + } + _exitOnFinalTask() } } } - fun fetchData() { + fun fetchData(climbingObjectUId: ClimbingObjectUId) { + _climbingObjectUId = climbingObjectUId _exitCode = ExitCode.SUCCESS _processedRequestsCount = 0 - initNetworkRequests() + initNetworkRequests(climbingObjectUId) networkRequests.forEach { - NetworkTask(it.requestId, this).execute(it.url) + NetworkTask(it, this).execute() } } @@ -77,12 +81,17 @@ abstract class JSONWebParser : NetworkListener { } @Throws(JSONException::class) - protected abstract fun parseData(requestId: NetworkRequestUId, json: String) + protected abstract fun parseData(request: NetworkRequest, json: String) - protected abstract fun initNetworkRequests() + protected abstract fun initNetworkRequests(climbingObjectUId: ClimbingObjectUId) - // NetworkListener protected open fun onFinalTaskResolved(exitCode: ExitCode) { listener?.onUpdateFinished(exitCode) } + + private fun _exitOnFinalTask() { + if (++_processedRequestsCount == networkRequests.size) { + onFinalTaskResolved(_exitCode) + } + } } diff --git a/app/src/main/java/com/yacgroup/yacguide/network/NetworkListener.kt b/app/src/main/java/com/yacgroup/yacguide/network/NetworkListener.kt index 0c7d4d35..bdcef1f9 100644 --- a/app/src/main/java/com/yacgroup/yacguide/network/NetworkListener.kt +++ b/app/src/main/java/com/yacgroup/yacguide/network/NetworkListener.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Fabian Kantereit + * Copyright (C) 2019, 2023 Axel Paetzold * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,6 +19,6 @@ package com.yacgroup.yacguide.network interface NetworkListener { - fun onNetworkTaskResolved(requestId: NetworkRequestUId, result: String) + fun onNetworkTaskResolved(request: NetworkRequest, result: String) } diff --git a/app/src/main/java/com/yacgroup/yacguide/network/NetworkRequest.kt b/app/src/main/java/com/yacgroup/yacguide/network/NetworkRequest.kt index c55204da..7e6e09c4 100644 --- a/app/src/main/java/com/yacgroup/yacguide/network/NetworkRequest.kt +++ b/app/src/main/java/com/yacgroup/yacguide/network/NetworkRequest.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Fabian Kantereit + * Copyright (C) 2019, 2023 Axel Paetzold * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,4 +17,20 @@ package com.yacgroup.yacguide.network -class NetworkRequest(val requestId: NetworkRequestUId, val url: String) +import com.yacgroup.yacguide.ClimbingObjectUId + +enum class RequestType { + COUNTRY_DATA, + REGION_DATA, + SECTOR_DATA, + ROCK_DATA, + ROUTE_DATA, + REGION_COMMENTS, + SECTOR_COMMENTS +} + +class NetworkRequest( + val uid: ClimbingObjectUId, + val type: RequestType, + val url: String +) diff --git a/app/src/main/java/com/yacgroup/yacguide/network/NetworkRequestUId.kt b/app/src/main/java/com/yacgroup/yacguide/network/NetworkRequestUId.kt deleted file mode 100644 index 149571a9..00000000 --- a/app/src/main/java/com/yacgroup/yacguide/network/NetworkRequestUId.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2019 Fabian Kantereit - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.yacgroup.yacguide.network - -enum class RequestType { - COUNTRY_DATA, - REGION_DATA, - SECTOR_DATA, - ROCK_DATA, - ROUTE_DATA, - REGION_COMMENTS, - SECTOR_COMMENTS -} - -class NetworkRequestUId(val type: RequestType, val id: Int, val name: String = "") diff --git a/app/src/main/java/com/yacgroup/yacguide/network/NetworkTask.kt b/app/src/main/java/com/yacgroup/yacguide/network/NetworkTask.kt index e624be36..1fc14e9f 100644 --- a/app/src/main/java/com/yacgroup/yacguide/network/NetworkTask.kt +++ b/app/src/main/java/com/yacgroup/yacguide/network/NetworkTask.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019, 2022 Axel Paetzold + * Copyright (C) 2019, 2022, 2023 Axel Paetzold * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,19 +27,19 @@ import java.net.HttpURLConnection import java.net.URL import kotlin.coroutines.CoroutineContext -class NetworkTask(private val _requestId: NetworkRequestUId, +class NetworkTask(private val _request: NetworkRequest, private val _listener: NetworkListener) : CoroutineScope { override val coroutineContext: CoroutineContext get() = Dispatchers.Main - fun execute(url: String) = launch { - val result = _doInBackground(url) - _onPostExecute(result) + fun execute() = launch { + val result = _performNetworkRequest() + _listener.onNetworkTaskResolved(_request, result) } - private suspend fun _doInBackground(url: String): String = withContext(Dispatchers.IO) { - val connection = URL(url).openConnection() as HttpURLConnection + private suspend fun _performNetworkRequest(): String = withContext(Dispatchers.IO) { + val connection = URL(_request.url).openConnection() as HttpURLConnection return@withContext try { connection.inputStream.bufferedReader().readText() @@ -50,8 +50,4 @@ class NetworkTask(private val _requestId: NetworkRequestUId, connection.disconnect() } } - - private fun _onPostExecute(result: String) { - _listener.onNetworkTaskResolved(_requestId, result) - } } diff --git a/app/src/main/java/com/yacgroup/yacguide/network/SectorParser.kt b/app/src/main/java/com/yacgroup/yacguide/network/SectorParser.kt index 274a49bb..347f2577 100644 --- a/app/src/main/java/com/yacgroup/yacguide/network/SectorParser.kt +++ b/app/src/main/java/com/yacgroup/yacguide/network/SectorParser.kt @@ -17,6 +17,7 @@ package com.yacgroup.yacguide.network +import com.yacgroup.yacguide.ClimbingObjectUId import com.yacgroup.yacguide.database.* import com.yacgroup.yacguide.database.comment.RegionComment import com.yacgroup.yacguide.database.comment.RockComment @@ -31,9 +32,7 @@ import java.lang.RuntimeException import java.util.* import kotlin.jvm.Throws -class SectorParser(private val _db: DatabaseWrapper, - private var _regionId: Int, - private var _regionName: String = "") : JSONWebParser() { +class SectorParser(private val _db: DatabaseWrapper) : JSONWebParser() { private val _CLIMBING_OBJECT_TYPES = object : HashSet() { init { @@ -54,27 +53,30 @@ class SectorParser(private val _db: DatabaseWrapper, private val _sectorComments = mutableListOf() private val _rockComments = mutableListOf() private val _routeComments = mutableListOf() - + private var _regionId: Int = 0 private var _sectorCount: Int = 0 private var _parsedSectorCount: Int = 0 - override fun initNetworkRequests() { + override fun initNetworkRequests(climbingObjectUId: ClimbingObjectUId) { + _regionId = climbingObjectUId.id networkRequests = LinkedList(listOf( NetworkRequest( - NetworkRequestUId(RequestType.SECTOR_DATA, 0), - "${baseUrl}jsonteilgebiet.php?app=yacguide&gebietid=$_regionId"), + uid = climbingObjectUId, + type = RequestType.SECTOR_DATA, + url = "${baseUrl}jsonteilgebiet.php?app=yacguide&gebietid=$_regionId"), NetworkRequest( - NetworkRequestUId(RequestType.REGION_COMMENTS, 0), - "${baseUrl}jsonkomment.php?app=yacguide&gebietid=$_regionId") + uid = climbingObjectUId, + type = RequestType.REGION_COMMENTS, + url = "${baseUrl}jsonkomment.php?app=yacguide&gebietid=$_regionId") )) } @Throws(JSONException::class) - override fun parseData(requestId: NetworkRequestUId, json: String) { - when (requestId.type) { + override fun parseData(request: NetworkRequest, json: String) { + when (request.type) { RequestType.SECTOR_DATA -> _parseSectors(json) RequestType.REGION_COMMENTS -> _parseRegionComments(json) - RequestType.ROCK_DATA -> _parseRocks(json, requestId.id) + RequestType.ROCK_DATA -> _parseRocks(json, request.uid.id) RequestType.ROUTE_DATA -> _parseRoutes(json) RequestType.SECTOR_COMMENTS -> _parseComments(json) else -> throw RuntimeException("Invalid request type") @@ -108,32 +110,24 @@ class SectorParser(private val _db: DatabaseWrapper, super.onFinalTaskResolved(exitCode) } - fun setRegionId(id: Int) { - _regionId = id - } - - fun setRegionName(name: String) { - _regionName = name - } - @Throws(JSONException::class) private fun _parseSectors(json: String) { val jsonSectors = JSONArray(json) _sectorCount = jsonSectors.length() _parsedSectorCount = 0 - listener?.onUpdateStatus("$_regionName 0 %") + listener?.onUpdateStatus("0 %") for (i in 0 until jsonSectors.length()) { val jsonSector = jsonSectors.getJSONObject(i) val firstName = ParserUtils.replaceUnderscores(jsonSector.getString("sektorname_d")) val secondName = ParserUtils.replaceUnderscores(jsonSector.getString("sektorname_cz")) - val s = Sector( + val sector = Sector( id = ParserUtils.jsonField2Int(jsonSector, "sektor_ID"), name = ParserUtils.encodeObjectNames(firstName, secondName), nr = ParserUtils.jsonField2Float(jsonSector, "sektornr"), parentId = _regionId ) - _sectors.add(s) - _requestRocks(s.id) + _sectors.add(sector) + _requestRocks(ClimbingObjectUId(sector.id, sector.name.orEmpty())) } } @@ -153,21 +147,24 @@ class SectorParser(private val _db: DatabaseWrapper, } } - private fun _requestRocks(sectorId: Int) { + private fun _requestRocks(sectorUId: ClimbingObjectUId) { val requests = listOf( NetworkRequest( - NetworkRequestUId(RequestType.ROCK_DATA, sectorId), - "${baseUrl}jsongipfel.php?app=yacguide&sektorid=$sectorId"), + uid = sectorUId, + type = RequestType.ROCK_DATA, + url = "${baseUrl}jsongipfel.php?app=yacguide&sektorid=${sectorUId.id}"), NetworkRequest( - NetworkRequestUId(RequestType.ROUTE_DATA, sectorId), - "${baseUrl}jsonwege.php?app=yacguide&sektorid=$sectorId"), + uid = sectorUId, + type = RequestType.ROUTE_DATA, + url = "${baseUrl}jsonwege.php?app=yacguide&sektorid=${sectorUId.id}"), NetworkRequest( - NetworkRequestUId(RequestType.SECTOR_COMMENTS, sectorId), - "${baseUrl}jsonkomment.php?app=yacguide&sektorid=$sectorId") + uid = sectorUId, + type = RequestType.SECTOR_COMMENTS, + url = "${baseUrl}jsonkomment.php?app=yacguide&sektorid=${sectorUId.id}") ) networkRequests.addAll(requests) requests.forEach { - NetworkTask(it.requestId, this).execute(it.url) + NetworkTask(it, this).execute() } } @@ -226,7 +223,7 @@ class SectorParser(private val _db: DatabaseWrapper, ) _routes.add(route) } - listener?.onUpdateStatus("$_regionName ${ (100 * (++_parsedSectorCount)) / _sectorCount } %") + listener?.onUpdateStatus("${ (100 * (++_parsedSectorCount)) / _sectorCount } %") } @Throws(JSONException::class) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a047f991..c13adb15 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -68,6 +68,7 @@ Wähle eine Email-App. + Aktualisierung fehlgeschlagen für Kletterpartner löschen? Kletterpartner hinzufügen Kletterpartner ändern @@ -113,6 +114,7 @@ Land nicht gepinnt + Länder und Gebiete Teilgebiet Felsen Weg