Explorar el Código

Added dates for finished books and checkboxes for planned books

sirekanyan hace 8 años
padre
commit
72cbc21f9d

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

@@ -151,7 +151,7 @@ class MainActivity : AppCompatActivity() {
         .io2main()
         .subscribe({
           finishedBooks.clear()
-          finishedBooks.addAll(it)
+          finishedBooks.addAll(it.sortedByDescending(FinishedBook::order))
           finishedBooksAdapter.notifyDataSetChanged()
         }, {
           logError("cannot load finished books", it)
@@ -166,7 +166,7 @@ class MainActivity : AppCompatActivity() {
         .io2main()
         .subscribe({
           plannedBooks.clear()
-          plannedBooks.addAll(it.sortedBy { -it.priority })
+          plannedBooks.addAll(it.sortedByDescending { it.priority })
           plannedBooksAdapter.notifyDataSetChanged()
         }, {
           logError("cannot load planned books", it)

+ 27 - 0
app/src/main/java/me/vadik/knigopis/adapters/BooksAdapter.kt

@@ -1,5 +1,7 @@
 package me.vadik.knigopis.adapters
 
+import android.view.View
+import android.widget.CheckBox
 import android.widget.ImageView
 import android.widget.TextView
 import com.bumptech.glide.Glide
@@ -8,6 +10,8 @@ import me.vadik.knigopis.api.BookCoverSearch
 import me.vadik.knigopis.R
 import me.vadik.knigopis.logError
 import me.vadik.knigopis.model.Book
+import me.vadik.knigopis.model.FinishedBook
+import me.vadik.knigopis.model.PlannedBook
 
 class BooksAdapter(private val coverSearch: BookCoverSearch) {
 
@@ -33,5 +37,28 @@ class BooksAdapter(private val coverSearch: BookCoverSearch) {
           it.author
         }
       }
+      .bind<TextView>(R.id.book_read_date) {
+        when (it) {
+          is FinishedBook -> {
+            visibility = View.VISIBLE
+            text = it.readYear
+          }
+          is PlannedBook -> {
+            visibility = View.GONE
+          }
+          else -> TODO()
+        }
+      }
+      .bind<CheckBox>(R.id.book_read_checkbox) {
+        when (it) {
+          is FinishedBook -> {
+            visibility = View.GONE
+          }
+          is PlannedBook -> {
+            visibility = View.VISIBLE
+          }
+          else -> TODO()
+        }
+      }
       .build()
 }

+ 8 - 1
app/src/main/java/me/vadik/knigopis/model/FinishedBook.kt

@@ -4,7 +4,14 @@ class FinishedBook(
     override val id: String,
     override val title: String,
     override val author: String,
+    val readDay: String,
+    val readMonth: String,
+    val readYear: String,
     val notes: String,
     val createdAt: String,
     val user: User
-) : Book
+) : Book {
+  val order
+    get() = arrayOf(readYear, readMonth, readDay)
+        .joinToString("") { it.padStart(4, '0') }
+}

+ 22 - 1
app/src/main/res/layout/book.xml

@@ -11,7 +11,8 @@
         android:layout_height="40dp"
         android:layout_gravity="center_vertical"
         android:layout_marginStart="16dp"
-        tools:ignore="ContentDescription"/>
+        tools:ignore="ContentDescription"
+        tools:src="@color/colorAccent"/>
 
     <LinearLayout
         android:layout_width="match_parent"
@@ -43,4 +44,24 @@
 
     </LinearLayout>
 
+    <FrameLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center_vertical|end"
+        android:layout_marginEnd="16dp">
+
+        <TextView
+            android:id="@+id/book_read_date"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            tools:text="2011"/>
+
+        <CheckBox
+            android:id="@+id/book_read_checkbox"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:visibility="gone"/>
+
+    </FrameLayout>
+
 </FrameLayout>