mirror of
				https://framagit.org/tom79/fedilab-tube
				synced 2025-06-05 21:09:11 +02:00 
			
		
		
		
	Fix issue #20
This commit is contained in:
		| @@ -9,8 +9,11 @@ | ||||
|     <string name="set_autoplay_choice" translatable="false">set_autoplay_choice</string> | ||||
|     <string name="set_theme_choice" translatable="false">set_theme_choice</string> | ||||
|     <string name="set_fullscreen_choice" translatable="false">set_fullscreen_choice</string> | ||||
|     <string name="set_autoplay_next_videochoice" translatable="false">set_autoplay_next_videochoice</string> | ||||
|     <string name="set_store_in_history">set_store_in_history</string> | ||||
|  | ||||
|  | ||||
|     <string name="enable_history">Activer l\'historique</string> | ||||
|     <string name="set_autoplay">Lecture automatique</string> | ||||
|     <string name="set_autoplay_description">Si activé, les vidéos seront lues automatiquement</string> | ||||
|  | ||||
|   | ||||
| @@ -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 | ||||
| - Double tap video left/right to seek - or + 10 seconds | ||||
|   | ||||
| @@ -6,9 +6,12 @@ | ||||
|     <string name="set_video_quality_choice" translatable="false">set_video_quality_choice</string> | ||||
|     <string name="set_video_cache_choice" translatable="false">set_video_cache_choice</string> | ||||
|     <string name="set_autoplay_choice" translatable="false">set_autoplay_choice</string> | ||||
|     <string name="set_store_in_history">set_store_in_history</string> | ||||
|     <string name="set_autoplay_next_videochoice" translatable="false">set_autoplay_next_videochoice</string> | ||||
|     <string name="set_theme_choice" translatable="false">set_theme_choice</string> | ||||
|     <string name="set_fullscreen_choice" translatable="false">set_fullscreen_choice</string> | ||||
|  | ||||
|     <string name="enable_history">Enable history</string> | ||||
|  | ||||
|     <string name="set_autoplay">Automatic playback</string> | ||||
|     <string name="set_autoplay_description">If enabled, videos will be played automatically</string> | ||||
|   | ||||
| @@ -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<String> 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); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -114,6 +114,24 @@ public interface PeertubeService { | ||||
|     @GET("users/me") | ||||
|     Call<UserMe> verifyCredentials(@Header("Authorization") String credentials); | ||||
|  | ||||
|     @FormUrlEncoded | ||||
|     @PUT("users/me") | ||||
|     Call<String> updateUser( | ||||
|             @Header("Authorization") String credentials, | ||||
|             @Field("videosHistoryEnabled") Boolean videosHistoryEnabled, | ||||
|             @Field("autoPlayVideo") Boolean autoPlayVideo, | ||||
|             @Field("webTorrentEnabled") Boolean webTorrentEnabled, | ||||
|             @Field("videoLanguages") List<String> videoLanguages, | ||||
|             @Field("description") String description, | ||||
|             @Field("displayName") String displayName | ||||
|             ); | ||||
|  | ||||
|     @Multipart | ||||
|     @POST("users/me/avatar/pick") | ||||
|     Call<String> updateProfilePicture( | ||||
|             @Header("Authorization") String credentials, | ||||
|             @Part MultipartBody.Part avatarfile); | ||||
|  | ||||
|     //Timelines Authenticated | ||||
|     //Subscriber timeline | ||||
|     @GET("users/me/subscriptions/videos?sort=-publishedAt") | ||||
|   | ||||
| @@ -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<String> updateUser = peertubeService.updateUser(getToken(), | ||||
|                 userSettings.isVideosHistoryEnabled(), | ||||
|                 userSettings.isAutoPlayVideo(), | ||||
|                 userSettings.isWebTorrentEnabled(), | ||||
|                 userSettings.getVideoLanguages(), | ||||
|                 userSettings.getDescription(), | ||||
|                 userSettings.getDisplayName() | ||||
|         ); | ||||
|         try { | ||||
|             Response<String> 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<String> updateProfilePicture = peertubeService.updateProfilePicture(getToken(), bodyThumbnail); | ||||
|         } | ||||
|         return apiResponse; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Check if users via their uris are following the authenticated user | ||||
|      * | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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 <http://www.gnu.org/licenses>. */ | ||||
|  | ||||
| import java.util.List; | ||||
| import java.io.File; | ||||
|  | ||||
| public class UserSettings { | ||||
|  | ||||
|     private Boolean videosHistoryEnabled; | ||||
|     private Boolean autoPlayVideo; | ||||
|     private Boolean webTorrentEnabled; | ||||
|     private List<String> 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<String> getVideoLanguages() { | ||||
|         return videoLanguages; | ||||
|     } | ||||
|  | ||||
|     public void setVideoLanguages(List<String> 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; | ||||
|     } | ||||
| } | ||||
| @@ -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<String> 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(); | ||||
|         } | ||||
|   | ||||
| @@ -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="M15.1,19.37l1,1.74c-0.96,0.44 -2.01,0.73 -3.1,0.84v-2.02C13.74,19.84 14.44,19.65 15.1,19.37zM4.07,13H2.05c0.11,1.1 0.4,2.14 0.84,3.1l1.74,-1C4.35,14.44 4.16,13.74 4.07,13zM15.1,4.63l1,-1.74C15.14,2.45 14.1,2.16 13,2.05v2.02C13.74,4.16 14.44,4.35 15.1,4.63zM19.93,11h2.02c-0.11,-1.1 -0.4,-2.14 -0.84,-3.1l-1.74,1C19.65,9.56 19.84,10.26 19.93,11zM8.9,19.37l-1,1.74c0.96,0.44 2.01,0.73 3.1,0.84v-2.02C10.26,19.84 9.56,19.65 8.9,19.37zM11,4.07V2.05c-1.1,0.11 -2.14,0.4 -3.1,0.84l1,1.74C9.56,4.35 10.26,4.16 11,4.07zM18.36,7.17l1.74,-1.01c-0.63,-0.87 -1.4,-1.64 -2.27,-2.27l-1.01,1.74C17.41,6.08 17.92,6.59 18.36,7.17zM4.63,8.9l-1.74,-1C2.45,8.86 2.16,9.9 2.05,11h2.02C4.16,10.26 4.35,9.56 4.63,8.9zM19.93,13c-0.09,0.74 -0.28,1.44 -0.56,2.1l1.74,1c0.44,-0.96 0.73,-2.01 0.84,-3.1H19.93zM16.83,18.36l1.01,1.74c0.87,-0.63 1.64,-1.4 2.27,-2.27l-1.74,-1.01C17.92,17.41 17.41,17.92 16.83,18.36zM7.17,5.64L6.17,3.89C5.29,4.53 4.53,5.29 3.9,6.17l1.74,1.01C6.08,6.59 6.59,6.08 7.17,5.64zM5.64,16.83L3.9,17.83c0.63,0.87 1.4,1.64 2.27,2.27l1.01,-1.74C6.59,17.92 6.08,17.41 5.64,16.83zM13,7h-2v5.41l4.29,4.29l1.41,-1.41L13,11.59V7z"/> | ||||
| </vector> | ||||
| @@ -55,6 +55,13 @@ | ||||
|         android:icon="@drawable/ic_baseline_search_24" | ||||
|         android:title="@string/sepia_search" | ||||
|         app:showAsAction="ifRoom" /> | ||||
|     <item | ||||
|         android:id="@+id/action_incognito" | ||||
|         android:icon="@drawable/ic_baseline_history_toggle_off_24" | ||||
|         android:title="@string/enable_history" | ||||
|         android:checkable="true" | ||||
|         app:actionViewClass="android.widget.CheckBox" | ||||
|         app:showAsAction="ifRoom" /> | ||||
|     <item | ||||
|         android:id="@+id/action_about" | ||||
|         android:icon="@drawable/ic_baseline_info_24" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user