transaction list: add a hollow placeholder at the bottom of the list
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 19 Jan 2019 13:45:38 +0000 (13:45 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 19 Jan 2019 13:45:38 +0000 (13:45 +0000)
to ensure the FAB is not always over something

app/src/main/java/net/ktnx/mobileledger/model/TransactionListItem.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListViewModel.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionRowHolder.java
app/src/main/res/layout/transaction_list_row.xml

index 55fe04a..9243721 100644 (file)
@@ -27,6 +27,9 @@ public class TransactionListItem {
     private boolean monthShown;
     private LedgerTransaction transaction;
     private boolean odd;
+    public TransactionListItem() {
+        this.type = Type.TRAILER;
+    }
     public TransactionListItem(Date date, boolean monthShown) {
         this.type = Type.DELIMITER;
         this.date = date;
@@ -53,5 +56,5 @@ public class TransactionListItem {
     public boolean isOdd() {
         return odd;
     }
-    public enum Type {TRANSACTION, DELIMITER}
+    public enum Type {TRANSACTION, DELIMITER, TRAILER}
 }
index b6e7057..f4a0bcb 100644 (file)
@@ -57,43 +57,53 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
         // a bit longer
         if (item == null) return;
 
-        if (item.getType() == TransactionListItem.Type.TRANSACTION) {
-            holder.vTransaction.setVisibility(View.VISIBLE);
-            holder.vDelimiter.setVisibility(View.GONE);
-            LedgerTransaction tr = item.getTransaction();
-
-//        Log.d("transactions", String.format("Filling position %d with %d accounts", position,
-//                tr.getAccounts().size()));
-
-            TransactionLoader loader = new TransactionLoader();
-            loader.execute(new TransactionLoaderParams(tr, holder, position, boldAccountName,
-                    item.isOdd()));
-
-            // WORKAROUND what seems to be a bug in CardHolder somewhere
-            // when a view that was previously holding a delimiter is re-purposed
-            // occasionally it stays too short (not high enough)
-            holder.vTransaction.measure(View.MeasureSpec
-                            .makeMeasureSpec(holder.itemView.getWidth(), View.MeasureSpec.EXACTLY),
-                    View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
-        }
-        else {
-            Date date = item.getDate();
-            holder.vTransaction.setVisibility(View.GONE);
-            holder.vDelimiter.setVisibility(View.VISIBLE);
-            holder.tvDelimiterDate.setText(DateFormat.getDateInstance().format(date));
-            if (item.isMonthShown()) {
-                holder.tvDelimiterMonth.setText(Globals.monthNames[date.getMonth()]);
-                holder.tvDelimiterMonth.setVisibility(View.VISIBLE);
-//                holder.vDelimiterLine.setBackgroundResource(R.drawable.dashed_border_8dp);
-                holder.vDelimiterLine.setVisibility(View.GONE);
-                holder.vDelimiterThick.setVisibility(View.VISIBLE);
-            }
-            else {
-                holder.tvDelimiterMonth.setVisibility(View.GONE);
-//                holder.vDelimiterLine.setBackgroundResource(R.drawable.dashed_border_1dp);
-                holder.vDelimiterLine.setVisibility(View.VISIBLE);
-                holder.vDelimiterThick.setVisibility(View.GONE);
-            }
+        switch (item.getType()) {
+            case TRANSACTION:
+                holder.vTransaction.setVisibility(View.VISIBLE);
+                holder.vDelimiter.setVisibility(View.GONE);
+                holder.vTrailer.setVisibility(View.GONE);
+                LedgerTransaction tr = item.getTransaction();
+
+                //        Log.d("transactions", String.format("Filling position %d with %d accounts", position,
+                //                tr.getAccounts().size()));
+
+                TransactionLoader loader = new TransactionLoader();
+                loader.execute(new TransactionLoaderParams(tr, holder, position, boldAccountName,
+                        item.isOdd()));
+
+                // WORKAROUND what seems to be a bug in CardHolder somewhere
+                // when a view that was previously holding a delimiter is re-purposed
+                // occasionally it stays too short (not high enough)
+                holder.vTransaction.measure(View.MeasureSpec
+                                .makeMeasureSpec(holder.itemView.getWidth(), View.MeasureSpec.EXACTLY),
+                        View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
+                break;
+            case DELIMITER:
+                Date date = item.getDate();
+                holder.vTransaction.setVisibility(View.GONE);
+                holder.vTrailer.setVisibility(View.GONE);
+                holder.vDelimiter.setVisibility(View.VISIBLE);
+                holder.tvDelimiterDate.setText(DateFormat.getDateInstance().format(date));
+                if (item.isMonthShown()) {
+                    holder.tvDelimiterMonth.setText(Globals.monthNames[date.getMonth()]);
+                    holder.tvDelimiterMonth.setVisibility(View.VISIBLE);
+                    //                holder.vDelimiterLine.setBackgroundResource(R.drawable.dashed_border_8dp);
+                    holder.vDelimiterLine.setVisibility(View.GONE);
+                    holder.vDelimiterThick.setVisibility(View.VISIBLE);
+                }
+                else {
+                    holder.tvDelimiterMonth.setVisibility(View.GONE);
+                    //                holder.vDelimiterLine.setBackgroundResource(R.drawable.dashed_border_1dp);
+                    holder.vDelimiterLine.setVisibility(View.VISIBLE);
+                    holder.vDelimiterThick.setVisibility(View.GONE);
+                }
+                break;
+            case TRAILER:
+                holder.vTransaction.setVisibility(View.GONE);
+                holder.vTrailer.setVisibility(View.VISIBLE);
+                holder.vDelimiter.setVisibility(View.GONE);
+
+                break;
         }
     }
 
@@ -108,7 +118,7 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
 
     @Override
     public int getItemCount() {
-        return TransactionListViewModel.getTransactionCount();
+        return TransactionListViewModel.getTransactionCount() + 1;
     }
     public void setBoldAccountName(String boldAccountName) {
         this.boldAccountName = boldAccountName;
index 0cf97bc..f0e65c7 100644 (file)
@@ -38,7 +38,8 @@ public class TransactionListViewModel extends ViewModel {
     }
     public static TransactionListItem getTransactionListItem(int position) {
         List<TransactionListItem> transactions = Data.transactions.get();
-        if (position >= transactions.size()) return null;
+        if (position >= transactions.size() + 1) return null;
+        if (position == transactions.size()) return new TransactionListItem();
         return transactions.get(position);
     }
     public static int getTransactionCount() {
index 7baba8f..73dd316 100644 (file)
@@ -35,6 +35,7 @@ class TransactionRowHolder extends RecyclerView.ViewHolder {
     CardView vTransaction;
     TextView tvDelimiterMonth, tvDelimiterDate;
     View vDelimiterLine, vDelimiterThick;
+    View vTrailer;
     public TransactionRowHolder(@NonNull View itemView) {
         super(itemView);
         this.row = itemView.findViewById(R.id.transaction_row);
@@ -46,5 +47,6 @@ class TransactionRowHolder extends RecyclerView.ViewHolder {
         this.tvDelimiterMonth = itemView.findViewById(R.id.transaction_delimiter_month);
         this.vDelimiterLine = itemView.findViewById(R.id.transaction_delimiter_line);
         this.vDelimiterThick = itemView.findViewById(R.id.transaction_delimiter_thick);
+        this.vTrailer = itemView.findViewById(R.id.transaction_list_trailer);
     }
 }
index dea0bfd..28864be 100644 (file)
             app:layout_constraintTop_toTopOf="parent" />
 
     </android.support.constraint.ConstraintLayout>
+
+    <view
+        android:id="@+id/transaction_list_trailer"
+        class="android.support.constraint.Placeholder"
+        id="@+id/view"
+        android:layout_width="match_parent"
+        android:layout_height="80dp" />
 </android.support.v7.widget.ContentFrameLayout>
\ No newline at end of file