Skip to content

Commit

Permalink
[chore] #98 코드리뷰 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
Doreminwoo committed Jan 12, 2024
1 parent b419ce8 commit e4db7be
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".presentation.ui.joingroup.JoinGroupCodeActivity"
android:exported="true"
android:exported="false"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ package org.sopt.pingle.data.model.remote.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity

@Serializable
data class RequestJoinGroupCodeDto(
@SerialName("code")
val code: String
) {
fun toRequestJoinGroupCode() = RequestJoinGroupCodeEntity(
code = this.code
)
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface JoinGroupService {
@POST("$VERSION/$TEAMS/{$TEAM_ID}/$REGISTER")
suspend fun postJoinGroupCode(
@Path("$TEAM_ID") teamId: Int,
@Body code: RequestJoinGroupCodeDto
@Body requestJoinGroupCodeDto: RequestJoinGroupCodeDto
): BaseResponse<ResponseJoinGroupCodeDto>

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class JoinGroupCodeActivity :

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.joinViewModel = viewModel

initLayout()
addListeners()
Expand All @@ -31,13 +32,12 @@ class JoinGroupCodeActivity :
}

private fun initLayout() {
binding.joinViewModel = viewModel
viewModel.getJoinGroupInfo(TEAM_ID)
viewModel.joinGroupInfoState(TEAM_ID)
}

private fun addListeners() {
binding.btnJoinGroupCodeNext.setOnClickListener {
viewModel.postJoinGroupCode(
viewModel.joinGroupCodeState(
TEAM_ID,
RequestJoinGroupCodeEntity(viewModel.joinGroupCodeEditText.value.toString())
)
Expand All @@ -55,7 +55,7 @@ class JoinGroupCodeActivity :
}

private fun collectData() {
viewModel.joinGroupCodeState.flowWithLifecycle(lifecycle).onEach { uiState ->
viewModel.joinGroupInfoState.flowWithLifecycle(lifecycle).onEach { uiState ->
when (uiState) {
is UiState.Success -> {
with(binding) {
Expand All @@ -82,15 +82,15 @@ class JoinGroupCodeActivity :
}
}.launchIn(lifecycleScope)

viewModel.joinGroupCode.flowWithLifecycle(lifecycle).onEach { uiState ->
viewModel.joinGroupCodeState.flowWithLifecycle(lifecycle).onEach { uiState ->
when (uiState) {
is UiState.Success -> navigateToJoinGroupSuccess()

is UiState.Error -> {
PingleSnackbar.makeSnackbar(
binding.root,
getString(R.string.join_group_code_snackbar_message),
97
SNACKBAR_BOTTOM_MARGIN
)
}

Expand All @@ -114,5 +114,6 @@ class JoinGroupCodeActivity :
const val LOADING = "Loding"
const val EMPTY = "Empty"
const val JOIN_GROUP_CODE_ACTIVITY = "JoinGroupCodeActivity"
const val SNACKBAR_BOTTOM_MARGIN = 97
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ class JoinViewModel @Inject constructor(
private val _joinGroupSearchData = MutableStateFlow<List<JoinGroupSearchEntity>>(emptyList())
val joinGroupSearchData get() = _joinGroupSearchData

private val _joinGroupCodeState =
private val _joinGroupInfoState =
MutableStateFlow<UiState<JoinGroupInfoEntity>>(UiState.Empty)
val joinGroupCodeState get() = _joinGroupCodeState.asStateFlow()
val joinGroupInfoState get() = _joinGroupInfoState.asStateFlow()

private var _isJoinGroupCodeBtn = MutableLiveData(false)
val isJoinGroupCodeBtn get() = _isJoinGroupCodeBtn

private var _joinGroupCode =
private var _joinGroupCodeState =
MutableStateFlow<UiState<ResponseJoinGroupCodeEntity>>(UiState.Empty)
val joinGroupCode get() = _joinGroupCode
val joinGroupCodeState get() = _joinGroupCodeState

val joinGroupCodeEditText = MutableLiveData<String>()

Expand Down Expand Up @@ -72,34 +72,34 @@ class JoinViewModel @Inject constructor(

private fun getIsSelected(position: Int) = _joinGroupSearchData.value[position].isSelected.get()

fun getJoinGroupInfo(teamId: Int) {
_joinGroupCodeState.value = UiState.Loading
fun joinGroupInfoState(teamId: Int) {
_joinGroupInfoState.value = UiState.Loading
viewModelScope.launch {
_joinGroupCodeState.value = UiState.Loading
_joinGroupInfoState.value = UiState.Loading
runCatching {
getJoinGroupInfoUseCase.invoke(teamId = teamId).collect { joinGroupInfo ->
_joinGroupCodeState.value = UiState.Success(joinGroupInfo)
_joinGroupInfoState.value = UiState.Success(joinGroupInfo)
}
}.onFailure {
_joinGroupCodeState.value = UiState.Error(it.message)
_joinGroupInfoState.value = UiState.Error(it.message)
}
}
}

fun postJoinGroupCode(teamId: Int, code: RequestJoinGroupCodeEntity) {
_joinGroupCode.value = UiState.Loading
fun joinGroupCodeState(teamId: Int, code: RequestJoinGroupCodeEntity) {
_joinGroupCodeState.value = UiState.Loading
viewModelScope.launch {
runCatching {
postJoinGroupCodeUseCase.invoke(teamId = teamId, code = code)
postJoinGroupCodeUseCase(teamId = teamId, code = code)
.collect { joinGroupCode ->
_joinGroupCode.value = UiState.Success(joinGroupCode)
_joinGroupCodeState.value = UiState.Success(joinGroupCode)
with(localStorage) {
groupId = joinGroupCode.id
groupName = joinGroupCode.name
}
}
}.onFailure {
_joinGroupCode.value = UiState.Error(it.message)
_joinGroupCodeState.value = UiState.Error(it.message)
}
}
}
Expand Down

0 comments on commit e4db7be

Please sign in to comment.