diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index ca0c3b3..5f6051b 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -481,7 +481,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd setFullscreen(FullScreenMediaController.fullscreen.OFF); fullScreenMode = false; } - + updateHistory(0); binding.peertubePlaylist.setVisibility(View.VISIBLE); binding.peertubeBookmark.setVisibility(View.GONE); TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class); @@ -944,6 +944,9 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd @Override protected void onPause() { super.onPause(); + if( player != null) { + updateHistory(player.getCurrentPosition()/1000); + } if (player != null && !isPlayInMinimized) { player.setPlayWhenReady(false); } @@ -1393,6 +1396,20 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd } } + private void updateHistory(long position) { + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + boolean storeInHistory = sharedpreferences.getBoolean(getString(R.string.set_store_in_history), true); + if( Helper.isLoggedIn(PeertubeActivity.this) && peertube != null && storeInHistory) { + new Thread(() -> { + try { + RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(PeertubeActivity.this); + api.updateHistory(peertube.getUuid(), position); + } catch (Exception e) { + e.printStackTrace(); + } + }).start(); + } + } @Override public void onAllCommentRemoved() { 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 e0f8bfd..ab11398 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,15 @@ public interface PeertubeService { @GET("users/me") Call verifyCredentials(@Header("Authorization") String credentials); + + @FormUrlEncoded + @PUT("videos/{id}/watching") + Call addToHistory( + @Header("Authorization") String credentials, + @Path("id") String id, + @Field("currentTime") long currentTime); + + @FormUrlEncoded @PUT("users/me") Call updateUser( 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 12b7868..eeccf16 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java @@ -421,14 +421,37 @@ public class RetrofitPeertubeAPI { return apiResponse; } + /** + * Update history + * + * @param videoId String + * @param currentTime int + */ + public void updateHistory(String videoId, long currentTime) { + APIResponse apiResponse = new APIResponse(); + PeertubeService peertubeService = init(); + Call updateUser = peertubeService.addToHistory(getToken(), + videoId, + currentTime + ); + try { + Response response = updateUser.execute(); + if (response.isSuccessful()) { + apiResponse.setActionReturn(response.body()); + } else { + setError(apiResponse, response.code(), response.errorBody()); + } + } catch (IOException e) { + e.printStackTrace(); + } + } /** * Update account information * * @param userSettings UserSettings - * @return APIResponse */ - public APIResponse updateUser(UserSettings userSettings) { + public void updateUser(UserSettings userSettings) { APIResponse apiResponse = new APIResponse(); PeertubeService peertubeService = init(); Call updateUser = peertubeService.updateUser(getToken(), @@ -454,7 +477,6 @@ public class RetrofitPeertubeAPI { MultipartBody.Part bodyThumbnail = MultipartBody.Part.createFormData("avatarfile", userSettings.getAvatarfile().getName(), requestFile); Call updateProfilePicture = peertubeService.updateProfilePicture(getToken(), bodyThumbnail); } - return apiResponse; } /**