mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-08 14:52:13 -04:00
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:
commit
d1d7abd195
@ -69,10 +69,15 @@ class ZimManageActivity : BaseActivity() {
|
|||||||
offscreenPageLimit = sectionsPagerAdapter.count - 1
|
offscreenPageLimit = sectionsPagerAdapter.count - 1
|
||||||
tabs.setupWithViewPager(this)
|
tabs.setupWithViewPager(this)
|
||||||
addOnPageChangeListener(SimplePageChangeListener(::updateMenu))
|
addOnPageChangeListener(SimplePageChangeListener(::updateMenu))
|
||||||
|
addOnPageChangeListener(SimplePageChangeListener(::updatePage))
|
||||||
}
|
}
|
||||||
setViewPagerPositionFromIntent(intent)
|
setViewPagerPositionFromIntent(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updatePage(position: Int) {
|
||||||
|
zimManageViewModel.currentPage.offer(position)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent?) {
|
override fun onNewIntent(intent: Intent?) {
|
||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
setViewPagerPositionFromIntent(intent)
|
setViewPagerPositionFromIntent(intent)
|
||||||
|
@ -108,6 +108,9 @@ class ZimManageViewModel @Inject constructor(
|
|||||||
val fileSelectActions = PublishProcessor.create<FileSelectActions>()
|
val fileSelectActions = PublishProcessor.create<FileSelectActions>()
|
||||||
val requestDownloadLibrary = BehaviorProcessor.createDefault<Unit>(Unit)
|
val requestDownloadLibrary = BehaviorProcessor.createDefault<Unit>(Unit)
|
||||||
val requestFiltering = BehaviorProcessor.createDefault<String>("")
|
val requestFiltering = BehaviorProcessor.createDefault<String>("")
|
||||||
|
val currentPage = PublishProcessor.create<Int>()
|
||||||
|
|
||||||
|
val libraryTabIsVisible = currentPage.map { it == 1 }.filter { it }
|
||||||
|
|
||||||
private val compositeDisposable = CompositeDisposable()
|
private val compositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
|
@ -111,6 +111,12 @@ class ZimFileSelectFragment : BaseFragment() {
|
|||||||
if (savedInstanceState != null && savedInstanceState.getBoolean(WAS_IN_ACTION_MODE)) {
|
if (savedInstanceState != null && savedInstanceState.getBoolean(WAS_IN_ACTION_MODE)) {
|
||||||
zimManageViewModel.fileSelectActions.offer(FileSelectActions.RestartActionMode)
|
zimManageViewModel.fileSelectActions.offer(FileSelectActions.RestartActionMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
disposable.add(zimManageViewModel.libraryTabIsVisible.subscribe { finishActionMode() })
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun finishActionMode() {
|
||||||
|
actionMode?.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sideEffects() = zimManageViewModel.sideEffects.subscribe(
|
private fun sideEffects() = zimManageViewModel.sideEffects.subscribe(
|
||||||
|
@ -517,4 +517,18 @@ class ZimManageViewModelTest {
|
|||||||
.assertValues(StartMultiSelection(viewModel.fileSelectActions))
|
.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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user