mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-06-05 21:49:21 +02:00
implement the Dark theme switch visuals
This commit is contained in:
parent
03709860a6
commit
1c5128c19a
@ -37,7 +37,7 @@ class AboutActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupRateUs() {
|
private fun setupRateUs() {
|
||||||
if (preferences().isFirstRun) {
|
if (preferences.isFirstRun) {
|
||||||
about_rate_us.visibility = View.GONE
|
about_rate_us.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
preferences().isFirstRun = false
|
preferences.isFirstRun = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,32 @@
|
|||||||
package com.simplemobiletools.applauncher.activities
|
package com.simplemobiletools.applauncher.activities
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.support.v4.app.TaskStackBuilder
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
import com.simplemobiletools.applauncher.R
|
import com.simplemobiletools.applauncher.R
|
||||||
|
import com.simplemobiletools.applauncher.extensions.isDarkTheme
|
||||||
|
import com.simplemobiletools.applauncher.extensions.preferences
|
||||||
|
import kotlinx.android.synthetic.main.activity_settings.*
|
||||||
|
|
||||||
class SettingsActivity : AppCompatActivity() {
|
class SettingsActivity : AppCompatActivity() {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_settings)
|
setContentView(R.layout.activity_settings)
|
||||||
|
setupDarkTheme()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupDarkTheme() {
|
||||||
|
settings_dark_theme.isChecked = preferences.isDarkTheme
|
||||||
|
|
||||||
|
settings_dark_theme_holder.setOnClickListener {
|
||||||
|
settings_dark_theme.isChecked = !settings_dark_theme.isChecked
|
||||||
|
preferences.isDarkTheme = settings_dark_theme.isChecked
|
||||||
|
restartActivity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun restartActivity() {
|
||||||
|
TaskStackBuilder.create(applicationContext).addNextIntentWithParentStack(intent).startActivities()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,11 @@ import android.content.SharedPreferences
|
|||||||
|
|
||||||
val PREFS_KEY = "App Launcher"
|
val PREFS_KEY = "App Launcher"
|
||||||
val IS_FIRST_RUN = "is_first_run"
|
val IS_FIRST_RUN = "is_first_run"
|
||||||
|
val IS_DARK_THEME = "is_dark_theme"
|
||||||
|
|
||||||
private val defaultInit: Any.() -> Unit = {}
|
private val defaultInit: Any.() -> Unit = {}
|
||||||
|
|
||||||
|
val Context.preferences: SharedPreferences get() = preferences()
|
||||||
fun Context.preferences(init: SharedPreferences.() -> Unit = defaultInit): SharedPreferences {
|
fun Context.preferences(init: SharedPreferences.() -> Unit = defaultInit): SharedPreferences {
|
||||||
val defaultPreferences = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
val defaultPreferences = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
||||||
defaultPreferences.init()
|
defaultPreferences.init()
|
||||||
@ -21,3 +23,11 @@ var SharedPreferences.isFirstRun: Boolean
|
|||||||
get() {
|
get() {
|
||||||
return getBoolean(IS_FIRST_RUN, true)
|
return getBoolean(IS_FIRST_RUN, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var SharedPreferences.isDarkTheme: Boolean
|
||||||
|
set(isDarkTheme: Boolean) {
|
||||||
|
edit().putBoolean(IS_DARK_THEME, isDarkTheme).apply()
|
||||||
|
}
|
||||||
|
get() {
|
||||||
|
return getBoolean(IS_DARK_THEME, false)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user