From f328efb831262a1191da1b6a839643203b0fbdf1 Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Fri, 26 Feb 2021 19:24:17 +0100 Subject: [PATCH 1/2] Allow media to be played automatically (#1153) * Allow media to be played automatically * Fix for media been always autoplayed when opened from miniplayer --- .../main/java/io/lbry/browser/MainActivity.java | 6 ++++++ .../ui/findcontent/FileViewFragment.java | 17 +++++++++++------ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/settings.xml | 5 +++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/MainActivity.java b/app/src/main/java/io/lbry/browser/MainActivity.java index 522e1cdf..fcd34261 100644 --- a/app/src/main/java/io/lbry/browser/MainActivity.java +++ b/app/src/main/java/io/lbry/browser/MainActivity.java @@ -336,6 +336,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener // preference keys public static final String PREFERENCE_KEY_BACKGROUND_PLAYBACK = "io.lbry.browser.preference.userinterface.BackgroundPlayback"; + public static final String PREFERENCE_KEY_MEDIA_AUTOPLAY = "io.lbry.browser.preference.userinterface.MediaAutoplay"; public static final String PREFERENCE_KEY_DARK_MODE = "io.lbry.browser.preference.userinterface.DarkMode"; public static final String PREFERENCE_KEY_SHOW_MATURE_CONTENT = "io.lbry.browser.preference.userinterface.ShowMatureContent"; public static final String PREFERENCE_KEY_SHOW_URL_SUGGESTIONS = "io.lbry.browser.preference.userinterface.UrlSuggestions"; @@ -680,6 +681,11 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener return sp.getBoolean(PREFERENCE_KEY_BACKGROUND_PLAYBACK, true); } + public boolean isMediaAutoplayEnabled() { + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); + return sp.getBoolean(PREFERENCE_KEY_MEDIA_AUTOPLAY, true); + } + public boolean initialSubscriptionMergeDone() { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); return sp.getBoolean(PREFERENCE_KEY_INTERNAL_INITIAL_SUBSCRIPTION_MERGE_DONE, false); diff --git a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java index e04e5068..b2248c62 100644 --- a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java @@ -12,7 +12,6 @@ import android.graphics.Color; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; -import android.os.Handler; import android.text.Editable; import android.text.TextWatcher; import android.text.format.DateUtils; @@ -98,6 +97,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -284,14 +284,13 @@ public class FileViewFragment extends BaseFragment implements fileViewPlayerListener = new Player.EventListener() { @Override - public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { + public void onPlaybackStateChanged(@Player.State int playbackState) { if (playbackState == Player.STATE_READY) { elapsedDuration = MainActivity.appPlayer.getCurrentPosition(); totalDuration = MainActivity.appPlayer.getDuration() < 0 ? 0 : MainActivity.appPlayer.getDuration(); if (!playbackStarted) { logPlay(currentUrl, startTimeMillis); playbackStarted = true; - isPlaying = true; long lastPosition = loadLastPlaybackPosition(); if (lastPosition > -1) { @@ -303,7 +302,7 @@ public class FileViewFragment extends BaseFragment implements hideBuffering(); if (loadingNewClaim) { - MainActivity.appPlayer.setPlayWhenReady(true); + MainActivity.appPlayer.setPlayWhenReady(Objects.requireNonNull((MainActivity) (getActivity())).isMediaAutoplayEnabled()); loadingNewClaim = false; } } else if (playbackState == Player.STATE_BUFFERING) { @@ -340,6 +339,11 @@ public class FileViewFragment extends BaseFragment implements hideBuffering(); } } + + @Override + public void onIsPlayingChanged(boolean isPlayng) { + isPlaying = isPlayng; + } }; return root; @@ -1762,7 +1766,7 @@ public class FileViewFragment extends BaseFragment implements ((MainActivity) context).setNowPlayingClaim(claim, currentUrl); } - MainActivity.appPlayer.setPlayWhenReady(true); + MainActivity.appPlayer.setPlayWhenReady(Objects.requireNonNull((MainActivity) (getActivity())).isMediaAutoplayEnabled()); String userAgent = Util.getUserAgent(context, getString(R.string.app_name)); String mediaSourceUrl = getStreamingUrl(); MediaSource mediaSource = new ProgressiveMediaSource.Factory( @@ -1770,7 +1774,8 @@ public class FileViewFragment extends BaseFragment implements new DefaultExtractorsFactory() ).setLoadErrorHandlingPolicy(new StreamLoadErrorPolicy()).createMediaSource(Uri.parse(mediaSourceUrl)); - MainActivity.appPlayer.prepare(mediaSource, true, true); + MainActivity.appPlayer.setMediaSource(mediaSource, true); + MainActivity.appPlayer.prepare(); } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7463513e..5c4da9f9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -247,6 +247,7 @@ Content & User interface Other Enable background playback + Autoplay media files Enable dark theme Show mature content Show URL suggestions diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 6348a2d9..9f588829 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -10,6 +10,11 @@ app:defaultValue="true" app:title="@string/enable_background_playback" app:iconSpaceReserved="false" /> + Date: Fri, 26 Feb 2021 19:31:11 +0100 Subject: [PATCH 2/2] Hide support button and comments consistently with claim tags (#1152) * Hide support button and comments consistently with claim tags * Set visibility to GONE instead of INVISIBLE for the tipping button --- .../ui/channel/ChannelCommentsFragment.java | 16 +++++++++++-- .../browser/ui/channel/ChannelFragment.java | 5 ++++ .../ui/findcontent/FileViewFragment.java | 24 +++++++++++++++++-- .../res/layout/fragment_channel_comments.xml | 17 ++++++++++++- .../main/res/layout/fragment_file_view.xml | 16 ++++++++++++- app/src/main/res/values/strings.xml | 2 ++ 6 files changed, 74 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/ui/channel/ChannelCommentsFragment.java b/app/src/main/java/io/lbry/browser/ui/channel/ChannelCommentsFragment.java index c32d0f05..3374e963 100644 --- a/app/src/main/java/io/lbry/browser/ui/channel/ChannelCommentsFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/channel/ChannelCommentsFragment.java @@ -187,9 +187,21 @@ public class ChannelCommentsFragment extends Fragment implements SdkStatusListen private void checkAndLoadComments() { View root = getView(); if (root != null) { + View commentsDisabledText = root.findViewById(R.id.channel_disabled_comments); + View commentForm = root.findViewById(R.id.container_comment_form); RecyclerView commentsList = root.findViewById(R.id.channel_comments_list); - if (commentsList == null || commentsList.getAdapter() == null || commentsList.getAdapter().getItemCount() == 0) { - loadComments(); + + if (claim.getTags().contains("disable-comments")) { + Helper.setViewVisibility(commentsDisabledText, View.VISIBLE); + Helper.setViewVisibility(commentForm, View.GONE); + Helper.setViewVisibility(commentsList, View.GONE); + } else { + Helper.setViewVisibility(commentsDisabledText, View.GONE); + Helper.setViewVisibility(commentForm, View.VISIBLE); + Helper.setViewVisibility(commentsList, View.VISIBLE); + if (commentsList == null || commentsList.getAdapter() == null || commentsList.getAdapter().getItemCount() == 0) { + loadComments(); + } } } } diff --git a/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java b/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java index f7bb34e3..d42d125e 100644 --- a/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java @@ -503,6 +503,11 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen layoutLoadingState.setVisibility(View.GONE); layoutDisplayArea.setVisibility(View.VISIBLE); + if (claim.getTags().contains("disable-support")) + buttonTip.setVisibility(View.GONE); + else + buttonTip.setVisibility(View.VISIBLE); + String thumbnailUrl = claim.getThumbnailUrl(); String coverUrl = claim.getCoverUrl(); textTitle.setText(Helper.isNullOrEmpty(claim.getTitle()) ? claim.getName() : claim.getTitle()); diff --git a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java index b2248c62..5db02284 100644 --- a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java @@ -210,6 +210,8 @@ public class FileViewFragment extends BaseFragment implements private View layoutResolving; private int lastPositionSaved; + private View tipButton; + private WebView webView; private boolean webViewAdded; @@ -255,6 +257,8 @@ public class FileViewFragment extends BaseFragment implements layoutDisplayArea = root.findViewById(R.id.file_view_claim_display_area); buttonPublishSomething = root.findViewById(R.id.nothing_at_location_publish_button); + tipButton = root.findViewById(R.id.file_view_action_tip); + containerReplyToComment = root.findViewById(R.id.comment_form_reply_to_container); textReplyingTo = root.findViewById(R.id.comment_form_replying_to_text); textReplyToBody = root.findViewById(R.id.comment_form_reply_to_body); @@ -1497,6 +1501,11 @@ public class FileViewFragment extends BaseFragment implements Helper.setViewVisibility(layoutLoadingState, View.GONE); Helper.setViewVisibility(layoutNothingAtLocation, View.GONE); + if (claim.getTags().contains("disable-support") || claim.getSigningChannel().getTags().contains("disable-support")) + Helper.setViewVisibility(tipButton, View.GONE); + else + Helper.setViewVisibility(tipButton, View.VISIBLE); + loadViewCount(); checkIsFollowing(); @@ -1679,9 +1688,20 @@ public class FileViewFragment extends BaseFragment implements private void checkAndLoadComments() { View root = getView(); if (root != null) { + View commentsDisabledText = root.findViewById(R.id.file_view_disabled_comments); + View commentForm = root.findViewById(R.id.container_comment_form); RecyclerView commentsList = root.findViewById(R.id.file_view_comments_list); - if (commentsList == null || commentsList.getAdapter() == null || commentsList.getAdapter().getItemCount() == 0) { - loadComments(); + if (claim.getTags().contains("disable-comments") || claim.getSigningChannel().getTags().contains("disable-comments")) { + Helper.setViewVisibility(commentsDisabledText, View.VISIBLE); + Helper.setViewVisibility(commentForm, View.GONE); + Helper.setViewVisibility(commentsList, View.GONE); + } else { + Helper.setViewVisibility(commentsDisabledText, View.GONE); + Helper.setViewVisibility(commentForm, View.VISIBLE); + Helper.setViewVisibility(commentsList, View.VISIBLE); + if (commentsList == null || commentsList.getAdapter() == null || commentsList.getAdapter().getItemCount() == 0) { + loadComments(); + } } } } diff --git a/app/src/main/res/layout/fragment_channel_comments.xml b/app/src/main/res/layout/fragment_channel_comments.xml index d2c65ea2..75834a08 100644 --- a/app/src/main/res/layout/fragment_channel_comments.xml +++ b/app/src/main/res/layout/fragment_channel_comments.xml @@ -28,12 +28,27 @@ android:orientation="vertical"> + android:layout_marginBottom="16dp" + android:visibility="gone" /> + + - + + + No comments to display at this time. Comments will display after the background service is initialized. Your comment could not be posted at this time. Please try again later. + This channel has disabled comments on their page. + The creator of this content has disabled comments. Share LBRY content View Play