Skip to content

Commit 867af66

Browse files
Merge pull request #254 from Semper-Viventem/master
* Improve deep analysis acknowledgment
2 parents 8b6d735 + dcb1556 commit 867af66

File tree

6 files changed

+95
-16
lines changed

6 files changed

+95
-16
lines changed

.idea/vcs.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ android {
2626
minSdk = 29
2727
targetSdk = 36
2828

29-
versionCode = 1708536380
30-
versionName = "0.32.0-beta"
29+
versionCode = 1708536381
30+
versionName = "0.32.1-beta"
3131

3232
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3333

app/src/main/java/f/cking/software/data/repo/SettingsRepository.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class SettingsRepository(
1313

1414
private val silentModeState = MutableStateFlow(getSilentMode())
1515
private val hideBackgroundLocationWarning = MutableStateFlow(getHideBackgroundLocationWarning())
16+
private val enableDeepAnalysisState = MutableStateFlow(false)
1617

1718
fun setGarbagingTime(time: Long) {
1819
sharedPreferences.edit().putLong(KEY_GARBAGING_TIME, time).apply()
@@ -105,11 +106,13 @@ class SettingsRepository(
105106
}
106107

107108
fun setEnableDeepAnalysis(value: Boolean) {
108-
sharedPreferences.edit { putBoolean(KEY_ENABLE_DEEP_ANALYSIS, value) }
109+
enableDeepAnalysisState.value = value
110+
//sharedPreferences.edit { putBoolean(KEY_ENABLE_DEEP_ANALYSIS, value) }
109111
}
110112

111113
fun getEnableDeepAnalysis(): Boolean {
112-
return sharedPreferences.getBoolean(KEY_ENABLE_DEEP_ANALYSIS, false)
114+
return enableDeepAnalysisState.value
115+
//return sharedPreferences.getBoolean(KEY_ENABLE_DEEP_ANALYSIS, false)
113116
}
114117

115118
fun setDisclaimerWasAccepted(value: Boolean) {
@@ -147,7 +150,7 @@ class SettingsRepository(
147150
private const val KEY_SILENT_NETWORK_MODE = "silent_network_mode"
148151
private const val KEY_CURRENT_BATCH_SORTING_STRATEGY_ID = "key_current_batch_sorting_strategy_id"
149152
private const val KEY_HIDE_BACKGROUND_LOCATION_WARNING = "key_hide_background_location_warning"
150-
private const val KEY_ENABLE_DEEP_ANALYSIS = "key_enable_deep_analysis"
153+
private const val KEY_ENABLE_DEEP_ANALYSIS = "key_enable_deep_analysis_v2"
151154
private const val KEY_DISCLAIMER_WAS_ACCEPTED = "key_disclaimer_was_accepted"
152155
private const val KEY_WHAT_IS_THIS_APP_FOR_WAS_SHOWN = "what_is_this_app_for_was_shown"
153156
private const val KEY_WAKE_UP_SCREEN_WHILE_SCANNING = "key_wake_up_screen_while_scanning"

app/src/main/java/f/cking/software/ui/settings/SettingsScreen.kt

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import f.cking.software.utils.graphic.FABSpacer
3838
import f.cking.software.utils.graphic.RoundedBox
3939
import f.cking.software.utils.graphic.Switcher
4040
import f.cking.software.utils.graphic.ThemedDialog
41+
import f.cking.software.utils.graphic.agreementDialog
4142
import org.koin.androidx.compose.koinViewModel
4243

4344
object SettingsScreen {
@@ -288,17 +289,46 @@ object SettingsScreen {
288289
subtitle = null,
289290
onClick = { viewModel.setRunOnStartup() }
290291
)
292+
293+
val deepAnalysisDialog = agreementDialog(
294+
title = stringResource(R.string.deep_analysis_warning_title),
295+
content = stringResource(R.string.deep_analysis_warning_text),
296+
agreement = stringResource(R.string.deep_analysis_agreement_text),
297+
buttons = { state ->
298+
{
299+
negativeButton(
300+
stringResource(R.string.deep_analysis_decline),
301+
textStyle = TextStyle(color = MaterialTheme.colorScheme.onSurface)
302+
) { state.hide() }
303+
positiveButton(
304+
stringResource(R.string.deep_analysis_enable),
305+
textStyle = TextStyle(color = MaterialTheme.colorScheme.onSurface)
306+
) {
307+
state.hide()
308+
viewModel.onEnableDeepAnalysisClick()
309+
}
310+
}
311+
}
312+
)
291313
Switcher(
292314
value = viewModel.deepAnalysisEnabled,
293315
title = stringResource(R.string.enable_deep_analysis),
294316
subtitle = stringResource(R.string.enable_deep_analysis_description),
295-
onClick = { viewModel.onEnableDeepAnalysisClick() }
317+
onClick = {
318+
if (viewModel.deepAnalysisEnabled) {
319+
viewModel.onEnableDeepAnalysisClick()
320+
} else {
321+
deepAnalysisDialog.show()
322+
}
323+
}
296324
)
297325
Switcher(
298326
value = viewModel.wakeUpWhileScanning,
299327
title = stringResource(R.string.settings_keep_screen_on_while_scanning_title),
300328
subtitle = stringResource(R.string.settings_keep_screen_on_while_scanning_description),
301-
onClick = { viewModel.toggleWakeUpOnScreen() }
329+
onClick = {
330+
viewModel.toggleWakeUpOnScreen()
331+
}
302332
)
303333
}
304334
}

app/src/main/java/f/cking/software/utils/graphic/ComposeFunctions.kt

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import androidx.compose.material.icons.filled.Star
3030
import androidx.compose.material.icons.outlined.Info
3131
import androidx.compose.material3.AssistChip
3232
import androidx.compose.material3.AssistChipDefaults
33+
import androidx.compose.material3.Checkbox
3334
import androidx.compose.material3.CircularProgressIndicator
3435
import androidx.compose.material3.ColorScheme
3536
import androidx.compose.material3.Icon
@@ -214,6 +215,41 @@ fun infoDialog(
214215
return dialogState
215216
}
216217

218+
@Composable
219+
fun agreementDialog(
220+
title: String,
221+
content: String,
222+
agreement: String,
223+
buttons: ((state: MaterialDialogState) -> (@Composable MaterialDialogButtons.() -> Unit)),
224+
): MaterialDialogState {
225+
val dialogState = rememberMaterialDialogState()
226+
ThemedDialog(
227+
dialogState = dialogState,
228+
buttons = buttons.invoke(dialogState),
229+
) {
230+
var agreed: Boolean by remember { mutableStateOf(false) }
231+
positiveButtonEnabled[0] = agreed
232+
Column(modifier = Modifier.padding(16.dp)) {
233+
Text(text = title, fontWeight = FontWeight.Bold)
234+
Spacer(modifier = Modifier.height(8.dp))
235+
Text(text = content)
236+
Spacer(modifier = Modifier.height(8.dp))
237+
val agreedClick = {
238+
agreed = !agreed
239+
positiveButtonEnabled[0] = agreed
240+
}
241+
Row(Modifier.clickable(onClick = agreedClick), verticalAlignment = Alignment.CenterVertically) {
242+
Checkbox(
243+
checked = agreed,
244+
onCheckedChange = { agreedClick.invoke() }
245+
)
246+
Text(text = agreement)
247+
}
248+
}
249+
}
250+
return dialogState
251+
}
252+
217253
@Composable
218254
fun ThemedDialog(
219255
dialogState: MaterialDialogState = rememberMaterialDialogState(),
@@ -286,7 +322,9 @@ fun DeviceListItem(
286322
.clickable { onClick.invoke() },
287323
) {
288324
Row(
289-
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp)
325+
modifier = Modifier
326+
.fillMaxWidth()
327+
.padding(horizontal = 16.dp, vertical = 8.dp)
290328
) {
291329
DeviceTypeIcon(
292330
modifier = Modifier.size(64.dp),
@@ -374,7 +412,8 @@ fun DevicePairedIcon(isPaired: Boolean, extended: Boolean = false) {
374412
content = null,
375413
)
376414
Row(
377-
modifier = Modifier.background(color.copy(0.2f), RoundedCornerShape(20.dp))
415+
modifier = Modifier
416+
.background(color.copy(0.2f), RoundedCornerShape(20.dp))
378417
.clickable { infoDialog.show() },
379418
verticalAlignment = Alignment.CenterVertically,
380419
) {
@@ -407,7 +446,8 @@ fun DeviceTypeIcon(
407446
val icon = remember(device) { GetIconForDeviceClass.getIcon(device) }
408447
val color = colorByHash(device.address.hashCode())
409448
Icon(
410-
modifier = modifier.background(color.copy(0.2f), CircleShape)
449+
modifier = modifier
450+
.background(color.copy(0.2f), CircleShape)
411451
.padding(paddingDp),
412452
painter = painterResource(icon),
413453
contentDescription = stringResource(R.string.device_type),
@@ -696,9 +736,10 @@ fun Switcher(
696736
subtitle: String?,
697737
onClick: () -> Unit,
698738
) {
699-
Box(modifier = modifier
700-
.fillMaxWidth()
701-
.clickable { onClick.invoke() }
739+
Box(
740+
modifier = modifier
741+
.fillMaxWidth()
742+
.clickable { onClick.invoke() }
702743
) {
703744
Row(
704745
modifier = Modifier

app/src/main/res/values/strings.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,13 @@
106106
<string name="database_locations_count">Location records: %s</string>
107107
<string name="app_settings_title">App settings</string>
108108
<string name="silent_mode_is_off_toast">Offline mode is turned off. You can change it in the settings.</string>
109-
<string name="enable_deep_analysis">Deep analysis</string>
110-
<string name="enable_deep_analysis_description">Enabling deep analysis for all found devices will provide more data for each scan, but increase scan time and power consumption.</string>
109+
<string name="enable_deep_analysis">Deep analysis (Experimental)</string>
110+
<string name="enable_deep_analysis_description">If Deep Analysis is enabled, the app will request more information from all found devices. It will provide more data for each scan, but will also increase scan time and power consumption and may disclose your presence.</string>
111+
<string name="deep_analysis_warning_title">Enable Deep Analysis? (EXPERIMENTAL)</string>
112+
<string name="deep_analysis_warning_text">Deep Analysis does not only scan for BLE devices. It also actively requests data from their accessible GATT services.\n\nSome devices may require authentication or encryption to access certain services. In such cases, this may trigger a pairing request.\n\nThis mode may also make your device more visible to nearby devices.\n\nOnly enable this feature if you understand how it works and accept these side effects.</string>
113+
<string name="deep_analysis_agreement_text">I know what I\'m doing</string>
114+
<string name="deep_analysis_decline">Cancel</string>
115+
<string name="deep_analysis_enable">Enable</string>
111116

112117
<!-- Select manufacturer -->
113118
<string name="select_manufacturer">Search manufacturer</string>

0 commit comments

Comments
 (0)