Skip to content

Commit 5f2cc81

Browse files
committed
Add a separate layout for new note item
1 parent 1b94c48 commit 5f2cc81

File tree

3 files changed

+62
-10
lines changed

3 files changed

+62
-10
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/OpenNoteAdapter.kt

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import com.google.gson.Gson
1111
import com.google.gson.reflect.TypeToken
1212
import com.simplemobiletools.commons.activities.BaseSimpleActivity
1313
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
14-
import com.simplemobiletools.commons.extensions.*
14+
import com.simplemobiletools.commons.extensions.applyColorFilter
15+
import com.simplemobiletools.commons.extensions.beGoneIf
16+
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
17+
import com.simplemobiletools.commons.extensions.isBlackAndWhiteTheme
1518
import com.simplemobiletools.commons.helpers.LOWER_ALPHA_INT
1619
import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM
1720
import com.simplemobiletools.commons.views.MyRecyclerView
@@ -20,6 +23,9 @@ import com.simplemobiletools.notes.pro.extensions.config
2023
import com.simplemobiletools.notes.pro.models.ChecklistItem
2124
import com.simplemobiletools.notes.pro.models.Note
2225
import 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
2329
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_holder
2430
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_text
2531
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_title
@@ -30,6 +36,8 @@ class OpenNoteAdapter(
3036
) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
3137
private companion object {
3238
const val NEW_NOTE_ID = -1
39+
const val VIEW_TYPE_NOTE = 0
40+
const val VIEW_TYPE_NEW_NOTE = 1
3341
}
3442

3543
override fun getActionMenuId() = 0
@@ -54,7 +62,20 @@ class OpenNoteAdapter(
5462

5563
override fun prepareActionMode(menu: Menu) {}
5664

57-
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.open_note_item, parent)
65+
override fun getItemViewType(position: Int): Int = if (position == items.size) {
66+
VIEW_TYPE_NEW_NOTE
67+
} else {
68+
VIEW_TYPE_NOTE
69+
}
70+
71+
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)
78+
}
5879

5980
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
6081
if (position == items.size) {
@@ -74,7 +95,7 @@ class OpenNoteAdapter(
7495

7596
private fun setupView(view: View, note: Note) {
7697
view.apply {
77-
setupCard()
98+
setupCard(open_note_item_holder)
7899
open_note_item_title.apply {
79100
text = note.title
80101
setTextColor(properPrimaryColor)
@@ -90,18 +111,18 @@ class OpenNoteAdapter(
90111

91112
private fun setupNewNoteView(view: View) {
92113
view.apply {
93-
setupCard()
94-
open_note_item_title.apply {
114+
setupCard(open_new_note_item_holder)
115+
open_new_note_item_title.apply {
95116
setText(R.string.create_new_note)
96117
setTextColor(properPrimaryColor)
97118
}
98-
open_note_item_text.beGone()
119+
open_new_note_icon.applyColorFilter(properPrimaryColor)
99120
}
100121
}
101122

102-
private fun View.setupCard() {
123+
private fun View.setupCard(holder: View) {
103124
if (context.isBlackAndWhiteTheme()) {
104-
open_note_item_holder.setBackgroundResource(R.drawable.black_dialog_background)
125+
holder.setBackgroundResource(R.drawable.black_dialog_background)
105126
} else {
106127
val cardBackgroundColor = if (backgroundColor == Color.BLACK) {
107128
Color.WHITE
@@ -113,7 +134,7 @@ class OpenNoteAdapter(
113134
} else {
114135
R.drawable.dialog_bg
115136
}
116-
open_note_item_holder.background =
137+
holder.background =
117138
activity.resources.getColoredDrawableWithColor(cardBackground, cardBackgroundColor, LOWER_ALPHA_INT)
118139
}
119140
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/open_new_note_item_holder"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:layout_margin="@dimen/medium_margin"
7+
android:background="@drawable/widget_round_background"
8+
android:orientation="vertical"
9+
android:padding="@dimen/normal_margin">
10+
11+
<com.simplemobiletools.commons.views.MyTextView
12+
android:id="@+id/open_new_note_item_title"
13+
android:layout_width="wrap_content"
14+
android:layout_height="wrap_content"
15+
android:ellipsize="end"
16+
android:maxLines="2"
17+
android:textSize="@dimen/big_text_size"
18+
android:textStyle="bold"
19+
android:layout_gravity="center"
20+
android:textAlignment="center"
21+
android:text="@string/create_new_note" />
22+
23+
<ImageView
24+
android:id="@+id/open_new_note_icon"
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:src="@drawable/ic_plus_vector"
28+
android:layout_gravity="center"
29+
android:importantForAccessibility="no" />
30+
31+
</LinearLayout>

app/src/main/res/layout/open_note_item.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
android:layout_width="wrap_content"
1515
android:layout_height="wrap_content"
1616
android:ellipsize="end"
17-
android:maxLines="2"
17+
android:lines="1"
1818
android:textSize="@dimen/big_text_size"
1919
android:textStyle="bold"
2020
tools:text="Title" />

0 commit comments

Comments
 (0)