#1392 Collapsing toolbar sticky feed header

This commit is contained in:
sictiru 2021-01-01 13:14:16 -08:00
parent 44963672c0
commit fc443a4e52
4 changed files with 167 additions and 181 deletions

View file

@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.4.20'
ext.kotlin_version = '1.4.21'
repositories {
mavenCentral()
maven {

View file

@ -1,199 +1,197 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent">
<!-- The two views in this top FrameLayout are swapped when HTML5 webview custom content wants to be displayed -->
<com.newsblur.view.ReadingScrollView
android:id="@+id/reading_scrollview"
<RelativeLayout
android:id="@+id/reading_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="?readingBackground"
>
android:layout_height="match_parent">
<LinearLayout
<FrameLayout
android:id="@+id/row_item_feed_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
>
android:minHeight="6dp"
android:paddingTop="4dp"
android:paddingBottom="4dp">
<RelativeLayout
<ImageView
android:id="@+id/reading_feed_icon"
android:layout_width="17dp"
android:layout_height="17dp"
android:layout_marginStart="16dp"
android:contentDescription="@string/description_row_folder_icon" />
<TextView
android:id="@+id/reading_feed_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
style="?rowItemHeaderBackground">
android:layout_gravity="center_vertical"
android:layout_marginStart="40dp"
android:ellipsize="end"
android:lines="1"
android:textSize="12sp"
android:textStyle="bold" />
</FrameLayout>
<View
android:id="@+id/item_feed_border"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/row_item_feed_header"
android:background="@color/gray55" />
<com.newsblur.view.ReadingScrollView
android:id="@+id/reading_scrollview"
style="?readingBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/item_feed_border">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/row_item_feed_header"
android:layout_height="wrap_content"
style="?rowItemHeaderBackground"
android:layout_width="match_parent"
android:minHeight="6dp"
android:paddingTop="4dp"
android:paddingBottom="4dp" >
android:layout_height="wrap_content"
android:paddingBottom="8dp">
<ImageView
android:id="@+id/reading_feed_icon"
android:layout_width="17dp"
android:layout_height="17dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="16dp"
android:layout_marginRight="5dp"
android:contentDescription="@string/description_row_folder_icon" />
<ImageButton
android:id="@+id/story_context_menu_button"
style="?android:attr/actionOverflowButtonStyle"
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_alignParentRight="true"
android:layout_margin="5dp"
android:contentDescription="@string/description_menu" />
<TextView
android:id="@+id/reading_feed_title"
android:id="@+id/reading_item_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@id/reading_feed_icon"
android:layout_centerVertical="true"
android:ellipsize="end"
android:lines="1"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="10dp"
android:layout_marginRight="16dp"
android:layout_toLeftOf="@id/story_context_menu_button"
android:textSize="17sp" />
<TextView
android:id="@+id/reading_item_date"
style="?readingItemMetadata"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/reading_item_title"
android:layout_alignLeft="@id/reading_item_title"
android:layout_marginTop="8dp"
android:layout_marginRight="12dp"
android:textSize="12sp" />
<TextView
android:id="@+id/reading_item_authors"
style="?readingItemMetadata"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/reading_item_date"
android:layout_toRightOf="@id/reading_item_date"
android:maxLines="1"
android:minWidth="80dp"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="@+id/reading_story_changes"
style="?readingItemMetadata"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/reading_item_date"
android:layout_alignLeft="@id/reading_item_title"
android:drawableStart="@drawable/ic_file_edit"
android:drawablePadding="6dp"
android:gravity="center_vertical"
android:paddingTop="8dp"
android:paddingBottom="4dp"
android:text="@string/story_show_changes"
android:textSize="12sp"
android:visibility="gone" />
<com.newsblur.view.FlowLayout
android:id="@+id/reading_item_tags"
android:layout_width="match_parent"
android:layout_height="17dp"
android:layout_below="@id/reading_story_changes"
android:layout_alignLeft="@id/reading_item_title"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp" />
</RelativeLayout>
<View
android:id="@+id/item_feed_border"
style="?itemHeaderDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/row_item_feed_header"
android:background="@color/gray55"/>
android:layout_gravity="bottom" />
<ImageButton
android:id="@+id/story_context_menu_button"
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_margin="5dp"
style="?android:attr/actionOverflowButtonStyle"
android:contentDescription="@string/description_menu"
android:layout_below="@id/item_feed_border"
android:layout_alignParentRight="true" />
<include layout="@layout/include_reading_share_bar" />
<TextView
android:id="@+id/reading_item_title"
<View
android:id="@+id/share_bar_underline"
style="?android:divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="16dp"
android:layout_below="@id/item_feed_border"
android:layout_toLeftOf="@id/story_context_menu_button"
android:textSize="17sp" />
<TextView
android:id="@+id/reading_item_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/reading_item_title"
android:layout_alignLeft="@id/reading_item_title"
android:layout_marginRight="12dp"
android:layout_marginTop="8dp"
style="?readingItemMetadata"
android:textSize="12sp" />
<TextView
android:id="@+id/reading_item_authors"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/reading_item_date"
android:layout_toRightOf="@id/reading_item_date"
android:maxLines="1"
android:minWidth="80dp"
style="?readingItemMetadata"
android:textSize="12sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/reading_story_changes"
style="?readingItemMetadata"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/reading_item_date"
android:layout_alignLeft="@id/reading_item_title"
android:paddingTop="8dp"
android:gravity="center_vertical"
android:paddingBottom="4dp"
android:drawablePadding="6dp"
android:drawableStart="@drawable/ic_file_edit"
android:text="@string/story_show_changes"
android:textSize="12sp"
android:layout_height="3dp"
android:visibility="gone" />
<com.newsblur.view.FlowLayout
android:id="@+id/reading_item_tags"
<TextView
android:id="@+id/reading_textloading"
style="?readingBackground"
android:layout_width="match_parent"
android:layout_height="17dp"
android:layout_alignLeft="@id/reading_item_title"
android:layout_below="@id/reading_story_changes"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp" />
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="@string/orig_text_loading"
android:textSize="16sp"
android:textStyle="italic"
android:visibility="gone" />
</RelativeLayout>
<TextView
android:id="@+id/reading_textmodefailed"
style="?readingBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="@string/orig_text_failed"
android:textSize="16sp"
android:textStyle="italic"
android:visibility="gone" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="bottom"
style="?itemHeaderDivider" />
<com.newsblur.view.NewsblurWebview
android:id="@+id/reading_webview"
style="?readingBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="12dp"
android:layout_marginRight="10dp"
android:scrollbars="none" />
<include layout="@layout/include_reading_share_bar" />
<include layout="@layout/include_reading_item_comment" />
<View
android:id="@+id/share_bar_underline"
android:layout_width="match_parent"
android:layout_height="3dp"
style="?android:divider"
android:visibility="gone" />
</LinearLayout>
<TextView
android:id="@+id/reading_textloading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
style="?readingBackground"
android:gravity="center_horizontal"
android:text="@string/orig_text_loading"
android:textSize="16sp"
android:textStyle="italic"
android:visibility="gone"
/>
</com.newsblur.view.ReadingScrollView>
<TextView
android:id="@+id/reading_textmodefailed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
style="?readingBackground"
android:gravity="center_horizontal"
android:text="@string/orig_text_failed"
android:textSize="16sp"
android:textStyle="italic"
android:visibility="gone"
/>
<com.newsblur.view.NewsblurWebview
android:id="@+id/reading_webview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?readingBackground"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="12dp"
android:scrollbars="none"
/>
<include
layout="@layout/include_reading_item_comment" />
</LinearLayout>
</com.newsblur.view.ReadingScrollView>
</RelativeLayout>
<FrameLayout
android:id="@+id/custom_view_container"

View file

@ -28,7 +28,6 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView.HitTestResult;
import android.widget.ImageView;
import android.widget.TextView;
import com.newsblur.R;
@ -52,7 +51,6 @@ import com.newsblur.util.PrefsUtils;
import com.newsblur.util.StoryChangesState;
import com.newsblur.util.StoryUtils;
import com.newsblur.util.UIUtils;
import com.newsblur.view.ReadingScrollView;
import java.util.HashMap;
import java.util.regex.Matcher;
@ -66,12 +64,10 @@ public class ReadingItemFragment extends NbFragment implements PopupMenu.OnMenuI
public static final String READING_FONT_CHANGED = "readingFontChanged";
public Story story;
private FeedSet fs;
private LayoutInflater inflater;
private String feedColor, feedTitle, feedFade, feedBorder, feedIconUrl, faviconText;
private Classifier classifier;
private BroadcastReceiver textSizeReceiver, readingFontReceiver;
private boolean displayFeedDetails;
private View view;
private UserDetails user;
private DefaultFeedView selectedFeedView;
private boolean textViewUnavailable;
@ -163,7 +159,7 @@ public class ReadingItemFragment extends NbFragment implements PopupMenu.OnMenuI
getActivity().unregisterReceiver(textSizeReceiver);
getActivity().unregisterReceiver(readingFontReceiver);
binding.readingWebview.setOnTouchListener(null);
view.setOnTouchListener(null);
binding.getRoot().setOnTouchListener(null);
getActivity().getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(null);
super.onDestroy();
}
@ -184,8 +180,7 @@ public class ReadingItemFragment extends NbFragment implements PopupMenu.OnMenuI
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
this.inflater = inflater;
view = inflater.inflate(R.layout.fragment_readingitem, null);
View view = inflater.inflate(R.layout.fragment_readingitem, container, false);
binding = FragmentReadingitemBinding.bind(view);
itemCommentBinding = IncludeReadingItemCommentBinding.bind(binding.getRoot());
@ -196,7 +191,7 @@ public class ReadingItemFragment extends NbFragment implements PopupMenu.OnMenuI
registerForContextMenu(binding.readingWebview);
binding.readingWebview.setCustomViewLayout(binding.customViewContainer);
binding.readingWebview.setWebviewWrapperLayout(binding.readingScrollview);
binding.readingWebview.setWebviewWrapperLayout(binding.readingContainer);
binding.readingWebview.setBackgroundColor(Color.TRANSPARENT);
binding.readingWebview.fragment = this;
binding.readingWebview.activity = activity;
@ -206,8 +201,7 @@ public class ReadingItemFragment extends NbFragment implements PopupMenu.OnMenuI
updateSaveButton();
setupItemCommentsAndShares();
ReadingScrollView scrollView = (ReadingScrollView) view.findViewById(R.id.reading_scrollview);
scrollView.registerScrollChangeListener(activity);
binding.readingScrollview.registerScrollChangeListener(activity);
return view;
}
@ -417,15 +411,10 @@ public class ReadingItemFragment extends NbFragment implements PopupMenu.OnMenuI
}
private void setupItemCommentsAndShares() {
new SetupCommentSectionTask(this, view, inflater, story).execute();
new SetupCommentSectionTask(this, binding.getRoot(), getLayoutInflater(), story).execute();
}
private void setupItemMetadata() {
View feedHeader = view.findViewById(R.id.row_item_feed_header);
View feedHeaderBorder = view.findViewById(R.id.item_feed_border);
TextView itemDate = (TextView) view.findViewById(R.id.reading_item_date);
ImageView feedIcon = (ImageView) view.findViewById(R.id.reading_feed_icon);
if ((feedColor == null) ||
(feedFade == null) ||
TextUtils.equals(feedColor, "null") ||
@ -440,8 +429,8 @@ public class ReadingItemFragment extends NbFragment implements PopupMenu.OnMenuI
Color.parseColor("#" + feedFade),
};
GradientDrawable gradient = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, colors);
UIUtils.setViewBackground(feedHeader, gradient);
feedHeaderBorder.setBackgroundColor(Color.parseColor("#" + feedBorder));
UIUtils.setViewBackground(binding.rowItemFeedHeader, gradient);
binding.itemFeedBorder.setBackgroundColor(Color.parseColor("#" + feedBorder));
if (TextUtils.equals(faviconText, "black")) {
binding.readingFeedTitle.setTextColor(UIUtils.getColor(getActivity(), R.color.text));
@ -453,13 +442,13 @@ public class ReadingItemFragment extends NbFragment implements PopupMenu.OnMenuI
if (!displayFeedDetails) {
binding.readingFeedTitle.setVisibility(View.GONE);
feedIcon.setVisibility(View.GONE);
binding.readingFeedIcon.setVisibility(View.GONE);
} else {
FeedUtils.iconLoader.displayImage(feedIconUrl, feedIcon, 0, false);
FeedUtils.iconLoader.displayImage(feedIconUrl, binding.readingFeedIcon, 0, false);
binding.readingFeedTitle.setText(feedTitle);
}
itemDate.setText(StoryUtils.formatLongDate(getActivity(), story.timestamp));
binding.readingItemDate.setText(StoryUtils.formatLongDate(getActivity(), story.timestamp));
if (story.tags.length <= 0) {
binding.readingItemTags.setVisibility(View.GONE);
@ -510,7 +499,7 @@ public class ReadingItemFragment extends NbFragment implements PopupMenu.OnMenuI
// TODO: these textviews with compound images are buggy, but stubbed in to let colourblind users
// see what is going on. these should be replaced with proper Chips when the v28 Chip lib
// is in full release.
View v = inflater.inflate(R.layout.tag_view, null);
View v = getLayoutInflater().inflate(R.layout.tag_view, null);
TextView tagText = (TextView) v.findViewById(R.id.tag_text);
tagText.setText(tag);

View file

@ -4,7 +4,6 @@ import java.io.File;
import java.util.Map;
import static android.graphics.Bitmap.Config.ARGB_8888;
import static com.google.android.material.appbar.AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS;
import static com.google.android.material.appbar.AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL;
import static com.google.android.material.appbar.AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP;
@ -218,7 +217,7 @@ public class UIUtils {
// enabled scrolling app bar only for reading
if (activity instanceof Reading) {
AppBarLayout.LayoutParams p = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
p.setScrollFlags(SCROLL_FLAG_SCROLL | SCROLL_FLAG_ENTER_ALWAYS | SCROLL_FLAG_SNAP);
p.setScrollFlags(SCROLL_FLAG_SCROLL | SCROLL_FLAG_SNAP);
toolbar.setLayoutParams(p);
}