@@ -11,7 +11,6 @@ import com.google.gson.Gson
1111import com.google.gson.reflect.TypeToken
1212import com.simplemobiletools.commons.activities.BaseSimpleActivity
1313import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
14- import com.simplemobiletools.commons.extensions.applyColorFilter
1514import com.simplemobiletools.commons.extensions.beGoneIf
1615import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
1716import com.simplemobiletools.commons.extensions.isBlackAndWhiteTheme
@@ -23,9 +22,6 @@ import com.simplemobiletools.notes.pro.extensions.config
2322import com.simplemobiletools.notes.pro.models.ChecklistItem
2423import com.simplemobiletools.notes.pro.models.Note
2524import com.simplemobiletools.notes.pro.models.NoteType
26- import kotlinx.android.synthetic.main.open_new_note_item.view.open_new_note_icon
27- import kotlinx.android.synthetic.main.open_new_note_item.view.open_new_note_item_holder
28- import kotlinx.android.synthetic.main.open_new_note_item.view.open_new_note_item_title
2925import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_holder
3026import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_text
3127import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_title
@@ -34,12 +30,6 @@ class OpenNoteAdapter(
3430 activity : BaseSimpleActivity , var items : List <Note >,
3531 recyclerView : MyRecyclerView , itemClick : (Any ) -> Unit
3632) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
37- private companion object {
38- const val NEW_NOTE_ID = - 1
39- const val VIEW_TYPE_NOTE = 0
40- const val VIEW_TYPE_NEW_NOTE = 1
41- }
42-
4333 override fun getActionMenuId () = 0
4434
4535 override fun actionItemPressed (id : Int ) {}
@@ -48,50 +38,29 @@ class OpenNoteAdapter(
4838
4939 override fun getIsItemSelectable (position : Int ) = false
5040
51- override fun getItemSelectionKey (position : Int ) = items.getOrNull(position)?.id?.toInt() ? : NEW_NOTE_ID
41+ override fun getItemSelectionKey (position : Int ) = items.getOrNull(position)?.id?.toInt()
5242
53- override fun getItemKeyPosition (key : Int ) = if (key == NEW_NOTE_ID ) {
54- items.size
55- } else {
56- items.indexOfFirst { it.id?.toInt() == key }
57- }
43+ override fun getItemKeyPosition (key : Int ) = items.indexOfFirst { it.id?.toInt() == key }
5844
5945 override fun onActionModeCreated () {}
6046
6147 override fun onActionModeDestroyed () {}
6248
6349 override fun prepareActionMode (menu : Menu ) {}
6450
65- override fun getItemViewType (position : Int ): Int = if (position == items.size) {
66- VIEW_TYPE_NEW_NOTE
67- } else {
68- VIEW_TYPE_NOTE
69- }
70-
7151 override fun onCreateViewHolder (parent : ViewGroup , viewType : Int ): ViewHolder {
72- val layout = if (viewType == VIEW_TYPE_NEW_NOTE ) {
73- R .layout.open_new_note_item
74- } else {
75- R .layout.open_note_item
76- }
77- return createViewHolder(layout, parent)
52+ return createViewHolder(R .layout.open_note_item, parent)
7853 }
7954
8055 override fun onBindViewHolder (holder : ViewHolder , position : Int ) {
81- if (position == items.size) {
82- holder.bindView(NEW_NOTE_ID , true , false ) { itemView, layoutPosition ->
83- setupNewNoteView(itemView)
84- }
85- } else {
86- val item = items[position]
87- holder.bindView(item, true , false ) { itemView, layoutPosition ->
88- setupView(itemView, item)
89- }
56+ val item = items[position]
57+ holder.bindView(item, true , false ) { itemView, layoutPosition ->
58+ setupView(itemView, item)
9059 }
9160 bindViewHolder(holder)
9261 }
9362
94- override fun getItemCount () = items.size + 1
63+ override fun getItemCount () = items.size
9564
9665 private fun setupView (view : View , note : Note ) {
9766 view.apply {
@@ -109,17 +78,6 @@ class OpenNoteAdapter(
10978 }
11079 }
11180
112- private fun setupNewNoteView (view : View ) {
113- view.apply {
114- setupCard(open_new_note_item_holder)
115- open_new_note_item_title.apply {
116- setText(R .string.create_new_note)
117- setTextColor(properPrimaryColor)
118- }
119- open_new_note_icon.applyColorFilter(properPrimaryColor)
120- }
121- }
122-
12381 private fun View.setupCard (holder : View ) {
12482 if (context.isBlackAndWhiteTheme()) {
12583 holder.setBackgroundResource(R .drawable.black_dialog_background)
0 commit comments