diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/DarkThemeDialog.kt b/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/DarkThemeDialog.kt new file mode 100644 index 000000000..0c62622df --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/DarkThemeDialog.kt @@ -0,0 +1,50 @@ +package com.topjohnwu.magisk.model.events.dialog + +import android.app.Activity +import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.app.AppCompatDelegate +import com.topjohnwu.magisk.Config +import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.model.events.ActivityExecutor +import com.topjohnwu.magisk.view.MagiskDialog +import java.lang.ref.WeakReference + +class DarkThemeDialog : DialogEvent(), ActivityExecutor { + + private var activity: WeakReference? = null + + override fun invoke(activity: AppCompatActivity) { + this.activity = WeakReference(activity) + } + + override fun build(dialog: MagiskDialog) { + dialog.applyTitle(R.string.settings_dark_mode_title) + .applyMessage(R.string.settings_dark_mode_message) + .applyButton(MagiskDialog.ButtonType.POSITIVE) { + titleRes = R.string.settings_dark_mode_light + icon = R.drawable.ic_day + onClick { selectTheme(AppCompatDelegate.MODE_NIGHT_NO) } + } + .applyButton(MagiskDialog.ButtonType.NEUTRAL) { + titleRes = R.string.settings_dark_mode_system + icon = R.drawable.ic_day_night + onClick { selectTheme(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) } + } + .applyButton(MagiskDialog.ButtonType.NEGATIVE) { + titleRes = R.string.settings_dark_mode_dark + icon = R.drawable.ic_night + onClick { selectTheme(AppCompatDelegate.MODE_NIGHT_YES) } + } + .onDismiss { + activity?.clear() + activity = null + } + } + + private fun selectTheme(mode: Int) { + Config.darkThemeExtended = mode + activity?.get()?.recreate() + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsViewModel.kt index 0014b8cd8..dca920e12 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsViewModel.kt @@ -4,14 +4,13 @@ import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.extensions.addOnPropertyChangedCallback import com.topjohnwu.magisk.extensions.toggle import com.topjohnwu.magisk.model.events.DieEvent -import com.topjohnwu.magisk.model.events.RecreateEvent +import com.topjohnwu.magisk.model.events.dialog.DarkThemeDialog import com.topjohnwu.magisk.redesign.compat.CompatViewModel import com.topjohnwu.magisk.utils.KObservableField class SettingsViewModel : CompatViewModel() { val redesign = KObservableField(Config.redesign) - val darkTheme = KObservableField(Config.darkTheme) init { //todo make observable preference @@ -19,12 +18,9 @@ class SettingsViewModel : CompatViewModel() { Config.redesign = redesign.value DieEvent().publish() } - darkTheme.addOnPropertyChangedCallback { - Config.darkTheme = darkTheme.value - RecreateEvent().publish() - } } fun toggle(item: KObservableField) = item.toggle() + fun darkModePressed() = DarkThemeDialog().publish() } \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_day.xml b/app/src/main/res/drawable/ic_day.xml new file mode 100644 index 000000000..2899017da --- /dev/null +++ b/app/src/main/res/drawable/ic_day.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_day_night.xml b/app/src/main/res/drawable/ic_day_night.xml new file mode 100644 index 000000000..8452fab77 --- /dev/null +++ b/app/src/main/res/drawable/ic_day_night.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_night.xml b/app/src/main/res/drawable/ic_night.xml new file mode 100644 index 000000000..c31bd0593 --- /dev/null +++ b/app/src/main/res/drawable/ic_night.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_settings_md2.xml b/app/src/main/res/layout/fragment_settings_md2.xml index d989ef96c..ace4a82b3 100644 --- a/app/src/main/res/layout/fragment_settings_md2.xml +++ b/app/src/main/res/layout/fragment_settings_md2.xml @@ -18,7 +18,8 @@ android:fillViewport="true" android:paddingTop="@{viewModel.insets.top + (int) @dimen/internal_action_bar_size + (int) @dimen/l2}" android:paddingBottom="@{viewModel.insets.bottom + (int) @dimen/l2}" - tools:layout_marginTop="24dp"> + tools:layout_marginTop="24dp" + tools:paddingTop="@dimen/l1"> - + android:orientation="vertical"> + + + + + android:background="@null" + android:gravity="start|center_vertical" + android:singleLine="true" + android:text="@string/settings_dark_mode_title" + android:textAppearance="?appearanceTextBodyNormal" + android:textStyle="bold" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/settings_card_dark_pointer" + app:layout_constraintStart_toEndOf="@+id/settings_card_dark_icon" + app:layout_constraintTop_toTopOf="parent" /> - - - + @@ -65,10 +84,9 @@ style="?styleCardNormal" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginLeft="@dimen/l2" - android:layout_marginTop="@dimen/l1" - android:layout_marginRight="@dimen/l2" - android:layout_marginBottom="@dimen/l2" + android:layout_marginLeft="@dimen/l1" + android:layout_marginRight="@dimen/l1" + android:layout_marginBottom="@dimen/l1" android:onClick="@{() -> viewModel.toggle(viewModel.redesign)}" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/settings_card_dark" diff --git a/app/src/main/res/values/strings_md2.xml b/app/src/main/res/values/strings_md2.xml index 9a21d50fc..17dd1ab75 100644 --- a/app/src/main/res/values/strings_md2.xml +++ b/app/src/main/res/values/strings_md2.xml @@ -29,4 +29,10 @@ Hide + Theme Mode + Select mode which best suits your style! + Always Light + Follow System + Always Dark + \ No newline at end of file diff --git a/app/src/main/res/values/styles_md2_impl.xml b/app/src/main/res/values/styles_md2_impl.xml index 1ecc8dca5..75d824623 100644 --- a/app/src/main/res/values/styles_md2_impl.xml +++ b/app/src/main/res/values/styles_md2_impl.xml @@ -53,6 +53,8 @@ variant. Make sure to use style referenced by attribute defined it attrs.xml.