-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright © 2019 Damyan Ivanov.
~ This file is part of Mobile-Ledger.
~ Mobile-Ledger is free software: you can distribute it and/or modify it
~
~ You should have received a copy of the GNU General Public License
~ along with Mobile-Ledger. If not, see <https://www.gnu.org/licenses/>.
- -->
-
+-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.ktnx.mobileledger">
<uses-permission android:name="android.permission.INTERNET" />
<application
+ android:name=".MobileLedgerApplication"
android:allowBackup="true"
android:fullBackupContent="@xml/backup_descriptor"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
- android:name="net.ktnx.mobileledger.MobileLedgerApplication"
android:theme="@style/AppTheme">
<activity
android:name=".ui.activity.MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
+
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.ColorInt;
+import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
-import android.support.v4.app.FragmentTransaction;
+import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.GravityCompat;
+import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
private View bTransactionListCancelDownload;
private ProgressBar progressBar;
private LinearLayout progressLayout;
+ private SectionsPagerAdapter mSectionsPagerAdapter;
+ private ViewPager mViewPager;
+ @Override
+ protected void onStart() {
+ super.onStart();
+
+ Data.lastUpdateDate.set(null);
+ updateLastUpdateTextFromDB();
+ Date lastUpdate = Data.lastUpdateDate.get();
+
+ long now = new Date().getTime();
+ if ((lastUpdate == null) || (now > (lastUpdate.getTime() + (24 * 3600 * 1000)))) {
+ if (lastUpdate == null) Log.d("db::", "WEB data never fetched. scheduling a fetch");
+ else Log.d("db",
+ String.format("WEB data last fetched at %1.3f and now is %1.3f. re-fetching",
+ lastUpdate.getTime() / 1000f, now / 1000f));
+
+ scheduleTransactionListRetrieval();
+ }
+ }
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
"Can't get hold on the transaction value progress bar layout");
fragmentManager = getSupportFragmentManager();
+ mSectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager);
- onAccountSummaryClicked(null);
+ mViewPager = findViewById(R.id.root_frame);
+ mViewPager.setAdapter(mSectionsPagerAdapter);
+ mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
+ @Override
+ public void onPageSelected(int position) {
+ switch (position) {
+ case 0:
+ markDrawerItemCurrent(R.id.nav_account_summary);
+ break;
+ case 1:
+ markDrawerItemCurrent(R.id.nav_latest_transactions);
+ break;
+ default:
+ Log.e("MainActivity", String.format("Unexpected page index %d", position));
+ }
+
+ super.onPageSelected(position);
+ }
+ });
Data.lastUpdateDate.addObserver(new Observer() {
@Override
}
});
- updateLastUpdateTextFromDB();
- Date lastUpdate = Data.lastUpdateDate.get();
-
- long now = new Date().getTime();
- if ((lastUpdate == null) || (now > (lastUpdate.getTime() + (24 * 3600 * 1000)))) {
- if (lastUpdate == null) Log.d("db", "WEB data never fetched. scheduling a fetch");
- else Log.d("db",
- String.format("WEB data last fetched at %1.3f and now is %1.3f. re-fetching",
- lastUpdate.getTime() / 1000f, now / 1000f));
-
- scheduleTransactionListRetrieval();
- }
-
Data.ledgerTitle.addObserver(new Observer() {
@Override
public void update(Observable o, Object arg) {
runOnUiThread(() -> {
String title = Data.ledgerTitle.get();
- if (title == null)
- toolbar.setSubtitle("");
- else
- toolbar.setSubtitle(title);
+ if (title == null) toolbar.setSubtitle("");
+ else toolbar.setSubtitle(title);
});
}
});
public void onAccountSummaryClicked(View view) {
drawer.closeDrawers();
- resetFragmentBackStack();
-
showAccountSummaryFragment();
}
private void showAccountSummaryFragment() {
- FragmentTransaction ft = fragmentManager.beginTransaction();
- accountSummaryFragment = new AccountSummaryFragment();
- ft.replace(R.id.root_frame, accountSummaryFragment);
- ft.commit();
- currentFragment = accountSummaryFragment;
+ mViewPager.setCurrentItem(0, true);
+// FragmentTransaction ft = fragmentManager.beginTransaction();
+// accountSummaryFragment = new AccountSummaryFragment();
+// ft.replace(R.id.root_frame, accountSummaryFragment);
+// ft.commit();
+// currentFragment = accountSummaryFragment;
}
public void onLatestTransactionsClicked(View view) {
drawer.closeDrawers();
- 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;
+ mViewPager.setCurrentItem(1, true);
+// 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);
progressBar.setIndeterminate(false);
}
}
+ public class SectionsPagerAdapter extends FragmentPagerAdapter {
+
+ public SectionsPagerAdapter(FragmentManager fm) {
+ super(fm);
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ Log.d("main", String.format("Switching to gragment %d", position));
+ switch (position) {
+ case 0:
+ return new AccountSummaryFragment();
+ case 1:
+ return new TransactionListFragment();
+ default:
+ throw new IllegalStateException(
+ String.format("Unexpected fragment index: " + "%d", position));
+ }
+ }
+
+ @Override
+ public int getCount() {
+ return 2;
+ }
+ }
}