瀏覽代碼

Added screen for adding book

sirekanyan 8 年之前
父節點
當前提交
9b54e00ace

+ 1 - 0
app/build.gradle

@@ -19,6 +19,7 @@ dependencies {
     compile "com.android.support:appcompat-v7:$support_version"
     compile "com.android.support:design:$support_version"
     compile "com.android.support:support-vector-drawable:$support_version"
+    compile 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
     compile "io.reactivex.rxjava2:rxjava:2.1.4"
     compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
     compile "com.squareup.retrofit2:retrofit:$retrofit_version"

+ 10 - 7
app/src/main/AndroidManifest.xml

@@ -1,11 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
-<manifest
-    xmlns:android="http://schemas.android.com/apk/res/android"
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     package="me.vadik.knigopis">
 
-    <uses-permission android:name="android.permission.INTERNET"/>
-    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
 
     <application
         android:name=".App"
@@ -22,13 +21,17 @@
             android:name=".MainActivity"
             android:label="@string/app_name">
             <intent-filter>
-                <action android:name="android.intent.action.MAIN"/>
-                <category android:name="android.intent.category.LAUNCHER"/>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
 
+        <activity
+            android:name=".BookActivity"
+            android:label="@string/book_edit_title" />
+
         <activity
             android:name="ru.ulogin.sdk.UloginAuthActivity"
-            android:configChanges="orientation|screenSize"/>
+            android:configChanges="orientation|screenSize" />
     </application>
 </manifest>

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

@@ -0,0 +1,12 @@
+package me.vadik.knigopis
+
+import android.os.Bundle
+import android.support.v7.app.AppCompatActivity
+
+class BookActivity : AppCompatActivity() {
+
+  override fun onCreate(savedInstanceState: Bundle?) {
+    super.onCreate(savedInstanceState)
+    setContentView(R.layout.book_edit)
+  }
+}

+ 10 - 4
app/src/main/java/me/vadik/knigopis/MainActivity.kt

@@ -3,6 +3,7 @@ package me.vadik.knigopis
 import android.content.Intent
 import android.os.Bundle
 import android.support.design.widget.BottomNavigationView
+import android.support.design.widget.FloatingActionButton
 import android.support.v7.app.AppCompatActivity
 import android.support.v7.widget.LinearLayoutManager
 import android.support.v7.widget.RecyclerView
@@ -36,6 +37,7 @@ class MainActivity : AppCompatActivity() {
   private val allBooksAdapter by lazy { booksAdapter.build(allBooks) }
   private val finishedBooksAdapter by lazy { booksAdapter.build(finishedBooks) }
   private val plannedBooksAdapter by lazy { booksAdapter.build(plannedBooks) }
+  private val fab by lazy { findView<FloatingActionButton>(R.id.add_book_button) }
   private lateinit var booksRecyclerView: RecyclerView
   private lateinit var loginOption: MenuItem
   private lateinit var currentTab: CurrentTab
@@ -46,6 +48,9 @@ class MainActivity : AppCompatActivity() {
     booksRecyclerView = initRecyclerView(findView(R.id.books_recycler_view))
     initNavigationView(findView(R.id.navigation))
     initToolbar(findView(R.id.toolbar))
+    fab.setOnClickListener {
+      startActivity(Intent(this, BookActivity::class.java))
+    }
   }
 
   override fun onStart() {
@@ -111,11 +116,12 @@ class MainActivity : AppCompatActivity() {
   }
 
   private fun setCurrentTab(tab: CurrentTab) {
+    if (tab == HOME_TAB) fab.show() else fab.hide()
     currentTab = tab
     when (tab) {
       HOME_TAB -> refreshHomeTab()
-      USERS_TAB -> refreshDoneTab()
-      NOTES_TAB -> refreshTodoTab()
+      USERS_TAB -> refreshUsersTab()
+      NOTES_TAB -> refreshNotesTab()
     }
   }
 
@@ -138,7 +144,7 @@ class MainActivity : AppCompatActivity() {
         })
   }
 
-  private fun refreshDoneTab() {
+  private fun refreshUsersTab() {
     booksRecyclerView.adapter = finishedBooksAdapter
     api.getFinishedBooks(auth.getAccessToken())
         .io2main()
@@ -151,7 +157,7 @@ class MainActivity : AppCompatActivity() {
         })
   }
 
-  private fun refreshTodoTab() {
+  private fun refreshNotesTab() {
     booksRecyclerView.adapter = plannedBooksAdapter
     api.getPlannedBooks(auth.getAccessToken())
         .io2main()

+ 9 - 0
app/src/main/res/drawable/ic_add.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="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
+</vector>

+ 22 - 8
app/src/main/res/layout/activity_main.xml

@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<LinearLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout 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/container"
@@ -18,16 +17,31 @@
             android:id="@+id/toolbar"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            app:title="@string/app_name"/>
+            app:title="@string/app_name" />
 
     </android.support.design.widget.AppBarLayout>
 
-    <android.support.v7.widget.RecyclerView
-        android:id="@+id/books_recycler_view"
+    <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="0dp"
-        android:layout_weight="1"
-        tools:listitem="@layout/book"/>
+        android:layout_weight="1">
+
+        <android.support.v7.widget.RecyclerView
+            android:id="@+id/books_recycler_view"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            tools:listitem="@layout/book" />
+
+        <android.support.design.widget.FloatingActionButton
+            android:id="@+id/add_book_button"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="end|bottom"
+            android:layout_margin="16dp"
+            android:tint="@color/white"
+            app:srcCompat="@drawable/ic_add" />
+
+    </FrameLayout>
 
     <android.support.design.widget.BottomNavigationView
         android:id="@+id/navigation"
@@ -35,6 +49,6 @@
         android:layout_height="wrap_content"
         android:layout_gravity="bottom"
         android:background="?android:attr/windowBackground"
-        app:menu="@menu/navigation"/>
+        app:menu="@menu/navigation" />
 
 </LinearLayout>

+ 130 - 0
app/src/main/res/layout/book_edit.xml

@@ -0,0 +1,130 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <android.support.design.widget.AppBarLayout
+        android:id="@+id/app_bar_layout"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:theme="@style/AppBarTheme"
+        app:layout_constraintTop_toTopOf="parent">
+
+        <android.support.v7.widget.Toolbar
+            android:id="@+id/toolbar"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            app:title="@string/book_add_title" />
+
+    </android.support.design.widget.AppBarLayout>
+
+    <android.support.design.widget.TextInputLayout
+        android:id="@+id/book_title_input"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_margin="16dp"
+        app:layout_constraintTop_toBottomOf="@id/app_bar_layout">
+
+        <EditText
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:hint="@string/book_hint_title"
+            android:inputType="textCapSentences"
+            tools:text="Два капитана" />
+
+    </android.support.design.widget.TextInputLayout>
+
+    <android.support.design.widget.TextInputLayout
+        android:id="@+id/book_author_input"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_margin="16dp"
+        app:layout_constraintTop_toBottomOf="@id/book_title_input">
+
+        <EditText
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:hint="@string/book_hint_author"
+            android:inputType="textCapWords"
+            tools:text="Вениамин Каверин" />
+
+    </android.support.design.widget.TextInputLayout>
+
+    <android.support.design.widget.TextInputLayout
+        android:id="@+id/book_year_input"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_margin="16dp"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toLeftOf="@+id/book_month_input"
+        app:layout_constraintTop_toBottomOf="@id/book_author_input">
+
+        <EditText
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:hint="@string/book_hint_year"
+            android:inputType="number"
+            tools:text="2012" />
+
+    </android.support.design.widget.TextInputLayout>
+
+    <android.support.design.widget.TextInputLayout
+        android:id="@+id/book_month_input"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_margin="16dp"
+        app:layout_constraintLeft_toRightOf="@id/book_year_input"
+        app:layout_constraintRight_toLeftOf="@+id/book_day_input"
+        app:layout_constraintTop_toBottomOf="@id/book_author_input">
+
+        <EditText
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:hint="@string/book_hint_month"
+            android:inputType="number" />
+
+    </android.support.design.widget.TextInputLayout>
+
+    <android.support.design.widget.TextInputLayout
+        android:id="@+id/book_day_input"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_margin="16dp"
+        app:layout_constraintLeft_toRightOf="@id/book_month_input"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toBottomOf="@id/book_author_input">
+
+        <EditText
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:hint="@string/book_hint_day"
+            android:inputType="number" />
+
+    </android.support.design.widget.TextInputLayout>
+
+    <CheckBox
+        android:id="@+id/book_read_checkbox"
+        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" />
+
+    <ImageView
+        android:layout_width="0dp"
+        android:layout_height="0dp"
+        android:layout_margin="16dp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toBottomOf="@id/book_read_checkbox"
+        tools:ignore="ContentDescription"
+        tools:src="@color/colorAccent" />
+
+</android.support.constraint.ConstraintLayout>

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

@@ -1,8 +1,23 @@
 <resources>
+    <!-- toolbar -->
     <string name="app_name">Книгопись</string>
+    <string name="book_add_title">Добавить книгу</string>
+    <string name="book_edit_title">Редактировать книгу</string>
+
+    <!-- navigation -->
     <string name="title_home">Мои книги</string>
     <string name="title_users">Подписки</string>
     <string name="title_notes">Примечания</string>
+
+    <!-- menu -->
     <string name="option_login">Войти</string>
     <string name="option_logout">Выйти</string>
+
+    <!-- edit book -->
+    <string name="book_hint_title">Название</string>
+    <string name="book_hint_author">Автор</string>
+    <string name="book_hint_year">Год</string>
+    <string name="book_hint_month">Месяц</string>
+    <string name="book_hint_day">День</string>
+    <string name="book_read_checkbox">Прочитана</string>
 </resources>

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

@@ -1,8 +1,23 @@
 <resources>
+    <!-- toolbar -->
     <string name="app_name">Knigopis</string>
+    <string name="book_add_title">Add book</string>
+    <string name="book_edit_title">Edit book</string>
+
+    <!-- navigation -->
     <string name="title_home">Books</string>
     <string name="title_users">Followers</string>
     <string name="title_notes">Notes</string>
+
+    <!-- menu -->
     <string name="option_login">Login</string>
     <string name="option_logout">Logout</string>
+
+    <!-- edit book -->
+    <string name="book_hint_title">Title</string>
+    <string name="book_hint_author">Author</string>
+    <string name="book_hint_year">Year</string>
+    <string name="book_hint_month">Month</string>
+    <string name="book_hint_day">Day</string>
+    <string name="book_read_checkbox">Done</string>
 </resources>