- private void setupProfile() {
- String profileUUID = MLDB.getOption(MLDB.OPT_PROFILE_UUID, null);
- MobileLedgerProfile profile;
-
- if (profileUUID == null) {
- if (Data.profiles.isEmpty()) {
- Data.profiles.setList(MobileLedgerProfile.createInitialProfileList());
- profile = Data.profiles.get(0);
-
- SharedPreferences backend = getSharedPreferences("backend", MODE_PRIVATE);
- Log.d("profiles", "Migrating from preferences to profiles");
- // migration to multiple profiles
- if (profile.getUrl().isEmpty()) {
- // no legacy config
- Intent intent = new Intent(this, ProfileListActivity.class);
- startActivity(intent);
- }
- profile.setUrl(backend.getString("backend_url", ""));
- profile.setAuthEnabled(backend.getBoolean("backend_use_http_auth", false));
- profile.setAuthUserName(backend.getString("backend_auth_user", null));
- profile.setAuthPassword(backend.getString("backend_auth_password", null));
- profile.storeInDB();
- SharedPreferences.Editor editor = backend.edit();
- editor.clear();
- editor.apply();
- }
- else profile = Data.profiles.get(0);
+ private void scheduleDataRetrievalIfStale(long lastUpdate) {
+ long now = new Date().getTime();
+ if ((lastUpdate == 0) || (now > (lastUpdate + (24 * 3600 * 1000)))) {
+ if (lastUpdate == 0)
+ Logger.debug("db::", "WEB data never fetched. scheduling a fetch");
+ else
+ Logger.debug("db", String.format(Locale.ENGLISH,
+ "WEB data last fetched at %1.3f and now is %1.3f. re-fetching",
+ lastUpdate / 1000f, now / 1000f));
+
+ mainModel.scheduleTransactionListRetrieval();
+ }
+ }
+ private void createShortcuts(List<MobileLedgerProfile> list) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1)
+ return;
+
+ ShortcutManager sm = getSystemService(ShortcutManager.class);
+ List<ShortcutInfo> shortcuts = new ArrayList<>();
+ int i = 0;
+ for (MobileLedgerProfile p : list) {
+ if (shortcuts.size() >= sm.getMaxShortcutCountPerActivity())
+ break;
+
+ if (!p.isPostingPermitted())
+ continue;
+
+ final ShortcutInfo.Builder builder =
+ new ShortcutInfo.Builder(this, "new_transaction_" + p.getUuid());
+ ShortcutInfo si = builder.setShortLabel(p.getName())
+ .setIcon(Icon.createWithResource(this,
+ R.drawable.thick_plus_icon))
+ .setIntent(new Intent(Intent.ACTION_VIEW, null, this,
+ NewTransactionActivity.class).putExtra("profile_uuid",
+ p.getUuid()))
+ .setRank(i)
+ .build();
+ shortcuts.add(si);
+ i++;
+ }
+ sm.setDynamicShortcuts(shortcuts);
+ }
+ private void onProfileListChanged(List<MobileLedgerProfile> newList) {
+ if ((newList == null) || newList.isEmpty()) {
+ b.noProfilesLayout.setVisibility(View.VISIBLE);
+ b.mainAppLayout.setVisibility(View.GONE);
+ return;
+ }
+
+ b.mainAppLayout.setVisibility(View.VISIBLE);
+ b.noProfilesLayout.setVisibility(View.GONE);
+
+ b.navProfileList.setMinimumHeight(
+ (int) (getResources().getDimension(R.dimen.thumb_row_height) * newList.size()));
+
+ Logger.debug("profiles", "profile list changed");
+ mProfileListAdapter.notifyDataSetChanged();
+
+ createShortcuts(newList);
+ }
+ /**
+ * called when the current profile has changed
+ */
+ private void onProfileChanged(MobileLedgerProfile profile) {
+ if (this.profile == null) {
+ if (profile == null)
+ return;