-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0575e3b
commit 9adc693
Showing
4 changed files
with
52 additions
and
27 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
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
46 changes: 27 additions & 19 deletions
46
presentation/src/main/java/kr/genti/presentation/main/feed/FeedViewModel.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 |
---|---|---|
@@ -1,32 +1,40 @@ | ||
package kr.genti.presentation.main.feed | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
import kr.genti.core.state.UiState | ||
import kr.genti.domain.entity.response.FeedItemModel | ||
import kr.genti.domain.repository.FeedRepository | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class FeedViewModel | ||
@Inject | ||
constructor( | ||
// private val profileRepository: ProfileRepository, | ||
private val feedRepository: FeedRepository, | ||
) : ViewModel() { | ||
val mockItemList = | ||
listOf( | ||
FeedItemModel( | ||
0, | ||
"https://github.com/Genti2024/Genti-Android/assets/97405341/68bf3348-f732-4874-947d-891f312b241e", | ||
"프랑스 야경을 즐기는 모습을 그려주세요. 항공점퍼를 입고 테라스에 서 있는 모습이에요.", | ||
), | ||
FeedItemModel( | ||
1, | ||
"https://github.com/Genti2024/Genti-Android/assets/97405341/0eb2d7f2-90d2-436a-aa53-4ad7a414d805", | ||
"프랑스 야경을 즐기는 모습을 그려주세요. 항공점퍼를 입고 테라스에 서 있는 모습이에요.", | ||
), | ||
FeedItemModel( | ||
2, | ||
"https://github.com/Genti2024/Genti-Android/assets/97405341/0eb2d7f2-90d2-436a-aa53-4ad7a414d805", | ||
"프랑스 야경을 즐기는 모습을 그려주세요. 항공점퍼를 입고 테라스에 서 있는 모습이에요.", | ||
), | ||
) | ||
private val _getExampleItemsState = | ||
MutableStateFlow<UiState<List<FeedItemModel>>>(UiState.Empty) | ||
val getExampleItemsState: StateFlow<UiState<List<FeedItemModel>>> = _getExampleItemsState | ||
|
||
init { | ||
getExamplePromptsFromServer() | ||
} | ||
|
||
private fun getExamplePromptsFromServer() { | ||
viewModelScope.launch { | ||
_getExampleItemsState.value = UiState.Loading | ||
feedRepository.getExampleItems() | ||
.onSuccess { | ||
_getExampleItemsState.value = UiState.Success(it) | ||
} | ||
.onFailure { t -> | ||
_getExampleItemsState.value = UiState.Failure(t.message.toString()) | ||
} | ||
} | ||
} | ||
} |