]> git.ktnx.net Git - mobile-ledger.git/commitdiff
go to transactions for the account when an account is clicked in the account summary
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 31 Dec 2018 19:00:20 +0000 (19:00 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 31 Dec 2018 19:00:20 +0000 (19:00 +0000)
app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java
app/src/main/res/layout/account_summary_row.xml

index b0b673273a8424b59491fb7267316a677aa9c9f3..3a09f2bbde2cc5d90ad5196eb19520b871f4c46f 100644 (file)
@@ -82,6 +82,8 @@ public class AccountSummaryFragment extends Fragment {
     public void onActivityCreated(@Nullable Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
 
+        mActivity.markDrawerItemCurrent(R.id.nav_account_summary);
+
         model = ViewModelProviders.of(this).get(AccountSummaryViewModel.class);
         List<LedgerAccount> accounts = model.getAccounts(this.getContext());
         modelAdapter = new AccountSummaryAdapter(accounts);
@@ -103,6 +105,14 @@ public class AccountSummaryFragment extends Fragment {
                         if (modelAdapter.isSelectionActive()) {
                             modelAdapter.selectItem(position);
                         }
+                        else {
+                            List<LedgerAccount> accounts = model.getAccounts(mActivity);
+                            if (accounts != null) {
+                                LedgerAccount account = accounts.get(position);
+
+                                mActivity.showAccountTransactions(account);
+                            }
+                        }
                     }
 
                     @Override
index 52436c4d85b55bac04bb7afb296f9b2e539999b7..ad124667f5b788088a7009e8151c7420fadd94ec 100644 (file)
@@ -35,8 +35,9 @@ import android.view.MenuItem;
 import android.view.View;
 import android.widget.LinearLayout;
 
-import net.ktnx.mobileledger.ui.account_summary.AccountSummaryFragment;
 import net.ktnx.mobileledger.R;
+import net.ktnx.mobileledger.model.LedgerAccount;
+import net.ktnx.mobileledger.ui.account_summary.AccountSummaryFragment;
 import net.ktnx.mobileledger.ui.transaction_list.TransactionListFragment;
 
 public class MainActivity extends AppCompatActivity {
@@ -44,6 +45,7 @@ public class MainActivity extends AppCompatActivity {
     private AccountSummaryFragment accountSummaryFragment;
     private TransactionListFragment transactionListFragment;
     private Fragment currentFragment = null;
+    private FragmentManager fragmentManager;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -70,6 +72,8 @@ public class MainActivity extends AppCompatActivity {
             e.printStackTrace();
         }
 
+        fragmentManager = getSupportFragmentManager();
+
         onAccountSummaryClicked(null);
     }
 
@@ -112,7 +116,7 @@ public class MainActivity extends AppCompatActivity {
         Intent intent = new Intent(this, SettingsActivity.class);
         startActivity(intent);
     }
-    private void markDrawerItemCurrent(int id) {
+    public void markDrawerItemCurrent(int id) {
         View item = drawer.findViewById(id);
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
             item.setBackgroundColor(getResources().getColor(R.color.table_row_even_bg, getTheme()));
@@ -163,24 +167,50 @@ public class MainActivity extends AppCompatActivity {
         }
     }
     public void onAccountSummaryClicked(View view) {
-        markDrawerItemCurrent(R.id.nav_account_summary);
         drawer.closeDrawers();
 
-        FragmentManager fm = getSupportFragmentManager();
-        FragmentTransaction ft = fm.beginTransaction();
-        currentFragment = accountSummaryFragment = new AccountSummaryFragment();
+        resetFragmentBackStack();
+
+        showAccountSummaryFragment();
+    }
+    private void showAccountSummaryFragment() {
+        FragmentTransaction ft = fragmentManager.beginTransaction();
+        accountSummaryFragment = new AccountSummaryFragment();
         ft.replace(R.id.root_frame, accountSummaryFragment);
         ft.commit();
+        currentFragment = accountSummaryFragment;
     }
     public void onLatestTransactionsClicked(View view) {
-        markDrawerItemCurrent(R.id.nav_latest_transactions);
         drawer.closeDrawers();
 
-        FragmentManager fm = getSupportFragmentManager();
-        FragmentTransaction ft = fm.beginTransaction();
-        currentFragment = transactionListFragment = new TransactionListFragment();
+        resetFragmentBackStack();
+
+        showTransactionsFragment(null);
+    }
+    private void resetFragmentBackStack() {
+//        fragmentManager.popBackStack(0, FragmentManager.POP_BACK_STACK_INCLUSIVE);
+    }
+    private void showTransactionsFragment(LedgerAccount account) {
+        FragmentTransaction ft = fragmentManager.beginTransaction();
+        if (transactionListFragment == null) {
+            Log.d("flow", "MainActivity creating TransactionListFragment");
+            transactionListFragment = new TransactionListFragment();
+        }
+        Bundle bundle = new Bundle();
+        if (account != null) {
+            bundle.putString(TransactionListFragment.BUNDLE_KEY_FILTER_ACCOUNT_NAME,
+                    account.getName());
+        }
+        transactionListFragment.setArguments(bundle);
         ft.replace(R.id.root_frame, transactionListFragment);
+        if (account != null)
+            ft.addToBackStack(getResources().getString(R.string.title_activity_transaction_list));
         ft.commit();
+
+        currentFragment = transactionListFragment;
+    }
+    public void showAccountTransactions(LedgerAccount account) {
+        showTransactionsFragment(account);
     }
     @Override
     public void onBackPressed() {
@@ -189,6 +219,9 @@ public class MainActivity extends AppCompatActivity {
             drawer.closeDrawer(GravityCompat.START);
         }
         else {
+            Log.d("fragments",
+                    String.format("manager stack: %d", fragmentManager.getBackStackEntryCount()));
+
             super.onBackPressed();
         }
     }
index 72e07b27ba9229ea08599834f72dad2357b970e1..4ea48ab98f02b9c5ce151739e2a8ce3bf353323c 100644 (file)
@@ -43,9 +43,9 @@ import android.widget.LinearLayout;
 import android.widget.ProgressBar;
 import android.widget.TextView;
 
-import net.ktnx.mobileledger.ui.activity.MainActivity;
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.async.RetrieveTransactionsTask;
+import net.ktnx.mobileledger.ui.activity.MainActivity;
 import net.ktnx.mobileledger.utils.Globals;
 import net.ktnx.mobileledger.utils.MLDB;
 
@@ -57,7 +57,9 @@ import java.util.Date;
 import static android.content.Context.INPUT_METHOD_SERVICE;
 
 public class TransactionListFragment extends Fragment {
+    public static final String BUNDLE_KEY_FILTER_ACCOUNT_NAME = "filter_account_name";
     public TransactionListViewModel model;
+    private String mShowOnlyAccountName;
     private MainActivity mActivity;
     private View bTransactionListCancelDownload;
     private MenuItem menuTransactionListFilter;
@@ -70,6 +72,25 @@ public class TransactionListFragment extends Fragment {
     private TransactionListAdapter modelAdapter;
     private RetrieveTransactionsTask retrieveTransactionsTask;
     private AutoCompleteTextView accNameFilter;
+    public void setShowOnlyAccountName(String mShowOnlyAccountName) {
+        this.mShowOnlyAccountName = mShowOnlyAccountName;
+        if (modelAdapter != null) {
+            modelAdapter.setBoldAccountName(mShowOnlyAccountName);
+        }
+        if (accNameFilter != null) {
+            accNameFilter.setText(mShowOnlyAccountName, false);
+        }
+        if (vAccountFilter != null) {
+            vAccountFilter.setVisibility(
+                    ((mShowOnlyAccountName != null) && !mShowOnlyAccountName.isEmpty())
+                    ? View.VISIBLE : View.GONE);
+        }
+    }
+    @Override
+    public void setArguments(@Nullable Bundle args) {
+        super.setArguments(args);
+        mShowOnlyAccountName = args.getString(BUNDLE_KEY_FILTER_ACCOUNT_NAME);
+    }
     @Override
     public void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -92,6 +113,8 @@ public class TransactionListFragment extends Fragment {
         Log.d("flow", "TransactionListFragment.onActivityCreated called");
         super.onActivityCreated(savedInstanceState);
 
+        mActivity.markDrawerItemCurrent(R.id.nav_latest_transactions);
+
         swiper = mActivity.findViewById(R.id.transaction_swipe);
         if (swiper == null) throw new RuntimeException("Can't get hold on the swipe layout");
         root = mActivity.findViewById(R.id.transaction_root);
@@ -107,6 +130,8 @@ public class TransactionListFragment extends Fragment {
         model = ViewModelProviders.of(this).get(TransactionListViewModel.class);
         modelAdapter = new TransactionListAdapter(model);
 
+        modelAdapter.setBoldAccountName(mShowOnlyAccountName);
+
         RecyclerView root = mActivity.findViewById(R.id.transaction_root);
         root.setAdapter(modelAdapter);
 
@@ -144,6 +169,13 @@ public class TransactionListFragment extends Fragment {
         updateLastUpdateText();
         long last_update = MLDB.get_option_value(mActivity, MLDB.OPT_TRANSACTION_LIST_STAMP, 0L);
         Log.d("transactions", String.format("Last update = %d", last_update));
+
+        if (mShowOnlyAccountName != null) {
+            accNameFilter.setText(mShowOnlyAccountName, false);
+            onShowFilterClick(null);
+            Log.d("flow", String.format("Account filter set to '%s'", mShowOnlyAccountName));
+        }
+
         if (last_update == 0) {
             update_transactions();
         }
@@ -158,6 +190,10 @@ public class TransactionListFragment extends Fragment {
         menuTransactionListFilter = menu.findItem(R.id.menu_transaction_list_filter);
         if ((menuTransactionListFilter == null)) throw new AssertionError();
 
+        if (mShowOnlyAccountName != null) {
+            menuTransactionListFilter.setVisible(false);
+        }
+
         super.onCreateOptionsMenu(menu, inflater);
     }
     private void update_transactions() {
@@ -225,8 +261,9 @@ public class TransactionListFragment extends Fragment {
     }
     public void onClearAccountNameClick(View view) {
         vAccountFilter.setVisibility(View.GONE);
-        menuTransactionListFilter.setVisible(true);
+        if (menuTransactionListFilter != null) menuTransactionListFilter.setVisible(true);
         accNameFilter.setText(null);
+        mShowOnlyAccountName = null;
         model.reloadTransactions(this);
         modelAdapter.resetBoldAccountName();
         modelAdapter.notifyDataSetChanged();
@@ -234,11 +271,13 @@ public class TransactionListFragment extends Fragment {
     }
     public void onShowFilterClick(MenuItem menuItem) {
         vAccountFilter.setVisibility(View.VISIBLE);
-        menuTransactionListFilter.setVisible(false);
-        accNameFilter.requestFocus();
-        InputMethodManager imm =
-                (InputMethodManager) mActivity.getSystemService(INPUT_METHOD_SERVICE);
-        imm.showSoftInput(accNameFilter, 0);
+        if (menuTransactionListFilter != null) menuTransactionListFilter.setVisible(false);
+        if (menuItem != null) {
+            accNameFilter.requestFocus();
+            InputMethodManager imm =
+                    (InputMethodManager) mActivity.getSystemService(INPUT_METHOD_SERVICE);
+            imm.showSoftInput(accNameFilter, 0);
+        }
     }
     public void onStopTransactionRefreshClick(View view) {
         Log.d("interactive", "Cancelling transactions refresh");
index e7c7cfbbd4ea93f54b83f4f333d4aa5cae39a6fa..05813dabae7d9dc4fa5645348ad023712392381a 100644 (file)
@@ -24,7 +24,7 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:gravity="center_vertical"
-    android:minHeight="36dp"
+    android:minHeight="?attr/android:actionBarSize"
     android:orientation="horizontal"
     android:paddingStart="8dp"
     android:paddingEnd="8dp"