From f5a10775b9ceb8ea5343cac5926a30c2bc1c1bd6 Mon Sep 17 00:00:00 2001 From: stom79 Date: Sat, 12 Jan 2019 18:12:11 +0100 Subject: [PATCH] Peertube NSFW filter --- .../etalab/mastodon/client/PeertubeAPI.java | 4 +- .../fragments/SettingsPeertubeFragment.java | 15 ++++++ .../gouv/etalab/mastodon/helper/Helper.java | 1 + .../res/layout/fragment_peertube_settings.xml | 53 +++++++++++++------ app/src/main/res/values/strings.xml | 1 + 5 files changed, 56 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/PeertubeAPI.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/PeertubeAPI.java index f658574dc..1f63ee3e1 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/PeertubeAPI.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/PeertubeAPI.java @@ -729,7 +729,9 @@ public class PeertubeAPI { params.put("sort","publishedAt"); if( filter != null) params.put("filter",filter); - + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + boolean nsfw = sharedpreferences.getBoolean(Helper.SET_VIDEO_NSFW, false); + params.put("nsfw", String.valueOf(nsfw)); List peertubes = new ArrayList<>(); try { HttpsConnection httpsConnection = new HttpsConnection(context); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsPeertubeFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsPeertubeFragment.java index f47dcf9a1..12bf86941 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsPeertubeFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsPeertubeFragment.java @@ -24,6 +24,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.CheckBox; import android.widget.Spinner; import fr.gouv.etalab.mastodon.R; @@ -87,6 +88,20 @@ public class SettingsPeertubeFragment extends Fragment { } }); + + boolean video_nsfw = sharedpreferences.getBoolean(Helper.SET_VIDEO_NSFW, false); + final CheckBox set_video_nsfw = rootView.findViewById(R.id.set_video_nsfw); + set_video_nsfw.setChecked(video_nsfw); + + set_video_nsfw.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putBoolean(Helper.SET_VIDEO_NSFW, set_video_nsfw.isChecked()); + editor.apply(); + } + }); + return rootView; } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 73b1a4c48..4fb06acc8 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -272,6 +272,7 @@ public class Helper { public static final String SET_LED_COLOUR = "set_led_colour"; public static final String SET_SHOW_BOOSTS = "set_show_boost"; public static final String SET_SHOW_REPLIES = "set_show_replies"; + public static final String SET_VIDEO_NSFW = "set_video_nsfw"; public static final String INSTANCE_VERSION = "instance_version"; public static final String SET_LIVE_NOTIFICATIONS = "set_live_notifications"; public static final String SET_DISABLE_GIF = "set_disable_gif"; diff --git a/app/src/main/res/layout/fragment_peertube_settings.xml b/app/src/main/res/layout/fragment_peertube_settings.xml index 9c8ce8469..8deb419f8 100644 --- a/app/src/main/res/layout/fragment_peertube_settings.xml +++ b/app/src/main/res/layout/fragment_peertube_settings.xml @@ -15,33 +15,52 @@ You should have received a copy of the GNU General Public License along with Mastalab; if not, see . --> - + android:layout_height="match_parent" + android:layout_marginStart="@dimen/fab_margin" + android:layout_marginEnd="@dimen/fab_margin"> - - - - + + - - + android:orientation="horizontal"> + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f4628a760..6d83c399a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -817,6 +817,7 @@ Delete video Are you sure to delete this video? No videos uploaded yet! + Display NSFW videos