From 28fcbbcf7bc984e842a4db84a9b565866cf86570 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Thu, 17 Oct 2019 19:26:35 +0200 Subject: [PATCH] Added basic preferences to settings --- .../magisk/model/events/ViewEvents.kt | 12 ++- .../redesign/settings/SettingsFragment.kt | 9 ++ .../redesign/settings/SettingsViewModel.kt | 27 +++++- .../main/res/layout/fragment_settings_md2.xml | 88 ++++++++++++++++++- 4 files changed, 131 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt b/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt index 48c25fb92..9c3c725da 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt @@ -85,4 +85,14 @@ class BackPressEvent : ViewEvent(), ActivityExecutor { } } -class DieEvent : ViewEvent() +class DieEvent : ViewEvent(), ActivityExecutor { + override fun invoke(activity: AppCompatActivity) { + activity.finish() + } +} + +class RecreateEvent : ViewEvent(), ActivityExecutor { + override fun invoke(activity: AppCompatActivity) { + activity.recreate() + } +} diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsFragment.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsFragment.kt index 1135e1ee5..6f665624b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsFragment.kt @@ -1,5 +1,6 @@ package com.topjohnwu.magisk.redesign.settings +import android.graphics.Insets import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.FragmentSettingsMd2Binding import com.topjohnwu.magisk.redesign.compat.CompatFragment @@ -10,4 +11,12 @@ class SettingsFragment : CompatFragment() + override fun consumeSystemWindowInsets(insets: Insets) = insets + + override fun onStart() { + super.onStart() + + activity.title = resources.getString(R.string.section_settings) + } + } \ 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 76b92fe19..0014b8cd8 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 @@ -1,5 +1,30 @@ package com.topjohnwu.magisk.redesign.settings +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.redesign.compat.CompatViewModel +import com.topjohnwu.magisk.utils.KObservableField -class SettingsViewModel : CompatViewModel() \ No newline at end of file +class SettingsViewModel : CompatViewModel() { + + val redesign = KObservableField(Config.redesign) + val darkTheme = KObservableField(Config.darkTheme) + + init { + //todo make observable preference + redesign.addOnPropertyChangedCallback { + Config.redesign = redesign.value + DieEvent().publish() + } + darkTheme.addOnPropertyChangedCallback { + Config.darkTheme = darkTheme.value + RecreateEvent().publish() + } + } + + fun toggle(item: KObservableField) = item.toggle() + +} \ 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 640519ada..d989ef96c 100644 --- a/app/src/main/res/layout/fragment_settings_md2.xml +++ b/app/src/main/res/layout/fragment_settings_md2.xml @@ -1,5 +1,7 @@ - + @@ -12,11 +14,91 @@ + android:clipToPadding="false" + 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"> + android:layout_height="wrap_content"> + + + + + + + + + + + + + + + + + + + + + + + + + +