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

Introduce options menu for rock view #264

Merged
merged 1 commit into from
Nov 25, 2021
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
29 changes: 18 additions & 11 deletions app/src/main/java/com/yacgroup/yacguide/CountryActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,31 @@ import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.LinearLayout
import com.yacgroup.yacguide.activity_properties.*
import com.yacgroup.yacguide.network.CountryParser
import com.yacgroup.yacguide.utils.IntentConstants
import com.yacgroup.yacguide.utils.WidgetUtils

class CountryActivity : UpdatableTableActivity() {
class CountryActivity : TableActivityWithOptionsMenu() {

private lateinit var _updatable: Updatable

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

jsonParser = CountryParser(db, this)
val rockSearchable = RockSearchable(
this,
) { db.getRocks() }
val ascentFilterable = AscentFilterable(
this,
{ db.getProjectedRocks() },
{ db.getBotchedRocks() }
)
_updatable = Updatable(
this,
CountryParser(db)
) { db.deleteCountriesRecursively() }
properties = arrayListOf(rockSearchable, ascentFilterable, _updatable)

WhatsNewInfo(this).let {
if (it.checkForVersionUpdate()) {
Expand Down Expand Up @@ -59,15 +74,7 @@ class CountryActivity : UpdatableTableActivity() {
layout.addView(WidgetUtils.createHorizontalLine(this, 1))
}
if (countries.isEmpty()) {
displayDownloadButton()
layout.addView(_updatable.getDownloadButton())
}
}

override fun deleteContent() = db.deleteCountriesRecursively()

override fun searchRocks() = db.getRocks()

override fun searchProjects() = db.getProjectedRocks()

override fun searchBotches() = db.getBotchedRocks()
}
29 changes: 18 additions & 11 deletions app/src/main/java/com/yacgroup/yacguide/RegionActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,35 @@ import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.LinearLayout
import com.yacgroup.yacguide.activity_properties.*

import com.yacgroup.yacguide.network.RegionParser
import com.yacgroup.yacguide.utils.IntentConstants
import com.yacgroup.yacguide.utils.WidgetUtils

class RegionActivity : UpdatableTableActivity() {
class RegionActivity : TableActivityWithOptionsMenu() {

private lateinit var _countryName: String
private lateinit var _updatable: Updatable

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

_countryName = intent.getStringExtra(IntentConstants.COUNTRY_KEY).toString()
jsonParser = RegionParser(db, this, _countryName)

val rockSearchable = RockSearchable(
this
) { db.getRocksForCountry(_countryName) }
val ascentFilterable = AscentFilterable(
this,
{ db.getProjectedRocksForCountry(_countryName) },
{ db.getBotchedRocksForCountry(_countryName) }
)
_updatable = Updatable(
this,
RegionParser(db, _countryName)
) { db.deleteRegionsRecursively(_countryName) }
properties = arrayListOf(rockSearchable, ascentFilterable, _updatable)
}

override fun getLayoutId() = R.layout.activity_region
Expand All @@ -57,15 +72,7 @@ class RegionActivity : UpdatableTableActivity() {
layout.addView(WidgetUtils.createHorizontalLine(this, 1))
}
if (regions.isEmpty()) {
displayDownloadButton()
layout.addView(_updatable.getDownloadButton())
}
}

override fun deleteContent() = db.deleteRegionsRecursively(_countryName)

override fun searchRocks() = db.getRocksForCountry(_countryName)

override fun searchProjects() = db.getProjectedRocksForCountry(_countryName)

override fun searchBotches() = db.getBotchedRocksForCountry(_countryName)
}
22 changes: 16 additions & 6 deletions app/src/main/java/com/yacgroup/yacguide/RockActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import android.graphics.Typeface
import android.os.Bundle
import android.view.View
import android.widget.*
import com.yacgroup.yacguide.activity_properties.AscentFilterable
import com.yacgroup.yacguide.activity_properties.RockSearchable

import com.yacgroup.yacguide.database.comment.SectorComment
import com.yacgroup.yacguide.database.DatabaseWrapper
Expand All @@ -33,7 +35,7 @@ import com.yacgroup.yacguide.utils.ParserUtils
import com.yacgroup.yacguide.utils.SearchBarHandler
import com.yacgroup.yacguide.utils.WidgetUtils

class RockActivity : TableActivity() {
class RockActivity : TableActivityWithOptionsMenu() {

private lateinit var _sector: Sector
private lateinit var _searchBarHandler: SearchBarHandler
Expand All @@ -44,13 +46,25 @@ class RockActivity : TableActivity() {
super.onCreate(savedInstanceState)

val sectorId = intent.getIntExtra(IntentConstants.SECTOR_KEY, DatabaseWrapper.INVALID_ID)

_sector = db.getSector(sectorId)!!

val rockSearchable = RockSearchable(
this
) { db.getRocksForSector(sectorId) }
val ascentFilterable = AscentFilterable(
this,
{ db.getProjectedRocksForSector(sectorId) },
{ db.getBotchedRocksForSector(sectorId) }
)
properties = arrayListOf(rockSearchable, ascentFilterable)

_searchBarHandler = SearchBarHandler(findViewById(R.id.searchBarLayout), R.string.rock_search, R.array.rockFilters) {
rockNamePart, rockFilter -> _onSearchBarUpdate(rockNamePart, rockFilter)
}
}

override fun getLayoutId() = R.layout.activity_rock

override fun showComments(v: View) {
val comments = db.getSectorComments(_sector.id)
if (comments.isNotEmpty()) {
Expand Down Expand Up @@ -142,8 +156,4 @@ class RockActivity : TableActivity() {
&& rock.status != Rock.statusProhibited
&& rock.status != Rock.statusCollapsed
}

override fun getLayoutId(): Int {
return R.layout.activity_rock
}
}
6 changes: 2 additions & 4 deletions app/src/main/java/com/yacgroup/yacguide/RouteActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class RouteActivity : TableActivity() {
findViewById<TextView>(R.id.infoTextView).text = rockStatus
}

override fun getLayoutId() = R.layout.activity_route

@Suppress("UNUSED_PARAMETER")
fun showMap(v: View) {
try {
Expand Down Expand Up @@ -170,9 +172,5 @@ class RouteActivity : TableActivity() {
&& route.statusId != Route.STATUS_UNACKNOWLEDGED
&& route.statusId != Route.STATUS_UNFINISHED
}

override fun getLayoutId(): Int {
return R.layout.activity_route
}
}

30 changes: 18 additions & 12 deletions app/src/main/java/com/yacgroup/yacguide/SectorActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.graphics.Typeface
import android.os.Bundle
import android.view.View
import android.widget.*
import com.yacgroup.yacguide.activity_properties.*

import com.yacgroup.yacguide.database.comment.RegionComment
import com.yacgroup.yacguide.database.DatabaseWrapper
Expand All @@ -33,17 +34,30 @@ import com.yacgroup.yacguide.utils.IntentConstants
import com.yacgroup.yacguide.utils.ParserUtils
import com.yacgroup.yacguide.utils.WidgetUtils

class SectorActivity : UpdatableTableActivity() {
class SectorActivity : TableActivityWithOptionsMenu() {

private lateinit var _region: Region
private lateinit var _updatable: Updatable

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val regionId = intent.getIntExtra(IntentConstants.REGION_KEY, DatabaseWrapper.INVALID_ID)

jsonParser = SectorParser(db, this, regionId)
_region = db.getRegion(regionId)!!

val rockSearchable = RockSearchable(
this
) { db.getRocksForRegion(regionId) }
val ascentFilterable = AscentFilterable(
this,
{ db.getProjectedRocksForRegion(regionId) },
{ db.getBotchedRocksForRegion(regionId) }
)
_updatable = Updatable(
this,
SectorParser(db, regionId)
) { db.deleteSectorsRecursively(_region.id) }
properties = arrayListOf(rockSearchable, ascentFilterable, _updatable)
}

override fun getLayoutId() = R.layout.activity_sector
Expand Down Expand Up @@ -103,18 +117,10 @@ class SectorActivity : UpdatableTableActivity() {
layout.addView(WidgetUtils.createHorizontalLine(this, 1))
}
if (sectors.isEmpty()) {
displayDownloadButton()
layout.addView(_updatable.getDownloadButton())
}
}

override fun deleteContent() = db.deleteSectorsRecursively(_region.id)

override fun searchRocks() = db.getRocksForRegion(_region.id)

override fun searchProjects() = db.getProjectedRocksForRegion(_region.id)

override fun searchBotches() = db.getBotchedRocksForRegion(_region.id)

private fun _generateRockCountString(rocks: List<Rock>): String {
val countSummits = customSettings.getBoolean(getString(R.string.count_summits), resources.getBoolean(R.bool.count_summits))
val countMassifs = customSettings.getBoolean(getString(R.string.count_massifs), resources.getBoolean(R.bool.count_massifs))
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/yacgroup/yacguide/TableActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ abstract class TableActivity : BaseNavigationActivity() {
return "$botchAdd$projectAdd$watchingAdd"
}

protected abstract fun displayContent()
abstract fun displayContent()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2019 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
* 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 <https://www.gnu.org/licenses/>.
*/

package com.yacgroup.yacguide

import android.annotation.SuppressLint
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.view.menu.MenuBuilder
import androidx.core.view.MenuCompat
import com.yacgroup.yacguide.activity_properties.ActivityProperty

abstract class TableActivityWithOptionsMenu : TableActivity() {

protected lateinit var properties: ArrayList<ActivityProperty>

@SuppressLint("RestrictedApi")
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.options_menu, menu)
properties.map { menu.setGroupVisible(it.getMenuGroupId(), true) }
MenuCompat.setGroupDividerEnabled(menu, true);
if (menu is MenuBuilder) {
menu.setOptionalIconsVisible(true)
}
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
for (prop in properties) {
if (item.groupId == prop.getMenuGroupId()) {
prop.onMenuAction(item.itemId)
break
}
}
return true
}
}
Loading