Skip to content

Commit

Permalink
Merge pull request #132 from Semper-Viventem/support-regex-for-radar-…
Browse files Browse the repository at this point in the history
…filters

Support regex for address filter and save a sorting type
  • Loading branch information
Semper-Viventem authored Apr 25, 2024
2 parents f40a1bd + 5a371ae commit 27221dd
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
minSdk = 29
targetSdk = 34

versionCode = 1708536351
versionName = "0.24.1-beta"
versionCode = 1708536352
versionName = "0.25.0-beta"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
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 @@ -29,7 +29,7 @@ class FilterCheckerImpl(
device.name != null && device.name.contains(filter.name, filter.ignoreCase)
}
private val address = filterChecker<RadarProfile.Filter.Address>(useCache = true) { device, filter ->
device.address == filter.address
device.address.contains(filter.address.toRegex())
}
private val manufacturer = filterChecker<RadarProfile.Filter.Manufacturer>(useCache = true) { device, filter ->
device.manufacturerInfo?.id?.let { it == filter.manufacturerId } ?: false
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
12 changes: 10 additions & 2 deletions app/src/main/java/f/cking/software/ui/filter/FilterScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Clear
Expand All @@ -37,6 +38,7 @@ import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.vanpra.composematerialdialogs.rememberMaterialDialogState
Expand Down Expand Up @@ -249,13 +251,19 @@ object FilterScreen {
color = colorResource(R.color.filter_address),
onDeleteButtonClick = { onDeleteClick.invoke(filter) }
) {
Spacer(modifier = Modifier.height(4.dp))
Row {
TextField(
modifier = Modifier.weight(1f),
value = filter.address,
singleLine = true,
onValueChange = { filter.address = it.uppercase() },
placeholder = { Text(text = "00:00:00:00:00:00") }
label = { Text(text = stringResource(R.string.filter_by_address_disclaimer)) },
onValueChange = { filter.address = it },
placeholder = { Text(text = "00:00:00:00:00:00") },
keyboardOptions = KeyboardOptions.Default.copy(
capitalization = KeyboardCapitalization.Characters,
autoCorrect = false,
),
)
Spacer(modifier = Modifier.width(4.dp))
IconButton(onClick = {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<string name="select_filter">Выбор фильтра</string>
<string name="filter_by_name">По имени</string>
<string name="filter_by_address">По адресу</string>
<string name="filter_by_address_disclaimer">Адрес устройства или регулярное выражение</string>
<string name="filter_by_first_detection_period">По периоду первого обнаружения</string>
<string name="filter_by_last_detection_period">По периоду последнего обнаружения</string>
<string name="filter_by_is_favorite">По флагу избранное</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<string name="filter_by_name">By name</string>
<string name="filter_by_name_description">Triggers when the device name matches</string>
<string name="filter_by_address">By address</string>
<string name="filter_by_address_disclaimer">The device address or a regex</string>
<string name="filter_by_address_description">Triggers when the device address matches</string>
<string name="filter_by_first_detection_period">By first detection period</string>
<string name="filter_by_first_detection_period_description">Triggers if the found device was first time detected in the selected period</string>
Expand Down

0 comments on commit 27221dd

Please sign in to comment.