Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show failed regions on update error #391

Merged
merged 3 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/src/main/java/com/yacgroup/yacguide/ClimbingObject.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -32,4 +32,6 @@ enum class ClimbingObjectLevel(val value: Int) {
}
}

class ClimbingObject(val level: ClimbingObjectLevel, val parentId: Int, val parentName: String)
class ClimbingObjectUId(val id: Int, val name: String)

class ClimbingObject(val level: ClimbingObjectLevel, val parentUId: ClimbingObjectUId)
5 changes: 4 additions & 1 deletion app/src/main/java/com/yacgroup/yacguide/CountryActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<TextView>(R.id.infoTextView).text =
"${getString(R.string.route_restricted)} ${Route.STATUS[_route.statusId]}"
Expand All @@ -55,7 +55,7 @@ class DescriptionActivity : TableActivity() {
}

override fun showComments(v: View) {
showRouteComments(activityLevel.parentId)
showRouteComments(activityLevel.parentUId.id)
}

@Suppress("UNUSED_PARAMETER")
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/yacgroup/yacguide/LaunchActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/yacgroup/yacguide/RegionActivity.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
10 changes: 4 additions & 6 deletions app/src/main/java/com/yacgroup/yacguide/RegionManagerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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(
Expand Down Expand Up @@ -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()) },
Expand All @@ -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) {
Expand Down
26 changes: 13 additions & 13 deletions app/src/main/java/com/yacgroup/yacguide/RockActivity.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) }
)
)

Expand All @@ -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()
Expand Down
76 changes: 38 additions & 38 deletions app/src/main/java/com/yacgroup/yacguide/RouteActivity.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) }
)
)

Expand All @@ -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<ImageButton>(R.id.mapButton).visibility = View.INVISIBLE
}
Expand Down Expand Up @@ -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))

Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/com/yacgroup/yacguide/SectorActivity.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -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) {
Expand Down
Loading