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/#157] 사진 생성 대기뷰 UI 리디자인 #158

Merged
merged 5 commits into from
Oct 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PushDialog : BaseDialog<DialogPushBinding>(R.layout.dialog_push) {
super.onStart()
dialog?.window?.apply {
setLayout(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,
)
setBackgroundDrawableResource(R.color.transparent)
Expand All @@ -50,7 +50,12 @@ class PushDialog : BaseDialog<DialogPushBinding>(R.layout.dialog_push) {
}

private fun initCloseBtnListener() {
binding.btnClose.setOnSingleClickListener { dismiss() }
binding.btnClose.setOnSingleClickListener {
with(requireActivity()) {
setResult(Activity.RESULT_OK)
finish()
}
}
}

private fun initGetAlarmBtnListener() {
Expand Down Expand Up @@ -92,13 +97,4 @@ class PushDialog : BaseDialog<DialogPushBinding>(R.layout.dialog_push) {
requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
}
}

override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)

with(requireActivity()) {
setResult(Activity.RESULT_OK)
finish()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ import kr.genti.core.extension.stringOf
import kr.genti.core.extension.toast
import kr.genti.core.state.UiState
import kr.genti.domain.entity.response.ImageModel
import kr.genti.domain.enums.GenerateStatus
import kr.genti.presentation.R
import kr.genti.presentation.create.CreateActivity
import kr.genti.presentation.databinding.FragmentProfileBinding
import kr.genti.presentation.generate.waiting.WaitingActivity
import kr.genti.presentation.main.CreateErrorDialog
import kr.genti.presentation.main.CreateFinishedDialog
import kr.genti.presentation.main.CreateUnableDialog
import kr.genti.presentation.setting.SettingActivity
import kr.genti.presentation.util.AmplitudeManager

Expand All @@ -34,6 +39,9 @@ class ProfileFragment() : BaseFragment<FragmentProfileBinding>(R.layout.fragment
private val viewModel by activityViewModels<ProfileViewModel>()

private var profileImageDialog: ProfileImageDialog? = null
private var createFinishedDialog: CreateFinishedDialog? = null
private var createErrorDialog: CreateErrorDialog? = null
private var createUnableDialog: CreateUnableDialog? = null

override fun onViewCreated(
view: View,
Expand All @@ -47,6 +55,7 @@ class ProfileFragment() : BaseFragment<FragmentProfileBinding>(R.layout.fragment
setListWithInfinityScroll()
observeGenerateStatus()
observePictureListPageState()
observeServerAvailableState()
}

private fun initView() {
Expand Down Expand Up @@ -78,7 +87,27 @@ class ProfileFragment() : BaseFragment<FragmentProfileBinding>(R.layout.fragment
}

private fun initMoveClickListener(x: Boolean) {
startActivity(Intent(requireActivity(), CreateActivity::class.java))
when (viewModel.currentStatus) {
GenerateStatus.NEW_REQUEST_AVAILABLE -> {
viewModel.getIsServerAvailable()
}

GenerateStatus.AWAIT_USER_VERIFICATION -> {
createFinishedDialog = CreateFinishedDialog()
createFinishedDialog?.show(parentFragmentManager, DIALOG_FINISHED)
}

GenerateStatus.IN_PROGRESS -> {
startActivity(Intent(requireActivity(), WaitingActivity::class.java))
}

GenerateStatus.CANCELED -> {
createErrorDialog = CreateErrorDialog()
createErrorDialog?.show(parentFragmentManager, DIALOG_ERROR)
}

GenerateStatus.EMPTY -> return
}
}

private fun setListWithInfinityScroll() {
Expand Down Expand Up @@ -153,13 +182,41 @@ class ProfileFragment() : BaseFragment<FragmentProfileBinding>(R.layout.fragment
}
}

private fun observeServerAvailableState() {
viewModel.serverAvailableState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
is UiState.Success -> {
if (state.data.status) {
AmplitudeManager.trackEvent("click_createpictab")
startActivity(Intent(requireActivity(), CreateActivity::class.java))
} else {
createUnableDialog =
CreateUnableDialog.newInstance(state.data.message.orEmpty())
createUnableDialog?.show(parentFragmentManager, DIALOG_UNABLE)
}
}

is UiState.Failure -> toast(stringOf(R.string.error_msg))
else -> return@onEach
}
viewModel.resetIsServerAvailable()
}.launchIn(lifecycleScope)
}

override fun onDestroyView() {
super.onDestroyView()
_adapter = null
profileImageDialog = null
createFinishedDialog = null
createErrorDialog = null
createUnableDialog = null
}

companion object {
private const val IMAGE_VIEWER = "IMAGE_VIEWER"

private const val DIALOG_FINISHED = "DIALOG_FINISHED"
private const val DIALOG_ERROR = "DIALOG_ERROR"
private const val DIALOG_UNABLE = "DIALOG_UNABLE"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,66 +8,92 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import kr.genti.core.state.UiState
import kr.genti.domain.entity.response.PicturePagedListModel
import kr.genti.domain.entity.response.ServerAvailableModel
import kr.genti.domain.enums.GenerateStatus
import kr.genti.domain.repository.GenerateRepository
import javax.inject.Inject

@HiltViewModel
class ProfileViewModel
@Inject
constructor(
private val generateRepository: GenerateRepository,
) : ViewModel() {
private val _getGenerateStatusState =
MutableStateFlow<UiState<Boolean>>(UiState.Empty)
val getGenerateStatusState: StateFlow<UiState<Boolean>> = _getGenerateStatusState
@Inject
constructor(
private val generateRepository: GenerateRepository,
) : ViewModel() {
private val _getGenerateStatusState =
MutableStateFlow<UiState<Boolean>>(UiState.Empty)
val getGenerateStatusState: StateFlow<UiState<Boolean>> = _getGenerateStatusState

private val _getPictureListState =
MutableStateFlow<UiState<PicturePagedListModel>>(UiState.Loading)
val getPictureListState: StateFlow<UiState<PicturePagedListModel>> = _getPictureListState
var currentStatus: GenerateStatus = GenerateStatus.NEW_REQUEST_AVAILABLE

private var currentPage = -1
private var isPagingFinish = false
private var totalPage = Int.MAX_VALUE
private val _serverAvailableState =
MutableStateFlow<UiState<ServerAvailableModel>>(UiState.Empty)
val serverAvailableState: StateFlow<UiState<ServerAvailableModel>> = _serverAvailableState

var isFirstLoading = true
private val _getPictureListState =
MutableStateFlow<UiState<PicturePagedListModel>>(UiState.Loading)
val getPictureListState: StateFlow<UiState<PicturePagedListModel>> = _getPictureListState

fun getGenerateStatusFromServer() {
viewModelScope.launch {
_getGenerateStatusState.value = UiState.Loading
generateRepository.getGenerateStatus()
.onSuccess {
_getGenerateStatusState.value =
UiState.Success(it.status == GenerateStatus.IN_PROGRESS)
}
.onFailure { t ->
_getGenerateStatusState.value = UiState.Failure(t.message.toString())
}
}
private var currentPage = -1
private var isPagingFinish = false
private var totalPage = Int.MAX_VALUE

var isFirstLoading = true

fun getGenerateStatusFromServer() {
viewModelScope.launch {
_getGenerateStatusState.value = UiState.Loading
generateRepository.getGenerateStatus()
.onSuccess {
currentStatus = it.status
_getGenerateStatusState.value =
UiState.Success(it.status == GenerateStatus.IN_PROGRESS)

}
.onFailure { t ->
_getGenerateStatusState.value = UiState.Failure(t.message.toString())
}
}
}

fun getIsServerAvailable() {
_serverAvailableState.value = UiState.Loading
viewModelScope.launch {
generateRepository
.getIsServerAvailable()
.onSuccess {
_serverAvailableState.value = UiState.Success(it)
}.onFailure {
_serverAvailableState.value = UiState.Failure(it.message.orEmpty())
}
}
}

fun resetIsServerAvailable() {
_serverAvailableState.value = UiState.Empty
}

fun getPictureListFromServer() {
viewModelScope.launch {
if (isPagingFinish) return@launch
_getPictureListState.value = UiState.Loading
generateRepository.getGeneratedPictureList(
++currentPage,
10,
null,
null,
)
.onSuccess {
totalPage = it.totalPages - 1
if (totalPage == currentPage) isPagingFinish = true
if (it.content.isEmpty()) {
_getPictureListState.value = UiState.Empty
return@launch
}
if (isFirstLoading) isFirstLoading = false
_getPictureListState.value = UiState.Success(it)
}.onFailure {
_getPictureListState.value = UiState.Failure(it.message.toString())
fun getPictureListFromServer() {
viewModelScope.launch {
if (isPagingFinish) return@launch
_getPictureListState.value = UiState.Loading
generateRepository.getGeneratedPictureList(
++currentPage,
10,
null,
null,
)
.onSuccess {
totalPage = it.totalPages - 1
if (totalPage == currentPage) isPagingFinish = true
if (it.content.isEmpty()) {
_getPictureListState.value = UiState.Empty
return@launch
}
}
if (isFirstLoading) isFirstLoading = false
_getPictureListState.value = UiState.Success(it)
}.onFailure {
_getPictureListState.value = UiState.Failure(it.message.toString())
}
}
}
}
Binary file modified presentation/src/main/res/drawable/img_alarm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added presentation/src/main/res/drawable/img_glow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
24 changes: 0 additions & 24 deletions presentation/src/main/res/drawable/img_waiting_title.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="16dp"/>
<solid android:color="@color/gray" />
</shape>
Loading
Loading