This commit is contained in:
Javi Rueda 2021-03-01 23:26:55 +01:00
commit 7c7795476f
8 changed files with 97 additions and 12 deletions

View file

@ -314,6 +314,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";
@ -627,6 +628,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);

View file

@ -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();
}
}
}
}

View file

@ -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());

View file

@ -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;
@ -209,6 +209,8 @@ public class FileViewFragment extends BaseFragment implements
private View layoutResolving;
private int lastPositionSaved;
private View tipButton;
private WebView webView;
private boolean webViewAdded;
@ -254,6 +256,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);
@ -283,14 +287,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) {
@ -302,7 +305,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) {
@ -339,6 +342,11 @@ public class FileViewFragment extends BaseFragment implements
hideBuffering();
}
}
@Override
public void onIsPlayingChanged(boolean isPlayng) {
isPlaying = isPlayng;
}
};
return root;
@ -1485,6 +1493,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();
@ -1667,9 +1680,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();
}
}
}
}
@ -1754,7 +1778,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(
@ -1762,7 +1786,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();
}
}
}

View file

@ -28,12 +28,27 @@
android:orientation="vertical">
<include layout="@layout/container_comment_form"
android:id="@+id/container_comment_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp" />
android:layout_marginBottom="16dp"
android:visibility="gone" />
<TextView
android:id="@+id/channel_disabled_comments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:fontFamily="@font/inter"
android:text="@string/channel_disabled_comments"
android:textFontWeight="300"
android:textSize="14sp"
android:visibility="gone" />
<TextView
android:id="@+id/channel_no_comments"

View file

@ -845,7 +845,21 @@
android:textSize="16sp" />
</RelativeLayout>
<include layout="@layout/container_comment_form" />
<include layout="@layout/container_comment_form"
android:id="@+id/container_comment_form"/>
<TextView
android:id="@+id/file_view_disabled_comments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:fontFamily="@font/inter"
android:text="@string/creator_disabled_comments"
android:textFontWeight="300"
android:textSize="14sp"
android:visibility="gone" />
<TextView
android:id="@+id/file_view_no_comments"

View file

@ -64,6 +64,8 @@
<string name="no_comments">No comments to display at this time.</string>
<string name="sdk_initializing_comments">Comments will display after the background service is initialized.</string>
<string name="comment_error">Your comment could not be posted at this time. Please try again later.</string>
<string name="channel_disabled_comments">This channel has disabled comments on their page.</string>
<string name="creator_disabled_comments">The creator of this content has disabled comments.</string>
<string name="share_lbry_content">Share LBRY content</string>
<string name="view">View</string>
<string name="play">Play</string>
@ -247,6 +249,7 @@
<string name="user_interface">Content &amp; User interface</string>
<string name="other">Other</string>
<string name="enable_background_playback">Enable background playback</string>
<string name="enable_autoplay">Autoplay media files</string>
<string name="enable_dark_mode">Enable dark theme</string>
<string name="show_mature_content">Show mature content</string>
<string name="show_url_suggestions">Show URL suggestions</string>

View file

@ -10,6 +10,11 @@
app:defaultValue="true"
app:title="@string/enable_background_playback"
app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
app:key="io.lbry.browser.preference.userinterface.MediaAutoplay"
app:defaultValue="true"
app:title="@string/enable_autoplay"
app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
app:key="io.lbry.browser.preference.userinterface.DarkMode"
app:title="@string/enable_dark_mode"