X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FMainActivity.java;h=bc164a55333a9d28450a78d346c7720a66e63bee;hb=ab42c559ad21aaf85d977f390e68b638346f51d7;hp=6a290685636cbf04bb730638d7e5b2db3e545fb2;hpb=dbbdc8443ad87659433bdb9239cfb3e2732ef2cf;p=mobile-ledger.git 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 6a290685..bc164a55 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 @@ -22,7 +22,6 @@ import android.content.pm.PackageInfo; import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutManager; import android.content.res.ColorStateList; -import android.content.res.Resources; import android.graphics.Color; import android.graphics.drawable.Icon; import android.os.AsyncTask; @@ -143,7 +142,8 @@ public class MainActivity extends ProfileThemedActivity { barDrawerToggle = null; if (mViewPager != null) mViewPager.removeOnPageChangeListener(pageChangeListener); pageChangeListener = null; - if (mProfileListAdapter != null) mProfileListAdapter.deleteEditingProfilesObserver(editingProfilesObserver); + if (mProfileListAdapter != null) + mProfileListAdapter.deleteEditingProfilesObserver(editingProfilesObserver); editingProfilesObserver = null; super.onDestroy(); } @@ -189,8 +189,8 @@ public class MainActivity extends ProfileThemedActivity { } if (barDrawerToggle == null) { - barDrawerToggle = new ActionBarDrawerToggle(this, drawer, mToolbar, R.string.navigation_drawer_open, - R.string.navigation_drawer_close); + barDrawerToggle = new ActionBarDrawerToggle(this, drawer, mToolbar, + R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(barDrawerToggle); } barDrawerToggle.syncState(); @@ -227,7 +227,8 @@ public class MainActivity extends ProfileThemedActivity { markDrawerItemCurrent(R.id.nav_latest_transactions); break; default: - Log.e("MainActivity", String.format("Unexpected page index %d", position)); + Log.e("MainActivity", + String.format("Unexpected page index %d", position)); } super.onPageSelected(position); @@ -311,12 +312,18 @@ public class MainActivity extends ProfileThemedActivity { drawer.addDrawerListener(drawerListener); } + findViewById(R.id.nav_profile_list_head_layout) + .setOnClickListener(this::navProfilesHeadClicked); + findViewById(R.id.nav_profiles_label).setOnClickListener(this::navProfilesHeadClicked); setupProfile(); onProfileChanged(null); updateLastUpdateTextFromDB(); - Date lastUpdate = Data.lastUpdateDate.get(); + scheduleDataRetrievalIfStale(); + } + private void scheduleDataRetrievalIfStale() { + 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"); @@ -328,7 +335,8 @@ public class MainActivity extends ProfileThemedActivity { } } private void createShortcuts() { - Resources rm = getResources(); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return; + List shortcuts = new ArrayList<>(); try (LockHolder lh = Data.profiles.lockForReading()) { for (int i = 0; i < Data.profiles.size(); i++) { @@ -340,8 +348,7 @@ public class MainActivity extends ProfileThemedActivity { .setIcon(Icon.createWithResource(this, R.drawable.svg_thick_plus_white)) .setIntent(new Intent(Intent.ACTION_VIEW, null, this, NewTransactionActivity.class).putExtra("profile_uuid", p.getUuid())) - .setRank(i) - .build(); + .setRank(i).build(); shortcuts.add(si); } } @@ -363,6 +370,11 @@ public class MainActivity extends ProfileThemedActivity { MobileLedgerProfile profile = Data.profile.get(); MainActivity.this.runOnUiThread(() -> { + boolean haveProfile = profile != null; + findViewById(R.id.no_profiles_layout).setVisibility(haveProfile ? View.GONE : View.VISIBLE); + findViewById(R.id.pager_layout) + .setVisibility(haveProfile ? View.VISIBLE : View.VISIBLE); + Data.transactions.clear(); Log.d("transactions", "requesting list reload"); TransactionListViewModel.scheduleTransactionListReload(); @@ -415,6 +427,10 @@ public class MainActivity extends ProfileThemedActivity { fab.hide(); } } + + updateLastUpdateTextFromDB(); + + scheduleDataRetrievalIfStale(); }); } private void updateLastUpdateDisplay() {