فهرست منبع

Added progress seek bar instead of temporary text field

sirekanyan 8 سال پیش
والد
کامیت
31e401f425

+ 18 - 3
app/src/main/java/me/vadik/knigopis/BookActivity.kt

@@ -4,6 +4,7 @@ import android.content.Context
 import android.content.Intent
 import android.os.Bundle
 import android.support.v7.app.AppCompatActivity
+import android.view.KeyEvent.ACTION_UP
 import android.view.View.*
 import kotlinx.android.synthetic.main.book_edit.*
 import me.vadik.knigopis.api.BookCoverSearch
@@ -78,7 +79,7 @@ class BookActivity : AppCompatActivity() {
                                 titleEditText.text.toString(),
                                 authorEditText.text.toString(),
                                 notesTextArea.text.toString(),
-                                bookPriority.text.toString().toInt()
+                                progressSeekBar.progress
                             )
                         )
                     }.io2main()
@@ -124,7 +125,21 @@ class BookActivity : AppCompatActivity() {
             }
         }
         readCheckbox.setOnCheckedChangeListener { _, checked ->
-            bookDateInputGroup.visibility = if (checked) VISIBLE else GONE
+            if (checked) {
+                bookDateInputGroup.visibility = VISIBLE
+                progressSeekBar.setProgressSmoothly(100)
+                progressSeekBar.hide()
+            } else {
+                bookDateInputGroup.visibility = GONE
+                progressSeekBar.setProgressSmoothly(0)
+                progressSeekBar.show()
+            }
+        }
+        progressSeekBar.setOnTouchListener { _, event ->
+            if (event.action == ACTION_UP && progressSeekBar.progress == 100) {
+                readCheckbox.isChecked = true
+            }
+            false
         }
     }
 
@@ -147,7 +162,7 @@ class BookActivity : AppCompatActivity() {
                     .doOnSuccess { plannedBook ->
                         readCheckbox.isChecked = false
                         notesTextArea.setText(plannedBook.notes)
-                        bookPriority.setText(plannedBook.priority.toString())
+                        progressSeekBar.setProgressSmoothly(plannedBook.priority)
                     }
             }.subscribe({ book ->
                 titleEditText.setText(book.title)

+ 18 - 0
app/src/main/java/me/vadik/knigopis/extensions.kt

@@ -1,5 +1,6 @@
 package me.vadik.knigopis
 
+import android.animation.ObjectAnimator
 import android.app.Activity
 import android.content.Context
 import android.support.annotation.IdRes
@@ -10,6 +11,7 @@ import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
 import android.view.inputmethod.InputMethodManager
+import android.widget.SeekBar
 import android.widget.Toast
 import com.bumptech.glide.RequestBuilder
 import com.bumptech.glide.load.DataSource
@@ -90,6 +92,22 @@ fun View.hide() {
         .start()
 }
 
+fun SeekBar.show() {
+    animate().alpha(1f)
+        .withStartAction { isEnabled = true }
+        .start()
+}
+
+fun SeekBar.hide() {
+    animate().alpha(0f)
+        .withEndAction { isEnabled = false }
+        .start()
+}
+
+fun SeekBar.setProgressSmoothly(progress: Int) {
+    ObjectAnimator.ofInt(this, "progress", progress).start()
+}
+
 fun Activity.hideKeyboard() {
     currentFocus?.let { view ->
         (getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager)

+ 13 - 12
app/src/main/res/layout/book_edit.xml

@@ -141,7 +141,7 @@
 
             <CheckBox
                 android:id="@+id/readCheckbox"
-                android:layout_width="match_parent"
+                android:layout_width="0dp"
                 android:layout_height="wrap_content"
                 android:layout_marginBottom="16dp"
                 android:layout_marginEnd="9dp"
@@ -151,9 +151,20 @@
                 android:paddingStart="8dp"
                 android:text="@string/book_read_checkbox"
                 android:textSize="16sp"
+                app:layout_constraintLeft_toLeftOf="parent"
                 app:layout_constraintTop_toBottomOf="@id/bookYearInput"
                 tools:checked="true" />
 
+            <android.support.v7.widget.AppCompatSeekBar
+                android:id="@+id/progressSeekBar"
+                android:layout_width="0dp"
+                android:layout_height="0dp"
+                app:layout_constraintBottom_toBottomOf="@id/readCheckbox"
+                app:layout_constraintLeft_toRightOf="@id/readCheckbox"
+                app:layout_constraintRight_toRightOf="parent"
+                app:layout_constraintTop_toTopOf="@id/readCheckbox"
+                tools:progress="20" />
+
             <android.support.v7.widget.AppCompatEditText
                 android:id="@+id/notesTextArea"
                 android:layout_width="match_parent"
@@ -166,20 +177,10 @@
                 android:inputType="textCapSentences|textMultiLine"
                 android:minLines="2"
                 android:padding="16dp"
+                app:layout_constraintBottom_toBottomOf="parent"
                 app:layout_constraintTop_toBottomOf="@id/readCheckbox"
                 tools:text="Неистово плюсую" />
 
-            <!-- todo: remove -->
-            <EditText
-                android:id="@+id/bookPriority"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_margin="16dp"
-                android:hint="priority (temp)"
-                android:inputType="number"
-                app:layout_constraintBottom_toBottomOf="parent"
-                app:layout_constraintTop_toBottomOf="@id/notesTextArea" />
-
             <android.support.constraint.Group
                 android:id="@+id/bookDateInputGroup"
                 android:layout_width="0dp"