Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [ANDROAPP-6665] Clear filters when navigating back #3895

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/src/main/java/org/dhis2/usescases/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ class MainActivity :
}

override fun onPause() {
presenter.setOpeningFilterToNone()
presenter.onDetach()
super.onPause()
}
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/org/dhis2/usescases/main/MainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import dhis2.org.analytics.charts.Charts
import org.dhis2.commons.di.dagger.PerActivity
import org.dhis2.commons.featureconfig.data.FeatureConfigRepository
import org.dhis2.commons.filters.FilterManager
import org.dhis2.commons.filters.data.FilterRepository
import org.dhis2.commons.matomo.MatomoAnalyticsController
import org.dhis2.commons.prefs.PreferenceProvider
import org.dhis2.commons.resources.ColorUtils
Expand All @@ -32,7 +31,7 @@ class MainModule(val view: MainView, private val forceToNotSynced: Boolean) {
schedulerProvider: SchedulerProvider,
preferences: PreferenceProvider,
workManagerController: WorkManagerController,
filterRepository: FilterRepository,
filterManager: FilterManager,
matomoAnalyticsController: MatomoAnalyticsController,
userManager: UserManager,
deleteUserData: DeleteUserData,
Expand All @@ -47,7 +46,7 @@ class MainModule(val view: MainView, private val forceToNotSynced: Boolean) {
schedulerProvider,
preferences,
workManagerController,
filterRepository,
filterManager,
matomoAnalyticsController,
userManager,
deleteUserData,
Expand Down
10 changes: 3 additions & 7 deletions app/src/main/java/org/dhis2/usescases/main/MainPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import kotlinx.coroutines.launch
import org.dhis2.BuildConfig
import org.dhis2.commons.Constants
import org.dhis2.commons.filters.FilterManager
import org.dhis2.commons.filters.data.FilterRepository
import org.dhis2.commons.matomo.Actions.Companion.BLOCK_SESSION_PIN
import org.dhis2.commons.matomo.Actions.Companion.OPEN_ANALYTICS
import org.dhis2.commons.matomo.Actions.Companion.QR_SCANNER
Expand Down Expand Up @@ -57,7 +56,7 @@ class MainPresenter(
private val schedulerProvider: SchedulerProvider,
private val preferences: PreferenceProvider,
private val workManagerController: WorkManagerController,
private val filterRepository: FilterRepository,
private val filterManager: FilterManager,
private val matomoAnalyticsController: MatomoAnalyticsController,
private val userManager: UserManager,
private val deleteUserData: DeleteUserData,
Expand All @@ -78,6 +77,7 @@ class MainPresenter(
val downloadingVersion = MutableLiveData(false)

fun init() {
filterManager.clearAllFilters()
preferences.removeValue(Preference.CURRENT_ORG_UNIT)
disposable.add(
repository.user()
Expand Down Expand Up @@ -158,7 +158,7 @@ class MainPresenter(
Completable.fromCallable {
workManagerController.cancelAllWork()
syncStatusController.restore()
FilterManager.getInstance().clearAllFilters()
filterManager.clearAllFilters()
preferences.setValue(Preference.SESSION_LOCKED, false)
preferences.setValue(Preference.PIN_ENABLED, false)
userManager.d2.dataStoreModule().localDataStore().value(PIN).blockingDeleteIfExist()
Expand Down Expand Up @@ -225,10 +225,6 @@ class MainPresenter(
matomoAnalyticsController.trackEvent(HOME, SETTINGS, CLICK)
}

fun setOpeningFilterToNone() {
filterRepository.collapseAllFilters()
}

fun isPinStored() = repository.isPinStored()

fun launchInitialDataSync() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.setMain
import org.dhis2.commons.filters.data.FilterRepository
import org.dhis2.commons.filters.FilterManager
import org.dhis2.commons.matomo.Categories.Companion.HOME
import org.dhis2.commons.matomo.MatomoAnalyticsController
import org.dhis2.commons.prefs.Preference.Companion.DEFAULT_CAT_COMBO
Expand Down Expand Up @@ -52,7 +52,7 @@ class MainPresenterTest {
private val view: MainView = mock()
private val preferences: PreferenceProvider = mock()
private val workManagerController: WorkManagerController = mock()
private val filterRepository: FilterRepository = mock()
private val filterManager: FilterManager = mock()
private val matomoAnalyticsController: MatomoAnalyticsController = mock()
private val userManager: UserManager = mock()
private val deleteUserData: DeleteUserData = mock()
Expand Down Expand Up @@ -82,7 +82,7 @@ class MainPresenterTest {
schedulers,
preferences,
workManagerController,
filterRepository,
filterManager,
matomoAnalyticsController,
userManager,
deleteUserData,
Expand All @@ -103,6 +103,7 @@ class MainPresenterTest {
verify(view).renderUsername(any())
verify(preferences).setValue(DEFAULT_CAT_COMBO, "uid")
verify(preferences).setValue(PREF_DEFAULT_CAT_OPTION_COMBO, "uid")
verify(filterManager).clearAllFilters()
}

@Test
Expand All @@ -120,6 +121,7 @@ class MainPresenterTest {
verify(workManagerController).cancelAllWork()
verify(preferences).setValue(SESSION_LOCKED, false)
verify(userManager.d2.dataStoreModule().localDataStore().value(PIN)).blockingDeleteIfExist()
verify(filterManager).clearAllFilters()
verify(view).goToLogin(1, false)
}

Expand Down