Skip to content

Commit

Permalink
Adding option to reset settings
Browse files Browse the repository at this point in the history
  • Loading branch information
philips77 committed Sep 12, 2022
1 parent ad346a4 commit 75ca982
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class DfuAnalytics @Inject constructor(
AppOpenEvent,
HandleDeepLinkEvent,
InstallationStartedEvent,
ResetSettingsEvent,
DFUAbortedEvent,
DFUSuccessEvent -> analytics.logEvent(event.eventName)
is DFUErrorEvent -> analytics.logEvent(event.eventName, event.createBundle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ object HandleDeepLinkEvent : DfuEvent {
override val eventName: String = "HANDLE_DEEP_LINK_EVENT"
}

object ResetSettingsEvent: DfuEvent {
override val eventName: String = "SETTINGS_RESET"
}

sealed interface DFUResultEvent : DfuEvent

object DFUSuccessEvent : DFUResultEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Backup
import androidx.compose.material.icons.outlined.Restore
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material.icons.outlined.SettingsBackupRestore
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
Expand All @@ -50,6 +55,7 @@ import no.nordicsemi.android.common.analytics.view.AnalyticsPermissionSwitch
import no.nordicsemi.android.common.theme.view.NordicAppBar
import no.nordicsemi.android.dfu.BuildConfig.VERSION_NAME
import no.nordicsemi.android.dfu.profile.R
import no.nordicsemi.android.dfu.profile.main.view.OnSettingsButtonClick
import no.nordicsemi.android.dfu.profile.settings.viewmodel.SettingsViewModel

@Composable
Expand All @@ -70,6 +76,14 @@ internal fun SettingsScreen() {
NordicAppBar(
text = stringResource(R.string.dfu_settings),
onNavigationButtonClick = { onEvent(NavigateUp) },
actions = {
IconButton(onClick = { onEvent(OnResetButtonClick) }) {
Icon(
imageVector = Icons.Outlined.SettingsBackupRestore,
contentDescription = stringResource(id = R.string.dfu_settings_reset)
)
}
}
)

// Scrollable Column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

package no.nordicsemi.android.dfu.profile.settings.view

import no.nordicsemi.android.dfu.profile.main.view.DFUViewEvent

sealed interface SettingsScreenViewEvent

object OnPacketsReceiptNotificationSwitchClick : SettingsScreenViewEvent
Expand All @@ -56,3 +58,5 @@ object OnAboutDfuClick : SettingsScreenViewEvent
object OnAboutAppClick : SettingsScreenViewEvent

object NavigateUp : SettingsScreenViewEvent

object OnResetButtonClick : SettingsScreenViewEvent
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class SettingsViewModel @Inject constructor(
fun onEvent(event: SettingsScreenViewEvent) {
when (event) {
NavigateUp -> navigationManager.navigateUp()
OnResetButtonClick -> restoreDefaultSettings()
OnAboutAppClick -> navigationManager.navigateTo(DfuWelcomeScreen)
OnAboutDfuClick -> navigationManager.openLink(INFOCENTER_LINK)
OnExternalMcuDfuSwitchClick -> onExternalMcuDfuSwitchClick()
Expand All @@ -73,6 +74,13 @@ class SettingsViewModel @Inject constructor(
}
}

private fun restoreDefaultSettings() {
viewModelScope.launch {
repository.storeSettings(DFUSettings().copy(showWelcomeScreen = false))
}
analytics.logEvent(ResetSettingsEvent)
}

private fun onExternalMcuDfuSwitchClick() {
val currentValue = state.value.externalMcuDfu
val newSettings = state.value.copy(externalMcuDfu = !currentValue)
Expand Down
1 change: 1 addition & 0 deletions profile_dfu/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<string name="dfu_settings_action">Open settings screen.</string>

<string name="dfu_navigate_up">Navigate up</string>
<string name="dfu_settings_reset">Restore default values</string>
<string name="dfu_settings">Settings</string>
<string name="dfu_settings_other">Other</string>
<string name="dfu_settings_force_scanning">Force scanning</string>
Expand Down

0 comments on commit 75ca982

Please sign in to comment.