-
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
26 changed files
with
327 additions
and
189 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
10 changes: 10 additions & 0 deletions
10
core/navigation/src/main/java/tht/core/navigation/ChatNavigation.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package tht.core.navigation | ||
|
||
import androidx.fragment.app.FragmentManager | ||
|
||
interface ChatNavigation { | ||
fun navigateChat( | ||
fragmentManager: FragmentManager, | ||
fragmentContainerResourceId: Int | ||
) | ||
} |
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,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<manifest> | ||
|
||
<application> | ||
<activity | ||
android:name=".screen.detail.ChatDetailActivity" | ||
android:exported="false" /> | ||
</application> | ||
|
||
</manifest> | ||
</manifest> |
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
75 changes: 75 additions & 0 deletions
75
feature/chat/src/main/java/tht/feature/chat/chat/screen/ChatEmptyScreen.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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package tht.feature.chat.chat.screen | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import com.example.compose_ui.component.button.ThtButton | ||
import com.example.compose_ui.component.text.headline.ThtHeadline4 | ||
import com.example.compose_ui.component.text.headline.ThtHeadline5 | ||
import com.example.compose_ui.component.text.p.ThtP1 | ||
import tht.feature.chat.R | ||
|
||
@Composable | ||
internal fun ChatEmptyScreen( | ||
onClickChangeTitle: () -> Unit | ||
) { | ||
Column( | ||
modifier = Modifier.fillMaxSize(), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.Center | ||
) { | ||
Column( | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.Center | ||
) { | ||
Image( | ||
painter = painterResource(id = R.drawable.ic_empty), | ||
contentDescription = null | ||
) | ||
Spacer(modifier = Modifier.height(16.dp)) | ||
ThtHeadline4( | ||
text = "아직 매칭된 무디가 없어요", | ||
fontWeight = FontWeight.W600, | ||
color = Color.White | ||
) | ||
Spacer(modifier = Modifier.height(6.dp)) | ||
ThtP1( | ||
text = "대화가 잘 통하는 무디를 찾아볼까요?", | ||
fontWeight = FontWeight.W400, | ||
color = Color(0xFF8D8D8D) | ||
) | ||
} | ||
Spacer(modifier = Modifier.height(64.dp)) | ||
ThtButton( | ||
modifier = Modifier | ||
.clip(RoundedCornerShape(16.dp)) | ||
.border(1.dp, Color.White, RoundedCornerShape(16.dp)) | ||
.padding(horizontal = 70.dp), | ||
backgroundColor = Color.Transparent, | ||
contentColor = Color.White, | ||
onClick = onClickChangeTitle, | ||
content = { | ||
ThtHeadline5( | ||
text = "무디들 만나러 가기", | ||
fontWeight = FontWeight.W700, | ||
color = Color.White | ||
) | ||
} | ||
) | ||
Spacer(modifier = Modifier.height(56.dp)) | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...re/chat/screen/chatlist/ChatListScreen.kt → ...eature/chat/chat/screen/ChatListScreen.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
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: 46 additions & 0 deletions
46
feature/chat/src/main/java/tht/feature/chat/chat/screen/Extensions.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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package tht.feature.chat.chat.screen | ||
|
||
import android.os.Build | ||
import androidx.annotation.RequiresApi | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.DisposableEffect | ||
import androidx.compose.runtime.rememberUpdatedState | ||
import androidx.compose.ui.platform.LocalLifecycleOwner | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleEventObserver | ||
import androidx.lifecycle.LifecycleOwner | ||
import java.time.Instant | ||
import java.time.LocalDateTime | ||
import java.time.ZoneOffset | ||
import java.time.format.DateTimeFormatter | ||
|
||
@Composable | ||
fun OnLifecycleEvent( | ||
onEvent: ( | ||
owner: LifecycleOwner, | ||
event: Lifecycle.Event, | ||
) -> Unit | ||
) { | ||
val eventHandler = rememberUpdatedState(onEvent) | ||
val lifecycleOwner = rememberUpdatedState(LocalLifecycleOwner.current) | ||
|
||
DisposableEffect(lifecycleOwner.value) { | ||
val lifecycle = lifecycleOwner.value.lifecycle | ||
val observer = LifecycleEventObserver { owner, event -> | ||
eventHandler.value(owner, event) | ||
} | ||
|
||
lifecycle.addObserver(observer) | ||
onDispose { | ||
lifecycle.removeObserver(observer) | ||
} | ||
} | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.O) | ||
fun format(milliseconds: Long): String { | ||
return LocalDateTime.ofInstant( | ||
Instant.ofEpochMilli(milliseconds), | ||
ZoneOffset.systemDefault() | ||
).format(DateTimeFormatter.ISO_DATE) | ||
} |
3 changes: 3 additions & 0 deletions
3
feature/chat/src/main/java/tht/feature/chat/chat/state/ChatDetailSideEffect.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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package tht.feature.chat.chat.state | ||
|
||
sealed class ChatDetailSideEffect |
2 changes: 1 addition & 1 deletion
2
...viewmodel/detail/state/ChatDetailState.kt → ...eature/chat/chat/state/ChatDetailState.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
3 changes: 3 additions & 0 deletions
3
feature/chat/src/main/java/tht/feature/chat/chat/state/ChatSideEffect.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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package tht.feature.chat.chat.state | ||
|
||
sealed class ChatSideEffect |
2 changes: 1 addition & 1 deletion
2
...feature/chat/viewmodel/state/ChatState.kt → .../tht/feature/chat/chat/state/ChatState.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
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
85 changes: 85 additions & 0 deletions
85
feature/chat/src/main/java/tht/feature/chat/chat/viewmodel/ChatViewModel.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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package tht.feature.chat.chat.viewmodel | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.example.compose_ui.common.viewmodel.Container | ||
import com.example.compose_ui.common.viewmodel.Store | ||
import com.example.compose_ui.common.viewmodel.intent | ||
import com.example.compose_ui.common.viewmodel.store | ||
import com.tht.tht.domain.chat.model.ChatListModel | ||
import com.tht.tht.domain.chat.usecase.GetChatListUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.collections.immutable.persistentListOf | ||
import kotlinx.collections.immutable.toImmutableList | ||
import kotlinx.coroutines.launch | ||
import tht.feature.chat.chat.state.ChatSideEffect | ||
import tht.feature.chat.chat.state.ChatState | ||
import tht.feature.chat.mapper.toModel | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
internal class ChatViewModel @Inject constructor( | ||
private val getChatListUseCase: GetChatListUseCase | ||
) : ViewModel(), Container<ChatState, ChatSideEffect> { | ||
override val store: Store<ChatState, ChatSideEffect> = | ||
store(initialState = ChatState.ChatList(isLoading = true, chatList = persistentListOf())) | ||
|
||
fun getChatList() { | ||
viewModelScope.launch { | ||
val chatList = getChatListUseCase().getOrNull() ?: listOf() | ||
intent { | ||
reduce { | ||
if (chatList.isEmpty()) { | ||
ChatState.Empty | ||
} else { | ||
ChatState.ChatList( | ||
isLoading = false, | ||
chatList = chatList.map { it.toModel() }.toImmutableList() | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun getFakeChatList() { | ||
viewModelScope.launch { | ||
intent { | ||
reduce { | ||
ChatState.ChatList( | ||
isLoading = false, | ||
chatList = listOf( | ||
ChatListModel( | ||
chatRoomIdx = 1L, | ||
partnerName = "최웅재", | ||
partnerProfileUrl = "", | ||
currentMessage = "안녕", | ||
messageTime = "2020.08.08" | ||
), | ||
ChatListModel( | ||
chatRoomIdx = 2L, | ||
partnerName = "최웅재", | ||
partnerProfileUrl = "", | ||
currentMessage = "안녕", | ||
messageTime = "2020.08.08" | ||
), | ||
ChatListModel( | ||
chatRoomIdx = 3L, | ||
partnerName = "최웅재", | ||
partnerProfileUrl = "", | ||
currentMessage = "안녕", | ||
messageTime = "2020.08.08" | ||
), ChatListModel( | ||
chatRoomIdx = 4L, | ||
partnerName = "최웅재", | ||
partnerProfileUrl = "", | ||
currentMessage = "안녕", | ||
messageTime = "2020.08.08" | ||
) | ||
).map { it.toModel() }.toImmutableList() | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
feature/chat/src/main/java/tht/feature/chat/navigation/ChatDestination.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package tht.feature.chat.navigation | ||
|
||
interface ChatDestination { | ||
val route: String | ||
} | ||
|
||
object Chat : ChatDestination { | ||
override val route: String = "chat" | ||
} | ||
|
||
object ChatDetail : ChatDestination { | ||
override val route: String = "chat-detail" | ||
} |
Oops, something went wrong.