Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/android/exception catch: Exception 분기 처리 및 가로모드 대응 추가 #227

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8b30dc8
refactor: repository exception 처리
p-chanmin Dec 11, 2023
54e06e1
feat: 로그인 만료시 LoginActivity 이동 함수 base 구현
p-chanmin Dec 11, 2023
2c48bd1
feat: 일정 추가 Activity exception 분기 처리
p-chanmin Dec 11, 2023
099daf0
feat: follow Ui 로딩 화면 추가
p-chanmin Dec 11, 2023
9a595e9
refactor: 로그인 만료시 LoginActivity 이동 함수 base fragment 이동
p-chanmin Dec 11, 2023
449886a
feat: follow fragment exception 분기 처리
p-chanmin Dec 11, 2023
3c8b0b7
refactor: FollowUiEvent 네이밍 변경
p-chanmin Dec 11, 2023
471e10a
feat: selfLogin fragment exception 분기 처리
p-chanmin Dec 11, 2023
98f5f18
refactor: SelfLoginUiEvent 네이밍 변경
p-chanmin Dec 11, 2023
0013f59
feat: SignUpfragment exception 분기 처리
p-chanmin Dec 11, 2023
4601f71
refactor: SignUpUiEvent 네이밍 변경
p-chanmin Dec 11, 2023
b16cc40
feat: NotificationFragment exception 분기 처리
p-chanmin Dec 11, 2023
0c33148
feat: SettingAccountFragment exception 분기 처리
p-chanmin Dec 11, 2023
12e07e6
feat: SettingHomeFragment exception 분기 처리
p-chanmin Dec 11, 2023
bad176d
refactor: SettingHomeUiEvent 네이밍 변경
p-chanmin Dec 11, 2023
4289306
feat: SettingPasswordChangeFragment exception 분기 처리
p-chanmin Dec 11, 2023
4752049
feat: SettingProfileFragment exception 분기 처리
p-chanmin Dec 11, 2023
858cd58
refactor: 프로필 변경 flow combine 변경 (#55)
p-chanmin Dec 11, 2023
7fa7b84
refactor: 가로모드 대응 스크롤뷰 추가
p-chanmin Dec 11, 2023
83f861d
feat: AddEventActivity exception 분기 처리
p-chanmin Dec 11, 2023
c8791dd
refactor: @StringRes 어노테이션 추가
p-chanmin Dec 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.teameetmeet.meetmeet.data.network.entity.AddEventRequest
import com.teameetmeet.meetmeet.data.network.entity.EventResponse
import com.teameetmeet.meetmeet.data.network.entity.UserEventResponse
import com.teameetmeet.meetmeet.data.toEvent
import com.teameetmeet.meetmeet.data.toException
import com.teameetmeet.meetmeet.presentation.model.EventColor
import com.teameetmeet.meetmeet.presentation.model.EventNotification
import com.teameetmeet.meetmeet.util.date.DateTimeFormat
Expand Down Expand Up @@ -71,7 +72,7 @@ class CalendarRepository @Inject constructor(
)
return remoteCalendarDataSource.addEvent(request)
.catch {
throw it
throw it.toException()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class EventStoryRepository @Inject constructor(
val request = EventInviteRequest(userId = userId, eventId = eventId)
eventStoryApi.inviteEvent(request)
}.catch {
throw it
throw it.toException()
}
}

Expand All @@ -199,7 +199,7 @@ class EventStoryRepository @Inject constructor(
.map {
eventStoryApi.getFollowingWithEventStatus(eventId).users
}.catch {
throw it
throw it.toException()
}
}

Expand All @@ -208,7 +208,7 @@ class EventStoryRepository @Inject constructor(
.map {
eventStoryApi.getFollowerWithEventStatus(eventId).users
}.catch {
throw it
throw it.toException()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FollowRepository @Inject constructor(
.map {
followApi.getFollowingWithFollowStatus().users
}.catch {
throw it
throw it.toException()
}
}

Expand All @@ -46,7 +46,7 @@ class FollowRepository @Inject constructor(
.map {
followApi.getFollowerWithFollowStatus().users
}.catch {
throw it
throw it.toException()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.teameetmeet.meetmeet.data.local.datastore.DataStoreHelper
import com.teameetmeet.meetmeet.data.network.api.LoginApi
import com.teameetmeet.meetmeet.data.network.entity.KakaoLoginRequest
import com.teameetmeet.meetmeet.data.network.entity.SelfSignRequest
import com.teameetmeet.meetmeet.data.toException
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flowOf
Expand Down Expand Up @@ -33,7 +34,7 @@ class LoginRepository @Inject constructor(
val response = loginApi.loginSelf(request)
storeAppToken(response.accessToken, response.refreshToken)
}.catch {
throw it
throw it.toException()
}
}

Expand All @@ -43,7 +44,7 @@ class LoginRepository @Inject constructor(
val response = loginApi.checkEmailDuplication(email)
response.isAvailable
}.catch {
throw it
throw it.toException()
}
}

Expand All @@ -55,7 +56,7 @@ class LoginRepository @Inject constructor(
val response = loginApi.loginSelf(request)
storeAppToken(response.accessToken, response.refreshToken)
}.catch {
throw it
throw it.toException()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class UserRepository @Inject constructor(
dataStore.deleteUserProfile()
dataStore.deleteAppToken()
}.catch {
throw it
throw it.toException()
}
}

Expand All @@ -115,7 +115,7 @@ class UserRepository @Inject constructor(
val response = userApi.checkNickNameDuplication(nickname)
response.isAvailable
}.catch {
throw it
throw it.toException()
}
}

Expand All @@ -124,7 +124,7 @@ class UserRepository @Inject constructor(
.map {
userApi.patchPassword(PasswordChangeRequest(password))
}.catch {
throw it
throw it.toException()
}
}

Expand All @@ -133,7 +133,7 @@ class UserRepository @Inject constructor(
.map {
userApi.patchNickname(NicknameChangeRequest(nickname))
}.catch {
throw it
throw it.toException()
}
}

Expand All @@ -157,7 +157,7 @@ class UserRepository @Inject constructor(
userApi.updateProfileImage(profileImageRequest)
imageFile?.delete()
}.catch {
throw it
throw it.toException()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ class AddEventActivity : BaseActivity<ActivityAddEventBinding>(R.layout.activity
viewModel.event.collect { event ->
when (event) {
is AddEventUiEvent.ShowMessage -> showMessage(
event.messageId,
event.extraMessage
event.messageId, event.extraMessage
)

is AddEventUiEvent.FinishAddEventActivity -> {
finish()
}

is AddEventUiEvent.NavigateToLoginActivity -> {
navigateToLoginActivity()
}
}
}
}
Expand Down Expand Up @@ -120,15 +123,13 @@ class AddEventActivity : BaseActivity<ActivityAddEventBinding>(R.layout.activity
}

private fun setDateTimePicker() {
val dateRangePicker =
MaterialDatePicker.Builder.dateRangePicker()
.setTitleText(getString(R.string.add_event_title))
.setSelection(
Pair(
viewModel.uiState.value.startDate.toLong(ZoneId.of("UTC")),
viewModel.uiState.value.endDate.toLong(ZoneId.of("UTC"))
)
).build()
val dateRangePicker = MaterialDatePicker.Builder.dateRangePicker()
.setTitleText(getString(R.string.add_event_title)).setSelection(
Pair(
viewModel.uiState.value.startDate.toLong(ZoneId.of("UTC")),
viewModel.uiState.value.endDate.toLong(ZoneId.of("UTC"))
)
).build()

dateRangePicker.addOnPositiveButtonClickListener {
viewModel.setEventDate(
Expand Down Expand Up @@ -157,8 +158,7 @@ class AddEventActivity : BaseActivity<ActivityAddEventBinding>(R.layout.activity
val startTimePicker = MaterialTimePicker.Builder().setTimeFormat(TimeFormat.CLOCK_12H)
.setHour(viewModel.uiState.value.startTime.hour)
.setMinute(viewModel.uiState.value.startTime.minute)
.setTitleText(getString(R.string.add_event_err_start_time))
.build()
.setTitleText(getString(R.string.add_event_err_start_time)).build()

startTimePicker.addOnPositiveButtonClickListener {
viewModel.setEventStartTime(startTimePicker.hour, startTimePicker.minute)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.teameetmeet.meetmeet.presentation.addevent

import androidx.annotation.StringRes

sealed class AddEventUiEvent {
data class ShowMessage(val messageId: Int, val extraMessage: String = "") : AddEventUiEvent()
data class ShowMessage(@StringRes val messageId: Int, val extraMessage: String = "") :
AddEventUiEvent()

data object FinishAddEventActivity : AddEventUiEvent()
data object NavigateToLoginActivity : AddEventUiEvent()
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.teameetmeet.meetmeet.presentation.addevent

import android.widget.RadioGroup
import androidx.annotation.StringRes
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.teameetmeet.meetmeet.R
import com.teameetmeet.meetmeet.data.ExpiredRefreshTokenException
import com.teameetmeet.meetmeet.data.network.entity.EventResponse
import com.teameetmeet.meetmeet.data.repository.CalendarRepository
import com.teameetmeet.meetmeet.presentation.model.EventColor
Expand All @@ -26,6 +28,7 @@ import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import java.net.UnknownHostException
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.temporal.ChronoUnit
Expand All @@ -37,10 +40,6 @@ class AddEventViewModel @Inject constructor(
private val alarmHelper: AlarmHelper
) : ViewModel() {

companion object {
const val MAX_ALARM_COUNT = 2
}

private val _uiState = MutableStateFlow(AddEventUiState())
val uiState: StateFlow<AddEventUiState> = _uiState

Expand Down Expand Up @@ -84,16 +83,17 @@ class AddEventViewModel @Inject constructor(
color = color,
alarm = alarm,
).catch {
_event.emit(AddEventUiEvent.ShowMessage(R.string.add_event_err_fail))
emitExceptionEvent(it, R.string.add_event_err_fail)
_showPlaceholder.update { false }
}.collectLatest { events ->
events.take(MAX_ALARM_COUNT).forEach { event ->
setAlarm(event)
}
_event.emit(AddEventUiEvent.FinishAddEventActivity)
_showPlaceholder.update { false }
}
_event.emit(AddEventUiEvent.FinishAddEventActivity)
}
}
_showPlaceholder.update { false }
}
}

Expand Down Expand Up @@ -159,7 +159,23 @@ class AddEventViewModel @Inject constructor(
)
}
}
}

private suspend fun emitExceptionEvent(e: Throwable, @StringRes message: Int) {
when (e) {
is ExpiredRefreshTokenException -> {
_event.emit(AddEventUiEvent.ShowMessage(R.string.common_message_expired_login))
_event.emit(AddEventUiEvent.NavigateToLoginActivity)
}

is UnknownHostException -> {
_event.emit(AddEventUiEvent.ShowMessage(R.string.common_message_no_internet))
}

else -> {
_event.emit(AddEventUiEvent.ShowMessage(message))
}
}
}

fun setEventMemo(memo: CharSequence) {
Expand Down Expand Up @@ -225,4 +241,8 @@ class AddEventViewModel @Inject constructor(
it.copy(color = EventColor.values()[index])
}
}

companion object {
const val MAX_ALARM_COUNT = 2
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.teameetmeet.meetmeet.presentation.base

import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.teameetmeet.meetmeet.presentation.login.LoginActivity

abstract class BaseActivity<T : ViewDataBinding>(private val layoutResId: Int) :
AppCompatActivity() {
Expand All @@ -28,4 +30,9 @@ abstract class BaseActivity<T : ViewDataBinding>(private val layoutResId: Int) :
Toast.makeText(this, getString(messageId), Toast.LENGTH_SHORT).show()
}
}

protected fun navigateToLoginActivity() {
startActivity(Intent(this, LoginActivity::class.java))
finishAffinity()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.teameetmeet.meetmeet.presentation.base

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -8,6 +9,7 @@ import android.widget.Toast
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import com.teameetmeet.meetmeet.presentation.login.LoginActivity

abstract class BaseFragment<T : ViewDataBinding>(private val layoutResId: Int) : Fragment() {

Expand Down Expand Up @@ -38,4 +40,9 @@ abstract class BaseFragment<T : ViewDataBinding>(private val layoutResId: Int) :
Toast.makeText(requireContext(), getString(messageId), Toast.LENGTH_SHORT).show()
}
}

protected fun navigateToLoginActivity() {
startActivity(Intent(requireActivity(), LoginActivity::class.java))
requireActivity().finishAffinity()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@ class EventStoryFragment : BaseFragment<FragmentEventStoryBinding>(R.layout.frag
}
}

private fun navigateToLoginActivity() {
findNavController().navigate(EventStoryFragmentDirections.actionEventStoryFragmentToLoginActivity())
requireActivity().finishAffinity()
}


private fun navigateToEventDetailFragment() {
findNavController().navigate(
EventStoryFragmentDirections.actionEventStoryFragmentToEventStoryDetailFragment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ class EventStoryDetailFragment :
binding.vm = viewModel
}

private fun navigateToLoginActivity() {
findNavController().navigate(EventStoryDetailFragmentDirections.actionEventStoryDetailFragmentToLoginActivity())
requireActivity().finishAffinity()
}

private fun setRepeatOptions() {
binding.storyDetailEtEventRepeat.setOnItemClickListener { _, _, index, _ ->
viewModel.setEventRepeat(index)
Expand Down

This file was deleted.

Loading