Skip to content

Commit

Permalink
Fix #2853 (make multitasking working, create always a new task when c…
Browse files Browse the repository at this point in the history
…licking deep link)
  • Loading branch information
tuomas2 committed Sep 18, 2023
1 parent d5ce365 commit 1416163
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,11 @@ open class StartupActivity : CustomTitlebarActivityBase() {
private fun gotoMainBibleActivity() {
Log.i(TAG, "Going to MainBibleActivity")
val handlerIntent = Intent(this, MainBibleActivity::class.java)
handlerIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
if(intent?.action == Intent.ACTION_VIEW) {
handlerIntent.putExtra("openLink", intent.dataString)
handlerIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK
} else {
handlerIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
}
lifecycleScope.launch(Dispatchers.Main) {
if(SwordDocumentFacade.bibles.none { !it.isLocked }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,16 +597,6 @@ class MainBibleActivity : CustomTitlebarActivityBase() {
}
}

override fun onPause() {
CommonUtils.windowControl.windowRepository.saveIntoDb(false)
fullScreen = false;
if(CommonUtils.showCalculator) {
(window.decorView as ViewGroup).removeView(binding.root)
super.setContentView(empty.root)
}
super.onPause()
}

private var lastBackPressed: Long? = null

override fun onBackPressed() {
Expand Down Expand Up @@ -1068,6 +1058,7 @@ class MainBibleActivity : CustomTitlebarActivityBase() {
}

fun onEventMainThread(passageEvent: CurrentVerseChangedEvent) {
if(paused) return
updateTitle()
}

Expand Down Expand Up @@ -1382,6 +1373,7 @@ class MainBibleActivity : CustomTitlebarActivityBase() {
}

fun onEvent(event: AppToBackgroundEvent) {
if(paused) return
if (event.isMovedToBackground) {
mWholeAppWasInBackground = true
stopPeriodicSync()
Expand Down Expand Up @@ -1445,6 +1437,7 @@ class MainBibleActivity : CustomTitlebarActivityBase() {
}

fun onEvent(event: ScreenSettings.NightModeChanged) {
if(paused) return
if(CurrentActivityHolder.currentActivity == this) {
refreshIfNightModeChange()
}
Expand Down Expand Up @@ -1764,10 +1757,12 @@ class MainBibleActivity : CustomTitlebarActivityBase() {
}

fun onEvent(event: CurrentWindowChangedEvent) {
if(paused) return
updateActions()
}

fun onEvent(event: NumberOfWindowsChangedEvent) {
if(paused) return
setSoftKeyboardMode()
}

Expand All @@ -1783,21 +1778,63 @@ class MainBibleActivity : CustomTitlebarActivityBase() {
* called by PassageChangeMediator after a new passage has been changed and displayed
*/
fun onEventMainThread(event: PassageChangedEvent) {
if(paused) return
updateActions()
}

private var paused = false
override fun onPause() {
windowControl.windowRepository.saveIntoDb(false)
paused = true
fullScreen = false
if(CommonUtils.showCalculator) {
(window.decorView as ViewGroup).removeView(binding.root)
super.setContentView(empty.root)
}
super.onPause()
}

override fun onResume() {
windowControl.windowRepository = windowRepository
paused = false
var needRefresh = false
if(windowControl.windowRepository != windowRepository) {
windowControl.windowRepository = windowRepository
needRefresh = true
}
super.onResume()
if(CommonUtils.showCalculator && empty.root.parent != null) {
(window.decorView as ViewGroup).removeView(empty.root)
super.setContentView(binding.root)
}

if(needRefresh) {
currentWorkspaceId = currentWorkspaceId // will reload workspace from db
}
// allow webView to start monitoring tilt by setting focus which causes tilt-scroll to resume
documentViewManager.documentView.asView().requestFocus()
}

private var frozen = false

override fun freeze() {
if(CurrentActivityHolder.mainBibleActivities < 2) return
if(!frozen) {
ABEventBus.unregister(this)
(window.decorView as ViewGroup).removeView(binding.root)
super.setContentView(frozenBinding.root)
}
frozen = true
}

override fun unFreeze() {
if(frozen) {
windowControl.windowRepository = windowRepository
ABEventBus.register(this)
(window.decorView as ViewGroup).removeView(frozenBinding.root)
super.setContentView(binding.root)
}
frozen = false
}

/**
* user swiped right
*/
Expand All @@ -1821,28 +1858,6 @@ class MainBibleActivity : CustomTitlebarActivityBase() {
return if(reverse) !CommonUtils.isPortrait else CommonUtils.isPortrait
}

private var frozen = false

override fun freeze() {
if(CurrentActivityHolder.mainBibleActivities < 2) return
if(!frozen) {
ABEventBus.unregister(this)
(window.decorView as ViewGroup).removeView(binding.root)
super.setContentView(frozenBinding.root)
}
frozen = true
}

override fun unFreeze() {
if(frozen) {
windowControl.windowRepository = windowRepository
ABEventBus.register(this)
(window.decorView as ViewGroup).removeView(frozenBinding.root)
super.setContentView(binding.root)
}
frozen = false
}

fun activate(v: View) {
CurrentActivityHolder.activate(this)
}
Expand Down

0 comments on commit 1416163

Please sign in to comment.