feat(gift): 선물함 화면을 연결한다
This commit is contained in:
@@ -115,6 +115,9 @@
|
|||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".main.MainActivity" />
|
<activity android:name=".main.MainActivity" />
|
||||||
<activity android:name=".v2.main.MainV2Activity" />
|
<activity android:name=".v2.main.MainV2Activity" />
|
||||||
|
<activity
|
||||||
|
android:name=".v2.gift.GiftInboxActivity"
|
||||||
|
android:exported="false" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".v2.gift.GiftSendRequestActivity"
|
android:name=".v2.gift.GiftSendRequestActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ import kr.co.vividnext.sodalive.home.HomeRepository
|
|||||||
import kr.co.vividnext.sodalive.home.HomeViewModel
|
import kr.co.vividnext.sodalive.home.HomeViewModel
|
||||||
import kr.co.vividnext.sodalive.home.pushnotification.PushNotificationListViewModel
|
import kr.co.vividnext.sodalive.home.pushnotification.PushNotificationListViewModel
|
||||||
import kr.co.vividnext.sodalive.v2.gift.GiftSendRequestViewModel
|
import kr.co.vividnext.sodalive.v2.gift.GiftSendRequestViewModel
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.GiftInboxViewModel
|
||||||
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.GiftRepository
|
import kr.co.vividnext.sodalive.v2.gift.data.GiftRepository
|
||||||
import kr.co.vividnext.sodalive.live.LiveApi
|
import kr.co.vividnext.sodalive.live.LiveApi
|
||||||
@@ -463,6 +464,7 @@ class AppDI(private val context: Context, isDebugMode: Boolean) {
|
|||||||
viewModel { HomeFollowingViewModel(get(), get()) }
|
viewModel { HomeFollowingViewModel(get(), get()) }
|
||||||
viewModel { HomeRecommendationViewModel(get()) }
|
viewModel { HomeRecommendationViewModel(get()) }
|
||||||
viewModel { GiftSendRequestViewModel(get()) }
|
viewModel { GiftSendRequestViewModel(get()) }
|
||||||
|
viewModel { GiftInboxViewModel(get()) }
|
||||||
viewModel { HomeOnAirLiveViewModel(get()) }
|
viewModel { HomeOnAirLiveViewModel(get()) }
|
||||||
viewModel { CreatorChannelHomeViewModel(get()) }
|
viewModel { CreatorChannelHomeViewModel(get()) }
|
||||||
viewModel { CreatorChannelLiveViewModel(get()) }
|
viewModel { CreatorChannelLiveViewModel(get()) }
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.gift
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import androidx.core.view.isVisible
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import kr.co.vividnext.sodalive.R
|
||||||
|
import kr.co.vividnext.sodalive.base.BaseActivity
|
||||||
|
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||||
|
import kr.co.vividnext.sodalive.databinding.ActivityGiftInboxBinding
|
||||||
|
import kr.co.vividnext.sodalive.settings.notification.MemberRole
|
||||||
|
import kr.co.vividnext.sodalive.v2.gift.ui.GiftInboxAdapter
|
||||||
|
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||||
|
|
||||||
|
class GiftInboxActivity : BaseActivity<ActivityGiftInboxBinding>(ActivityGiftInboxBinding::inflate) {
|
||||||
|
private val viewModel: GiftInboxViewModel by viewModel()
|
||||||
|
private val inboxAdapter = GiftInboxAdapter(
|
||||||
|
onCardClick = { viewModel.onCardClick(it) },
|
||||||
|
onInquiryClick = { viewModel.onInquiryClick() },
|
||||||
|
onRetryClick = { viewModel.retry() }
|
||||||
|
)
|
||||||
|
private val viewMode: GiftInboxViewMode by lazy {
|
||||||
|
GiftInboxViewMode.entries.firstOrNull { it.name == intent.getStringExtra(EXTRA_GIFT_INBOX_VIEW_MODE) }
|
||||||
|
?: GiftInboxViewMode.ALL
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setupView() {
|
||||||
|
binding.btnBack.setOnClickListener { finish() }
|
||||||
|
binding.retry.setOnClickListener { viewModel.retry() }
|
||||||
|
binding.refresh.setOnRefreshListener { viewModel.refresh() }
|
||||||
|
binding.refresh.setColorSchemeResources(R.color.soda_400)
|
||||||
|
val layoutManager = LinearLayoutManager(this)
|
||||||
|
binding.list.layoutManager = layoutManager
|
||||||
|
binding.list.adapter = inboxAdapter
|
||||||
|
binding.list.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||||
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||||
|
if (dy > 0 && layoutManager.findLastVisibleItemPosition() >= inboxAdapter.itemCount - 3) {
|
||||||
|
viewModel.loadNextPage()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
viewModel.state.observe(this, ::render)
|
||||||
|
viewModel.toastLiveData.observe(this) { event ->
|
||||||
|
if (event != null) {
|
||||||
|
viewModel.consumeToast()?.let { toast ->
|
||||||
|
showToast(toast.resId?.let(::getString) ?: toast.message.orEmpty())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
viewModel.inquiryLiveData.observe(this) { requested ->
|
||||||
|
if (requested) viewModel.consumeInquiryIntent()?.let(::startActivity)
|
||||||
|
}
|
||||||
|
viewModel.loadFirstPage()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun render(state: GiftInboxUiState) {
|
||||||
|
val content = state as? GiftInboxUiState.Content
|
||||||
|
binding.progress.isVisible = state == GiftInboxUiState.Loading
|
||||||
|
binding.error.isVisible = state is GiftInboxUiState.Error
|
||||||
|
binding.refresh.isRefreshing = content?.isRefreshing == true
|
||||||
|
binding.refresh.isEnabled = state != GiftInboxUiState.Loading
|
||||||
|
binding.list.isVisible = state is GiftInboxUiState.Content || state == GiftInboxUiState.Empty
|
||||||
|
if (state is GiftInboxUiState.Error) {
|
||||||
|
binding.errorMessage.text = state.message?.takeIf { it.isNotBlank() } ?: getString(R.string.common_error_unknown)
|
||||||
|
}
|
||||||
|
if (binding.list.isVisible) {
|
||||||
|
inboxAdapter.submitList(
|
||||||
|
GiftInboxPresenter.toUiModels(
|
||||||
|
items = content?.items.orEmpty(),
|
||||||
|
viewMode = viewMode,
|
||||||
|
isCreator = SharedPreferenceManager.role == MemberRole.CREATOR.name,
|
||||||
|
isAppending = content?.isAppending == true,
|
||||||
|
canRetry = content?.appendError == true || content?.refreshError == true
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
binding.list.post {
|
||||||
|
if (!binding.list.canScrollVertically(1)) viewModel.loadNextPage()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val EXTRA_GIFT_INBOX_VIEW_MODE = "EXTRA_GIFT_INBOX_VIEW_MODE"
|
||||||
|
|
||||||
|
fun newIntent(context: Context, viewMode: GiftInboxViewMode = GiftInboxViewMode.ALL): Intent =
|
||||||
|
Intent(context, GiftInboxActivity::class.java).putExtra(EXTRA_GIFT_INBOX_VIEW_MODE, viewMode.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/black"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingVertical="@dimen/spacing_4">
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/btn_back"
|
||||||
|
android:layout_width="@dimen/spacing_48"
|
||||||
|
android:layout_height="@dimen/spacing_48"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/a11y_back"
|
||||||
|
android:src="@drawable/ic_new_bar_back" />
|
||||||
|
<TextView
|
||||||
|
style="@style/Typography.Heading4"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:fontFamily="@font/medium"
|
||||||
|
android:text="@string/gift_inbox_title"
|
||||||
|
android:textColor="@color/white" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1">
|
||||||
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/refresh"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:paddingHorizontal="@dimen/spacing_14"
|
||||||
|
android:paddingTop="@dimen/spacing_14"
|
||||||
|
android:paddingBottom="@dimen/spacing_24" />
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progress"
|
||||||
|
android:layout_width="@dimen/spacing_48"
|
||||||
|
android:layout_height="@dimen/spacing_48"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:indeterminateTint="@color/soda_400" />
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/error"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="@dimen/spacing_24"
|
||||||
|
android:visibility="gone">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/error_message"
|
||||||
|
style="@style/Typography.Body3"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/common_error_unknown"
|
||||||
|
android:textColor="@color/gray_500" />
|
||||||
|
<Button
|
||||||
|
android:id="@+id/retry"
|
||||||
|
style="@style/Typography.Body5"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/spacing_14"
|
||||||
|
android:background="@drawable/bg_creator_channel_live_retry"
|
||||||
|
android:backgroundTint="@color/gray_800"
|
||||||
|
android:minHeight="@dimen/spacing_48"
|
||||||
|
android:paddingHorizontal="@dimen/spacing_20"
|
||||||
|
android:text="@string/gift_inbox_retry"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textColor="@color/white" />
|
||||||
|
</LinearLayout>
|
||||||
|
</FrameLayout>
|
||||||
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user