From 0361e05ca8551fe117cedda77b87c744a85af712 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Thu, 4 Jan 2024 18:42:07 +0100 Subject: [PATCH] Permanently hide Echo section if it has too few hours --- .../ui/home/sections/EchoSection.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/ui/home/sections/EchoSection.java b/app/src/main/java/de/danoeh/antennapod/ui/home/sections/EchoSection.java index 813ca4d1e..05b716abb 100644 --- a/app/src/main/java/de/danoeh/antennapod/ui/home/sections/EchoSection.java +++ b/app/src/main/java/de/danoeh/antennapod/ui/home/sections/EchoSection.java @@ -34,11 +34,7 @@ public class EchoSection extends Fragment { viewBinding = HomeSectionEchoBinding.inflate(inflater); viewBinding.titleLabel.setText(getString(R.string.antennapod_echo_year, EchoActivity.RELEASE_YEAR)); viewBinding.echoButton.setOnClickListener(v -> startActivity(new Intent(getContext(), EchoActivity.class))); - viewBinding.closeButton.setOnClickListener(v -> { - getContext().getSharedPreferences(HomeFragment.PREF_NAME, Context.MODE_PRIVATE) - .edit().putInt(HomeFragment.PREF_HIDE_ECHO, EchoActivity.RELEASE_YEAR).apply(); - ((MainActivity) getActivity()).loadFragment(HomeFragment.TAG, null); - }); + viewBinding.closeButton.setOnClickListener(v -> hideThisYear()); updateVisibility(); return viewBinding.getRoot(); } @@ -70,8 +66,18 @@ public class EchoSection extends Fragment { }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(totalTime -> viewBinding.getRoot() - .setVisibility((totalTime >= 3600 * 10) ? View.VISIBLE : View.GONE), - Throwable::printStackTrace); + .subscribe(totalTime -> { + boolean shouldShow = (totalTime >= 3600 * 10); + 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); } }