Added basic preferences to settings
This commit is contained in:
parent
0f4326151f
commit
28fcbbcf7b
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.topjohnwu.magisk.redesign.settings
|
package com.topjohnwu.magisk.redesign.settings
|
||||||
|
|
||||||
|
import android.graphics.Insets
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.databinding.FragmentSettingsMd2Binding
|
import com.topjohnwu.magisk.databinding.FragmentSettingsMd2Binding
|
||||||
import com.topjohnwu.magisk.redesign.compat.CompatFragment
|
import com.topjohnwu.magisk.redesign.compat.CompatFragment
|
||||||
@ -10,4 +11,12 @@ class SettingsFragment : CompatFragment<SettingsViewModel, FragmentSettingsMd2Bi
|
|||||||
override val layoutRes = R.layout.fragment_settings_md2
|
override val layoutRes = R.layout.fragment_settings_md2
|
||||||
override val viewModel by viewModel<SettingsViewModel>()
|
override val viewModel by viewModel<SettingsViewModel>()
|
||||||
|
|
||||||
|
override fun consumeSystemWindowInsets(insets: Insets) = insets
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
|
|
||||||
|
activity.title = resources.getString(R.string.section_settings)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,5 +1,30 @@
|
|||||||
package com.topjohnwu.magisk.redesign.settings
|
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.redesign.compat.CompatViewModel
|
||||||
|
import com.topjohnwu.magisk.utils.KObservableField
|
||||||
|
|
||||||
class SettingsViewModel : CompatViewModel()
|
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<Boolean>) = item.toggle()
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<data>
|
<data>
|
||||||
|
|
||||||
@ -12,11 +14,91 @@
|
|||||||
<androidx.core.widget.NestedScrollView
|
<androidx.core.widget.NestedScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:fillViewport="true">
|
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">
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
android:id="@+id/settings_card_dark"
|
||||||
|
style="?styleCardNormal"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="@dimen/l2"
|
||||||
|
android:layout_marginTop="@dimen/l1"
|
||||||
|
android:onClick="@{() -> viewModel.toggle(viewModel.darkTheme)}"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/settings_card_redesign"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="@dimen/l1">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/settings_dark_theme_title"
|
||||||
|
android:textAppearance="?appearanceTextTitleNormal" />
|
||||||
|
|
||||||
|
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:checked="@={viewModel.darkTheme}" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
android:id="@+id/settings_card_redesign"
|
||||||
|
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:onClick="@{() -> viewModel.toggle(viewModel.redesign)}"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/settings_card_dark"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="@dimen/l1">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="Redesign"
|
||||||
|
android:textAppearance="?appearanceTextTitleNormal" />
|
||||||
|
|
||||||
|
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:checked="@={viewModel.redesign}" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user