Skip to content

Commit

Permalink
Add extended fab
Browse files Browse the repository at this point in the history
  • Loading branch information
shubertm committed Dec 6, 2023
1 parent 17d5097 commit e41726d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import by.kirich1409.viewbindingdelegate.viewBinding
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
import com.google.android.material.floatingactionbutton.FloatingActionButton
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
Expand All @@ -38,9 +39,12 @@ class NotesFragment: Fragment(R.layout.fragment_notes) {
private lateinit var newTextNoteButton: FloatingActionButton
private lateinit var newGraphicNoteButton: FloatingActionButton
private lateinit var pasteNoteButton: Button
private lateinit var newNoteButton: ExtendedFloatingActionButton

private lateinit var recyclerView: RecyclerView

private var showFabs = false

private val newTextNoteClickListener = View.OnClickListener {
activity.fragment = EditTextNotesFragment()
activity.replaceFragment(activity.fragment, EditTextNotesFragment.TAG)
Expand Down Expand Up @@ -70,9 +74,24 @@ class NotesFragment: Fragment(R.layout.fragment_notes) {
recyclerView = binding.include.recyclerView
activity.title = getString(R.string.app_name)
activity.supportActionBar?.setDisplayHomeAsUpEnabled(false)
newTextNoteButton = binding.newNote
newTextNoteButton = binding.newTextNote
pasteNoteButton = binding.pasteNote
newGraphicNoteButton = binding.newGraphicNote
newNoteButton = binding.newNote
newNoteButton.shrink()
newNoteButton.setOnClickListener {
showFabs = if (!showFabs) {
newNoteButton.extend()
newTextNoteButton.show()
newGraphicNoteButton.show()
true
} else {
newNoteButton.shrink()
newTextNoteButton.hide()
newGraphicNoteButton.hide()
false
}
}
newTextNoteButton.setOnClickListener(newTextNoteClickListener)
newGraphicNoteButton.setOnClickListener(newGraphicNoteClickListener)
pasteNoteButton.setOnClickListener(pasteNoteClickListener)
Expand Down
25 changes: 19 additions & 6 deletions app/src/main/res/layout/fragment_notes.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<include
android:id="@+id/include"
Expand All @@ -10,13 +11,24 @@
android:layout_marginBottom="80dp"
layout="@layout/recyclerview"/>

<com.google.android.material.floatingactionbutton.FloatingActionButton
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/newNote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ark_memo_close"
android:layout_gravity="bottom|end"
android:layout_marginEnd="20dp"
android:layout_marginBottom="90dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="20dp"
app:icon="@drawable/add"/>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/newTextNote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="16dp"
android:layout_marginBottom="150dp"
android:visibility="gone"
android:clickable="true"
android:contentDescription="@string/new_note"
android:src="@drawable/ic_create" />
Expand All @@ -26,9 +38,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="80dp"
android:clickable="true"
android:visibility="gone"
android:contentDescription="@string/new_note"
android:src="@drawable/ic_brush" />

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@
<string name="ark_memo_just_now">Just now</string>
<string name="ark_memo_graphic_note">Graphic note %1$s</string>
<string name="ark_memo_text_note">Text note %1$s</string>
<string name="ark_memo_add_new_note">New note</string>
<string name="ark_memo_close">Close</string>

</resources>

0 comments on commit e41726d

Please sign in to comment.