]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java
private field
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / account_summary / AccountSummaryFragment.java
index 94056ab80201c4412d7dea2d8f13677642b18771..224440f15f5dadbf4ca0761b19f3dfceea4c1856 100644 (file)
@@ -37,7 +37,7 @@ import net.ktnx.mobileledger.ui.MobileLedgerListFragment;
 import net.ktnx.mobileledger.ui.activity.MainActivity;
 import net.ktnx.mobileledger.utils.Colors;
 
-import java.util.Observer;
+import org.jetbrains.annotations.NotNull;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
@@ -49,39 +49,19 @@ import static net.ktnx.mobileledger.ui.activity.SettingsActivity.PREF_KEY_SHOW_O
 
 public class AccountSummaryFragment extends MobileLedgerListFragment {
 
-    MenuItem mShowOnlyStarred;
+    private MenuItem mShowOnlyStarred;
     public 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);
         Log.d("flow", "AccountSummaryFragment.onCreate()");
         setHasOptionsMenu(true);
 
-        if (backgroundTaskCountObserver == null) {
-            Log.d("acc", "creating background task count observer");
-            Data.backgroundTaskCount.addObserver(backgroundTaskCountObserver = (o, arg) -> {
-                if (mActivity == null) return;
-                if (swiper == null) return;
-                mActivity.runOnUiThread(() -> {
-                    int cnt = Data.backgroundTaskCount.get();
-                    Log.d("acc", String.format("background task count changed to %d", cnt));
-                    swiper.setRefreshing(cnt > 0);
-                });
-            });
-        }
+        Data.backgroundTasksRunning.observe(this, this::onBackgroundTaskRunningChanged);
     }
-    public void onAttach(Context context) {
+    public void onAttach(@NotNull Context context) {
         super.onAttach(context);
         Log.d("flow", "AccountSummaryFragment.onAttach()");
         mActivity = (MainActivity) context;
@@ -191,7 +171,7 @@ public class AccountSummaryFragment extends MobileLedgerListFragment {
         stopSelection();
     }
     @Override
-    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+    public void onCreateOptionsMenu(@NotNull Menu menu, @NotNull MenuInflater inflater) {
         // Inflate the menu; this adds items to the action bar if it is present.
         inflater.inflate(R.menu.account_summary, menu);
         optMenu = menu;