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
No related branches found
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 ...@@ -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 https://gitlab.fel.cvut.cz/barysole/ackee-test-task/-/blob/master/apk/app-release.apk
## KNOWING ISSUES ## KNOWING ISSUES
- Problem: The characters list doesn't save its scrolling position after navigating to the character detail screen and back. - 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.
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.
No preview for this file type
...@@ -31,4 +31,7 @@ interface CharacterDao { ...@@ -31,4 +31,7 @@ interface CharacterDao {
"ORDER BY id ASC" "ORDER BY id ASC"
) )
fun getCharactersByName(characterName: String): PagingSource<Int, CharacterInfo> 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( ...@@ -65,6 +65,9 @@ class CharacterRemoteMediator(
val response = rickAndMortyApi.getAllCharacters(requiredPage) val response = rickAndMortyApi.getAllCharacters(requiredPage)
val endOfPaginationReached = response.paginationInfo?.next == null val endOfPaginationReached = response.paginationInfo?.next == null
appDatabase.withTransaction { appDatabase.withTransaction {
if (loadType == LoadType.REFRESH) {
appDatabase.characterDao().deleteNotFavorite()
}
appDatabase.paginationDao().insert( appDatabase.paginationDao().insert(
PaginationInfo( PaginationInfo(
PaginationDataType.SearchCharacterPagination.paginationName, PaginationDataType.SearchCharacterPagination.paginationName,
......
...@@ -26,7 +26,8 @@ class CharacterRepositoryImpl @Inject constructor( ...@@ -26,7 +26,8 @@ class CharacterRepositoryImpl @Inject constructor(
return Pager( return Pager(
config = PagingConfig( config = PagingConfig(
pageSize = NETWORK_PAGE_SIZE, pageSize = NETWORK_PAGE_SIZE,
enablePlaceholders = false prefetchDistance = NETWORK_PAGE_SIZE,
initialLoadSize = NETWORK_PAGE_SIZE
), ),
pagingSourceFactory = { pagingSourceFactory = {
CharactersSearchPagingSource( CharactersSearchPagingSource(
...@@ -40,7 +41,9 @@ class CharacterRepositoryImpl @Inject constructor( ...@@ -40,7 +41,9 @@ class CharacterRepositoryImpl @Inject constructor(
override fun getCharactersFlow(): Flow<PagingData<CharacterInfo>> { override fun getCharactersFlow(): Flow<PagingData<CharacterInfo>> {
@OptIn(ExperimentalPagingApi::class) @OptIn(ExperimentalPagingApi::class)
return Pager( 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( remoteMediator = CharacterRemoteMediator(
rickAndMortyApi, rickAndMortyApi,
appDatabase appDatabase
...@@ -53,7 +56,8 @@ class CharacterRepositoryImpl @Inject constructor( ...@@ -53,7 +56,8 @@ class CharacterRepositoryImpl @Inject constructor(
return Pager( return Pager(
config = PagingConfig( config = PagingConfig(
pageSize = NETWORK_PAGE_SIZE, pageSize = NETWORK_PAGE_SIZE,
enablePlaceholders = false prefetchDistance = NETWORK_PAGE_SIZE,
initialLoadSize = NETWORK_PAGE_SIZE
), ),
pagingSourceFactory = { appDatabase.characterDao().getFavorite() } pagingSourceFactory = { appDatabase.characterDao().getFavorite() }
).flow ).flow
......
...@@ -21,12 +21,11 @@ fun FavoriteCharacterListScreen( ...@@ -21,12 +21,11 @@ fun FavoriteCharacterListScreen(
onSelectItem: (id: Long) -> Unit, onSelectItem: (id: Long) -> Unit,
favoriteCharacterListViewModel: FavoriteCharacterListViewModel = hiltViewModel() favoriteCharacterListViewModel: FavoriteCharacterListViewModel = hiltViewModel()
) { ) {
favoriteCharacterListViewModel.refreshList()
val favoriteCharacters =
favoriteCharacterListViewModel.favoriteCharactersPDFlow.collectAsLazyPagingItems()
Surface( Surface(
color = MaterialTheme.colorScheme.background color = MaterialTheme.colorScheme.background
) { ) {
val favoriteCharacters =
favoriteCharacterListViewModel.favoriteCharactersPDFlow.collectAsLazyPagingItems()
if (favoriteCharacters.itemCount == 0) { if (favoriteCharacters.itemCount == 0) {
Column( Column(
modifier = Modifier modifier = Modifier
......
package cz.fel.barysole.ackeetesttask.ui.uielement.character package cz.fel.barysole.ackeetesttask.ui.uielement.character
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.LazyPagingItems
import cz.fel.barysole.ackeetesttask.model.CharacterInfo import cz.fel.barysole.ackeetesttask.model.CharacterInfo
@Composable @Composable
fun CharacterList( fun CharacterList(
characterList: LazyPagingItems<CharacterInfo>, characterList: LazyPagingItems<CharacterInfo>,
onSelectItem: (id: Long) -> Unit onSelectItem: (id: Long) -> Unit
) { ) {
LazyColumn(modifier = Modifier.padding(vertical = 4.dp)) { LazyColumn() {
items( items(
count = characterList.itemCount, count = characterList.itemCount,
contentType = { if (characterList[it] == null) 1 else 0 } 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