From 1a9cdd813d18a26a29880137dbf5c23b3cbcfe09 Mon Sep 17 00:00:00 2001 From: ii2001 Date: Thu, 25 Jul 2024 20:18:02 +0900 Subject: [PATCH 01/12] :sparkles: add navigate with bot_nav --- .../android/presentation/MainActivity.kt | 2 +- .../app/src/main/res/navigation/nav_graph.xml | 33 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/java/net/pengcook/android/presentation/MainActivity.kt b/android/app/src/main/java/net/pengcook/android/presentation/MainActivity.kt index 8ffa3bf9..180573c3 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/MainActivity.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/MainActivity.kt @@ -21,7 +21,7 @@ class MainActivity : AppCompatActivity() { navController.addOnDestinationChangedListener { _, destination, _ -> when (destination.id) { - R.id.homeFragment -> bottomNav.visibility = View.VISIBLE + R.id.homeFragment, R.id.searchFragment, R.id.profileFragment, R.id.categoryFragment -> bottomNav.visibility = View.VISIBLE else -> bottomNav.visibility = View.GONE } } diff --git a/android/app/src/main/res/navigation/nav_graph.xml b/android/app/src/main/res/navigation/nav_graph.xml index a19a918b..d20148ce 100644 --- a/android/app/src/main/res/navigation/nav_graph.xml +++ b/android/app/src/main/res/navigation/nav_graph.xml @@ -9,7 +9,20 @@ android:id="@+id/homeFragment" android:name="net.pengcook.android.presentation.home.HomeFragment" android:label="fragment_home" - tools:layout="@layout/fragment_home" /> + tools:layout="@layout/fragment_home" > + + + + + + tools:layout="@layout/fragment_category" > + + + + tools:layout="@layout/fragment_search" > + + + From 93f52cdeaf34ef90daf03f208af572b21756ed70 Mon Sep 17 00:00:00 2001 From: ii2001 Date: Fri, 26 Jul 2024 01:15:14 +0900 Subject: [PATCH 02/12] :fire: remove newInstance func --- .../android/presentation/step/RecipeStepFragment.kt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/android/app/src/main/java/net/pengcook/android/presentation/step/RecipeStepFragment.kt b/android/app/src/main/java/net/pengcook/android/presentation/step/RecipeStepFragment.kt index 013185a4..ce359213 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/step/RecipeStepFragment.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/step/RecipeStepFragment.kt @@ -70,14 +70,4 @@ class RecipeStepFragment : Fragment() { super.onDestroyView() _binding = null } - - companion object { - fun newInstance(recipeId: Long): RecipeStepFragment { - val fragment = RecipeStepFragment() - val args = Bundle() - args.putLong("recipeId", recipeId) - fragment.arguments = args - return fragment - } - } } From d805fc87000963aa94d9099a3fd8f9d289bac97c Mon Sep 17 00:00:00 2001 From: ii2001 Date: Fri, 26 Jul 2024 01:33:32 +0900 Subject: [PATCH 03/12] :sparkles: add safeargs with kotlin --- android/app/build.gradle.kts | 1 + android/build.gradle.kts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 8e58ecc1..e3fcb109 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -7,6 +7,7 @@ plugins { alias(libs.plugins.google.gms.google.services) id("kotlin-kapt") id("kotlin-parcelize") + id("androidx.navigation.safeargs.kotlin") } android { diff --git a/android/build.gradle.kts b/android/build.gradle.kts index 6b29c71c..6f22452c 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -8,3 +8,8 @@ plugins { allprojects { apply(plugin = "org.jlleitschuh.gradle.ktlint") } +buildscript{ + dependencies { + classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.7.7") + } +} From ba32731eb66de45ffe5ea3d3ef9be3d0bc63a6be Mon Sep 17 00:00:00 2001 From: ii2001 Date: Fri, 26 Jul 2024 01:33:52 +0900 Subject: [PATCH 04/12] :truck: divide FeedViewHolder --- .../home/FeedRecyclerViewAdapter.kt | 17 +++++------------ .../presentation/home/holder/FeedViewHolder.kt | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 android/app/src/main/java/net/pengcook/android/presentation/home/holder/FeedViewHolder.kt diff --git a/android/app/src/main/java/net/pengcook/android/presentation/home/FeedRecyclerViewAdapter.kt b/android/app/src/main/java/net/pengcook/android/presentation/home/FeedRecyclerViewAdapter.kt index cc49fa94..e14d991a 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/home/FeedRecyclerViewAdapter.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/home/FeedRecyclerViewAdapter.kt @@ -4,24 +4,24 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.paging.PagingDataAdapter import androidx.recyclerview.widget.DiffUtil -import androidx.recyclerview.widget.RecyclerView import net.pengcook.android.databinding.ItemFeedBinding import net.pengcook.android.presentation.core.model.Recipe +import net.pengcook.android.presentation.home.holder.FeedViewHolder import net.pengcook.android.presentation.home.listener.FeedItemEventListener class FeedRecyclerViewAdapter(private val eventListener: FeedItemEventListener) : - PagingDataAdapter(diffCallback) { + PagingDataAdapter(diffCallback) { override fun onCreateViewHolder( parent: ViewGroup, viewType: Int, - ): ViewHolder { + ): FeedViewHolder { val inflater = LayoutInflater.from(parent.context) val binding = ItemFeedBinding.inflate(inflater, parent, false) - return ViewHolder(binding) + return FeedViewHolder(binding, eventListener) } override fun onBindViewHolder( - holder: ViewHolder, + holder: FeedViewHolder, position: Int, ) { val item = getItem(position) @@ -30,13 +30,6 @@ class FeedRecyclerViewAdapter(private val eventListener: FeedItemEventListener) } } - class ViewHolder(private val binding: ItemFeedBinding) : RecyclerView.ViewHolder(binding.root) { - fun bind(item: Recipe) { - binding.recipe = item - binding.executePendingBindings() - } - } - companion object { val diffCallback = object : DiffUtil.ItemCallback() { diff --git a/android/app/src/main/java/net/pengcook/android/presentation/home/holder/FeedViewHolder.kt b/android/app/src/main/java/net/pengcook/android/presentation/home/holder/FeedViewHolder.kt new file mode 100644 index 00000000..8b288f1a --- /dev/null +++ b/android/app/src/main/java/net/pengcook/android/presentation/home/holder/FeedViewHolder.kt @@ -0,0 +1,17 @@ +package net.pengcook.android.presentation.home.holder + +import androidx.recyclerview.widget.RecyclerView +import net.pengcook.android.databinding.ItemFeedBinding +import net.pengcook.android.presentation.core.model.Recipe +import net.pengcook.android.presentation.home.listener.FeedItemEventListener + +class FeedViewHolder( + private val binding: ItemFeedBinding, + private val eventListener: FeedItemEventListener +) : RecyclerView.ViewHolder(binding.root) { + fun bind(item: Recipe) { + binding.recipe = item + binding.eventListener = eventListener + binding.executePendingBindings() + } +} From ed04bd8b929f2282a99b2f82fc11e3723b0cf0b9 Mon Sep 17 00:00:00 2001 From: ii2001 Date: Fri, 26 Jul 2024 01:36:11 +0900 Subject: [PATCH 05/12] :sparkles: add navigate in nav_graph --- .../app/src/main/res/navigation/nav_graph.xml | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/res/navigation/nav_graph.xml b/android/app/src/main/res/navigation/nav_graph.xml index d20148ce..c568f213 100644 --- a/android/app/src/main/res/navigation/nav_graph.xml +++ b/android/app/src/main/res/navigation/nav_graph.xml @@ -16,19 +16,26 @@ - + + tools:layout="@layout/fragment_detail_recipe" > + + + + + + + + + + From 78091223a44729890301f7c184c581c25d076460 Mon Sep 17 00:00:00 2001 From: ii2001 Date: Fri, 26 Jul 2024 01:36:41 +0900 Subject: [PATCH 06/12] :sparkles: impl navigate home to detail --- .../detail/DetailRecipeFragment.kt | 7 +- .../android/presentation/home/HomeFragment.kt | 15 +++++ .../presentation/home/HomeViewModel.kt | 16 ++++- .../app/src/main/res/layout/fragment_home.xml | 1 + android/app/src/main/res/layout/item_feed.xml | 66 ++++++++++--------- 5 files changed, 67 insertions(+), 38 deletions(-) diff --git a/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeFragment.kt b/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeFragment.kt index 8e7ec01f..33d6cfd9 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeFragment.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeFragment.kt @@ -5,10 +5,12 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment +import androidx.navigation.fragment.navArgs import net.pengcook.android.databinding.FragmentDetailRecipeBinding import net.pengcook.android.presentation.core.model.Recipe class DetailRecipeFragment : Fragment() { + private val args: DetailRecipeFragmentArgs by navArgs() private val binding by lazy { FragmentDetailRecipeBinding.inflate(layoutInflater) } private val viewModel by lazy { DetailRecipeViewModel(recipe) } private lateinit var recipe: Recipe @@ -28,10 +30,7 @@ class DetailRecipeFragment : Fragment() { } private fun fetchRecipe() { - val argument = arguments?.getParcelable(RECIPE_KEY) as Recipe? - if (argument is Recipe) { - recipe = argument - } + recipe = args.recipe binding.recipe = recipe } diff --git a/android/app/src/main/java/net/pengcook/android/presentation/home/HomeFragment.kt b/android/app/src/main/java/net/pengcook/android/presentation/home/HomeFragment.kt index e3c6682f..3fe040fb 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/home/HomeFragment.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/home/HomeFragment.kt @@ -7,6 +7,7 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope +import androidx.navigation.fragment.findNavController import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -15,6 +16,7 @@ import net.pengcook.android.data.remote.api.FeedService import net.pengcook.android.data.repository.feed.DefaultFeedRepository import net.pengcook.android.data.util.network.RetrofitClient import net.pengcook.android.databinding.FragmentHomeBinding +import net.pengcook.android.presentation.core.model.Recipe class HomeFragment : Fragment() { private val viewModel: HomeViewModel by viewModels { @@ -50,6 +52,14 @@ class HomeFragment : Fragment() { initBinding() observeFeedData() + viewModel.uiEvent.observe(viewLifecycleOwner) { event -> + val newEvent = event.getContentIfNotHandled() ?: return@observe + when (newEvent) { + is HomeEvent.NavigateToDetail -> { + onSingleMovieClicked(newEvent.recipe) + } + } + } } private fun observeFeedData() { @@ -62,6 +72,11 @@ class HomeFragment : Fragment() { } } + private fun onSingleMovieClicked(recipe: Recipe) { + val action = HomeFragmentDirections.actionHomeFragmentToDetailRecipeFragment(recipe) + findNavController().navigate(action) + } + private fun initBinding() { binding.lifecycleOwner = viewLifecycleOwner binding.viewModel = viewModel diff --git a/android/app/src/main/java/net/pengcook/android/presentation/home/HomeViewModel.kt b/android/app/src/main/java/net/pengcook/android/presentation/home/HomeViewModel.kt index a67f574a..26ce35ae 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/home/HomeViewModel.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/home/HomeViewModel.kt @@ -1,6 +1,7 @@ package net.pengcook.android.presentation.home import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import androidx.paging.Pager @@ -11,11 +12,16 @@ import androidx.paging.liveData import net.pengcook.android.data.datasource.FeedPagingSource import net.pengcook.android.data.repository.feed.FeedRepository import net.pengcook.android.presentation.core.model.Recipe +import net.pengcook.android.presentation.core.util.Event import net.pengcook.android.presentation.home.listener.FeedItemEventListener class HomeViewModel( private val feedRepository: FeedRepository, ) : ViewModel(), FeedItemEventListener { + private val _uiEvent: MutableLiveData> = MutableLiveData() + val uiEvent: LiveData> + get() = _uiEvent + val feedData: LiveData> = Pager( config = PagingConfig(pageSize = PAGE_SIZE, enablePlaceholders = false), @@ -24,11 +30,15 @@ class HomeViewModel( .liveData .cachedIn(viewModelScope) + override fun onNavigateToDetail(recipe: Recipe) { + _uiEvent.value = Event(HomeEvent.NavigateToDetail(recipe)) + } + companion object { private const val PAGE_SIZE = 10 } +} - override fun onNavigateToDetail(recipe: Recipe) { - // Navigate to detail page - } +sealed interface HomeEvent { + data class NavigateToDetail(val recipe: Recipe) : HomeEvent } diff --git a/android/app/src/main/res/layout/fragment_home.xml b/android/app/src/main/res/layout/fragment_home.xml index cff738a5..8976958f 100644 --- a/android/app/src/main/res/layout/fragment_home.xml +++ b/android/app/src/main/res/layout/fragment_home.xml @@ -73,6 +73,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/followingText" + app:layout_constraintVertical_bias="0.0" tools:listitem="@layout/item_feed" /> diff --git a/android/app/src/main/res/layout/item_feed.xml b/android/app/src/main/res/layout/item_feed.xml index 234ebf02..ba16ed1e 100644 --- a/android/app/src/main/res/layout/item_feed.xml +++ b/android/app/src/main/res/layout/item_feed.xml @@ -8,12 +8,17 @@ + + + android:layout_marginBottom="12dp" + android:onClick="@{() -> eventListener.onNavigateToDetail(recipe)}"> + app:layout_constraintTop_toTopOf="parent" /> + app:shapeAppearanceOverlay="@style/roundImageView" + tools:src="@drawable/ic_launcher_background" /> + app:layout_constraintStart_toEndOf="@id/profile_image" + app:layout_constraintTop_toTopOf="@id/profile_image" + tools:text="Username" /> + android:src="@drawable/ic_menu_dots" + app:layout_constraintBottom_toBottomOf="@id/profile_image" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="@id/profile_image" /> @@ -96,11 +100,11 @@ android:layout_width="24dp" android:layout_height="24dp" android:layout_marginTop="8dp" + android:layout_marginBottom="@dimen/item_feed_padding" android:src="@drawable/ic_heart" - app:layout_constraintStart_toStartOf="@id/recipe_title" - app:layout_constraintTop_toBottomOf="@id/recipe_title" app:layout_constraintBottom_toBottomOf="parent" - android:layout_marginBottom="@dimen/item_feed_padding"/> + app:layout_constraintStart_toStartOf="@id/recipe_title" + app:layout_constraintTop_toBottomOf="@id/recipe_title" /> + tools:text="1200" /> + tools:text="800" /> From 13a6c8ca48141cad3160a944ebb305e2ded5d96c Mon Sep 17 00:00:00 2001 From: ii2001 Date: Fri, 26 Jul 2024 02:42:11 +0900 Subject: [PATCH 07/12] :sparkles: impl navigate main making to step making --- .../presentation/making/RecipeMakingFragment.kt | 12 ++++++++++++ .../presentation/making/RecipeMakingViewModel.kt | 12 +++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingFragment.kt b/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingFragment.kt index bb908b4c..df72f32d 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingFragment.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingFragment.kt @@ -6,6 +6,7 @@ import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels +import androidx.navigation.fragment.findNavController import net.pengcook.android.databinding.FragmentRecipeMakingBinding class RecipeMakingFragment : Fragment() { @@ -29,6 +30,12 @@ class RecipeMakingFragment : Fragment() { ) { super.onViewCreated(view, savedInstanceState) initBinding() + viewModel.uiEvent.observe(viewLifecycleOwner) { event -> + val newEvent = event.getContentIfNotHandled() ?: return@observe + when (newEvent) { + is MakingEvent.NavigateToStep -> onNextClicked() + } + } } override fun onDestroyView() { @@ -36,6 +43,11 @@ class RecipeMakingFragment : Fragment() { _binding = null } + private fun onNextClicked() { + val action = RecipeMakingFragmentDirections.actionRecipeMakingFragmentToMakingStepFragment() + findNavController().navigate(action) + } + private fun initBinding() { binding.lifecycleOwner = this binding.vm = viewModel diff --git a/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingViewModel.kt b/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingViewModel.kt index 92bfe13c..980c25f5 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingViewModel.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingViewModel.kt @@ -1,10 +1,16 @@ package net.pengcook.android.presentation.making +import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import net.pengcook.android.presentation.core.util.Event import net.pengcook.android.presentation.making.listener.RecipeMakingEventListener class RecipeMakingViewModel : ViewModel(), RecipeMakingEventListener { + private val _uiEvent: MutableLiveData> = MutableLiveData() + val uiEvent: LiveData> + get() = _uiEvent + val titleContent = MutableLiveData() val categorySelectedValue = MutableLiveData() @@ -16,6 +22,10 @@ class RecipeMakingViewModel : ViewModel(), RecipeMakingEventListener { val introductionContent = MutableLiveData() override fun onNavigateToStep() { - // TODO: Implement navigation logic + _uiEvent.value = Event(MakingEvent.NavigateToStep) } } + +sealed interface MakingEvent { + data object NavigateToStep : MakingEvent +} From 134ee9d10bd762aa69cebac81594c233e7641e19 Mon Sep 17 00:00:00 2001 From: ii2001 Date: Fri, 26 Jul 2024 02:42:53 +0900 Subject: [PATCH 08/12] :truck: id change --- .../app/src/main/res/navigation/nav_graph.xml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/android/app/src/main/res/navigation/nav_graph.xml b/android/app/src/main/res/navigation/nav_graph.xml index c568f213..eace5e2d 100644 --- a/android/app/src/main/res/navigation/nav_graph.xml +++ b/android/app/src/main/res/navigation/nav_graph.xml @@ -9,7 +9,7 @@ android:id="@+id/homeFragment" android:name="net.pengcook.android.presentation.home.HomeFragment" android:label="fragment_home" - tools:layout="@layout/fragment_home" > + tools:layout="@layout/fragment_home"> @@ -28,7 +28,7 @@ android:id="@+id/detailRecipeFragment" android:name="net.pengcook.android.presentation.detail.DetailRecipeFragment" android:label="fragment_detail_recipe" - tools:layout="@layout/fragment_detail_recipe" > + tools:layout="@layout/fragment_detail_recipe"> @@ -68,7 +68,7 @@ android:id="@+id/categoryFragment" android:name="net.pengcook.android.presentation.category.CategoryFragment" android:label="fragment_category" - tools:layout="@layout/fragment_category" > + tools:layout="@layout/fragment_category"> @@ -84,7 +84,7 @@ android:id="@+id/searchFragment" android:name="net.pengcook.android.presentation.search.SearchFragment" android:label="fragment_search" - tools:layout="@layout/fragment_search" > + tools:layout="@layout/fragment_search"> @@ -98,18 +98,19 @@ + android:label="RecipeMakingFragment"> + android:id="@+id/action_recipeMakingFragment_to_makingStepFragment" + app:destination="@id/makingStepFragment" /> + android:label="StepMakingFragment"> + From 77083d8d887fce9bc050c9ca229c7145ef2d5864 Mon Sep 17 00:00:00 2001 From: ii2001 Date: Fri, 26 Jul 2024 02:44:15 +0900 Subject: [PATCH 09/12] :sparkles: impl navigate detail to cooking step --- .../detail/DetailRecipeFragment.kt | 25 ++++++++++++++----- .../detail/DetailRecipeViewModel.kt | 14 ++++++++--- .../res/layout/fragment_detail_recipe.xml | 8 +++++- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeFragment.kt b/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeFragment.kt index 33d6cfd9..1d40fd60 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeFragment.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeFragment.kt @@ -5,6 +5,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment +import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import net.pengcook.android.databinding.FragmentDetailRecipeBinding import net.pengcook.android.presentation.core.model.Recipe @@ -21,17 +22,29 @@ class DetailRecipeFragment : Fragment() { savedInstanceState: Bundle?, ): View = binding.root - override fun onViewCreated( - view: View, - savedInstanceState: Bundle?, - ) { + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) fetchRecipe() + observeNavigationEvent() + } + + private fun observeNavigationEvent() { + viewModel.navigateToStepEvent.observe(viewLifecycleOwner) { shouldNavigate -> + if (shouldNavigate) { + navigateToStep() + } + } } private fun fetchRecipe() { - recipe = args.recipe - binding.recipe = recipe + binding.recipe = args.recipe + binding.vm = viewModel + } + + + private fun navigateToStep() { + val action = DetailRecipeFragmentDirections.actionDetailRecipeFragmentToRecipeStepFragment() + findNavController().navigate(action) } companion object { diff --git a/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeViewModel.kt b/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeViewModel.kt index 25c632c2..b274de5b 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeViewModel.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeViewModel.kt @@ -1,8 +1,16 @@ package net.pengcook.android.presentation.detail +// DetailRecipeViewModel.kt +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import net.pengcook.android.presentation.core.model.Recipe -class DetailRecipeViewModel( - private val recipe: Recipe, -) : ViewModel() +class DetailRecipeViewModel(private val recipe: Recipe) : ViewModel() { + private val _navigateToStepEvent = MutableLiveData() + val navigateToStepEvent: LiveData get() = _navigateToStepEvent + + fun onNavigateToMakingStep() { + _navigateToStepEvent.value = true + } +} diff --git a/android/app/src/main/res/layout/fragment_detail_recipe.xml b/android/app/src/main/res/layout/fragment_detail_recipe.xml index 6b5f81b3..3513f7e4 100644 --- a/android/app/src/main/res/layout/fragment_detail_recipe.xml +++ b/android/app/src/main/res/layout/fragment_detail_recipe.xml @@ -8,6 +8,10 @@ + + Date: Fri, 26 Jul 2024 02:46:40 +0900 Subject: [PATCH 10/12] :truck: change name navigateToMakingStep --- .../android/presentation/making/RecipeMakingFragment.kt | 2 +- .../android/presentation/making/RecipeMakingViewModel.kt | 6 +++--- .../making/listener/RecipeMakingEventListener.kt | 2 +- android/app/src/main/res/layout/fragment_recipe_making.xml | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingFragment.kt b/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingFragment.kt index df72f32d..fbb223e8 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingFragment.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingFragment.kt @@ -33,7 +33,7 @@ class RecipeMakingFragment : Fragment() { viewModel.uiEvent.observe(viewLifecycleOwner) { event -> val newEvent = event.getContentIfNotHandled() ?: return@observe when (newEvent) { - is MakingEvent.NavigateToStep -> onNextClicked() + is MakingEvent.NavigateToMakingStep -> onNextClicked() } } } diff --git a/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingViewModel.kt b/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingViewModel.kt index 980c25f5..1bf1d1bf 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingViewModel.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/making/RecipeMakingViewModel.kt @@ -21,11 +21,11 @@ class RecipeMakingViewModel : ViewModel(), RecipeMakingEventListener { val introductionContent = MutableLiveData() - override fun onNavigateToStep() { - _uiEvent.value = Event(MakingEvent.NavigateToStep) + override fun onNavigateToMakingStep() { + _uiEvent.value = Event(MakingEvent.NavigateToMakingStep) } } sealed interface MakingEvent { - data object NavigateToStep : MakingEvent + data object NavigateToMakingStep : MakingEvent } diff --git a/android/app/src/main/java/net/pengcook/android/presentation/making/listener/RecipeMakingEventListener.kt b/android/app/src/main/java/net/pengcook/android/presentation/making/listener/RecipeMakingEventListener.kt index 3d00d454..dd905377 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/making/listener/RecipeMakingEventListener.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/making/listener/RecipeMakingEventListener.kt @@ -1,5 +1,5 @@ package net.pengcook.android.presentation.making.listener interface RecipeMakingEventListener { - fun onNavigateToStep() + fun onNavigateToMakingStep() } diff --git a/android/app/src/main/res/layout/fragment_recipe_making.xml b/android/app/src/main/res/layout/fragment_recipe_making.xml index d785d288..b230af10 100644 --- a/android/app/src/main/res/layout/fragment_recipe_making.xml +++ b/android/app/src/main/res/layout/fragment_recipe_making.xml @@ -147,6 +147,7 @@ android:backgroundTint="@color/gray_300" android:text="@string/making_next" android:textColor="@color/black_100" + android:onClick="@{() -> vm.onNavigateToMakingStep()}" android:textStyle="bold" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" From 9489e76633042b038acbbca002d03a07e904311d Mon Sep 17 00:00:00 2001 From: ii2001 Date: Fri, 26 Jul 2024 02:47:36 +0900 Subject: [PATCH 11/12] :recycle: divide function --- .../pengcook/android/presentation/home/HomeFragment.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/android/app/src/main/java/net/pengcook/android/presentation/home/HomeFragment.kt b/android/app/src/main/java/net/pengcook/android/presentation/home/HomeFragment.kt index 3fe040fb..058109fe 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/home/HomeFragment.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/home/HomeFragment.kt @@ -51,7 +51,15 @@ class HomeFragment : Fragment() { super.onViewCreated(view, savedInstanceState) initBinding() + observing() + } + + private fun observing() { observeFeedData() + observeUiEvent() + } + + private fun observeUiEvent() { viewModel.uiEvent.observe(viewLifecycleOwner) { event -> val newEvent = event.getContentIfNotHandled() ?: return@observe when (newEvent) { From cddfaad86b28e3d142461c3329731e5accd9448b Mon Sep 17 00:00:00 2001 From: ii2001 Date: Fri, 26 Jul 2024 02:48:24 +0900 Subject: [PATCH 12/12] :rotating_light: ktLint Formating --- .../android/presentation/detail/DetailRecipeFragment.kt | 6 ++++-- .../android/presentation/home/holder/FeedViewHolder.kt | 2 +- .../main/res/drawable/{ic_plus.xml => ic_add_recipe.xml} | 0 android/app/src/main/res/layout/item_feed.xml | 1 + android/app/src/main/res/menu/bottom_nav_menu.xml | 4 ++-- android/build.gradle.kts | 2 +- 6 files changed, 9 insertions(+), 6 deletions(-) rename android/app/src/main/res/drawable/{ic_plus.xml => ic_add_recipe.xml} (100%) diff --git a/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeFragment.kt b/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeFragment.kt index 1d40fd60..0f7660c0 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeFragment.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/detail/DetailRecipeFragment.kt @@ -22,7 +22,10 @@ class DetailRecipeFragment : Fragment() { savedInstanceState: Bundle?, ): View = binding.root - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + override fun onViewCreated( + view: View, + savedInstanceState: Bundle?, + ) { super.onViewCreated(view, savedInstanceState) fetchRecipe() observeNavigationEvent() @@ -41,7 +44,6 @@ class DetailRecipeFragment : Fragment() { binding.vm = viewModel } - private fun navigateToStep() { val action = DetailRecipeFragmentDirections.actionDetailRecipeFragmentToRecipeStepFragment() findNavController().navigate(action) diff --git a/android/app/src/main/java/net/pengcook/android/presentation/home/holder/FeedViewHolder.kt b/android/app/src/main/java/net/pengcook/android/presentation/home/holder/FeedViewHolder.kt index 8b288f1a..03aaa589 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/home/holder/FeedViewHolder.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/home/holder/FeedViewHolder.kt @@ -7,7 +7,7 @@ import net.pengcook.android.presentation.home.listener.FeedItemEventListener class FeedViewHolder( private val binding: ItemFeedBinding, - private val eventListener: FeedItemEventListener + private val eventListener: FeedItemEventListener, ) : RecyclerView.ViewHolder(binding.root) { fun bind(item: Recipe) { binding.recipe = item diff --git a/android/app/src/main/res/drawable/ic_plus.xml b/android/app/src/main/res/drawable/ic_add_recipe.xml similarity index 100% rename from android/app/src/main/res/drawable/ic_plus.xml rename to android/app/src/main/res/drawable/ic_add_recipe.xml diff --git a/android/app/src/main/res/layout/item_feed.xml b/android/app/src/main/res/layout/item_feed.xml index ba16ed1e..8fcab5fc 100644 --- a/android/app/src/main/res/layout/item_feed.xml +++ b/android/app/src/main/res/layout/item_feed.xml @@ -74,6 +74,7 @@ android:layout_height="wrap_content" android:layout_marginEnd="@dimen/item_feed_padding" android:background="@android:color/transparent" + android:contentDescription="TODO" android:padding="12dp" android:src="@drawable/ic_menu_dots" app:layout_constraintBottom_toBottomOf="@id/profile_image" diff --git a/android/app/src/main/res/menu/bottom_nav_menu.xml b/android/app/src/main/res/menu/bottom_nav_menu.xml index 745fe410..72ce5073 100644 --- a/android/app/src/main/res/menu/bottom_nav_menu.xml +++ b/android/app/src/main/res/menu/bottom_nav_menu.xml @@ -12,8 +12,8 @@ android:title="Search" />