Don't restart activity changing alignment
When changing alignment in the reader we were restarting the reader activity to reload. Doing this led to reloading the article which was initially opened every time you changed alignment. Now, when changing the alignment we retain all existing fragments but command all of them to update their alignment setting.
This commit is contained in:
parent
212d259a33
commit
4859b77ac0
@ -209,28 +209,24 @@ class ReaderActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.align_left -> {
|
R.id.align_left -> switchAlignmentSetting(AppSettingsService.ALIGN_LEFT)
|
||||||
switchAlignmentSetting(AppSettingsService.ALIGN_LEFT)
|
|
||||||
refreshFragment()
|
|
||||||
}
|
|
||||||
|
|
||||||
R.id.align_justify -> {
|
R.id.align_justify -> switchAlignmentSetting(AppSettingsService.JUSTIFY)
|
||||||
switchAlignmentSetting(AppSettingsService.JUSTIFY)
|
|
||||||
refreshFragment()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun switchAlignmentSetting(allignment: Int) {
|
private fun switchAlignmentSetting(alignment: Int) {
|
||||||
appSettingsService.changeAllignment(allignment)
|
appSettingsService.changeAllignment(alignment)
|
||||||
alignmentMenu()
|
alignmentMenu()
|
||||||
}
|
|
||||||
|
|
||||||
private fun refreshFragment() {
|
val fragmentManager = supportFragmentManager
|
||||||
finish()
|
val fragments = fragmentManager.fragments
|
||||||
overridePendingTransition(0, 0)
|
|
||||||
startActivity(intent)
|
for (fragment in fragments) {
|
||||||
overridePendingTransition(0, 0)
|
if (fragment is ArticleFragment) {
|
||||||
|
fragment.refreshAlignment()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,13 +263,15 @@ class ArticleFragment :
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshAlignment() {
|
fun refreshAlignment() {
|
||||||
textAlignment =
|
textAlignment =
|
||||||
when (appSettingsService.getActiveAllignment()) {
|
when (appSettingsService.getActiveAllignment()) {
|
||||||
1 -> "justify"
|
1 -> "justify"
|
||||||
2 -> "left"
|
2 -> "left"
|
||||||
else -> "justify"
|
else -> "justify"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
htmlToWebview()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("detekt:SwallowedException")
|
@Suppress("detekt:SwallowedException")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user