add battery filter
This commit is contained in:
parent
dcf6580a95
commit
d3356f4794
|
|
@ -4,16 +4,15 @@
|
|||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="jbr-17" />
|
||||
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveExternalAnnotations" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ android {
|
|||
applicationId "llc.arma.ble"
|
||||
minSdk 26
|
||||
targetSdk 33
|
||||
versionCode 13
|
||||
versionName "1.2.13"
|
||||
versionCode 14
|
||||
versionName "1.2.14"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,10 @@ class BleListContract {
|
|||
val rssi: ClosedFloatingPointRange<Float>
|
||||
) : Event()
|
||||
|
||||
data class OnBatteryRangeChanged(
|
||||
val battery: ClosedFloatingPointRange<Float>
|
||||
) : Event()
|
||||
|
||||
data class OnMacFilterChanged(
|
||||
val mac: String
|
||||
) : Event()
|
||||
|
|
@ -48,6 +52,7 @@ class BleListContract {
|
|||
data class Filter(
|
||||
val name: String = "",
|
||||
val mac: String = "",
|
||||
val battery: ClosedFloatingPointRange<Float> = (0f)..(100f),
|
||||
val rssi: ClosedFloatingPointRange<Float> = (-100f)..(-10f),
|
||||
val bleType: BleInfo.Type? = null
|
||||
)
|
||||
|
|
|
|||
|
|
@ -126,7 +126,8 @@ fun BleListScreen(
|
|||
(it.type == state.filter.bleType || state.filter.bleType == null) &&
|
||||
it.name.contains(state.filter.name) &&
|
||||
it.serial.contains(state.filter.mac) &&
|
||||
state.filter.rssi.contains(it.rssi?.toFloat() ?: Float.MIN_VALUE)
|
||||
state.filter.rssi.contains(it.rssi?.toFloat() ?: Float.MIN_VALUE) &&
|
||||
state.filter.battery.contains(it.batteryLevel.toFloat())
|
||||
}
|
||||
|
||||
if(filteredData.isEmpty()){
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ class BleListViewModel @Inject constructor(
|
|||
is BleListContract.Event.OnRssiRangeChanged -> reduce(viewState.value, event)
|
||||
is BleListContract.Event.OnShowFilter -> reduce(viewState.value, event)
|
||||
is BleListContract.Event.OnTypeChanged -> reduce(viewState.value, event)
|
||||
is BleListContract.Event.OnBatteryRangeChanged -> reduce(viewState.value, event)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -125,6 +126,17 @@ class BleListViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: BleListContract.State,
|
||||
event: BleListContract.Event.OnBatteryRangeChanged
|
||||
) {
|
||||
setState {
|
||||
copy(
|
||||
filter = this.filter.copy(battery = event.battery)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: BleListContract.State,
|
||||
event: BleListContract.Event.OnTypeChanged
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.height
|
|||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.BatteryFull
|
||||
import androidx.compose.material.icons.rounded.Bluetooth
|
||||
import androidx.compose.material.icons.rounded.Close
|
||||
import androidx.compose.material.icons.rounded.Search
|
||||
|
|
@ -266,6 +267,49 @@ fun Filter(
|
|||
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.padding(end = 8.dp)
|
||||
) {
|
||||
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.BatteryFull,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.padding(12.dp)
|
||||
)
|
||||
|
||||
Column() {
|
||||
|
||||
RangeSlider(
|
||||
value = filter.rssi,
|
||||
onValueChange = {
|
||||
onEvent(BleListContract.Event.OnRssiRangeChanged(it))
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 99,
|
||||
colors = SliderDefaults.colors(
|
||||
activeTickColor = MaterialTheme.colorScheme.primary,
|
||||
inactiveTickColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.38f)
|
||||
)
|
||||
)
|
||||
|
||||
Row {
|
||||
|
||||
Text(text = "0 %")
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
Text(text = "100 %")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
Box(
|
||||
|
|
|
|||
Loading…
Reference in New Issue