From 795833a3baa23c7a159ed8855ca01a74736d6d42 Mon Sep 17 00:00:00 2001 From: minyoung Date: Sun, 1 Jan 2023 17:28:32 +0900 Subject: [PATCH 1/4] [feat]#12 recommand view --- app/src/main/AndroidManifest.xml | 8 ++++++++ app/src/main/java/kr/co/nottodo/RecommandActivity.kt | 11 +++++++++++ app/src/main/res/layout/activity_recommand.xml | 9 +++++++++ 3 files changed, 28 insertions(+) create mode 100644 app/src/main/java/kr/co/nottodo/RecommandActivity.kt create mode 100644 app/src/main/res/layout/activity_recommand.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e4332b4f..14d0658c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,6 +16,13 @@ android:theme="@style/Theme.NotToDo" android:usesCleartextTraffic="true" tools:targetApi="31"> + + + + diff --git a/app/src/main/java/kr/co/nottodo/RecommandActivity.kt b/app/src/main/java/kr/co/nottodo/RecommandActivity.kt new file mode 100644 index 00000000..8602784b --- /dev/null +++ b/app/src/main/java/kr/co/nottodo/RecommandActivity.kt @@ -0,0 +1,11 @@ +package kr.co.nottodo + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle + +class RecommandActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_recommand) + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_recommand.xml b/app/src/main/res/layout/activity_recommand.xml new file mode 100644 index 00000000..4589fd9a --- /dev/null +++ b/app/src/main/res/layout/activity_recommand.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file From b6f49e23dcc3819e785d4018c856ad64e8b5e305 Mon Sep 17 00:00:00 2001 From: minyoung Date: Sun, 1 Jan 2023 23:10:50 +0900 Subject: [PATCH 2/4] [feat]#12 recommend view --- app/src/main/AndroidManifest.xml | 2 +- .../{RecommandActivity.kt => RecommendActivity.kt} | 4 ++-- .../{activity_recommand.xml => activity_recommend.xml} | 9 ++++++++- 3 files changed, 11 insertions(+), 4 deletions(-) rename app/src/main/java/kr/co/nottodo/{RecommandActivity.kt => RecommendActivity.kt} (67%) rename app/src/main/res/layout/{activity_recommand.xml => activity_recommend.xml} (63%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 14d0658c..511a3226 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,7 +17,7 @@ android:usesCleartextTraffic="true" tools:targetApi="31"> + tools:context=".RecommendActivity"> + + + \ No newline at end of file From c679706d83eb7a115d7dfa40a03b6ee4c95d1d24 Mon Sep 17 00:00:00 2001 From: minyoung Date: Tue, 3 Jan 2023 13:38:45 +0900 Subject: [PATCH 3/4] [feat]#12 fragment_recommendation --- app/build.gradle | 4 ++ .../java/kr/co/nottodo/RecommendActivity.kt | 2 +- .../co/nottodo/presentation/MainActivity.kt | 2 + .../recommendation/RecommendationAdapter.kt | 19 +++++++ .../recommendation/RecommendationFragment.kt | 39 +++++++++++++ .../RecommendationViewHolder.kt | 15 +++++ .../recommendation/data/Recommendationdata.kt | 6 ++ .../main/res/layout/activity_recommend.xml | 16 ------ .../res/layout/fragment_recommendation.xml | 57 +++++++++++++++++++ app/src/main/res/layout/item_recommend.xml | 39 +++++++++++++ app/src/main/res/values/strings.xml | 4 +- 11 files changed, 185 insertions(+), 18 deletions(-) create mode 100644 app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationAdapter.kt create mode 100644 app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationFragment.kt create mode 100644 app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationViewHolder.kt create mode 100644 app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/data/Recommendationdata.kt delete mode 100644 app/src/main/res/layout/activity_recommend.xml create mode 100644 app/src/main/res/layout/fragment_recommendation.xml create mode 100644 app/src/main/res/layout/item_recommend.xml diff --git a/app/build.gradle b/app/build.gradle index 78e82082..4273547c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,6 +25,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + + buildFeatures{ + viewBinding true + } compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 diff --git a/app/src/main/java/kr/co/nottodo/RecommendActivity.kt b/app/src/main/java/kr/co/nottodo/RecommendActivity.kt index f0f88f5e..027d910e 100644 --- a/app/src/main/java/kr/co/nottodo/RecommendActivity.kt +++ b/app/src/main/java/kr/co/nottodo/RecommendActivity.kt @@ -6,6 +6,6 @@ import android.os.Bundle class RecommendActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_recommend) + setContentView(R.layout.fragment_recommendation) } } \ No newline at end of file diff --git a/app/src/main/java/kr/co/nottodo/presentation/MainActivity.kt b/app/src/main/java/kr/co/nottodo/presentation/MainActivity.kt index 091b3e46..ae773dfe 100644 --- a/app/src/main/java/kr/co/nottodo/presentation/MainActivity.kt +++ b/app/src/main/java/kr/co/nottodo/presentation/MainActivity.kt @@ -5,6 +5,8 @@ import android.os.Bundle import kr.co.nottodo.R class MainActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) diff --git a/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationAdapter.kt b/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationAdapter.kt new file mode 100644 index 00000000..89fcf6b9 --- /dev/null +++ b/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationAdapter.kt @@ -0,0 +1,19 @@ +package kr.co.nottodo.presentation.toplevel.recommendation + +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView + +class RecommendationAdapter : RecyclerView.Adapter(){ + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecommendationViewHolder { + TODO("Not yet implemented") + } + + override fun onBindViewHolder(holder: RecommendationViewHolder, position: Int) { + TODO("Not yet implemented") + } + + override fun getItemCount(): Int { + TODO("Not yet implemented") + } + +} \ No newline at end of file diff --git a/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationFragment.kt b/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationFragment.kt new file mode 100644 index 00000000..b3631a77 --- /dev/null +++ b/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationFragment.kt @@ -0,0 +1,39 @@ +package kr.co.nottodo.presentation.toplevel.recommendation + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.databinding.DataBindingUtil +import androidx.recyclerview.widget.LinearLayoutManager +import kotlinx.coroutines.NonDisposableHandle.parent +import kr.co.nottodo.R +import kr.co.nottodo.databinding.FragmentRecommendationBinding + +class RecommendationFragment : Fragment() { + + private lateinit var binding: FragmentRecommendationBinding + + private lateinit var recommendationAdapter: RecommendationAdapter + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + binding = DataBindingUtil.inflate( + inflater,R.layout.fragment_recommendation, container,false + ) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + // 여기서 프라그먼트 작업을 해주시면 좋습니다 + recommendationAdapter = RecommendationAdapter() + + binding.rvRecommendation.apply { + layoutManager = LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationViewHolder.kt b/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationViewHolder.kt new file mode 100644 index 00000000..b5f1d087 --- /dev/null +++ b/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationViewHolder.kt @@ -0,0 +1,15 @@ +package kr.co.nottodo.presentation.toplevel.recommendation + +import androidx.recyclerview.widget.RecyclerView +import androidx.recyclerview.widget.RecyclerView.ViewHolder +import kr.co.nottodo.databinding.ItemRecommendBinding +import kr.co.nottodo.presentation.toplevel.recommendation.data.Recommendationdata + +class RecommendationViewHolder( + private val binding : ItemRecommendBinding +) : RecyclerView.ViewHolder(binding.root) { + fun onBind(data:Recommendationdata){ + binding.ivRecommend. + } + +} \ No newline at end of file diff --git a/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/data/Recommendationdata.kt b/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/data/Recommendationdata.kt new file mode 100644 index 00000000..fd36019f --- /dev/null +++ b/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/data/Recommendationdata.kt @@ -0,0 +1,6 @@ +package kr.co.nottodo.presentation.toplevel.recommendation.data + +data class Recommendationdata( + val image: String, // 서버에서 이미지 url이 내려오는 경우 String으로 받아야합니다. + val name: String, +) diff --git a/app/src/main/res/layout/activity_recommend.xml b/app/src/main/res/layout/activity_recommend.xml deleted file mode 100644 index 7df0f521..00000000 --- a/app/src/main/res/layout/activity_recommend.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_recommendation.xml b/app/src/main/res/layout/fragment_recommendation.xml new file mode 100644 index 00000000..dc438c41 --- /dev/null +++ b/app/src/main/res/layout/fragment_recommendation.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_recommend.xml b/app/src/main/res/layout/item_recommend.xml new file mode 100644 index 00000000..47a75256 --- /dev/null +++ b/app/src/main/res/layout/item_recommend.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 95a196d2..9487650a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,5 @@ NotToDo - \ No newline at end of file + + Hello blank fragment + From b4e781e92ca7af05627e9aae925458520c46cc6e Mon Sep 17 00:00:00 2001 From: minyoung Date: Wed, 4 Jan 2023 13:13:13 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[feat]#12=20fragment=20=EC=B6=94=EC=B2=9C?= =?UTF-8?q?=EB=B7=B0=20reyclerview=20=EC=A0=90=EA=B2=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recommendation/RecommendationAdapter.kt | 81 +++++++++++++++++-- .../recommendation/RecommendationFragment.kt | 10 ++- .../RecommendationViewHolder.kt | 13 +-- .../res/layout/fragment_recommendation.xml | 10 +-- 4 files changed, 95 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationAdapter.kt b/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationAdapter.kt index 89fcf6b9..7922cef1 100644 --- a/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationAdapter.kt +++ b/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationAdapter.kt @@ -1,19 +1,86 @@ package kr.co.nottodo.presentation.toplevel.recommendation +import android.annotation.SuppressLint +import android.graphics.Color +import android.view.LayoutInflater import android.view.ViewGroup +import androidx.databinding.DataBindingUtil import androidx.recyclerview.widget.RecyclerView +import kr.co.nottodo.R +import kr.co.nottodo.databinding.ItemRecommendBinding +import kr.co.nottodo.presentation.toplevel.recommendation.data.Recommendationdata -class RecommendationAdapter : RecyclerView.Adapter(){ - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecommendationViewHolder { - TODO("Not yet implemented") +class RecommendationAdapter(private val tools: List) : + RecyclerView.Adapter() { + + private val sampleItems = mutableListOf() + private val items: List = tools + private var selectedPosition = -1 + private var lastItemSelectedPosition = -1 + + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): + RecommendationViewHolder { + val layoutInflater = LayoutInflater.from(parent.context) + val binding: ItemRecommendBinding = + DataBindingUtil.inflate(layoutInflater, R.layout.item_recommend, parent, false) + return RecommendationViewHolder(binding) } - override fun onBindViewHolder(holder: RecommendationViewHolder, position: Int) { - TODO("Not yet implemented") + override fun onBindViewHolder( + holder: RecommendationViewHolder, position: Int + ) { + if (position == selectedPosition) { + selectBackground(holder, sampleItems[position]) + } else { + normalBackground(holder, sampleItems[position]) + } + bind(holder, position) } - override fun getItemCount(): Int { - TODO("Not yet implemented") + override fun getItemCount(): Int = sampleItems.size + + fun submitList(list: List) { + sampleItems.clear() + sampleItems.addAll(list) + notifyDataSetChanged() } + private fun bind( + holder: RecommendationViewHolder, + position: Int + ) { + if (!holder.itemView.hasOnClickListeners()) { + holder.itemView.setOnClickListener { + selectedPosition = position + lastItemSelectedPosition = if (lastItemSelectedPosition == -1) { + selectedPosition + } else { + notifyItemChanged(lastItemSelectedPosition) + selectedPosition + } + notifyItemChanged(selectedPosition) + } + } + } + + private fun normalBackground( + holder: RecommendationViewHolder, + data: Recommendationdata + ) { + holder.binding.apply { + this.root.setBackgroundColor(Color.parseColor("#334455")) + executePendingBindings() + } + } + + private fun selectBackground( + holder: RecommendationViewHolder, + data: Recommendationdata + ) { + holder.binding.apply { + this.root.setBackgroundColor(Color.parseColor("#112233")) + executePendingBindings() + } + } } \ No newline at end of file diff --git a/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationFragment.kt b/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationFragment.kt index b3631a77..a69112bd 100644 --- a/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationFragment.kt +++ b/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationFragment.kt @@ -7,14 +7,18 @@ import android.view.View import android.view.ViewGroup import androidx.databinding.DataBindingUtil import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import kotlinx.coroutines.NonDisposableHandle.parent import kr.co.nottodo.R import kr.co.nottodo.databinding.FragmentRecommendationBinding +import kr.co.nottodo.databinding.ItemRecommendBinding +import kr.co.nottodo.presentation.toplevel.recommendation.data.Recommendationdata + +class RecommendViewHolder(val binding: ItemRecommendBinding) : RecyclerView.ViewHolder(binding.root) class RecommendationFragment : Fragment() { private lateinit var binding: FragmentRecommendationBinding - private lateinit var recommendationAdapter: RecommendationAdapter override fun onCreateView( @@ -30,8 +34,10 @@ class RecommendationFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { // 여기서 프라그먼트 작업을 해주시면 좋습니다 - recommendationAdapter = RecommendationAdapter() + val itemList: List = listOf(Recommendationdata("ㅎㅇ", "ㅎㅇ"), Recommendationdata("ㅎㅇ", "ㅎㅇ") ) + recommendationAdapter = RecommendationAdapter(itemList) + binding.rvRecommendation.adapter = recommendationAdapter binding.rvRecommendation.apply { layoutManager = LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false) } diff --git a/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationViewHolder.kt b/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationViewHolder.kt index b5f1d087..7ef8b48c 100644 --- a/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationViewHolder.kt +++ b/app/src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationViewHolder.kt @@ -2,14 +2,17 @@ package kr.co.nottodo.presentation.toplevel.recommendation import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView.ViewHolder +import com.bumptech.glide.Glide import kr.co.nottodo.databinding.ItemRecommendBinding import kr.co.nottodo.presentation.toplevel.recommendation.data.Recommendationdata class RecommendationViewHolder( - private val binding : ItemRecommendBinding + val binding: ItemRecommendBinding ) : RecyclerView.ViewHolder(binding.root) { - fun onBind(data:Recommendationdata){ - binding.ivRecommend. - } -} \ No newline at end of file + fun onBind(data: Recommendationdata) { + Glide.with(binding.root.context) + .load("https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory&fname=https://k.kakaocdn.net/dn/EShJF/btquPLT192D/SRxSvXqcWjHRTju3kHcOQK/img.png") + .into(binding.ivRecommend) + } +} diff --git a/app/src/main/res/layout/fragment_recommendation.xml b/app/src/main/res/layout/fragment_recommendation.xml index dc438c41..b5c65fa6 100644 --- a/app/src/main/res/layout/fragment_recommendation.xml +++ b/app/src/main/res/layout/fragment_recommendation.xml @@ -13,7 +13,7 @@ tools:context=".RecommendActivity"> + app:layout_constraintTop_toBottomOf="@id/et_recommend" />