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.
This commit is contained in:
parent
ff5a2c78d8
commit
17b713e10c
|
@ -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);
|
||||
|
|
|
@ -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(() -> {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue