mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-15 20:53:07 +01:00
Add an option to disable autoplaying nsfw videos. Support imgur gifv videos.
This commit is contained in:
parent
e5d9f93e96
commit
c37cc1bed3
@ -7,6 +7,7 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@ -213,6 +214,13 @@ public class LinkResolverActivity extends AppCompatActivity {
|
||||
intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_TYPE, ViewImgurMediaActivity.IMGUR_TYPE_IMAGE);
|
||||
intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_ID, path.substring(1));
|
||||
startActivity(intent);
|
||||
} else if (path.endsWith("gifv")) {
|
||||
String url = uri.toString();
|
||||
url = url.substring(0, url.length() - 5) + ".mp4";
|
||||
Intent intent = new Intent(this, ViewVideoActivity.class);
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_DIRECT);
|
||||
intent.setData(Uri.parse(url));
|
||||
startActivity(intent);
|
||||
} else {
|
||||
deepLinkError(uri);
|
||||
}
|
||||
|
@ -154,6 +154,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
private boolean mShowCommentDivider;
|
||||
private boolean mShowAbsoluteNumberOfVotes;
|
||||
private boolean mAutoplay = false;
|
||||
private boolean mAutoplayNsfwVideos;
|
||||
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
|
||||
private boolean isInitiallyLoading;
|
||||
private boolean isInitiallyLoadingFailed;
|
||||
@ -317,6 +318,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
} else if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
|
||||
mAutoplay = Utils.isConnectedToWifi(activity);
|
||||
}
|
||||
mAutoplayNsfwVideos = mSharedPreferences.getBoolean(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS, true);
|
||||
|
||||
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
|
||||
isInitiallyLoading = true;
|
||||
@ -382,12 +384,18 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
switch (mPost.getPostType()) {
|
||||
case Post.VIDEO_TYPE:
|
||||
if (mAutoplay) {
|
||||
if (!mAutoplayNsfwVideos && mPost.isNSFW()) {
|
||||
return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW;
|
||||
}
|
||||
return VIEW_TYPE_POST_DETAIL_VIDEO_AUTOPLAY;
|
||||
} else {
|
||||
return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW;
|
||||
}
|
||||
case Post.GIF_TYPE:
|
||||
if (mAutoplay) {
|
||||
if (!mAutoplayNsfwVideos && mPost.isNSFW()) {
|
||||
return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW;
|
||||
}
|
||||
return VIEW_TYPE_POST_DETAIL_IMAGE_AND_GIF_AUTOPLAY;
|
||||
} else {
|
||||
return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW;
|
||||
|
@ -162,6 +162,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
private boolean mShowDividerInCompactLayout;
|
||||
private boolean mShowAbsoluteNumberOfVotes;
|
||||
private boolean mAutoplay = false;
|
||||
private boolean mAutoplayNsfwVideos;
|
||||
private Drawable mCommentIcon;
|
||||
private NetworkState networkState;
|
||||
private ExoCreator mExoCreator;
|
||||
@ -194,6 +195,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
} else if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
|
||||
mAutoplay = Utils.isConnectedToWifi(activity);
|
||||
}
|
||||
mAutoplayNsfwVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS, true);
|
||||
mPostLayout = postLayout;
|
||||
|
||||
mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme();
|
||||
@ -260,11 +262,17 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
switch (post.getPostType()) {
|
||||
case Post.VIDEO_TYPE:
|
||||
if (mAutoplay) {
|
||||
if (!mAutoplayNsfwVideos && post.isNSFW()) {
|
||||
return VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE;
|
||||
}
|
||||
return VIEW_TYPE_POST_CARD_VIDEO_TYPE_AUTOPLAY;
|
||||
}
|
||||
return VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE;
|
||||
case Post.GIF_TYPE:
|
||||
if (mAutoplay) {
|
||||
if (!mAutoplayNsfwVideos && post.isNSFW()) {
|
||||
return VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE;
|
||||
}
|
||||
return VIEW_TYPE_POST_CARD_IMAGE_AND_GIF_AUTOPLAY_TYPE;
|
||||
}
|
||||
return VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE;
|
||||
@ -1309,6 +1317,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
return mAutoplay;
|
||||
}
|
||||
|
||||
public void setAutoplayNsfwVideos(boolean autoplayNsfwVideos) {
|
||||
mAutoplayNsfwVideos = autoplayNsfwVideos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
||||
super.onViewRecycled(holder);
|
||||
|
@ -0,0 +1,9 @@
|
||||
package ml.docilealligator.infinityforreddit.Event;
|
||||
|
||||
public class ChangeAutoplayNsfwVideosEvent {
|
||||
public boolean autoplayNsfwVideos;
|
||||
|
||||
public ChangeAutoplayNsfwVideosEvent(boolean autoplayNsfwVideos) {
|
||||
this.autoplayNsfwVideos = autoplayNsfwVideos;
|
||||
}
|
||||
}
|
@ -57,6 +57,7 @@ import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity
|
||||
import ml.docilealligator.infinityforreddit.Adapter.PostRecyclerViewAdapter;
|
||||
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
||||
import ml.docilealligator.infinityforreddit.CustomView.CustomToroContainer;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeAutoplayNsfwVideosEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent;
|
||||
@ -883,6 +884,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onChangeAutoplayNsfwVideosEvent(ChangeAutoplayNsfwVideosEvent changeAutoplayNsfwVideosEvent) {
|
||||
if (mAdapter != null) {
|
||||
mAdapter.setAutoplayNsfwVideos(changeAutoplayNsfwVideosEvent.autoplayNsfwVideos);
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onChangeWifiStatusEvent(ChangeWifiStatusEvent changeWifiStatusEvent) {
|
||||
if (mAdapter != null) {
|
||||
|
@ -0,0 +1,37 @@
|
||||
package ml.docilealligator.infinityforreddit.Settings;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeAutoplayNsfwVideosEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeVideoAutoplayEvent;
|
||||
import ml.docilealligator.infinityforreddit.R;
|
||||
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
|
||||
|
||||
public class AutoplayPreferenceFragment extends PreferenceFragmentCompat {
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
setPreferencesFromResource(R.xml.autoplay_preferences, rootKey);
|
||||
|
||||
ListPreference videoAutoplayListPreference = findPreference(SharedPreferencesUtils.VIDEO_AUTOPLAY);
|
||||
SwitchPreference autoplayNsfwVideosSwitchPreference = findPreference(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS);
|
||||
|
||||
if (videoAutoplayListPreference != null && autoplayNsfwVideosSwitchPreference != null) {
|
||||
videoAutoplayListPreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
EventBus.getDefault().post(new ChangeVideoAutoplayEvent((String) newValue));
|
||||
return true;
|
||||
});
|
||||
|
||||
autoplayNsfwVideosSwitchPreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
EventBus.getDefault().post(new ChangeAutoplayNsfwVideosEvent((Boolean) newValue));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
@ -19,15 +18,11 @@ import javax.inject.Named;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeVideoAutoplayEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent;
|
||||
import ml.docilealligator.infinityforreddit.Infinity;
|
||||
import ml.docilealligator.infinityforreddit.R;
|
||||
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
|
||||
|
||||
/**
|
||||
* A simple {@link PreferenceFragmentCompat} subclass.
|
||||
*/
|
||||
public class MainPreferenceFragment extends PreferenceFragmentCompat {
|
||||
|
||||
@Inject
|
||||
@ -40,18 +35,11 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat {
|
||||
setPreferencesFromResource(R.xml.main_preferences, rootKey);
|
||||
((Infinity) activity.getApplication()).getAppComponent().inject(this);
|
||||
|
||||
ListPreference videoAutoplaySwitch = findPreference(SharedPreferencesUtils.VIDEO_AUTOPLAY);
|
||||
SwitchPreference confirmToExitSwitch = findPreference(SharedPreferencesUtils.CONFIRM_TO_EXIT);
|
||||
SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY);
|
||||
SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY);
|
||||
SwitchPreference blurSpoilerSwitch = findPreference(SharedPreferencesUtils.BLUR_SPOILER_KEY);
|
||||
|
||||
if (videoAutoplaySwitch != null) {
|
||||
videoAutoplaySwitch.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
EventBus.getDefault().post(new ChangeVideoAutoplayEvent((String) newValue));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
if (confirmToExitSwitch != null) {
|
||||
confirmToExitSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
EventBus.getDefault().post(new RecreateActivityEvent());
|
||||
|
@ -80,6 +80,7 @@ public class SharedPreferencesUtils {
|
||||
public static final String VIDEO_AUTOPLAY_VALUE_ALWAYS_ON = "2";
|
||||
public static final String VIDEO_AUTOPLAY_VALUE_ON_WIFI = "1";
|
||||
public static final String VIDEO_AUTOPLAY_VALUE_NEVER = "0";
|
||||
public static final String AUTOPLAY_NSFW_VIDEOS = "autoplay_nsfw_videos";
|
||||
public static final String LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON = "lock_jump_to_next_top_level_comment_button";
|
||||
public static final String SWAP_TAP_AND_LONG_COMMENTS = "swap_tap_and_long_in_comments";
|
||||
public static final String SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON = "swipe_up_to_hide_jump_to_next_top_level_comments_button";
|
||||
|
@ -320,6 +320,7 @@
|
||||
<string name="settings_gestures_and_buttons_title">Gestures & Buttons</string>
|
||||
<string name="settings_open_link_in_app_title">Open Link In App</string>
|
||||
<string name="settings_video_autoplay_title">Video Autoplay</string>
|
||||
<string name="settings_autoplay_nsfw_videos_title">Autoplay NSFW Videos</string>
|
||||
<string name="settings_immersive_interface_title">Immersive Interface</string>
|
||||
<string name="settings_immersive_interface_ignore_nav_bar_title">Ignore Navigation Bar in Immersive Interface</string>
|
||||
<string name="settings_immersive_interface_ignore_nav_bar_summary">Prevent the Bottom Navigation Bar Having Extra Padding</string>
|
||||
@ -738,5 +739,7 @@
|
||||
<string name="fetching_video_info_please_wait">Fetching video info. Please wait.</string>
|
||||
|
||||
<string name="error_fetching_imgur_media">Cannot load images</string>
|
||||
<!-- TODO: Remove or change this placeholder text -->
|
||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||
|
||||
</resources>
|
||||
|
18
app/src/main/res/xml/autoplay_preferences.xml
Normal file
18
app/src/main/res/xml/autoplay_preferences.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<ListPreference
|
||||
app:defaultValue="0"
|
||||
android:entries="@array/settings_video_autoplay"
|
||||
app:entryValues="@array/settings_video_autoplay_values"
|
||||
app:key="video_autoplay"
|
||||
app:title="@string/settings_video_autoplay_title"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<SwitchPreference
|
||||
app:defaultValue="true"
|
||||
app:key="autoplay_nsfw_videos"
|
||||
app:title="@string/settings_autoplay_nsfw_videos_title" />
|
||||
|
||||
</PreferenceScreen>
|
@ -28,13 +28,9 @@
|
||||
app:key="open_link_in_app"
|
||||
app:title="@string/settings_open_link_in_app_title" />
|
||||
|
||||
<ListPreference
|
||||
app:defaultValue="0"
|
||||
android:entries="@array/settings_video_autoplay"
|
||||
app:entryValues="@array/settings_video_autoplay_values"
|
||||
app:key="video_autoplay"
|
||||
<Preference
|
||||
app:title="@string/settings_video_autoplay_title"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
app:fragment="ml.docilealligator.infinityforreddit.Settings.AutoplayPreferenceFragment" />
|
||||
|
||||
<SwitchPreference
|
||||
app:defaultValue="false"
|
||||
|
Loading…
x
Reference in New Issue
Block a user