-
Notifications
You must be signed in to change notification settings - Fork 0
내기록 화면 구현 #93
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
Merged
Merged
내기록 화면 구현 #93
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
30239f4
feat: 내기록 타이틀 추가
6ae15a4
feat: 내기록 리스트 정보 UI
4a0eedc
feat: 내기록 리스트 Item UI
d6ff8ea
feat: History 데이터 모델 구조 변경 및 로직 추가
01493a2
feat: History 이미지 비율 변경
6e464d4
feat: HistoryViewModel 추가 및 연동
1753a6f
feat: 새로고침 구현
cd3a7c4
feat: 페이징 구현
d406977
feat: onHistoryClick 끌어올리기
e4cd959
feat: 인증 사진 없을 경우 빈 케이스 이미지 사용
ea6b841
feat: Date Format 패턴 try catch 추가
797207c
feat: 멤버수 조건문 추가
f70ba8d
refactor: 페이지 계산 개선
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
9 changes: 9 additions & 0 deletions
9
feature/history/src/main/java/com/goalpanzi/mission_mate/feature/history/HistoryUiState.kt
This file contains hidden or 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,9 @@ | ||
| package com.goalpanzi.mission_mate.feature.history | ||
|
|
||
| import com.goalpanzi.mission_mate.feature.history.model.Histories | ||
|
|
||
| sealed interface HistoryUiState { | ||
| data object Loading : HistoryUiState | ||
| data object Refreshing : HistoryUiState | ||
| data class Success(val histories: Histories) : HistoryUiState | ||
| } |
78 changes: 78 additions & 0 deletions
78
feature/history/src/main/java/com/goalpanzi/mission_mate/feature/history/HistoryViewModel.kt
This file contains hidden or 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,78 @@ | ||
| package com.goalpanzi.mission_mate.feature.history | ||
|
|
||
| import android.util.Log | ||
| import androidx.lifecycle.ViewModel | ||
| import androidx.lifecycle.viewModelScope | ||
| import com.goalpanzi.mission_mate.core.domain.common.DomainResult | ||
| import com.goalpanzi.mission_mate.core.domain.history.usecase.GetMissionHistoriesUseCase | ||
| import com.goalpanzi.mission_mate.feature.history.model.History | ||
| import com.goalpanzi.mission_mate.feature.history.model.toUiModel | ||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.StateFlow | ||
| import kotlinx.coroutines.flow.asStateFlow | ||
| import kotlinx.coroutines.launch | ||
| import javax.inject.Inject | ||
|
|
||
| @HiltViewModel | ||
| class HistoryViewModel @Inject constructor( | ||
| private val getMissionHistoriesUseCase: GetMissionHistoriesUseCase | ||
| ) : ViewModel() { | ||
|
|
||
| private var _page = 0 | ||
|
|
||
| private val _historyState = MutableStateFlow<HistoryUiState>(HistoryUiState.Loading) | ||
| val historyState: StateFlow<HistoryUiState> = _historyState.asStateFlow() | ||
|
|
||
| fun initHistories() { | ||
| viewModelScope.launch { | ||
| _historyState.emit(HistoryUiState.Loading) | ||
| getHistories(0) | ||
| } | ||
| } | ||
|
|
||
| fun refresh() { | ||
| viewModelScope.launch { | ||
| _historyState.emit(HistoryUiState.Refreshing) | ||
| getHistories(0) | ||
| } | ||
| } | ||
|
|
||
| fun fetchHistories() { | ||
| viewModelScope.launch { | ||
| getHistories(_page + 1) | ||
| } | ||
| } | ||
|
|
||
| private suspend fun getHistories(page: Int) { | ||
| _page = page | ||
| getMissionHistoriesUseCase(page).collect { result -> | ||
| val uiState = when (result) { | ||
| is DomainResult.Success -> { | ||
| val data = result.data.toUiModel() | ||
|
|
||
| if(page == 0) HistoryUiState.Success(data) | ||
| else HistoryUiState.Success( | ||
| data.copy(resultList = getCurrentList(historyState.value) + data.resultList) | ||
| ) | ||
| } | ||
|
|
||
| is DomainResult.Error -> { | ||
| HistoryUiState.Loading | ||
| } | ||
|
|
||
| is DomainResult.Exception -> { | ||
| HistoryUiState.Loading | ||
| } | ||
| } | ||
| _historyState.emit(uiState) | ||
| } | ||
| } | ||
|
|
||
| private fun getCurrentList( | ||
| historyUiState: HistoryUiState | ||
| ): List<History> { | ||
| return if (historyUiState is HistoryUiState.Success) historyUiState.histories.resultList | ||
| else emptyList() | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.