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-6673] Recover home filters #3931

Merged
merged 5 commits into from
Dec 18, 2024
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
113 changes: 111 additions & 2 deletions app/src/main/java/org/dhis2/usescases/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.transition.ChangeBounds
import android.transition.TransitionManager
import android.view.View
import android.webkit.MimeTypeMap
import android.widget.TextView
Expand All @@ -21,6 +23,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.constraintlayout.widget.ConstraintSet
import androidx.core.app.NotificationCompat
import androidx.databinding.DataBindingUtil
import androidx.drawerlayout.widget.DrawerLayout
Expand All @@ -35,6 +38,11 @@ import org.dhis2.bindings.app
import org.dhis2.bindings.hasPermissions
import org.dhis2.commons.animations.hide
import org.dhis2.commons.animations.show
import org.dhis2.commons.date.DateUtils
import org.dhis2.commons.filters.FilterItem
import org.dhis2.commons.filters.FilterManager
import org.dhis2.commons.filters.FiltersAdapter
import org.dhis2.commons.orgunitselector.OUTreeFragment
import org.dhis2.commons.sync.OnDismissListener
import org.dhis2.commons.sync.SyncContext
import org.dhis2.databinding.ActivityMainBinding
Expand Down Expand Up @@ -68,11 +76,15 @@ class MainActivity :
DrawerLayout.DrawerListener {

private lateinit var binding: ActivityMainBinding

lateinit var mainComponent: MainComponent

@Inject
lateinit var presenter: MainPresenter

@Inject
lateinit var newAdapter: FiltersAdapter

@Inject
lateinit var pageConfigurator: NavigationPageConfigurator

Expand All @@ -83,6 +95,8 @@ class MainActivity :
// no-op
}

private var backDropActive = false

private val requestWritePermissions =
registerForActivityResult(
ActivityResultContracts.RequestPermission(),
Expand Down Expand Up @@ -136,9 +150,14 @@ class MainActivity :
mainNavigator = MainNavigator(
dispatcherProvider = presenter.dispatcherProvider,
supportFragmentManager,
{ /*no-op*/ },
) { titleRes, _, showBottomNavigation ->
{
if (backDropActive) {
showHideFilter()
}
},
) { titleRes, showFilterButton, showBottomNavigation ->
setTitle(getString(titleRes))
setFilterButtonVisibility(showFilterButton)
setBottomNavigationVisibility(showBottomNavigation)
}
super.onCreate(savedInstanceState)
Expand All @@ -157,6 +176,8 @@ class MainActivity :

binding.mainDrawerLayout.addDrawerListener(this)

binding.filterRecycler.adapter = newAdapter

setUpNavigationBar()
setUpDevelopmentMode()

Expand Down Expand Up @@ -218,6 +239,8 @@ class MainActivity :
super.onResume()
if (sessionManagerServiceImpl.isUserLoggedIn()) {
presenter.init()
presenter.initFilters()
binding.totalFilters = FilterManager.getInstance().totalFilters
}
}

Expand Down Expand Up @@ -289,10 +312,12 @@ class MainActivity :
when (it.running) {
true -> {
binding.syncActionButton.visibility = View.GONE
setFilterButtonVisibility(false)
setBottomNavigationVisibility(false)
}

false -> {
setFilterButtonVisibility(true)
binding.syncActionButton.visibility = View.VISIBLE
setBottomNavigationVisibility(true)
presenter.onDataSuccess()
Expand Down Expand Up @@ -329,6 +354,35 @@ class MainActivity :
}
}

override fun showHideFilter() {
val transition = ChangeBounds()
transition.duration = 200
TransitionManager.beginDelayedTransition(binding.backdropLayout, transition)
backDropActive = !backDropActive
val initSet = ConstraintSet()
initSet.clone(binding.backdropLayout)
if (backDropActive) {
initSet.connect(
R.id.fragment_container,
ConstraintSet.TOP,
R.id.filterRecycler,
ConstraintSet.BOTTOM,
50,
)
binding.navigationBar.hide()
} else {
initSet.connect(
R.id.fragment_container,
ConstraintSet.TOP,
R.id.toolbar,
ConstraintSet.BOTTOM,
0,
)
binding.navigationBar.show()
}
initSet.applyTo(binding.backdropLayout)
}

override fun showGranularSync() {
SyncStatusDialog.Builder()
.withContext(this)
Expand All @@ -353,6 +407,37 @@ class MainActivity :
.show("ALL_SYNC")
}

override fun updateFilters(totalFilters: Int) {
binding.totalFilters = totalFilters
}

override fun showPeriodRequest(periodRequest: FilterManager.PeriodRequest) {
if (periodRequest == FilterManager.PeriodRequest.FROM_TO) {
DateUtils.getInstance()
.fromCalendarSelector(this) { FilterManager.getInstance().addPeriod(it) }
} else {
DateUtils.getInstance()
.showPeriodDialog(
this,
{ datePeriods -> FilterManager.getInstance().addPeriod(datePeriods) },
true,
{ FilterManager.getInstance().addPeriod(null) },
)
}
}

override fun openOrgUnitTreeSelector() {
OUTreeFragment.Builder()
.withPreselectedOrgUnits(
FilterManager.getInstance().orgUnitFilters.map { it.uid() }.toMutableList(),
)
.onSelection { selectedOrgUnits ->
presenter.setOrgUnitFilters(selectedOrgUnits)
}
.build()
.show(supportFragmentManager, "OUTreeFragment")
}

override fun goToLogin(accountsCount: Int, isDeletion: Boolean) {
startActivity(
LoginActivity::class.java,
Expand All @@ -373,6 +458,19 @@ class MainActivity :
binding.executePendingBindings()
}

private fun setFilterButtonVisibility(showFilterButton: Boolean) {
binding.filterActionButton.visibility = if (showFilterButton && presenter.hasFilters()) {
View.VISIBLE
} else {
View.GONE
}
binding.syncActionButton.visibility = if (showFilterButton) {
View.VISIBLE
} else {
View.GONE
}
}

override fun openDrawer(gravity: Int) {
if (!binding.mainDrawerLayout.isDrawerOpen(gravity)) {
binding.mainDrawerLayout.openDrawer(gravity)
Expand All @@ -381,6 +479,14 @@ class MainActivity :
}
}

override fun setFilters(filters: List<FilterItem>) {
newAdapter.submitList(filters)
}

override fun hideFilters() {
binding.filterActionButton.visibility = View.GONE
}

override fun onLockClick() {
if (!presenter.isPinStored()) {
binding.mainDrawerLayout.closeDrawers()
Expand Down Expand Up @@ -425,16 +531,19 @@ class MainActivity :
}

override fun onDrawerStateChanged(newState: Int) {
// no op
}

override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
// no op
}

override fun onDrawerClosed(drawerView: View) {
initCurrentScreen()
}

override fun onDrawerOpened(drawerView: View) {
// no op
}

private fun initCurrentScreen() {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/org/dhis2/usescases/main/MainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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.FiltersAdapter
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,6 +34,7 @@ class MainModule(val view: MainView, private val forceToNotSynced: Boolean) {
preferences: PreferenceProvider,
workManagerController: WorkManagerController,
filterManager: FilterManager,
filterRepository: FilterRepository,
matomoAnalyticsController: MatomoAnalyticsController,
userManager: UserManager,
deleteUserData: DeleteUserData,
Expand All @@ -47,6 +50,7 @@ class MainModule(val view: MainView, private val forceToNotSynced: Boolean) {
preferences,
workManagerController,
filterManager,
filterRepository,
matomoAnalyticsController,
userManager,
deleteUserData,
Expand Down Expand Up @@ -74,6 +78,12 @@ class MainModule(val view: MainView, private val forceToNotSynced: Boolean) {
return HomeRepositoryImpl(d2, charts, featureConfigRepositoryImpl)
}

@Provides
@PerActivity
fun provideNewFiltersAdapter(): FiltersAdapter {
return FiltersAdapter()
}

@Provides
@PerActivity
fun providePageConfigurator(
Expand Down
Loading
Loading