From 808ce72078684462980f63b8abf915b9b8939a75 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Thu, 4 Jan 2018 05:28:01 +0100 Subject: [PATCH] fix share menu for playlists --- app/build.gradle | 2 +- .../newpipe/fragments/BaseStateFragment.java | 18 ++++++++++ .../fragments/detail/VideoDetailFragment.java | 11 ++----- .../list/channel/ChannelFragment.java | 16 ++------- .../fragments/list/kiosk/KioskFragment.java | 4 --- .../list/playlist/PlaylistFragment.java | 33 +++++++++++++++---- 6 files changed, 49 insertions(+), 35 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 50fa6ab12..66fdc2b24 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -55,7 +55,7 @@ dependencies { exclude module: 'support-annotations' } - implementation 'com.github.TeamNewPipe:NewPipeExtractor:044b8fe32f47e28' + implementation 'com.github.TeamNewPipe:NewPipeExtractor:5f2d0cf6b5dfac2965b1cf400' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:1.10.19' diff --git a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java index a6c8f5fcc..2ee467758 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java @@ -1,6 +1,7 @@ package org.schabi.newpipe.fragments; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.annotation.StringRes; @@ -240,4 +241,21 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC ErrorActivity.reportError(getContext(), exception, MainActivity.class, rootView, ErrorActivity.ErrorInfo.make(userAction, serviceName, request, errorId)); } + + /*////////////////////////////////////////////////////////////////////////// + // Utils + //////////////////////////////////////////////////////////////////////////*/ + + + protected void openUrlInBrowser(String url) { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + startActivity(intent); + } + + protected void shareUrl(String url) { + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_TEXT, url); + startActivity(Intent.createChooser(intent, getString(R.string.share_dialog_title))); + } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 5b445e813..fdf6ca5bb 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -626,21 +626,14 @@ public class VideoDetailFragment extends BaseStateFragment implement actionBarHandler.setOnShareListener(new ActionBarHandler.OnActionListener() { @Override public void onActionSelected(int selectedStreamId) { - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_SEND); - intent.putExtra(Intent.EXTRA_TEXT, info.getUrl()); - intent.setType("text/plain"); - startActivity(Intent.createChooser(intent, activity.getString(R.string.share_dialog_title))); + shareUrl(info.getUrl()); } }); actionBarHandler.setOnOpenInBrowserListener(new ActionBarHandler.OnActionListener() { @Override public void onActionSelected(int selectedStreamId) { - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_VIEW); - intent.setData(Uri.parse(info.getUrl())); - startActivity(Intent.createChooser(intent, activity.getString(R.string.choose_browser))); + openUrlInBrowser(info.getUrl()); } }); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 7a2c65898..89f43795a 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -222,18 +222,6 @@ public class ChannelFragment extends BaseListInfoFragment { } } - private void openChannelUriInBrowser() { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - startActivity(intent); - } - - private void shareChannelUri() { - Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType("text/plain"); - intent.putExtra(Intent.EXTRA_TEXT, url); - startActivity(Intent.createChooser(intent, getString(R.string.share_dialog_title))); - } - @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { @@ -241,10 +229,10 @@ public class ChannelFragment extends BaseListInfoFragment { openRssFeed(); break; case R.id.menu_item_openInBrowser: - openChannelUriInBrowser(); + openUrlInBrowser(url); break; case R.id.menu_item_share: { - shareChannelUri(); + shareUrl(url); break; } default: diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java index ad0d0432f..037556c5c 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java @@ -58,14 +58,10 @@ public class KioskFragment extends BaseListInfoFragment { @State protected String kioskId = ""; - /*////////////////////////////////////////////////////////////////////////// // Views //////////////////////////////////////////////////////////////////////////*/ - private View headerRootLayout; - private TextView headerTitleView; - public static KioskFragment getInstance(int serviceId) throws ExtractionException { return getInstance(serviceId, NewPipe.getService(serviceId) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index 4f87228a5..fcddafef6 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -12,6 +12,7 @@ import android.view.Gravity; 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 android.widget.ImageView; @@ -98,13 +99,6 @@ public class PlaylistFragment extends BaseListInfoFragment { infoListAdapter.useMiniItemVariants(true); } - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu + "], inflater = [" + inflater + "]"); - super.onCreateOptionsMenu(menu, inflater); - inflater.inflate(R.menu.menu_playlist, menu); - } - @Override protected void showStreamDialog(final StreamInfoItem item) { final Context context = getContext(); @@ -146,6 +140,14 @@ public class PlaylistFragment extends BaseListInfoFragment { new InfoItemDialog(getActivity(), item, commands, actions).show(); } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu + "], inflater = [" + inflater + "]"); + super.onCreateOptionsMenu(menu, inflater); + inflater.inflate(R.menu.menu_playlist, menu); + } + /*////////////////////////////////////////////////////////////////////////// // Load and handle //////////////////////////////////////////////////////////////////////////*/ @@ -160,6 +162,23 @@ public class PlaylistFragment extends BaseListInfoFragment { return ExtractorHelper.getPlaylistInfo(serviceId, url, forceLoad); } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_item_openInBrowser: + openUrlInBrowser(url); + break; + case R.id.menu_item_share: { + shareUrl(url); + break; + } + default: + return super.onOptionsItemSelected(item); + } + return true; + } + + /*////////////////////////////////////////////////////////////////////////// // Contract //////////////////////////////////////////////////////////////////////////*/