Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/4879-darkmode-switch-in-login-pa…
Browse files Browse the repository at this point in the history
…ge' into 4879-darkmode-switch-in-login-page
  • Loading branch information
Avinash-Codes committed Dec 17, 2024
2 parents ff036e2 + ac8f733 commit 9603c23
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions app/src/main/java/org/ole/planet/myplanet/ui/SettingActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ class SettingActivity : AppCompatActivity() {

companion object {
fun darkMode(context: Context) {
val options = arrayOf(context.getString(R.string.dark_mode_off),
context.getString(R.string.dark_mode_on),context.getString(R.string.dark_mode_follow_system))
val options = arrayOf(context.getString(R.string.dark_mode_off), context.getString(R.string.dark_mode_on),context.getString(R.string.dark_mode_follow_system))
val currentMode = getCurrentThemeMode(context)
val checkedItem = when (currentMode) {
ThemeMode.LIGHT -> 0
Expand All @@ -283,13 +282,7 @@ context.getString(R.string.dark_mode_on),context.getString(R.string.dark_mode_fo

val builder = AlertDialog.Builder(context, R.style.CustomAlertDialogStyle)
.setTitle(context.getString(R.string.select_theme_mode))
.setSingleChoiceItems(
ArrayAdapter(
context,
R.layout.checked_list_item,
options
), checkedItem
) { dialog, which ->
.setSingleChoiceItems(ArrayAdapter(context, R.layout.checked_list_item, options), checkedItem) { dialog, which ->
val selectedMode = when (which) {
0 -> ThemeMode.LIGHT
1 -> ThemeMode.DARK
Expand All @@ -304,15 +297,13 @@ context.getString(R.string.dark_mode_on),context.getString(R.string.dark_mode_fo
val dialog = builder.create()
dialog.show()

// Set the dialog window size
val window = dialog.window
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
}

private fun getCurrentThemeMode(context: Context): String {
val sharedPreferences = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE)
return sharedPreferences.getString("theme_mode", ThemeMode.FOLLOW_SYSTEM)
?: ThemeMode.FOLLOW_SYSTEM
return sharedPreferences.getString("theme_mode", ThemeMode.FOLLOW_SYSTEM) ?: ThemeMode.FOLLOW_SYSTEM
}

private fun setThemeMode(context: Context, themeMode: String) {
Expand Down

0 comments on commit 9603c23

Please sign in to comment.