mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
Ensure upwards compatibility of themes and preferences
The app now saves which version was used the last time and recognizes, if something changed / settings have to be adjusted to fit the version.
This commit is contained in:
parent
abcc1870fc
commit
08d4a6c2ef
9 changed files with 99 additions and 109 deletions
|
@ -12,7 +12,7 @@
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/finnmglasTheme">
|
android:theme="@style/baseTheme">
|
||||||
|
|
||||||
<activity android:name=".HomeActivity"
|
<activity android:name=".HomeActivity"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
|
|
|
@ -53,6 +53,8 @@ const val PREF_THEME = "theme"
|
||||||
const val PREF_STARTED = "startedBefore"
|
const val PREF_STARTED = "startedBefore"
|
||||||
const val PREF_STARTED_TIME = "firstStartup"
|
const val PREF_STARTED_TIME = "firstStartup"
|
||||||
|
|
||||||
|
const val PREF_VERSION = "version"
|
||||||
|
|
||||||
/* Objects used by multiple activities */
|
/* Objects used by multiple activities */
|
||||||
lateinit var appListViewAdapter: AppsRecyclerAdapter
|
lateinit var appListViewAdapter: AppsRecyclerAdapter
|
||||||
|
|
||||||
|
@ -239,6 +241,40 @@ fun saveTheme(themeName : String) : String {
|
||||||
return themeName
|
return themeName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun resetToDefaultTheme(activity: Activity) {
|
||||||
|
dominantColor = activity.resources.getColor(R.color.finnmglasTheme_background_color)
|
||||||
|
vibrantColor = activity.resources.getColor(R.color.finnmglasTheme_accent_color)
|
||||||
|
|
||||||
|
launcherPreferences.edit()
|
||||||
|
.putString(PREF_WALLPAPER, "")
|
||||||
|
.putInt(PREF_DOMINANT, dominantColor)
|
||||||
|
.putInt(PREF_VIBRANT, vibrantColor)
|
||||||
|
.apply()
|
||||||
|
|
||||||
|
saveTheme("finn")
|
||||||
|
loadSettings()
|
||||||
|
|
||||||
|
intendedSettingsPause = true
|
||||||
|
activity.recreate()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resetToDarkTheme(activity: Activity) {
|
||||||
|
dominantColor = activity.resources.getColor(R.color.darkTheme_background_color)
|
||||||
|
vibrantColor = activity.resources.getColor(R.color.darkTheme_accent_color)
|
||||||
|
|
||||||
|
launcherPreferences.edit()
|
||||||
|
.putString(PREF_WALLPAPER, "")
|
||||||
|
.putInt(PREF_DOMINANT, dominantColor)
|
||||||
|
.putInt(PREF_VIBRANT, vibrantColor)
|
||||||
|
.apply()
|
||||||
|
|
||||||
|
saveTheme("dark")
|
||||||
|
|
||||||
|
intendedSettingsPause = true
|
||||||
|
activity.recreate()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun openAppSettings(pkg :String, context:Context) {
|
fun openAppSettings(pkg :String, context:Context) {
|
||||||
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||||
intent.data = Uri.parse("package:$pkg")
|
intent.data = Uri.parse("package:$pkg")
|
||||||
|
@ -322,6 +358,18 @@ fun pickDefaultApp(action: String, context: Context) : String {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used in Tutorial and Settings `ActivityOnResult`
|
||||||
|
fun saveListActivityChoice(data: Intent?) {
|
||||||
|
val value = data?.getStringExtra("value")
|
||||||
|
val forApp = data?.getStringExtra("forApp") ?: return
|
||||||
|
|
||||||
|
launcherPreferences.edit()
|
||||||
|
.putString("action_$forApp", value.toString())
|
||||||
|
.apply()
|
||||||
|
|
||||||
|
loadSettings()
|
||||||
|
}
|
||||||
|
|
||||||
/* Bitmaps */
|
/* Bitmaps */
|
||||||
|
|
||||||
fun setButtonColor(btn: Button, color: Int) {
|
fun setButtonColor(btn: Button, color: Int) {
|
||||||
|
@ -332,10 +380,7 @@ fun setButtonColor(btn: Button, color: Int) {
|
||||||
// tested with API 28 (Android 9 on S8) -> necessary
|
// tested with API 28 (Android 9 on S8) -> necessary
|
||||||
btn.background.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)
|
btn.background.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)
|
||||||
}
|
}
|
||||||
else {
|
// not setting it in any other case (yet), unable to find a good solution
|
||||||
// not setting it here, unable to find a good alternative
|
|
||||||
// TODO at some point (or you do it now)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Taken from: https://stackoverflow.com/a/33072575/12787264
|
// Taken from: https://stackoverflow.com/a/33072575/12787264
|
||||||
|
|
|
@ -16,6 +16,7 @@ import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.concurrent.fixedRateTimer
|
import kotlin.concurrent.fixedRateTimer
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
import com.finnmglas.launcher.BuildConfig.VERSION_NAME
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [HomeActivity] is the actual application Launcher,
|
* [HomeActivity] is the actual application Launcher,
|
||||||
|
@ -56,9 +57,34 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
||||||
appListViewAdapter = AppsRecyclerAdapter(this)
|
appListViewAdapter = AppsRecyclerAdapter(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
// First time opening the app: show Tutorial
|
// First time opening the app: show Tutorial, else: check versions
|
||||||
if (!launcherPreferences.getBoolean(PREF_STARTED, false))
|
if (!launcherPreferences.getBoolean(PREF_STARTED, false))
|
||||||
startActivity(Intent(this, TutorialActivity::class.java))
|
startActivity(Intent(this, TutorialActivity::class.java))
|
||||||
|
else when (launcherPreferences.getString(PREF_VERSION, "")) {
|
||||||
|
// Check versions, make sure transitions between versions go well
|
||||||
|
|
||||||
|
VERSION_NAME -> { /* the version installed and used previously are the same */ }
|
||||||
|
"" -> { /* The version used before was pre- v1.3.0,
|
||||||
|
as version tracking started then */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* before, the dominant and vibrant color of the `finn` and `dark` theme
|
||||||
|
* were not stored anywhere. Now they have to be stored:
|
||||||
|
* -> we just reset them using newly implemented functions
|
||||||
|
*/
|
||||||
|
when (getSavedTheme(this)) {
|
||||||
|
"finn" -> resetToDefaultTheme(this)
|
||||||
|
"dark" -> resetToDarkTheme(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
launcherPreferences.edit()
|
||||||
|
.putString(PREF_VERSION, VERSION_NAME) // save new version
|
||||||
|
.apply()
|
||||||
|
|
||||||
|
// show the new tutorial
|
||||||
|
startActivity(Intent(this, TutorialActivity::class.java))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Initialise layout
|
// Initialise layout
|
||||||
setContentView(R.layout.home)
|
setContentView(R.layout.home)
|
||||||
|
@ -195,19 +221,9 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
||||||
)
|
)
|
||||||
} catch (e: Exception) { }
|
} catch (e: Exception) { }
|
||||||
|
|
||||||
if (background == null) { // same as in Settings - TODO make function called by both
|
// Background image was deleted or something unexpected happened
|
||||||
dominantColor = resources.getColor(R.color.finnmglasTheme_background_color)
|
if (background == null) resetToDefaultTheme(this)
|
||||||
vibrantColor = resources.getColor(R.color.finnmglasTheme_accent_color)
|
|
||||||
|
|
||||||
launcherPreferences.edit()
|
|
||||||
.putString(PREF_WALLPAPER, "")
|
|
||||||
.putInt(PREF_DOMINANT, dominantColor)
|
|
||||||
.putInt(PREF_VIBRANT, vibrantColor)
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
saveTheme("finn")
|
|
||||||
recreate()
|
|
||||||
}
|
|
||||||
home_background_image.visibility = View.VISIBLE
|
home_background_image.visibility = View.VISIBLE
|
||||||
} else {
|
} else {
|
||||||
home_background_image.visibility = View.INVISIBLE
|
home_background_image.visibility = View.INVISIBLE
|
||||||
|
|
|
@ -20,7 +20,7 @@ import com.finnmglas.launcher.list.other.ListFragmentOther
|
||||||
|
|
||||||
var intendedChoosePause = false // know when to close
|
var intendedChoosePause = false // know when to close
|
||||||
|
|
||||||
// TODO: Better solution for this (used in list-fragments)
|
// TODO: Better solution for this intercommunication fuctionality (used in list-fragments)
|
||||||
var intention = "view"
|
var intention = "view"
|
||||||
var forApp = ""
|
var forApp = ""
|
||||||
|
|
||||||
|
|
|
@ -80,16 +80,7 @@ class SettingsActivity: AppCompatActivity(), UIObject {
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
when (requestCode) {
|
when (requestCode) {
|
||||||
REQUEST_CHOOSE_APP -> {
|
REQUEST_CHOOSE_APP -> saveListActivityChoice(data)
|
||||||
val value = data?.getStringExtra("value")
|
|
||||||
val forApp = data?.getStringExtra("forApp") ?: return
|
|
||||||
|
|
||||||
launcherPreferences.edit()
|
|
||||||
.putString("action_$forApp", value.toString())
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
loadSettings()
|
|
||||||
}
|
|
||||||
else -> super.onActivityResult(requestCode, resultCode, data)
|
else -> super.onActivityResult(requestCode, resultCode, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,34 +123,10 @@ class SettingsFragmentTheme : Fragment(), UIObject {
|
||||||
override fun setOnClicks() {
|
override fun setOnClicks() {
|
||||||
// Theme changing buttons
|
// Theme changing buttons
|
||||||
settings_theme_dark_button_select.setOnClickListener {
|
settings_theme_dark_button_select.setOnClickListener {
|
||||||
dominantColor = resources.getColor(R.color.darkTheme_background_color)
|
resetToDarkTheme(activity!!)
|
||||||
vibrantColor = resources.getColor(R.color.darkTheme_accent_color)
|
|
||||||
|
|
||||||
launcherPreferences.edit()
|
|
||||||
.putString(PREF_WALLPAPER, "")
|
|
||||||
.putInt(PREF_DOMINANT, dominantColor)
|
|
||||||
.putInt(PREF_VIBRANT, vibrantColor)
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
saveTheme("dark")
|
|
||||||
|
|
||||||
intendedSettingsPause = true
|
|
||||||
activity!!.recreate()
|
|
||||||
}
|
}
|
||||||
settings_theme_finn_button_select.setOnClickListener {
|
settings_theme_finn_button_select.setOnClickListener {
|
||||||
dominantColor = resources.getColor(R.color.finnmglasTheme_background_color)
|
resetToDefaultTheme(activity!!)
|
||||||
vibrantColor = resources.getColor(R.color.finnmglasTheme_accent_color)
|
|
||||||
|
|
||||||
launcherPreferences.edit()
|
|
||||||
.putString(PREF_WALLPAPER, "")
|
|
||||||
.putInt(PREF_DOMINANT, dominantColor)
|
|
||||||
.putInt(PREF_VIBRANT, vibrantColor)
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
saveTheme("finn")
|
|
||||||
|
|
||||||
intendedSettingsPause = true
|
|
||||||
activity!!.recreate()
|
|
||||||
}
|
}
|
||||||
settings_theme_custom_button_select.setOnClickListener {
|
settings_theme_custom_button_select.setOnClickListener {
|
||||||
intendedSettingsPause = true
|
intendedSettingsPause = true
|
||||||
|
|
|
@ -59,24 +59,14 @@ class TutorialActivity: AppCompatActivity(), UIObject {
|
||||||
tutorial_close.setOnClickListener() { finish() }
|
tutorial_close.setOnClickListener() { finish() }
|
||||||
}
|
}
|
||||||
|
|
||||||
// same as in SettingsActivity; TODO: Use same function
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
when (requestCode) {
|
when (requestCode) {
|
||||||
REQUEST_CHOOSE_APP -> {
|
REQUEST_CHOOSE_APP -> saveListActivityChoice(data)
|
||||||
val value = data?.getStringExtra("value")
|
|
||||||
val forApp = data?.getStringExtra("forApp") ?: return
|
|
||||||
|
|
||||||
launcherPreferences.edit()
|
|
||||||
.putString("action_$forApp", value.toString())
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
loadSettings()
|
|
||||||
}
|
|
||||||
else -> super.onActivityResult(requestCode, resultCode, data)
|
else -> super.onActivityResult(requestCode, resultCode, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent going back, allow if viewed again later
|
// Default: prevent going back, allow if viewed again later
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
if (launcherPreferences.getBoolean(PREF_STARTED, false))
|
if (launcherPreferences.getBoolean(PREF_STARTED, false))
|
||||||
super.onBackPressed()
|
super.onBackPressed()
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.finnmglas.launcher.*
|
import com.finnmglas.launcher.*
|
||||||
|
import com.finnmglas.launcher.BuildConfig.VERSION_NAME
|
||||||
import kotlinx.android.synthetic.main.tutorial_finish.*
|
import kotlinx.android.synthetic.main.tutorial_finish.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,19 +38,12 @@ class TutorialFragmentFinish(): Fragment(), UIObject {
|
||||||
tutorial_finish_button_start.setOnClickListener{ finishTutorial() }
|
tutorial_finish_button_start.setOnClickListener{ finishTutorial() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun adjustLayout() {
|
|
||||||
super.adjustLayout()
|
|
||||||
|
|
||||||
// Different text if opened again later (from settings)
|
|
||||||
if (launcherPreferences.getBoolean(PREF_STARTED, false))
|
|
||||||
tutorial_finish_button_start.text = "Back to Settings"
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun finishTutorial() {
|
private fun finishTutorial() {
|
||||||
if (!launcherPreferences.getBoolean(PREF_STARTED, false)){
|
if (!launcherPreferences.getBoolean(PREF_STARTED, false)){
|
||||||
launcherPreferences.edit()
|
launcherPreferences.edit()
|
||||||
.putBoolean(PREF_STARTED, true) // never auto run this again
|
.putBoolean(PREF_STARTED, true) // never auto run this again
|
||||||
.putLong(PREF_STARTED_TIME, System.currentTimeMillis() / 1000L) // record first startup timestamp
|
.putLong(PREF_STARTED_TIME, System.currentTimeMillis() / 1000L) // record first startup timestamp
|
||||||
|
.putString(PREF_VERSION, VERSION_NAME) // save current launcher version
|
||||||
.apply()
|
.apply()
|
||||||
}
|
}
|
||||||
activity!!.finish()
|
activity!!.finish()
|
||||||
|
|
|
@ -1,49 +1,27 @@
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<!-- Personal Theme of Finn M Glas -->
|
<!-- Base theme for Launcher
|
||||||
<style name="finnmglasTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
|
||||||
|
This does not define the actual style of launcher,
|
||||||
|
as the style / colors etc are dynamically generated.
|
||||||
|
|
||||||
|
This is more like a fallback- theme that may partially be used by older apis.
|
||||||
|
|
||||||
|
-->
|
||||||
|
<style name="baseTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||||
<item name="colorPrimary">@color/finnmglasTheme_background_color</item>
|
<item name="colorPrimary">@color/finnmglasTheme_background_color</item>
|
||||||
<item name="colorPrimaryDark">@color/finnmglasTheme_background_color</item>
|
<item name="colorPrimaryDark">@color/finnmglasTheme_background_color</item>
|
||||||
<item name="android:colorBackground">@color/finnmglasTheme_background_color</item>
|
<item name="android:colorBackground">@color/finnmglasTheme_background_color</item>
|
||||||
|
|
||||||
<item name="colorAccent">#888</item>
|
<item name="colorAccent">#555</item>
|
||||||
|
|
||||||
<item name="android:textColor">@color/finnmglasTheme_text_color</item>
|
<item name="android:textColor">#ffffff</item>
|
||||||
<item name="android:textColorSecondary">@color/finnmglasTheme_text_color</item>
|
<item name="android:textColorSecondary">@color/finnmglasTheme_text_color</item>
|
||||||
<item name="android:textColorPrimary">@color/finnmglasTheme_text_color</item>
|
<item name="android:textColorPrimary">@color/finnmglasTheme_text_color</item>
|
||||||
<item name="android:textColorHint">#555</item>
|
<item name="android:textColorHint">#555</item>
|
||||||
|
|
||||||
<item name="android:buttonStyle">@style/Widget.AppCompat.Button.Colored</item>
|
<item name="android:buttonStyle">@style/Widget.AppCompat.Button.Colored</item>
|
||||||
<item name="colorButtonNormal">@color/finnmglasTheme_accent_color</item>
|
<item name="colorButtonNormal">#555</item>
|
||||||
|
|
||||||
<item name="android:popupMenuStyle">@style/PopupMenuCustom</item>
|
|
||||||
|
|
||||||
<item name="android:windowDisablePreview">true</item>
|
|
||||||
<item name="android:windowAnimationStyle">@style/WindowFadeTransition</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<!-- A dark efficiency theme -->
|
|
||||||
<style name="darkTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
|
||||||
<item name="colorPrimary">@color/darkTheme_background_color</item>
|
|
||||||
<item name="colorPrimaryDark">@color/darkTheme_background_color</item>
|
|
||||||
|
|
||||||
<item name="colorAccent">@color/darkTheme_accent_color</item>
|
|
||||||
|
|
||||||
<item name="android:textColor">@color/darkTheme_text_color</item>
|
|
||||||
<item name="android:buttonStyle">@style/Widget.AppCompat.Button.Colored</item>
|
|
||||||
<item name="colorButtonNormal">@color/darkTheme_accent_color</item>
|
|
||||||
|
|
||||||
<item name="android:popupMenuStyle">@style/PopupMenuCustom</item>
|
|
||||||
|
|
||||||
<item name="android:windowDisablePreview">true</item>
|
|
||||||
<item name="android:windowAnimationStyle">@style/WindowFadeTransition</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<!-- Custom theme -->
|
|
||||||
<style name="customTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
|
||||||
<item name="android:textColor">#ffffff</item>
|
|
||||||
<item name="android:buttonStyle">@style/Widget.AppCompat.Button.Colored</item>
|
|
||||||
<item name="colorButtonNormal">#252827</item>
|
|
||||||
|
|
||||||
<item name="android:popupMenuStyle">@style/PopupMenuCustom</item>
|
<item name="android:popupMenuStyle">@style/PopupMenuCustom</item>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue