@@ -11,6 +11,8 @@ 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.beGone
15+ import com.simplemobiletools.commons.extensions.beVisible
1416import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
1517import com.simplemobiletools.commons.extensions.isBlackAndWhiteTheme
1618import com.simplemobiletools.commons.helpers.LOWER_ALPHA_INT
@@ -29,18 +31,25 @@ class OpenNoteAdapter(
2931 activity : BaseSimpleActivity , var items : List <Note >,
3032 recyclerView : MyRecyclerView , itemClick : (Any ) -> Unit
3133) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
34+ private companion object {
35+ const val NEW_NOTE_ID = - 1
36+ }
3237
3338 override fun getActionMenuId () = 0
3439
3540 override fun actionItemPressed (id : Int ) {}
3641
37- override fun getSelectableItemCount () = items.size
42+ override fun getSelectableItemCount () = itemCount
3843
3944 override fun getIsItemSelectable (position : Int ) = false
4045
41- override fun getItemSelectionKey (position : Int ) = items.getOrNull(position)?.id?.toInt()
46+ override fun getItemSelectionKey (position : Int ) = items.getOrNull(position)?.id?.toInt() ? : NEW_NOTE_ID
4247
43- override fun getItemKeyPosition (key : Int ) = items.indexOfFirst { it.id?.toInt() == key }
48+ override fun getItemKeyPosition (key : Int ) = if (key == NEW_NOTE_ID ) {
49+ items.size
50+ } else {
51+ items.indexOfFirst { it.id?.toInt() == key }
52+ }
4453
4554 override fun onActionModeCreated () {}
4655
@@ -51,44 +60,66 @@ class OpenNoteAdapter(
5160 override fun onCreateViewHolder (parent : ViewGroup , viewType : Int ) = createViewHolder(R .layout.open_note_item, parent)
5261
5362 override fun onBindViewHolder (holder : ViewHolder , position : Int ) {
54- val item = items[position]
55- holder.bindView(item, true , false ) { itemView, layoutPosition ->
56- setupView(itemView, item)
63+ if (position == items.size) {
64+ holder.bindView(NEW_NOTE_ID , true , false ) { itemView, layoutPosition ->
65+ setupNewNoteView(itemView)
66+ }
67+ } else {
68+ val item = items[position]
69+ holder.bindView(item, true , false ) { itemView, layoutPosition ->
70+ setupView(itemView, item)
71+ }
5772 }
5873 bindViewHolder(holder)
5974 }
6075
61- override fun getItemCount () = items.size
76+ override fun getItemCount () = items.size + 1
6277
6378 private fun setupView (view : View , note : Note ) {
6479 view.apply {
65- if (context.isBlackAndWhiteTheme()) {
66- open_note_item_holder.setBackgroundResource(R .drawable.black_dialog_background)
67- } else {
68- val cardBackgroundColor = if (backgroundColor == Color .BLACK ) {
69- Color .WHITE
70- } else {
71- Color .BLACK
72- }
73- val cardBackground = if (context.config.isUsingSystemTheme) {
74- R .drawable.dialog_you_background
75- } else {
76- R .drawable.dialog_bg
77- }
78- open_note_item_holder.background =
79- activity.resources.getColoredDrawableWithColor(cardBackground, cardBackgroundColor, LOWER_ALPHA_INT )
80- }
80+ setupCard()
8181 open_note_item_title.apply {
8282 text = note.title
8383 setTextColor(properPrimaryColor)
8484 }
85+ open_note_item_text.beVisible()
8586 open_note_item_text.apply {
8687 text = note.getFormattedValue(context)
8788 setTextColor(textColor)
8889 }
8990 }
9091 }
9192
93+ private fun setupNewNoteView (view : View ) {
94+ view.apply {
95+ setupCard()
96+ open_note_item_title.apply {
97+ setText(R .string.create_new_note)
98+ setTextColor(properPrimaryColor)
99+ }
100+ open_note_item_text.beGone()
101+ }
102+ }
103+
104+ private fun View.setupCard () {
105+ if (context.isBlackAndWhiteTheme()) {
106+ open_note_item_holder.setBackgroundResource(R .drawable.black_dialog_background)
107+ } else {
108+ val cardBackgroundColor = if (backgroundColor == Color .BLACK ) {
109+ Color .WHITE
110+ } else {
111+ Color .BLACK
112+ }
113+ val cardBackground = if (context.config.isUsingSystemTheme) {
114+ R .drawable.dialog_you_background
115+ } else {
116+ R .drawable.dialog_bg
117+ }
118+ open_note_item_holder.background =
119+ activity.resources.getColoredDrawableWithColor(cardBackground, cardBackgroundColor, LOWER_ALPHA_INT )
120+ }
121+ }
122+
92123 private fun Note.getFormattedValue (context : Context ): CharSequence? {
93124 return when (type) {
94125 NoteType .TYPE_TEXT -> getNoteStoredValue(context)
0 commit comments