Dbrant has uploaded a new change for review.
https://gerrit.wikimedia.org/r/277704
Change subject: Groundwork for bottom sheets, part 1.
......................................................................
Groundwork for bottom sheets, part 1.
This is the first patch of the "bottom sheets" series. This does the
following:
- Create an "ExclusiveBottomSheetHandler" class that is bound to
PageActivity, and is responsible for ensuring that only a single modal
bottom sheet can be shown at a time. It handles the work of placing
a DialogFragment onto the activity's fragment manager, and making sure
that any previous DialogFragments are dismissed.
- Start feeding the LinkPreviewDialog into the bottom sheet handler, which
simplifies the code for launching link previews. (this does not yet
transition the LinkPreviewDialog to be an actual BottomSheetDialog)
- Transition the ThemeChooserDialog to be a BottomSheetDialogFragment, as
an introduction to the power of the new bottom sheets functionality.
We also now feed the ThemeChooserDialog into the exclusive bottom sheet
handler. Since the theme chooser is now a DialogFragment, and lives in
the activity's fragment manager, its instanceState is automatically
saved, so we no longer have to maintain its state manually (a
significant benefit and simplification)!
- This also fixes one other possible leak cause in LinkPreviewDialog.
To come: transition the References dialog and the PageIssues/Disambig
dialog to be bottom sheets. And later -- make a new bottom sheet dialog:
Add to Category.
Change-Id: I510afa1e88783fcd960f8097e317cb0ff497e50b
---
A app/src/main/java/org/wikipedia/page/ExclusiveBottomSheetHandler.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/theme/ThemeChooserDialog.java
4 files changed, 73 insertions(+), 62 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia
refs/changes/04/277704/1
diff --git
a/app/src/main/java/org/wikipedia/page/ExclusiveBottomSheetHandler.java
b/app/src/main/java/org/wikipedia/page/ExclusiveBottomSheetHandler.java
new file mode 100644
index 0000000..bce3014
--- /dev/null
+++ b/app/src/main/java/org/wikipedia/page/ExclusiveBottomSheetHandler.java
@@ -0,0 +1,25 @@
+package org.wikipedia.page;
+
+import android.support.v4.app.DialogFragment;
+import android.support.v4.app.FragmentActivity;
+
+public class ExclusiveBottomSheetHandler {
+ private static final String BOTTOM_SHEET_FRAGMENT_TAG =
"bottom_sheet_fragment";
+ private FragmentActivity activity;
+
+ public ExclusiveBottomSheetHandler(FragmentActivity activity) {
+ this.activity = activity;
+ }
+
+ public void show(DialogFragment dialog) {
+ dismiss();
+ dialog.show(activity.getSupportFragmentManager(),
BOTTOM_SHEET_FRAGMENT_TAG);
+ }
+
+ public void dismiss() {
+ DialogFragment dialog = (DialogFragment)
activity.getSupportFragmentManager().findFragmentByTag(BOTTOM_SHEET_FRAGMENT_TAG);
+ if (dialog != null) {
+ dialog.dismiss();
+ }
+ }
+}
diff --git a/app/src/main/java/org/wikipedia/page/PageActivity.java
b/app/src/main/java/org/wikipedia/page/PageActivity.java
index 7863a96..90012cc 100644
--- a/app/src/main/java/org/wikipedia/page/PageActivity.java
+++ b/app/src/main/java/org/wikipedia/page/PageActivity.java
@@ -54,7 +54,6 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView;
-import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
@@ -102,7 +101,6 @@
private static final String LANGUAGE_CODE_BUNDLE_KEY = "language";
private static final String PLAIN_TEXT_MIME_TYPE = "text/plain";
- private static final String LINK_PREVIEW_FRAGMENT_TAG =
"link_preview_dialog";
private Bus bus;
private EventBusMethods busMethods;
@@ -120,11 +118,11 @@
private SearchBarHideHandler searchBarHideHandler;
private boolean isZeroEnabled;
private ZeroConfig currentZeroConfig;
- private ThemeChooserDialog themeChooser;
private RandomHandler randomHandler;
private NavDrawerHelper navDrawerHelper;
private boolean navItemSelected;
private WikipediaZeroUsageFunnel zeroFunnel;
+ private ExclusiveBottomSheetHandler bottomSheetHandler = new
ExclusiveBottomSheetHandler(this);
public View getContentView() {
return fragmentContainerView;
@@ -253,11 +251,6 @@
if (savedInstanceState != null) {
isZeroEnabled =
savedInstanceState.getBoolean("pausedZeroEnabledState");
currentZeroConfig =
savedInstanceState.getParcelable("pausedZeroConfig");
- if (savedInstanceState.containsKey("themeChooserShowing")) {
- if (savedInstanceState.getBoolean("themeChooserShowing")) {
- showThemeChooser();
- }
- }
if (savedInstanceState.getBoolean("isSearching")) {
searchFragment.openSearch();
}
@@ -678,27 +671,15 @@
}
public void showLinkPreview(PageTitle title, int entrySource, @Nullable
Location location) {
- if
(getSupportFragmentManager().findFragmentByTag(LINK_PREVIEW_FRAGMENT_TAG) ==
null) {
- DialogFragment linkPreview = LinkPreviewDialog.newInstance(title,
entrySource, location);
- linkPreview.show(getSupportFragmentManager(),
LINK_PREVIEW_FRAGMENT_TAG);
- }
+ bottomSheetHandler.show(LinkPreviewDialog.newInstance(title,
entrySource, location));
}
- /**
- * Dismiss the current link preview, if one is open.
- */
private void hideLinkPreview() {
- DialogFragment linkPreview = (DialogFragment)
getSupportFragmentManager().findFragmentByTag(LINK_PREVIEW_FRAGMENT_TAG);
- if (linkPreview != null) {
- linkPreview.dismiss();
- }
+ bottomSheetHandler.dismiss();
}
public void showThemeChooser() {
- if (themeChooser == null) {
- themeChooser = new ThemeChooserDialog(this);
- }
- themeChooser.show();
+ bottomSheetHandler.show(new ThemeChooserDialog());
}
// Note: back button first handled in {@link #onOptionsItemSelected()};
@@ -860,9 +841,6 @@
private void saveState(Bundle outState) {
outState.putBoolean("pausedZeroEnabledState", isZeroEnabled);
outState.putParcelable("pausedZeroConfig", currentZeroConfig);
- if (themeChooser != null) {
- outState.putBoolean("themeChooserShowing",
themeChooser.isShowing());
- }
outState.putBoolean("isSearching", isSearching());
outState.putString(LANGUAGE_CODE_BUNDLE_KEY,
app.getAppOrSystemLanguageCode());
}
@@ -891,11 +869,7 @@
@Override
protected void onStop() {
- if (themeChooser != null && themeChooser.isShowing()) {
- themeChooser.dismiss();
- }
app.getSessionFunnel().persistSession();
-
super.onStop();
}
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 3aa8740..bf0ab29 100755
--- a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
+++ b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
@@ -56,6 +56,7 @@
private GalleryThumbnailScrollView thumbnailGallery;
private View toolbarView;
private View overflowButton;
+ private Button goButton;
private PageTitle pageTitle;
private int entrySource;
@@ -123,7 +124,7 @@
toolbarView.setOnClickListener(goToPageListener);
View overlayRootView = addOverlay(inflater,
R.layout.dialog_link_preview_overlay);
- Button goButton = (Button)
overlayRootView.findViewById(R.id.link_preview_go_button);
+ goButton = (Button)
overlayRootView.findViewById(R.id.link_preview_go_button);
goButton.setOnClickListener(goToPageListener);
goButton.setText(getStringForArticleLanguage(pageTitle,
R.string.button_continue_to_article));
@@ -206,6 +207,7 @@
thumbnailGallery.setGalleryViewListener(null);
toolbarView.setOnClickListener(null);
overflowButton.setOnClickListener(null);
+ goButton.setOnClickListener(null);
super.onDestroyView();
}
diff --git a/app/src/main/java/org/wikipedia/theme/ThemeChooserDialog.java
b/app/src/main/java/org/wikipedia/theme/ThemeChooserDialog.java
index 41d1bde..d3326f1 100644
--- a/app/src/main/java/org/wikipedia/theme/ThemeChooserDialog.java
+++ b/app/src/main/java/org/wikipedia/theme/ThemeChooserDialog.java
@@ -1,7 +1,10 @@
package org.wikipedia.theme;
-import android.content.Context;
+import android.os.Bundle;
+import android.support.design.widget.BottomSheetDialogFragment;
+import android.view.LayoutInflater;
import android.view.View;
+import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ProgressBar;
import com.squareup.otto.Subscribe;
@@ -10,10 +13,9 @@
import org.wikipedia.WikipediaApp;
import org.wikipedia.analytics.AppearanceChangeFunnel;
import org.wikipedia.events.WebViewInvalidateEvent;
-import org.wikipedia.page.BottomDialog;
import org.wikipedia.settings.Prefs;
-public class ThemeChooserDialog extends BottomDialog {
+public class ThemeChooserDialog extends BottomSheetDialogFragment {
private WikipediaApp app;
private Button buttonDefaultTextSize;
private Button buttonDecreaseTextSize;
@@ -24,75 +26,83 @@
private boolean updatingFont = false;
private AppearanceChangeFunnel funnel;
- public ThemeChooserDialog(Context context) {
- super(context, R.layout.dialog_themechooser);
- app = WikipediaApp.getInstance();
- funnel = new AppearanceChangeFunnel(app, app.getSite());
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = inflater.inflate(R.layout.dialog_themechooser,
container);
- buttonDecreaseTextSize = (Button)
getDialogLayout().findViewById(R.id.buttonDecreaseTextSize);
+ buttonDecreaseTextSize = (Button)
rootView.findViewById(R.id.buttonDecreaseTextSize);
buttonDecreaseTextSize.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
updatingFont = true;
- float currentSize = app.getFontSize(getWindow());
+ float currentSize = app.getFontSize(getDialog().getWindow());
app.setFontSizeMultiplier(Prefs.getTextSizeMultiplier() - 1);
updateButtonState();
- funnel.logFontSizeChange(currentSize,
app.getFontSize(getWindow()));
+ funnel.logFontSizeChange(currentSize,
app.getFontSize(getDialog().getWindow()));
}
});
- buttonDefaultTextSize = (Button)
getDialogLayout().findViewById(R.id.buttonDefaultTextSize);
+ buttonDefaultTextSize = (Button)
rootView.findViewById(R.id.buttonDefaultTextSize);
buttonDefaultTextSize.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
updatingFont = true;
- float currentSize = app.getFontSize(getWindow());
+ float currentSize = app.getFontSize(getDialog().getWindow());
app.setFontSizeMultiplier(0);
updateButtonState();
- funnel.logFontSizeChange(currentSize,
app.getFontSize(getWindow()));
+ funnel.logFontSizeChange(currentSize,
app.getFontSize(getDialog().getWindow()));
}
});
- buttonIncreaseTextSize = (Button)
getDialogLayout().findViewById(R.id.buttonIncreaseTextSize);
+ buttonIncreaseTextSize = (Button)
rootView.findViewById(R.id.buttonIncreaseTextSize);
buttonIncreaseTextSize.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
updatingFont = true;
- float currentSize = app.getFontSize(getWindow());
+ float currentSize = app.getFontSize(getDialog().getWindow());
app.setFontSizeMultiplier(Prefs.getTextSizeMultiplier() + 1);
updateButtonState();
- funnel.logFontSizeChange(currentSize,
app.getFontSize(getWindow()));
+ funnel.logFontSizeChange(currentSize,
app.getFontSize(getDialog().getWindow()));
}
});
ThemeOnClickListener themeOnClickListener = new ThemeOnClickListener();
- buttonThemeLight = (Button)
getDialogLayout().findViewById(R.id.buttonColorsLight);
+ buttonThemeLight = (Button)
rootView.findViewById(R.id.buttonColorsLight);
buttonThemeLight.setOnClickListener(themeOnClickListener);
- buttonThemeDark = (Button)
getDialogLayout().findViewById(R.id.buttonColorsDark);
+ buttonThemeDark = (Button)
rootView.findViewById(R.id.buttonColorsDark);
buttonThemeDark.setOnClickListener(themeOnClickListener);
- fontChangeProgressBar = (ProgressBar)
getDialogLayout().findViewById(R.id.font_change_progress_bar);
+ fontChangeProgressBar = (ProgressBar)
rootView.findViewById(R.id.font_change_progress_bar);
updateButtonState();
+ return rootView;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ app = WikipediaApp.getInstance();
+ app.getBus().register(this);
+ funnel = new AppearanceChangeFunnel(app, app.getSite());
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ app.getBus().unregister(this);
}
@Subscribe
public void onWebViewInvalidated(WebViewInvalidateEvent event) {
updatingFont = false;
updateButtonState();
- }
-
- @Override
- public void show() {
- app.getBus().register(this);
- super.show();
- }
-
- @Override
- public void dismiss() {
- app.getBus().unregister(this);
- super.dismiss();
}
private void updateButtonState() {
--
To view, visit https://gerrit.wikimedia.org/r/277704
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I510afa1e88783fcd960f8097e317cb0ff497e50b
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits