jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/342827 )
Change subject: Bring back link preview overlay buttons.
......................................................................
Bring back link preview overlay buttons.
This reenables the "Read article" button (and the "Get directinos" button
when in Nearby) to float translucently on top of the link preview dialog.
This is now accomplished by making the overlay into a custom view, and
injecting it into the view hierarchy at runtime when the dialog is shown.
The injection is done in onResume(), since it can't be done in
onCreateView() because the view hierarchy isn't constructed yet. We
search for a parent view called "id/content" (common to all dialogs)
which, conveniently, is a FrameLayout, and lets us float the overlay at
the bottom.
Bug: T159571
Change-Id: I781e259abb6fd08a4396b259da6111557f8dc250
---
M app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
A app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewOverlayView.java
M app/src/main/res/layout/dialog_link_preview.xml
A app/src/main/res/layout/view_link_preview_overlay.xml
4 files changed, 143 insertions(+), 69 deletions(-)
Approvals:
Niedzielski: Looks good to me, approved
jenkins-bot: Verified
diff --git
a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
index 3ae7b61..ae871d9 100755
--- a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
+++ b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
@@ -63,7 +63,6 @@
private GalleryThumbnailScrollView thumbnailGallery;
private View toolbarView;
private View overflowButton;
- private TextView goButton;
private PageTitle pageTitle;
private int entrySource;
@@ -71,7 +70,8 @@
private LinkPreviewFunnel funnel;
private LinkPreviewContents contents;
- private OnNavigateListener onNavigateListener;
+ private LinkPreviewOverlayView overlayView;
+ private OverlayViewCallback overlayCallback = new OverlayViewCallback();
private GalleryThumbnailScrollView.GalleryViewListener galleryViewListener
= new GalleryThumbnailScrollView.GalleryViewListener() {
@@ -87,13 +87,6 @@
@Override
public void onClick(View v) {
goToLinkedPage();
- }
- };
-
- private View.OnClickListener getDirectionsListener = new
View.OnClickListener() {
- @Override
- public void onClick(View v) {
- goToExternalMapsApp();
}
};
@@ -122,17 +115,6 @@
toolbarView = rootView.findViewById(R.id.link_preview_toolbar);
toolbarView.setOnClickListener(goToPageListener);
- goButton = (TextView)
rootView.findViewById(R.id.link_preview_go_button);
- goButton.setOnClickListener(goToPageListener);
- goButton.setText(getStringForArticleLanguage(pageTitle,
R.string.button_continue_to_article));
-
- TextView directionsButton = (TextView)
rootView.findViewById(R.id.link_preview_directions_button);
- if (location != null) {
- directionsButton.setOnClickListener(getDirectionsListener);
- } else {
- directionsButton.setVisibility(View.GONE);
- }
-
TextView titleText = (TextView)
rootView.findViewById(R.id.link_preview_title);
titleText.setText(pageTitle.getDisplayText());
setConditionalLayoutDirection(rootView,
pageTitle.getWikiSite().languageCode());
@@ -146,7 +128,6 @@
ViewUtil.setBottomPaddingDp(titleText, bottomPadding);
}
- onNavigateListener = new DefaultOnNavigateListener();
extractText = (TextView)
rootView.findViewById(R.id.link_preview_extract);
thumbnailView = (SimpleDraweeView)
rootView.findViewById(R.id.link_preview_thumbnail);
@@ -179,18 +160,25 @@
return rootView;
}
- public interface OnNavigateListener {
- void onNavigate(PageTitle title);
- }
-
public void goToLinkedPage() {
navigateSuccess = true;
funnel.logNavigate();
if (getDialog() != null) {
getDialog().dismiss();
}
- if (onNavigateListener != null) {
- onNavigateListener.onNavigate(pageTitle);
+ HistoryEntry newEntry = new HistoryEntry(pageTitle, entrySource);
+ loadPage(pageTitle, newEntry, false);
+ }
+
+ @Override public void onResume() {
+ super.onResume();
+ if (overlayView == null) {
+ ViewGroup containerView = (ViewGroup)
getDialog().findViewById(android.R.id.content);
+ overlayView = new LinkPreviewOverlayView(getContext());
+ overlayView.setCallback(overlayCallback);
+
overlayView.setPrimaryButtonText(getStringForArticleLanguage(pageTitle,
R.string.button_continue_to_article));
+ overlayView.showSecondaryButton(location != null);
+ containerView.addView(overlayView);
}
}
@@ -199,7 +187,8 @@
thumbnailGallery.setGalleryViewListener(null);
toolbarView.setOnClickListener(null);
overflowButton.setOnClickListener(null);
- goButton.setOnClickListener(null);
+ overlayView.setCallback(null);
+ overlayView = null;
super.onDestroyView();
}
@@ -313,14 +302,6 @@
}
};
- private class DefaultOnNavigateListener implements OnNavigateListener {
- @Override
- public void onNavigate(PageTitle title) {
- HistoryEntry newEntry = new HistoryEntry(title, entrySource);
- loadPage(title, newEntry, false);
- }
- }
-
private void layoutPreview() {
if (contents.getExtract().length() > 0) {
extractText.setText(contents.getExtract());
@@ -336,7 +317,7 @@
@Override
public void onGalleryResult(GalleryCollection result) {
- if (!result.getItemList().isEmpty()) {
+ if (result.getItemList() != null &&
!result.getItemList().isEmpty()) {
thumbnailGallery.setGalleryCollection(result);
}
}
@@ -362,6 +343,18 @@
}
}
+ private class OverlayViewCallback implements
LinkPreviewOverlayView.Callback {
+ @Override
+ public void onPrimaryClick() {
+ goToLinkedPage();
+ }
+
+ @Override
+ public void onSecondaryClick() {
+ goToExternalMapsApp();
+ }
+ }
+
@Nullable private Callback callback() {
return FragmentUtil.getCallback(this, Callback.class);
}
diff --git
a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewOverlayView.java
b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewOverlayView.java
new file mode 100644
index 0000000..5712bb8
--- /dev/null
+++
b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewOverlayView.java
@@ -0,0 +1,80 @@
+package org.wikipedia.page.linkpreview;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.os.Build;
+import android.support.annotation.Nullable;
+import android.util.AttributeSet;
+import android.view.Gravity;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import org.wikipedia.R;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import butterknife.OnClick;
+
+public class LinkPreviewOverlayView extends LinearLayout {
+ public interface Callback {
+ void onPrimaryClick();
+ void onSecondaryClick();
+ }
+
+ @BindView(R.id.link_preview_primary_button) TextView primaryButton;
+ @BindView(R.id.link_preview_secondary_button) View secondaryButton;
+
+ @Nullable private Callback callback;
+
+ public LinkPreviewOverlayView(Context context) {
+ super(context);
+ init();
+ }
+
+ public LinkPreviewOverlayView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init();
+ }
+
+ public LinkPreviewOverlayView(Context context, AttributeSet attrs, int
defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ init();
+ }
+
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ public LinkPreviewOverlayView(Context context, AttributeSet attrs, int
defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ init();
+ }
+
+ public void setCallback(@Nullable Callback callback) {
+ this.callback = callback;
+ }
+
+ public void setPrimaryButtonText(@Nullable CharSequence text) {
+ primaryButton.setText(text);
+ }
+
+ public void showSecondaryButton(boolean show) {
+ secondaryButton.setVisibility(show ? VISIBLE : GONE);
+ }
+
+ @OnClick(R.id.link_preview_primary_button) void onPrimaryClick(View view) {
+ if (callback != null) {
+ callback.onPrimaryClick();
+ }
+ }
+
+ @OnClick(R.id.link_preview_secondary_button) void onSecondaryClick(View
view) {
+ if (callback != null) {
+ callback.onSecondaryClick();
+ }
+ }
+
+ private void init() {
+ inflate(getContext(), R.layout.view_link_preview_overlay, this);
+ ButterKnife.bind(this);
+ setVerticalGravity(Gravity.BOTTOM);
+ }
+}
diff --git a/app/src/main/res/layout/dialog_link_preview.xml
b/app/src/main/res/layout/dialog_link_preview.xml
index 20613d2..a25cb38 100755
--- a/app/src/main/res/layout/dialog_link_preview.xml
+++ b/app/src/main/res/layout/dialog_link_preview.xml
@@ -100,36 +100,4 @@
android:layout_height="wrap_content"
android:layout_gravity="center"/>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="bottom">
-
- <TextView
- android:id="@+id/link_preview_directions_button"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:paddingTop="16dp"
- android:paddingBottom="16dp"
- android:textColor="@color/gray_highlight"
- android:background="?attr/link_preview_button_background"
- style="@style/Widget.AppCompat.Button.Borderless"
- android:textSize="@dimen/abc_text_size_menu_material"
- android:text="@string/button_get_directions"/>
- <TextView
- android:id="@+id/link_preview_go_button"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:paddingTop="16dp"
- android:paddingBottom="16dp"
- android:textColor="?attr/link_color"
- android:background="?attr/link_preview_button_background"
- style="@style/Widget.AppCompat.Button.Borderless"
- android:textSize="@dimen/abc_text_size_menu_material"
- android:text="@string/button_continue_to_article"/>
-
- </LinearLayout>
-
</FrameLayout>
diff --git a/app/src/main/res/layout/view_link_preview_overlay.xml
b/app/src/main/res/layout/view_link_preview_overlay.xml
new file mode 100644
index 0000000..a546cda
--- /dev/null
+++ b/app/src/main/res/layout/view_link_preview_overlay.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<merge
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/link_preview_secondary_button"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:textColor="@color/gray_highlight"
+ android:background="?attr/link_preview_button_background"
+ style="@style/Widget.AppCompat.Button.Borderless"
+ android:textSize="@dimen/abc_text_size_menu_material"
+ android:text="@string/button_get_directions"/>
+ <TextView
+ android:id="@+id/link_preview_primary_button"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:textColor="?attr/link_color"
+ android:background="?attr/link_preview_button_background"
+ style="@style/Widget.AppCompat.Button.Borderless"
+ android:textSize="@dimen/abc_text_size_menu_material"
+ android:text="@string/button_continue_to_article"/>
+
+</merge>
--
To view, visit https://gerrit.wikimedia.org/r/342827
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I781e259abb6fd08a4396b259da6111557f8dc250
Gerrit-PatchSet: 2
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Mholloway <[email protected]>
Gerrit-Reviewer: Niedzielski <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits