-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/12 reccomend view #18
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package kr.co.nottodo | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
|
||
class RecommendActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.fragment_recommendation) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...src/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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(private val tools: List<Recommendationdata>) : | ||
RecyclerView.Adapter<RecommendationViewHolder>() { | ||
|
||
private val sampleItems = mutableListOf<Recommendationdata>() | ||
private val items: List<Recommendationdata> = 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 | ||
) { | ||
if (position == selectedPosition) { | ||
selectBackground(holder, sampleItems[position]) | ||
} else { | ||
normalBackground(holder, sampleItems[position]) | ||
} | ||
bind(holder, position) | ||
} | ||
|
||
override fun getItemCount(): Int = sampleItems.size | ||
|
||
fun submitList(list: List<Recommendationdata>) { | ||
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() | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...rc/main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요건 따로 파일하나 만들어서 관리하는건 어떨까요?! |
||
|
||
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<FragmentRecommendationBinding>( | ||
inflater,R.layout.fragment_recommendation, container,false | ||
) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아마 RecyclerView의 제약조건이 match 로 걸려서 꽉 차보이는 거 일 거같아요. width = match_parent, height = wrap_content로 변경해보면 어떨까요? |
||
// 여기서 프라그먼트 작업을 해주시면 좋습니다 | ||
val itemList: List<Recommendationdata> = listOf(Recommendationdata("ㅎㅇ", "ㅎㅇ"), Recommendationdata("ㅎㅇ", "ㅎㅇ") ) | ||
recommendationAdapter = RecommendationAdapter(itemList) | ||
|
||
binding.rvRecommendation.adapter = recommendationAdapter | ||
binding.rvRecommendation.apply { | ||
layoutManager = LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false) | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../main/java/kr/co/nottodo/presentation/toplevel/recommendation/RecommendationViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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( | ||
val binding: ItemRecommendBinding | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
|
||
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) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...c/main/java/kr/co/nottodo/presentation/toplevel/recommendation/data/Recommendationdata.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package kr.co.nottodo.presentation.toplevel.recommendation.data | ||
|
||
data class Recommendationdata( | ||
val image: String, // 서버에서 이미지 url이 내려오는 경우 String으로 받아야합니다. | ||
val name: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<data> | ||
|
||
</data> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".RecommendActivity"> | ||
|
||
<EditText | ||
android:id="@+id/et_recommend" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="94dp" | ||
android:layout_marginTop="37dp" | ||
android:layout_marginBottom="21dp" | ||
android:text="추천받기" | ||
android:textSize="22sp" | ||
app:layout_constraintBottom_toTopOf="@id/divider" | ||
app:layout_constraintStart_toEndOf="@id/btn_recommendation_back" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<View | ||
android:id="@+id/divider" | ||
android:layout_width="match_parent" | ||
android:layout_height="1dp" | ||
android:layout_marginTop="21dp" | ||
android:backgroundTint="@color/gray_1_626068" | ||
app:layout_constraintTop_toBottomOf="@id/et_recommend" /> | ||
|
||
<ImageButton | ||
android:id="@+id/btn_recommendation_back" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="20dp" | ||
android:layout_marginTop="38dp" | ||
android:src="@drawable/ic_btn_back" | ||
app:layout_constraintEnd_toStartOf="@id/et_recommend" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/rv_recommendation" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginHorizontal="10dp" | ||
android:layout_marginTop="20dp" | ||
app:layout_constraintTop_toBottomOf="@id/divider" | ||
app:spanCount="5" | ||
tools:listitem="@layout/item_recommend" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content"> | ||
|
||
<ImageView | ||
android:id="@+id/iv_recommend" | ||
android:layout_width="46dp" | ||
android:layout_height="46dp" | ||
android:layout_marginStart="12dp" | ||
android:layout_marginEnd="12dp" | ||
android:layout_marginTop="8dp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:src="@drawable/ic_sns_active" /> | ||
|
||
<TextView | ||
android:id="@+id/tv_recommend_title" | ||
style="@style/B12" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="6dp" | ||
android:layout_marginBottom="12dp" | ||
android:textColor="@color/gray_1_626068" | ||
android:text="민영 테스트" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="@id/iv_recommend" | ||
app:layout_constraintStart_toStartOf="@id/iv_recommend" | ||
app:layout_constraintTop_toBottomOf="@id/iv_recommend" | ||
tools:text="민영 테스트" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adapter를 생성할 때는 list는 안받습니다!
이렇게 구현이 된다면 순서를 생각해봤을 때
서버에서 리스트 데이터를 받는다.
받은 리스트 데이터를 활용해 어댑터를 만든다.
이 순서가 되는데 그게 아니라
어댑터를 만들어 놓는다.
서버에서 데이터가 들어오면 어댑터에 비어 있는 리스트에 담아둔다!
는 순서로 바꿔야 됩니다!