summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
ab1300b)
re-inventing a pissibly brooken wheel doesn't sound like a good idea
import java.util.ArrayList;
import java.util.Date;
import java.util.ArrayList;
import java.util.Date;
+import androidx.lifecycle.MutableLiveData;
+
public final class Data {
public static ObservableList<TransactionListItem> transactions = new ObservableList<>(new ArrayList<>());
public static ObservableList<LedgerAccount> accounts = new ObservableList<>(new ArrayList<>());
public static ObservableAtomicInteger backgroundTaskCount = new ObservableAtomicInteger(0);
public final class Data {
public static ObservableList<TransactionListItem> transactions = new ObservableList<>(new ArrayList<>());
public static ObservableList<LedgerAccount> accounts = new ObservableList<>(new ArrayList<>());
public static ObservableAtomicInteger backgroundTaskCount = new ObservableAtomicInteger(0);
- public static ObservableValue<Date> lastUpdateDate = new ObservableValue<>();
+ public static MutableLiveData<Date> lastUpdateDate = new MutableLiveData<>();
public static ObservableValue<MobileLedgerProfile> profile = new ObservableValue<>();
public static ObservableList<MobileLedgerProfile> profiles =
new ObservableList<>(new ArrayList<>());
public static ObservableValue<MobileLedgerProfile> profile = new ObservableValue<>();
public static ObservableList<MobileLedgerProfile> profiles =
new ObservableList<>(new ArrayList<>());
Log.d("db", "Updating transaction value stamp");
Date now = new Date();
setLongOption(MLDB.OPT_LAST_SCRAPE, now.getTime());
Log.d("db", "Updating transaction value stamp");
Date now = new Date();
setLongOption(MLDB.OPT_LAST_SCRAPE, now.getTime());
- Data.lastUpdateDate.set(now);
+ Data.lastUpdateDate.postValue(now);
}
public List<LedgerAccount> loadChildAccountsOf(LedgerAccount acc) {
List<LedgerAccount> result = new ArrayList<>();
}
public List<LedgerAccount> loadChildAccountsOf(LedgerAccount acc) {
List<LedgerAccount> result = new ArrayList<>();
private boolean mBackMeansToAccountList = false;
private Observer profileObserver;
private Observer profilesObserver;
private boolean mBackMeansToAccountList = false;
private Observer profileObserver;
private Observer profilesObserver;
- private Observer lastUpdateDateObserver;
private Toolbar mToolbar;
private DrawerLayout.SimpleDrawerListener drawerListener;
private ActionBarDrawerToggle barDrawerToggle;
private Toolbar mToolbar;
private DrawerLayout.SimpleDrawerListener drawerListener;
private ActionBarDrawerToggle barDrawerToggle;
profileObserver = null;
Data.profiles.deleteObserver(profilesObserver);
profilesObserver = null;
profileObserver = null;
Data.profiles.deleteObserver(profilesObserver);
profilesObserver = null;
- Data.lastUpdateDate.deleteObserver(lastUpdateDateObserver);
- lastUpdateDateObserver = null;
RecyclerView root = findViewById(R.id.nav_profile_list);
if (root != null) root.setAdapter(null);
if (drawer != null) drawer.removeDrawerListener(drawerListener);
RecyclerView root = findViewById(R.id.nav_profile_list);
if (root != null) root.setAdapter(null);
if (drawer != null) drawer.removeDrawerListener(drawerListener);
}
else mAccountFilter = null;
}
else mAccountFilter = null;
- if (lastUpdateDateObserver == null) {
- lastUpdateDateObserver = (o, arg) -> {
- Log.d("main", "lastUpdateDate changed");
- runOnUiThread(this::updateLastUpdateDisplay);
- };
- Data.lastUpdateDate.addObserver(lastUpdateDateObserver);
- }
-
- updateLastUpdateDisplay();
+ Data.lastUpdateDate.observe(this, this::updateLastUpdateDisplay);
findViewById(R.id.btn_no_profiles_add)
.setOnClickListener(v -> startEditProfileActivity(null));
findViewById(R.id.btn_no_profiles_add)
.setOnClickListener(v -> startEditProfileActivity(null));
onProfileChanged(null);
updateLastUpdateTextFromDB();
onProfileChanged(null);
updateLastUpdateTextFromDB();
-
- scheduleDataRetrievalIfStale();
- private void scheduleDataRetrievalIfStale() {
- Date lastUpdate = Data.lastUpdateDate.get();
+ private void scheduleDataRetrievalIfStale(Date lastUpdate) {
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");
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");
}
updateLastUpdateTextFromDB();
}
updateLastUpdateTextFromDB();
-
- scheduleDataRetrievalIfStale();
- private void updateLastUpdateDisplay() {
+ private void updateLastUpdateDisplay(Date newValue) {
LinearLayout l = findViewById(R.id.transactions_last_update_layout);
TextView v = findViewById(R.id.transactions_last_update);
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) {
+ if (newValue == null) {
l.setVisibility(View.INVISIBLE);
Log.d("main", "no last update date :(");
}
else {
l.setVisibility(View.INVISIBLE);
Log.d("main", "no last update date :(");
}
else {
- final String text = DateFormat.getDateTimeInstance().format(date);
+ final String text = DateFormat.getDateTimeInstance().format(newValue);
v.setText(text);
l.setVisibility(View.VISIBLE);
Log.d("main", String.format("Date formatted: %s", text));
}
v.setText(text);
l.setVisibility(View.VISIBLE);
Log.d("main", String.format("Date formatted: %s", text));
}
+
+ scheduleDataRetrievalIfStale(newValue);
}
@Override
public void finish() {
}
@Override
public void finish() {
}
}
public void updateLastUpdateTextFromDB() {
}
}
public void updateLastUpdateTextFromDB() {
- {
- final MobileLedgerProfile profile = Data.profile.get();
- long last_update =
- (profile != null) ? profile.getLongOption(MLDB.OPT_LAST_SCRAPE, 0L) : 0;
+ final MobileLedgerProfile profile = Data.profile.get();
+ long last_update = (profile != null) ? profile.getLongOption(MLDB.OPT_LAST_SCRAPE, 0L) : 0;
- Log.d("transactions", String.format("Last update = %d", last_update));
- if (last_update == 0) {
- Data.lastUpdateDate.set(null);
- }
- else {
- Data.lastUpdateDate.set(new Date(last_update));
- }
+ Log.d("transactions", String.format("Last update = %d", last_update));
+ if (last_update == 0) {
+ Data.lastUpdateDate.postValue(null);
+ }
+ else {
+ Data.lastUpdateDate.postValue(new Date(last_update));
}
}
public void scheduleTransactionListRetrieval() {
}
}
public void scheduleTransactionListRetrieval() {