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

[FIX] 기술적 QA 수정 #149

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file modified buildSrc/build/kotlin/compileKotlin/cacheable/last-build.bin
Binary file not shown.
Binary file modified buildSrc/build/kotlin/compileKotlin/local-state/build-history.bin
Binary file not shown.
Binary file modified buildSrc/build/libs/buildSrc.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.depromeet.presentation.R
import com.depromeet.presentation.databinding.ActivityProfileEditBinding
import com.dpm.core.base.BaseActivity
import com.dpm.core.state.UiState
import com.dpm.designsystem.SpotImageSnackBar
import com.dpm.domain.entity.response.home.ResponseBaseballTeam
import com.dpm.presentation.extension.dpToPx
import com.dpm.presentation.extension.loadAndCircleProfile
Expand Down Expand Up @@ -110,7 +111,7 @@ class ProfileEditActivity : BaseActivity<ActivityProfileEditBinding>(
viewModel.events.collect { event ->
when (event) {
is ProfileEvents.ShowSnackMessage -> {
toast(event.message)
//
}
}
}
Expand Down Expand Up @@ -178,11 +179,11 @@ class ProfileEditActivity : BaseActivity<ActivityProfileEditBinding>(
is UiState.Loading -> {}
is UiState.Success -> {}
is UiState.Failure -> {
toast("이미지 업로드를 실패하였습니다. 다시 선택해주세요.")
makeSpotImageAppbar("이미지 업로드를 실패하였습니다. 다시 선택해주세요.")
}

is UiState.Empty -> {
toast("실패")
makeSpotImageAppbar("이미지 업로드를 실패하였습니다. 다시 선택해주세요.")
}
}
}
Expand All @@ -201,11 +202,11 @@ class ProfileEditActivity : BaseActivity<ActivityProfileEditBinding>(
}

is UiState.Failure -> {
toast("프로필 변경에 실패\n다시 시도바람")
makeSpotImageAppbar("프로필 변경을 실패하였습니다. 다시 시도 바랍니다")
}

is UiState.Empty -> {
toast("프로필 변경 실패\n다시 시도바람(빈값")
makeSpotImageAppbar("프로필 변경을 실패하였습니다. 다시 시도 바랍니다")
}

is UiState.Loading -> {}
Expand All @@ -225,15 +226,15 @@ class ProfileEditActivity : BaseActivity<ActivityProfileEditBinding>(
}

is UiState.Loading -> {
toast("로딩 중")

}

is UiState.Empty -> {
toast("빈값 에러")
makeSpotImageAppbar("팀불러오기를 실패하였습니다.")
}

is UiState.Failure -> {
toast("통신 실패")
makeSpotImageAppbar("팀불러오기를 실패하였습니다.")
}
}
}
Expand Down Expand Up @@ -285,4 +286,15 @@ class ProfileEditActivity : BaseActivity<ActivityProfileEditBinding>(
)
}

private fun makeSpotImageAppbar(message: String) {
SpotImageSnackBar.make(
view = binding.root,
message = message,
messageColor = com.depromeet.designsystem.R.color.color_foreground_white,
icon = com.depromeet.designsystem.R.drawable.ic_alert_circle,
iconColor = com.depromeet.designsystem.R.color.color_error_secondary,
marginBottom = 20
).show()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ class SeatRecordActivity : BaseActivity<ActivitySeatRecordBinding>(
setShimmer(false)
monthSeatReviewAdapter.submitList(emptyList())
makeSpotImageAppbar("해당 날짜에 작성한 글이 없습니다.")
setErrorVisibility(SeatRecordErrorType.EMPTY)
}

is UiState.Failure -> {
Expand All @@ -337,6 +338,7 @@ class SeatRecordActivity : BaseActivity<ActivitySeatRecordBinding>(
setShimmer(false)
monthSeatReviewAdapter.submitList(emptyList())
makeSpotImageAppbar("해당 날짜에 작성한 글이 없습니다.")
setErrorVisibility(SeatRecordErrorType.EMPTY)
}

is UiState.Failure -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.dpm.presentation.setting

import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.fragment.app.commit
import androidx.lifecycle.asLiveData
Expand All @@ -12,6 +14,7 @@ import com.depromeet.presentation.databinding.ActivitySettingBinding
import com.dpm.presentation.extension.toast
import com.dpm.presentation.home.ProfileEditActivity
import com.dpm.presentation.login.ui.SignUpActivity
import com.dpm.presentation.seatrecord.SeatRecordActivity
import dagger.hilt.android.AndroidEntryPoint


Expand All @@ -21,6 +24,19 @@ class SettingActivity : BaseActivity<ActivitySettingBinding>(
){
private val viewModel : SettingViewModel by viewModels()

private val editProfileLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
val data = result.data
val nickname = data?.getStringExtra(ProfileEditActivity.PROFILE_NAME) ?: ""
val profileImage = data?.getStringExtra(ProfileEditActivity.PROFILE_IMAGE) ?: ""
val teamId = data?.getIntExtra(ProfileEditActivity.PROFILE_CHEER_TEAM_ID, 0) ?: 0
val teamName = data?.getStringExtra(ProfileEditActivity.PROFILE_CHEER_TEAM_NAME)

viewModel.updateProfile(nickname, profileImage, teamId, teamName)
}
}


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -63,6 +79,7 @@ class SettingActivity : BaseActivity<ActivitySettingBinding>(

private fun initView() {
binding.tvSettingAppVersion.text = "V.${packageManager.getPackageInfo(this.packageName, 0).versionName}"
viewModel.getProfile()
}

private fun initEvent() = with(binding){
Expand All @@ -71,9 +88,7 @@ class SettingActivity : BaseActivity<ActivitySettingBinding>(
}

ivSettingMyProfile.setOnClickListener {
Intent(this@SettingActivity, ProfileEditActivity::class.java).apply {
startActivity(this)
}
navigateToProfileEditActivity()
}

clSettingFeedback.setOnClickListener {
Expand Down Expand Up @@ -124,4 +139,12 @@ class SettingActivity : BaseActivity<ActivitySettingBinding>(
.show(supportFragmentManager, "tag")
}
}

private fun navigateToProfileEditActivity() {
editProfileLauncher.launch(Intent(this, ProfileEditActivity::class.java).apply {
putExtra(SeatRecordActivity.PROFILE_NAME, viewModel.profile.value.nickname)
putExtra(SeatRecordActivity.PROFILE_IMAGE, viewModel.profile.value.profileImage)
putExtra(SeatRecordActivity.PROFILE_CHEER_TEAM, viewModel.profile.value.teamId)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.dpm.presentation.setting

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.dpm.domain.entity.response.home.ResponseUserInfo
import com.dpm.domain.preference.SharedPreference
import com.dpm.domain.repository.HomeRepository
import com.dpm.domain.repository.SignupRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.channels.BufferOverflow
Expand All @@ -25,6 +27,7 @@ sealed class WithdrawState {

@HiltViewModel
class SettingViewModel @Inject constructor(
private val homeRepository : HomeRepository,
private val sharedPreference: SharedPreference,
private val signupRepository: SignupRepository
) : ViewModel() {
Expand All @@ -39,6 +42,10 @@ class SettingViewModel @Inject constructor(
private val _withdrawState = MutableStateFlow<WithdrawState>(WithdrawState.Init)
val withdrawState : StateFlow<WithdrawState> = _withdrawState.asStateFlow()

private val _profile =
MutableStateFlow(ResponseUserInfo())
val profile = _profile.asStateFlow()

fun logout() {
sharedPreference.clear()
_logoutEvent.tryEmit(Unit)
Expand All @@ -55,4 +62,49 @@ class SettingViewModel @Inject constructor(
}
}
}

fun getProfile(){
viewModelScope.launch {
homeRepository.getMyUserInfo()
.onSuccess {data ->
_profile.value = data
saveLocalProfile()
}
.onFailure {
getLocalProfile()
}
}
}

private fun saveLocalProfile() {
val profile = _profile.value
sharedPreference.level = profile.level
sharedPreference.profileImage = profile.profileImage
sharedPreference.nickname = profile.nickname
sharedPreference.teamId = profile.teamId ?: 0
sharedPreference.teamName = profile.teamName ?: ""
sharedPreference.levelTitle = profile.levelTitle

}

fun getLocalProfile() {
_profile.value = profile.value.copy(
level = sharedPreference.level,
levelTitle = sharedPreference.levelTitle,
nickname = sharedPreference.nickname,
teamId = sharedPreference.teamId,
teamName = sharedPreference.teamName,
profileImage = sharedPreference.profileImage
)
}

fun updateProfile(nickname: String, profileImage: String, teamId: Int, teamName: String?) {
_profile.value = profile.value.copy(
nickname = nickname, profileImage = profileImage, teamId = teamId, teamName = teamName
)
sharedPreference.nickname = nickname
sharedPreference.profileImage = profileImage
sharedPreference.teamId = teamId
sharedPreference.teamName = teamName ?: ""
}
}
2 changes: 1 addition & 1 deletion presentation/src/main/res/layout/activity_seat_record.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="196dp" />
app:layout_constraintGuide_percent="0.5" />

<TextView
android:id="@+id/tvSeatView"
Expand Down
Loading