Skip to content

Commit

Permalink
Merge pull request #125 from depromeet/feat/#123-viewfinder2-v4
Browse files Browse the repository at this point in the history
[FEAT] 시야찾기 2차 MVP 4번째 구현
  • Loading branch information
Jokwanhee authored Aug 25, 2024
2 parents 8c8b348 + 0fe808e commit 81541da
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ data class ResponseBlockReviewDto(
val scrapsCount: Long,
@SerialName("reviewType")
val reviewType: String?,
) {
@SerialName("isLiked")
val isLiked: Boolean,
@SerialName("isScrapped")
val isScrapped: Boolean,
) {
@Serializable
data class ResponseReviewImageDto(
@SerialName("id")
Expand Down Expand Up @@ -198,11 +202,11 @@ fun ResponseBlockReviewDto.ResponseReviewDto.toReviewResponse() =
content = content ?: "",
images = images.map { it.toReviewImageResponse() },
keywords = keywords.map { it.toReviewKeywordResponse() },
isLike = false,
isScrap = false,
isLike = isLiked,
isScrap = isScrapped,
likesCount = likesCount,
scrapsCount = scrapsCount,
reviewType = reviewType ?: ""
reviewType = reviewType ?: "",
)

fun ResponseBlockReviewDto.ResponseLocationDto.toLocationResponse() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,15 @@ class HomeActivity : BaseActivity<ActivityHomeBinding>(
endMessage = "확인하러 가기",
marginBottom = 93,
) {
// TODO : onclick -> 방금 작성한 시야 후기 상세페이지 게시물 화면으로 이동
val reviewData = intent.getCompatibleParcelableExtra<ReviewData>(REVIEW_DATA)
if (reviewData != null) {
Intent(this@HomeActivity, StadiumDetailActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
putExtra(SchemeKey.STADIUM_ID, reviewData.stadiumId)
putExtra(SchemeKey.BLOCK_CODE, reviewData.blockCode)
putExtra(SchemeKey.REVIEW_ID, reviewData.reviewId)
}.let { startActivity(it) }
}
}.show()
}
}
Expand Down Expand Up @@ -298,9 +306,23 @@ class HomeActivity : BaseActivity<ActivityHomeBinding>(
val navReview = intent.getCompatibleParcelableExtra<SchemeState.NavReview>(SchemeKey.NAV_REVIEW)
if (navReview != null) {
Intent(this, StadiumDetailActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
putExtra(SchemeKey.STADIUM_ID, navReview.stadiumId)
putExtra(SchemeKey.BLOCK_CODE, navReview.blockCode)
}.let { startActivity(it) }
}
navigateToReviewDetail()
}

private fun navigateToReviewDetail() {
val navReviewDetail = intent.getCompatibleParcelableExtra<SchemeState.NavReviewDetail>(SchemeKey.NAV_REVIEW_DETAIL)
if (navReviewDetail != null) {
Intent(this, StadiumDetailActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
putExtra(SchemeKey.STADIUM_ID, navReviewDetail.stadiumId)
putExtra(SchemeKey.BLOCK_CODE, navReviewDetail.blockCode)
putExtra(SchemeKey.REVIEW_ID, navReviewDetail.reviewId)
}.let { startActivity(it) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class ReviewActivity : BaseActivity<ActivityReviewBinding>({
}

private val viewModel by viewModels<ReviewViewModel>()
private val method by lazy { intent.getStringExtra(METHOD_KEY)?.let { ReviewMethod.valueOf(it) } }
private val method by lazy {
intent.getStringExtra(METHOD_KEY)?.let { ReviewMethod.valueOf(it) }
}
private val selectedImage: List<ImageView> by lazy {
listOf(
binding.ivFirstImage,
Expand Down Expand Up @@ -125,11 +127,13 @@ class ReviewActivity : BaseActivity<ActivityReviewBinding>({
binding.tvAddImage.text = "야구장 시야 사진을\n올려주세요"
binding.tvReviewMySeat.text = "내 시야 후기"
}

ReviewMethod.FEED -> {
binding.tvTitle.text = "경기의 순간을 간직해보세요"
binding.tvAddImage.text = "직관후기 사진을\n올려주세요"
binding.tvReviewMySeat.text = "내 직관 후기"
}

null -> {}
}
}
Expand Down Expand Up @@ -276,7 +280,11 @@ class ReviewActivity : BaseActivity<ActivityReviewBinding>({
}
observeReviewViewModel()
}
is UiState.Failure -> { toast("오류가 발생했습니다") }

is UiState.Failure -> {
toast("오류가 발생했습니다")
}

is UiState.Loading -> {}
is UiState.Empty -> {}
else -> {}
Expand Down Expand Up @@ -328,6 +336,7 @@ class ReviewActivity : BaseActivity<ActivityReviewBinding>({
viewModel.setSelectedImages(selectedImageUris)
}
}

private fun updateSelectedImages() {
with(binding) {
layoutAddDefaultImage.isVisible = selectedImageUris.isEmpty()
Expand Down Expand Up @@ -355,6 +364,7 @@ class ReviewActivity : BaseActivity<ActivityReviewBinding>({
tvImageCount.text = selectedImageUris.size.toString()
}
}

private fun updateNextButtonState() {
val isSelectedDateFilled = viewModel.selectedDate.value.isNotEmpty()
val isSelectedImageFilled = viewModel.selectedImages.value.isNotEmpty()
Expand All @@ -366,9 +376,9 @@ class ReviewActivity : BaseActivity<ActivityReviewBinding>({

with(binding.tvUploadBtn) {
val isReadyToUpload = isSelectedDateFilled && isSelectedImageFilled &&
(isSelectedGoodBtnFilled || isSelectedBadBtnFilled) &&
isSelectedBlockFilled &&
(isSelectedColumnFilled || isSelectedNumberFilled)
(isSelectedGoodBtnFilled || isSelectedBadBtnFilled) &&
isSelectedBlockFilled &&
(isSelectedColumnFilled || isSelectedNumberFilled)

if (isReadyToUpload) {
setBackgroundResource(R.drawable.rect_action_enabled_fill_8)
Expand Down Expand Up @@ -409,13 +419,16 @@ class ReviewActivity : BaseActivity<ActivityReviewBinding>({
binding.tvUploadBtn.setBackgroundResource(R.drawable.rect_action_disabled_fill_8)
makeSpotImageAppbar("내 시야 후기를 등록해주세요")
}

!(isSelectedBlockFilled && (isSelectedColumnFilled || isSelectedNumberFilled)) && (isSelectedGoodBtnFilled || isSelectedBadBtnFilled) -> {
binding.tvUploadBtn.setBackgroundResource(R.drawable.rect_action_disabled_fill_8)
makeSpotImageAppbar("좌석을 선택해주세요")
}

((!isSelectedGoodBtnFilled && !isSelectedBadBtnFilled) || !(isSelectedBlockFilled && (isSelectedColumnFilled || isSelectedNumberFilled))) -> {
binding.tvUploadBtn.setBackgroundResource(R.drawable.rect_action_disabled_fill_8)
}

else -> {
val uniqueImageUris = selectedImageUris.distinct()
uniqueImageUris.forEach { imageUriString ->
Expand Down Expand Up @@ -465,9 +478,11 @@ class ReviewActivity : BaseActivity<ActivityReviewBinding>({
ReviewMethod.VIEW -> {
viewModel.postSeatReview(ReviewMethod.VIEW)
}

ReviewMethod.FEED -> {
viewModel.postSeatReview(ReviewMethod.FEED)
}

null -> {}
}
}
Expand Down Expand Up @@ -498,12 +513,15 @@ class ReviewActivity : BaseActivity<ActivityReviewBinding>({
)
dialogType?.let {
Intent(this, HomeActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
putExtra(DIALOG_TYPE, dialogType)
putExtra(REVIEW_DATA, reviewData)
finish()
startActivity(this)
}
}
}

is UiState.Failure -> {
toast("리뷰 등록 실패: $state")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import coil.transform.RoundedCornersTransformation
import com.depromeet.presentation.R
import com.depromeet.presentation.databinding.ActivitySelectViewImageBinding
import com.dpm.core.base.BaseActivity
import com.dpm.core.state.UiState
import com.dpm.domain.model.seatreview.ReviewMethod
import com.dpm.presentation.extension.setOnSingleClickListener
import com.dpm.presentation.home.HomeActivity
import com.dpm.presentation.seatreview.adapter.SelectKeywordAdapter
import com.dpm.presentation.seatreview.dialog.feed.FeedUploadDialog
import com.dpm.presentation.seatreview.viewmodel.ReviewViewModel
import dagger.hilt.android.AndroidEntryPoint

Expand All @@ -40,7 +40,7 @@ class SelectViewImageActivity : BaseActivity<ActivitySelectViewImageBinding>({
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
initView()
observeSelectedImageUris()
initObserve()
}

private fun initView() {
Expand All @@ -56,6 +56,32 @@ class SelectViewImageActivity : BaseActivity<ActivitySelectViewImageBinding>({
initEvent()
}

private fun initObserve() {
observeSelectedImageUris()
viewModel.postReviewState.asLiveData().observe(this) { uiState ->
when (uiState) {
is UiState.Success -> {
var reviewData = intent.getParcelableExtra<ReviewData>(REVIEW_DATA)
reviewData = reviewData?.copy(
reviewId = uiState.data.id
)

Intent(this, HomeActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
putExtra(UPLOAD_SNACKBAR, true)
putExtra(REVIEW_DATA,reviewData)
}.let {
finish()
startActivity(it)
}
}
is UiState.Empty -> Unit
is UiState.Failure -> Unit
is UiState.Loading -> Unit
}
}
}

private fun updateImageViews(urls: List<String>) {
val selectImages = listOf(
binding.clFirstImage to binding.ivFirstImage,
Expand Down Expand Up @@ -158,11 +184,6 @@ class SelectViewImageActivity : BaseActivity<ActivitySelectViewImageBinding>({
}

viewModel.postSeatReview(ReviewMethod.VIEW)
startActivity(
Intent(this, HomeActivity::class.java)
.putExtra(UPLOAD_SNACKBAR, true)
.putExtra(REVIEW_DATA,reviewData)
); finish()
}
binding.ivExit.setOnSingleClickListener {
startActivity(Intent(this, HomeActivity::class.java))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import com.depromeet.presentation.R
import com.depromeet.presentation.databinding.FragmentViewUploadDialogBinding
import com.dpm.core.base.BindingDialogFragment
import com.dpm.presentation.extension.setOnSingleClickListener
import com.dpm.presentation.home.HomeActivity
import com.dpm.presentation.scheme.SchemeKey
import com.dpm.presentation.scheme.viewmodel.SchemeState
import com.dpm.presentation.viewfinder.StadiumDetailActivity
import toNavReviewDetail

class ViewUploadDialog : BindingDialogFragment<FragmentViewUploadDialogBinding>(
R.layout.fragment_view_upload_dialog,
Expand All @@ -35,8 +39,13 @@ class ViewUploadDialog : BindingDialogFragment<FragmentViewUploadDialogBinding>(
dismiss()
}
binding.btnConfirmReview.setOnSingleClickListener {
// TODO : 방금 작성한 시야 후기 상세 페이지 게시물 화면으로 이동
startActivity(Intent(requireContext(), StadiumDetailActivity::class.java))
if (reviewData != null) {
val navReviewDetail = reviewData.toNavReviewDetail()
Intent(requireContext(), HomeActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
putExtra(SchemeKey.NAV_REVIEW_DETAIL, navReviewDetail)
}.let { startActivity(it) }
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import android.os.Parcelable
import com.dpm.presentation.scheme.viewmodel.SchemeState
import kotlinx.parcelize.Parcelize

@Parcelize
Expand All @@ -15,3 +16,9 @@ data class ReviewData(
val detailReviewText: String,
val selectedDate: String,
) : Parcelable

fun ReviewData.toNavReviewDetail() = SchemeState.NavReviewDetail(
stadiumId = stadiumId,
blockCode = blockCode,
reviewId = reviewId
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.runtime.withFrameNanos
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
Expand All @@ -36,6 +38,8 @@ import com.dpm.presentation.util.toTitle
import com.dpm.presentation.viewfinder.StadiumDetailActivity
import com.dpm.presentation.viewfinder.uistate.StadiumDetailUiState
import com.dpm.presentation.viewfinder.viewmodel.StadiumDetailViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import timber.log.Timber

@OptIn(ExperimentalFoundationApi::class)
Expand Down Expand Up @@ -63,10 +67,27 @@ fun StadiumDetailScreen(
val detailUiState by viewModel.detailUiState.collectAsStateWithLifecycle()
val currentIndex by viewModel.currentIndex.collectAsStateWithLifecycle()


LaunchedEffect(key1 = scrollState) {
verticalScrollState.scrollToItem(0)
viewModel.updateScrollState(false)
if (viewModel.reviewId == 0){
verticalScrollState.scrollToItem(0)
viewModel.updateScrollState(false)
}
}

LaunchedEffect(key1 = detailUiState) {
if (viewModel.reviewId != 0) {
when (val data = detailUiState) {
is StadiumDetailUiState.ReviewsData -> {
val index = data.reviews.indexOfFirst { it.id.toInt() == viewModel.reviewId }
if (index != -1){
verticalScrollState.scrollToItem(index + 1)
viewModel.reviewId = 0
}
}

else -> Unit
}
}
}

LaunchedEffect(key1 = verticalScrollState.firstVisibleItemScrollOffset) {
Expand Down

0 comments on commit 81541da

Please sign in to comment.