From aecb4034ad6e310efde8bb593c612150e6f65d3b Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 30 Oct 2020 14:45:37 +0100 Subject: [PATCH] Fix issue #20 --- app/src/acad/res/values/strings.xml | 3 + .../play/release-notes/en-US/default.txt | 8 +- app/src/full/res/values/strings.xml | 3 + .../app/fedilab/fedilabtube/MainActivity.java | 28 ++++++ .../fedilabtube/client/PeertubeService.java | 18 ++++ .../client/RetrofitPeertubeAPI.java | 37 ++++++++ .../fedilabtube/client/entities/UserMe.java | 10 +++ .../client/entities/UserSettings.java | 85 +++++++++++++++++++ .../fragment/SettingsFragment.java | 27 ++++++ .../ic_baseline_history_toggle_off_24.xml | 10 +++ app/src/main/res/menu/main_menu.xml | 7 ++ 11 files changed, 229 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/app/fedilab/fedilabtube/client/entities/UserSettings.java create mode 100644 app/src/main/res/drawable/ic_baseline_history_toggle_off_24.xml diff --git a/app/src/acad/res/values/strings.xml b/app/src/acad/res/values/strings.xml index 6dcf9fa..10095f1 100644 --- a/app/src/acad/res/values/strings.xml +++ b/app/src/acad/res/values/strings.xml @@ -9,8 +9,11 @@ set_autoplay_choice set_theme_choice set_fullscreen_choice + set_autoplay_next_videochoice + set_store_in_history + Activer l\'historique Lecture automatique Si activé, les vidéos seront lues automatiquement diff --git a/app/src/fdroid_full/play/release-notes/en-US/default.txt b/app/src/fdroid_full/play/release-notes/en-US/default.txt index d727833..2c606f4 100644 --- a/app/src/fdroid_full/play/release-notes/en-US/default.txt +++ b/app/src/fdroid_full/play/release-notes/en-US/default.txt @@ -1,8 +1,2 @@ Added: -- Enable/disable auto playback -- Enter in fullscreen automatically (default disabled) -- Back press pauses the video in fullscreen - -Fixes: -- Public timelines don't honor muted accounts -- Comments are not removed when switching to a video without comments \ No newline at end of file +- Double tap video left/right to seek - or + 10 seconds diff --git a/app/src/full/res/values/strings.xml b/app/src/full/res/values/strings.xml index 1e2c3fd..c42007f 100644 --- a/app/src/full/res/values/strings.xml +++ b/app/src/full/res/values/strings.xml @@ -6,9 +6,12 @@ set_video_quality_choice set_video_cache_choice set_autoplay_choice + set_store_in_history + set_autoplay_next_videochoice set_theme_choice set_fullscreen_choice + Enable history Automatic playback If enabled, videos will be played automatically diff --git a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java index 3d23deb..0e91b5f 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java @@ -53,6 +53,7 @@ import app.fedilab.fedilabtube.client.entities.OauthParams; import app.fedilab.fedilabtube.client.entities.PeertubeInformation; import app.fedilab.fedilabtube.client.entities.Token; import app.fedilab.fedilabtube.client.entities.UserMe; +import app.fedilab.fedilabtube.client.entities.UserSettings; import app.fedilab.fedilabtube.client.entities.WellKnownNodeinfo; import app.fedilab.fedilabtube.fragment.DisplayOverviewFragment; import app.fedilab.fedilabtube.fragment.DisplayVideosFragment; @@ -224,6 +225,9 @@ public class MainActivity extends AppCompatActivity { SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(Helper.PREF_KEY_ID, account.getId()); editor.putString(Helper.PREF_KEY_NAME, account.getUsername()); + 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_autoplay_next_videochoice), userMe.isAutoPlayNextVideo()); //Sync languages from server List videoLanguageServer = userMe.getVideoLanguages(); if (videoLanguageServer != null) { @@ -307,6 +311,7 @@ public class MainActivity extends AppCompatActivity { MenuItem mostLikedItem = menu.findItem(R.id.action_most_liked); MenuItem settingsItem = menu.findItem(R.id.action_settings); MenuItem sepiaSearchItem = menu.findItem(R.id.action_sepia_search); + MenuItem incognitoItem = menu.findItem(R.id.action_incognito); if (Helper.isLoggedIn(MainActivity.this)) { instanceItem.setVisible(false); uploadItem.setVisible(true); @@ -315,6 +320,10 @@ public class MainActivity extends AppCompatActivity { historyItem.setVisible(true); settingsItem.setVisible(false); mostLikedItem.setVisible(true); + incognitoItem.setVisible(true); + final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + boolean checked = sharedpreferences.getBoolean(getString(R.string.set_store_in_history), true); + incognitoItem.setChecked(checked); } else { instanceItem.setVisible(true); uploadItem.setVisible(false); @@ -323,6 +332,7 @@ public class MainActivity extends AppCompatActivity { historyItem.setVisible(false); settingsItem.setVisible(true); mostLikedItem.setVisible(false); + incognitoItem.setVisible(false); } if (!BuildConfig.full_instances) { sepiaSearchItem.setVisible(false); @@ -389,7 +399,25 @@ public class MainActivity extends AppCompatActivity { Intent intent = new Intent(MainActivity.this, AboutActivity.class); startActivity(intent); return true; + } else if (item.getItemId() == R.id.action_incognito) { + item.setChecked(!item.isChecked()); + final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putBoolean(getString(R.string.set_store_in_history), item.isChecked()); + editor.apply(); + new Thread(() -> { + UserSettings userSettings = new UserSettings(); + userSettings.setVideosHistoryEnabled(item.isChecked()); + try { + RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(MainActivity.this); + api.updateUser(userSettings); + } catch (Exception e) { + e.printStackTrace(); + } + }).start(); + return false; } + return super.onOptionsItemSelected(item); } diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java index c4eaac3..e0f8bfd 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java @@ -114,6 +114,24 @@ public interface PeertubeService { @GET("users/me") Call verifyCredentials(@Header("Authorization") String credentials); + @FormUrlEncoded + @PUT("users/me") + Call updateUser( + @Header("Authorization") String credentials, + @Field("videosHistoryEnabled") Boolean videosHistoryEnabled, + @Field("autoPlayVideo") Boolean autoPlayVideo, + @Field("webTorrentEnabled") Boolean webTorrentEnabled, + @Field("videoLanguages") List videoLanguages, + @Field("description") String description, + @Field("displayName") String displayName + ); + + @Multipart + @POST("users/me/avatar/pick") + Call updateProfilePicture( + @Header("Authorization") String credentials, + @Part MultipartBody.Part avatarfile); + //Timelines Authenticated //Subscriber timeline @GET("users/me/subscriptions/videos?sort=-publishedAt") diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java index d6be7c0..12b7868 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java @@ -61,6 +61,7 @@ import app.fedilab.fedilabtube.client.entities.Rating; import app.fedilab.fedilabtube.client.entities.Report; import app.fedilab.fedilabtube.client.entities.Token; import app.fedilab.fedilabtube.client.entities.UserMe; +import app.fedilab.fedilabtube.client.entities.UserSettings; import app.fedilab.fedilabtube.client.entities.VideoParams; import app.fedilab.fedilabtube.client.entities.WellKnownNodeinfo; import app.fedilab.fedilabtube.helper.Helper; @@ -106,6 +107,7 @@ public class RetrofitPeertubeAPI { count = String.valueOf(sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE)); } + public static void updateCredential(Activity activity, String token, String client_id, String client_secret, String refresh_token, String host) { new Thread(() -> { AccountData.Account account; @@ -420,6 +422,41 @@ public class RetrofitPeertubeAPI { } + /** + * Update account information + * + * @param userSettings UserSettings + * @return APIResponse + */ + public APIResponse updateUser(UserSettings userSettings) { + APIResponse apiResponse = new APIResponse(); + PeertubeService peertubeService = init(); + Call updateUser = peertubeService.updateUser(getToken(), + userSettings.isVideosHistoryEnabled(), + userSettings.isAutoPlayVideo(), + userSettings.isWebTorrentEnabled(), + userSettings.getVideoLanguages(), + userSettings.getDescription(), + userSettings.getDisplayName() + ); + try { + Response response = updateUser.execute(); + if (response.isSuccessful()) { + apiResponse.setActionReturn(response.body()); + } else { + setError(apiResponse, response.code(), response.errorBody()); + } + } catch (IOException e) { + e.printStackTrace(); + } + if (userSettings.getAvatarfile() != null) { + RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), userSettings.getAvatarfile()); + MultipartBody.Part bodyThumbnail = MultipartBody.Part.createFormData("avatarfile", userSettings.getAvatarfile().getName(), requestFile); + Call updateProfilePicture = peertubeService.updateProfilePicture(getToken(), bodyThumbnail); + } + return apiResponse; + } + /** * Check if users via their uris are following the authenticated user * diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/entities/UserMe.java b/app/src/main/java/app/fedilab/fedilabtube/client/entities/UserMe.java index 2609d7e..f359fbb 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/entities/UserMe.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/entities/UserMe.java @@ -31,6 +31,8 @@ public class UserMe { private boolean autoPlayNextVideo; @SerializedName("autoPlayNextVideoPlaylist") private boolean autoPlayNextVideoPlaylist; + @SerializedName("autoPlayVideo") + private boolean autoPlayVideo; @SerializedName("blocked") private boolean blocked; @SerializedName("blockedReason") @@ -255,4 +257,12 @@ public class UserMe { public void setWebTorrentEnabled(boolean webTorrentEnabled) { this.webTorrentEnabled = webTorrentEnabled; } + + public boolean isAutoPlayVideo() { + return autoPlayVideo; + } + + public void setAutoPlayVideo(boolean autoPlayVideo) { + this.autoPlayVideo = autoPlayVideo; + } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/entities/UserSettings.java b/app/src/main/java/app/fedilab/fedilabtube/client/entities/UserSettings.java new file mode 100644 index 0000000..0e0f074 --- /dev/null +++ b/app/src/main/java/app/fedilab/fedilabtube/client/entities/UserSettings.java @@ -0,0 +1,85 @@ +package app.fedilab.fedilabtube.client.entities; +/* Copyright 2020 Thomas Schneider + * + * This file is a part of TubeLab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with TubeLab; if not, + * see . */ + +import java.util.List; +import java.io.File; + +public class UserSettings { + + private Boolean videosHistoryEnabled; + private Boolean autoPlayVideo; + private Boolean webTorrentEnabled; + private List videoLanguages; + private String description; + private String displayName; + private File avatarfile; + + public Boolean isVideosHistoryEnabled() { + return videosHistoryEnabled; + } + + public void setVideosHistoryEnabled(Boolean videosHistoryEnabled) { + this.videosHistoryEnabled = videosHistoryEnabled; + } + + public Boolean isAutoPlayVideo() { + return autoPlayVideo; + } + + public void setAutoPlayVideo(Boolean autoPlayVideo) { + this.autoPlayVideo = autoPlayVideo; + } + + public Boolean isWebTorrentEnabled() { + return webTorrentEnabled; + } + + public void setWebTorrentEnabled(Boolean webTorrentEnabled) { + this.webTorrentEnabled = webTorrentEnabled; + } + + public List getVideoLanguages() { + return videoLanguages; + } + + public void setVideoLanguages(List videoLanguages) { + this.videoLanguages = videoLanguages; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public File getAvatarfile() { + return avatarfile; + } + + public void setAvatarfile(File avatarfile) { + this.avatarfile = avatarfile; + } +} diff --git a/app/src/main/java/app/fedilab/fedilabtube/fragment/SettingsFragment.java b/app/src/main/java/app/fedilab/fedilabtube/fragment/SettingsFragment.java index 7940c7a..6e4afcb 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/fragment/SettingsFragment.java +++ b/app/src/main/java/app/fedilab/fedilabtube/fragment/SettingsFragment.java @@ -21,6 +21,8 @@ import java.util.Map; import java.util.Set; import app.fedilab.fedilabtube.R; +import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI; +import app.fedilab.fedilabtube.client.entities.UserSettings; import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.helper.ThemeHelper; import es.dmoral.toasty.Toasty; @@ -141,6 +143,18 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared SwitchPreference set_autoplay_choice = findPreference(getString(R.string.set_autoplay_choice)); assert set_autoplay_choice != null; editor.putBoolean(getString(R.string.set_autoplay_choice), set_autoplay_choice.isChecked()); + if(Helper.isLoggedIn(getActivity())) { + new Thread(() -> { + UserSettings userSettings = new UserSettings(); + userSettings.setAutoPlayVideo(set_autoplay_choice.isChecked()); + try { + RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(getActivity()); + api.updateUser(userSettings); + } catch (Exception e) { + e.printStackTrace(); + } + }).start(); + } } if (key.compareTo(getString(R.string.set_fullscreen_choice)) == 0) { SwitchPreference set_fullscreen_choice = findPreference(getString(R.string.set_fullscreen_choice)); @@ -151,6 +165,19 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared MultiSelectListPreference set_video_language_choice = findPreference(getString(R.string.set_video_language_choice)); assert set_video_language_choice != null; editor.putStringSet(getString(R.string.set_video_language_choice), set_video_language_choice.getValues()); + if(Helper.isLoggedIn(getActivity())) { + new Thread(() -> { + UserSettings userSettings = new UserSettings(); + Set language_choiceValues = set_video_language_choice.getValues(); + userSettings.setVideoLanguages(new ArrayList<>(language_choiceValues)); + try { + RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(getActivity()); + api.updateUser(userSettings); + } catch (Exception e) { + e.printStackTrace(); + } + }).start(); + } } editor.apply(); } diff --git a/app/src/main/res/drawable/ic_baseline_history_toggle_off_24.xml b/app/src/main/res/drawable/ic_baseline_history_toggle_off_24.xml new file mode 100644 index 0000000..ece916d --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_history_toggle_off_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/menu/main_menu.xml b/app/src/main/res/menu/main_menu.xml index e4a608c..619b9a4 100644 --- a/app/src/main/res/menu/main_menu.xml +++ b/app/src/main/res/menu/main_menu.xml @@ -55,6 +55,13 @@ android:icon="@drawable/ic_baseline_search_24" android:title="@string/sepia_search" app:showAsAction="ifRoom" /> +