Fix issue #44 - Sync NSFW + add them in settings to apply them.

This commit is contained in:
Thomas 2020-11-08 16:45:38 +01:00
parent fe3546e282
commit fee593d059
12 changed files with 127 additions and 38 deletions

View File

@ -135,5 +135,6 @@ dependencies {
implementation "androidx.work:work-runtime:2.4.0" implementation "androidx.work:work-runtime:2.4.0"
implementation "androidx.work:work-runtime-ktx:2.4.0" implementation "androidx.work:work-runtime-ktx:2.4.0"
implementation 'jp.wasabeef:glide-transformations:4.0.0'
} }

View File

@ -14,7 +14,7 @@
<string name="set_store_in_history" translatable="false">set_store_in_history</string> <string name="set_store_in_history" translatable="false">set_store_in_history</string>
<string name="set_play_screen_lock_choice" translatable="false">set_play_screen_lock_choice</string> <string name="set_play_screen_lock_choice" translatable="false">set_play_screen_lock_choice</string>
<string name="set_video_in_list_choice" translatable="false">set_video_in_list_choice</string> <string name="set_video_in_list_choice" translatable="false">set_video_in_list_choice</string>
<string name="set_video_sensitive_choice" translatable="false">set_video_sensitive_choice</string>
<string name="set_video_in_list">Vidéos dans une liste</string> <string name="set_video_in_list">Vidéos dans une liste</string>
<string name="set_video_in_list_description">Change la mise en page pour afficher les vidéos dans une liste</string> <string name="set_video_in_list_description">Change la mise en page pour afficher les vidéos dans une liste</string>

View File

@ -13,7 +13,7 @@
<string name="set_fullscreen_choice" translatable="false">set_fullscreen_choice</string> <string name="set_fullscreen_choice" translatable="false">set_fullscreen_choice</string>
<string name="set_play_screen_lock_choice" translatable="false">set_play_screen_lock_choice</string> <string name="set_play_screen_lock_choice" translatable="false">set_play_screen_lock_choice</string>
<string name="set_video_in_list_choice" translatable="false">set_video_in_list_choice</string> <string name="set_video_in_list_choice" translatable="false">set_video_in_list_choice</string>
<string name="set_video_sensitive_choice" translatable="false">set_video_sensitive_choice</string>
<string name="set_video_in_list">Videos in list</string> <string name="set_video_in_list">Videos in list</string>
<string name="set_video_in_list_description">Change the layout for displaying videos in a list</string> <string name="set_video_in_list_description">Change the layout for displaying videos in a list</string>

View File

@ -243,6 +243,7 @@ public class MainActivity extends AppCompatActivity {
editor.putBoolean(getString(R.string.set_autoplay_choice), userMe.isAutoPlayVideo()); editor.putBoolean(getString(R.string.set_autoplay_choice), userMe.isAutoPlayVideo());
editor.putBoolean(getString(R.string.set_store_in_history), userMe.isVideosHistoryEnabled()); editor.putBoolean(getString(R.string.set_store_in_history), userMe.isVideosHistoryEnabled());
editor.putBoolean(getString(R.string.set_autoplay_next_video_choice), userMe.isAutoPlayNextVideo()); editor.putBoolean(getString(R.string.set_autoplay_next_video_choice), userMe.isAutoPlayNextVideo());
editor.putString(getString(R.string.set_video_sensitive_choice), userMe.getNsfwPolicy());
//Sync languages from server //Sync languages from server
List<String> videoLanguageServer = userMe.getVideoLanguages(); List<String> videoLanguageServer = userMe.getVideoLanguages();
if (videoLanguageServer != null) { if (videoLanguageServer != null) {

View File

@ -134,7 +134,8 @@ public interface PeertubeService {
@Field("webTorrentEnabled") Boolean webTorrentEnabled, @Field("webTorrentEnabled") Boolean webTorrentEnabled,
@Field("videoLanguages") List<String> videoLanguages, @Field("videoLanguages") List<String> videoLanguages,
@Field("description") String description, @Field("description") String description,
@Field("displayName") String displayName @Field("displayName") String displayName,
@Field("nsfwPolicy") String nsfwPolicy
); );
@Multipart @Multipart

View File

@ -495,7 +495,8 @@ public class RetrofitPeertubeAPI {
userSettings.isWebTorrentEnabled(), userSettings.isWebTorrentEnabled(),
userSettings.getVideoLanguages(), userSettings.getVideoLanguages(),
userSettings.getDescription(), userSettings.getDescription(),
userSettings.getDisplayName() userSettings.getDisplayName(),
userSettings.getNsfwPolicy()
); );
Response<String> response = updateUser.execute(); Response<String> response = updateUser.execute();
if (response.isSuccessful()) { if (response.isSuccessful()) {

View File

@ -31,6 +31,7 @@ public class UserSettings {
private Uri avatarfile; private Uri avatarfile;
private String fileName; private String fileName;
private NotificationSettings notificationSettings; private NotificationSettings notificationSettings;
private String nsfwPolicy;
public Boolean isVideosHistoryEnabled() { public Boolean isVideosHistoryEnabled() {
return videosHistoryEnabled; return videosHistoryEnabled;
@ -131,5 +132,13 @@ public class UserSettings {
public void setNotificationSettings(NotificationSettings notificationSettings) { public void setNotificationSettings(NotificationSettings notificationSettings) {
this.notificationSettings = notificationSettings; this.notificationSettings = notificationSettings;
} }
public String getNsfwPolicy() {
return nsfwPolicy;
}
public void setNsfwPolicy(String nsfwPolicy) {
this.nsfwPolicy = nsfwPolicy;
}
} }

View File

@ -128,12 +128,13 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
holder.peertube_date.setText(String.format(" - %s", Helper.dateDiff(context, video.getCreatedAt()))); holder.peertube_date.setText(String.format(" - %s", Helper.dateDiff(context, video.getCreatedAt())));
holder.peertube_views.setText(context.getString(R.string.number_view_video, Helper.withSuffix(video.getViews()))); holder.peertube_views.setText(context.getString(R.string.number_view_video, Helper.withSuffix(video.getViews())));
boolean blur = sharedpreferences.getString(context.getString(R.string.set_video_sensitive_choice), Helper.BLUR).compareTo("blur") == 0 && video.isNsfw();
if(videoInList) { if(videoInList) {
Helper.loadGiF(context, instance, video.getThumbnailPath(), holder.peertube_video_image_small); Helper.loadGiF(context, instance, video.getThumbnailPath(), holder.peertube_video_image_small, blur);
holder.peertube_video_image_small.setVisibility(View.VISIBLE); holder.peertube_video_image_small.setVisibility(View.VISIBLE);
holder.preview_container.setVisibility(View.GONE); holder.preview_container.setVisibility(View.GONE);
}else{ }else{
Helper.loadGiF(context, instance, video.getThumbnailPath(), holder.peertube_video_image); Helper.loadGiF(context, instance, video.getThumbnailPath(), holder.peertube_video_image, blur);
holder.peertube_video_image_small.setVisibility(View.GONE); holder.peertube_video_image_small.setVisibility(View.GONE);
holder.preview_container.setVisibility(View.VISIBLE); holder.preview_container.setVisibility(View.VISIBLE);
} }

View File

@ -21,31 +21,6 @@ import androidx.preference.PreferenceScreen;
import androidx.preference.SeekBarPreference; import androidx.preference.SeekBarPreference;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import app.fedilab.fedilabtube.MainActivity;
import app.fedilab.fedilabtube.PeertubeActivity;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.UserSettings;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.ThemeHelper;
import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
import static app.fedilab.fedilabtube.MainActivity.userMe;
/* Copyright 2020 Thomas Schneider /* Copyright 2020 Thomas Schneider
* *
* This file is a part of TubeLab * This file is a part of TubeLab
@ -61,6 +36,30 @@ import static app.fedilab.fedilabtube.MainActivity.userMe;
* You should have received a copy of the GNU General Public License along with TubeLab; if not, * You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import app.fedilab.fedilabtube.MainActivity;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.UserSettings;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.ThemeHelper;
import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
import static app.fedilab.fedilabtube.MainActivity.userMe;
public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override @Override
@ -131,6 +130,26 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
ThemeHelper.switchTo(choice); ThemeHelper.switchTo(choice);
} }
} }
if (key.compareTo(getString(R.string.set_video_sensitive_choice)) == 0) {
ListPreference set_video_sensitive_choice = findPreference(getString(R.string.set_video_sensitive_choice));
if (set_video_sensitive_choice != null) {
editor.putString(getString(R.string.set_video_sensitive_choice), set_video_sensitive_choice.getValue());
editor.apply();
if(Helper.isLoggedIn(getActivity())) {
new Thread(() -> {
UserSettings userSettings = new UserSettings();
userSettings.setNsfwPolicy(set_video_sensitive_choice.getValue());
try {
RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(getActivity());
api.updateUser(userSettings);
userMe.setNsfwPolicy(set_video_sensitive_choice.getValue());
} catch (Exception | Error e) {
e.printStackTrace();
}
}).start();
}
}
}
if (key.compareTo(getString(R.string.set_video_quality_choice)) == 0) { if (key.compareTo(getString(R.string.set_video_quality_choice)) == 0) {
ListPreference set_video_quality_choice = findPreference(getString(R.string.set_video_quality_choice)); ListPreference set_video_quality_choice = findPreference(getString(R.string.set_video_quality_choice));
if (set_video_quality_choice != null) { if (set_video_quality_choice != null) {
@ -287,6 +306,8 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
set_theme_choice.setValueIndex(currentTheme); set_theme_choice.setValueIndex(currentTheme);
} }
//****** Video mode ******* //****** Video mode *******
ListPreference set_video_mode_choice = findPreference(getString(R.string.set_video_mode_choice)); ListPreference set_video_mode_choice = findPreference(getString(R.string.set_video_mode_choice));
List<String> array = Arrays.asList(getResources().getStringArray(R.array.settings_video_mode)); List<String> array = Arrays.asList(getResources().getStringArray(R.array.settings_video_mode));
@ -387,6 +408,31 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
if (selection != null) { if (selection != null) {
set_video_language_choice.setValues(selection); set_video_language_choice.setValues(selection);
} }
//****** Display sensitive content *******
ListPreference set_video_sensitive_choice = findPreference(getString(R.string.set_video_sensitive_choice));
List<String> arraySensitive = new ArrayList<>();
arraySensitive.add(getString(R.string.do_not_list));
arraySensitive.add(getString(R.string.blur));
arraySensitive.add(getString(R.string.display));
CharSequence[] entriesSensitive = arraySensitive.toArray(new CharSequence[0]);
CharSequence[] entryValuesSensitive = new CharSequence[3];
String currentSensitive = sharedpref.getString(getString(R.string.set_video_sensitive_choice), Helper.BLUR);
entryValuesSensitive[0] = Helper.DO_NOT_LIST.toLowerCase();
entryValuesSensitive[1] = Helper.BLUR.toLowerCase();
entryValuesSensitive[2] = Helper.DISPLAY.toLowerCase();
int currentSensitivePosition = 0;
for(CharSequence val : entryValuesSensitive) {
if(val.equals(currentSensitive)) {
break;
}
currentSensitivePosition++;
}
if (set_video_sensitive_choice != null) {
set_video_sensitive_choice.setEntries(entriesSensitive);
set_video_sensitive_choice.setEntryValues(entryValuesSensitive);
set_video_sensitive_choice.setValueIndex(currentSensitivePosition);
}
} }
} }

View File

@ -26,6 +26,7 @@ import android.content.res.Resources;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
@ -45,6 +46,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.load.resource.bitmap.CenterCrop; import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
@ -71,6 +73,7 @@ import app.fedilab.fedilabtube.sqlite.Sqlite;
import app.fedilab.fedilabtube.webview.CustomWebview; import app.fedilab.fedilabtube.webview.CustomWebview;
import app.fedilab.fedilabtube.webview.ProxyHelper; import app.fedilab.fedilabtube.webview.ProxyHelper;
import es.dmoral.toasty.Toasty; import es.dmoral.toasty.Toasty;
import jp.wasabeef.glide.transformations.BlurTransformation;
import static android.content.Context.DOWNLOAD_SERVICE; import static android.content.Context.DOWNLOAD_SERVICE;
@ -83,6 +86,9 @@ public class Helper {
public static final int LIGHT_MODE = 0; public static final int LIGHT_MODE = 0;
public static final int DARK_MODE = 1; public static final int DARK_MODE = 1;
public static final int DEFAULT_MODE = 2; public static final int DEFAULT_MODE = 2;
public static final String DO_NOT_LIST = "do_not_list";
public static final String BLUR = "blur";
public static final String DISPLAY = "display";
public static final String TIMELINE_TYPE = "timeline_type"; public static final String TIMELINE_TYPE = "timeline_type";
public static final int VIDEO_MODE_NORMAL = 0; public static final int VIDEO_MODE_NORMAL = 0;
public static final int VIDEO_MODE_MAGNET = 2; public static final int VIDEO_MODE_MAGNET = 2;
@ -439,16 +445,21 @@ public class Helper {
loadGiF(context, url, imageView, 10); loadGiF(context, url, imageView, 10);
} }
public static void loadGiF(final Context context, String instance, String url, final ImageView imageView, boolean blur) {
loadGif(context, instance, url, imageView, 10, blur);
}
public static void loadGiF(final Context context, String instance, String url, final ImageView imageView) { public static void loadGiF(final Context context, String instance, String url, final ImageView imageView) {
loadGif(context, instance, url, imageView, 10); loadGif(context, instance, url, imageView, 10, false);
} }
public static void loadGiF(final Context context, String url, final ImageView imageView, int round) { public static void loadGiF(final Context context, String url, final ImageView imageView, int round) {
loadGif(context, null, url, imageView, round); loadGif(context, null, url, imageView, round, false);
} }
@SuppressLint("CheckResult")
@SuppressWarnings("SameParameterValue") @SuppressWarnings("SameParameterValue")
private static void loadGif(final Context context, String instance, String url, final ImageView imageView, int round) { private static void loadGif(final Context context, String instance, String url, final ImageView imageView, int round, boolean blur) {
if (url == null || url.trim().toLowerCase().compareTo("null") == 0 || url.endsWith("null")) { if (url == null || url.trim().toLowerCase().compareTo("null") == 0 || url.endsWith("null")) {
Glide.with(imageView.getContext()) Glide.with(imageView.getContext())
.asDrawable() .asDrawable()
@ -464,11 +475,15 @@ public class Helper {
url = "https://" + url; url = "https://" + url;
} }
try { try {
Glide.with(imageView.getContext()) RequestBuilder<Drawable> requestBuilder = Glide.with(imageView.getContext())
.load(url) .load(url)
.thumbnail(0.1f) .thumbnail(0.1f);
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(round))) if( blur ) {
.into(imageView); requestBuilder.apply(new RequestOptions().transform(new BlurTransformation(50, 3), new CenterCrop(), new RoundedCorners(10)));
}else {
requestBuilder.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(round)));
}
requestBuilder.into(imageView);
} catch (Exception e) { } catch (Exception e) {
try { try {
Glide.with(imageView.getContext()) Glide.with(imageView.getContext())

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M6,13c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM6,17c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM6,9c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM3,9.5c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5 0.5,-0.22 0.5,-0.5 -0.22,-0.5 -0.5,-0.5zM6,5c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM21,10.5c0.28,0 0.5,-0.22 0.5,-0.5s-0.22,-0.5 -0.5,-0.5 -0.5,0.22 -0.5,0.5 0.22,0.5 0.5,0.5zM14,7c0.55,0 1,-0.45 1,-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,1.5s0.67,1.5 1.5,1.5 1.5,-0.67 1.5,-1.5 -0.67,-1.5 -1.5,-1.5zM10,17c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM14,12.5c-0.83,0 -1.5,0.67 -1.5,1.5s0.67,1.5 1.5,1.5 1.5,-0.67 1.5,-1.5 -0.67,-1.5 -1.5,-1.5zM14,8.5c-0.83,0 -1.5,0.67 -1.5,1.5s0.67,1.5 1.5,1.5 1.5,-0.67 1.5,-1.5 -0.67,-1.5 -1.5,-1.5z"/>
</vector>

View File

@ -68,6 +68,10 @@
android:key="@string/set_theme_choice" android:key="@string/set_theme_choice"
android:summary="@string/set_theme_description" android:summary="@string/set_theme_description"
android:title="@string/set_theme" /> android:title="@string/set_theme" />
<androidx.preference.ListPreference
android:icon="@drawable/ic_baseline_blur_on_24"
android:key="@string/set_video_sensitive_choice"
android:title="@string/sepia_element_nsfw" />
<androidx.preference.MultiSelectListPreference <androidx.preference.MultiSelectListPreference
android:icon="@drawable/ic_baseline_language_24" android:icon="@drawable/ic_baseline_language_24"
android:key="@string/set_video_language_choice" android:key="@string/set_video_language_choice"