-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3469 from dhis2/ANDROAPP-5536
refactor: [ANDROAPP-5536] Search uses paging3
- Loading branch information
Showing
12 changed files
with
225 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchRepositoryImplKt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.dhis2.usescases.searchTrackEntity | ||
|
||
import androidx.paging.PagingData | ||
import kotlinx.coroutines.flow.Flow | ||
import org.dhis2.commons.filters.FilterManager | ||
import org.dhis2.data.search.SearchParametersModel | ||
import org.hisp.dhis.android.core.trackedentity.search.TrackedEntitySearchCollectionRepository | ||
import org.hisp.dhis.android.core.trackedentity.search.TrackedEntitySearchItem | ||
|
||
class SearchRepositoryImplKt( | ||
private val searchRepositoryJava: SearchRepository, | ||
) : SearchRepositoryKt { | ||
|
||
private lateinit var savedSearchParamenters: SearchParametersModel | ||
|
||
private lateinit var savedFilters: FilterManager | ||
|
||
private lateinit var trackedEntityInstanceQuery: TrackedEntitySearchCollectionRepository | ||
|
||
private val fetchedTeiUids = HashSet<String>() | ||
|
||
override fun searchTrackedEntities( | ||
searchParametersModel: SearchParametersModel, | ||
isOnline: Boolean, | ||
): Flow<PagingData<TrackedEntitySearchItem>> { | ||
var allowCache = false | ||
savedSearchParamenters = searchParametersModel.copy() | ||
savedFilters = FilterManager.getInstance().copy() | ||
|
||
if (searchParametersModel != savedSearchParamenters || !FilterManager.getInstance().sameFilters(savedFilters)) { | ||
trackedEntityInstanceQuery = searchRepositoryJava.getFilteredRepository(searchParametersModel) | ||
} else { | ||
trackedEntityInstanceQuery = searchRepositoryJava.getFilteredRepository(searchParametersModel) | ||
allowCache = true | ||
} | ||
|
||
if (fetchedTeiUids.isNotEmpty() && searchParametersModel.selectedProgram == null) { | ||
trackedEntityInstanceQuery = | ||
trackedEntityInstanceQuery.excludeUids().`in`(fetchedTeiUids.toList()) | ||
} | ||
|
||
val pagerFlow = if (isOnline && FilterManager.getInstance().stateFilters.isNotEmpty()) { | ||
trackedEntityInstanceQuery.allowOnlineCache().eq(allowCache).offlineFirst().getPagingData(10) | ||
} else { | ||
trackedEntityInstanceQuery.allowOnlineCache().eq(allowCache).offlineOnly().getPagingData(10) | ||
} | ||
|
||
return pagerFlow | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchRepositoryKt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.dhis2.usescases.searchTrackEntity | ||
|
||
import androidx.paging.PagingData | ||
import kotlinx.coroutines.flow.Flow | ||
import org.dhis2.data.search.SearchParametersModel | ||
import org.hisp.dhis.android.core.trackedentity.search.TrackedEntitySearchItem | ||
|
||
interface SearchRepositoryKt { | ||
|
||
fun searchTrackedEntities( | ||
searchParametersModel: SearchParametersModel, | ||
isOnline: Boolean, | ||
): Flow<PagingData<TrackedEntitySearchItem>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.