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

Added drying filter for routes #346

Merged
merged 1 commit into from
Mar 8, 2022
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: 3 additions & 3 deletions app/src/main/java/com/yacgroup/yacguide/RockActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ class RockActivity : TableActivityWithOptionsMenu() {
private var _onlyOfficialSummits: Boolean = false
private var _rockNamePart: String = ""
private var _filterName: String = ""
private var _filterMaxRelevanceId: Int = RockComment.RELEVANCE_NONE
private var _filterMaxRelevanceId: Int = RockComment.NO_INFO_ID

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

_filterName = intent.getStringExtra(IntentConstants.FILTER_NAME).orEmpty()
_filterMaxRelevanceId = intent.getIntExtra(IntentConstants.FILTER_RELEVANCE, RockComment.RELEVANCE_NONE)
_filterMaxRelevanceId = intent.getIntExtra(IntentConstants.FILTER_RELEVANCE, RockComment.NO_INFO_ID)

properties = arrayListOf(
RouteSearchable(this),
Expand Down Expand Up @@ -136,7 +136,7 @@ class RockActivity : TableActivityWithOptionsMenu() {
if (_filterName.isEmpty()) null
else rockGetter.getByName().toSet()
val relevanceFilteredRocks =
if (_filterMaxRelevanceId == RockComment.RELEVANCE_NONE) null
if (_filterMaxRelevanceId == RockComment.NO_INFO_ID) null
else rockGetter.getByRelevance().toSet()
listOfNotNull(nameFilteredRocks, relevanceFilteredRocks).reduce {
intersection, filteredRocks -> intersection.intersect(filteredRocks)
Expand Down
31 changes: 22 additions & 9 deletions app/src/main/java/com/yacgroup/yacguide/RouteActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class RouteActivity : TableActivityWithOptionsMenu() {
private var _onlyOfficialRoutes: Boolean = false
private var _routeNamePart: String = ""
private var _filterName: String = ""
private var _filterMaxQualityId: Int = RouteComment.QUALITY_NONE
private var _filterMaxProtectionId: Int = RouteComment.PROTECTION_NONE
private var _filterMaxQualityId: Int = RouteComment.NO_INFO_ID
private var _filterMaxProtectionId: Int = RouteComment.NO_INFO_ID
private var _filterMaxDryingId: Int = RouteComment.NO_INFO_ID
private var _filterProjects: Boolean = false
private var _filterBotches: Boolean = false
private var _rock: Rock? = null
Expand All @@ -53,8 +54,9 @@ class RouteActivity : TableActivityWithOptionsMenu() {
super.onCreate(savedInstanceState)

_filterName = intent.getStringExtra(IntentConstants.FILTER_NAME).orEmpty()
_filterMaxQualityId = intent.getIntExtra(IntentConstants.FILTER_RELEVANCE, RouteComment.QUALITY_NONE)
_filterMaxProtectionId = intent.getIntExtra(IntentConstants.FILTER_PROTECTION, RouteComment.PROTECTION_NONE)
_filterMaxQualityId = intent.getIntExtra(IntentConstants.FILTER_RELEVANCE, RouteComment.NO_INFO_ID)
_filterMaxProtectionId = intent.getIntExtra(IntentConstants.FILTER_PROTECTION, RouteComment.NO_INFO_ID)
_filterMaxDryingId = intent.getIntExtra(IntentConstants.FILTER_DRYING, RouteComment.NO_INFO_ID)
_filterProjects = intent.getBooleanExtra(IntentConstants.FILTER_PROJECTS, false)
_filterBotches = intent.getBooleanExtra(IntentConstants.FILTER_BOTCHES, false)

Expand All @@ -69,6 +71,7 @@ class RouteActivity : TableActivityWithOptionsMenu() {
getByName = { db.getRoutesByName(_filterName) },
getByQuality = { db.getRoutesByQuality(_filterMaxQualityId) },
getByProtection = { db.getRoutesByProtection(_filterMaxProtectionId) },
getByDrying = { db.getRoutesByDrying(_filterMaxDryingId) },
getProjects = { db.getProjectedRoutes() },
getBotches = { db.getBotchedRoutes() }
),
Expand All @@ -77,6 +80,7 @@ class RouteActivity : TableActivityWithOptionsMenu() {
getByName = { db.getRoutesByNameForCountry(activityLevel.parentName, _filterName) },
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) }
),
Expand All @@ -85,6 +89,7 @@ class RouteActivity : TableActivityWithOptionsMenu() {
getByName = { db.getRoutesByNameForRegion(activityLevel.parentId, _filterName) },
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) }
),
Expand All @@ -93,6 +98,7 @@ class RouteActivity : TableActivityWithOptionsMenu() {
getByName = { db.getRoutesByNameForSector(activityLevel.parentId, _filterName) },
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) }
),
Expand All @@ -101,6 +107,7 @@ class RouteActivity : TableActivityWithOptionsMenu() {
getByName = { db.getRoutesByNameForRock(activityLevel.parentId, _filterName) },
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) }
)
Expand Down Expand Up @@ -184,22 +191,27 @@ class RouteActivity : TableActivityWithOptionsMenu() {
} else if (_filterBotches) {
routeGetter.getBotches()
} else if (_filterName.isEmpty()
&& _filterMaxQualityId == RouteComment.QUALITY_NONE
&& _filterMaxProtectionId == RouteComment.PROTECTION_NONE) {
&& _filterMaxQualityId == RouteComment.NO_INFO_ID
&& _filterMaxProtectionId == RouteComment.NO_INFO_ID
&& _filterMaxDryingId == RouteComment.NO_INFO_ID) {
routeGetter.getAll()
} else {
val nameFilteredRoutes =
if (_filterName.isEmpty()) null
else routeGetter.getByName().toSet()
val qualityFilteredRoutes =
if (_filterMaxQualityId == RouteComment.QUALITY_NONE) null
if (_filterMaxQualityId == RouteComment.NO_INFO_ID) null
else routeGetter.getByQuality().toSet()
val protectionFilteredRoutes =
if (_filterMaxProtectionId == RouteComment.PROTECTION_NONE) null
if (_filterMaxProtectionId == RouteComment.NO_INFO_ID) null
else routeGetter.getByProtection().toSet()
val dryingFilteredRoutes =
if (_filterMaxDryingId == RouteComment.NO_INFO_ID) null
else routeGetter.getByDrying().toSet()
listOfNotNull(nameFilteredRoutes,
qualityFilteredRoutes,
protectionFilteredRoutes).reduce {
protectionFilteredRoutes,
dryingFilteredRoutes).reduce {
intersection, filteredRoutes -> intersection.intersect(filteredRoutes)
}.toList()
}
Expand Down Expand Up @@ -247,6 +259,7 @@ class RouteGetter(
val getByName: () -> List<Route>,
val getByQuality: () -> List<Route>,
val getByProtection: () -> List<Route>,
val getByDrying: () -> List<Route>,
val getProjects: () -> List<Route>,
val getBotches: () -> List<Route>
)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/yacgroup/yacguide/TableActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ abstract class TableActivity : BaseNavigationActivity() {
_addCommentPropertyView(it, R.string.route_quality, RouteComment.QUALITY_MAP, comment.qualityId)
_addCommentPropertyView(it, R.string.grade, RouteComment.GRADE_MAP, comment.gradeId)
_addCommentPropertyView(it, R.string.protection, RouteComment.PROTECTION_MAP, comment.securityId)
_addCommentPropertyView(it, R.string.drying, RouteComment.WETNESS_MAP, comment.wetnessId)
_addCommentPropertyView(it, R.string.drying, RouteComment.DRYING_MAP, comment.wetnessId)
_addCommentTextView(it, comment.text.orEmpty())
}
it.addView(WidgetUtils.createHorizontalLine(this, 1))
Expand Down Expand Up @@ -159,7 +159,7 @@ abstract class TableActivity : BaseNavigationActivity() {
}

private fun _addCommentPropertyView(layout: LinearLayout, titleRes: Int, propertyMap: Map<Int, String>, propertyKey: Int) {
if (propertyMap.containsKey(propertyKey)) {
if (propertyMap.containsKey(propertyKey) && propertyKey > RouteComment.NO_INFO_ID) {
_addCommentTextView(layout, getString(titleRes), propertyMap[propertyKey].orEmpty())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import com.yacgroup.yacguide.utils.FilterSpinnerListener

class RockSearchable(private val _activity: TableActivityWithOptionsMenu) : ActivityProperty, FilterSpinnerListener {

private var _maxRelevanceId: Int = RockComment.RELEVANCE_NONE
private var _maxRelevanceId: Int = RockComment.NO_INFO_ID

override fun getMenuGroupId() = R.id.group_rock_search

Expand All @@ -44,7 +44,7 @@ class RockSearchable(private val _activity: TableActivityWithOptionsMenu) : Acti

searchDialog.findViewById<Button>(R.id.searchButton)?.setOnClickListener {
val rockName = searchDialog.findViewById<EditText>(R.id.dialogEditText)?.text.toString().trim { it <= ' ' }
if (rockName.isEmpty() && _maxRelevanceId == RockComment.RELEVANCE_NONE) {
if (rockName.isEmpty() && _maxRelevanceId == RockComment.NO_INFO_ID) {
Toast.makeText(searchDialog.context, R.string.no_filter_selected, Toast.LENGTH_SHORT).show()
} else {
_activity.startActivity(Intent(_activity, RockActivity::class.java).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import com.yacgroup.yacguide.utils.IntentConstants

class RouteSearchable(private val _activity: TableActivityWithOptionsMenu) : ActivityProperty, FilterSpinnerListener {

private var _maxQualityId: Int = RouteComment.QUALITY_NONE
private var _maxProtectionId: Int = RouteComment.PROTECTION_NONE
private var _maxQualityId: Int = RouteComment.NO_INFO_ID
private var _maxProtectionId: Int = RouteComment.NO_INFO_ID
private var _maxDryingId: Int = RouteComment.NO_INFO_ID

override fun getMenuGroupId() = R.id.group_route_search

Expand All @@ -43,12 +44,14 @@ class RouteSearchable(private val _activity: TableActivityWithOptionsMenu) : Act

FilterSpinner(searchDialog, R.id.routeQualitySpinner, RouteComment.QUALITY_MAP, this).create()
FilterSpinner(searchDialog, R.id.routeProtectionSpinner, RouteComment.PROTECTION_MAP, this).create()
FilterSpinner(searchDialog, R.id.routeDryingSpinner, RouteComment.DRYING_MAP, this).create()

searchDialog.findViewById<Button>(R.id.searchButton)?.setOnClickListener {
val routeName = searchDialog.findViewById<EditText>(R.id.dialogEditText)?.text.toString().trim { it <= ' ' }
if (routeName.isEmpty()
&& _maxQualityId == RouteComment.QUALITY_NONE
&& _maxProtectionId == RouteComment.PROTECTION_NONE) {
&& _maxQualityId == RouteComment.NO_INFO_ID
&& _maxProtectionId == RouteComment.NO_INFO_ID
&& _maxDryingId == RouteComment.NO_INFO_ID) {
Toast.makeText(searchDialog.context, R.string.no_filter_selected, Toast.LENGTH_SHORT).show()
} else {
_activity.startActivity(Intent(_activity, RouteActivity::class.java).apply {
Expand All @@ -58,6 +61,7 @@ class RouteSearchable(private val _activity: TableActivityWithOptionsMenu) : Act
putExtra(IntentConstants.FILTER_NAME, routeName)
putExtra(IntentConstants.FILTER_RELEVANCE, _maxQualityId)
putExtra(IntentConstants.FILTER_PROTECTION, _maxProtectionId)
putExtra(IntentConstants.FILTER_DRYING, _maxDryingId)
})
searchDialog.dismiss()
}
Expand All @@ -72,6 +76,7 @@ class RouteSearchable(private val _activity: TableActivityWithOptionsMenu) : Act
when (resourceId) {
R.id.routeQualitySpinner -> _maxQualityId = selectionKey
R.id.routeProtectionSpinner -> _maxProtectionId = selectionKey
R.id.routeDryingSpinner -> _maxDryingId = selectionKey
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class DatabaseWrapper(context: Context) {

fun getRoutesByProtectionForRock(rockId: Int, maxProtectionId: Int) = _db.routeDao().getAllByProtectionAtRock(rockId, maxProtectionId)

fun getRoutesByDryingForRock(rockId: Int, maxDryingId: Int) = _db.routeDao().getAllByDryingAtRock(rockId, maxDryingId)

fun getProjectedRoutesForRock(rockId: Int) = _db.routeDao().getAllAtRockForStyle(rockId, AscendStyle.ePROJECT.id)

fun getBotchedRoutesForRock(rockId: Int) = _db.routeDao().getAllAtRockForStyle(rockId, AscendStyle.eBOTCHED.id)
Expand All @@ -109,6 +111,8 @@ class DatabaseWrapper(context: Context) {

fun getRoutesByProtectionForSector(sectorId: Int, maxProtectionId: Int) = _db.routeDao().getAllByProtectionInSector(sectorId, maxProtectionId)

fun getRoutesByDryingForSector(sectorId: Int, maxDryingId: Int) = _db.routeDao().getAllByDryingInSector(sectorId, maxDryingId)

fun getProjectedRoutesForSector(sectorId: Int) = _db.routeDao().getAllInSectorForStyle(sectorId, AscendStyle.ePROJECT.id)

fun getBotchedRoutesForSector(sectorId: Int) = _db.routeDao().getAllInSectorForStyle(sectorId, AscendStyle.eBOTCHED.id)
Expand All @@ -121,6 +125,8 @@ class DatabaseWrapper(context: Context) {

fun getRoutesByProtectionForRegion(regionId: Int, maxProtectionId: Int) = _db.routeDao().getAllByProtectionInRegion(regionId, maxProtectionId)

fun getRoutesByDryingForRegion(regionId: Int, maxDryingId: Int) = _db.routeDao().getAllByDryingInRegion(regionId, maxDryingId)

fun getProjectedRoutesForRegion(regionId: Int) = _db.routeDao().getAllInRegionForStyle(regionId, AscendStyle.ePROJECT.id)

fun getBotchedRoutesForRegion(regionId: Int) = _db.routeDao().getAllInRegionForStyle(regionId, AscendStyle.eBOTCHED.id)
Expand All @@ -133,6 +139,8 @@ class DatabaseWrapper(context: Context) {

fun getRoutesByProtectionForCountry(countryName: String, maxProtectionId: Int) = _db.routeDao().getAllByProtectionInCountry(countryName, maxProtectionId)

fun getRoutesByDryingForCountry(countryName: String, maxDryingId: Int) = _db.routeDao().getAllByDryingInCountry(countryName, maxDryingId)

fun getProjectedRoutesForCountry(countryName: String) = _db.routeDao().getAllInCountryForStyle(countryName, AscendStyle.ePROJECT.id)

fun getBotchedRoutesForCountry(countryName: String) = _db.routeDao().getAllInCountryForStyle(countryName, AscendStyle.eBOTCHED.id)
Expand All @@ -145,6 +153,8 @@ class DatabaseWrapper(context: Context) {

fun getRoutesByProtection(maxProtectionId: Int) = _db.routeDao().getAllByProtection(maxProtectionId)

fun getRoutesByDrying(maxDryingId: Int) = _db.routeDao().getAllByDrying(maxDryingId)

fun getProjectedRoutes() = _db.routeDao().getAllForStyle(AscendStyle.ePROJECT.id)

fun getBotchedRoutes() = _db.routeDao().getAllForStyle(AscendStyle.eBOTCHED.id)
Expand Down
Loading