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 {
private AccountSummaryFragment accountSummaryFragment;
private TransactionListFragment transactionListFragment;
private Fragment currentFragment = null;
+ private FragmentManager fragmentManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
e.printStackTrace();
}
+ fragmentManager = getSupportFragmentManager();
+
onAccountSummaryClicked(null);
}
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()));
}
}
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() {
drawer.closeDrawer(GravityCompat.START);
}
else {
+ Log.d("fragments",
+ String.format("manager stack: %d", fragmentManager.getBackStackEntryCount()));
+
super.onBackPressed();
}
}
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;
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;
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);
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);
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);
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();
}
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() {
}
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();
}
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");