Skip to content

Commit

Permalink
feat:Graph Add filters based on Giulia view PIDs selections
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski committed May 31, 2024
1 parent f7c22d3 commit b617d2c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 6 deletions.
24 changes: 23 additions & 1 deletion app/src/main/java/org/obd/graphs/activity/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.obd.graphs.activity

import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.util.Log
import android.view.MenuItem
import androidx.core.os.bundleOf
import androidx.core.view.GravityCompat
Expand Down Expand Up @@ -146,7 +147,9 @@ internal fun MainActivity.setupNavigationBar() {
it.menu.findItem(R.id.ctx_menu_view_custom_action_1).isVisible = true
it.menu.findItem(R.id.ctx_menu_view_custom_action_1).title =
resources.getString(R.string.pref_graph_trips_selected)
}

it.menu.findItem(R.id.ctx_menu_submenu_filters).isVisible = true
}

resources.getString(R.string.navigation_title_giulia) -> {
it.menu.findItem(R.id.ctx_menu_view_custom_action_1).isVisible = true
Expand All @@ -156,6 +159,8 @@ internal fun MainActivity.setupNavigationBar() {

else -> {
it.menu.findItem(R.id.ctx_menu_view_custom_action_1).isVisible = false
it.menu.findItem(R.id.ctx_menu_submenu_filters).isVisible = false

}
}
}
Expand Down Expand Up @@ -184,6 +189,14 @@ internal fun MainActivity.setupNavigationBarButtons() {
}
}

R.id.ctx_menu_submenu_filters_filter_1 -> applyGraphViewFilter(1)
R.id.ctx_menu_submenu_filters_filter_2 -> applyGraphViewFilter(2)
R.id.ctx_menu_submenu_filters_filter_3 -> applyGraphViewFilter(3)
R.id.ctx_menu_submenu_filters_filter_4 -> applyGraphViewFilter(4)
R.id.ctx_menu_submenu_filters_filter_5 -> applyGraphViewFilter(5)
R.id.ctx_menu_submenu_filters_filter_6 -> applyGraphViewFilter(6)
R.id.ctx_menu_submenu_filters_filter_7 -> applyGraphViewFilter(7)

R.id.ctx_menu_pids_to_display -> {
val screenId = when (getCurrentScreenId()) {
R.id.navigation_gauge -> PREF_GAUGE_DISPLAYED_PARAMETERS_IDS
Expand Down Expand Up @@ -238,6 +251,15 @@ internal fun MainActivity.setupNavigationBarButtons() {
}
}

private fun applyGraphViewFilter(screenId: Int) {
Log.e("EEEEEEEEEEE", "EEEEEEEEEEEEEEEEEE $screenId")

tripVirtualScreenManager.updateReservedVirtualScreen(Prefs.getStringSet(giuliaVirtualScreen.getVirtualScreenPrefKey("$screenId")).toList())
tripVirtualScreenManager.updateScreenId()

navigateToScreen(R.id.navigation_graph)
}

private fun MainActivity.getCurrentScreenId(): Int {
val bottomNavigationView: BottomNavigationView = findViewById(R.id.bottom_nav_view)
val selectedItemId: Int = bottomNavigationView.selectedItemId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const val PREF_GAUGE_DIALOG = "pref.giulia.pids.selected"
class GiuliaVirtualScreenPreferences {
fun getCurrentVirtualScreen() = Prefs.getString(VIRTUAL_SCREEN_SELECTION, "1")!!

fun getVirtualScreenPrefKey(): String = "$PREF_GAUGE_DIALOG.${getCurrentVirtualScreen()}"
fun getVirtualScreenPrefKey(default: String = getCurrentVirtualScreen()): String = "$PREF_GAUGE_DIALOG.${default}"


fun updateVirtualScreen(screenId: String) {
Prefs.updateString(VIRTUAL_SCREEN_SELECTION, screenId)
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/res/menu/context_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,43 @@
android:id="@+id/ctx_menu_view_custom_action_1"
android:title="@string/context_menu.custom_action_1" />

<item
android:id="@+id/ctx_menu_submenu_filters"
android:title="@string/graph_view.filters_based_on_giulia_screen">
<menu>
<item
android:id="@+id/ctx_menu_submenu_filters_filter_1"
android:title="@string/graph_view.filters_filter_1"/>

<item
android:id="@+id/ctx_menu_submenu_filters_filter_2"
android:title="@string/graph_view.filters_filter_2"/>

<item
android:id="@+id/ctx_menu_submenu_filters_filter_3"
android:title="@string/graph_view.filters_filter_3"/>

<item
android:id="@+id/ctx_menu_submenu_filters_filter_4"
android:title="@string/graph_view.filters_filter_4"/>

<item
android:id="@+id/ctx_menu_submenu_filters_filter_5"
android:title="@string/graph_view.filters_filter_5"/>

<item
android:id="@+id/ctx_menu_submenu_filters_filter_6"
android:title="@string/graph_view.filters_filter_6"/>

<item
android:id="@+id/ctx_menu_submenu_filters_filter_7"
android:title="@string/graph_view.filters_filter_7"/>

</menu>

</item>


<item
android:id="@+id/ctx_menu_about"
android:title="@string/context_menu.about" />
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,15 @@
<string name="graph_view.virtual_screen_4">4</string>
<string name="graph_view.virtual_screen_5">5</string>
<string name="graph_view.virtual_screen_reserved">Reserved</string>
<string name="graph_view.filters_based_on_giulia_screen">Filters (from Giulia screen)</string>
<string name="graph_view.filters_filter_1">Filter 1</string>
<string name="graph_view.filters_filter_2">Filter 2</string>
<string name="graph_view.filters_filter_3">Filter 3</string>
<string name="graph_view.filters_filter_4">Filter 4</string>
<string name="graph_view.filters_filter_5">Filter 5</string>
<string name="graph_view.filters_filter_6">Filter 6</string>
<string name="graph_view.filters_filter_7">Filter 7</string>


<string-array name="pref.numbers_1_20">
<item name="0">0</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,13 @@ const val RESERVED_SCREEN_ID = "6"
class TripVirtualScreenManager {
fun getCurrentScreenId() = Prefs.getString(VIRTUAL_SCREEN_SELECTION, "1")!!

fun updateScreenId(screenId: String) {
Prefs.updateString(VIRTUAL_SCREEN_SELECTION, screenId)
}
fun updateScreenId(screenId: String = getCurrentScreenId()) = Prefs.updateString(VIRTUAL_SCREEN_SELECTION, screenId)

fun getCurrentMetrics(): Set<String> =
Prefs.getStringSet(getVirtualScreenPrefKey(), mutableSetOf())!!

fun updateReservedVirtualScreen(metrics: List<String>) {
Prefs.updateStringSet("$PREF_GRAPH_DIALOG.$RESERVED_SCREEN_ID",metrics)

}
fun getVirtualScreenPrefKey(): String = "$PREF_GRAPH_DIALOG.${getCurrentScreenId()}"
}
Expand Down

0 comments on commit b617d2c

Please sign in to comment.