diff --git a/app/build.gradle b/app/build.gradle index c2f55d37..f0399680 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -66,7 +66,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:f737f6c38b' + implementation 'com.github.esensar:Simple-Commons:2a2c17151e' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.documentfile:documentfile:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/OpenNoteAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/OpenNoteAdapter.kt new file mode 100644 index 00000000..ce38150c --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/OpenNoteAdapter.kt @@ -0,0 +1,66 @@ +package com.simplemobiletools.notes.pro.adapters + +import android.view.Menu +import android.view.View +import android.view.ViewGroup +import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter +import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor +import com.simplemobiletools.commons.helpers.MEDIUM_ALPHA_INT +import com.simplemobiletools.commons.views.MyRecyclerView +import com.simplemobiletools.notes.pro.R +import com.simplemobiletools.notes.pro.models.Note +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_title + +class OpenNoteAdapter( + activity: BaseSimpleActivity, var items: List, + recyclerView: MyRecyclerView, itemClick: (Any) -> Unit +) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) { + + override fun getActionMenuId() = 0 + + override fun actionItemPressed(id: Int) {} + + override fun getSelectableItemCount() = items.size + + override fun getIsItemSelectable(position: Int) = false + + override fun getItemSelectionKey(position: Int) = items.getOrNull(position)?.id?.toInt() + + override fun getItemKeyPosition(key: Int) = items.indexOfFirst { it.id?.toInt() == key } + + override fun onActionModeCreated() {} + + override fun onActionModeDestroyed() {} + + override fun prepareActionMode(menu: Menu) {} + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.open_note_item, parent) + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val item = items[position] + holder.bindView(item, true, false) { itemView, layoutPosition -> + setupView(itemView, item) + } + bindViewHolder(holder) + } + + override fun getItemCount() = items.size + + private fun setupView(view: View, note: Note) { + view.apply { + open_note_item_holder.background = + activity.resources.getColoredDrawableWithColor(R.drawable.black_dialog_background, backgroundColor, MEDIUM_ALPHA_INT) + open_note_item_title.apply { + text = note.title + setTextColor(properPrimaryColor) + } + open_note_item_text.apply { + text = note.getNoteStoredValue(context) + setTextColor(textColor) + } + } + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/OpenNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/OpenNoteDialog.kt index b465a41c..abe1401f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/OpenNoteDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/OpenNoteDialog.kt @@ -1,27 +1,24 @@ package com.simplemobiletools.notes.pro.dialogs -import android.app.Activity import android.view.View -import android.view.ViewGroup -import android.widget.RadioGroup import androidx.appcompat.app.AlertDialog -import com.simplemobiletools.commons.extensions.* +import androidx.recyclerview.widget.StaggeredGridLayoutManager +import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder +import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.views.AutoStaggeredGridLayoutManager import com.simplemobiletools.notes.pro.R -import com.simplemobiletools.notes.pro.extensions.config +import com.simplemobiletools.notes.pro.adapters.OpenNoteAdapter import com.simplemobiletools.notes.pro.helpers.NotesHelper import com.simplemobiletools.notes.pro.models.Note -import kotlinx.android.synthetic.main.dialog_open_note.view.* -import kotlinx.android.synthetic.main.open_note_item.view.* +import kotlinx.android.synthetic.main.dialog_open_note.view.dialog_open_note_list +import kotlinx.android.synthetic.main.dialog_open_note.view.dialog_open_note_new_radio -class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Long, newNote: Note?) -> Unit) { +class OpenNoteDialog(val activity: BaseSimpleActivity, val callback: (checkedId: Long, newNote: Note?) -> Unit) { private var dialog: AlertDialog? = null init { val view = activity.layoutInflater.inflate(R.layout.dialog_open_note, null) - NotesHelper(activity).getNotes { - initDialog(it, view) - } - view.dialog_open_note_new_radio.setOnClickListener { view.dialog_open_note_new_radio.isChecked = false NewNoteDialog(activity, setChecklistAsDefault = false) { @@ -29,32 +26,20 @@ class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Long, new dialog?.dismiss() } } + + val noteItemWidth = activity.resources.getDimensionPixelSize(R.dimen.grid_note_item_width) + + view.dialog_open_note_list.layoutManager = AutoStaggeredGridLayoutManager(noteItemWidth, StaggeredGridLayoutManager.VERTICAL) + + NotesHelper(activity).getNotes { + initDialog(it, view) + } } private fun initDialog(notes: List, view: View) { - val textColor = activity.getProperTextColor() - notes.forEach { - activity.layoutInflater.inflate(R.layout.open_note_item, null).apply { - val note = it - open_note_item_radio_button.apply { - text = note.title - isChecked = note.id == activity.config.currentNoteId - id = note.id!!.toInt() - - setOnClickListener { - callback(note.id!!, null) - dialog?.dismiss() - } - } - open_note_item_icon.apply { - beVisibleIf(note.path.isNotEmpty()) - applyColorFilter(textColor) - setOnClickListener { - activity.toast(note.path) - } - } - view.dialog_open_note_linear.addView(this, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)) - } + view.dialog_open_note_list.adapter = OpenNoteAdapter(activity, notes, view.dialog_open_note_list) { + callback((it as Note).id!!, null) + dialog?.dismiss() } activity.getAlertDialogBuilder().apply { diff --git a/app/src/main/res/layout/dialog_open_note.xml b/app/src/main/res/layout/dialog_open_note.xml index 0e015af1..659374c1 100644 --- a/app/src/main/res/layout/dialog_open_note.xml +++ b/app/src/main/res/layout/dialog_open_note.xml @@ -1,45 +1,45 @@ - - + android:layout_height="match_parent" + android:layout_above="@+id/dialog_open_note_divider" + android:layout_alignParentTop="true" + android:layout_marginStart="@dimen/small_margin" + android:layout_marginTop="@dimen/medium_margin" + android:layout_marginEnd="@dimen/small_margin" + tools:itemCount="2" + tools:listitem="@layout/open_note_item" /> - + + + + + android:text="@string/create_new_note" /> - - - - - - - - - + + diff --git a/app/src/main/res/layout/open_note_item.xml b/app/src/main/res/layout/open_note_item.xml index b4364e4d..f317a23f 100644 --- a/app/src/main/res/layout/open_note_item.xml +++ b/app/src/main/res/layout/open_note_item.xml @@ -1,24 +1,31 @@ - + 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"> - - - + android:ellipsize="end" + android:lines="1" + android:textSize="@dimen/big_text_size" + android:textStyle="bold" + tools:text="Title" /> - + + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 1a0e9740..195c26d6 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,3 +1,5 @@ 56dp + 150dp + 300dp