Skip to content

Commit

Permalink
style: ktlint 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
gaeun5744 committed Aug 11, 2024
1 parent 2fdb152 commit c60d82a
Show file tree
Hide file tree
Showing 22 changed files with 95 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -226,7 +226,6 @@ class AppModule(context: Context) {
val subScribeMessageUseCase: SubScribeMessageUseCase =
SubScribeMessageUseCase(repository = webSocketRepository)


companion object {
private var instance: AppModule? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatRooms> =
source.getChatList().mapCatching { it.toDomain() }
override suspend fun getChatList(): Result<ChatRooms> = source.getChatList().mapCatching { it.toDomain() }

override suspend fun getMembers(chatRoomId: Long): Result<List<ChatMember>> =
source.getMembers(chatRoomId).mapCatching { member ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatComponent> =
override suspend fun subscribeMessage(
chatRoomId: Long,
myMemberId: Long,
): Flow<ChatComponent> =
source.subscribeMessage(chatRoomId).map {
when (it.messageType) {
MessageTypeDto.ENTER -> it.toEnter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatRoomListDto>

suspend fun getMembers(chatRoomId: Long): Result<List<ChatMemberDto>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import com.happy.friendogly.data.model.MessageDto
import kotlinx.coroutines.flow.Flow

interface WebSocketDataSource {
suspend fun publishEnter(memberId: Long):Result<Unit>
suspend fun publishEnter(memberId: Long): Result<Unit>

suspend fun publishSend(
chatRoomId: Long,
content: String,
):Result<Unit>
): Result<Unit>

suspend fun publishLeave(chatRoomId: Long):Result<Unit>
suspend fun publishLeave(chatRoomId: Long): Result<Unit>

suspend fun subscribeMessage(chatRoomId: Long): Flow<MessageDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ interface WebSocketRepository {

suspend fun publishLeave(chatRoomId: Long): Result<Unit>

suspend fun subscribeMessage(chatRoomId: Long, myMemberId: Long): Flow<ChatComponent>
suspend fun subscribeMessage(
chatRoomId: Long,
myMemberId: Long,
): Flow<ChatComponent>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Unit> =
repository.publishEnter(chatRoomId)
suspend operator fun invoke(chatRoomId: Long): Result<Unit> = repository.publishEnter(chatRoomId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Unit> = repository.publishLeave(chatRoomId)
suspend operator fun invoke(chatRoomId: Long): Result<Unit> = repository.publishLeave(chatRoomId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Unit> =
repository.publishSend(chatRoomId, content)
suspend operator fun invoke(
chatRoomId: Long,
content: String,
): Result<Unit> = repository.publishSend(chatRoomId, content)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatComponent> =
repository.subscribeMessage(chatRoomId, myMemberId)
suspend operator fun invoke(
chatRoomId: Long,
myMemberId: Long,
): Flow<ChatComponent> = repository.subscribeMessage(chatRoomId, myMemberId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ActivityChatBinding>(R.layout.activity_chat),
class ChatActivity :
BaseActivity<ActivityChatBinding>(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
Expand All @@ -39,13 +40,17 @@ class ChatActivity : BaseActivity<ActivityChatBinding>(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, "")
}
}
Expand All @@ -72,11 +77,11 @@ class ChatActivity : BaseActivity<ActivityChatBinding>(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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ sealed interface ChatUiModel {
val profileUrl: String?,
val message: String,
val time: LocalTime,
val memberId:Long
val memberId: Long,
) : ChatUiModel
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<ChatUiModel>> = MutableLiveData()
val chats: LiveData<List<ChatUiModel>> get() = _chats
Expand All @@ -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 {
Expand Down Expand Up @@ -62,12 +65,12 @@ class ChatViewModel(
companion object {
fun factory(
subScribeMessageUseCase: SubScribeMessageUseCase,
publishSendMessageUseCase: PublishSendMessageUseCase
publishSendMessageUseCase: PublishSendMessageUseCase,
): ViewModelProvider.Factory {
return BaseViewModelFactory { _ ->
ChatViewModel(
subScribeMessageUseCase,
publishSendMessageUseCase
publishSendMessageUseCase,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatUiModel, ChatViewHolder>(ChatDiffCallback) {
init {
setHasStableIds(true)
Expand Down Expand Up @@ -65,7 +65,8 @@ class ChatAdapter(
inflater,
parent,
false,
), onMemberClick
),
onMemberClick,
)

else -> error("$viewType 잘못된 viewType이 들어왔습니다")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<JoinPeople, JoinPeopleAdapter.JoinPeopleViewHolder>(ChatInfoDiffCallback) {
init {
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ fun Message.Other.toUiModel() =
message = content,
time = dateTime.toLocalTime(),
profileUrl = profileUrl,
memberId = memberId
memberId = memberId,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatRoomListDto> = runCatching {
service.getChatList().data.toData()
}

override suspend fun getMembers(chatRoomId: Long): Result<List<ChatMemberDto>> = runCatching {
service.getChatMembers(chatRoomId).body()?.map { it.toData() } ?: emptyList()
}
class ChatDataSourceImpl(private val service: ChatService) : ChatDataSource {
override suspend fun getChatList(): Result<ChatRoomListDto> =
runCatching {
service.getChatList().data.toData()
}

override suspend fun getMembers(chatRoomId: Long): Result<List<ChatMemberDto>> =
runCatching {
service.getChatMembers(chatRoomId).body()?.map { it.toData() } ?: emptyList()
}
}
Loading

0 comments on commit c60d82a

Please sign in to comment.