mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-08 06:42:21 -04:00
Subscribe to a field in view model to control action mode
This commit is contained in:
parent
30f40c829f
commit
15a0d9aae2
@ -19,9 +19,7 @@
|
|||||||
package org.kiwix.kiwixmobile.zim_manager
|
package org.kiwix.kiwixmobile.zim_manager
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
import androidx.appcompat.view.ActionMode
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
@ -112,6 +110,8 @@ class ZimManageViewModel @Inject constructor(
|
|||||||
val requestFiltering = BehaviorProcessor.createDefault<String>("")
|
val requestFiltering = BehaviorProcessor.createDefault<String>("")
|
||||||
val currentPage = PublishProcessor.create<Int>()
|
val currentPage = PublishProcessor.create<Int>()
|
||||||
|
|
||||||
|
val libraryFragmentIsVisible = currentPage.filter { it == 1 }
|
||||||
|
|
||||||
private val compositeDisposable = CompositeDisposable()
|
private val compositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -146,12 +146,6 @@ class ZimManageViewModel @Inject constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun actionMode(actionMode: ActionMode?) {
|
|
||||||
currentPage.filter { it == 1 }.subscribe {
|
|
||||||
actionMode?.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun fileSelectActions() = fileSelectActions.subscribe({
|
private fun fileSelectActions() = fileSelectActions.subscribe({
|
||||||
sideEffects.offer(
|
sideEffects.offer(
|
||||||
when (it) {
|
when (it) {
|
||||||
|
@ -112,9 +112,7 @@ class ZimFileSelectFragment : BaseFragment() {
|
|||||||
zimManageViewModel.fileSelectActions.offer(FileSelectActions.RestartActionMode)
|
zimManageViewModel.fileSelectActions.offer(FileSelectActions.RestartActionMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
zimManageViewModel.currentPage.subscribe {
|
disposable.add(zimManageViewModel.libraryFragmentIsVisible.subscribe { actionMode?.finish() })
|
||||||
zimManageViewModel.actionMode(actionMode)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sideEffects() = zimManageViewModel.sideEffects.subscribe(
|
private fun sideEffects() = zimManageViewModel.sideEffects.subscribe(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user