mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-19 01:50:07 +01:00
Add fab for OpenNoteDialog
This commit is contained in:
parent
da61c2eb32
commit
835168ef0a
@ -11,7 +11,6 @@ import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.beGoneIf
|
||||
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
|
||||
import com.simplemobiletools.commons.extensions.isBlackAndWhiteTheme
|
||||
@ -23,9 +22,6 @@ import com.simplemobiletools.notes.pro.extensions.config
|
||||
import com.simplemobiletools.notes.pro.models.ChecklistItem
|
||||
import com.simplemobiletools.notes.pro.models.Note
|
||||
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_text
|
||||
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_title
|
||||
@ -34,12 +30,6 @@ class OpenNoteAdapter(
|
||||
activity: BaseSimpleActivity, var items: List<Note>,
|
||||
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit
|
||||
) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
|
||||
private companion object {
|
||||
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 actionItemPressed(id: Int) {}
|
||||
@ -48,13 +38,9 @@ class OpenNoteAdapter(
|
||||
|
||||
override fun getIsItemSelectable(position: Int) = false
|
||||
|
||||
override fun getItemSelectionKey(position: Int) = items.getOrNull(position)?.id?.toInt() ?: NEW_NOTE_ID
|
||||
override fun getItemSelectionKey(position: Int) = items.getOrNull(position)?.id?.toInt()
|
||||
|
||||
override fun getItemKeyPosition(key: Int) = if (key == NEW_NOTE_ID) {
|
||||
items.size
|
||||
} else {
|
||||
items.indexOfFirst { it.id?.toInt() == key }
|
||||
}
|
||||
override fun getItemKeyPosition(key: Int) = items.indexOfFirst { it.id?.toInt() == key }
|
||||
|
||||
override fun onActionModeCreated() {}
|
||||
|
||||
@ -62,36 +48,19 @@ class OpenNoteAdapter(
|
||||
|
||||
override fun prepareActionMode(menu: Menu) {}
|
||||
|
||||
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)
|
||||
return createViewHolder(R.layout.open_note_item, parent)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
if (position == items.size) {
|
||||
holder.bindView(NEW_NOTE_ID, true, false) { itemView, layoutPosition ->
|
||||
setupNewNoteView(itemView)
|
||||
}
|
||||
} else {
|
||||
val item = items[position]
|
||||
holder.bindView(item, true, false) { itemView, layoutPosition ->
|
||||
setupView(itemView, item)
|
||||
}
|
||||
val item = items[position]
|
||||
holder.bindView(item, true, false) { itemView, layoutPosition ->
|
||||
setupView(itemView, item)
|
||||
}
|
||||
bindViewHolder(holder)
|
||||
}
|
||||
|
||||
override fun getItemCount() = items.size + 1
|
||||
override fun getItemCount() = items.size
|
||||
|
||||
private fun setupView(view: View, note: Note) {
|
||||
view.apply {
|
||||
@ -109,17 +78,6 @@ class OpenNoteAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupNewNoteView(view: View) {
|
||||
view.apply {
|
||||
setupCard(open_new_note_item_holder)
|
||||
open_new_note_item_title.apply {
|
||||
setText(R.string.create_new_note)
|
||||
setTextColor(properPrimaryColor)
|
||||
}
|
||||
open_new_note_icon.applyColorFilter(properPrimaryColor)
|
||||
}
|
||||
}
|
||||
|
||||
private fun View.setupCard(holder: View) {
|
||||
if (context.isBlackAndWhiteTheme()) {
|
||||
holder.setBackgroundResource(R.drawable.black_dialog_background)
|
||||
|
@ -12,6 +12,7 @@ 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.dialog_open_note_list
|
||||
import kotlinx.android.synthetic.main.dialog_open_note.view.new_note_fab
|
||||
|
||||
class OpenNoteDialog(val activity: BaseSimpleActivity, val callback: (checkedId: Long, newNote: Note?) -> Unit) {
|
||||
private var dialog: AlertDialog? = null
|
||||
@ -29,14 +30,15 @@ class OpenNoteDialog(val activity: BaseSimpleActivity, val callback: (checkedId:
|
||||
|
||||
private fun initDialog(notes: List<Note>, view: View) {
|
||||
view.dialog_open_note_list.adapter = OpenNoteAdapter(activity, notes, view.dialog_open_note_list) {
|
||||
if (it is Note) {
|
||||
callback(it.id!!, null)
|
||||
it as Note
|
||||
callback(it.id!!, null)
|
||||
dialog?.dismiss()
|
||||
}
|
||||
|
||||
view.new_note_fab.setOnClickListener {
|
||||
NewNoteDialog(activity, setChecklistAsDefault = false) {
|
||||
callback(0, it)
|
||||
dialog?.dismiss()
|
||||
} else {
|
||||
NewNoteDialog(activity, setChecklistAsDefault = false) {
|
||||
callback(0, it)
|
||||
dialog?.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,26 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/dialog_open_note_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="@dimen/small_margin"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:layout_marginEnd="@dimen/small_margin"
|
||||
app:layout_constraintHeight_max="500dp">
|
||||
android:minHeight="@dimen/min_open_note_popup_height"
|
||||
app:layout_constraintHeight_max="@dimen/max_open_note_popup_height">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/dialog_open_note_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:itemCount="10"
|
||||
tools:listitem="@layout/open_note_item" />
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyFloatingActionButton
|
||||
android:id="@+id/new_note_fab"
|
||||
android:layout_width="@dimen/fab_size"
|
||||
android:layout_height="@dimen/fab_size"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/activity_margin"
|
||||
android:src="@drawable/ic_plus_vector" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
@ -2,4 +2,6 @@
|
||||
<dimen name="checklist_image_size">56dp</dimen>
|
||||
<dimen name="grid_note_item_width">150dp</dimen>
|
||||
<dimen name="grid_note_item_max_height">300dp</dimen>
|
||||
<dimen name="max_open_note_popup_height">500dp</dimen>
|
||||
<dimen name="min_open_note_popup_height">200dp</dimen>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user