Skip to content

Commit 835168e

Browse files
committed
Add fab for OpenNoteDialog
1 parent da61c2e commit 835168e

File tree

4 files changed

+35
-64
lines changed

4 files changed

+35
-64
lines changed

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

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ 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.applyColorFilter
1514
import com.simplemobiletools.commons.extensions.beGoneIf
1615
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
1716
import com.simplemobiletools.commons.extensions.isBlackAndWhiteTheme
@@ -23,9 +22,6 @@ import com.simplemobiletools.notes.pro.extensions.config
2322
import com.simplemobiletools.notes.pro.models.ChecklistItem
2423
import com.simplemobiletools.notes.pro.models.Note
2524
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
2925
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_holder
3026
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_text
3127
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_title
@@ -34,12 +30,6 @@ class OpenNoteAdapter(
3430
activity: BaseSimpleActivity, var items: List<Note>,
3531
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit
3632
) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
37-
private companion object {
38-
const val NEW_NOTE_ID = -1
39-
const val VIEW_TYPE_NOTE = 0
40-
const val VIEW_TYPE_NEW_NOTE = 1
41-
}
42-
4333
override fun getActionMenuId() = 0
4434

4535
override fun actionItemPressed(id: Int) {}
@@ -48,50 +38,29 @@ class OpenNoteAdapter(
4838

4939
override fun getIsItemSelectable(position: Int) = false
5040

51-
override fun getItemSelectionKey(position: Int) = items.getOrNull(position)?.id?.toInt() ?: NEW_NOTE_ID
41+
override fun getItemSelectionKey(position: Int) = items.getOrNull(position)?.id?.toInt()
5242

53-
override fun getItemKeyPosition(key: Int) = if (key == NEW_NOTE_ID) {
54-
items.size
55-
} else {
56-
items.indexOfFirst { it.id?.toInt() == key }
57-
}
43+
override fun getItemKeyPosition(key: Int) = items.indexOfFirst { it.id?.toInt() == key }
5844

5945
override fun onActionModeCreated() {}
6046

6147
override fun onActionModeDestroyed() {}
6248

6349
override fun prepareActionMode(menu: Menu) {}
6450

65-
override fun getItemViewType(position: Int): Int = if (position == items.size) {
66-
VIEW_TYPE_NEW_NOTE
67-
} else {
68-
VIEW_TYPE_NOTE
69-
}
70-
7151
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)
52+
return createViewHolder(R.layout.open_note_item, parent)
7853
}
7954

8055
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
81-
if (position == items.size) {
82-
holder.bindView(NEW_NOTE_ID, true, false) { itemView, layoutPosition ->
83-
setupNewNoteView(itemView)
84-
}
85-
} else {
86-
val item = items[position]
87-
holder.bindView(item, true, false) { itemView, layoutPosition ->
88-
setupView(itemView, item)
89-
}
56+
val item = items[position]
57+
holder.bindView(item, true, false) { itemView, layoutPosition ->
58+
setupView(itemView, item)
9059
}
9160
bindViewHolder(holder)
9261
}
9362

94-
override fun getItemCount() = items.size + 1
63+
override fun getItemCount() = items.size
9564

9665
private fun setupView(view: View, note: Note) {
9766
view.apply {
@@ -109,17 +78,6 @@ class OpenNoteAdapter(
10978
}
11079
}
11180

112-
private fun setupNewNoteView(view: View) {
113-
view.apply {
114-
setupCard(open_new_note_item_holder)
115-
open_new_note_item_title.apply {
116-
setText(R.string.create_new_note)
117-
setTextColor(properPrimaryColor)
118-
}
119-
open_new_note_icon.applyColorFilter(properPrimaryColor)
120-
}
121-
}
122-
12381
private fun View.setupCard(holder: View) {
12482
if (context.isBlackAndWhiteTheme()) {
12583
holder.setBackgroundResource(R.drawable.black_dialog_background)

app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/OpenNoteDialog.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.simplemobiletools.notes.pro.adapters.OpenNoteAdapter
1212
import com.simplemobiletools.notes.pro.helpers.NotesHelper
1313
import com.simplemobiletools.notes.pro.models.Note
1414
import kotlinx.android.synthetic.main.dialog_open_note.view.dialog_open_note_list
15+
import kotlinx.android.synthetic.main.dialog_open_note.view.new_note_fab
1516

1617
class OpenNoteDialog(val activity: BaseSimpleActivity, val callback: (checkedId: Long, newNote: Note?) -> Unit) {
1718
private var dialog: AlertDialog? = null
@@ -29,14 +30,15 @@ class OpenNoteDialog(val activity: BaseSimpleActivity, val callback: (checkedId:
2930

3031
private fun initDialog(notes: List<Note>, view: View) {
3132
view.dialog_open_note_list.adapter = OpenNoteAdapter(activity, notes, view.dialog_open_note_list) {
32-
if (it is Note) {
33-
callback(it.id!!, null)
33+
it as Note
34+
callback(it.id!!, null)
35+
dialog?.dismiss()
36+
}
37+
38+
view.new_note_fab.setOnClickListener {
39+
NewNoteDialog(activity, setChecklistAsDefault = false) {
40+
callback(0, it)
3441
dialog?.dismiss()
35-
} else {
36-
NewNoteDialog(activity, setChecklistAsDefault = false) {
37-
callback(0, it)
38-
dialog?.dismiss()
39-
}
4042
}
4143
}
4244

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:tools="http://schemas.android.com/tools"
2+
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
43
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
55
android:id="@+id/dialog_open_note_holder"
66
android:layout_width="match_parent"
77
android:layout_height="wrap_content">
88

99
<androidx.core.widget.NestedScrollView
1010
android:layout_width="match_parent"
11-
android:layout_height="0dp"
12-
app:layout_constraintStart_toStartOf="parent"
13-
app:layout_constraintEnd_toEndOf="parent"
14-
app:layout_constraintTop_toTopOf="parent"
11+
android:layout_height="match_parent"
1512
android:layout_marginStart="@dimen/small_margin"
1613
android:layout_marginTop="@dimen/medium_margin"
1714
android:layout_marginEnd="@dimen/small_margin"
18-
app:layout_constraintHeight_max="500dp">
15+
android:minHeight="@dimen/min_open_note_popup_height"
16+
app:layout_constraintHeight_max="@dimen/max_open_note_popup_height">
17+
1918
<com.simplemobiletools.commons.views.MyRecyclerView
2019
android:id="@+id/dialog_open_note_list"
2120
android:layout_width="match_parent"
2221
android:layout_height="match_parent"
2322
tools:itemCount="10"
2423
tools:listitem="@layout/open_note_item" />
24+
2525
</androidx.core.widget.NestedScrollView>
26-
</androidx.constraintlayout.widget.ConstraintLayout>
26+
27+
<com.simplemobiletools.commons.views.MyFloatingActionButton
28+
android:id="@+id/new_note_fab"
29+
android:layout_width="@dimen/fab_size"
30+
android:layout_height="@dimen/fab_size"
31+
android:layout_gravity="bottom|end"
32+
android:layout_margin="@dimen/activity_margin"
33+
android:src="@drawable/ic_plus_vector" />
34+
35+
</androidx.coordinatorlayout.widget.CoordinatorLayout>

app/src/main/res/values/dimens.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
<dimen name="checklist_image_size">56dp</dimen>
33
<dimen name="grid_note_item_width">150dp</dimen>
44
<dimen name="grid_note_item_max_height">300dp</dimen>
5+
<dimen name="max_open_note_popup_height">500dp</dimen>
6+
<dimen name="min_open_note_popup_height">200dp</dimen>
57
</resources>

0 commit comments

Comments
 (0)