Skip to content

Commit fe5406f

Browse files
feat(settings): Add options to clear theme and WOTD data
This commit introduces functionality to clear specific sets of user data from the "Theme Creations" and "Word of the Day" bottom sheets. Each "Clear" option prompts the user with a confirmation dialog before proceeding. The changes include: - Adding a "Clear" item to the "Theme Creations" bottom sheet, which resets all theme-related preferences and recreates the activity. - Adding a "Clear" item to the "Word of the Day" bottom sheet, which removes the custom word list and recreates the activity. - Implementing `confirmClearTheme()` and `confirmClearWOTD()` methods with corresponding `clearTheme()` and `clearWOTD()` logic in `DialogManager`. - Adding new string resources for the clear options, confirmation dialog titles, messages, and action buttons.
1 parent 12f1f77 commit fe5406f

File tree

2 files changed

+94
-21
lines changed

2 files changed

+94
-21
lines changed

app/src/main/java/com/github/codeworkscreativehub/mlauncher/ui/components/DialogManager.kt

Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import android.widget.TextView
2525
import androidx.appcompat.widget.AppCompatImageButton
2626
import androidx.core.content.ContextCompat
2727
import androidx.core.graphics.toColorInt
28-
import com.github.creativecodecat.components.views.FontBottomSheetDialogLocked
2928
import com.github.codeworkscreativehub.common.getCpuBatteryInfo
3029
import com.github.codeworkscreativehub.common.getLocalizedString
3130
import com.github.codeworkscreativehub.common.getRamInfo
@@ -42,6 +41,7 @@ import com.github.codeworkscreativehub.mlauncher.helper.themeDownloadButton
4241
import com.github.codeworkscreativehub.mlauncher.helper.utils.AppReloader
4342
import com.github.codeworkscreativehub.mlauncher.helper.wordofthedayDownloadButton
4443
import com.github.codeworkscreativehub.mlauncher.services.HapticFeedbackService
44+
import com.github.creativecodecat.components.views.FontBottomSheetDialogLocked
4545
import com.google.android.material.dialog.MaterialAlertDialogBuilder
4646

4747
class DialogManager(val context: Context, val activity: Activity) {
@@ -106,6 +106,25 @@ class DialogManager(val context: Context, val activity: Activity) {
106106
backupRestoreBottomSheet?.show() // ✅ Correct method call
107107
}
108108

109+
// Function to handle the Clear Data action, with a confirmation dialog
110+
private fun confirmClearData() {
111+
MaterialAlertDialogBuilder(context)
112+
.setTitle(getLocalizedString(R.string.advanced_settings_backup_restore_clear_title))
113+
.setMessage(getLocalizedString(R.string.advanced_settings_backup_restore_clear_description))
114+
.setPositiveButton(getLocalizedString(R.string.advanced_settings_clear_yes)) { _, _ ->
115+
clearData()
116+
}
117+
.setNegativeButton(getLocalizedString(R.string.advanced_settings_clear_no), null)
118+
.show()
119+
}
120+
121+
private fun clearData() {
122+
prefs = Prefs(context)
123+
prefs.clear()
124+
125+
AppReloader.restartApp(context)
126+
}
127+
109128
var saveLoadThemeBottomSheet: FontBottomSheetDialogLocked? = null
110129

111130
fun showSaveLoadThemeBottomSheet() {
@@ -157,13 +176,54 @@ class DialogManager(val context: Context, val activity: Activity) {
157176
(activity as MainActivity).restoreThemeBackup()
158177
})
159178

179+
// Add Clear Option
180+
layout.addView(createItem(getLocalizedString(R.string.advanced_settings_theme_clear)) {
181+
confirmClearTheme()
182+
})
183+
160184
// Create and show the LockedBottomSheetDialog
161185
saveLoadThemeBottomSheet = FontBottomSheetDialogLocked(context).apply {
162186
setContentView(layout)
163187
}
164188
saveLoadThemeBottomSheet?.show()
165189
}
166190

191+
private fun confirmClearTheme() {
192+
MaterialAlertDialogBuilder(context)
193+
.setTitle(getLocalizedString(R.string.advanced_settings_theme_clear_title))
194+
.setMessage(getLocalizedString(R.string.advanced_settings_theme_clear_description))
195+
.setPositiveButton(getLocalizedString(R.string.advanced_settings_clear_yes)) { _, _ ->
196+
clearTheme()
197+
}
198+
.setNegativeButton(getLocalizedString(R.string.advanced_settings_clear_no), null)
199+
.show()
200+
}
201+
202+
fun clearTheme() {
203+
val prefs = Prefs(context)
204+
val keys = listOf(
205+
"BACKGROUND_COLOR",
206+
"APP_COLOR",
207+
"DATE_COLOR",
208+
"ALARM_CLOCK_COLOR",
209+
"CLOCK_COLOR",
210+
"BATTERY_COLOR",
211+
"DAILY_WORD_COLOR",
212+
"NOTES_BACKGROUND_COLOR",
213+
"BUBBLE_BACKGROUND_COLOR",
214+
"BUBBLE_MESSAGE_COLOR",
215+
"BUBBLE_TIMEDATE_COLOR",
216+
"BUBBLE_CATEGORY_COLOR",
217+
"INPUT_MESSAGE_COLOR",
218+
"INPUT_MESSAGEHINT_COLOR"
219+
220+
)
221+
keys.forEach { prefs.remove(it) }
222+
if (context is Activity) {
223+
context.recreate()
224+
}
225+
}
226+
167227
var saveDownloadWOTDBottomSheet: FontBottomSheetDialogLocked? = null
168228

169229
fun showSaveDownloadWOTDBottomSheet() {
@@ -211,31 +271,35 @@ class DialogManager(val context: Context, val activity: Activity) {
211271
(activity as MainActivity).restoreWordsBackup()
212272
})
213273

274+
// Add Clear Option
275+
layout.addView(createItem(getLocalizedString(R.string.advanced_settings_wotd_clear)) {
276+
confirmClearWOTD()
277+
})
278+
214279
// Create and show the LockedBottomSheetDialog
215280
saveDownloadWOTDBottomSheet = FontBottomSheetDialogLocked(context).apply {
216281
setContentView(layout)
217282
}
218283
saveDownloadWOTDBottomSheet?.show()
219284
}
220285

221-
222-
// Function to handle the Clear Data action, with a confirmation dialog
223-
private fun confirmClearData() {
286+
private fun confirmClearWOTD() {
224287
MaterialAlertDialogBuilder(context)
225-
.setTitle(getLocalizedString(R.string.advanced_settings_backup_restore_clear_title))
226-
.setMessage(getLocalizedString(R.string.advanced_settings_backup_restore_clear_description))
227-
.setPositiveButton(getLocalizedString(R.string.advanced_settings_backup_restore_clear_yes)) { _, _ ->
228-
clearData()
288+
.setTitle(getLocalizedString(R.string.advanced_settings_wotd_clear_title))
289+
.setMessage(getLocalizedString(R.string.advanced_settings_wotd_clear_description))
290+
.setPositiveButton(getLocalizedString(R.string.advanced_settings_clear_yes)) { _, _ ->
291+
clearWOTD()
229292
}
230-
.setNegativeButton(getLocalizedString(R.string.advanced_settings_backup_restore_clear_no), null)
293+
.setNegativeButton(getLocalizedString(R.string.advanced_settings_clear_no), null)
231294
.show()
232295
}
233296

234-
private fun clearData() {
235-
prefs = Prefs(context)
236-
prefs.clear()
237-
238-
AppReloader.restartApp(context)
297+
fun clearWOTD() {
298+
val prefs = Prefs(context)
299+
prefs.remove("WORD_LIST")
300+
if (context is Activity) {
301+
context.recreate()
302+
}
239303
}
240304

241305
var sliderBottomSheet: FontBottomSheetDialogLocked? = null

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,23 +249,32 @@
249249
<string name="advanced_settings_backup_restore_restore">Restore</string>
250250
<string name="advanced_settings_backup_restore_clear">Clear All Data</string>
251251

252+
<string name="advanced_settings_backup_restore_clear_title">Clear Preferences</string>
253+
<string name="advanced_settings_backup_restore_clear_description">Are you sure you want to do this?</string>
254+
252255
<string name="advanced_settings_theme_title">Theme Creations</string>
253256
<string name="advanced_settings_theme_description">Customize themes to suit you.</string>
254257

255-
<string name="advanced_settings_wotd_title">Word of the Day</string>
256-
<string name="advanced_settings_wotd_description">Import custom Word of the Day list.</string>
257-
258258
<string name="advanced_settings_theme_download">Download</string>
259259
<string name="advanced_settings_theme_export">Export</string>
260260
<string name="advanced_settings_theme_import">Import</string>
261+
<string name="advanced_settings_theme_clear">Clear</string>
262+
263+
<string name="advanced_settings_theme_clear_title">Reset Theme</string>
264+
<string name="advanced_settings_theme_clear_description">Are you sure you want to reset all theme settings?</string>
265+
266+
<string name="advanced_settings_wotd_title">Word of the Day</string>
267+
<string name="advanced_settings_wotd_description">Import custom Word of the Day list.</string>
261268

262269
<string name="advanced_settings_wotd_download">Download</string>
263270
<string name="advanced_settings_wotd_import">Import</string>
271+
<string name="advanced_settings_wotd_clear">Clear</string>
264272

265-
<string name="advanced_settings_backup_restore_clear_title">Clear Preferences</string>
266-
<string name="advanced_settings_backup_restore_clear_description">Are you sure you want to do this?</string>
267-
<string name="advanced_settings_backup_restore_clear_yes">Yes</string>
268-
<string name="advanced_settings_backup_restore_clear_no">No</string>
273+
<string name="advanced_settings_wotd_clear_title">Reset Word Of The Day</string>
274+
<string name="advanced_settings_wotd_clear_description">Are you sure you want to reset the Word Of The Day array?</string>
275+
276+
<string name="advanced_settings_clear_yes">Yes</string>
277+
<string name="advanced_settings_clear_no">No</string>
269278

270279
<string name="advanced_settings_help_feedback_title">Help &amp; Feedback</string>
271280
<string name="advanced_settings_community_support_title">Community Support</string>

0 commit comments

Comments
 (0)