Skip to content

Commit

Permalink
moving some config variable check into main activity
Browse files Browse the repository at this point in the history
  • Loading branch information
tibbi committed May 19, 2021
1 parent c469c99 commit 740a4e0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -428,6 +466,8 @@ class MainActivity : SimpleActivity() {
}
}

private fun getAllFragments() = arrayListOf(items_fragment)

private fun getCurrentFragment() = items_fragment

private fun checkWhatsNewDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
Expand All @@ -78,27 +67,28 @@ 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()
}

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
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 740a4e0

Please sign in to comment.