This commit is contained in:
Thomas 2020-10-30 16:21:56 +01:00
parent aecb4034ad
commit 4f909417f1
3 changed files with 52 additions and 4 deletions

View File

@ -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() {

View File

@ -114,6 +114,15 @@ public interface PeertubeService {
@GET("users/me")
Call<UserMe> verifyCredentials(@Header("Authorization") String credentials);
@FormUrlEncoded
@PUT("videos/{id}/watching")
Call<String> addToHistory(
@Header("Authorization") String credentials,
@Path("id") String id,
@Field("currentTime") long currentTime);
@FormUrlEncoded
@PUT("users/me")
Call<String> updateUser(

View File

@ -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<String> updateUser = peertubeService.addToHistory(getToken(),
videoId,
currentTime
);
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();
}
}
/**
* 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<String> updateUser = peertubeService.updateUser(getToken(),
@ -454,7 +477,6 @@ public class RetrofitPeertubeAPI {
MultipartBody.Part bodyThumbnail = MultipartBody.Part.createFormData("avatarfile", userSettings.getAvatarfile().getName(), requestFile);
Call<String> updateProfilePicture = peertubeService.updateProfilePicture(getToken(), bodyThumbnail);
}
return apiResponse;
}
/**