summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflofriday <flohacksfriday@gmail.com>2024-07-10 21:30:32 +0200
committerGitHub <noreply@github.com>2024-07-10 21:30:32 +0200
commit17b713e10cae24b883fd9b57496e239d1d911b05 (patch)
treecba82cbe6d9113caa5a68d5866968ca0b279c21d
parentff5a2c78d81ff61679161a766cb457d749478b3b (diff)
downloadAntennaPod-17b713e10cae24b883fd9b57496e239d1d911b05.zip
Improve collapsing toolbar state (#7277)
First this commit improves the threshold at which the icon color is changed. We now ask the collapsing toolbar at which size it will be collapsed instead of guessing. Second, this commit also sets the appbar title (when collapsed) to the podcast name in the podcast episode view.
-rw-r--r--app/src/main/java/de/danoeh/antennapod/ui/screen/feed/FeedInfoFragment.java1
-rw-r--r--app/src/main/java/de/danoeh/antennapod/ui/screen/feed/FeedItemlistFragment.java11
-rw-r--r--app/src/main/java/de/danoeh/antennapod/ui/screen/feed/ToolbarIconTintManager.java27
-rw-r--r--app/src/main/res/layout/feed_item_list_fragment.xml1
-rw-r--r--ui/common/src/main/java/de/danoeh/antennapod/ui/common/OnCollapseChangeListener.java25
5 files changed, 44 insertions, 21 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/FeedInfoFragment.java b/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/FeedInfoFragment.java
index 56164a819..6169e3888 100644
--- a/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/FeedInfoFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/FeedInfoFragment.java
@@ -105,7 +105,6 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu
ToolbarIconTintManager iconTintManager =
new ToolbarIconTintManager(viewBinding.toolbar, viewBinding.collapsingToolbar);
- iconTintManager.updateTint();
viewBinding.appBar.addOnOffsetChangedListener(iconTintManager);
viewBinding.header.butShowInfo.setVisibility(View.INVISIBLE);
diff --git a/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/FeedItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/FeedItemlistFragment.java
index 6dbab44a8..2d5d8fa35 100644
--- a/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/FeedItemlistFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/FeedItemlistFragment.java
@@ -51,6 +51,7 @@ import de.danoeh.antennapod.ui.TransitionEffect;
import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter;
import de.danoeh.antennapod.ui.cleaner.HtmlToPlainText;
import de.danoeh.antennapod.ui.common.IntentUtils;
+import de.danoeh.antennapod.ui.common.OnCollapseChangeListener;
import de.danoeh.antennapod.ui.episodeslist.EpisodeItemListAdapter;
import de.danoeh.antennapod.ui.episodeslist.EpisodeItemViewHolder;
import de.danoeh.antennapod.ui.episodeslist.EpisodeMultiSelectActionHandler;
@@ -161,8 +162,16 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
ToolbarIconTintManager iconTintManager =
new ToolbarIconTintManager(viewBinding.toolbar, viewBinding.collapsingToolbar);
- iconTintManager.updateTint();
viewBinding.appBar.addOnOffsetChangedListener(iconTintManager);
+ viewBinding.appBar.addOnOffsetChangedListener(new OnCollapseChangeListener(viewBinding.collapsingToolbar) {
+ @Override
+ public void onCollapseChanged(boolean isCollapsed) {
+ if (feed == null) {
+ return;
+ }
+ viewBinding.toolbar.setTitle(isCollapsed ? feed.getTitle() : "");
+ }
+ });
nextPageLoader = new MoreContentListFooterUtil(viewBinding.moreContent.moreContentListFooter);
nextPageLoader.setClickListener(() -> {
diff --git a/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/ToolbarIconTintManager.java b/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/ToolbarIconTintManager.java
index 7b2104fba..11aa27557 100644
--- a/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/ToolbarIconTintManager.java
+++ b/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/ToolbarIconTintManager.java
@@ -5,38 +5,27 @@ import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.view.Menu;
-import com.google.android.material.appbar.MaterialToolbar;
-import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
+import com.google.android.material.appbar.MaterialToolbar;
+
+import de.danoeh.antennapod.ui.common.OnCollapseChangeListener;
/**
* A manager that automatically finds all icons in a collapsable toolbar and tints them according to the collapse state
* of the toolbar.
*/
-public class ToolbarIconTintManager implements AppBarLayout.OnOffsetChangedListener {
- private final CollapsingToolbarLayout collapsingToolbar;
+public class ToolbarIconTintManager extends OnCollapseChangeListener {
private final MaterialToolbar toolbar;
- private boolean isTinted = false;
public ToolbarIconTintManager(MaterialToolbar toolbar, CollapsingToolbarLayout collapsingToolbar) {
- this.collapsingToolbar = collapsingToolbar;
+ super(collapsingToolbar);
this.toolbar = toolbar;
+ this.onCollapseChanged(false);
}
@Override
- public void onOffsetChanged(AppBarLayout appBarLayout, int offset) {
- boolean tint = (collapsingToolbar.getHeight() + offset) > (2 * collapsingToolbar.getMinimumHeight());
- if (isTinted != tint) {
- isTinted = tint;
- updateTint();
- }
- }
-
- public void updateTint() {
- PorterDuffColorFilter filter = null;
- if (isTinted) {
- filter = new PorterDuffColorFilter(0xffffffff, Mode.SRC_ATOP);
- }
+ public void onCollapseChanged(boolean isCollapsed) {
+ PorterDuffColorFilter filter = isCollapsed ? null : new PorterDuffColorFilter(0xffffffff, Mode.SRC_ATOP);
safeSetColorFilter(toolbar.getNavigationIcon(), filter);
safeSetColorFilter(toolbar.getOverflowIcon(), filter);
diff --git a/app/src/main/res/layout/feed_item_list_fragment.xml b/app/src/main/res/layout/feed_item_list_fragment.xml
index f236ee90a..f697288cd 100644
--- a/app/src/main/res/layout/feed_item_list_fragment.xml
+++ b/app/src/main/res/layout/feed_item_list_fragment.xml
@@ -16,6 +16,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:scrimAnimationDuration="200"
+ app:titleEnabled="false"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
diff --git a/ui/common/src/main/java/de/danoeh/antennapod/ui/common/OnCollapseChangeListener.java b/ui/common/src/main/java/de/danoeh/antennapod/ui/common/OnCollapseChangeListener.java
new file mode 100644
index 000000000..eaa698fb5
--- /dev/null
+++ b/ui/common/src/main/java/de/danoeh/antennapod/ui/common/OnCollapseChangeListener.java
@@ -0,0 +1,25 @@
+package de.danoeh.antennapod.ui.common;
+
+import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.appbar.CollapsingToolbarLayout;
+
+public abstract class OnCollapseChangeListener implements AppBarLayout.OnOffsetChangedListener {
+ private final CollapsingToolbarLayout collapsingToolbar;
+ private boolean wasCollapsed = false;
+
+ public OnCollapseChangeListener(CollapsingToolbarLayout collapsingToolbar) {
+ this.collapsingToolbar = collapsingToolbar;
+ }
+
+ @Override
+ public void onOffsetChanged(AppBarLayout appBarLayout, int offset) {
+ boolean isCollapsed = (collapsingToolbar.getHeight() + offset)
+ < collapsingToolbar.getScrimVisibleHeightTrigger();
+ if (wasCollapsed != isCollapsed) {
+ wasCollapsed = isCollapsed;
+ onCollapseChanged(isCollapsed);
+ }
+ }
+
+ public abstract void onCollapseChanged(boolean isCollapsed);
+}