Merge pull request #1900 from yashk2000/feature/yashk2000/1899-finish-action-mode

Fix #1899 Finish action mode when shifting fragments
This commit is contained in:
Seán Mac Gillicuddy 2020-04-17 15:59:02 +01:00 committed by GitHub
commit d1d7abd195
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 0 deletions

View File

@ -69,10 +69,15 @@ class ZimManageActivity : BaseActivity() {
offscreenPageLimit = sectionsPagerAdapter.count - 1
tabs.setupWithViewPager(this)
addOnPageChangeListener(SimplePageChangeListener(::updateMenu))
addOnPageChangeListener(SimplePageChangeListener(::updatePage))
}
setViewPagerPositionFromIntent(intent)
}
private fun updatePage(position: Int) {
zimManageViewModel.currentPage.offer(position)
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
setViewPagerPositionFromIntent(intent)

View File

@ -108,6 +108,9 @@ class ZimManageViewModel @Inject constructor(
val fileSelectActions = PublishProcessor.create<FileSelectActions>()
val requestDownloadLibrary = BehaviorProcessor.createDefault<Unit>(Unit)
val requestFiltering = BehaviorProcessor.createDefault<String>("")
val currentPage = PublishProcessor.create<Int>()
val libraryTabIsVisible = currentPage.map { it == 1 }.filter { it }
private val compositeDisposable = CompositeDisposable()

View File

@ -111,6 +111,12 @@ class ZimFileSelectFragment : BaseFragment() {
if (savedInstanceState != null && savedInstanceState.getBoolean(WAS_IN_ACTION_MODE)) {
zimManageViewModel.fileSelectActions.offer(FileSelectActions.RestartActionMode)
}
disposable.add(zimManageViewModel.libraryTabIsVisible.subscribe { finishActionMode() })
}
private fun finishActionMode() {
actionMode?.finish()
}
private fun sideEffects() = zimManageViewModel.sideEffects.subscribe(

View File

@ -517,4 +517,18 @@ class ZimManageViewModelTest {
.assertValues(StartMultiSelection(viewModel.fileSelectActions))
}
}
@Test
fun `libraryTabIsVisible emits when currentPage is 1`() {
viewModel.libraryTabIsVisible.test()
.also { viewModel.currentPage.offer(1) }
.assertValue(true)
}
@Test
fun `libraryTabIsVisible does not emit when currentPage is 0`() {
viewModel.libraryTabIsVisible.test()
.also { viewModel.currentPage.offer(0) }
.assertEmpty()
}
}