Permanently hide Echo section if it has too few hours

This commit is contained in:
ByteHamster 2024-01-04 18:42:07 +01:00
parent 9eac993e45
commit 0361e05ca8
1 changed files with 14 additions and 8 deletions

View File

@ -34,11 +34,7 @@ public class EchoSection extends Fragment {
viewBinding = HomeSectionEchoBinding.inflate(inflater); viewBinding = HomeSectionEchoBinding.inflate(inflater);
viewBinding.titleLabel.setText(getString(R.string.antennapod_echo_year, EchoActivity.RELEASE_YEAR)); viewBinding.titleLabel.setText(getString(R.string.antennapod_echo_year, EchoActivity.RELEASE_YEAR));
viewBinding.echoButton.setOnClickListener(v -> startActivity(new Intent(getContext(), EchoActivity.class))); viewBinding.echoButton.setOnClickListener(v -> startActivity(new Intent(getContext(), EchoActivity.class)));
viewBinding.closeButton.setOnClickListener(v -> { viewBinding.closeButton.setOnClickListener(v -> hideThisYear());
getContext().getSharedPreferences(HomeFragment.PREF_NAME, Context.MODE_PRIVATE)
.edit().putInt(HomeFragment.PREF_HIDE_ECHO, EchoActivity.RELEASE_YEAR).apply();
((MainActivity) getActivity()).loadFragment(HomeFragment.TAG, null);
});
updateVisibility(); updateVisibility();
return viewBinding.getRoot(); return viewBinding.getRoot();
} }
@ -70,8 +66,18 @@ public class EchoSection extends Fragment {
}) })
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(totalTime -> viewBinding.getRoot() .subscribe(totalTime -> {
.setVisibility((totalTime >= 3600 * 10) ? View.VISIBLE : View.GONE), boolean shouldShow = (totalTime >= 3600 * 10);
Throwable::printStackTrace); viewBinding.getRoot().setVisibility(shouldShow ? View.VISIBLE : View.GONE);
if (!shouldShow) {
hideThisYear();
}
}, Throwable::printStackTrace);
}
void hideThisYear() {
getContext().getSharedPreferences(HomeFragment.PREF_NAME, Context.MODE_PRIVATE)
.edit().putInt(HomeFragment.PREF_HIDE_ECHO, EchoActivity.RELEASE_YEAR).apply();
((MainActivity) getActivity()).loadFragment(HomeFragment.TAG, null);
} }
} }