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;
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;
}
});
swiper = mActivity.findViewById(R.id.account_swiper);
- Colors.themeWatch.addObserver((o, arg) -> swiper.setColorSchemeColors(Colors.primary));
- swiper.setColorSchemeColors(Colors.primary);
+ Colors.themeWatch.observe(this, this::themeChanged);
swiper.setOnRefreshListener(() -> {
Log.d("ui", "refreshing accounts via swipe");
mActivity.scheduleTransactionListRetrieval();
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;