From 6e5c23564a27736df121b20428f0398ce4ddc03e Mon Sep 17 00:00:00 2001 From: gaeun Date: Fri, 9 Aug 2024 10:43:26 +0900 Subject: [PATCH 1/9] =?UTF-8?q?fix:=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C?= =?UTF-8?q?=20=EB=8D=94=EB=AF=B8=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EA=B8=88?= =?UTF-8?q?=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/ui/chatlist/ChatListViewModel.kt | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListViewModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListViewModel.kt index 1719e4edf..9a9ba2a37 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListViewModel.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListViewModel.kt @@ -23,14 +23,7 @@ class ChatListViewModel( fun getChats() { viewModelScope.launch { chatRepository.getChatList().onSuccess { room -> - _chats.value = room.chatRooms.map { it.toUiModel() } + - ChatListUiModel( - "", "", 2, 0, - ChatDateTime.Yesterday( - LocalDateTime.now(), - ), - "", 1, - ) + _chats.value = room.chatRooms.map { it.toUiModel() } memberId = room.myMemberId } } From 4d95f3f8ed47065335b961aa000e875520ba6c82 Mon Sep 17 00:00:00 2001 From: gaeun Date: Sun, 11 Aug 2024 23:49:19 +0900 Subject: [PATCH 2/9] =?UTF-8?q?feat:=20=EC=B1=84=ED=8C=85=20dataSource=20?= =?UTF-8?q?=EB=B0=8F=20useCase=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../friendogly/application/di/AppModule.kt | 9 ++++++++- .../data/repository/ChatRepositoryImpl.kt | 13 +++++-------- .../friendogly/data/source/ChatDataSource.kt | 13 +++++++++++++ .../domain/usecase/GetChatListUseCase.kt | 10 ++++++++++ .../domain/usecase/GetChatMemberUseCase.kt | 10 ++++++++++ .../happy/friendogly/remote/api/ChatService.kt | 3 ++- .../remote/source/ChatDataSourceImpl.kt | 18 ++++++++++++++++++ 7 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 android/app/src/main/java/com/happy/friendogly/data/source/ChatDataSource.kt create mode 100644 android/app/src/main/java/com/happy/friendogly/domain/usecase/GetChatListUseCase.kt create mode 100644 android/app/src/main/java/com/happy/friendogly/domain/usecase/GetChatMemberUseCase.kt create mode 100644 android/app/src/main/java/com/happy/friendogly/remote/source/ChatDataSourceImpl.kt diff --git a/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt b/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt index 5deb9fa16..f26d98fe0 100644 --- a/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt +++ b/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt @@ -16,6 +16,7 @@ import com.happy.friendogly.data.repository.WebSocketRepositoryImpl import com.happy.friendogly.data.repository.WoofRepositoryImpl import com.happy.friendogly.data.source.AddressDataSource import com.happy.friendogly.data.source.AuthDataSource +import com.happy.friendogly.data.source.ChatDataSource import com.happy.friendogly.data.source.ClubDataSource import com.happy.friendogly.data.source.KakaoLoginDataSource import com.happy.friendogly.data.source.MemberDataSource @@ -37,6 +38,8 @@ import com.happy.friendogly.domain.usecase.DeleteAddressUseCase import com.happy.friendogly.domain.usecase.DeleteClubMemberUseCase import com.happy.friendogly.domain.usecase.DeleteTokenUseCase import com.happy.friendogly.domain.usecase.GetAddressUseCase +import com.happy.friendogly.domain.usecase.GetChatListUseCase +import com.happy.friendogly.domain.usecase.GetChatMemberUseCase import com.happy.friendogly.domain.usecase.GetClubUseCase import com.happy.friendogly.domain.usecase.GetFootprintInfoUseCase import com.happy.friendogly.domain.usecase.GetFootprintMarkBtnInfoUseCase @@ -67,6 +70,7 @@ import com.happy.friendogly.remote.api.BaseUrl import com.happy.friendogly.remote.api.WebSocketService import com.happy.friendogly.remote.di.RemoteModule import com.happy.friendogly.remote.source.AuthDataSourceImpl +import com.happy.friendogly.remote.source.ChatDataSourceImpl import com.happy.friendogly.remote.source.ClubDataSourceImpl import com.happy.friendogly.remote.source.MemberDataSourceImpl import com.happy.friendogly.remote.source.PetDataSourceImpl @@ -152,6 +156,7 @@ class AppModule(context: Context) { private val petDataSource: PetDataSource = PetDataSourceImpl(service = petService) private val webSocketDataSource: WebSocketDataSource = WebSocketDataSourceImpl(service = webSocketService) + private val chatDataSource:ChatDataSource = ChatDataSourceImpl(service = chatService) // repository private val authRepository: AuthRepository = AuthRepositoryImpl(source = authDataSource) @@ -166,7 +171,7 @@ class AppModule(context: Context) { AddressRepositoryImpl(addressDataSource = addressDataSource) val webSocketRepository: WebSocketRepository = WebSocketRepositoryImpl(source = webSocketDataSource) - val chatRepository: ChatRepository = ChatRepositoryImpl(service = chatService) + val chatRepository: ChatRepository = ChatRepositoryImpl(source = chatDataSource) // use case val postKakaoLoginUseCase: PostKakaoLoginUseCase = @@ -205,6 +210,8 @@ class AppModule(context: Context) { val saveAddressUseCase: SaveAddressUseCase = SaveAddressUseCase(repository = addressRepository) val deleteAddressUseCase: DeleteAddressUseCase = DeleteAddressUseCase(repository = addressRepository) + val getChatListUseCase: GetChatListUseCase = GetChatListUseCase(repository = chatRepository) + val getChatMemberUseCase: GetChatMemberUseCase = GetChatMemberUseCase(repository = chatRepository) companion object { private var instance: AppModule? = null diff --git a/android/app/src/main/java/com/happy/friendogly/data/repository/ChatRepositoryImpl.kt b/android/app/src/main/java/com/happy/friendogly/data/repository/ChatRepositoryImpl.kt index 8eb21052d..7335512c6 100644 --- a/android/app/src/main/java/com/happy/friendogly/data/repository/ChatRepositoryImpl.kt +++ b/android/app/src/main/java/com/happy/friendogly/data/repository/ChatRepositoryImpl.kt @@ -1,20 +1,17 @@ package com.happy.friendogly.data.repository import com.happy.friendogly.data.mapper.toDomain +import com.happy.friendogly.data.source.ChatDataSource import com.happy.friendogly.domain.model.ChatMember import com.happy.friendogly.domain.model.ChatRooms import com.happy.friendogly.domain.repository.ChatRepository -import com.happy.friendogly.remote.api.ChatService -import com.happy.friendogly.remote.mapper.toData -class ChatRepositoryImpl(private val service: ChatService) : ChatRepository { +class ChatRepositoryImpl(private val source: ChatDataSource) : ChatRepository { override suspend fun getChatList(): Result = - runCatching { - service.getChatList().data.toData().toDomain() - } + source.getChatList().mapCatching { it.toDomain() } override suspend fun getMembers(chatRoomId: Long): Result> = - runCatching { - service.getChatMembers(chatRoomId).data.map { it.toData() }.map { it.toDomain() } + source.getMembers(chatRoomId).mapCatching { member -> + member.map { it.toDomain() } } } diff --git a/android/app/src/main/java/com/happy/friendogly/data/source/ChatDataSource.kt b/android/app/src/main/java/com/happy/friendogly/data/source/ChatDataSource.kt new file mode 100644 index 000000000..b8999612d --- /dev/null +++ b/android/app/src/main/java/com/happy/friendogly/data/source/ChatDataSource.kt @@ -0,0 +1,13 @@ +package com.happy.friendogly.data.source + +import com.happy.friendogly.data.model.ChatMemberDto +import com.happy.friendogly.data.model.ChatRoomListDto +import com.happy.friendogly.domain.model.ChatMember +import com.happy.friendogly.domain.model.ChatRooms + +interface ChatDataSource { + + suspend fun getChatList(): Result + + suspend fun getMembers(chatRoomId: Long): Result> +} diff --git a/android/app/src/main/java/com/happy/friendogly/domain/usecase/GetChatListUseCase.kt b/android/app/src/main/java/com/happy/friendogly/domain/usecase/GetChatListUseCase.kt new file mode 100644 index 000000000..0b2ef5d5b --- /dev/null +++ b/android/app/src/main/java/com/happy/friendogly/domain/usecase/GetChatListUseCase.kt @@ -0,0 +1,10 @@ +package com.happy.friendogly.domain.usecase + +import com.happy.friendogly.domain.model.ChatRooms +import com.happy.friendogly.domain.repository.ChatRepository + +class GetChatListUseCase( + val repository: ChatRepository, +) { + suspend operator fun invoke(): Result = repository.getChatList() +} diff --git a/android/app/src/main/java/com/happy/friendogly/domain/usecase/GetChatMemberUseCase.kt b/android/app/src/main/java/com/happy/friendogly/domain/usecase/GetChatMemberUseCase.kt new file mode 100644 index 000000000..02700b0d8 --- /dev/null +++ b/android/app/src/main/java/com/happy/friendogly/domain/usecase/GetChatMemberUseCase.kt @@ -0,0 +1,10 @@ +package com.happy.friendogly.domain.usecase + +import com.happy.friendogly.domain.model.ChatMember +import com.happy.friendogly.domain.repository.ChatRepository + +class GetChatMemberUseCase( + val repository: ChatRepository, +) { + suspend operator fun invoke(chatRoomId: Long): Result> = repository.getMembers(chatRoomId) +} diff --git a/android/app/src/main/java/com/happy/friendogly/remote/api/ChatService.kt b/android/app/src/main/java/com/happy/friendogly/remote/api/ChatService.kt index 83a9882be..40518ba45 100644 --- a/android/app/src/main/java/com/happy/friendogly/remote/api/ChatService.kt +++ b/android/app/src/main/java/com/happy/friendogly/remote/api/ChatService.kt @@ -3,6 +3,7 @@ package com.happy.friendogly.remote.api import com.happy.friendogly.remote.model.response.BaseResponse import com.happy.friendogly.remote.model.response.ChatClubMemberResponse import com.happy.friendogly.remote.model.response.ChatRoomListResponse +import okhttp3.Response import retrofit2.http.GET import retrofit2.http.Path @@ -13,5 +14,5 @@ interface ChatService { @GET(ApiClient.Chat.MEMBERS) suspend fun getChatMembers( @Path("chatRoomId") chatRoomId: Long, - ): BaseResponse> + ): retrofit2.Response> } diff --git a/android/app/src/main/java/com/happy/friendogly/remote/source/ChatDataSourceImpl.kt b/android/app/src/main/java/com/happy/friendogly/remote/source/ChatDataSourceImpl.kt new file mode 100644 index 000000000..aa5a63568 --- /dev/null +++ b/android/app/src/main/java/com/happy/friendogly/remote/source/ChatDataSourceImpl.kt @@ -0,0 +1,18 @@ +package com.happy.friendogly.remote.source + +import com.happy.friendogly.data.model.ChatMemberDto +import com.happy.friendogly.data.model.ChatRoomListDto +import com.happy.friendogly.data.source.ChatDataSource +import com.happy.friendogly.remote.api.ChatService +import com.happy.friendogly.remote.mapper.toData + +class ChatDataSourceImpl(private val service:ChatService):ChatDataSource { + override suspend fun getChatList(): Result = runCatching { + service.getChatList().data.toData() + } + + override suspend fun getMembers(chatRoomId: Long): Result> = runCatching { + service.getChatMembers(chatRoomId).body()?.map { it.toData() } ?: emptyList() + } + +} From 51cc8b0e0187c72efdd17572945a3cfa78f25669 Mon Sep 17 00:00:00 2001 From: gaeun Date: Sun, 11 Aug 2024 23:52:44 +0900 Subject: [PATCH 3/9] =?UTF-8?q?feat:=20=EC=B1=84=ED=8C=85=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20api=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/chatlist/ChatListFragment.kt | 2 +- .../ui/chatlist/ChatListViewModel.kt | 11 ++-- .../ui/chatlist/adapter/ChatListAdapter.kt | 6 +- .../ui/chatlist/chat/ChatActivity.kt | 13 +++- .../ui/chatlist/chat/ChatViewModel.kt | 19 ------ .../ui/chatlist/chatinfo/ChatInfoMapper.kt | 12 ++++ .../ui/chatlist/chatinfo/ChatInfoSideSheet.kt | 55 +++++++++++----- .../ui/chatlist/chatinfo/ChatInfoUiModel.kt | 2 +- .../ui/chatlist/chatinfo/ChatInfoViewModel.kt | 65 ++++++++++++------- 9 files changed, 115 insertions(+), 70 deletions(-) create mode 100644 android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoMapper.kt diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListFragment.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListFragment.kt index 293673d65..c25673f73 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListFragment.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListFragment.kt @@ -13,7 +13,7 @@ class ChatListFragment : ChatListNavigationAction { private val viewModel: ChatListViewModel by viewModels { ChatListViewModel.factory( - AppModule.getInstance().chatRepository, + AppModule.getInstance().getChatListUseCase, ) } private lateinit var adapter: ChatListAdapter diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListViewModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListViewModel.kt index 07a73ba8c..317563291 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListViewModel.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListViewModel.kt @@ -5,22 +5,25 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope import com.happy.friendogly.domain.repository.ChatRepository +import com.happy.friendogly.domain.usecase.GetChatListUseCase +import com.happy.friendogly.domain.usecase.GetChatMemberUseCase import com.happy.friendogly.presentation.base.BaseViewModel import com.happy.friendogly.presentation.base.BaseViewModelFactory import com.happy.friendogly.presentation.ui.chatlist.uimodel.ChatListUiModel import kotlinx.coroutines.launch class ChatListViewModel( - private val chatRepository: ChatRepository, + private val getChatListUseCase: GetChatListUseCase, ) : BaseViewModel() { private val _chats: MutableLiveData> = MutableLiveData() val chats: LiveData> get() = _chats var memberId: Long = 0L + private set fun getChats() { viewModelScope.launch { - chatRepository.getChatList().onSuccess { room -> + getChatListUseCase.invoke().onSuccess { room -> _chats.value = room.chatRooms.map { it.toUiModel() } memberId = room.myMemberId } @@ -28,10 +31,10 @@ class ChatListViewModel( } companion object { - fun factory(chatRepository: ChatRepository): ViewModelProvider.Factory { + fun factory(getChatListUseCase: GetChatListUseCase): ViewModelProvider.Factory { return BaseViewModelFactory { _ -> ChatListViewModel( - chatRepository, + getChatListUseCase, ) } } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/adapter/ChatListAdapter.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/adapter/ChatListAdapter.kt index dd6e6e83e..a7ee8b7c7 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/adapter/ChatListAdapter.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/adapter/ChatListAdapter.kt @@ -38,8 +38,10 @@ class ChatListAdapter(private val chatListNavigationAction: ChatListNavigationAc private val chatListNavigationAction: ChatListNavigationAction, ) : RecyclerView.ViewHolder(binding.root) { fun bind(item: ChatListUiModel) { - Glide.with(itemView.context).load(item.imageUrl).transform(CenterCrop()) - .into(binding.ivChatGroup) + if (item.imageUrl?.isNotBlank() == true) { + Glide.with(itemView.context).load(item.imageUrl).transform(CenterCrop()) + .into(binding.ivChatGroup) + } binding.tvChatTitle.text = item.title binding.tvChatBody.text = item.body binding.tvChatMemberCount.text = item.numberOfPeople.toString() diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt index 316758a10..bd2029f07 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt @@ -24,9 +24,11 @@ class ChatActivity : BaseActivity(R.layout.activity_chat) { initAdapter() getChatList() clickBackBtn() - clickChatInfo() + val myMemberId: Long = intent.getLongExtra(EXTRA_MEMBER_ID, INVALID_ID) val chatId: Long = intent.getLongExtra(EXTRA_CHAT_ID, INVALID_ID) + clickChatInfo(myMemberId, chatId) + binding.ibChatSendMessage.setOnClickListener { viewModel.sendMessage(chatId, binding.edtChatSendMessage.text.toString()) binding.edtChatSendMessage.setText("") @@ -34,9 +36,14 @@ class ChatActivity : BaseActivity(R.layout.activity_chat) { viewModel.subscribeMessage(chatId) } - private fun clickChatInfo() { + private fun clickChatInfo(myMemberId: Long, chatRoomId: Long) { binding.ibChatSideMenu.setOnClickListener { - ChatInfoSideSheet().show(supportFragmentManager, "") + val chatInfoSideSheet = ChatInfoSideSheet() + chatInfoSideSheet.arguments = ChatInfoSideSheet.getBundle( + myMemberId = myMemberId, + chatRoomId = chatRoomId + ) + chatInfoSideSheet.show(supportFragmentManager, "") } } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt index 40697f35f..35dca7a76 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt @@ -23,8 +23,6 @@ class ChatViewModel( val sendMessage = MutableLiveData("") - var memberId: Long = 0L - val isCanSend = MediatorLiveData().apply { addSource(sendMessage) { @@ -61,23 +59,6 @@ class ChatViewModel( } companion object { - private val dummyChats = - listOf( - ChatUiModel.ComeOut("벼리", true), - ChatUiModel.ComeOut("누누", true), - ChatUiModel.Mine( - "이거 잘 작동되는거 맞냐", - LocalTime.now(), - ), - ChatUiModel.Other( - "채드", - "https://m.segye.com/content/image/2" + - "021/07/29/20210729517145.jpg", - "화면 보이는거 보니깐 잘 작동하는듯 \n 근데 나 긴 텍스트 필요하니깐 아무말이나 쓸게 블라블랄", - LocalTime.now(), - ), - ) - fun factory(webSocketRepository: WebSocketRepository): ViewModelProvider.Factory { return BaseViewModelFactory { _ -> ChatViewModel( diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoMapper.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoMapper.kt new file mode 100644 index 000000000..0d55720c3 --- /dev/null +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoMapper.kt @@ -0,0 +1,12 @@ +package com.happy.friendogly.presentation.ui.chatlist.chatinfo + +import com.happy.friendogly.domain.model.ChatMember + +fun ChatMember.toUiModel(myMemberId: Long): JoinPeople = + JoinPeople( + nickName = this.memberName, + isMe = myMemberId == memberId, + isLeader = isOwner, + profileUrl = memberProfileImageUrl, + memberId = memberId, + ) diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoSideSheet.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoSideSheet.kt index 4c7063161..e62a4c8d0 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoSideSheet.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoSideSheet.kt @@ -10,6 +10,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.sidesheet.SideSheetDialog import com.google.android.material.snackbar.Snackbar import com.happy.friendogly.R +import com.happy.friendogly.application.di.AppModule import com.happy.friendogly.databinding.LayoutChatDrawerBinding import com.happy.friendogly.presentation.ui.permission.AlarmPermission @@ -19,18 +20,19 @@ class ChatInfoSideSheet : BottomSheetDialogFragment() { get() = requireNotNull(_binding) { "${this::class.java.simpleName} is null" } private lateinit var adapter: JoinPeopleAdapter - private val alarmPermission: AlarmPermission = - AlarmPermission.from(this) { isPermitted -> - if (!isPermitted) { - Snackbar.make( - binding.root, - getString(R.string.chat_setting_alarm_alert), - Snackbar.LENGTH_SHORT, - ).show() - } + private val alarmPermission: AlarmPermission = AlarmPermission.from(this) { isPermitted -> + if (!isPermitted) { + Snackbar.make( + binding.root, + getString(R.string.chat_setting_alarm_alert), + Snackbar.LENGTH_SHORT, + ).show() } + } - private val viewModel: ChatInfoViewModel by viewModels() + private val viewModel: ChatInfoViewModel by viewModels { + ChatInfoViewModel.factory(AppModule.getInstance().getChatMemberUseCase) + } override fun onCreateView( inflater: LayoutInflater, @@ -53,15 +55,24 @@ class ChatInfoSideSheet : BottomSheetDialogFragment() { initAdapter() - viewModel.getChatInfo() - viewModel.chatInfo.observe(viewLifecycleOwner) { info -> - adapter.submitList(info.people) - setChatInfo(info) - } + initChatInfo() clickAlarmSetting() } + private fun initChatInfo() { + val memberId = requireNotNull(arguments?.getLong(EXTRA_MEMBER_ID, INVALID_ID)) + val chatId = requireNotNull(arguments?.getLong(EXTRA_CHAT_ROOM_ID, INVALID_ID)) + viewModel.getChatMember(myMemberId = memberId, chatRoomId = chatId) + viewModel.getClubInfo() + viewModel.clubInfo.observe(viewLifecycleOwner) { info -> + setChatInfo(info) + } + viewModel.joiningPeople.observe(viewLifecycleOwner) { + adapter.submitList(it) + } + } + private fun clickAlarmSetting() { binding.switchChatSettingAlarm.setOnCheckedChangeListener { _, isChecked -> if (isChecked) { @@ -106,4 +117,18 @@ class ChatInfoSideSheet : BottomSheetDialogFragment() { super.onDestroyView() _binding = null } + + companion object { + + private const val EXTRA_MEMBER_ID = "myMemberId" + private const val EXTRA_CHAT_ROOM_ID = "chatRoomId" + private const val INVALID_ID = -1L + + fun getBundle(myMemberId: Long, chatRoomId: Long): Bundle { + return Bundle().apply { + putLong(EXTRA_MEMBER_ID, myMemberId) + putLong(EXTRA_CHAT_ROOM_ID, chatRoomId) + } + } + } } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoUiModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoUiModel.kt index b7972a2cc..1045edd64 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoUiModel.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoUiModel.kt @@ -3,7 +3,6 @@ package com.happy.friendogly.presentation.ui.chatlist.chatinfo data class ChatInfoUiModel( val dogSize: List, val dogGender: List, - val people: List, ) data class JoinPeople( @@ -11,6 +10,7 @@ data class JoinPeople( val isMe: Boolean, val isLeader: Boolean, val profileUrl: String, + val memberId: Long, ) enum class DogSize { diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoViewModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoViewModel.kt index 9af028786..45b79d55f 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoViewModel.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoViewModel.kt @@ -1,37 +1,52 @@ package com.happy.friendogly.presentation.ui.chatlist.chatinfo +import android.util.Log import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.viewModelScope +import androidx.paging.LOG_TAG +import com.happy.friendogly.domain.usecase.GetChatMemberUseCase import com.happy.friendogly.presentation.base.BaseViewModel +import com.happy.friendogly.presentation.base.BaseViewModelFactory +import kotlinx.coroutines.launch -class ChatInfoViewModel : BaseViewModel() { - private val _chatInfo: MutableLiveData = MutableLiveData() - val chatInfo: LiveData get() = _chatInfo +class ChatInfoViewModel( + private val getChatMemberUseCase: GetChatMemberUseCase, +) : BaseViewModel() { + private val _clubInfo: MutableLiveData = MutableLiveData() + val clubInfo: LiveData get() = _clubInfo - fun getChatInfo() { - _chatInfo.value = dummyChatInfo + private val _joiningPeople: MutableLiveData> = MutableLiveData() + val joiningPeople: LiveData> get() = _joiningPeople + + fun getChatMember( + chatRoomId: Long, + myMemberId: Long, + ) { + viewModelScope.launch { + getChatMemberUseCase.invoke(chatRoomId).onSuccess { members -> + _joiningPeople.value = members.map { it.toUiModel(myMemberId) } + }.onFailure { + // TODO 에러 처리 + } + } + } + + fun getClubInfo() { // TODO Api 연결 + _clubInfo.value = ChatInfoUiModel( + dogSize = listOf(DogSize.SMALL), + dogGender = listOf(DogGender.FEMALE), + ) } companion object { - private val dummyChatInfo = - ChatInfoUiModel( - dogSize = listOf(DogSize.SMALL), - dogGender = listOf(DogGender.FEMALE), - people = - listOf( - JoinPeople( - "김유연", - true, - true, - "https://i.ytimg.com/vi/eEWrbcm6rHI/maxresdefault.jpg", - ), - JoinPeople( - "김재중", - false, - false, - "https://dimg.donga.com/wps/NEWS/IMAGE/2021/12/13/110760431.2.jpg", - ), - ), - ) + fun factory(getChatMemberUseCase: GetChatMemberUseCase): ViewModelProvider.Factory { + return BaseViewModelFactory { _ -> + ChatInfoViewModel( + getChatMemberUseCase, + ) + } + } } } From 7d52d89758120afee2fc8e6466d3727ff4686e61 Mon Sep 17 00:00:00 2001 From: gaeun Date: Sun, 11 Aug 2024 23:53:06 +0900 Subject: [PATCH 4/9] =?UTF-8?q?feat:=20url=EC=9D=B4=20=EC=97=86=EC=9D=84?= =?UTF-8?q?=20=EA=B2=BD=EC=9A=B0,=20=EA=B8=B0=EB=B3=B8=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=EA=B0=80=20=EB=B3=B4=EC=9D=B4=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/ui/chatlist/chatinfo/JoinPeopleAdapter.kt | 6 ++++-- android/app/src/main/res/layout/item_chat_join_people.xml | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/JoinPeopleAdapter.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/JoinPeopleAdapter.kt index 0f177706f..b987a0fc4 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/JoinPeopleAdapter.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/JoinPeopleAdapter.kt @@ -35,8 +35,10 @@ class JoinPeopleAdapter : private val binding: ItemChatJoinPeopleBinding, ) : RecyclerView.ViewHolder(binding.root) { fun bind(item: JoinPeople) { - Glide.with(itemView.context).load(item.profileUrl) - .into(binding.ivChatJoinPeople) + if (item.profileUrl.isNotBlank()) { + Glide.with(itemView.context).load(item.profileUrl) + .into(binding.ivChatJoinPeople) + } binding.tvChatJoinPeopleNickname.text = item.nickName binding.tvChatJoinPeopleIsMe.isVisible = item.isMe binding.ivChatJoinPeopleLeader.isVisible = item.isLeader diff --git a/android/app/src/main/res/layout/item_chat_join_people.xml b/android/app/src/main/res/layout/item_chat_join_people.xml index 2faadedcc..f5c34a255 100644 --- a/android/app/src/main/res/layout/item_chat_join_people.xml +++ b/android/app/src/main/res/layout/item_chat_join_people.xml @@ -9,14 +9,14 @@ android:id="@+id/iv_chat_join_people" android:layout_width="32dp" android:layout_height="0dp" + android:src="@drawable/img_profile_normal" android:layout_marginVertical="10dp" android:scaleType="centerCrop" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintDimensionRatio="1:1" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:shapeAppearanceOverlay="@style/Circle" - tools:src="@drawable/ic_launcher_background" /> + app:shapeAppearanceOverlay="@style/Circle" /> Date: Mon, 12 Aug 2024 00:25:12 +0900 Subject: [PATCH 5/9] =?UTF-8?q?feat:=20=EB=82=B4=20=EC=B1=84=ED=8C=85,=20?= =?UTF-8?q?=EB=82=A8=EC=9D=98=20=EC=B1=84=ED=8C=85=20=EA=B5=AC=EB=B6=84?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EB=B7=B0=EA=B0=80=20=EB=B3=B4=EC=9D=B4?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../happy/friendogly/data/mapper/MessageMapper.kt | 4 ++-- .../data/repository/WebSocketRepositoryImpl.kt | 7 +++++-- .../domain/repository/WebSocketRepository.kt | 2 +- .../presentation/ui/chatlist/chat/ChatActivity.kt | 13 +++++++++---- .../ui/chatlist/chat/ChatNavigationAction.kt | 5 +++++ .../presentation/ui/chatlist/chat/ChatViewModel.kt | 4 ++-- .../ui/chatlist/chatinfo/ChatInfoSideSheet.kt | 4 +++- .../ui/chatlist/chatinfo/JoinPeopleAdapter.kt | 13 +++++++++++-- android/app/src/main/res/layout/item_chat_other.xml | 12 ++++++------ 9 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatNavigationAction.kt diff --git a/android/app/src/main/java/com/happy/friendogly/data/mapper/MessageMapper.kt b/android/app/src/main/java/com/happy/friendogly/data/mapper/MessageMapper.kt index d9e67a0d8..bc9f34a95 100644 --- a/android/app/src/main/java/com/happy/friendogly/data/mapper/MessageMapper.kt +++ b/android/app/src/main/java/com/happy/friendogly/data/mapper/MessageMapper.kt @@ -8,14 +8,14 @@ fun MessageDto.toOther(): Message.Other = Message.Other( memberId = senderMemberId, name = senderName, - content = content!!, + content = content ?: "", dateTime = createdAt, profileUrl = profilePictureUrl, ) fun MessageDto.toMine(): Message.Mine = Message.Mine( - content = content!!, + content = content ?: "", dateTime = createdAt, ) diff --git a/android/app/src/main/java/com/happy/friendogly/data/repository/WebSocketRepositoryImpl.kt b/android/app/src/main/java/com/happy/friendogly/data/repository/WebSocketRepositoryImpl.kt index ab4143edf..e1fc702c1 100644 --- a/android/app/src/main/java/com/happy/friendogly/data/repository/WebSocketRepositoryImpl.kt +++ b/android/app/src/main/java/com/happy/friendogly/data/repository/WebSocketRepositoryImpl.kt @@ -2,6 +2,7 @@ package com.happy.friendogly.data.repository import com.happy.friendogly.data.mapper.toEnter import com.happy.friendogly.data.mapper.toLeave +import com.happy.friendogly.data.mapper.toMine import com.happy.friendogly.data.mapper.toOther import com.happy.friendogly.data.model.MessageTypeDto import com.happy.friendogly.data.source.WebSocketDataSource @@ -20,12 +21,14 @@ class WebSocketRepositoryImpl(private val source: WebSocketDataSource) : WebSock override suspend fun publishLeave(chatRoomId: Long) = source.publishLeave(chatRoomId) - override suspend fun subscribeMessage(chatRoomId: Long): Flow = + override suspend fun subscribeMessage(chatRoomId: Long, myMemberId: Long): Flow = source.subscribeMessage(chatRoomId).map { when (it.messageType) { MessageTypeDto.ENTER -> it.toEnter() MessageTypeDto.LEAVE -> it.toLeave() - MessageTypeDto.CHAT -> it.toOther() + MessageTypeDto.CHAT -> { + if (myMemberId == it.senderMemberId) it.toMine() else it.toOther() + } } } } diff --git a/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt b/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt index 9a581cd88..2b2c1b620 100644 --- a/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt +++ b/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt @@ -13,5 +13,5 @@ interface WebSocketRepository { suspend fun publishLeave(chatRoomId: Long) - suspend fun subscribeMessage(chatRoomId: Long): Flow + suspend fun subscribeMessage(chatRoomId: Long, myMemberId: Long): Flow } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt index bd2029f07..e2ad09b00 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt @@ -9,8 +9,9 @@ import com.happy.friendogly.databinding.ActivityChatBinding import com.happy.friendogly.presentation.base.BaseActivity import com.happy.friendogly.presentation.ui.chatlist.chat.adapter.ChatAdapter import com.happy.friendogly.presentation.ui.chatlist.chatinfo.ChatInfoSideSheet +import com.happy.friendogly.presentation.ui.otherprofile.OtherProfileActivity -class ChatActivity : BaseActivity(R.layout.activity_chat) { +class ChatActivity : BaseActivity(R.layout.activity_chat), ChatNavigationAction { private val viewModel: ChatViewModel by viewModels { ChatViewModel.factory( AppModule.getInstance().webSocketRepository, @@ -33,7 +34,7 @@ class ChatActivity : BaseActivity(R.layout.activity_chat) { viewModel.sendMessage(chatId, binding.edtChatSendMessage.text.toString()) binding.edtChatSendMessage.setText("") } - viewModel.subscribeMessage(chatId) + viewModel.subscribeMessage(chatId,myMemberId) } private fun clickChatInfo(myMemberId: Long, chatRoomId: Long) { @@ -64,12 +65,16 @@ class ChatActivity : BaseActivity(R.layout.activity_chat) { } } + override fun navigateToMemberProfile(memberId: Long) { + startActivity(OtherProfileActivity.getIntent(this, memberId)) + } + companion object { - private const val INVALID_ID = -1L + private const val INVALID_ID = -1L private const val EXTRA_CHAT_ID = "chatId" - private const val EXTRA_MEMBER_ID = "memberId" + private const val EXTRA_MEMBER_ID = "memberId" fun getIntent( context: Context, chatId: Long, diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatNavigationAction.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatNavigationAction.kt new file mode 100644 index 000000000..98a70990a --- /dev/null +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatNavigationAction.kt @@ -0,0 +1,5 @@ +package com.happy.friendogly.presentation.ui.chatlist.chat + +interface ChatNavigationAction { + fun navigateToMemberProfile(memberId: Long) +} diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt index 35dca7a76..52f432cce 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt @@ -30,10 +30,10 @@ class ChatViewModel( } } - fun subscribeMessage(chatRoomId: Long) { + fun subscribeMessage(chatRoomId: Long, myMemberId:Long) { viewModelScope.launch { val newChat = - webSocketRepository.subscribeMessage(chatRoomId).map { + webSocketRepository.subscribeMessage(chatRoomId, myMemberId).map { when (it) { is ChatComponent.Date -> it.toUiModel() is ChatComponent.Enter -> it.toUiModel() diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoSideSheet.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoSideSheet.kt index e62a4c8d0..59415a404 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoSideSheet.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoSideSheet.kt @@ -12,6 +12,8 @@ import com.google.android.material.snackbar.Snackbar import com.happy.friendogly.R import com.happy.friendogly.application.di.AppModule import com.happy.friendogly.databinding.LayoutChatDrawerBinding +import com.happy.friendogly.presentation.ui.chatlist.chat.ChatActivity +import com.happy.friendogly.presentation.ui.chatlist.chat.ChatNavigationAction import com.happy.friendogly.presentation.ui.permission.AlarmPermission class ChatInfoSideSheet : BottomSheetDialogFragment() { @@ -109,7 +111,7 @@ class ChatInfoSideSheet : BottomSheetDialogFragment() { } private fun initAdapter() { - adapter = JoinPeopleAdapter() + adapter = JoinPeopleAdapter((requireActivity() as ChatNavigationAction)) binding.rcvChatJoinPeople.adapter = adapter } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/JoinPeopleAdapter.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/JoinPeopleAdapter.kt index b987a0fc4..f49c5356e 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/JoinPeopleAdapter.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/JoinPeopleAdapter.kt @@ -8,8 +8,11 @@ import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide import com.happy.friendogly.databinding.ItemChatJoinPeopleBinding +import com.happy.friendogly.presentation.ui.chatlist.chat.ChatNavigationAction -class JoinPeopleAdapter : +class JoinPeopleAdapter( + private val onMemberClick: ChatNavigationAction +) : ListAdapter(ChatInfoDiffCallback) { init { setHasStableIds(true) @@ -21,7 +24,7 @@ class JoinPeopleAdapter : ): JoinPeopleViewHolder { val inflater = LayoutInflater.from(parent.context) val binding = ItemChatJoinPeopleBinding.inflate(inflater, parent, false) - return JoinPeopleViewHolder(binding) + return JoinPeopleViewHolder(binding, onMemberClick) } override fun onBindViewHolder( @@ -33,6 +36,7 @@ class JoinPeopleAdapter : class JoinPeopleViewHolder( private val binding: ItemChatJoinPeopleBinding, + private val onClick: ChatNavigationAction ) : RecyclerView.ViewHolder(binding.root) { fun bind(item: JoinPeople) { if (item.profileUrl.isNotBlank()) { @@ -42,6 +46,11 @@ class JoinPeopleAdapter : binding.tvChatJoinPeopleNickname.text = item.nickName binding.tvChatJoinPeopleIsMe.isVisible = item.isMe binding.ivChatJoinPeopleLeader.isVisible = item.isLeader + if (!item.isMe) { + binding.root.setOnClickListener { + onClick.navigateToMemberProfile(item.memberId) + } + } } } diff --git a/android/app/src/main/res/layout/item_chat_other.xml b/android/app/src/main/res/layout/item_chat_other.xml index 8d8feb772..c94a4c323 100644 --- a/android/app/src/main/res/layout/item_chat_other.xml +++ b/android/app/src/main/res/layout/item_chat_other.xml @@ -41,17 +41,16 @@ app:layout_constraintDimensionRatio="1:1" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:shapeAppearanceOverlay="@style/RoundXSmall" /> + app:shapeAppearanceOverlay="@style/Circle" /> From c2d8b709103cba5252cd950e3abb983902d182f2 Mon Sep 17 00:00:00 2001 From: gaeun Date: Mon, 12 Aug 2024 00:39:41 +0900 Subject: [PATCH 6/9] =?UTF-8?q?refactor:=20=EC=9B=B9=EC=86=8C=EC=BC=93=20u?= =?UTF-8?q?seCase=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../friendogly/application/di/AppModule.kt | 30 ++++++++++++++----- .../data/source/WebSocketDataSource.kt | 6 ++-- .../domain/repository/WebSocketRepository.kt | 6 ++-- .../domain/usecase/PublishInviteUseCase.kt | 10 +++++++ .../domain/usecase/PublishLeaveUseCase.kt | 9 ++++++ .../usecase/PublishSendMessageUseCase.kt | 10 +++++++ .../domain/usecase/SubScribeMessageUseCase.kt | 10 +++++++ .../ui/chatlist/chat/ChatActivity.kt | 8 +++-- .../ui/chatlist/chat/ChatViewModel.kt | 21 ++++++++----- .../remote/source/WebSocketDataSourceImpl.kt | 14 ++++++--- 10 files changed, 95 insertions(+), 29 deletions(-) create mode 100644 android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishInviteUseCase.kt create mode 100644 android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishLeaveUseCase.kt create mode 100644 android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishSendMessageUseCase.kt create mode 100644 android/app/src/main/java/com/happy/friendogly/domain/usecase/SubScribeMessageUseCase.kt diff --git a/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt b/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt index f26d98fe0..1b66f5435 100644 --- a/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt +++ b/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt @@ -58,8 +58,12 @@ import com.happy.friendogly.domain.usecase.PostFootprintUseCase import com.happy.friendogly.domain.usecase.PostKakaoLoginUseCase import com.happy.friendogly.domain.usecase.PostMemberUseCase import com.happy.friendogly.domain.usecase.PostPetUseCase +import com.happy.friendogly.domain.usecase.PublishInviteUseCase +import com.happy.friendogly.domain.usecase.PublishLeaveUseCase +import com.happy.friendogly.domain.usecase.PublishSendMessageUseCase import com.happy.friendogly.domain.usecase.SaveAddressUseCase import com.happy.friendogly.domain.usecase.SaveJwtTokenUseCase +import com.happy.friendogly.domain.usecase.SubScribeMessageUseCase import com.happy.friendogly.kakao.source.KakaoLoginDataSourceImpl import com.happy.friendogly.local.di.AddressModule import com.happy.friendogly.local.di.TokenManager @@ -128,11 +132,11 @@ class AppModule(context: Context) { private val webSocketService = WebSocketService( client = - RemoteModule.createStumpClient( - baseUrl = baseUrl, - tokenManager = tokenManager, - authenticationListener = authenticationListener, - ), + RemoteModule.createStumpClient( + baseUrl = baseUrl, + tokenManager = tokenManager, + authenticationListener = authenticationListener, + ), tokenManager = tokenManager, baseUrl = websocketUrl, ) @@ -156,7 +160,7 @@ class AppModule(context: Context) { private val petDataSource: PetDataSource = PetDataSourceImpl(service = petService) private val webSocketDataSource: WebSocketDataSource = WebSocketDataSourceImpl(service = webSocketService) - private val chatDataSource:ChatDataSource = ChatDataSourceImpl(service = chatService) + private val chatDataSource: ChatDataSource = ChatDataSourceImpl(service = chatService) // repository private val authRepository: AuthRepository = AuthRepositoryImpl(source = authDataSource) @@ -171,7 +175,7 @@ class AppModule(context: Context) { AddressRepositoryImpl(addressDataSource = addressDataSource) val webSocketRepository: WebSocketRepository = WebSocketRepositoryImpl(source = webSocketDataSource) - val chatRepository: ChatRepository = ChatRepositoryImpl(source = chatDataSource) + private val chatRepository: ChatRepository = ChatRepositoryImpl(source = chatDataSource) // use case val postKakaoLoginUseCase: PostKakaoLoginUseCase = @@ -211,7 +215,17 @@ class AppModule(context: Context) { val deleteAddressUseCase: DeleteAddressUseCase = DeleteAddressUseCase(repository = addressRepository) val getChatListUseCase: GetChatListUseCase = GetChatListUseCase(repository = chatRepository) - val getChatMemberUseCase: GetChatMemberUseCase = GetChatMemberUseCase(repository = chatRepository) + val getChatMemberUseCase: GetChatMemberUseCase = + GetChatMemberUseCase(repository = chatRepository) + val publishInviteUseCase: PublishInviteUseCase = + PublishInviteUseCase(repository = webSocketRepository) + val publishSendUseCase: PublishSendMessageUseCase = + PublishSendMessageUseCase(repository = webSocketRepository) + val publishLeaveUseCase: PublishLeaveUseCase = + PublishLeaveUseCase(repository = webSocketRepository) + val subScribeMessageUseCase: SubScribeMessageUseCase = + SubScribeMessageUseCase(repository = webSocketRepository) + companion object { private var instance: AppModule? = null diff --git a/android/app/src/main/java/com/happy/friendogly/data/source/WebSocketDataSource.kt b/android/app/src/main/java/com/happy/friendogly/data/source/WebSocketDataSource.kt index 8caaa5e96..d2a43a92b 100644 --- a/android/app/src/main/java/com/happy/friendogly/data/source/WebSocketDataSource.kt +++ b/android/app/src/main/java/com/happy/friendogly/data/source/WebSocketDataSource.kt @@ -4,14 +4,14 @@ import com.happy.friendogly.data.model.MessageDto import kotlinx.coroutines.flow.Flow interface WebSocketDataSource { - suspend fun publishInvite(memberId: Long) + suspend fun publishInvite(memberId: Long):Result suspend fun publishSend( chatRoomId: Long, content: String, - ) + ):Result - suspend fun publishLeave(chatRoomId: Long) + suspend fun publishLeave(chatRoomId: Long):Result suspend fun subscribeMessage(chatRoomId: Long): Flow } diff --git a/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt b/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt index 2b2c1b620..521d5ee48 100644 --- a/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt +++ b/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt @@ -4,14 +4,14 @@ import com.happy.friendogly.domain.model.ChatComponent import kotlinx.coroutines.flow.Flow interface WebSocketRepository { - suspend fun publishInvite(chatRoomId: Long) + suspend fun publishInvite(chatRoomId: Long): Result suspend fun publishSend( chatRoomId: Long, content: String, - ) + ): Result - suspend fun publishLeave(chatRoomId: Long) + suspend fun publishLeave(chatRoomId: Long): Result suspend fun subscribeMessage(chatRoomId: Long, myMemberId: Long): Flow } diff --git a/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishInviteUseCase.kt b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishInviteUseCase.kt new file mode 100644 index 000000000..53a396ac7 --- /dev/null +++ b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishInviteUseCase.kt @@ -0,0 +1,10 @@ +package com.happy.friendogly.domain.usecase + +import com.happy.friendogly.domain.repository.WebSocketRepository + +class PublishInviteUseCase( + private val repository: WebSocketRepository +) { + suspend operator fun invoke(chatRoomId: Long): Result = + repository.publishInvite(chatRoomId) +} diff --git a/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishLeaveUseCase.kt b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishLeaveUseCase.kt new file mode 100644 index 000000000..50ee2fb03 --- /dev/null +++ b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishLeaveUseCase.kt @@ -0,0 +1,9 @@ +package com.happy.friendogly.domain.usecase + +import com.happy.friendogly.domain.repository.WebSocketRepository + +class PublishLeaveUseCase( + private val repository: WebSocketRepository +) { + suspend operator fun invoke(chatRoomId:Long):Result = repository.publishInvite(chatRoomId) +} diff --git a/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishSendMessageUseCase.kt b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishSendMessageUseCase.kt new file mode 100644 index 000000000..7c28dbf14 --- /dev/null +++ b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishSendMessageUseCase.kt @@ -0,0 +1,10 @@ +package com.happy.friendogly.domain.usecase + +import com.happy.friendogly.domain.repository.WebSocketRepository + +class PublishSendMessageUseCase( + private val repository: WebSocketRepository +) { + suspend operator fun invoke(chatRoomId: Long, content: String): Result = + repository.publishSend(chatRoomId, content) +} diff --git a/android/app/src/main/java/com/happy/friendogly/domain/usecase/SubScribeMessageUseCase.kt b/android/app/src/main/java/com/happy/friendogly/domain/usecase/SubScribeMessageUseCase.kt new file mode 100644 index 000000000..0bacec942 --- /dev/null +++ b/android/app/src/main/java/com/happy/friendogly/domain/usecase/SubScribeMessageUseCase.kt @@ -0,0 +1,10 @@ +package com.happy.friendogly.domain.usecase + +import com.happy.friendogly.domain.model.ChatComponent +import com.happy.friendogly.domain.repository.WebSocketRepository +import kotlinx.coroutines.flow.Flow + +class SubScribeMessageUseCase(private val repository: WebSocketRepository) { + suspend operator fun invoke(chatRoomId: Long, myMemberId: Long): Flow = + repository.subscribeMessage(chatRoomId, myMemberId) +} diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt index e2ad09b00..2360d6408 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt @@ -11,10 +11,12 @@ import com.happy.friendogly.presentation.ui.chatlist.chat.adapter.ChatAdapter import com.happy.friendogly.presentation.ui.chatlist.chatinfo.ChatInfoSideSheet import com.happy.friendogly.presentation.ui.otherprofile.OtherProfileActivity -class ChatActivity : BaseActivity(R.layout.activity_chat), ChatNavigationAction { +class ChatActivity : BaseActivity(R.layout.activity_chat), + ChatNavigationAction { private val viewModel: ChatViewModel by viewModels { ChatViewModel.factory( - AppModule.getInstance().webSocketRepository, + AppModule.getInstance().subScribeMessageUseCase, + AppModule.getInstance().publishSendUseCase ) } private lateinit var adapter: ChatAdapter @@ -34,7 +36,7 @@ class ChatActivity : BaseActivity(R.layout.activity_chat), viewModel.sendMessage(chatId, binding.edtChatSendMessage.text.toString()) binding.edtChatSendMessage.setText("") } - viewModel.subscribeMessage(chatId,myMemberId) + viewModel.subscribeMessage(chatId, myMemberId) } private fun clickChatInfo(myMemberId: Long, chatRoomId: Long) { diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt index 52f432cce..a83b8a036 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt @@ -7,16 +7,17 @@ import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope import com.happy.friendogly.domain.model.ChatComponent import com.happy.friendogly.domain.model.Message -import com.happy.friendogly.domain.repository.WebSocketRepository +import com.happy.friendogly.domain.usecase.PublishSendMessageUseCase +import com.happy.friendogly.domain.usecase.SubScribeMessageUseCase import com.happy.friendogly.presentation.base.BaseViewModel import com.happy.friendogly.presentation.base.BaseViewModelFactory import com.happy.friendogly.presentation.ui.chatlist.uimodel.toUiModel import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch -import java.time.LocalTime class ChatViewModel( - private val webSocketRepository: WebSocketRepository, + private val subScribeMessageUseCase: SubScribeMessageUseCase, + private val publishSendMessageUseCase: PublishSendMessageUseCase ) : BaseViewModel() { private val _chats: MutableLiveData> = MutableLiveData() val chats: LiveData> get() = _chats @@ -30,10 +31,10 @@ class ChatViewModel( } } - fun subscribeMessage(chatRoomId: Long, myMemberId:Long) { + fun subscribeMessage(chatRoomId: Long, myMemberId: Long) { viewModelScope.launch { val newChat = - webSocketRepository.subscribeMessage(chatRoomId, myMemberId).map { + subScribeMessageUseCase(chatRoomId, myMemberId).map { when (it) { is ChatComponent.Date -> it.toUiModel() is ChatComponent.Enter -> it.toUiModel() @@ -54,15 +55,19 @@ class ChatViewModel( content: String, ) { viewModelScope.launch { - webSocketRepository.publishSend(chatRoomId, content) + publishSendMessageUseCase(chatRoomId, content) } } companion object { - fun factory(webSocketRepository: WebSocketRepository): ViewModelProvider.Factory { + fun factory( + subScribeMessageUseCase: SubScribeMessageUseCase, + publishSendMessageUseCase: PublishSendMessageUseCase + ): ViewModelProvider.Factory { return BaseViewModelFactory { _ -> ChatViewModel( - webSocketRepository, + subScribeMessageUseCase, + publishSendMessageUseCase ) } } diff --git a/android/app/src/main/java/com/happy/friendogly/remote/source/WebSocketDataSourceImpl.kt b/android/app/src/main/java/com/happy/friendogly/remote/source/WebSocketDataSourceImpl.kt index de8003f72..8eb3d95b6 100644 --- a/android/app/src/main/java/com/happy/friendogly/remote/source/WebSocketDataSourceImpl.kt +++ b/android/app/src/main/java/com/happy/friendogly/remote/source/WebSocketDataSourceImpl.kt @@ -8,14 +8,20 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map class WebSocketDataSourceImpl(private val service: WebSocketService) : WebSocketDataSource { - override suspend fun publishInvite(chatRoomId: Long) = service.publishInvite(chatRoomId) + override suspend fun publishInvite(chatRoomId: Long): Result = runCatching { + service.publishInvite(chatRoomId) + } override suspend fun publishSend( chatRoomId: Long, content: String, - ) = service.publishSend(chatRoomId, content) + ): Result = runCatching { + service.publishSend(chatRoomId, content) + } - override suspend fun publishLeave(chatRoomId: Long) = service.publishLeave(chatRoomId) + override suspend fun publishLeave(chatRoomId: Long): Result = + runCatching { service.publishLeave(chatRoomId) } - override suspend fun subscribeMessage(chatRoomId: Long): Flow = service.subscribeMessage(chatRoomId).map { it.toData() } + override suspend fun subscribeMessage(chatRoomId: Long): Flow = + service.subscribeMessage(chatRoomId).map { it.toData() } } From 9479b518d137a475e134b3c0bb6bc1af8a83bd7b Mon Sep 17 00:00:00 2001 From: gaeun Date: Mon, 12 Aug 2024 00:43:01 +0900 Subject: [PATCH 7/9] =?UTF-8?q?rename:=20invite=20->=20enter=EB=A1=9C=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/happy/friendogly/application/di/AppModule.kt | 6 +++--- .../friendogly/data/repository/WebSocketRepositoryImpl.kt | 2 +- .../com/happy/friendogly/data/source/WebSocketDataSource.kt | 2 +- .../friendogly/domain/repository/WebSocketRepository.kt | 2 +- .../{PublishInviteUseCase.kt => PublishEnterUseCase.kt} | 4 ++-- .../happy/friendogly/domain/usecase/PublishLeaveUseCase.kt | 2 +- .../friendogly/remote/source/WebSocketDataSourceImpl.kt | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) rename android/app/src/main/java/com/happy/friendogly/domain/usecase/{PublishInviteUseCase.kt => PublishEnterUseCase.kt} (76%) diff --git a/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt b/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt index 1b66f5435..9dda4e49e 100644 --- a/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt +++ b/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt @@ -58,7 +58,7 @@ import com.happy.friendogly.domain.usecase.PostFootprintUseCase import com.happy.friendogly.domain.usecase.PostKakaoLoginUseCase import com.happy.friendogly.domain.usecase.PostMemberUseCase import com.happy.friendogly.domain.usecase.PostPetUseCase -import com.happy.friendogly.domain.usecase.PublishInviteUseCase +import com.happy.friendogly.domain.usecase.PublishEnterUseCase import com.happy.friendogly.domain.usecase.PublishLeaveUseCase import com.happy.friendogly.domain.usecase.PublishSendMessageUseCase import com.happy.friendogly.domain.usecase.SaveAddressUseCase @@ -217,8 +217,8 @@ class AppModule(context: Context) { val getChatListUseCase: GetChatListUseCase = GetChatListUseCase(repository = chatRepository) val getChatMemberUseCase: GetChatMemberUseCase = GetChatMemberUseCase(repository = chatRepository) - val publishInviteUseCase: PublishInviteUseCase = - PublishInviteUseCase(repository = webSocketRepository) + val publishEnterUseCase: PublishEnterUseCase = + PublishEnterUseCase(repository = webSocketRepository) val publishSendUseCase: PublishSendMessageUseCase = PublishSendMessageUseCase(repository = webSocketRepository) val publishLeaveUseCase: PublishLeaveUseCase = diff --git a/android/app/src/main/java/com/happy/friendogly/data/repository/WebSocketRepositoryImpl.kt b/android/app/src/main/java/com/happy/friendogly/data/repository/WebSocketRepositoryImpl.kt index e1fc702c1..cb2557f12 100644 --- a/android/app/src/main/java/com/happy/friendogly/data/repository/WebSocketRepositoryImpl.kt +++ b/android/app/src/main/java/com/happy/friendogly/data/repository/WebSocketRepositoryImpl.kt @@ -12,7 +12,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map class WebSocketRepositoryImpl(private val source: WebSocketDataSource) : WebSocketRepository { - override suspend fun publishInvite(memberId: Long) = source.publishInvite(memberId) + override suspend fun publishEnter(memberId: Long) = source.publishEnter(memberId) override suspend fun publishSend( chatRoomId: Long, diff --git a/android/app/src/main/java/com/happy/friendogly/data/source/WebSocketDataSource.kt b/android/app/src/main/java/com/happy/friendogly/data/source/WebSocketDataSource.kt index d2a43a92b..05a789935 100644 --- a/android/app/src/main/java/com/happy/friendogly/data/source/WebSocketDataSource.kt +++ b/android/app/src/main/java/com/happy/friendogly/data/source/WebSocketDataSource.kt @@ -4,7 +4,7 @@ import com.happy.friendogly.data.model.MessageDto import kotlinx.coroutines.flow.Flow interface WebSocketDataSource { - suspend fun publishInvite(memberId: Long):Result + suspend fun publishEnter(memberId: Long):Result suspend fun publishSend( chatRoomId: Long, diff --git a/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt b/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt index 521d5ee48..a78a100cd 100644 --- a/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt +++ b/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt @@ -4,7 +4,7 @@ import com.happy.friendogly.domain.model.ChatComponent import kotlinx.coroutines.flow.Flow interface WebSocketRepository { - suspend fun publishInvite(chatRoomId: Long): Result + suspend fun publishEnter(chatRoomId: Long): Result suspend fun publishSend( chatRoomId: Long, diff --git a/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishInviteUseCase.kt b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishEnterUseCase.kt similarity index 76% rename from android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishInviteUseCase.kt rename to android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishEnterUseCase.kt index 53a396ac7..e9661f7ff 100644 --- a/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishInviteUseCase.kt +++ b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishEnterUseCase.kt @@ -2,9 +2,9 @@ package com.happy.friendogly.domain.usecase import com.happy.friendogly.domain.repository.WebSocketRepository -class PublishInviteUseCase( +class PublishEnterUseCase( private val repository: WebSocketRepository ) { suspend operator fun invoke(chatRoomId: Long): Result = - repository.publishInvite(chatRoomId) + repository.publishEnter(chatRoomId) } diff --git a/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishLeaveUseCase.kt b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishLeaveUseCase.kt index 50ee2fb03..baf1b4656 100644 --- a/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishLeaveUseCase.kt +++ b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishLeaveUseCase.kt @@ -5,5 +5,5 @@ import com.happy.friendogly.domain.repository.WebSocketRepository class PublishLeaveUseCase( private val repository: WebSocketRepository ) { - suspend operator fun invoke(chatRoomId:Long):Result = repository.publishInvite(chatRoomId) + suspend operator fun invoke(chatRoomId:Long):Result = repository.publishLeave(chatRoomId) } diff --git a/android/app/src/main/java/com/happy/friendogly/remote/source/WebSocketDataSourceImpl.kt b/android/app/src/main/java/com/happy/friendogly/remote/source/WebSocketDataSourceImpl.kt index 8eb3d95b6..2a876b5df 100644 --- a/android/app/src/main/java/com/happy/friendogly/remote/source/WebSocketDataSourceImpl.kt +++ b/android/app/src/main/java/com/happy/friendogly/remote/source/WebSocketDataSourceImpl.kt @@ -8,7 +8,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map class WebSocketDataSourceImpl(private val service: WebSocketService) : WebSocketDataSource { - override suspend fun publishInvite(chatRoomId: Long): Result = runCatching { + override suspend fun publishEnter(chatRoomId: Long): Result = runCatching { service.publishInvite(chatRoomId) } From 2fdb1524910f852a29bc419f1eb82080e3c969f0 Mon Sep 17 00:00:00 2001 From: gaeun Date: Mon, 12 Aug 2024 01:47:15 +0900 Subject: [PATCH 8/9] =?UTF-8?q?feat:=20=EC=9C=A0=EC=A0=80=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=ED=81=B4=EB=A6=AD=EC=8B=9C,=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EC=83=81=EC=84=B8=20=EB=B7=B0=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=8F=99=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/ui/chatlist/chat/ChatActivity.kt | 2 +- .../presentation/ui/chatlist/chat/ChatUiModel.kt | 3 ++- .../presentation/ui/chatlist/chat/adapter/ChatAdapter.kt | 7 +++++-- .../ui/chatlist/chat/adapter/ChatViewHolder.kt | 6 +++++- .../presentation/ui/chatlist/uimodel/ChatUiMapper.kt | 3 ++- android/app/src/main/res/layout/item_chat_other.xml | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt index 2360d6408..fe3e97e90 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt @@ -57,7 +57,7 @@ class ChatActivity : BaseActivity(R.layout.activity_chat), } private fun initAdapter() { - adapter = ChatAdapter() + adapter = ChatAdapter(this) binding.rcvChatDetail.adapter = adapter } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatUiModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatUiModel.kt index d1e549813..991a403b0 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatUiModel.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatUiModel.kt @@ -12,8 +12,9 @@ sealed interface ChatUiModel { data class Other( val nickName: String, - val profileUrl: String, + val profileUrl: String?, val message: String, val time: LocalTime, + val memberId:Long ) : ChatUiModel } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatAdapter.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatAdapter.kt index 3eddc883b..d779c1905 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatAdapter.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatAdapter.kt @@ -8,9 +8,12 @@ import com.happy.friendogly.databinding.ItemChatComeOutBinding import com.happy.friendogly.databinding.ItemChatDateBinding import com.happy.friendogly.databinding.ItemChatMineBinding import com.happy.friendogly.databinding.ItemChatOtherBinding +import com.happy.friendogly.presentation.ui.chatlist.chat.ChatNavigationAction import com.happy.friendogly.presentation.ui.chatlist.chat.ChatUiModel -class ChatAdapter : ListAdapter(ChatDiffCallback) { +class ChatAdapter( + private val onMemberClick: ChatNavigationAction +) : ListAdapter(ChatDiffCallback) { init { setHasStableIds(true) } @@ -62,7 +65,7 @@ class ChatAdapter : ListAdapter(ChatDiffCallback) { inflater, parent, false, - ), + ), onMemberClick ) else -> error("$viewType 잘못된 viewType이 들어왔습니다") diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatViewHolder.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatViewHolder.kt index f37bbe9c6..8a1c27955 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatViewHolder.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatViewHolder.kt @@ -7,6 +7,7 @@ import com.happy.friendogly.databinding.ItemChatComeOutBinding import com.happy.friendogly.databinding.ItemChatDateBinding import com.happy.friendogly.databinding.ItemChatMineBinding import com.happy.friendogly.databinding.ItemChatOtherBinding +import com.happy.friendogly.presentation.ui.chatlist.chat.ChatNavigationAction import com.happy.friendogly.presentation.ui.chatlist.chat.ChatUiModel import java.time.format.DateTimeFormatter @@ -39,7 +40,7 @@ class MineViewHolder(val binding: ItemChatMineBinding) : ChatViewHolder(binding. } } -class OtherViewHolder(val binding: ItemChatOtherBinding) : ChatViewHolder(binding.root) { +class OtherViewHolder(val binding: ItemChatOtherBinding, val onMemberClick:ChatNavigationAction) : ChatViewHolder(binding.root) { fun bind(item: ChatUiModel.Other) { binding.tvChatOtherMessage.text = item.message val timeFormatter = @@ -47,5 +48,8 @@ class OtherViewHolder(val binding: ItemChatOtherBinding) : ChatViewHolder(bindin binding.tvChatOtherTime.text = item.time.format(timeFormatter) binding.tvChatUserNickname.text = item.nickName binding.profileUrl = item.profileUrl + binding.ivChatUser.setOnClickListener { + onMemberClick.navigateToMemberProfile(item.memberId) + } } } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/uimodel/ChatUiMapper.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/uimodel/ChatUiMapper.kt index 48a7533de..340aacf68 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/uimodel/ChatUiMapper.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/uimodel/ChatUiMapper.kt @@ -32,5 +32,6 @@ fun Message.Other.toUiModel() = nickName = name, message = content, time = dateTime.toLocalTime(), - profileUrl = profileUrl ?: "", + profileUrl = profileUrl, + memberId = memberId ) diff --git a/android/app/src/main/res/layout/item_chat_other.xml b/android/app/src/main/res/layout/item_chat_other.xml index c94a4c323..aaab55834 100644 --- a/android/app/src/main/res/layout/item_chat_other.xml +++ b/android/app/src/main/res/layout/item_chat_other.xml @@ -37,7 +37,7 @@ android:layout_marginStart="21dp" android:layout_marginTop="5dp" android:scaleType="centerCrop" - android:src="@drawable/ic_launcher_background" + android:src="@drawable/img_profile_normal" app:layout_constraintDimensionRatio="1:1" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" From c60d82a9e1633b13576725b31a90cd2905707344 Mon Sep 17 00:00:00 2001 From: gaeun Date: Mon, 12 Aug 2024 02:17:30 +0900 Subject: [PATCH 9/9] =?UTF-8?q?style:=20ktlint=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../friendogly/application/di/AppModule.kt | 11 ++++----- .../data/repository/ChatRepositoryImpl.kt | 3 +-- .../repository/WebSocketRepositoryImpl.kt | 5 +++- .../friendogly/data/source/ChatDataSource.kt | 3 --- .../data/source/WebSocketDataSource.kt | 6 ++--- .../domain/repository/WebSocketRepository.kt | 5 +++- .../domain/usecase/PublishEnterUseCase.kt | 5 ++-- .../domain/usecase/PublishLeaveUseCase.kt | 4 ++-- .../usecase/PublishSendMessageUseCase.kt | 8 ++++--- .../domain/usecase/SubScribeMessageUseCase.kt | 6 +++-- .../ui/chatlist/ChatListViewModel.kt | 2 -- .../ui/chatlist/chat/ChatActivity.kt | 21 +++++++++------- .../ui/chatlist/chat/ChatUiModel.kt | 2 +- .../ui/chatlist/chat/ChatViewModel.kt | 11 +++++---- .../ui/chatlist/chat/adapter/ChatAdapter.kt | 5 ++-- .../chatlist/chat/adapter/ChatViewHolder.kt | 2 +- .../ui/chatlist/chatinfo/ChatInfoSideSheet.kt | 24 ++++++++++--------- .../ui/chatlist/chatinfo/ChatInfoViewModel.kt | 11 ++++----- .../ui/chatlist/chatinfo/JoinPeopleAdapter.kt | 4 ++-- .../ui/chatlist/uimodel/ChatUiMapper.kt | 2 +- .../remote/source/ChatDataSourceImpl.kt | 17 ++++++------- .../remote/source/WebSocketDataSourceImpl.kt | 20 ++++++++-------- 22 files changed, 95 insertions(+), 82 deletions(-) diff --git a/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt b/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt index 9dda4e49e..3a330dcb2 100644 --- a/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt +++ b/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt @@ -132,11 +132,11 @@ class AppModule(context: Context) { private val webSocketService = WebSocketService( client = - RemoteModule.createStumpClient( - baseUrl = baseUrl, - tokenManager = tokenManager, - authenticationListener = authenticationListener, - ), + RemoteModule.createStumpClient( + baseUrl = baseUrl, + tokenManager = tokenManager, + authenticationListener = authenticationListener, + ), tokenManager = tokenManager, baseUrl = websocketUrl, ) @@ -226,7 +226,6 @@ class AppModule(context: Context) { val subScribeMessageUseCase: SubScribeMessageUseCase = SubScribeMessageUseCase(repository = webSocketRepository) - companion object { private var instance: AppModule? = null diff --git a/android/app/src/main/java/com/happy/friendogly/data/repository/ChatRepositoryImpl.kt b/android/app/src/main/java/com/happy/friendogly/data/repository/ChatRepositoryImpl.kt index 7335512c6..49501a983 100644 --- a/android/app/src/main/java/com/happy/friendogly/data/repository/ChatRepositoryImpl.kt +++ b/android/app/src/main/java/com/happy/friendogly/data/repository/ChatRepositoryImpl.kt @@ -7,8 +7,7 @@ import com.happy.friendogly.domain.model.ChatRooms import com.happy.friendogly.domain.repository.ChatRepository class ChatRepositoryImpl(private val source: ChatDataSource) : ChatRepository { - override suspend fun getChatList(): Result = - source.getChatList().mapCatching { it.toDomain() } + override suspend fun getChatList(): Result = source.getChatList().mapCatching { it.toDomain() } override suspend fun getMembers(chatRoomId: Long): Result> = source.getMembers(chatRoomId).mapCatching { member -> diff --git a/android/app/src/main/java/com/happy/friendogly/data/repository/WebSocketRepositoryImpl.kt b/android/app/src/main/java/com/happy/friendogly/data/repository/WebSocketRepositoryImpl.kt index cb2557f12..e23d19e85 100644 --- a/android/app/src/main/java/com/happy/friendogly/data/repository/WebSocketRepositoryImpl.kt +++ b/android/app/src/main/java/com/happy/friendogly/data/repository/WebSocketRepositoryImpl.kt @@ -21,7 +21,10 @@ class WebSocketRepositoryImpl(private val source: WebSocketDataSource) : WebSock override suspend fun publishLeave(chatRoomId: Long) = source.publishLeave(chatRoomId) - override suspend fun subscribeMessage(chatRoomId: Long, myMemberId: Long): Flow = + override suspend fun subscribeMessage( + chatRoomId: Long, + myMemberId: Long, + ): Flow = source.subscribeMessage(chatRoomId).map { when (it.messageType) { MessageTypeDto.ENTER -> it.toEnter() diff --git a/android/app/src/main/java/com/happy/friendogly/data/source/ChatDataSource.kt b/android/app/src/main/java/com/happy/friendogly/data/source/ChatDataSource.kt index b8999612d..7eda46136 100644 --- a/android/app/src/main/java/com/happy/friendogly/data/source/ChatDataSource.kt +++ b/android/app/src/main/java/com/happy/friendogly/data/source/ChatDataSource.kt @@ -2,11 +2,8 @@ package com.happy.friendogly.data.source import com.happy.friendogly.data.model.ChatMemberDto import com.happy.friendogly.data.model.ChatRoomListDto -import com.happy.friendogly.domain.model.ChatMember -import com.happy.friendogly.domain.model.ChatRooms interface ChatDataSource { - suspend fun getChatList(): Result suspend fun getMembers(chatRoomId: Long): Result> diff --git a/android/app/src/main/java/com/happy/friendogly/data/source/WebSocketDataSource.kt b/android/app/src/main/java/com/happy/friendogly/data/source/WebSocketDataSource.kt index 05a789935..03ad8c275 100644 --- a/android/app/src/main/java/com/happy/friendogly/data/source/WebSocketDataSource.kt +++ b/android/app/src/main/java/com/happy/friendogly/data/source/WebSocketDataSource.kt @@ -4,14 +4,14 @@ import com.happy.friendogly.data.model.MessageDto import kotlinx.coroutines.flow.Flow interface WebSocketDataSource { - suspend fun publishEnter(memberId: Long):Result + suspend fun publishEnter(memberId: Long): Result suspend fun publishSend( chatRoomId: Long, content: String, - ):Result + ): Result - suspend fun publishLeave(chatRoomId: Long):Result + suspend fun publishLeave(chatRoomId: Long): Result suspend fun subscribeMessage(chatRoomId: Long): Flow } diff --git a/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt b/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt index a78a100cd..56c29a4b3 100644 --- a/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt +++ b/android/app/src/main/java/com/happy/friendogly/domain/repository/WebSocketRepository.kt @@ -13,5 +13,8 @@ interface WebSocketRepository { suspend fun publishLeave(chatRoomId: Long): Result - suspend fun subscribeMessage(chatRoomId: Long, myMemberId: Long): Flow + suspend fun subscribeMessage( + chatRoomId: Long, + myMemberId: Long, + ): Flow } diff --git a/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishEnterUseCase.kt b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishEnterUseCase.kt index e9661f7ff..e23aebb61 100644 --- a/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishEnterUseCase.kt +++ b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishEnterUseCase.kt @@ -3,8 +3,7 @@ package com.happy.friendogly.domain.usecase import com.happy.friendogly.domain.repository.WebSocketRepository class PublishEnterUseCase( - private val repository: WebSocketRepository + private val repository: WebSocketRepository, ) { - suspend operator fun invoke(chatRoomId: Long): Result = - repository.publishEnter(chatRoomId) + suspend operator fun invoke(chatRoomId: Long): Result = repository.publishEnter(chatRoomId) } diff --git a/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishLeaveUseCase.kt b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishLeaveUseCase.kt index baf1b4656..0c7362c89 100644 --- a/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishLeaveUseCase.kt +++ b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishLeaveUseCase.kt @@ -3,7 +3,7 @@ package com.happy.friendogly.domain.usecase import com.happy.friendogly.domain.repository.WebSocketRepository class PublishLeaveUseCase( - private val repository: WebSocketRepository + private val repository: WebSocketRepository, ) { - suspend operator fun invoke(chatRoomId:Long):Result = repository.publishLeave(chatRoomId) + suspend operator fun invoke(chatRoomId: Long): Result = repository.publishLeave(chatRoomId) } diff --git a/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishSendMessageUseCase.kt b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishSendMessageUseCase.kt index 7c28dbf14..b46ee3d8b 100644 --- a/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishSendMessageUseCase.kt +++ b/android/app/src/main/java/com/happy/friendogly/domain/usecase/PublishSendMessageUseCase.kt @@ -3,8 +3,10 @@ package com.happy.friendogly.domain.usecase import com.happy.friendogly.domain.repository.WebSocketRepository class PublishSendMessageUseCase( - private val repository: WebSocketRepository + private val repository: WebSocketRepository, ) { - suspend operator fun invoke(chatRoomId: Long, content: String): Result = - repository.publishSend(chatRoomId, content) + suspend operator fun invoke( + chatRoomId: Long, + content: String, + ): Result = repository.publishSend(chatRoomId, content) } diff --git a/android/app/src/main/java/com/happy/friendogly/domain/usecase/SubScribeMessageUseCase.kt b/android/app/src/main/java/com/happy/friendogly/domain/usecase/SubScribeMessageUseCase.kt index 0bacec942..a58d3bbc6 100644 --- a/android/app/src/main/java/com/happy/friendogly/domain/usecase/SubScribeMessageUseCase.kt +++ b/android/app/src/main/java/com/happy/friendogly/domain/usecase/SubScribeMessageUseCase.kt @@ -5,6 +5,8 @@ import com.happy.friendogly.domain.repository.WebSocketRepository import kotlinx.coroutines.flow.Flow class SubScribeMessageUseCase(private val repository: WebSocketRepository) { - suspend operator fun invoke(chatRoomId: Long, myMemberId: Long): Flow = - repository.subscribeMessage(chatRoomId, myMemberId) + suspend operator fun invoke( + chatRoomId: Long, + myMemberId: Long, + ): Flow = repository.subscribeMessage(chatRoomId, myMemberId) } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListViewModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListViewModel.kt index 317563291..bbdc90257 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListViewModel.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/ChatListViewModel.kt @@ -4,9 +4,7 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope -import com.happy.friendogly.domain.repository.ChatRepository import com.happy.friendogly.domain.usecase.GetChatListUseCase -import com.happy.friendogly.domain.usecase.GetChatMemberUseCase import com.happy.friendogly.presentation.base.BaseViewModel import com.happy.friendogly.presentation.base.BaseViewModelFactory import com.happy.friendogly.presentation.ui.chatlist.uimodel.ChatListUiModel diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt index fe3e97e90..0789d9bed 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatActivity.kt @@ -11,12 +11,13 @@ import com.happy.friendogly.presentation.ui.chatlist.chat.adapter.ChatAdapter import com.happy.friendogly.presentation.ui.chatlist.chatinfo.ChatInfoSideSheet import com.happy.friendogly.presentation.ui.otherprofile.OtherProfileActivity -class ChatActivity : BaseActivity(R.layout.activity_chat), +class ChatActivity : + BaseActivity(R.layout.activity_chat), ChatNavigationAction { private val viewModel: ChatViewModel by viewModels { ChatViewModel.factory( AppModule.getInstance().subScribeMessageUseCase, - AppModule.getInstance().publishSendUseCase + AppModule.getInstance().publishSendUseCase, ) } private lateinit var adapter: ChatAdapter @@ -39,13 +40,17 @@ class ChatActivity : BaseActivity(R.layout.activity_chat), viewModel.subscribeMessage(chatId, myMemberId) } - private fun clickChatInfo(myMemberId: Long, chatRoomId: Long) { + private fun clickChatInfo( + myMemberId: Long, + chatRoomId: Long, + ) { binding.ibChatSideMenu.setOnClickListener { val chatInfoSideSheet = ChatInfoSideSheet() - chatInfoSideSheet.arguments = ChatInfoSideSheet.getBundle( - myMemberId = myMemberId, - chatRoomId = chatRoomId - ) + chatInfoSideSheet.arguments = + ChatInfoSideSheet.getBundle( + myMemberId = myMemberId, + chatRoomId = chatRoomId, + ) chatInfoSideSheet.show(supportFragmentManager, "") } } @@ -72,11 +77,11 @@ class ChatActivity : BaseActivity(R.layout.activity_chat), } companion object { - private const val INVALID_ID = -1L private const val EXTRA_CHAT_ID = "chatId" private const val EXTRA_MEMBER_ID = "memberId" + fun getIntent( context: Context, chatId: Long, diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatUiModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatUiModel.kt index 991a403b0..aed57c931 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatUiModel.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatUiModel.kt @@ -15,6 +15,6 @@ sealed interface ChatUiModel { val profileUrl: String?, val message: String, val time: LocalTime, - val memberId:Long + val memberId: Long, ) : ChatUiModel } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt index a83b8a036..9e311aa03 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/ChatViewModel.kt @@ -17,7 +17,7 @@ import kotlinx.coroutines.launch class ChatViewModel( private val subScribeMessageUseCase: SubScribeMessageUseCase, - private val publishSendMessageUseCase: PublishSendMessageUseCase + private val publishSendMessageUseCase: PublishSendMessageUseCase, ) : BaseViewModel() { private val _chats: MutableLiveData> = MutableLiveData() val chats: LiveData> get() = _chats @@ -31,7 +31,10 @@ class ChatViewModel( } } - fun subscribeMessage(chatRoomId: Long, myMemberId: Long) { + fun subscribeMessage( + chatRoomId: Long, + myMemberId: Long, + ) { viewModelScope.launch { val newChat = subScribeMessageUseCase(chatRoomId, myMemberId).map { @@ -62,12 +65,12 @@ class ChatViewModel( companion object { fun factory( subScribeMessageUseCase: SubScribeMessageUseCase, - publishSendMessageUseCase: PublishSendMessageUseCase + publishSendMessageUseCase: PublishSendMessageUseCase, ): ViewModelProvider.Factory { return BaseViewModelFactory { _ -> ChatViewModel( subScribeMessageUseCase, - publishSendMessageUseCase + publishSendMessageUseCase, ) } } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatAdapter.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatAdapter.kt index d779c1905..ef6a2fa21 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatAdapter.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatAdapter.kt @@ -12,7 +12,7 @@ import com.happy.friendogly.presentation.ui.chatlist.chat.ChatNavigationAction import com.happy.friendogly.presentation.ui.chatlist.chat.ChatUiModel class ChatAdapter( - private val onMemberClick: ChatNavigationAction + private val onMemberClick: ChatNavigationAction, ) : ListAdapter(ChatDiffCallback) { init { setHasStableIds(true) @@ -65,7 +65,8 @@ class ChatAdapter( inflater, parent, false, - ), onMemberClick + ), + onMemberClick, ) else -> error("$viewType 잘못된 viewType이 들어왔습니다") diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatViewHolder.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatViewHolder.kt index 8a1c27955..caee86a38 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatViewHolder.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chat/adapter/ChatViewHolder.kt @@ -40,7 +40,7 @@ class MineViewHolder(val binding: ItemChatMineBinding) : ChatViewHolder(binding. } } -class OtherViewHolder(val binding: ItemChatOtherBinding, val onMemberClick:ChatNavigationAction) : ChatViewHolder(binding.root) { +class OtherViewHolder(val binding: ItemChatOtherBinding, val onMemberClick: ChatNavigationAction) : ChatViewHolder(binding.root) { fun bind(item: ChatUiModel.Other) { binding.tvChatOtherMessage.text = item.message val timeFormatter = diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoSideSheet.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoSideSheet.kt index 59415a404..27dc2e6a0 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoSideSheet.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoSideSheet.kt @@ -12,7 +12,6 @@ import com.google.android.material.snackbar.Snackbar import com.happy.friendogly.R import com.happy.friendogly.application.di.AppModule import com.happy.friendogly.databinding.LayoutChatDrawerBinding -import com.happy.friendogly.presentation.ui.chatlist.chat.ChatActivity import com.happy.friendogly.presentation.ui.chatlist.chat.ChatNavigationAction import com.happy.friendogly.presentation.ui.permission.AlarmPermission @@ -22,15 +21,16 @@ class ChatInfoSideSheet : BottomSheetDialogFragment() { get() = requireNotNull(_binding) { "${this::class.java.simpleName} is null" } private lateinit var adapter: JoinPeopleAdapter - private val alarmPermission: AlarmPermission = AlarmPermission.from(this) { isPermitted -> - if (!isPermitted) { - Snackbar.make( - binding.root, - getString(R.string.chat_setting_alarm_alert), - Snackbar.LENGTH_SHORT, - ).show() + private val alarmPermission: AlarmPermission = + AlarmPermission.from(this) { isPermitted -> + if (!isPermitted) { + Snackbar.make( + binding.root, + getString(R.string.chat_setting_alarm_alert), + Snackbar.LENGTH_SHORT, + ).show() + } } - } private val viewModel: ChatInfoViewModel by viewModels { ChatInfoViewModel.factory(AppModule.getInstance().getChatMemberUseCase) @@ -121,12 +121,14 @@ class ChatInfoSideSheet : BottomSheetDialogFragment() { } companion object { - private const val EXTRA_MEMBER_ID = "myMemberId" private const val EXTRA_CHAT_ROOM_ID = "chatRoomId" private const val INVALID_ID = -1L - fun getBundle(myMemberId: Long, chatRoomId: Long): Bundle { + fun getBundle( + myMemberId: Long, + chatRoomId: Long, + ): Bundle { return Bundle().apply { putLong(EXTRA_MEMBER_ID, myMemberId) putLong(EXTRA_CHAT_ROOM_ID, chatRoomId) diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoViewModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoViewModel.kt index 45b79d55f..4491d3f48 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoViewModel.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/ChatInfoViewModel.kt @@ -1,11 +1,9 @@ package com.happy.friendogly.presentation.ui.chatlist.chatinfo -import android.util.Log import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope -import androidx.paging.LOG_TAG import com.happy.friendogly.domain.usecase.GetChatMemberUseCase import com.happy.friendogly.presentation.base.BaseViewModel import com.happy.friendogly.presentation.base.BaseViewModelFactory @@ -34,10 +32,11 @@ class ChatInfoViewModel( } fun getClubInfo() { // TODO Api 연결 - _clubInfo.value = ChatInfoUiModel( - dogSize = listOf(DogSize.SMALL), - dogGender = listOf(DogGender.FEMALE), - ) + _clubInfo.value = + ChatInfoUiModel( + dogSize = listOf(DogSize.SMALL), + dogGender = listOf(DogGender.FEMALE), + ) } companion object { diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/JoinPeopleAdapter.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/JoinPeopleAdapter.kt index f49c5356e..f0ad53636 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/JoinPeopleAdapter.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/chatinfo/JoinPeopleAdapter.kt @@ -11,7 +11,7 @@ import com.happy.friendogly.databinding.ItemChatJoinPeopleBinding import com.happy.friendogly.presentation.ui.chatlist.chat.ChatNavigationAction class JoinPeopleAdapter( - private val onMemberClick: ChatNavigationAction + private val onMemberClick: ChatNavigationAction, ) : ListAdapter(ChatInfoDiffCallback) { init { @@ -36,7 +36,7 @@ class JoinPeopleAdapter( class JoinPeopleViewHolder( private val binding: ItemChatJoinPeopleBinding, - private val onClick: ChatNavigationAction + private val onClick: ChatNavigationAction, ) : RecyclerView.ViewHolder(binding.root) { fun bind(item: JoinPeople) { if (item.profileUrl.isNotBlank()) { diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/uimodel/ChatUiMapper.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/uimodel/ChatUiMapper.kt index 340aacf68..a80ce6bac 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/uimodel/ChatUiMapper.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/chatlist/uimodel/ChatUiMapper.kt @@ -33,5 +33,5 @@ fun Message.Other.toUiModel() = message = content, time = dateTime.toLocalTime(), profileUrl = profileUrl, - memberId = memberId + memberId = memberId, ) diff --git a/android/app/src/main/java/com/happy/friendogly/remote/source/ChatDataSourceImpl.kt b/android/app/src/main/java/com/happy/friendogly/remote/source/ChatDataSourceImpl.kt index aa5a63568..5cff771e7 100644 --- a/android/app/src/main/java/com/happy/friendogly/remote/source/ChatDataSourceImpl.kt +++ b/android/app/src/main/java/com/happy/friendogly/remote/source/ChatDataSourceImpl.kt @@ -6,13 +6,14 @@ import com.happy.friendogly.data.source.ChatDataSource import com.happy.friendogly.remote.api.ChatService import com.happy.friendogly.remote.mapper.toData -class ChatDataSourceImpl(private val service:ChatService):ChatDataSource { - override suspend fun getChatList(): Result = runCatching { - service.getChatList().data.toData() - } - - override suspend fun getMembers(chatRoomId: Long): Result> = runCatching { - service.getChatMembers(chatRoomId).body()?.map { it.toData() } ?: emptyList() - } +class ChatDataSourceImpl(private val service: ChatService) : ChatDataSource { + override suspend fun getChatList(): Result = + runCatching { + service.getChatList().data.toData() + } + override suspend fun getMembers(chatRoomId: Long): Result> = + runCatching { + service.getChatMembers(chatRoomId).body()?.map { it.toData() } ?: emptyList() + } } diff --git a/android/app/src/main/java/com/happy/friendogly/remote/source/WebSocketDataSourceImpl.kt b/android/app/src/main/java/com/happy/friendogly/remote/source/WebSocketDataSourceImpl.kt index 2a876b5df..f983e7cd7 100644 --- a/android/app/src/main/java/com/happy/friendogly/remote/source/WebSocketDataSourceImpl.kt +++ b/android/app/src/main/java/com/happy/friendogly/remote/source/WebSocketDataSourceImpl.kt @@ -8,20 +8,20 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map class WebSocketDataSourceImpl(private val service: WebSocketService) : WebSocketDataSource { - override suspend fun publishEnter(chatRoomId: Long): Result = runCatching { - service.publishInvite(chatRoomId) - } + override suspend fun publishEnter(chatRoomId: Long): Result = + runCatching { + service.publishInvite(chatRoomId) + } override suspend fun publishSend( chatRoomId: Long, content: String, - ): Result = runCatching { - service.publishSend(chatRoomId, content) - } + ): Result = + runCatching { + service.publishSend(chatRoomId, content) + } - override suspend fun publishLeave(chatRoomId: Long): Result = - runCatching { service.publishLeave(chatRoomId) } + override suspend fun publishLeave(chatRoomId: Long): Result = runCatching { service.publishLeave(chatRoomId) } - override suspend fun subscribeMessage(chatRoomId: Long): Flow = - service.subscribeMessage(chatRoomId).map { it.toData() } + override suspend fun subscribeMessage(chatRoomId: Long): Flow = service.subscribeMessage(chatRoomId).map { it.toData() } }