From 20fff727661344f24a88c340bde004f1dd6e6a2f Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Sun, 27 Oct 2024 20:48:07 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT/#153]=20=ED=94=84=EB=A1=AC=ED=94=84?= =?UTF-8?q?=ED=8A=B8=EB=B7=B0=20=EC=98=88=EC=8B=9C=20=EB=B7=B0=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A0=80=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/onboarding/OnboardingActivity.kt | 2 +- .../presentation/create/DefineAdapter.kt | 5 ++- .../presentation/create/DefineFragment.kt | 44 +++++++++++++------ .../presentation/create/DefineViewHolder.kt | 3 +- ...or_grey5.xml => ic_indicator_white_30.xml} | 2 +- .../main/res/layout/activity_onboarding.xml | 2 +- .../src/main/res/layout/fragment_define.xml | 35 +++++---------- .../main/res/layout/item_define_example.xml | 8 ++-- 8 files changed, 56 insertions(+), 45 deletions(-) rename presentation/src/main/res/drawable/{ic_indicator_grey5.xml => ic_indicator_white_30.xml} (89%) diff --git a/presentation/src/main/java/kr/genti/presentation/auth/onboarding/OnboardingActivity.kt b/presentation/src/main/java/kr/genti/presentation/auth/onboarding/OnboardingActivity.kt index f1cebf9b..ed8a2e9f 100644 --- a/presentation/src/main/java/kr/genti/presentation/auth/onboarding/OnboardingActivity.kt +++ b/presentation/src/main/java/kr/genti/presentation/auth/onboarding/OnboardingActivity.kt @@ -20,7 +20,7 @@ import kr.genti.presentation.util.AmplitudeManager.PROPERTY_PAGE @AndroidEntryPoint class OnboardingActivity : BaseActivity(R.layout.activity_onboarding) { private var _onboardingAdapter: OnboardingAdapter? = null - val onboardingAdapter + private val onboardingAdapter get() = requireNotNull(_onboardingAdapter) { getString(R.string.adapter_not_initialized_error_msg) } override fun onCreate(savedInstanceState: Bundle?) { diff --git a/presentation/src/main/java/kr/genti/presentation/create/DefineAdapter.kt b/presentation/src/main/java/kr/genti/presentation/create/DefineAdapter.kt index a8985655..416171e8 100644 --- a/presentation/src/main/java/kr/genti/presentation/create/DefineAdapter.kt +++ b/presentation/src/main/java/kr/genti/presentation/create/DefineAdapter.kt @@ -25,11 +25,14 @@ class DefineAdapter : ListAdapter(diffUtil) { holder.onBind(item) } + override fun getItemCount(): Int = TOTAL_VIEW_COUNT + companion object { + const val TOTAL_VIEW_COUNT = 5 private val diffUtil = ItemDiffCallback( - onItemsTheSame = { old, new -> old.length == new.length }, + onItemsTheSame = { old, new -> old == new }, onContentsTheSame = { old, new -> old == new }, ) } diff --git a/presentation/src/main/java/kr/genti/presentation/create/DefineFragment.kt b/presentation/src/main/java/kr/genti/presentation/create/DefineFragment.kt index 77445f77..71b6fe68 100644 --- a/presentation/src/main/java/kr/genti/presentation/create/DefineFragment.kt +++ b/presentation/src/main/java/kr/genti/presentation/create/DefineFragment.kt @@ -4,10 +4,12 @@ import android.os.Bundle import android.view.View import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController +import androidx.viewpager2.widget.ViewPager2 import dagger.hilt.android.AndroidEntryPoint import kr.genti.core.base.BaseFragment import kr.genti.core.extension.setOnSingleClickListener import kr.genti.presentation.R +import kr.genti.presentation.create.CreateViewModel.Companion.promptList import kr.genti.presentation.databinding.FragmentDefineBinding import kr.genti.presentation.util.AmplitudeManager import kr.genti.presentation.util.AmplitudeManager.EVENT_CLICK_BTN @@ -18,6 +20,10 @@ import kr.genti.presentation.util.AmplitudeManager.PROPERTY_PAGE class DefineFragment() : BaseFragment(R.layout.fragment_define) { private val viewModel by activityViewModels() + private var _adapter: DefineAdapter? = null + private val adapter + get() = requireNotNull(_adapter) { getString(R.string.adapter_not_initialized_error_msg) } + override fun onViewCreated( view: View, savedInstanceState: Bundle?, @@ -26,12 +32,12 @@ class DefineFragment() : BaseFragment(R.layout.fragment_d initView() initCreateBtnListener() - initRefreshExBtnListener() + initViewPager() + setPromptExample() } private fun initView() { binding.vm = viewModel - binding.tvCreateRandomExample.text = viewModel.getRandomPrompt() } private fun initCreateBtnListener() { @@ -46,18 +52,30 @@ class DefineFragment() : BaseFragment(R.layout.fragment_d } } - private fun initRefreshExBtnListener() { - binding.btnRefresh.setOnClickListener { - AmplitudeManager.apply { - trackEvent( - EVENT_CLICK_BTN, - mapOf(PROPERTY_PAGE to "create1"), - mapOf(PROPERTY_BTN to "promptsuggest_refresh"), - ) - plusIntProperties("user_promptsuggest_refresh") - } - binding.tvCreateRandomExample.text = viewModel.getRandomPrompt() + private fun initViewPager() { + _adapter = DefineAdapter() + with(binding) { + vpCreateRandom.adapter = adapter + vpCreateRandom.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() { + override fun onPageSelected(position: Int) { + super.onPageSelected(position) + AmplitudeManager.apply { + trackEvent( + EVENT_CLICK_BTN, + mapOf(PROPERTY_PAGE to "create1"), + mapOf(PROPERTY_BTN to "promptsuggest_refresh"), + ) + plusIntProperties("user_promptsuggest_refresh") + } + } + }) + dotIndicator.setViewPager(binding.vpCreateRandom) } } + private fun setPromptExample() { + adapter.submitList(promptList.subList(0, 5)) + adapter.notifyDataSetChanged() + } + } diff --git a/presentation/src/main/java/kr/genti/presentation/create/DefineViewHolder.kt b/presentation/src/main/java/kr/genti/presentation/create/DefineViewHolder.kt index 767ffc81..3e46bd81 100644 --- a/presentation/src/main/java/kr/genti/presentation/create/DefineViewHolder.kt +++ b/presentation/src/main/java/kr/genti/presentation/create/DefineViewHolder.kt @@ -1,6 +1,7 @@ package kr.genti.presentation.create import androidx.recyclerview.widget.RecyclerView +import kr.genti.core.extension.breakLines import kr.genti.presentation.databinding.ItemDefineExampleBinding class DefineViewHolder( @@ -8,7 +9,7 @@ class DefineViewHolder( ) : RecyclerView.ViewHolder(binding.root) { fun onBind(item: String) { with(binding) { - tvDefineExample.text = item + tvDefineExample.text = item.breakLines() } } } diff --git a/presentation/src/main/res/drawable/ic_indicator_grey5.xml b/presentation/src/main/res/drawable/ic_indicator_white_30.xml similarity index 89% rename from presentation/src/main/res/drawable/ic_indicator_grey5.xml rename to presentation/src/main/res/drawable/ic_indicator_white_30.xml index e9310364..67d16ad7 100644 --- a/presentation/src/main/res/drawable/ic_indicator_grey5.xml +++ b/presentation/src/main/res/drawable/ic_indicator_white_30.xml @@ -5,5 +5,5 @@ android:viewportHeight="10"> + android:fillColor="@color/white_30"/> diff --git a/presentation/src/main/res/layout/activity_onboarding.xml b/presentation/src/main/res/layout/activity_onboarding.xml index e61e9e7d..a07297c3 100644 --- a/presentation/src/main/res/layout/activity_onboarding.xml +++ b/presentation/src/main/res/layout/activity_onboarding.xml @@ -60,7 +60,7 @@ android:layout_height="16dp" android:layout_marginBottom="98dp" app:ci_drawable="@drawable/ic_indicator_green" - app:ci_drawable_unselected="@drawable/ic_indicator_grey5" + app:ci_drawable_unselected="@drawable/ic_indicator_white_30" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> diff --git a/presentation/src/main/res/layout/fragment_define.xml b/presentation/src/main/res/layout/fragment_define.xml index 22176e71..65126633 100644 --- a/presentation/src/main/res/layout/fragment_define.xml +++ b/presentation/src/main/res/layout/fragment_define.xml @@ -79,35 +79,24 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tv_create_script_subtitle_2" /> - + app:layout_constraintTop_toBottomOf="@id/tv_create_random_title" /> - + app:layout_constraintStart_toStartOf="parent" /> diff --git a/presentation/src/main/res/layout/item_define_example.xml b/presentation/src/main/res/layout/item_define_example.xml index 0d325560..c011f1a6 100644 --- a/presentation/src/main/res/layout/item_define_example.xml +++ b/presentation/src/main/res/layout/item_define_example.xml @@ -9,8 +9,7 @@ + android:layout_height="match_parent"> + android:layout_height="match_parent">