Skip to content

Commit

Permalink
[FEAT/#153] 프롬프트뷰 예시 뷰페이저 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchbreeze committed Oct 27, 2024
1 parent 45de31a commit 20fff72
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import kr.genti.presentation.util.AmplitudeManager.PROPERTY_PAGE
@AndroidEntryPoint
class OnboardingActivity : BaseActivity<ActivityOnboardingBinding>(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?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ class DefineAdapter : ListAdapter<String, DefineViewHolder>(diffUtil) {
holder.onBind(item)
}

override fun getItemCount(): Int = TOTAL_VIEW_COUNT

companion object {
const val TOTAL_VIEW_COUNT = 5

private val diffUtil =
ItemDiffCallback<String>(
onItemsTheSame = { old, new -> old.length == new.length },
onItemsTheSame = { old, new -> old == new },
onContentsTheSame = { old, new -> old == new },
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,6 +20,10 @@ import kr.genti.presentation.util.AmplitudeManager.PROPERTY_PAGE
class DefineFragment() : BaseFragment<FragmentDefineBinding>(R.layout.fragment_define) {
private val viewModel by activityViewModels<CreateViewModel>()

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?,
Expand All @@ -26,12 +32,12 @@ class DefineFragment() : BaseFragment<FragmentDefineBinding>(R.layout.fragment_d

initView()
initCreateBtnListener()
initRefreshExBtnListener()
initViewPager()
setPromptExample()
}

private fun initView() {
binding.vm = viewModel
binding.tvCreateRandomExample.text = viewModel.getRandomPrompt()
}

private fun initCreateBtnListener() {
Expand All @@ -46,18 +52,30 @@ class DefineFragment() : BaseFragment<FragmentDefineBinding>(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()
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package kr.genti.presentation.create

import androidx.recyclerview.widget.RecyclerView
import kr.genti.core.extension.breakLines
import kr.genti.presentation.databinding.ItemDefineExampleBinding

class DefineViewHolder(
val binding: ItemDefineExampleBinding,
) : RecyclerView.ViewHolder(binding.root) {
fun onBind(item: String) {
with(binding) {
tvDefineExample.text = item
tvDefineExample.text = item.breakLines()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
android:viewportHeight="10">
<path
android:pathData="M4.5,0.436L4.5,0.436A4.5,4.5 0,0 1,9 4.936L9,4.936A4.5,4.5 0,0 1,4.5 9.436L4.5,9.436A4.5,4.5 0,0 1,0 4.936L0,4.936A4.5,4.5 0,0 1,4.5 0.436z"
android:fillColor="@color/grey_5"/>
android:fillColor="@color/white_30"/>
</vector>
2 changes: 1 addition & 1 deletion presentation/src/main/res/layout/activity_onboarding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
35 changes: 12 additions & 23 deletions presentation/src/main/res/layout/fragment_define.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,35 +79,24 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_create_script_subtitle_2" />

<TextView
android:id="@+id/tv_create_random_example"
style="@style/TextAppearance.Genti.BodyDescription"
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/vp_create_random"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="14dp"
android:background="@color/gray_btn"
android:elevation="5dp"
android:minLines="2"
android:paddingHorizontal="8dp"
android:paddingVertical="13dp"
android:shadowColor="@color/black"
app:layout_constraintEnd_toStartOf="@id/btn_refresh"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_create_random_title"
tools:text="@string/create_tv_example_1" />
app:layout_constraintTop_toBottomOf="@id/tv_create_random_title" />

<ImageView
android:id="@+id/btn_refresh"
<me.relex.circleindicator.CircleIndicator3
android:id="@+id/dot_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="17dp"
android:background="@color/gray_btn"
android:padding="9dp"
android:src="@drawable/ic_refresh"
app:layout_constraintBottom_toBottomOf="@id/tv_create_random_example"
android:layout_height="16dp"
app:ci_drawable="@drawable/ic_indicator_green"
app:ci_drawable_unselected="@drawable/ic_indicator_white_30"
app:layout_constraintTop_toBottomOf="@id/vp_create_random"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_create_random_example" />
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down
8 changes: 4 additions & 4 deletions presentation/src/main/res/layout/item_define_example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black">
android:layout_height="match_parent">

<androidx.cardview.widget.CardView
android:layout_width="0dp"
Expand All @@ -20,15 +19,15 @@
android:shadowColor="@color/black"
app:cardCornerRadius="10dp"
app:cardElevation="6dp"
app:cardBackgroundColor="@color/gray"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/gray">
android:layout_height="match_parent">

<ImageView
android:id="@+id/iv_define_example"
Expand All @@ -45,6 +44,7 @@
android:id="@+id/tv_define_example"
style="@style/TextAppearance.Genti.Body_14_Medium"
android:layout_width="0dp"
android:minLines="3"
android:layout_height="wrap_content"
android:padding="16dp"
android:textSize="14dp"
Expand Down

0 comments on commit 20fff72

Please sign in to comment.