Add a separate layout for new note item

This commit is contained in:
Ensar Sarajčić 2023-07-27 15:53:09 +02:00
parent 1b94c4839f
commit 5f2cc8149b
3 changed files with 62 additions and 10 deletions

View File

@ -11,7 +11,10 @@ import com.google.gson.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.beGoneIf
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
import com.simplemobiletools.commons.extensions.isBlackAndWhiteTheme
import com.simplemobiletools.commons.helpers.LOWER_ALPHA_INT import com.simplemobiletools.commons.helpers.LOWER_ALPHA_INT
import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM
import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.commons.views.MyRecyclerView
@ -20,6 +23,9 @@ import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.models.ChecklistItem import com.simplemobiletools.notes.pro.models.ChecklistItem
import com.simplemobiletools.notes.pro.models.Note import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType import com.simplemobiletools.notes.pro.models.NoteType
import kotlinx.android.synthetic.main.open_new_note_item.view.open_new_note_icon
import kotlinx.android.synthetic.main.open_new_note_item.view.open_new_note_item_holder
import kotlinx.android.synthetic.main.open_new_note_item.view.open_new_note_item_title
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_holder import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_holder
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_text import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_text
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_title import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_title
@ -30,6 +36,8 @@ class OpenNoteAdapter(
) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) { ) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
private companion object { private companion object {
const val NEW_NOTE_ID = -1 const val NEW_NOTE_ID = -1
const val VIEW_TYPE_NOTE = 0
const val VIEW_TYPE_NEW_NOTE = 1
} }
override fun getActionMenuId() = 0 override fun getActionMenuId() = 0
@ -54,7 +62,20 @@ class OpenNoteAdapter(
override fun prepareActionMode(menu: Menu) {} override fun prepareActionMode(menu: Menu) {}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.open_note_item, parent) override fun getItemViewType(position: Int): Int = if (position == items.size) {
VIEW_TYPE_NEW_NOTE
} else {
VIEW_TYPE_NOTE
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layout = if (viewType == VIEW_TYPE_NEW_NOTE) {
R.layout.open_new_note_item
} else {
R.layout.open_note_item
}
return createViewHolder(layout, parent)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
if (position == items.size) { if (position == items.size) {
@ -74,7 +95,7 @@ class OpenNoteAdapter(
private fun setupView(view: View, note: Note) { private fun setupView(view: View, note: Note) {
view.apply { view.apply {
setupCard() setupCard(open_note_item_holder)
open_note_item_title.apply { open_note_item_title.apply {
text = note.title text = note.title
setTextColor(properPrimaryColor) setTextColor(properPrimaryColor)
@ -90,18 +111,18 @@ class OpenNoteAdapter(
private fun setupNewNoteView(view: View) { private fun setupNewNoteView(view: View) {
view.apply { view.apply {
setupCard() setupCard(open_new_note_item_holder)
open_note_item_title.apply { open_new_note_item_title.apply {
setText(R.string.create_new_note) setText(R.string.create_new_note)
setTextColor(properPrimaryColor) setTextColor(properPrimaryColor)
} }
open_note_item_text.beGone() open_new_note_icon.applyColorFilter(properPrimaryColor)
} }
} }
private fun View.setupCard() { private fun View.setupCard(holder: View) {
if (context.isBlackAndWhiteTheme()) { if (context.isBlackAndWhiteTheme()) {
open_note_item_holder.setBackgroundResource(R.drawable.black_dialog_background) holder.setBackgroundResource(R.drawable.black_dialog_background)
} else { } else {
val cardBackgroundColor = if (backgroundColor == Color.BLACK) { val cardBackgroundColor = if (backgroundColor == Color.BLACK) {
Color.WHITE Color.WHITE
@ -113,7 +134,7 @@ class OpenNoteAdapter(
} else { } else {
R.drawable.dialog_bg R.drawable.dialog_bg
} }
open_note_item_holder.background = holder.background =
activity.resources.getColoredDrawableWithColor(cardBackground, cardBackgroundColor, LOWER_ALPHA_INT) activity.resources.getColoredDrawableWithColor(cardBackground, cardBackgroundColor, LOWER_ALPHA_INT)
} }
} }

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/open_new_note_item_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/medium_margin"
android:background="@drawable/widget_round_background"
android:orientation="vertical"
android:padding="@dimen/normal_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/open_new_note_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textSize="@dimen/big_text_size"
android:textStyle="bold"
android:layout_gravity="center"
android:textAlignment="center"
android:text="@string/create_new_note" />
<ImageView
android:id="@+id/open_new_note_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_plus_vector"
android:layout_gravity="center"
android:importantForAccessibility="no" />
</LinearLayout>

View File

@ -14,7 +14,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="2" android:lines="1"
android:textSize="@dimen/big_text_size" android:textSize="@dimen/big_text_size"
android:textStyle="bold" android:textStyle="bold"
tools:text="Title" /> tools:text="Title" />