Dbrant has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311141

Change subject: Show overflow menu (Login, etc) in Feed fragment only.
......................................................................

Show overflow menu (Login, etc) in Feed fragment only.

Bug: T144028
Change-Id: Ia8b04672b0dbc694b795674e069519adb4292b25
---
M app/src/main/java/org/wikipedia/MainActivity.java
M app/src/main/java/org/wikipedia/MainFragment.java
M app/src/main/java/org/wikipedia/feed/FeedFragment.java
M app/src/main/res/menu/menu_feed.xml
D app/src/main/res/menu/menu_main.xml
5 files changed, 89 insertions(+), 100 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/41/311141/1

diff --git a/app/src/main/java/org/wikipedia/MainActivity.java 
b/app/src/main/java/org/wikipedia/MainActivity.java
index a4f9383..ea35ded 100644
--- a/app/src/main/java/org/wikipedia/MainActivity.java
+++ b/app/src/main/java/org/wikipedia/MainActivity.java
@@ -50,7 +50,7 @@
     @Nullable
     @Override
     public View getOverflowMenuButton() {
-        return getToolbar().findViewById(R.id.main_menu_overflow);
+        return getToolbar().findViewById(R.id.menu_overflow_button);
     }
 
     @Override
diff --git a/app/src/main/java/org/wikipedia/MainFragment.java 
b/app/src/main/java/org/wikipedia/MainFragment.java
index 3830523..d9da094 100644
--- a/app/src/main/java/org/wikipedia/MainFragment.java
+++ b/app/src/main/java/org/wikipedia/MainFragment.java
@@ -6,7 +6,6 @@
 import android.content.Intent;
 import android.graphics.Bitmap;
 import android.location.Location;
-import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.speech.RecognizerIntent;
@@ -16,16 +15,12 @@
 import android.support.v4.app.Fragment;
 import android.support.v4.view.ViewPager;
 import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 
 import org.wikipedia.activity.FragmentUtil;
 import org.wikipedia.analytics.GalleryFunnel;
 import org.wikipedia.analytics.IntentFunnel;
-import org.wikipedia.analytics.LoginFunnel;
 import org.wikipedia.feed.FeedFragment;
 import org.wikipedia.feed.image.FeaturedImage;
 import org.wikipedia.feed.image.FeaturedImageCard;
@@ -50,15 +45,12 @@
 import org.wikipedia.search.SearchInvokeSource;
 import org.wikipedia.search.SearchResultsFragment;
 import org.wikipedia.settings.Prefs;
-import org.wikipedia.settings.SettingsActivity;
 import org.wikipedia.util.ClipboardUtil;
 import org.wikipedia.util.DateUtil;
 import org.wikipedia.util.FeedbackUtil;
 import org.wikipedia.util.PermissionUtil;
 import org.wikipedia.util.ShareUtil;
-import org.wikipedia.util.UriUtil;
 import org.wikipedia.util.log.L;
-import org.wikipedia.views.ExploreOverflowView;
 
 import java.io.File;
 import java.util.concurrent.TimeUnit;
@@ -77,7 +69,6 @@
     private Unbinder unbinder;
     private SearchFragment searchFragment;
     private ExclusiveBottomSheetPresenter bottomSheetPresenter;
-    private OverflowCallback overflowCallback = new OverflowCallback();
 
     // The permissions request API doesn't take a callback, so in the event we 
have to
     // ask for permission to download a featured image from the feed, we'll 
have to hold
@@ -156,36 +147,6 @@
     }
 
     @Override
-    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
-        super.onCreateOptionsMenu(menu, inflater);
-        inflater.inflate(R.menu.menu_main, menu);
-        viewPager.post(new Runnable() {
-            @Override
-            public void run() {
-                setUpOverflowButton();
-            }
-        });
-    }
-
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        switch (item.getItemId()) {
-            case R.id.main_menu_overflow:
-                Callback callback = callback();
-                if (callback == null) {
-                    return false;
-                }
-                View overflowButton = callback.getOverflowMenuButton();
-                if (overflowButton != null) {
-                    showOverflowMenu(overflowButton);
-                }
-                return true;
-            default:
-                return super.onOptionsItemSelected(item);
-        }
-    }
-
-    @Override
     public void onRequestPermissionsResult(int requestCode,
                                            @NonNull String[] permissions,
                                            @NonNull int[] grantResults) {
@@ -226,23 +187,6 @@
             openSearchFromIntent(null, SearchInvokeSource.WIDGET);
         } else if (lastPageViewedWithin(1)) {
             startActivity(PageActivity.newIntent(getContext()));
-        }
-    }
-
-    private void setUpOverflowButton() {
-        Callback callback = callback();
-        if (callback == null) {
-            return;
-        }
-        View overflowButton = callback.getOverflowMenuButton();
-        if (overflowButton != null) {
-            overflowButton.setOnLongClickListener(new 
View.OnLongClickListener() {
-                @Override
-                public boolean onLongClick(View view) {
-                    showOverflowMenu(view);
-                    return true;
-                }
-            });
         }
     }
 
@@ -315,6 +259,13 @@
         startActivityForResult(GalleryActivity.newIntent(getActivity(), 
card.baseImage(),
                 card.filename(), card.site(), 
GalleryFunnel.SOURCE_FEED_FEATURED_IMAGE),
                 Constants.ACTIVITY_REQUEST_GALLERY);
+    }
+
+    @Nullable
+    @Override
+    public View getOverflowMenuButton() {
+        Callback callback = callback();
+        return callback == null ? null : callback.getOverflowMenuButton();
     }
 
     @Override public void onLoading() {
@@ -468,39 +419,6 @@
     private void requestWriteExternalStoragePermission() {
         PermissionUtil.requestWriteStorageRuntimePermissions(this,
                 Constants.ACTIVITY_REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION);
-    }
-
-    private void showOverflowMenu(@NonNull View anchor) {
-        ExploreOverflowView overflowView = new 
ExploreOverflowView(getContext());
-        overflowView.show(anchor, overflowCallback);
-    }
-
-    private class OverflowCallback implements ExploreOverflowView.Callback {
-        @Override
-        public void loginClick() {
-            startActivityForResult(LoginActivity.newIntent(getContext(), 
LoginFunnel.SOURCE_NAV),
-                    Constants.ACTIVITY_REQUEST_LOGIN);
-        }
-
-        @Override
-        public void settingsClick() {
-            startActivityForResult(SettingsActivity.newIntent(getContext()),
-                    SettingsActivity.ACTIVITY_REQUEST_SHOW_SETTINGS);
-        }
-
-        @Override
-        public void donateClick() {
-            UriUtil.visitInExternalBrowser(getContext(),
-                    Uri.parse(String.format(getString(R.string.donate_url),
-                            BuildConfig.VERSION_NAME,
-                            
WikipediaApp.getInstance().getSystemLanguageCode())));
-        }
-
-        @Override
-        public void logoutClick() {
-            WikipediaApp.getInstance().logOut();
-            FeedbackUtil.showMessage(MainFragment.this, 
R.string.toast_logout_complete);
-        }
     }
 
     @Nullable private Callback callback() {
diff --git a/app/src/main/java/org/wikipedia/feed/FeedFragment.java 
b/app/src/main/java/org/wikipedia/feed/FeedFragment.java
index 3693135..22de60a 100644
--- a/app/src/main/java/org/wikipedia/feed/FeedFragment.java
+++ b/app/src/main/java/org/wikipedia/feed/FeedFragment.java
@@ -1,5 +1,6 @@
 package org.wikipedia.feed;
 
+import android.net.Uri;
 import android.os.Bundle;
 import android.support.annotation.IntRange;
 import android.support.annotation.NonNull;
@@ -16,10 +17,13 @@
 import android.view.ViewGroup;
 
 import org.wikipedia.BackPressedHandler;
+import org.wikipedia.BuildConfig;
+import org.wikipedia.Constants;
 import org.wikipedia.R;
 import org.wikipedia.WikipediaApp;
 import org.wikipedia.activity.FragmentUtil;
 import org.wikipedia.analytics.FeedFunnel;
+import org.wikipedia.analytics.LoginFunnel;
 import org.wikipedia.feed.image.FeaturedImage;
 import org.wikipedia.feed.image.FeaturedImageCard;
 import org.wikipedia.feed.model.Card;
@@ -28,10 +32,14 @@
 import org.wikipedia.feed.view.FeedView;
 import org.wikipedia.feed.view.FeedViewCallback;
 import org.wikipedia.history.HistoryEntry;
+import org.wikipedia.login.LoginActivity;
 import org.wikipedia.settings.Prefs;
+import org.wikipedia.settings.SettingsActivity;
 import org.wikipedia.util.DimenUtil;
 import org.wikipedia.util.FeedbackUtil;
 import org.wikipedia.util.ResourceUtil;
+import org.wikipedia.util.UriUtil;
+import org.wikipedia.views.ExploreOverflowView;
 
 import java.util.List;
 
@@ -47,6 +55,7 @@
     private FeedCoordinator coordinator;
     private FeedFunnel funnel;
     private FeedViewCallback feedCallback = new FeedCallback();
+    private OverflowCallback overflowCallback = new OverflowCallback();
     private FeedHeaderOffsetChangedListener headerOffsetChangedListener = new 
FeedHeaderOffsetChangedListener();
     private int searchIconShowThresholdPx;
     private boolean searchIconVisible;
@@ -62,6 +71,7 @@
         void onFeedShareImage(FeaturedImageCard card);
         void onFeedDownloadImage(FeaturedImage image);
         void onFeaturedImageSelected(FeaturedImageCard card);
+        @Nullable View getOverflowMenuButton();
     }
 
     @NonNull public static FeedFragment newInstance() {
@@ -129,7 +139,14 @@
 
     @Override
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+        super.onCreateOptionsMenu(menu, inflater);
         inflater.inflate(R.menu.menu_feed, menu);
+        swipeRefreshLayout.post(new Runnable() {
+            @Override
+            public void run() {
+                setUpOverflowButton();
+            }
+        });
     }
 
     @Override
@@ -157,6 +174,16 @@
             case R.id.menu_feed_tabs:
                 if (getCallback() != null) {
                     getCallback().onFeedTabListRequested();
+                }
+                return true;
+            case R.id.menu_overflow_button:
+                Callback callback = getCallback();
+                if (callback == null) {
+                    return false;
+                }
+                View overflowButton = callback.getOverflowMenuButton();
+                if (overflowButton != null) {
+                    showOverflowMenu(overflowButton);
                 }
                 return true;
             default:
@@ -281,4 +308,54 @@
         });
         snackbar.show();
     }
+
+    private void setUpOverflowButton() {
+        Callback callback = getCallback();
+        if (callback == null) {
+            return;
+        }
+        View overflowButton = callback.getOverflowMenuButton();
+        if (overflowButton != null) {
+            overflowButton.setOnLongClickListener(new 
View.OnLongClickListener() {
+                @Override
+                public boolean onLongClick(View view) {
+                    showOverflowMenu(view);
+                    return true;
+                }
+            });
+        }
+    }
+
+    private void showOverflowMenu(@NonNull View anchor) {
+        ExploreOverflowView overflowView = new 
ExploreOverflowView(getContext());
+        overflowView.show(anchor, overflowCallback);
+    }
+
+    private class OverflowCallback implements ExploreOverflowView.Callback {
+        @Override
+        public void loginClick() {
+            startActivityForResult(LoginActivity.newIntent(getContext(), 
LoginFunnel.SOURCE_NAV),
+                    Constants.ACTIVITY_REQUEST_LOGIN);
+        }
+
+        @Override
+        public void settingsClick() {
+            startActivityForResult(SettingsActivity.newIntent(getContext()),
+                    SettingsActivity.ACTIVITY_REQUEST_SHOW_SETTINGS);
+        }
+
+        @Override
+        public void donateClick() {
+            UriUtil.visitInExternalBrowser(getContext(),
+                    Uri.parse(String.format(getString(R.string.donate_url),
+                            BuildConfig.VERSION_NAME,
+                            
WikipediaApp.getInstance().getSystemLanguageCode())));
+        }
+
+        @Override
+        public void logoutClick() {
+            WikipediaApp.getInstance().logOut();
+            FeedbackUtil.showMessage(FeedFragment.this, 
R.string.toast_logout_complete);
+        }
+    }
 }
diff --git a/app/src/main/res/menu/menu_feed.xml 
b/app/src/main/res/menu/menu_feed.xml
index 9a06f19..2cabd05 100644
--- a/app/src/main/res/menu/menu_feed.xml
+++ b/app/src/main/res/menu/menu_feed.xml
@@ -9,4 +9,8 @@
     <item android:id="@+id/menu_feed_tabs"
         android:title="@string/menu_page_show_tabs"
         app:showAsAction="ifRoom"/>
+    <item android:id="@+id/menu_overflow_button"
+        android:title="@null"
+        android:icon="@drawable/ic_more_vert_white_24dp"
+        app:showAsAction="ifRoom"/>
 </menu>
diff --git a/app/src/main/res/menu/menu_main.xml 
b/app/src/main/res/menu/menu_main.xml
deleted file mode 100644
index ff853a8..0000000
--- a/app/src/main/res/menu/menu_main.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<menu xmlns:android="http://schemas.android.com/apk/res/android";
-      xmlns:app="http://schemas.android.com/apk/res-auto";>
-    <item android:id="@+id/main_menu_overflow"
-        android:title="@null"
-        android:icon="@drawable/ic_more_vert_white_24dp"
-        android:orderInCategory="100"
-        app:showAsAction="ifRoom"/>
-</menu>

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia8b04672b0dbc694b795674e069519adb4292b25
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <dbr...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to