Skip to content

Commit

Permalink
ADS: Settings Screen migration (#2590)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1203411647299661/f

Migrate Settings screen and small section to new components

- Main Settings menu
- Theme Dialog
- App Icon Screen
- Fire Button Animation Dialog
- Automatically Clear... Dialog
- Clear On... Dialog
- Open Links in Apps Dialog
- DuckSuckGo Desktop App Screen
- About DuckDuckGo Screen

- Install from this branch
- Go to Settings
- [ ] Check settings menu, dialogs and screens mention in description
look as expected

| Before  | After |
| ------ | ----- |

![Screenshot_20221130-181442_DuckDuckGo](https://user-images.githubusercontent.com/20798495/204876902-c02e41a3-6ff4-40a9-9b04-82cf8206b2d6.jpg)|![Screenshot_20221130-181455_DuckDuckGo](https://user-images.githubusercontent.com/20798495/204876842-55c26244-32c1-4c54-adb6-7572b8862d90.jpg)|

Co-authored-by: David González <malmstein@gmail.com>
  • Loading branch information
2 people authored and aitorvs committed Dec 19, 2022
1 parent 73f85b6 commit 006e9cd
Show file tree
Hide file tree
Showing 28 changed files with 444 additions and 1,097 deletions.
20 changes: 12 additions & 8 deletions app/src/main/java/com/duckduckgo/app/icon/ui/ChangeIconActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ package com.duckduckgo.app.icon.ui
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.GridLayoutManager
import com.duckduckgo.anvil.annotations.InjectWith
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.browser.databinding.ActivityAppIconsBinding
import com.duckduckgo.app.global.DuckDuckGoActivity
import com.duckduckgo.di.scopes.ActivityScope
import com.duckduckgo.mobile.android.R as CommonR
import com.duckduckgo.mobile.android.ui.view.dialog.TextAlertDialogBuilder
import com.duckduckgo.mobile.android.ui.viewbinding.viewBinding

@InjectWith(ActivityScope::class)
Expand Down Expand Up @@ -79,16 +79,20 @@ class ChangeIconActivity : DuckDuckGoActivity() {
is ChangeIconViewModel.Command.IconChanged -> {
finish()
}

is ChangeIconViewModel.Command.ShowConfirmationDialog -> {
AlertDialog.Builder(this)
TextAlertDialogBuilder(this)
.setTitle(R.string.changeIconDialogTitle)
.setMessage(getString(R.string.changeIconDialogMessage))
.setPositiveButton(R.string.changeIconCtaAccept) { _, _ ->
viewModel.onIconConfirmed(it.viewData)
}
.setNegativeButton(R.string.changeIconCtaCancel) { dialog, _ ->
dialog.dismiss()
}
.setPositiveButton(R.string.changeIconCtaAccept)
.setNegativeButton(R.string.changeIconCtaCancel)
.addEventListener(
object : TextAlertDialogBuilder.EventListener() {
override fun onPositiveButtonClicked() {
viewModel.onIconConfirmed(it.viewData)
}
},
)
.show()
}
}
Expand Down
186 changes: 142 additions & 44 deletions app/src/main/java/com/duckduckgo/app/settings/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ import com.duckduckgo.app.pixels.AppPixelName
import com.duckduckgo.app.privacy.ui.WhitelistActivity
import com.duckduckgo.app.settings.SettingsViewModel.AutomaticallyClearData
import com.duckduckgo.app.settings.SettingsViewModel.Command
import com.duckduckgo.app.settings.clear.AppLinkSettingType
import com.duckduckgo.app.settings.clear.ClearWhatOption
import com.duckduckgo.app.settings.clear.ClearWhenOption
import com.duckduckgo.app.settings.clear.FireAnimation
import com.duckduckgo.app.settings.clear.FireAnimation.HeroAbstract.getAnimationForIndex
import com.duckduckgo.app.settings.clear.FireAnimation.None
import com.duckduckgo.app.settings.clear.getAppLinkSettingForIndex
import com.duckduckgo.app.settings.clear.getClearWhatOptionForIndex
import com.duckduckgo.app.settings.clear.getClearWhenForIndex
import com.duckduckgo.app.settings.extension.InternalFeaturePlugin
import com.duckduckgo.app.sitepermissions.SitePermissionsActivity
import com.duckduckgo.app.statistics.pixels.Pixel
Expand All @@ -65,7 +71,11 @@ import com.duckduckgo.autofill.ui.AutofillSettingsActivityLauncher
import com.duckduckgo.di.scopes.ActivityScope
import com.duckduckgo.macos_impl.MacOsActivity
import com.duckduckgo.mobile.android.ui.DuckDuckGoTheme
import com.duckduckgo.mobile.android.ui.DuckDuckGoTheme.DARK
import com.duckduckgo.mobile.android.ui.DuckDuckGoTheme.LIGHT
import com.duckduckgo.mobile.android.ui.DuckDuckGoTheme.SYSTEM_DEFAULT
import com.duckduckgo.mobile.android.ui.sendThemeChangedBroadcast
import com.duckduckgo.mobile.android.ui.view.dialog.RadioListAlertDialogBuilder
import com.duckduckgo.mobile.android.ui.view.listitem.TwoLineListItem
import com.duckduckgo.mobile.android.ui.viewbinding.viewBinding
import com.duckduckgo.mobile.android.vpn.ui.onboarding.VpnOnboardingActivity
Expand All @@ -77,13 +87,7 @@ import kotlinx.coroutines.flow.onEach
import timber.log.Timber

@InjectWith(ActivityScope::class)
class SettingsActivity :
DuckDuckGoActivity(),
SettingsAutomaticallyClearWhatFragment.Listener,
SettingsAutomaticallyClearWhenFragment.Listener,
SettingsThemeSelectorFragment.Listener,
SettingsAppLinksSelectorFragment.Listener,
SettingsFireAnimationSelectorFragment.Listener {
class SettingsActivity : DuckDuckGoActivity() {

private val viewModel: SettingsViewModel by bindViewModel()
private val binding: ActivitySettingsBinding by viewBinding()
Expand Down Expand Up @@ -294,9 +298,9 @@ class SettingsActivity :
private fun updateSelectedTheme(selectedTheme: DuckDuckGoTheme) {
val subtitle = getString(
when (selectedTheme) {
DuckDuckGoTheme.DARK -> R.string.settingsDarkTheme
DuckDuckGoTheme.LIGHT -> R.string.settingsLightTheme
DuckDuckGoTheme.SYSTEM_DEFAULT -> R.string.settingsSystemTheme
DARK -> R.string.settingsDarkTheme
LIGHT -> R.string.settingsLightTheme
SYSTEM_DEFAULT -> R.string.settingsSystemTheme
},
)
viewsAppearance.selectedThemeSetting.setSecondaryText(subtitle)
Expand Down Expand Up @@ -325,14 +329,58 @@ class SettingsActivity :
}

private fun launchAutomaticallyClearWhatDialog(option: ClearWhatOption) {
val dialog = SettingsAutomaticallyClearWhatFragment.create(option)
dialog.show(supportFragmentManager, CLEAR_WHAT_DIALOG_TAG)
val currentOption = option.getOptionIndex()
RadioListAlertDialogBuilder(this)
.setTitle(R.string.settingsAutomaticallyClearWhatDialogTitle)
.setOptions(
listOf(
R.string.settingsAutomaticallyClearWhatOptionNone,
R.string.settingsAutomaticallyClearWhatOptionTabs,
R.string.settingsAutomaticallyClearWhatOptionTabsAndData,
),
currentOption,
)
.setPositiveButton(R.string.settingsAutomaticallyClearingDialogSave)
.setNegativeButton(R.string.cancel)
.addEventListener(
object : RadioListAlertDialogBuilder.EventListener() {
override fun onPositiveButtonClicked(selectedItem: Int) {
val clearWhatSelected = selectedItem.getClearWhatOptionForIndex()
viewModel.onAutomaticallyWhatOptionSelected(clearWhatSelected)
}
},
)
.show()
pixel.fire(AppPixelName.AUTOMATIC_CLEAR_DATA_WHAT_SHOWN)
}

private fun launchAutomaticallyClearWhenDialog(option: ClearWhenOption) {
val dialog = SettingsAutomaticallyClearWhenFragment.create(option)
dialog.show(supportFragmentManager, CLEAR_WHEN_DIALOG_TAG)
val currentOption = option.getOptionIndex()
val clearWhenOptions = mutableListOf(
R.string.settingsAutomaticallyClearWhenAppExitOnly,
R.string.settingsAutomaticallyClearWhenAppExit5Minutes,
R.string.settingsAutomaticallyClearWhenAppExit15Minutes,
R.string.settingsAutomaticallyClearWhenAppExit30Minutes,
R.string.settingsAutomaticallyClearWhenAppExit60Minutes,
)
if (appBuildConfig.isDebug) {
clearWhenOptions.add(R.string.settingsAutomaticallyClearWhenAppExit5Seconds)
}
RadioListAlertDialogBuilder(this)
.setTitle(R.string.settingsAutomaticallyClearWhenDialogTitle)
.setOptions(clearWhenOptions, currentOption)
.setPositiveButton(R.string.settingsAutomaticallyClearingDialogSave)
.setNegativeButton(R.string.cancel)
.addEventListener(
object : RadioListAlertDialogBuilder.EventListener() {
override fun onPositiveButtonClicked(selectedItem: Int) {
val clearWhenSelected = selectedItem.getClearWhenForIndex()
viewModel.onAutomaticallyWhenOptionSelected(clearWhenSelected)
Timber.d("Option selected: $clearWhenSelected")
}
},
)
.show()
pixel.fire(AppPixelName.AUTOMATIC_CLEAR_DATA_WHEN_SHOWN)
}

Expand Down Expand Up @@ -443,18 +491,92 @@ class SettingsActivity :
}

private fun launchFireAnimationSelector(animation: FireAnimation) {
val dialog = SettingsFireAnimationSelectorFragment.create(animation)
dialog.show(supportFragmentManager, FIRE_ANIMATION_SELECTOR_TAG)
val currentAnimationOption = animation.getOptionIndex()

RadioListAlertDialogBuilder(this)
.setTitle(R.string.settingsSelectFireAnimationDialog)
.setOptions(
listOf(
R.string.settingsHeroFireAnimation,
R.string.settingsHeroWaterAnimation,
R.string.settingsHeroAbstractAnimation,
R.string.settingsNoneAnimation,
),
currentAnimationOption,
)
.setPositiveButton(R.string.settingsSelectFireAnimationDialogSave)
.setNegativeButton(R.string.cancel)
.addEventListener(
object : RadioListAlertDialogBuilder.EventListener() {
override fun onPositiveButtonClicked(selectedItem: Int) {
val selectedAnimation = selectedItem.getAnimationForIndex()

viewModel.onFireAnimationSelected(selectedAnimation)
}

override fun onRadioItemSelected(selectedItem: Int) {
val selectedAnimation = selectedItem.getAnimationForIndex()
if (selectedAnimation != None) {
startActivity(FireAnimationActivity.intent(baseContext, selectedAnimation))
}
}
},
)
.show()
}

private fun launchThemeSelector(theme: DuckDuckGoTheme) {
val dialog = SettingsThemeSelectorFragment.create(theme)
dialog.show(supportFragmentManager, THEME_SELECTOR_TAG)
val currentTheme = theme.getOptionIndex()
RadioListAlertDialogBuilder(this)
.setTitle(R.string.settingsTheme)
.setOptions(
listOf(
R.string.settingsSystemTheme,
R.string.settingsLightTheme,
R.string.settingsDarkTheme,
),
currentTheme,
)
.setPositiveButton(R.string.settingsThemeDialogSave)
.setNegativeButton(R.string.cancel)
.addEventListener(
object : RadioListAlertDialogBuilder.EventListener() {
override fun onPositiveButtonClicked(selectedItem: Int) {
val selectedTheme = when (selectedItem) {
2 -> LIGHT
3 -> DARK
else -> SYSTEM_DEFAULT
}
viewModel.onThemeSelected(selectedTheme)
}
},
)
.show()
}

private fun launchAppLinksSettingSelector(appLinkSettingType: AppLinkSettingType) {
val dialog = SettingsAppLinksSelectorFragment.create(appLinkSettingType)
dialog.show(supportFragmentManager, THEME_SELECTOR_TAG)
val currentAppLinkSetting = appLinkSettingType.getOptionIndex()
RadioListAlertDialogBuilder(this)
.setTitle(R.string.settingsTitleAppLinksDialog)
.setOptions(
listOf(
R.string.settingsAppLinksAskEveryTime,
R.string.settingsAppLinksAlways,
R.string.settingsAppLinksNever,
),
currentAppLinkSetting,
)
.setPositiveButton(R.string.dialogSave)
.setNegativeButton(R.string.cancel)
.addEventListener(
object : RadioListAlertDialogBuilder.EventListener() {
override fun onPositiveButtonClicked(selectedItem: Int) {
val selectedAppLinkSetting = selectedItem.getAppLinkSettingForIndex()
viewModel.onAppLinksSettingChanged(selectedAppLinkSetting)
}
},
)
.show()
}

private fun launchGlobalPrivacyControl() {
Expand Down Expand Up @@ -507,26 +629,6 @@ class SettingsActivity :
addWidgetLauncher.launchAddWidget(this)
}

override fun onThemeSelected(selectedTheme: DuckDuckGoTheme) {
viewModel.onThemeSelected(selectedTheme)
}

override fun onAppLinkSettingSelected(selectedSetting: AppLinkSettingType) {
viewModel.onAppLinksSettingChanged(selectedSetting)
}

override fun onAutomaticallyClearWhatOptionSelected(clearWhatSetting: ClearWhatOption) {
viewModel.onAutomaticallyWhatOptionSelected(clearWhatSetting)
}

override fun onAutomaticallyClearWhenOptionSelected(clearWhenSetting: ClearWhenOption) {
viewModel.onAutomaticallyWhenOptionSelected(clearWhenSetting)
}

override fun onFireAnimationSelected(selectedFireAnimation: FireAnimation) {
viewModel.onFireAnimationSelected(selectedFireAnimation)
}

@Suppress("DEPRECATION")
override fun onActivityResult(
requestCode: Int,
Expand Down Expand Up @@ -568,10 +670,6 @@ class SettingsActivity :
}

companion object {
private const val FIRE_ANIMATION_SELECTOR_TAG = "FIRE_ANIMATION_SELECTOR_DIALOG_FRAGMENT"
private const val THEME_SELECTOR_TAG = "THEME_SELECTOR_DIALOG_FRAGMENT"
private const val CLEAR_WHAT_DIALOG_TAG = "CLEAR_WHAT_DIALOG_FRAGMENT"
private const val CLEAR_WHEN_DIALOG_TAG = "CLEAR_WHEN_DIALOG_FRAGMENT"
private const val FEEDBACK_REQUEST_CODE = 100
private const val CHANGE_APP_ICON_REQUEST_CODE = 101
private const val PRIVACY_POLICY_WEB_LINK = "https://duckduckgo.com/privacy"
Expand Down

This file was deleted.

Loading

0 comments on commit 006e9cd

Please sign in to comment.