diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/build.gradle | 1 | ||||
-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 | ||||
-rw-r--r-- | app/src/main/res/layout/home_section_echo.xml | 91 |
4 files changed, 179 insertions, 1 deletions
diff --git a/app/build.gradle b/app/build.gradle index b26dc2fb0..64bc442a8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -89,6 +89,7 @@ dependencies { implementation project(':storage:preferences') implementation project(':ui:app-start-intent') implementation project(':ui:common') + implementation project(':ui:echo') implementation project(':ui:glide') implementation project(':ui:i18n') implementation project(':ui:statistics') 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); + } +} diff --git a/app/src/main/res/layout/home_section_echo.xml b/app/src/main/res/layout/home_section_echo.xml new file mode 100644 index 000000000..f5fdaa46f --- /dev/null +++ b/app/src/main/res/layout/home_section_echo.xml @@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingHorizontal="16dp"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal"> + + <TextView + android:layout_width="0dp" + android:layout_height="wrap_content" + android:textColor="?android:attr/textColorPrimary" + android:textSize="18sp" + android:layout_marginVertical="8dp" + android:accessibilityHeading="true" + android:layout_weight="1" + android:text="@string/echo_home_header" /> + + <ImageView + android:id="@+id/closeButton" + android:layout_width="48dp" + android:layout_height="48dp" + android:padding="16dp" + android:background="?attr/selectableItemBackgroundBorderless" + android:contentDescription="@string/close_label" + android:layout_gravity="center_vertical" + android:src="@drawable/ic_cancel" /> + + </LinearLayout> + + <androidx.cardview.widget.CardView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center" + android:orientation="vertical" + app:cardCornerRadius="8dp" + app:cardElevation="0dp"> + + <LinearLayout + android:id="@+id/echoButton" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@drawable/bg_blue_gradient" + android:orientation="vertical" + android:padding="16dp" + android:foreground="?attr/selectableItemBackground"> + + <TextView + android:id="@+id/titleLabel" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginBottom="8dp" + android:textColor="#fff" + android:text="@string/antennapod_echo_year" + android:textFontWeight="500" + style="@style/TextAppearance.Material3.TitleLarge" /> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal"> + + <TextView + android:layout_width="0dp" + android:layout_height="wrap_content" + android:textColor="#fff" + android:layout_weight="1" + android:text="@string/echo_home_subtitle" + style="@style/TextAppearance.Material3.BodyMedium" /> + + <ImageView + android:layout_width="24dp" + android:layout_height="24dp" + android:layout_gravity="bottom" + android:textColor="#fff" + android:importantForAccessibility="no" + android:src="@drawable/ic_arrow_right_white" /> + + </LinearLayout> + + </LinearLayout> + + </androidx.cardview.widget.CardView> + +</LinearLayout> |