import net.ktnx.mobileledger.model.Data;
import net.ktnx.mobileledger.model.LedgerAccount;
import net.ktnx.mobileledger.model.MobileLedgerProfile;
+import net.ktnx.mobileledger.ui.account_summary.AccountSummaryAdapter;
import net.ktnx.mobileledger.ui.account_summary.AccountSummaryFragment;
import net.ktnx.mobileledger.ui.profiles.ProfileDetailFragment;
import net.ktnx.mobileledger.ui.profiles.ProfilesRecyclerViewAdapter;
import androidx.viewpager.widget.ViewPager;
public class MainActivity extends ProfileThemedActivity {
- private static final String STATE_CURRENT_PAGE = "current_page";
- private static final String BUNDLE_SAVED_STATE = "bundle_savedState";
+ public static final String STATE_CURRENT_PAGE = "current_page";
+ public static final String BUNDLE_SAVED_STATE = "bundle_savedState";
+ public static final String STATE_ACC_FILTER = "account_filter";
public AccountSummaryFragment mAccountSummaryFragment;
DrawerLayout drawer;
private LinearLayout profileListContainer;
private boolean profileModificationEnabled = false;
private boolean profileListExpanded = false;
private ProfilesRecyclerViewAdapter mProfileListAdapter;
+ private int mCurrentPage;
+ private String mAccountFilter;
+ private boolean mBackMeansToAccountList = false;
@Override
protected void onStart() {
super.onStart();
scheduleTransactionListRetrieval();
}
+
+ mViewPager.setCurrentItem(mCurrentPage, false);
+ if (mAccountFilter != null) showTransactionsFragment(mAccountFilter);
+
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(STATE_CURRENT_PAGE, mViewPager.getCurrentItem());
+ if (TransactionListFragment.accountFilter.get() != null)
+ outState.putString(STATE_ACC_FILTER, TransactionListFragment.accountFilter.get());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
fab.hide();
}
+ int old_index = -1;
+ int new_index = -1;
+ if (arg != null) {
+ MobileLedgerProfile old = (MobileLedgerProfile) arg;
+ old_index = Data.getProfileIndex(old);
+ new_index = Data.getProfileIndex(profile);
+ }
+
+ if ((old_index != -1) && (new_index != -1)) {
+ mProfileListAdapter.notifyItemChanged(old_index);
+ mProfileListAdapter.notifyItemChanged(new_index);
+ }
+ else mProfileListAdapter.notifyDataSetChanged();
+
int newProfileTheme = profile.getThemeId();
if (newProfileTheme != Colors.profileThemeId) {
Log.d("profiles", String.format("profile theme %d → %d", Colors.profileThemeId,
}
});
+ mCurrentPage = 0;
if (savedInstanceState != null) {
int currentPage = savedInstanceState.getInt(STATE_CURRENT_PAGE, -1);
if (currentPage != -1) {
- mViewPager.setCurrentItem(currentPage, false);
+ mCurrentPage = currentPage;
}
+ mAccountFilter = savedInstanceState.getString(STATE_ACC_FILTER, null);
}
Data.lastUpdateDate.addObserver((o, arg) -> {
});
}
private void updateLastUpdateDisplay() {
+ LinearLayout l = findViewById(R.id.transactions_last_update_layout);
TextView v = findViewById(R.id.transactions_last_update);
Date date = Data.lastUpdateDate.get();
if (date == null) {
- v.setText(R.string.transaction_last_update_never);
+ l.setVisibility(View.INVISIBLE);
Log.d("main", "no last update date :(");
}
else {
final String text = DateFormat.getDateTimeInstance().format(date);
v.setText(text);
+ l.setVisibility(View.VISIBLE);
Log.d("main", String.format("Date formatted: %s", text));
}
}
// currentFragment = transactionListFragment;
}
public void showAccountTransactions(LedgerAccount account) {
+ mBackMeansToAccountList = true;
showTransactionsFragment(account);
}
@Override
drawer.closeDrawer(GravityCompat.START);
}
else {
- Log.d("fragments",
- String.format("manager stack: %d", fragmentManager.getBackStackEntryCount()));
+ if (mBackMeansToAccountList && (mViewPager.getCurrentItem() == 1)) {
+ TransactionListFragment.accountFilter.set(null);
+ showAccountSummaryFragment();
+ mBackMeansToAccountList = false;
+ }
+ else {
+ Log.d("fragments", String.format("manager stack: %d",
+ fragmentManager.getBackStackEntryCount()));
- super.onBackPressed();
+ super.onBackPressed();
+ }
}
}
public void updateLastUpdateTextFromDB() {