]> git.ktnx.net Git - mobile-ledger.git/commitdiff
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 55fe04ac7f224c0603e92c74e328a7a9d35227cc..9243721a2211405e73a65c988673e4518a165993 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 b6e7057d1aab08e39982e25cd72490a22fc4a700..f4a0bcbb11dd22682fc91206dde12d88a3791541 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 0cf97bca34c632fae97f0217dc2d7c0ad240a7f4..f0e65c7d32809f56b655451aff4d9ce5fc3074c8 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 7baba8fa38c6e6fbf617fee821e9418eaf9d15b7..73dd3168f51bd2c0e591c7986a6af39d0e1c7a2d 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 dea0bfd240b5c087778cd85d1fd1a43434ce3998..28864be95a189ce54b3ea534720a9ece9ef39264 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