]> git.ktnx.net Git - mobile-ledger.git/commitdiff
account list: add hollow trailing item
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 19 Jan 2019 15:34:02 +0000 (15:34 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 19 Jan 2019 15:34:02 +0000 (15:34 +0000)
so that the FAB can be in a position not to cover a useful item

app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java
app/src/main/res/layout/account_summary_row.xml

index 6c6f4a7624a5c48e0e05bd4532f6401e94f06610..6f3e4f2b29b1948b226bea5d2a69f8ac8657d373 100644 (file)
@@ -34,6 +34,8 @@ import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerAccount;
 
+import java.util.List;
+
 class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAdapter.LedgerRowHolder> {
     private boolean selectionActive;
 
@@ -42,40 +44,49 @@ class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAdapter.L
     }
 
     public void onBindViewHolder(@NonNull LedgerRowHolder holder, int position) {
-        LedgerAccount acc = Data.accounts.get().get(position);
-        Context ctx = holder.row.getContext();
-        Resources rm = ctx.getResources();
-
-        holder.tvAccountName.setText(acc.getShortName());
-        holder.tvAccountName.setPadding(
-                acc.getLevel() * rm.getDimensionPixelSize(R.dimen.activity_horizontal_margin) / 2,
-                0, 0, 0);
-        holder.tvAccountAmounts.setText(acc.getAmountsString());
-
-        if (acc.isHidden()) {
-            holder.tvAccountName.setTypeface(null, Typeface.ITALIC);
-            holder.tvAccountAmounts.setTypeface(null, Typeface.ITALIC);
-        }
-        else {
-            holder.tvAccountName.setTypeface(null, Typeface.NORMAL);
-            holder.tvAccountAmounts.setTypeface(null, Typeface.NORMAL);
-        }
+        List<LedgerAccount> accounts = Data.accounts.get();
+        if (position < accounts.size()) {
+            LedgerAccount acc = accounts.get(position);
+            Context ctx = holder.row.getContext();
+            Resources rm = ctx.getResources();
+
+            holder.row.setVisibility(View.VISIBLE);
+            holder.vTrailer.setVisibility(View.GONE);
+            holder.tvAccountName.setText(acc.getShortName());
+            holder.tvAccountName.setPadding(
+                    acc.getLevel() * rm.getDimensionPixelSize(R.dimen.activity_horizontal_margin) /
+                    2, 0, 0, 0);
+            holder.tvAccountAmounts.setText(acc.getAmountsString());
+
+            if (acc.isHidden()) {
+                holder.tvAccountName.setTypeface(null, Typeface.ITALIC);
+                holder.tvAccountAmounts.setTypeface(null, Typeface.ITALIC);
+            }
+            else {
+                holder.tvAccountName.setTypeface(null, Typeface.NORMAL);
+                holder.tvAccountAmounts.setTypeface(null, Typeface.NORMAL);
+            }
 
-        if (position % 2 == 0) {
-            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) holder.row
-                    .setBackgroundColor(rm.getColor(R.color.table_row_dark_bg, ctx.getTheme()));
-            else holder.row.setBackgroundColor(rm.getColor(R.color.table_row_dark_bg));
+            if (position % 2 == 0) {
+                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) holder.row
+                        .setBackgroundColor(rm.getColor(R.color.table_row_dark_bg, ctx.getTheme()));
+                else holder.row.setBackgroundColor(rm.getColor(R.color.table_row_dark_bg));
+            }
+            else {
+                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) holder.row
+                        .setBackgroundColor(rm.getColor(R.color.drawer_background, ctx.getTheme()));
+                else holder.row.setBackgroundColor(rm.getColor(R.color.drawer_background));
+            }
+
+            holder.selectionCb.setVisibility(selectionActive ? View.VISIBLE : View.GONE);
+            holder.selectionCb.setChecked(!acc.isHiddenToBe());
+
+            holder.row.setTag(R.id.POS, position);
         }
         else {
-            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) holder.row
-                    .setBackgroundColor(rm.getColor(R.color.drawer_background, ctx.getTheme()));
-            else holder.row.setBackgroundColor(rm.getColor(R.color.drawer_background));
+            holder.vTrailer.setVisibility(View.VISIBLE);
+            holder.row.setVisibility(View.GONE);
         }
-
-        holder.selectionCb.setVisibility(selectionActive ? View.VISIBLE : View.GONE);
-        holder.selectionCb.setChecked(!acc.isHiddenToBe());
-
-        holder.row.setTag(R.id.POS, position);
     }
 
     @NonNull
@@ -88,7 +99,7 @@ class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAdapter.L
 
     @Override
     public int getItemCount() {
-        return Data.accounts.get().size();
+        return Data.accounts.get().size() + 1;
     }
     public void startSelection() {
         for (LedgerAccount acc : Data.accounts.get()) acc.setHiddenToBe(acc.isHidden());
@@ -127,12 +138,14 @@ class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAdapter.L
         CheckBox selectionCb;
         TextView tvAccountName, tvAccountAmounts;
         LinearLayout row;
+        View vTrailer;
         public LedgerRowHolder(@NonNull View itemView) {
             super(itemView);
-            this.row = (LinearLayout) itemView;
+            this.row = itemView.findViewById(R.id.account_summary_row);
             this.tvAccountName = itemView.findViewById(R.id.account_row_acc_name);
             this.tvAccountAmounts = itemView.findViewById(R.id.account_row_acc_amounts);
             this.selectionCb = itemView.findViewById(R.id.account_row_check);
+            this.vTrailer = itemView.findViewById(R.id.account_summary_trailer);
         }
     }
 }
index f77580bad018979c5b8e4708eade5fb5979ea179..6610c3b2deccd783f55a4f22d161c7663e378169 100644 (file)
@@ -117,6 +117,21 @@ public class TransactionListFragment extends MobileLedgerListFragment {
         return inflater.inflate(R.layout.transaction_list_fragment, container, false);
     }
     @Override
+    public void onResume() {
+        super.onResume();
+        Log.d("flow", "TransactionListFragment.onResume()");
+    }
+    @Override
+    public void onStop() {
+        super.onStop();
+        Log.d("flow", "TransactionListFragment.onStop()");
+    }
+    @Override
+    public void onPause() {
+        super.onPause();
+        Log.d("flow", "TransactionListFragment.onPause()");
+    }
+    @Override
     public void onActivityCreated(@Nullable Bundle savedInstanceState) {
         Log.d("flow", "TransactionListFragment.onActivityCreated called");
         super.onActivityCreated(savedInstanceState);
index 05813dabae7d9dc4fa5645348ad023712392381a..daa033df0375c7045bd8da455e28d0ccb57428de 100644 (file)
@@ -2,7 +2,7 @@
 
 
 <!--
-  ~ Copyright © 2018 Damyan Ivanov.
+  ~ Copyright © 2019 Damyan Ivanov.
   ~ This file is part of Mobile-Ledger.
   ~ Mobile-Ledger is free software: you can distribute it and/or modify it
   ~ under the term of the GNU General Public License as published by
   ~ along with Mobile-Ledger. If not, see <https://www.gnu.org/licenses/>.
   -->
 
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<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:id="@+id/account_summary_row"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:gravity="center_vertical"
-    android:minHeight="?attr/android:actionBarSize"
-    android:orientation="horizontal"
-    android:paddingStart="8dp"
-    android:paddingEnd="8dp"
     tools:showIn="@id/account_root">
 
-    <CheckBox
-        android:id="@+id/account_row_check"
-        android:layout_width="wrap_content"
-        android:layout_height="match_parent"
-        android:button="@drawable/checkbox_star_black" />
-
-    <TextView
-        android:id="@+id/account_row_acc_name"
-        style="@style/account_summary_account_name"
-        android:text="Account name, a really long one. A very very very long one. It may even spawn on more than two lines -- three, four or more." />
-
-    <TextView
-        android:id="@+id/account_row_acc_amounts"
-        style="@style/account_summary_amounts"
-        android:text="123,45\n678,90" />
-</LinearLayout>
\ No newline at end of file
+    <LinearLayout
+        android:id="@+id/account_summary_row"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:gravity="center_vertical"
+        android:minHeight="?attr/android:actionBarSize"
+        android:orientation="horizontal"
+        android:paddingStart="8dp"
+        android:paddingEnd="8dp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent">
+
+        <CheckBox
+            android:id="@+id/account_row_check"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:button="@drawable/checkbox_star_black" />
+
+        <TextView
+            android:id="@+id/account_row_acc_name"
+            style="@style/account_summary_account_name"
+            android:text="Account name, a really long one. A very very very long one. It may even spawn on more than two lines -- three, four or more."
+            tools:ignore="HardcodedText" />
+
+        <TextView
+            android:id="@+id/account_row_acc_amounts"
+            style="@style/account_summary_amounts"
+            android:text="123,45\n678,90"
+            tools:ignore="HardcodedText" />
+    </LinearLayout>
+
+    <View
+        android:id="@+id/account_summary_trailer"
+        android:layout_width="match_parent"
+        android:layout_height="80dp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+</android.support.constraint.ConstraintLayout>
\ No newline at end of file