Przeglądaj źródła

Note UI bug fix

sduduzog 7 lat temu
rodzic
commit
a3a2474856

+ 5 - 7
app/src/main/java/com/sduduzog/slimlauncher/ui/main/notes/NoteFragment.kt

@@ -10,7 +10,6 @@ import android.view.ViewGroup
 import android.view.inputmethod.InputMethodManager
 import androidx.fragment.app.Fragment
 import androidx.lifecycle.ViewModelProviders
-import com.google.android.material.bottomsheet.BottomSheetBehavior
 import com.sduduzog.slimlauncher.MainActivity
 import com.sduduzog.slimlauncher.R
 import com.sduduzog.slimlauncher.data.Note
@@ -53,7 +52,7 @@ class NoteFragment : Fragment(), MainActivity.OnBackPressedListener {
         if (note.edited == -1L) {
             editBody()
         } else {
-            bodyEditText.visibility = View.INVISIBLE
+            bodyEditText.visibility = View.GONE
             textBody.visibility = View.VISIBLE
             textBody.text = note.body
             titleEditText.setText(note.title.orEmpty())
@@ -67,14 +66,14 @@ class NoteFragment : Fragment(), MainActivity.OnBackPressedListener {
             editBody()
             true
         }
-        note_fragment.setOnClickListener(object : DoubleClickListener() {
+        textBody.setOnClickListener(object : DoubleClickListener() {
             override fun onDoubleClick(v: View) {
                 titleEditText.isEnabled = true
                 editBody()
             }
 
             override fun onSingleClick(v: View) {
-
+                Log.d(TAG, "single click")
             }
         })
     }
@@ -100,9 +99,8 @@ class NoteFragment : Fragment(), MainActivity.OnBackPressedListener {
     }
 
     private fun editBody() {
-        textBody.visibility = View.INVISIBLE
+        textBody.visibility = View.GONE
         bodyEditText.visibility = View.VISIBLE
-        txtDoubleTap.visibility = View.INVISIBLE
         if (bodyEditText.requestFocus()) {
             val imm = activity!!.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
             imm.showSoftInput(bodyEditText, InputMethodManager.SHOW_IMPLICIT)
@@ -115,7 +113,7 @@ class NoteFragment : Fragment(), MainActivity.OnBackPressedListener {
         val title = titleEditText.text.toString()
         val newNote = Note(body, Date().time)
         newNote.title = if (title.isEmpty()) null else title
-        newNote.body = body
+        newNote.body = body.trim()
         newNote.id = note.id
         val currentDigest = hash(newNote.title + newNote.body)
         if (body.isEmpty()) return

+ 60 - 66
app/src/main/res/layout/note_fragment.xml

@@ -1,78 +1,72 @@
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<ScrollView 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/note_fragment"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    app:layout_constraintEnd_toEndOf="parent"
+    app:layout_constraintStart_toStartOf="parent"
+    app:layout_constraintTop_toTopOf="parent"
     tools:context="com.sduduzog.slimlauncher.ui.main.notes.NoteFragment">
 
-
-    <EditText
-        android:id="@+id/titleEditText"
-        android:layout_width="0dp"
+    <LinearLayout
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginStart="8dp"
-        android:layout_marginTop="8dp"
-        android:layout_marginEnd="8dp"
-        android:background="@android:color/transparent"
-        android:ems="10"
-        android:hint="@string/note_fragment_hint_title"
-        android:inputType="textPersonName"
-        android:padding="8dp"
-        android:textSize="24sp"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent"
-        tools:ignore="Autofill,LabelFor" />
+        android:orientation="vertical">
 
-    <EditText
-        android:id="@+id/bodyEditText"
-        android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:layout_marginStart="8dp"
-        android:layout_marginTop="8dp"
-        android:layout_marginEnd="8dp"
-        android:background="@android:color/transparent"
-        android:ems="10"
-        android:hint="@string/note_fragment_hint_body"
-        android:inputType="textAutoCorrect|textAutoComplete|textMultiLine|textImeMultiLine"
-        android:padding="8dp"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/titleEditText"
-        tools:ignore="Autofill,LabelFor" />
+        <EditText
+            android:id="@+id/titleEditText"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="8dp"
+            android:layout_marginTop="8dp"
+            android:layout_marginEnd="8dp"
+            android:background="@android:color/transparent"
+            android:ems="10"
+            android:hint="@string/note_fragment_hint_title"
+            android:inputType="textPersonName"
+            android:padding="8dp"
+            android:textSize="24sp"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent"
+            tools:ignore="Autofill,LabelFor" />
 
-    <TextView
-        android:id="@+id/textBody"
-        android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:layout_marginStart="8dp"
-        android:layout_marginTop="8dp"
-        android:layout_marginEnd="8dp"
-        android:padding="8dp"
-        android:text="@string/note_fragment_hint_body"
-        android:textSize="18sp"
-        android:visibility="invisible"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintHorizontal_bias="1.0"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/titleEditText" />
+        <EditText
+            android:id="@+id/bodyEditText"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="8dp"
+            android:layout_marginTop="8dp"
+            android:layout_marginEnd="8dp"
+            android:background="@android:color/transparent"
+            android:ems="10"
+            android:gravity="top"
+            android:hint="@string/note_fragment_hint_body"
+            android:inputType="textCapSentences|textAutoCorrect|textAutoComplete|textMultiLine|textImeMultiLine"
+            android:minLines="2"
+            android:padding="8dp"
+            android:textSize="14sp"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/titleEditText"
+            tools:ignore="Autofill,LabelFor" />
 
-    <TextView
-        android:id="@+id/txtDoubleTap"
-        android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:layout_marginStart="8dp"
-        android:layout_marginTop="8dp"
-        android:layout_marginEnd="8dp"
-        android:layout_marginBottom="32dp"
-        android:alpha="0.1"
-        android:gravity="center"
-        android:text="@string/double_tap_anywhere_to_edit"
-        android:textSize="30sp"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/textBody" />
+        <TextView
+            android:id="@+id/textBody"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="8dp"
+            android:layout_marginTop="8dp"
+            android:layout_marginEnd="8dp"
+            android:padding="8dp"
+            android:text="@string/note_fragment_hint_body"
+            android:textSize="14sp"
+            android:visibility="gone"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintHorizontal_bias="1.0"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/titleEditText" />
+    </LinearLayout>
+</ScrollView>
 
-</androidx.constraintlayout.widget.ConstraintLayout>