fixed visits update

This commit is contained in:
Izlydov 2025-02-20 16:32:27 +03:00
parent e13035320d
commit a40c448fc2
2 changed files with 16 additions and 2 deletions

View File

@ -108,6 +108,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) {
private fun refreshData() { private fun refreshData() {
viewModel.getInfo() viewModel.getInfo()
viewModel.resetVisits()
viewModel.visitListState.collectWithLifecycle(this) { data -> viewModel.visitListState.collectWithLifecycle(this) { data ->
adapter.submitData(data) adapter.submitData(data)
} }

View File

@ -32,7 +32,7 @@ class ProfileViewModel() : ViewModel() {
val _state = MutableStateFlow<State>(State.Loading) val _state = MutableStateFlow<State>(State.Loading)
val state = _state.asStateFlow() val state = _state.asStateFlow()
val visitListState = Pager( var visitListState = Pager(
config = PagingConfig( config = PagingConfig(
pageSize = 20, pageSize = 20,
enablePlaceholders = false, enablePlaceholders = false,
@ -43,7 +43,7 @@ class ProfileViewModel() : ViewModel() {
}.flow }.flow
.cachedIn(viewModelScope) .cachedIn(viewModelScope)
val visitListStateFromLogin = Pager( var visitListStateFromLogin = Pager(
config = PagingConfig(pageSize = 20, enablePlaceholders = false, maxSize = 100) config = PagingConfig(pageSize = 20, enablePlaceholders = false, maxSize = 100)
) { ) {
VisitListPagingSource { pageNum, pageSize -> VisitListPagingSource { pageNum, pageSize ->
@ -55,6 +55,19 @@ class ProfileViewModel() : ViewModel() {
UserServiceST.getInstance().logout() UserServiceST.getInstance().logout()
} }
fun resetVisits(){
visitListState = Pager(
config = PagingConfig(
pageSize = 20,
enablePlaceholders = false,
maxSize = 100
)
) {
VisitListPagingSource(VisitServiceST.getInstance()::getMyLastVisits)
}.flow
.cachedIn(viewModelScope)
}
fun getInfo() { fun getInfo() {
viewModelScope.launch { viewModelScope.launch {
UserServiceST.getInstance().getInfo().fold( UserServiceST.getInstance().getInfo().fold(