mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-04-23 06:17:28 +02:00
update the app if the text color or primary color changes
This commit is contained in:
parent
eb34554a01
commit
edc82e2390
@ -9,10 +9,12 @@ import com.simplemobiletools.applauncher.BuildConfig
|
|||||||
import com.simplemobiletools.applauncher.R
|
import com.simplemobiletools.applauncher.R
|
||||||
import com.simplemobiletools.applauncher.adapters.RecyclerAdapter
|
import com.simplemobiletools.applauncher.adapters.RecyclerAdapter
|
||||||
import com.simplemobiletools.applauncher.dialogs.AddAppLauncherDialog
|
import com.simplemobiletools.applauncher.dialogs.AddAppLauncherDialog
|
||||||
|
import com.simplemobiletools.applauncher.extensions.config
|
||||||
import com.simplemobiletools.applauncher.extensions.dbHelper
|
import com.simplemobiletools.applauncher.extensions.dbHelper
|
||||||
import com.simplemobiletools.applauncher.extensions.isAPredefinedApp
|
import com.simplemobiletools.applauncher.extensions.isAPredefinedApp
|
||||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||||
import com.simplemobiletools.commons.extensions.checkWhatsNew
|
import com.simplemobiletools.commons.extensions.checkWhatsNew
|
||||||
|
import com.simplemobiletools.commons.extensions.restartActivity
|
||||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||||
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
|
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
|
||||||
import com.simplemobiletools.commons.helpers.LICENSE_MULTISELECT
|
import com.simplemobiletools.commons.helpers.LICENSE_MULTISELECT
|
||||||
@ -24,6 +26,9 @@ import java.util.*
|
|||||||
|
|
||||||
class MainActivity : SimpleActivity(), RecyclerAdapter.AppLaunchersListener {
|
class MainActivity : SimpleActivity(), RecyclerAdapter.AppLaunchersListener {
|
||||||
private var launchers = ArrayList<AppLauncher>()
|
private var launchers = ArrayList<AppLauncher>()
|
||||||
|
private var mStoredPrimaryColor = 0
|
||||||
|
private var mStoredTextColor = 0
|
||||||
|
private var mStoredUseEnglish = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -31,6 +36,7 @@ class MainActivity : SimpleActivity(), RecyclerAdapter.AppLaunchersListener {
|
|||||||
setupLaunchers()
|
setupLaunchers()
|
||||||
checkWhatsNewDialog()
|
checkWhatsNewDialog()
|
||||||
setupGridLayoutManager()
|
setupGridLayoutManager()
|
||||||
|
storeStateVariables()
|
||||||
|
|
||||||
fab.setOnClickListener {
|
fab.setOnClickListener {
|
||||||
AddAppLauncherDialog(this, launchers) {
|
AddAppLauncherDialog(this, launchers) {
|
||||||
@ -41,9 +47,27 @@ class MainActivity : SimpleActivity(), RecyclerAdapter.AppLaunchersListener {
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
if (mStoredUseEnglish != config.useEnglish) {
|
||||||
|
restartActivity()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mStoredTextColor != config.textColor) {
|
||||||
|
getGridAdapter()?.updateTextColor(config.textColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mStoredPrimaryColor != config.primaryColor) {
|
||||||
|
getGridAdapter()?.updatePrimaryColor(config.primaryColor)
|
||||||
|
}
|
||||||
|
|
||||||
updateTextColors(coordinator_layout)
|
updateTextColors(coordinator_layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
storeStateVariables()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
menuInflater.inflate(R.menu.menu, menu)
|
menuInflater.inflate(R.menu.menu, menu)
|
||||||
updateMenuTextSize(resources, menu)
|
updateMenuTextSize(resources, menu)
|
||||||
@ -67,7 +91,7 @@ class MainActivity : SimpleActivity(), RecyclerAdapter.AppLaunchersListener {
|
|||||||
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT or LICENSE_STETHO, BuildConfig.VERSION_NAME)
|
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT or LICENSE_STETHO, BuildConfig.VERSION_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getGridAdapter() = (launchers_grid.adapter as RecyclerAdapter)
|
private fun getGridAdapter() = launchers_grid.adapter as? RecyclerAdapter
|
||||||
|
|
||||||
private fun setupGridLayoutManager() {
|
private fun setupGridLayoutManager() {
|
||||||
launchers_grid.isDragSelectionEnabled = true
|
launchers_grid.isDragSelectionEnabled = true
|
||||||
@ -77,11 +101,11 @@ class MainActivity : SimpleActivity(), RecyclerAdapter.AppLaunchersListener {
|
|||||||
override fun zoomOut() {}
|
override fun zoomOut() {}
|
||||||
|
|
||||||
override fun selectItem(position: Int) {
|
override fun selectItem(position: Int) {
|
||||||
getGridAdapter().selectItem(position)
|
getGridAdapter()?.selectItem(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun selectRange(initialSelection: Int, lastDraggedIndex: Int, minReached: Int, maxReached: Int) {
|
override fun selectRange(initialSelection: Int, lastDraggedIndex: Int, minReached: Int, maxReached: Int) {
|
||||||
getGridAdapter().selectRange(initialSelection, lastDraggedIndex, minReached, maxReached)
|
getGridAdapter()?.selectRange(initialSelection, lastDraggedIndex, minReached, maxReached)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,6 +138,14 @@ class MainActivity : SimpleActivity(), RecyclerAdapter.AppLaunchersListener {
|
|||||||
launchers = launchers.filter { !invalidIds.contains(it.id.toString()) } as ArrayList<AppLauncher>
|
launchers = launchers.filter { !invalidIds.contains(it.id.toString()) } as ArrayList<AppLauncher>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun storeStateVariables() {
|
||||||
|
config.apply {
|
||||||
|
mStoredPrimaryColor = primaryColor
|
||||||
|
mStoredTextColor = textColor
|
||||||
|
mStoredUseEnglish = useEnglish
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun refreshLaunchers() {
|
override fun refreshLaunchers() {
|
||||||
setupLaunchers()
|
setupLaunchers()
|
||||||
}
|
}
|
||||||
|
@ -147,6 +147,16 @@ class RecyclerAdapter(val activity: SimpleActivity, val launchers: MutableList<A
|
|||||||
actMode?.finish()
|
actMode?.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateTextColor(textColor: Int) {
|
||||||
|
this.textColor = textColor
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updatePrimaryColor(primaryColor: Int) {
|
||||||
|
this.primaryColor = primaryColor
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
fun selectItem(pos: Int) {
|
fun selectItem(pos: Int) {
|
||||||
toggleItemSelection(true, pos)
|
toggleItemSelection(true, pos)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user