Skip to content

Commit

Permalink
Save selected sorting type
Browse files Browse the repository at this point in the history
  • Loading branch information
Semper-Viventem committed Apr 25, 2024
1 parent 8ea2bdf commit b5ba7e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ class SettingsRepository(
return silentModeState
}

fun getCurrentBatchSortingStrategyId(): Int {
return sharedPreferences.getInt(KEY_CURRENT_BATCH_SORTING_STRATEGY_ID, 0)
}

fun setCurrentBatchSortingStrategyId(value: Int) {
sharedPreferences.edit().putInt(KEY_CURRENT_BATCH_SORTING_STRATEGY_ID, value).apply()
}

companion object {
private const val KEY_GARBAGING_TIME = "key_garbaging_time"
private const val KEY_USE_GPS_ONLY = "key_use_gps_location_only"
Expand All @@ -90,6 +98,7 @@ class SettingsRepository(
private const val KEY_ENJOY_THE_APP_ANSWERED = "key_enjoy_the_app_answered_v1"
private const val KEY_ENJOY_THE_APP_STARTING_POINT = "key_enjoy_the_app_starting_point"
private const val KEY_SILENT_NETWORK_MODE = "silent_network_mode"
private const val KEY_CURRENT_BATCH_SORTING_STRATEGY_ID = "key_current_batch_sorting_strategy_id"

const val NO_APP_LAUNCH_TIME = -1L
const val NO_ENJOY_THE_APP_STARTING_POINT = -1L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DeviceListViewModel(
private val intentHelper: IntentHelper,
) : ViewModel() {

var currentBatchSortingStrategy by mutableStateOf(CurrentBatchSortingStrategy.GENERAL)
var currentBatchSortingStrategy by mutableStateOf(getDefaultSortStrategy())
var devicesViewState by mutableStateOf(emptyList<DeviceData>())
var activeScannerExpandedState by mutableStateOf(ActiveScannerExpandedState.COLLAPSED)
var currentBatchViewState by mutableStateOf<List<DeviceData>?>(null)
Expand Down Expand Up @@ -153,6 +153,7 @@ class DeviceListViewModel(

fun applyCurrentBatchSortingStrategy(strategy: CurrentBatchSortingStrategy) {
currentBatchSortingStrategy = strategy
settingsRepository.setCurrentBatchSortingStrategyId(strategy.ordinal)
currentBatchViewState = currentBatchViewState?.sortedWith(strategy.comparator)
}

Expand Down Expand Up @@ -304,6 +305,11 @@ class DeviceListViewModel(
}
}

private fun getDefaultSortStrategy(): CurrentBatchSortingStrategy {
val id = settingsRepository.getCurrentBatchSortingStrategyId()
return CurrentBatchSortingStrategy.entries.getOrElse(id) { CurrentBatchSortingStrategy.GENERAL }
}

data class FilterHolder(
val displayName: String,
val filter: RadarProfile.Filter,
Expand Down

0 comments on commit b5ba7e1

Please sign in to comment.