import net.ktnx.mobileledger.R;
import net.ktnx.mobileledger.async.RetrieveAccountsTask;
+import net.ktnx.mobileledger.model.Data;
import net.ktnx.mobileledger.model.LedgerAccount;
import net.ktnx.mobileledger.ui.MobileLedgerListFragment;
import net.ktnx.mobileledger.ui.RecyclerItemListener;
import java.lang.ref.WeakReference;
import java.util.Date;
import java.util.List;
+import java.util.Observable;
+import java.util.Observer;
import static net.ktnx.mobileledger.ui.activity.SettingsActivity.PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS;
private AccountSummaryAdapter modelAdapter;
private Menu optMenu;
private FloatingActionButton fab;
+ private Observer backgroundTaskCountObserver;
+ @Override
+ public void onDestroy() {
+ if(backgroundTaskCountObserver!= null) {
+ Log.d("acc", "destroying background task count observer");
+ Data.backgroundTaskCount.deleteObserver(backgroundTaskCountObserver);
+ }
+ super.onDestroy();
+ }
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
+
+ if (backgroundTaskCountObserver == null) {
+ Log.d("acc", "creating background task count observer");
+ Data.backgroundTaskCount.addObserver(backgroundTaskCountObserver = new Observer() {
+ @Override
+ public void update(Observable o, Object arg) {
+ if (mActivity == null) return;
+ if (swiper == null) return;
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ int cnt = Data.backgroundTaskCount.get();
+ Log.d("acc", String.format("background task count changed to %d", cnt));
+ swiper.setRefreshing(cnt > 0);
+ }
+ });
+ }
+ });
+ }
}
public void onAttach(Context context) {
super.onAttach(context);
Log.d("ui", "refreshing accounts via swipe");
update_accounts(true);
});
- prepare_db();
-// update_account_table();
- update_accounts(false);
- }
- private void prepare_db() {
- account_list_last_updated = MLDB.get_option_value(MLDB.OPT_LAST_REFRESH, (long) 0);
+ Data.accounts.addObserver(new Observer() {
+ @Override
+ public void update(Observable o, Object arg) {
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ modelAdapter.notifyDataSetChanged();
+ }
+ });
+ }
+ });
+ update_account_table();
}
private void update_accounts(boolean force) {
private MenuItem menuTransactionListFilter;
private View vAccountFilter;
private AutoCompleteTextView accNameFilter;
+ private Observer backgroundTaskCountObserver;
private static void update(Observable o, Object arg) {
}
+ @Override
+ public void onDestroy() {
+ if (backgroundTaskCountObserver != null) {
+ Log.d("rtl", "destroying background task count observer");
+ Data.backgroundTaskCount.deleteObserver(backgroundTaskCountObserver);
+ }
+ super.onDestroy();
+ }
public void setShowOnlyAccountName(String mShowOnlyAccountName) {
this.mShowOnlyAccountName = mShowOnlyAccountName;
if (modelAdapter != null) {
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
+ if (backgroundTaskCountObserver == null) {
+ Log.d("rtl", "creating background task count observer");
+ Data.backgroundTaskCount.addObserver(backgroundTaskCountObserver = new Observer() {
+ @Override
+ public void update(Observable o, Object arg) {
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ int cnt = Data.backgroundTaskCount.get();
+ Log.d("trl", String.format("background task count changed to %d", cnt));
+ swiper.setRefreshing(cnt > 0);
+ }
+ });
+ }
+ });
+ }
}
@Override
public void onAttach(Context context) {
});
}
});
+
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
String accFilter = hasFilter ? String.valueOf(
((AutoCompleteTextView) act.findViewById(R.id.transaction_filter_account_name))
.getText()) : null;
- updating.set(true);
AsyncTask<String, Void, List<LedgerTransaction>> task = new UTT();
task.execute(accFilter);
}
@Override
protected void onPostExecute(List<LedgerTransaction> list) {
super.onPostExecute(list);
- updating.set(false);
if (list != null) Data.transactions.set(list);
}
- @Override
- protected void onCancelled(List<LedgerTransaction> ledgerTransactions) {
- super.onCancelled(ledgerTransactions);
- updating.set(false);
- }
- @Override
- protected void onCancelled() {
- super.onCancelled();
- updating.set(false);
- }
}
}