moving some config variable check into main activity

This commit is contained in:
tibbi 2021-05-19 17:42:16 +02:00
parent c469c9931f
commit 740a4e095d
2 changed files with 56 additions and 24 deletions

View File

@ -43,10 +43,15 @@ class MainActivity : SimpleActivity() {
private var mWasProtectionHandled = false
private var searchMenuItem: MenuItem? = null
private var storedFontSize = 0
private var storedDateFormat = ""
private var storedTimeFormat = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
appLaunched(BuildConfig.APPLICATION_ID)
storeStateVariables()
mIsPasswordProtectionPending = config.isAppPasswordProtectionOn
if (savedInstanceState == null) {
@ -65,6 +70,31 @@ class MainActivity : SimpleActivity() {
}
}
override fun onResume() {
super.onResume()
val adjustedPrimaryColor = getAdjustedPrimaryColor()
getAllFragments().forEach {
it?.setupColors(config.textColor, adjustedPrimaryColor)
}
if (storedFontSize != config.fontSize) {
getAllFragments().forEach {
it.updateFontSize()
}
}
if (storedDateFormat != config.dateFormat || storedTimeFormat != getTimeFormat()) {
getAllFragments().forEach {
it.updateDateTimeFormat()
}
}
}
override fun onPause() {
super.onPause()
storeStateVariables()
}
override fun onDestroy() {
super.onDestroy()
config.temporarilyShowHidden = false
@ -192,6 +222,14 @@ class MainActivity : SimpleActivity() {
})
}
private fun storeStateVariables() {
config.apply {
storedFontSize = fontSize
storedDateFormat = dateFormat
storedTimeFormat = context.getTimeFormat()
}
}
private fun tryInitFileManager() {
handlePermission(PERMISSION_WRITE_STORAGE) {
checkOTGPath()
@ -428,6 +466,8 @@ class MainActivity : SimpleActivity() {
}
}
private fun getAllFragments() = arrayListOf(items_fragment)
private fun getCurrentFragment() = items_fragment
private fun checkWhatsNewDialog() {

View File

@ -47,9 +47,6 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : CoordinatorL
private var zoomListener: MyRecyclerView.MyZoomListener? = null
private var storedItems = ArrayList<ListItem>()
private var storedFontSize = 0
private var storedDateFormat = ""
private var storedTimeFormat = ""
fun setupFragment(activity: SimpleActivity) {
if (this.activity == null) {
@ -60,14 +57,6 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : CoordinatorL
}
}
private fun storeStateVariables() {
context!!.config.apply {
storedFontSize = fontSize
storedDateFormat = dateFormat
storedTimeFormat = context.getTimeFormat()
}
}
fun setupColors(textColor: Int, adjustedPrimaryColor: Int) {
context!!.updateTextColors(this)
items_fastscroller.updatePrimaryColor()
@ -78,20 +67,8 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : CoordinatorL
}
breadcrumbs.updateColor(textColor)
items_fastscroller.updateBubbleColors()
val configFontSize = context!!.config.fontSize
if (storedFontSize != configFontSize) {
getRecyclerAdapter()?.updateFontSizes()
storedFontSize = configFontSize
breadcrumbs.updateFontSize(context!!.getTextSize())
}
if (storedDateFormat != context!!.config.dateFormat || storedTimeFormat != context!!.getTimeFormat()) {
getRecyclerAdapter()?.updateDateTimeFormat()
}
if (!isFirstResume) {
refreshItems()
}
@ -99,6 +76,19 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : CoordinatorL
isFirstResume = false
}
fun updateFontSize() {
getRecyclerAdapter()?.updateFontSizes()
breadcrumbs.updateFontSize(context!!.getTextSize())
}
fun updateDateTimeFormat() {
getRecyclerAdapter()?.updateDateTimeFormat()
}
fun finishActMode() {
getRecyclerAdapter()?.finishActMode()
}
fun openPath(path: String, forceRefresh: Boolean = false) {
if ((activity as? BaseSimpleActivity)?.isAskingPermissions == true) {
return
@ -157,9 +147,11 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : CoordinatorL
}
items_list.scheduleLayoutAnimation()
val dateFormat = context!!.config.dateFormat
val timeFormat = context!!.getTimeFormat()
items_fastscroller.setViews(items_list, items_swipe_refresh) {
val listItem = getRecyclerAdapter()?.listItems?.getOrNull(it)
items_fastscroller.updateBubbleText(listItem?.getBubbleText(context, storedDateFormat, storedTimeFormat) ?: "")
items_fastscroller.updateBubbleText(listItem?.getBubbleText(context, dateFormat, timeFormat) ?: "")
}
getRecyclerLayoutManager().onRestoreInstanceState(scrollStates[currentPath])