Skip to content
Snippets Groups Projects
Commit d0a7cb35 authored by Baryshnikov Oleg's avatar Baryshnikov Oleg
Browse files

Add DB cleaning after refreshing the character list.

Change Pagers configurations.
Recompile apk-file.
parent d2db3313
Branches master
No related tags found
No related merge requests found
......@@ -9,5 +9,4 @@ The application uses the modern Material Design 3 component library, and because
https://gitlab.fel.cvut.cz/barysole/ackee-test-task/-/blob/master/apk/app-release.apk
## KNOWING ISSUES
- Problem: The characters list doesn't save its scrolling position after navigating to the character detail screen and back.
Analysis: LazyColumn gets the characters list from the ViewModel flow by using the ".collectAsLazyPagingItems()" method, and this method retrieves only part of the characters list after navigation.
- Problem: The characters list doesn't accurately save its scrolling position after navigating to the character detail, add it to favorite and navigate back due to list recomposition.
No preview for this file type
......@@ -31,4 +31,7 @@ interface CharacterDao {
"ORDER BY id ASC"
)
fun getCharactersByName(characterName: String): PagingSource<Int, CharacterInfo>
@Query("DELETE FROM CharacterInfo WHERE isFavorite = 0")
suspend fun deleteNotFavorite()
}
\ No newline at end of file
......@@ -65,6 +65,9 @@ class CharacterRemoteMediator(
val response = rickAndMortyApi.getAllCharacters(requiredPage)
val endOfPaginationReached = response.paginationInfo?.next == null
appDatabase.withTransaction {
if (loadType == LoadType.REFRESH) {
appDatabase.characterDao().deleteNotFavorite()
}
appDatabase.paginationDao().insert(
PaginationInfo(
PaginationDataType.SearchCharacterPagination.paginationName,
......
......@@ -26,7 +26,8 @@ class CharacterRepositoryImpl @Inject constructor(
return Pager(
config = PagingConfig(
pageSize = NETWORK_PAGE_SIZE,
enablePlaceholders = false
prefetchDistance = NETWORK_PAGE_SIZE,
initialLoadSize = NETWORK_PAGE_SIZE
),
pagingSourceFactory = {
CharactersSearchPagingSource(
......@@ -40,7 +41,9 @@ class CharacterRepositoryImpl @Inject constructor(
override fun getCharactersFlow(): Flow<PagingData<CharacterInfo>> {
@OptIn(ExperimentalPagingApi::class)
return Pager(
config = PagingConfig(pageSize = NETWORK_PAGE_SIZE, enablePlaceholders = false),
config = PagingConfig(pageSize = NETWORK_PAGE_SIZE,
prefetchDistance = NETWORK_PAGE_SIZE,
initialLoadSize = NETWORK_PAGE_SIZE),
remoteMediator = CharacterRemoteMediator(
rickAndMortyApi,
appDatabase
......@@ -53,7 +56,8 @@ class CharacterRepositoryImpl @Inject constructor(
return Pager(
config = PagingConfig(
pageSize = NETWORK_PAGE_SIZE,
enablePlaceholders = false
prefetchDistance = NETWORK_PAGE_SIZE,
initialLoadSize = NETWORK_PAGE_SIZE
),
pagingSourceFactory = { appDatabase.characterDao().getFavorite() }
).flow
......
......@@ -21,12 +21,11 @@ fun FavoriteCharacterListScreen(
onSelectItem: (id: Long) -> Unit,
favoriteCharacterListViewModel: FavoriteCharacterListViewModel = hiltViewModel()
) {
favoriteCharacterListViewModel.refreshList()
val favoriteCharacters =
favoriteCharacterListViewModel.favoriteCharactersPDFlow.collectAsLazyPagingItems()
Surface(
color = MaterialTheme.colorScheme.background
) {
val favoriteCharacters =
favoriteCharacterListViewModel.favoriteCharactersPDFlow.collectAsLazyPagingItems()
if (favoriteCharacters.itemCount == 0) {
Column(
modifier = Modifier
......
package cz.fel.barysole.ackeetesttask.ui.uielement.character
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.paging.compose.LazyPagingItems
import cz.fel.barysole.ackeetesttask.model.CharacterInfo
@Composable
fun CharacterList(
characterList: LazyPagingItems<CharacterInfo>,
onSelectItem: (id: Long) -> Unit
) {
LazyColumn(modifier = Modifier.padding(vertical = 4.dp)) {
LazyColumn() {
items(
count = characterList.itemCount,
contentType = { if (characterList[it] == null) 1 else 0 }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment