From 24f09aa7ceb9b19e69a49d6e195d3b7d1d7774c9 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sun, 15 Dec 2024 11:45:28 +0100 Subject: [PATCH] Add menu on statistics screen to bring back Echo (#7555) --- .../de/danoeh/antennapod/ui/screen/home/HomeFragment.java | 6 +----- .../main/java/de/danoeh/antennapod/ui/echo/EchoConfig.java | 6 ++++++ ui/echo/src/main/res/values/echo-strings.xml | 1 - .../antennapod/ui/statistics/StatisticsFragment.java | 7 ++++--- ui/statistics/src/main/res/menu/statistics.xml | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/ui/screen/home/HomeFragment.java b/app/src/main/java/de/danoeh/antennapod/ui/screen/home/HomeFragment.java index be0793290..bb3f03dec 100644 --- a/app/src/main/java/de/danoeh/antennapod/ui/screen/home/HomeFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/ui/screen/home/HomeFragment.java @@ -39,7 +39,6 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import java.util.Calendar; import java.util.List; /** @@ -82,10 +81,7 @@ public class HomeFragment extends Fragment implements Toolbar.OnMenuItemClickLis viewBinding.homeContainer.removeAllViews(); SharedPreferences prefs = getContext().getSharedPreferences(HomeFragment.PREF_NAME, Context.MODE_PRIVATE); - if (Calendar.getInstance().get(Calendar.YEAR) == EchoConfig.RELEASE_YEAR - && Calendar.getInstance().get(Calendar.MONTH) == Calendar.DECEMBER - && Calendar.getInstance().get(Calendar.DAY_OF_MONTH) >= 10 - && prefs.getInt(PREF_HIDE_ECHO, 0) != EchoConfig.RELEASE_YEAR) { + if (EchoConfig.isCurrentlyVisible() && prefs.getInt(PREF_HIDE_ECHO, 0) != EchoConfig.RELEASE_YEAR) { addSection(new EchoSection()); } diff --git a/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/EchoConfig.java b/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/EchoConfig.java index d7bca4c9c..529419367 100644 --- a/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/EchoConfig.java +++ b/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/EchoConfig.java @@ -16,4 +16,10 @@ public class EchoConfig { date.set(Calendar.YEAR, RELEASE_YEAR); return date.getTimeInMillis(); } + + public static boolean isCurrentlyVisible() { + return Calendar.getInstance().get(Calendar.YEAR) == RELEASE_YEAR + && Calendar.getInstance().get(Calendar.MONTH) == Calendar.DECEMBER + && Calendar.getInstance().get(Calendar.DAY_OF_MONTH) >= 10; + } } diff --git a/ui/echo/src/main/res/values/echo-strings.xml b/ui/echo/src/main/res/values/echo-strings.xml index 161fe363e..09a64f1e4 100644 --- a/ui/echo/src/main/res/values/echo-strings.xml +++ b/ui/echo/src/main/res/values/echo-strings.xml @@ -1,6 +1,5 @@ - [Debug] Echo Review the year Your top podcasts and stats from the past year. Exclusively on your phone. diff --git a/ui/statistics/src/main/java/de/danoeh/antennapod/ui/statistics/StatisticsFragment.java b/ui/statistics/src/main/java/de/danoeh/antennapod/ui/statistics/StatisticsFragment.java index 74a0eaa5f..ef3cc4ef5 100644 --- a/ui/statistics/src/main/java/de/danoeh/antennapod/ui/statistics/StatisticsFragment.java +++ b/ui/statistics/src/main/java/de/danoeh/antennapod/ui/statistics/StatisticsFragment.java @@ -23,6 +23,7 @@ import de.danoeh.antennapod.storage.database.DBWriter; import de.danoeh.antennapod.event.StatisticsEvent; import de.danoeh.antennapod.ui.common.PagedToolbarFragment; import de.danoeh.antennapod.ui.echo.EchoActivity; +import de.danoeh.antennapod.ui.echo.EchoConfig; import de.danoeh.antennapod.ui.statistics.downloads.DownloadStatisticsFragment; import de.danoeh.antennapod.ui.statistics.subscriptions.SubscriptionStatisticsFragment; import de.danoeh.antennapod.ui.statistics.years.YearsStatisticsFragment; @@ -63,8 +64,8 @@ public class StatisticsFragment extends PagedToolbarFragment { toolbar = rootView.findViewById(R.id.toolbar); toolbar.setTitle(getString(R.string.statistics_label)); toolbar.inflateMenu(R.menu.statistics); - if (BuildConfig.DEBUG) { - toolbar.getMenu().findItem(R.id.debug_echo).setVisible(true); + if (BuildConfig.DEBUG || EchoConfig.isCurrentlyVisible()) { + toolbar.getMenu().findItem(R.id.show_echo).setVisible(true); } toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack()); viewPager.setAdapter(new StatisticsPagerAdapter(this)); @@ -94,7 +95,7 @@ public class StatisticsFragment extends PagedToolbarFragment { if (item.getItemId() == R.id.statistics_reset) { confirmResetStatistics(); return true; - } else if (item.getItemId() == R.id.debug_echo) { + } else if (item.getItemId() == R.id.show_echo) { startActivity(new Intent(getContext(), EchoActivity.class)); } return super.onOptionsItemSelected(item); diff --git a/ui/statistics/src/main/res/menu/statistics.xml b/ui/statistics/src/main/res/menu/statistics.xml index 9720e6880..00f6362cc 100644 --- a/ui/statistics/src/main/res/menu/statistics.xml +++ b/ui/statistics/src/main/res/menu/statistics.xml @@ -14,8 +14,8 @@ custom:showAsAction="ifRoom" />