Browse Source

Added action buttons; added hiding read date

sirekanyan 8 years ago
parent
commit
6ded33f26c

+ 33 - 0
app/src/main/java/me/vadik/knigopis/BookActivity.kt

@@ -2,11 +2,44 @@ package me.vadik.knigopis
 
 import android.os.Bundle
 import android.support.v7.app.AppCompatActivity
+import android.support.v7.widget.Toolbar
+import android.view.View
+import android.view.View.*
+import android.widget.CheckBox
 
 class BookActivity : AppCompatActivity() {
 
+  private val toolbar by lazy { findView<Toolbar>(R.id.toolbar) }
+  private val readCheckbox by lazy { findView<CheckBox>(R.id.book_read_checkbox) }
+  private val dateInputViews by lazy {
+    arrayOf<View>(
+        findView(R.id.book_year_input),
+        findView(R.id.book_month_input),
+        findView(R.id.book_day_input)
+    )
+  }
+
   override fun onCreate(savedInstanceState: Bundle?) {
     super.onCreate(savedInstanceState)
     setContentView(R.layout.book_edit)
+    toolbar.inflateMenu(R.menu.book_menu)
+    toolbar.setNavigationIcon(R.drawable.ic_arrow_back)
+    toolbar.setNavigationOnClickListener {
+      finish()
+    }
+    toolbar.setOnMenuItemClickListener {
+      when (it.itemId) {
+        R.id.option_save_book -> {
+          finish()
+          true
+        }
+        else -> false
+      }
+    }
+    readCheckbox.setOnCheckedChangeListener { _, checked ->
+      dateInputViews.forEach {
+        it.visibility = if (checked) VISIBLE else GONE
+      }
+    }
   }
 }

+ 9 - 0
app/src/main/res/drawable/ic_arrow_back.xml

@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
+</vector>

+ 9 - 0
app/src/main/res/drawable/ic_done.xml

@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
+</vector>

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

@@ -3,7 +3,8 @@
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
-    android:layout_height="match_parent">
+    android:layout_height="match_parent"
+    android:animateLayoutChanges="true">
 
     <android.support.design.widget.AppBarLayout
         android:id="@+id/app_bar_layout"
@@ -57,9 +58,11 @@
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_margin="16dp"
+        android:visibility="gone"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toLeftOf="@+id/book_month_input"
-        app:layout_constraintTop_toBottomOf="@id/book_author_input">
+        app:layout_constraintTop_toBottomOf="@id/book_author_input"
+        tools:visibility="visible">
 
         <EditText
             android:layout_width="match_parent"
@@ -75,9 +78,11 @@
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_margin="16dp"
+        android:visibility="gone"
         app:layout_constraintLeft_toRightOf="@id/book_year_input"
         app:layout_constraintRight_toLeftOf="@+id/book_day_input"
-        app:layout_constraintTop_toBottomOf="@id/book_author_input">
+        app:layout_constraintTop_toBottomOf="@id/book_author_input"
+        tools:visibility="visible">
 
         <EditText
             android:layout_width="match_parent"
@@ -92,9 +97,11 @@
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_margin="16dp"
+        android:visibility="gone"
         app:layout_constraintLeft_toRightOf="@id/book_month_input"
         app:layout_constraintRight_toRightOf="parent"
-        app:layout_constraintTop_toBottomOf="@id/book_author_input">
+        app:layout_constraintTop_toBottomOf="@id/book_author_input"
+        tools:visibility="visible">
 
         <EditText
             android:layout_width="match_parent"
@@ -109,12 +116,12 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_margin="16dp"
-        android:checked="true"
         android:paddingEnd="8dp"
         android:paddingStart="8dp"
         android:text="@string/book_read_checkbox"
         android:textSize="16sp"
-        app:layout_constraintTop_toBottomOf="@id/book_year_input" />
+        app:layout_constraintTop_toBottomOf="@id/book_year_input"
+        tools:checked="true" />
 
     <ImageView
         android:layout_width="0dp"

+ 11 - 0
app/src/main/res/menu/book_menu.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <item
+        android:id="@+id/option_save_book"
+        android:icon="@drawable/ic_done"
+        android:title="@string/book_option_save"
+        app:showAsAction="always" />
+
+</menu>

+ 1 - 0
app/src/main/res/values-ru/strings.xml

@@ -14,6 +14,7 @@
     <string name="option_logout">Выйти</string>
 
     <!-- edit book -->
+    <string name="book_option_save">Сохранить</string>
     <string name="book_hint_title">Название</string>
     <string name="book_hint_author">Автор</string>
     <string name="book_hint_year">Год</string>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -14,6 +14,7 @@
     <string name="option_logout">Logout</string>
 
     <!-- edit book -->
+    <string name="book_option_save">Save</string>
     <string name="book_hint_title">Title</string>
     <string name="book_hint_author">Author</string>
     <string name="book_hint_year">Year</string>

+ 2 - 0
app/src/main/res/values/styles.xml

@@ -10,5 +10,7 @@
         <item name="actionMenuTextColor">@color/white</item>
         <item name="titleTextColor">@color/white</item>
         <item name="android:textColorSecondary">@color/white</item>
+        <item name="iconTint">@color/white</item>
+        <item name="android:tint">@color/white</item>
     </style>
 </resources>