11package com.certified.notes.adapters
22
3- import android.content.Context
43import android.view.LayoutInflater
54import android.view.View
65import android.view.ViewGroup
6+ import android.widget.ImageView
77import android.widget.TextView
8- import androidx.preference.PreferenceManager
98import androidx.recyclerview.widget.DiffUtil
109import androidx.recyclerview.widget.ListAdapter
1110import androidx.recyclerview.widget.RecyclerView
1211import com.certified.notes.R
1312import com.certified.notes.model.BookMark
14- import com.certified.notes.room.NotesViewModel
15- import com.certified.notes.util.PreferenceKeys
1613import com.like.LikeButton
17- import com.like.OnLikeListener
1814
19- class BookMarkRecyclerAdapterKt (
20- private val context : Context ,
21- private val viewModel : NotesViewModel
15+ class BookMarkRecyclerAdapter (
16+ // private val context: Context,
17+ // private val viewModel: NotesViewModel
2218) :
23- ListAdapter <BookMark , BookMarkRecyclerAdapterKt .ViewHolder >(
19+ ListAdapter <BookMark , BookMarkRecyclerAdapter .ViewHolder >(
2420 DIFF_CALLBACK
2521 ) {
2622
27- private val listener: OnBookMarkClickedListener ?
23+ private lateinit var listener: OnBookMarkClickedListener
2824
29- init {
30- listener = null
25+ // init {
26+ // listener = null
27+ // }
28+
29+ fun setOnBookMarkClickedListener (listener : OnBookMarkClickedListener ) {
30+ this .listener = listener
3131 }
3232
3333 fun getBookMarkAt (position : Int ): BookMark {
@@ -42,15 +42,17 @@ class BookMarkRecyclerAdapterKt(
4242 val noteContent: TextView
4343 val noteTitle: TextView
4444 val likeButton: LikeButton
45+ val ivBookMark: ImageView
4546
4647 init {
4748 noteContent = itemView.findViewById(R .id.tv_note_content)
4849 noteTitle = itemView.findViewById(R .id.tv_note_title)
4950 likeButton = itemView.findViewById(R .id.likeButton)
51+ ivBookMark = itemView.findViewById(R .id.iv_bookmark)
5052
51- itemView.setOnClickListener{
53+ itemView.setOnClickListener {
5254 val position = adapterPosition
53- if (listener != null && position != RecyclerView .NO_POSITION ) {
55+ if (position != RecyclerView .NO_POSITION ) {
5456 listener.onBookMarkClick(getItem(position))
5557 }
5658 }
@@ -80,34 +82,35 @@ class BookMarkRecyclerAdapterKt(
8082 override fun onBindViewHolder (holder : ViewHolder , position : Int ) {
8183 val currentBookMark = getItem(position)
8284 holder.noteContent.text = currentBookMark.noteContent
83- holder.noteTitle.text = currentBookMark.noteContent
84- holder.likeButton.isLiked = true
85- holder.likeButton.setOnLikeListener(object : OnLikeListener {
86- override fun liked (likeButton : LikeButton ? ) {
87-
88- }
89-
90- override fun unLiked (likeButton : LikeButton ? ) {
91- val noteId = currentBookMark.noteId
92- val courseCode = currentBookMark.courseCode
93- val noteTitle = currentBookMark.noteTitle
94- val noteContent = currentBookMark.noteContent
95- val bookMark = BookMark (noteId, courseCode, noteTitle, noteContent)
96- bookMark.id = currentBookMark.id
97- viewModel.deleteBookMark(bookMark)
98-
99- val preferences = PreferenceManager .getDefaultSharedPreferences(context)
100- val editor = preferences.edit()
101-
102- val defValues = HashSet <String >()
103- defValues.add(" -1" )
104- val noteIds =
105- HashSet <String >(preferences.getStringSet(PreferenceKeys .NOTE_IDS , defValues))
106- noteIds.remove(noteId.toString())
107-
108- editor.putStringSet(PreferenceKeys .NOTE_IDS , noteIds)
109- editor.apply ()
110- }
111- })
85+ holder.noteTitle.text = currentBookMark.noteTitle
86+ holder.ivBookMark.visibility = View .VISIBLE
87+ // holder.likeButton.isLiked = true
88+ // holder.likeButton.setOnLikeListener(object : OnLikeListener {
89+ // override fun liked(likeButton: LikeButton?) {
90+ //
91+ // }
92+ //
93+ // override fun unLiked(likeButton: LikeButton?) {
94+ // val noteId = currentBookMark.noteId
95+ // val courseCode = currentBookMark.courseCode
96+ // val noteTitle = currentBookMark.noteTitle
97+ // val noteContent = currentBookMark.noteContent
98+ // val bookMark = BookMark(noteId, courseCode, noteTitle, noteContent)
99+ // bookMark.id = currentBookMark.id
100+ // viewModel.deleteBookMark(bookMark)
101+ //
102+ // val preferences = PreferenceManager.getDefaultSharedPreferences(context)
103+ // val editor = preferences.edit()
104+ //
105+ // val defValues = HashSet<String>()
106+ // defValues.add("-1")
107+ // val noteIds =
108+ // HashSet<String>(preferences.getStringSet(PreferenceKeys.NOTE_IDS, defValues))
109+ // noteIds.remove(noteId.toString())
110+ //
111+ // editor.putStringSet(PreferenceKeys.NOTE_IDS, noteIds)
112+ // editor.apply()
113+ // }
114+ // })
112115 }
113116}
0 commit comments