From: Damyan Ivanov Date: Mon, 31 Dec 2018 19:00:20 +0000 (+0000) Subject: go to transactions for the account when an account is clicked in the account summary X-Git-Tag: v0.3~155 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=abc331c02a265be778538a8416766c5d681a031f;p=mobile-ledger.git go to transactions for the account when an account is clicked in the account summary --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java index b0b67327..3a09f2bb 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java @@ -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 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 accounts = model.getAccounts(mActivity); + if (accounts != null) { + LedgerAccount account = accounts.get(position); + + mActivity.showAccountTransactions(account); + } + } } @Override diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index 52436c4d..ad124667 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -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(); } } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java index 72e07b27..4ea48ab9 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java @@ -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"); diff --git a/app/src/main/res/layout/account_summary_row.xml b/app/src/main/res/layout/account_summary_row.xml index e7c7cfbb..05813dab 100644 --- a/app/src/main/res/layout/account_summary_row.xml +++ b/app/src/main/res/layout/account_summary_row.xml @@ -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"