feat(gift): 선물함 상세 진입을 연결한다
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
package kr.co.vividnext.sodalive.v2.gift
|
package kr.co.vividnext.sodalive.v2.gift
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
@@ -15,6 +17,9 @@ import org.koin.androidx.viewmodel.ext.android.viewModel
|
|||||||
|
|
||||||
class GiftInboxActivity : BaseActivity<ActivityGiftInboxBinding>(ActivityGiftInboxBinding::inflate) {
|
class GiftInboxActivity : BaseActivity<ActivityGiftInboxBinding>(ActivityGiftInboxBinding::inflate) {
|
||||||
private val viewModel: GiftInboxViewModel by viewModel()
|
private val viewModel: GiftInboxViewModel by viewModel()
|
||||||
|
private val detailLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||||
|
if (shouldRefreshGiftInbox(result.resultCode)) viewModel.refresh()
|
||||||
|
}
|
||||||
private val inboxAdapter = GiftInboxAdapter(
|
private val inboxAdapter = GiftInboxAdapter(
|
||||||
onCardClick = { viewModel.onCardClick(it) },
|
onCardClick = { viewModel.onCardClick(it) },
|
||||||
onInquiryClick = { viewModel.onInquiryClick() },
|
onInquiryClick = { viewModel.onInquiryClick() },
|
||||||
@@ -41,6 +46,13 @@ class GiftInboxActivity : BaseActivity<ActivityGiftInboxBinding>(ActivityGiftInb
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
viewModel.state.observe(this, ::render)
|
viewModel.state.observe(this, ::render)
|
||||||
|
viewModel.detailNavigationLiveData.observe(this) { applicationNo ->
|
||||||
|
if (applicationNo != null) {
|
||||||
|
viewModel.consumeDetailNavigation()?.let {
|
||||||
|
detailLauncher.launch(GiftDetailActivity.newIntent(this, it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
viewModel.toastLiveData.observe(this) { event ->
|
viewModel.toastLiveData.observe(this) { event ->
|
||||||
if (event != null) {
|
if (event != null) {
|
||||||
viewModel.consumeToast()?.let { toast ->
|
viewModel.consumeToast()?.let { toast ->
|
||||||
@@ -88,3 +100,5 @@ class GiftInboxActivity : BaseActivity<ActivityGiftInboxBinding>(ActivityGiftInb
|
|||||||
Intent(context, GiftInboxActivity::class.java).putExtra(EXTRA_GIFT_INBOX_VIEW_MODE, viewMode.name)
|
Intent(context, GiftInboxActivity::class.java).putExtra(EXTRA_GIFT_INBOX_VIEW_MODE, viewMode.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun shouldRefreshGiftInbox(resultCode: Int): Boolean = resultCode == Activity.RESULT_OK
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ class GiftInboxViewModel(private val repository: GiftRepository) : BaseViewModel
|
|||||||
val toastLiveData: LiveData<ToastMessage?> = mutableToast
|
val toastLiveData: LiveData<ToastMessage?> = mutableToast
|
||||||
private val mutableInquiry = MutableLiveData(false)
|
private val mutableInquiry = MutableLiveData(false)
|
||||||
val inquiryLiveData: LiveData<Boolean> = mutableInquiry
|
val inquiryLiveData: LiveData<Boolean> = mutableInquiry
|
||||||
|
private val mutableDetailNavigation = MutableLiveData<String?>()
|
||||||
|
val detailNavigationLiveData: LiveData<String?> = mutableDetailNavigation
|
||||||
private val request = SerialDisposable()
|
private val request = SerialDisposable()
|
||||||
private var loading = false
|
private var loading = false
|
||||||
private var currentPage = 0
|
private var currentPage = 0
|
||||||
@@ -68,9 +70,11 @@ class GiftInboxViewModel(private val repository: GiftRepository) : BaseViewModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onCardClick(card: GiftInboxCardUiModel) {
|
fun onCardClick(card: GiftInboxCardUiModel) {
|
||||||
mutableToast.value = card.status
|
mutableDetailNavigation.value = card.applicationNo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun consumeDetailNavigation(): String? = mutableDetailNavigation.value.also { mutableDetailNavigation.value = null }
|
||||||
|
|
||||||
fun consumeToast(): ToastMessage? = mutableToast.value.also { mutableToast.value = null }
|
fun consumeToast(): ToastMessage? = mutableToast.value.also { mutableToast.value = null }
|
||||||
|
|
||||||
fun onInquiryClick() {
|
fun onInquiryClick() {
|
||||||
|
|||||||
@@ -8,15 +8,18 @@ import io.reactivex.rxjava3.core.Single
|
|||||||
import io.reactivex.rxjava3.plugins.RxJavaPlugins
|
import io.reactivex.rxjava3.plugins.RxJavaPlugins
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
import io.reactivex.rxjava3.subjects.SingleSubject
|
import io.reactivex.rxjava3.subjects.SingleSubject
|
||||||
import kr.co.vividnext.sodalive.R
|
|
||||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftApi
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftApi
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftCancelResponse
|
||||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftCreateRequest
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftCreateRequest
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftDetailResponse
|
||||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftFormOptionsResponse
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftFormOptionsResponse
|
||||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftInboxResponse
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftInboxResponse
|
||||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftInboxItemResponse
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftInboxItemResponse
|
||||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftRepository
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftRepository
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftTrackingRequest
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftTrackingResponse
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertFalse
|
import org.junit.Assert.assertFalse
|
||||||
@@ -175,13 +178,18 @@ class GiftInboxViewModelTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `카드와 배송지 배너는 같은 상태 토스트를 한 번 소비한다`() {
|
fun `카드와 배송지 배너는 상태 토스트 없이 같은 신청번호를 한 번 소비한다`() {
|
||||||
val card = GiftInboxPresenter.toCard(inboxItem(direction = "RECEIVED", status = "TRACKING_REGISTERED"))
|
val card = GiftInboxPresenter.toCard(inboxItem(direction = "RECEIVED", status = "TRACKING_REGISTERED"))
|
||||||
|
assertNull(viewModel.consumeDetailNavigation())
|
||||||
repeat(2) {
|
repeat(2) {
|
||||||
viewModel.onCardClick(card)
|
viewModel.onCardClick(card)
|
||||||
assertEquals(R.string.gift_inbox_address_required, viewModel.consumeToast()?.resId)
|
|
||||||
assertNull(viewModel.consumeToast())
|
assertNull(viewModel.consumeToast())
|
||||||
|
assertEquals(card.applicationNo, viewModel.detailNavigationLiveData.value)
|
||||||
|
assertEquals(card.applicationNo, viewModel.consumeDetailNavigation())
|
||||||
|
assertNull(viewModel.consumeDetailNavigation())
|
||||||
|
assertNull(viewModel.detailNavigationLiveData.value)
|
||||||
}
|
}
|
||||||
|
assertTrue(api.requests.isEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -219,4 +227,16 @@ internal class InboxFakeApi : GiftApi {
|
|||||||
|
|
||||||
override fun createGift(request: GiftCreateRequest, authHeader: String): Single<ApiResponse<Any>> =
|
override fun createGift(request: GiftCreateRequest, authHeader: String): Single<ApiResponse<Any>> =
|
||||||
Single.error(UnsupportedOperationException())
|
Single.error(UnsupportedOperationException())
|
||||||
|
|
||||||
|
override fun getGiftDetail(applicationNo: String, authHeader: String): Single<ApiResponse<GiftDetailResponse>> =
|
||||||
|
Single.error(UnsupportedOperationException())
|
||||||
|
|
||||||
|
override fun registerGiftTracking(
|
||||||
|
applicationNo: String,
|
||||||
|
request: GiftTrackingRequest,
|
||||||
|
authHeader: String
|
||||||
|
): Single<ApiResponse<GiftTrackingResponse>> = Single.error(UnsupportedOperationException())
|
||||||
|
|
||||||
|
override fun cancelGift(applicationNo: String, authHeader: String): Single<ApiResponse<GiftCancelResponse>> =
|
||||||
|
Single.error(UnsupportedOperationException())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user