-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
4 changed files
with
80 additions
and
15 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
core/domain/src/main/java/com/withpeace/withpeace/core/domain/model/post/Post.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,12 +1,12 @@ | ||
package com.withpeace.withpeace.core.domain.model.post | ||
|
||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
|
||
data class Post( | ||
val postId: Long, | ||
val title: String, | ||
val content: String, | ||
val postTopic: PostTopic, | ||
val createDate: LocalDate, | ||
val createDate: LocalDateTime, | ||
val postImageUrl: String, | ||
) |
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
36 changes: 34 additions & 2 deletions
36
feature/postlist/src/main/java/com/withpeace/withpeace/feature/postlist/PostListViewModel.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,10 +1,42 @@ | ||
package com.withpeace.withpeace.feature.postlist | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.withpeace.withpeace.core.domain.model.post.Post | ||
import com.withpeace.withpeace.core.domain.model.post.PostTopic | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.stateIn | ||
import kotlinx.coroutines.flow.update | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
import java.time.LocalTime | ||
import javax.inject.Inject | ||
|
||
class PostListViewModel @Inject constructor( | ||
class PostListViewModel @Inject constructor() : ViewModel() { | ||
|
||
) : ViewModel() { | ||
private val _currentTopic = MutableStateFlow(PostTopic.FREEDOM) | ||
val currentTopic = _currentTopic.asStateFlow() | ||
|
||
val postList = currentTopic.map { | ||
getPost(it) | ||
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), emptyList()) | ||
|
||
fun onTopicChanged(postTopic: PostTopic) { | ||
_currentTopic.update { postTopic } | ||
} | ||
|
||
// API 나오기 전까지 임시로 이렇게 하겠습니다! | ||
private fun getPost(postTopic: PostTopic) = List(10) { | ||
Post( | ||
postId = 1746, | ||
title = postTopic.toString(), | ||
content = postTopic.toString(), | ||
postTopic = postTopic, | ||
createDate = LocalDateTime.of(LocalDate.of(2024, 3, 18), LocalTime.of(12, 0, 0)), | ||
postImageUrl = "http://withpeace.s3-website.kr.object.ncloudstorage.com/userProfile/1", | ||
) | ||
} | ||
} |
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