diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2023-11-28 20:26:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-28 20:26:29 +0100 |
commit | ee554d0306a06903fa88be6c5af7954315685ed6 (patch) | |
tree | 322325e0a3929b4a6abacea0ff221c3bff24f05c /app/src/main/java/de/danoeh | |
parent | 637230e382a67ae8a0c7d889a773edb64bb74181 (diff) | |
download | AntennaPod-ee554d0306a06903fa88be6c5af7954315685ed6.zip |
AntennaPod Echo (#6780)
Diffstat (limited to 'app/src/main/java/de/danoeh')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/ui/home/HomeFragment.java | 11 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/ui/home/sections/EchoSection.java | 77 |
2 files changed, 87 insertions, 1 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/ui/home/HomeFragment.java b/app/src/main/java/de/danoeh/antennapod/ui/home/HomeFragment.java index 21b36bc49..fc925aa03 100644 --- a/app/src/main/java/de/danoeh/antennapod/ui/home/HomeFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/ui/home/HomeFragment.java @@ -21,12 +21,14 @@ import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentContainerView; +import de.danoeh.antennapod.ui.home.sections.EchoSection; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; import java.util.List; import de.danoeh.antennapod.R; @@ -60,6 +62,7 @@ public class HomeFragment extends Fragment implements Toolbar.OnMenuItemClickLis public static final String PREF_NAME = "PrefHomeFragment"; public static final String PREF_HIDDEN_SECTIONS = "PrefHomeSectionsString"; public static final String PREF_DISABLE_NOTIFICATION_PERMISSION_NAG = "DisableNotificationPermissionNag"; + public static final String PREF_HIDE_ECHO = "HideEcho"; private static final String KEY_UP_ARROW = "up_arrow"; private boolean displayUpArrow; @@ -94,13 +97,19 @@ public class HomeFragment extends Fragment implements Toolbar.OnMenuItemClickLis private void populateSectionList() { viewBinding.homeContainer.removeAllViews(); + SharedPreferences prefs = getContext().getSharedPreferences(HomeFragment.PREF_NAME, Context.MODE_PRIVATE); if (Build.VERSION.SDK_INT >= 33 && ContextCompat.checkSelfPermission(getContext(), Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { - SharedPreferences prefs = getContext().getSharedPreferences(HomeFragment.PREF_NAME, Context.MODE_PRIVATE); if (!prefs.getBoolean(HomeFragment.PREF_DISABLE_NOTIFICATION_PERMISSION_NAG, false)) { addSection(new AllowNotificationsSection()); } } + if (Calendar.getInstance().get(Calendar.MONTH) == Calendar.DECEMBER + && Calendar.getInstance().get(Calendar.YEAR) == 2023 + && Calendar.getInstance().get(Calendar.DAY_OF_MONTH) >= 10 + && prefs.getInt(PREF_HIDE_ECHO, 0) != 2023) { + addSection(new EchoSection()); + } List<String> hiddenSections = getHiddenSections(getContext()); String[] sectionTags = getResources().getStringArray(R.array.home_section_tags); 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 new file mode 100644 index 000000000..7261c6be4 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/ui/home/sections/EchoSection.java @@ -0,0 +1,77 @@ +package de.danoeh.antennapod.ui.home.sections; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.core.storage.DBReader; +import de.danoeh.antennapod.core.storage.StatisticsItem; +import de.danoeh.antennapod.databinding.HomeSectionEchoBinding; +import de.danoeh.antennapod.ui.echo.EchoActivity; +import de.danoeh.antennapod.ui.home.HomeFragment; +import io.reactivex.Observable; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; + +import java.util.Calendar; + +public class EchoSection extends Fragment { + private HomeSectionEchoBinding viewBinding; + private Disposable disposable; + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, + @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + viewBinding = HomeSectionEchoBinding.inflate(inflater); + viewBinding.titleLabel.setText(getString(R.string.antennapod_echo_year, 2023)); + 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, 2023).apply(); + ((MainActivity) getActivity()).loadFragment(HomeFragment.TAG, null); + }); + updateVisibility(); + return viewBinding.getRoot(); + } + + private long jan1() { + Calendar date = Calendar.getInstance(); + date.set(Calendar.HOUR_OF_DAY, 0); + date.set(Calendar.MINUTE, 0); + date.set(Calendar.SECOND, 0); + date.set(Calendar.MILLISECOND, 0); + date.set(Calendar.DAY_OF_MONTH, 1); + date.set(Calendar.MONTH, 0); + date.set(Calendar.YEAR, 2023); + return date.getTimeInMillis(); + } + + private void updateVisibility() { + if (disposable != null) { + disposable.dispose(); + } + disposable = Observable.fromCallable( + () -> { + DBReader.StatisticsResult statisticsResult = DBReader.getStatistics(false, jan1(), Long.MAX_VALUE); + long totalTime = 0; + for (StatisticsItem feedTime : statisticsResult.feedTime) { + totalTime += feedTime.timePlayed; + } + return totalTime; + }) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(totalTime -> viewBinding.getRoot() + .setVisibility((totalTime >= 3600 * 10) ? View.VISIBLE : View.GONE), + Throwable::printStackTrace); + } +} |