jenkins-bot has submitted this change and it was merged.

Change subject: Transition Wiktionary dialog to a bottom sheet.
......................................................................


Transition Wiktionary dialog to a bottom sheet.

This introduces ExtendedBottomSheetDialogFragment, which provides
functionality for optionally disabling dimming of the dialog background,
as well as setting a custom maximum width of the dialog, and whether to
start the dialog fully expanded.

Also a bit of renaming of dimens, to reflect bottom sheet nomenclature.

Change-Id: Ic1a58ff8af65f9ca8be3bd957f23871b680465f4
---
A app/src/main/java/org/wikipedia/page/ExtendedBottomSheetDialogFragment.java
M app/src/main/java/org/wikipedia/page/PageActivity.java
M app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
M app/src/main/java/org/wikipedia/page/linkpreview/SwipeableBottomDialog.java
M app/src/main/java/org/wikipedia/page/snippet/ShareHandler.java
M app/src/main/java/org/wikipedia/theme/ThemeChooserDialog.java
M app/src/main/java/org/wikipedia/wiktionary/WiktionaryDialog.java
M app/src/main/res/layout/dialog_link_preview.xml
M app/src/main/res/layout/dialog_wiktionary.xml
M app/src/main/res/values/dimens.xml
M app/src/main/res/values/styles.xml
11 files changed, 101 insertions(+), 33 deletions(-)

Approvals:
  Niedzielski: Looks good to me, approved
  jenkins-bot: Verified



diff --git 
a/app/src/main/java/org/wikipedia/page/ExtendedBottomSheetDialogFragment.java 
b/app/src/main/java/org/wikipedia/page/ExtendedBottomSheetDialogFragment.java
new file mode 100644
index 0000000..9af937e
--- /dev/null
+++ 
b/app/src/main/java/org/wikipedia/page/ExtendedBottomSheetDialogFragment.java
@@ -0,0 +1,66 @@
+package org.wikipedia.page;
+
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.support.design.widget.BottomSheetBehavior;
+import android.support.design.widget.BottomSheetDialogFragment;
+import android.view.ViewGroup;
+import android.widget.FrameLayout;
+
+import org.wikipedia.R;
+import org.wikipedia.util.DimenUtil;
+
+/**
+ * Descendant of BottomSheetDialogFragment that adds a few features and 
conveniences.
+ */
+public class ExtendedBottomSheetDialogFragment extends 
BottomSheetDialogFragment {
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+    }
+
+    @Override
+    public void onStart() {
+        super.onStart();
+        setWindowLayout();
+    }
+
+    @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+        setWindowLayout();
+    }
+
+    protected void disableBackgroundDim() {
+        getDialog().getWindow().setDimAmount(0f);
+    }
+
+    protected void startExpanded() {
+        /*
+        HACK: We'd like some of our bottom sheets to be fully expanded when 
opened (as
+        opposed to expanded to the peek height). In order to do this, however, 
we have to
+        call setState() only *after* the dialog is created and laid out.
+        https://code.google.com/p/android/issues/detail?id=202174
+        TODO: remove when this is improved in the library.
+        */
+        getDialog().getWindow().getDecorView().post(new Runnable() {
+            @Override
+            public void run() {
+                FrameLayout bottomSheet = (FrameLayout) 
getDialog().getWindow().getDecorView().findViewById(android.support.design.R.id.design_bottom_sheet);
+                BottomSheetBehavior behavior = 
BottomSheetBehavior.from(bottomSheet);
+                behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
+            }
+        });
+    }
+
+    private void setWindowLayout() {
+        if (getDialog() != null) {
+            getDialog().getWindow().setLayout(dialogWidthPx(), 
ViewGroup.LayoutParams.WRAP_CONTENT);
+        }
+    }
+
+    private int dialogWidthPx() {
+        return Math.min(DimenUtil.getDisplayWidthPx(),
+                (int) 
getResources().getDimension(R.dimen.bottomSheetMaxWidth));
+    }
+}
diff --git a/app/src/main/java/org/wikipedia/page/PageActivity.java 
b/app/src/main/java/org/wikipedia/page/PageActivity.java
index 7841b8c..62ea2f5 100644
--- a/app/src/main/java/org/wikipedia/page/PageActivity.java
+++ b/app/src/main/java/org/wikipedia/page/PageActivity.java
@@ -54,6 +54,7 @@
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.design.widget.BottomSheetDialog;
+import android.support.design.widget.BottomSheetDialogFragment;
 import android.support.design.widget.NavigationView;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
@@ -691,6 +692,10 @@
         bottomSheetPresenter.show(dialog);
     }
 
+    public void showBottomSheet(BottomSheetDialogFragment dialog) {
+        bottomSheetPresenter.show(dialog);
+    }
+
     // Note: back button first handled in {@link #onOptionsItemSelected()};
     @Override
     public void onBackPressed() {
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 0de6281..453a983 100755
--- a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
+++ b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
@@ -107,7 +107,7 @@
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setStyle(STYLE_NO_TITLE, R.style.LinkPreviewDialog);
-        setContentPeekHeight((int) 
getResources().getDimension(R.dimen.linkPreviewPeekHeight));
+        setContentPeekHeight((int) 
getResources().getDimension(R.dimen.bottomSheetPeekHeight));
     }
 
     @Override
diff --git 
a/app/src/main/java/org/wikipedia/page/linkpreview/SwipeableBottomDialog.java 
b/app/src/main/java/org/wikipedia/page/linkpreview/SwipeableBottomDialog.java
index c9a5ea2..552c022 100644
--- 
a/app/src/main/java/org/wikipedia/page/linkpreview/SwipeableBottomDialog.java
+++ 
b/app/src/main/java/org/wikipedia/page/linkpreview/SwipeableBottomDialog.java
@@ -197,7 +197,7 @@
 
     protected int dialogWidthPx() {
         return Math.min(DimenUtil.getDisplayWidthPx(),
-                (int) 
getResources().getDimension(R.dimen.swipeableDialogMaxWidth));
+                (int) 
getResources().getDimension(R.dimen.bottomSheetMaxWidth));
     }
 
     private int dialogHeightPx() {
diff --git a/app/src/main/java/org/wikipedia/page/snippet/ShareHandler.java 
b/app/src/main/java/org/wikipedia/page/snippet/ShareHandler.java
index a796e81..e0453f2 100755
--- a/app/src/main/java/org/wikipedia/page/snippet/ShareHandler.java
+++ b/app/src/main/java/org/wikipedia/page/snippet/ShareHandler.java
@@ -55,7 +55,6 @@
     private static final String PAYLOAD_PURPOSE_SHARE = "share";
     private static final String PAYLOAD_PURPOSE_DEFINE = "define";
     private static final String PAYLOAD_TEXT_KEY = "text";
-    private static final String WIKTIONARY_DEFINITION_TAG = 
"wiktionary_definition_dialog";
 
     @ColorRes private static final int SHARE_TOOL_TIP_COLOR = 
R.color.blue_liberal;
 
@@ -97,8 +96,7 @@
 
     public void showWiktionaryDefinition(String text) {
         PageTitle title = activity.getCurPageFragment().getTitle();
-        WiktionaryDialog dialog = WiktionaryDialog.newInstance(title, text);
-        dialog.show(activity.getSupportFragmentManager(), 
WIKTIONARY_DEFINITION_TAG);
+        activity.showBottomSheet(WiktionaryDialog.newInstance(title, text));
     }
 
     private void onSharePayload(String text) {
diff --git a/app/src/main/java/org/wikipedia/theme/ThemeChooserDialog.java 
b/app/src/main/java/org/wikipedia/theme/ThemeChooserDialog.java
index e61ccc6..ade7312 100644
--- a/app/src/main/java/org/wikipedia/theme/ThemeChooserDialog.java
+++ b/app/src/main/java/org/wikipedia/theme/ThemeChooserDialog.java
@@ -1,7 +1,6 @@
 package org.wikipedia.theme;
 
 import android.os.Bundle;
-import android.support.design.widget.BottomSheetDialogFragment;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -13,9 +12,10 @@
 import org.wikipedia.WikipediaApp;
 import org.wikipedia.analytics.AppearanceChangeFunnel;
 import org.wikipedia.events.WebViewInvalidateEvent;
+import org.wikipedia.page.ExtendedBottomSheetDialogFragment;
 import org.wikipedia.settings.Prefs;
 
-public class ThemeChooserDialog extends BottomSheetDialogFragment {
+public class ThemeChooserDialog extends ExtendedBottomSheetDialogFragment {
     private WikipediaApp app;
     private Button buttonDefaultTextSize;
     private Button buttonDecreaseTextSize;
@@ -77,6 +77,7 @@
         fontChangeProgressBar = (ProgressBar) 
rootView.findViewById(R.id.font_change_progress_bar);
 
         updateButtonState();
+        disableBackgroundDim();
         return rootView;
     }
 
diff --git a/app/src/main/java/org/wikipedia/wiktionary/WiktionaryDialog.java 
b/app/src/main/java/org/wikipedia/wiktionary/WiktionaryDialog.java
index 8a8ec91..231bd11 100644
--- a/app/src/main/java/org/wikipedia/wiktionary/WiktionaryDialog.java
+++ b/app/src/main/java/org/wikipedia/wiktionary/WiktionaryDialog.java
@@ -15,15 +15,14 @@
 import org.wikipedia.Site;
 import org.wikipedia.WikipediaApp;
 import org.wikipedia.analytics.WiktionaryDialogFunnel;
+import org.wikipedia.page.ExtendedBottomSheetDialogFragment;
 import org.wikipedia.page.LinkMovementMethodExt;
 import org.wikipedia.page.PageActivity;
 import org.wikipedia.page.PageTitle;
-import org.wikipedia.page.linkpreview.SwipeableBottomDialog;
 import org.wikipedia.server.PageServiceFactory;
 import org.wikipedia.server.PageService;
 import org.wikipedia.server.restbase.RbPageService;
 import org.wikipedia.server.restbase.RbDefinition;
-import org.wikipedia.util.DimenUtil;
 import org.wikipedia.util.log.L;
 import org.wikipedia.views.AppTextView;
 
@@ -36,12 +35,11 @@
 import static org.wikipedia.util.StringUtil.hasSectionAnchor;
 import static org.wikipedia.util.StringUtil.removeSectionAnchor;
 
-public class WiktionaryDialog extends SwipeableBottomDialog {
+public class WiktionaryDialog extends ExtendedBottomSheetDialogFragment {
     private static final String WIKTIONARY_DOMAIN = ".wiktionary.org";
     private static final String TITLE = "title";
     private static final String SELECTED_TEXT = "selected_text";
     private static final String PATH_WIKI = "/wiki/";
-    private static final int PEEK_HEIGHT_DIVISOR = 3;
 
     private static String[] ENABLED_LANGUAGES = {
             "en" // English
@@ -70,16 +68,13 @@
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        setStyle(STYLE_NO_TITLE, R.style.LinkPreviewDialog);
-        int peekHeight = DimenUtil.getDisplayHeightPx() / PEEK_HEIGHT_DIVISOR;
-        setContentPeekHeight(peekHeight);
+        pageTitle = getArguments().getParcelable(TITLE);
+        selectedText = getArguments().getString(SELECTED_TEXT);
     }
 
     @Override
-    protected View inflateDialogView(LayoutInflater inflater, ViewGroup 
container) {
-        pageTitle = getArguments().getParcelable(TITLE);
-        selectedText = getArguments().getString(SELECTED_TEXT);
-
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                             Bundle savedInstanceState) {
         rootView = inflater.inflate(R.layout.dialog_wiktionary, container);
         progressBar = (ProgressBar) 
rootView.findViewById(R.id.dialog_wiktionary_progress);
 
diff --git a/app/src/main/res/layout/dialog_link_preview.xml 
b/app/src/main/res/layout/dialog_link_preview.xml
index 3838982..1ff0a94 100755
--- a/app/src/main/res/layout/dialog_link_preview.xml
+++ b/app/src/main/res/layout/dialog_link_preview.xml
@@ -20,7 +20,7 @@
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:minHeight="@dimen/linkPreviewPeekHeight"
+            android:minHeight="@dimen/bottomSheetPeekHeight"
             android:orientation="vertical"
             android:background="?attr/link_preview_background_color"
             android:animateLayoutChanges="true">
diff --git a/app/src/main/res/layout/dialog_wiktionary.xml 
b/app/src/main/res/layout/dialog_wiktionary.xml
index 6a46f3c..cb7326a 100644
--- a/app/src/main/res/layout/dialog_wiktionary.xml
+++ b/app/src/main/res/layout/dialog_wiktionary.xml
@@ -4,20 +4,14 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
 
-    <LinearLayout
+    <android.support.v4.widget.NestedScrollView
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="vertical">
-
-        <View
-            android:layout_width="match_parent"
-            android:layout_height="8dp"
-            android:background="@drawable/link_preview_top_shadow"/>
+        android:layout_height="wrap_content">
 
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:minHeight="@dimen/linkPreviewPeekHeight"
+            android:minHeight="@dimen/bottomSheetPeekHeight"
             android:paddingLeft="16dp"
             android:paddingRight="16dp"
             android:background="?attr/link_preview_background_color"
@@ -78,7 +72,7 @@
 
         </LinearLayout>
 
-    </LinearLayout>
+    </android.support.v4.widget.NestedScrollView>
 
     <ProgressBar
         android:id="@+id/dialog_wiktionary_progress"
diff --git a/app/src/main/res/values/dimens.xml 
b/app/src/main/res/values/dimens.xml
index ed63fc4..ac09711 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -39,12 +39,12 @@
     <!-- Tool tips -->
     <dimen name="tool_tip_max_width">250dp</dimen>
 
-    <!-- Default width of swipeable bottom dialogs. -->
-    <dimen name="swipeableDialogMaxWidth">480dp</dimen>
+    <!-- Default maximum width of bottom sheets. -->
+    <dimen name="bottomSheetMaxWidth">480dp</dimen>
+    <!-- Default height with which bottom sheets peek out from the bottom -->
+    <dimen name="bottomSheetPeekHeight">320dp</dimen>
     <!-- Default size of images in Link Preview thumbnail gallery -->
     <dimen name="linkPreviewImageSize">112dp</dimen>
-    <!-- Default height with which the Link Preview peeks out from the bottom 
-->
-    <dimen name="linkPreviewPeekHeight">320dp</dimen>
 
     <item type="dimen" format="float" 
name="linkPreviewThumbPressScale">1.03</item>
     <item type="dimen" format="float" 
name="linkPreviewThumbPressOverScale">1.05</item>
diff --git a/app/src/main/res/values/styles.xml 
b/app/src/main/res/values/styles.xml
index 94b4132..4ebdfabd 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -3,6 +3,7 @@
 
     <style name="AppTheme" parent="Theme.Light">
         <item name="preferenceTheme">@style/AppPreferenceTheme</item>
+        <item 
name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
         <item 
name="editTextAutoSummarizePreferenceStyle">@style/EditTextAutoSummarizePreference</item>
         <item name="longPreferenceStyle">@style/LongPreference</item>
         <item name="intPreferenceStyle">@style/IntPreference</item>
@@ -150,6 +151,14 @@
         <item 
name="colorControlHighlight">@color/link_preview_button_background_light_highlight</item>
     </style>
 
+    <style name="AppBottomSheetDialogTheme" 
parent="Theme.Design.Light.BottomSheetDialog">
+        <item name="bottomSheetStyle">@style/AppBottomSheetModalStyle</item>
+    </style>
+
+    <style name="AppBottomSheetModalStyle" 
parent="Widget.Design.BottomSheet.Modal">
+        <item name="behavior_peekHeight">@dimen/bottomSheetPeekHeight</item>
+    </style>
+
     <!-- Default style for floating action buttons -->
     <style name="FloatingActionButton">
         <item 
name="android:layout_marginLeft">@dimen/floating_action_button_margin_left</item>

-- 
To view, visit https://gerrit.wikimedia.org/r/277856
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic1a58ff8af65f9ca8be3bd957f23871b680465f4
Gerrit-PatchSet: 5
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
Gerrit-Reviewer: BearND <[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

Reply via email to