From 7678da2bb6cc47b84c1b75753bc5e194c9d63ed6 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 8 Oct 2020 18:13:04 +0200 Subject: [PATCH] Change description + fix pagination --- .../play/listings/en-US/short-description.txt | 2 +- .../fedilab/fedilabtube/PeertubeActivity.java | 182 +++++++++--------- .../fedilabtube/client/PeertubeService.java | 31 +-- .../client/RetrofitPeertubeAPI.java | 38 ++-- .../fragment/DisplayVideosFragment.java | 9 +- .../fedilab/fedilabtube/helper/Helper.java | 2 +- .../fedilabtube/viewmodel/PlaylistsVM.java | 2 +- .../fedilabtube/viewmodel/TimelineVM.java | 8 +- 8 files changed, 143 insertions(+), 131 deletions(-) diff --git a/app/src/fdroid_full/play/listings/en-US/short-description.txt b/app/src/fdroid_full/play/listings/en-US/short-description.txt index 1f0744b..338e1e4 100644 --- a/app/src/fdroid_full/play/listings/en-US/short-description.txt +++ b/app/src/fdroid_full/play/listings/en-US/short-description.txt @@ -1 +1 @@ -TubeLab est une application Peertube pour les instances académiques. \ No newline at end of file +App for all Peertube instances \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index 1c7fe45..a67ee3d 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -31,6 +31,7 @@ import android.os.Bundle; import android.os.Handler; import android.support.v4.media.session.MediaSessionCompat; import android.text.Html; +import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -88,7 +89,7 @@ import com.google.android.exoplayer2.util.Util; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Iterator; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -98,7 +99,7 @@ import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI; import app.fedilab.fedilabtube.client.data.AccountData.Account; import app.fedilab.fedilabtube.client.data.CaptionData.Caption; import app.fedilab.fedilabtube.client.data.CommentData.Comment; -import app.fedilab.fedilabtube.client.data.PlaylistData.Playlist; +import app.fedilab.fedilabtube.client.data.PlaylistData; import app.fedilab.fedilabtube.client.data.VideoData; import app.fedilab.fedilabtube.client.entities.File; import app.fedilab.fedilabtube.client.entities.ItemStr; @@ -127,13 +128,12 @@ import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPO import static app.fedilab.fedilabtube.helper.Helper.getAttColor; import static app.fedilab.fedilabtube.helper.Helper.getLiveInstance; import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn; -import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_PLAYLISTS; public class PeertubeActivity extends AppCompatActivity implements CommentListAdapter.AllCommentRemoved { public static String video_id; - private String peertubeInstance, videoId, videoUuid; + private String peertubeInstance, videoUuid; private FullScreenMediaController.fullscreen fullscreen; private RelativeLayout loader; private TextView peertube_view_count, peertube_playlist, peertube_bookmark, peertube_like_count, peertube_dislike_count, peertube_description, peertube_title, more_actions; @@ -150,9 +150,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd private ImageView send; private TextView add_comment_read; private EditText add_comment_write; - private List playlistForVideo; - private List playlists; - private PlaylistsVM playlistsViewModel; + private Map> playlists; private boolean playInMinimized; private boolean onStopCalled; private List captions; @@ -222,19 +220,14 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd mode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL); - playlistForVideo = new ArrayList<>(); - playlistsViewModel = new ViewModelProvider(PeertubeActivity.this).get(PlaylistsVM.class); - if (Helper.isLoggedIn(PeertubeActivity.this)) { - playlistsViewModel.manage(GET_PLAYLISTS, null, null).observe(PeertubeActivity.this, apiResponse -> manageVIewPlaylists(GET_PLAYLISTS, apiResponse)); - } Bundle b = getIntent().getExtras(); if (b != null) { peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this)); - videoId = b.getString("video_id", null); videoUuid = b.getString("video_uuid", null); isMyVideo = b.getBoolean("isMyVideo", false); } + playInMinimized = sharedpreferences.getBoolean(getString(R.string.set_video_minimize_choice), true); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N && !getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) { @@ -346,7 +339,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd Bundle b = intent.getExtras(); if (b != null) { peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this)); - videoId = b.getString("video_id", null); videoUuid = b.getString("video_uuid", null); playVideo(); } @@ -512,6 +504,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd peertube = apiResponse.getPeertubes().get(0); + List videoIds = new ArrayList<>(); + videoIds.add(peertube.getId()); + PlaylistsVM viewModel = new ViewModelProvider(this).get(PlaylistsVM.class); + viewModel.videoExists(videoIds).observe(this, this::manageVIewPlaylist); + add_comment_read.setOnClickListener(v -> { if (isLoggedIn(PeertubeActivity.this)) { @@ -529,8 +526,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd if (isLoggedIn(PeertubeActivity.this)) { String comment = add_comment_write.getText().toString(); if (comment.trim().length() > 0) { - PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); - viewModel.comment(ADD_COMMENT, peertube.getId(), null, comment).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(ADD_COMMENT, apiResponse1)); + PostActionsVM viewModelComment = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); + viewModelComment.comment(ADD_COMMENT, peertube.getId(), null, comment).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(ADD_COMMENT, apiResponse1)); add_comment_write.setText(""); add_comment_read.setVisibility(View.VISIBLE); add_comment_write.setVisibility(View.GONE); @@ -544,57 +541,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd peertube_playlist.setOnClickListener(v -> { - if (playlists != null && videoUuid != null) { - PopupMenu popup = new PopupMenu(PeertubeActivity.this, peertube_playlist); - - for (Playlist playlist : playlists) { - String title = null; - boolean isPresent = false; - String elementId = null; - PlaylistExist playlistExistTarget = null; - for (PlaylistExist playlistExist : playlistForVideo) { - if (playlist.getId().compareTo(playlistExist.getPlaylistId()) == 0) { - title = "✔ " + playlist.getDisplayName(); - isPresent = true; - playlistExistTarget = playlistExist; - elementId = playlistExist.getPlaylistElementId(); - break; - } - } - if (title == null) { - title = playlist.getDisplayName(); - } - MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title); - boolean finalIsPresent = isPresent; - String finalElementId = elementId; - PlaylistExist finalPlaylistExistTarget = playlistExistTarget; - item.setOnMenuItemClickListener(item1 -> { - item1.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); - item1.setActionView(new View(PeertubeActivity.this)); - item1.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { - @Override - public boolean onMenuItemActionExpand(MenuItem item1) { - return false; - } - - @Override - public boolean onMenuItemActionCollapse(MenuItem item1) { - return false; - } - }); - if (finalIsPresent) { - item1.setTitle(playlist.getDisplayName()); - playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, playlist, finalElementId).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.DELETE_VIDEOS, apiResponse3)); - playlistForVideo.remove(finalPlaylistExistTarget); - } else { - item1.setTitle("✔ " + playlist.getDisplayName()); - playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, playlist, videoUuid).observe(PeertubeActivity.this, apiResponse3 -> addElement(playlist.getId(), apiResponse3)); - } - return false; - }); - popup.show(); - } - } + PlaylistsVM viewModelOwnerPlaylist = new ViewModelProvider(PeertubeActivity.this).get(PlaylistsVM.class); + viewModelOwnerPlaylist.manage(PlaylistsVM.action.GET_PLAYLISTS, null, null).observe(PeertubeActivity.this, this::manageVIewPlaylists); }); no_action_text = findViewById(R.id.no_action_text); @@ -625,8 +573,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd peertube_like_count.setOnClickListener(v -> { if (isLoggedIn(PeertubeActivity.this)) { String newState = peertube.getMyRating().equals("like") ? "none" : "like"; - PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); - viewModel.post(RATEVIDEO, peertube.getId(), newState).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(RATEVIDEO, apiResponse1)); + PostActionsVM viewModelLike = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); + viewModelLike.post(RATEVIDEO, peertube.getId(), newState).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(RATEVIDEO, apiResponse1)); peertube.setMyRating(newState); int count = Integer.parseInt(peertube_like_count.getText().toString()); if (newState.compareTo("none") == 0) { @@ -646,8 +594,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd peertube_dislike_count.setOnClickListener(v -> { if (isLoggedIn(PeertubeActivity.this)) { String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike"; - PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); - viewModel.post(RATEVIDEO, peertube.getId(), newState).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(RATEVIDEO, apiResponse1)); + PostActionsVM viewModelLike = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); + viewModelLike.post(RATEVIDEO, peertube.getId(), newState).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(RATEVIDEO, apiResponse1)); peertube.setMyRating(newState); int count = Integer.parseInt(peertube_dislike_count.getText().toString()); if (newState.compareTo("none") == 0) { @@ -1085,36 +1033,88 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd peertube_dislike_count.setCompoundDrawablesWithIntrinsicBounds(null, thumbDown, null, null); } - public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) { - if (actionType == GET_PLAYLISTS && apiResponse != null) { - playlists = apiResponse.getPlaylists(); - List videoIds = new ArrayList<>(); - videoIds.add(videoId); - playlistsViewModel.videoExists(videoIds).observe(PeertubeActivity.this, this::manageVIewVideosExist); + public void manageVIewPlaylists(APIResponse apiResponse) { + Log.v(Helper.TAG,"manageVIewPlaylists: " + apiResponse); + if (apiResponse.getError() != null) { + return; + } + Log.v(Helper.TAG,"apiResponse.getPlaylists(): " + apiResponse.getPlaylists()); + if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) { + androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(PeertubeActivity.this); + builder.setTitle(R.string.modify_playlists); + + List ownerPlaylists = apiResponse.getPlaylists(); + if( ownerPlaylists == null){ + return; + } + String[] label = new String[ownerPlaylists.size()]; + boolean[] checked = new boolean[ownerPlaylists.size()]; + int i = 0; + List playlistsForVideo = playlists.get(peertube.getId()); + + + for (PlaylistData.Playlist playlist : ownerPlaylists) { + checked[i] = false; + if (playlistsForVideo != null) { + for (PlaylistExist playlistExist : playlistsForVideo) { + if (playlistExist != null && playlistExist.getPlaylistId().compareTo(playlist.getId()) == 0) { + checked[i] = true; + break; + } + } + } + label[i] = playlist.getDisplayName(); + i++; + } + + builder.setMultiChoiceItems(label, checked, (dialog, which, isChecked) -> { + PlaylistsVM playlistsViewModel = new ViewModelProvider(PeertubeActivity.this).get(PlaylistsVM.class); + if (isChecked) { //Add to playlist + playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, ownerPlaylists.get(which), peertube.getUuid()).observe(PeertubeActivity.this, apiResponse3 -> addElement(ownerPlaylists.get(which).getId(), peertube.getId(), apiResponse3)); + } else { //Remove from playlist + String elementInPlaylistId = null; + for (PlaylistExist playlistExist : peertube.getPlaylistExists()) { + if (playlistExist.getPlaylistId().compareTo(ownerPlaylists.get(which).getId()) == 0) { + elementInPlaylistId = playlistExist.getPlaylistElementId(); + } + } + playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, ownerPlaylists.get(which), elementInPlaylistId); + playlists.remove(peertube.getId()); + } + }); + builder.setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss()); + androidx.appcompat.app.AlertDialog dialog = builder.create(); + dialog.show(); } } + public void manageVIewPlaylist(APIResponse apiResponse) { + if (apiResponse.getError() != null || apiResponse.getVideoExistPlaylist() == null) { + return; + } + if (playlists == null) { + playlists = new HashMap<>(); + } + playlists.putAll(apiResponse.getVideoExistPlaylist()); + peertube.setPlaylistExists(playlists.get(peertube.getId())); - public void addElement(String playlistId, APIResponse apiResponse) { + } + + + public void addElement(String playlistId, String videoId, APIResponse apiResponse) { if (apiResponse != null && apiResponse.getActionReturn() != null) { + PlaylistExist playlistExist = new PlaylistExist(); playlistExist.setPlaylistId(playlistId); playlistExist.setPlaylistElementId(apiResponse.getActionReturn()); - playlistForVideo.add(playlistExist); + List playlistExistList = playlists.get(videoId); + if (playlistExistList == null) { + playlistExistList = new ArrayList<>(); + } + playlistExistList.add(playlistExist); + playlists.put(videoId, playlistExistList); } } - public void manageVIewVideosExist(APIResponse apiResponse) { - if (apiResponse.getError() == null && apiResponse.getVideoExistPlaylist() != null) { - Map> videoIds = apiResponse.getVideoExistPlaylist(); - Iterator>> it = videoIds.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry> pair = it.next(); - List playlistExistVideo = pair.getValue(); - playlistForVideo.addAll(playlistExistVideo); - it.remove(); - } - } - } @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 ba09f89..64a2a27 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java @@ -57,6 +57,7 @@ import retrofit2.http.QueryMap; @SuppressWarnings({"unused", "RedundantSuppression"}) public interface PeertubeService { + @GET("instances") Call getInstances(@QueryMap Map params, @Query("nsfwPolicy[]") String nsfwPolicy, @Query("categoriesOr[]") List categories, @Query("languagesOr[]") List languages); @@ -116,7 +117,7 @@ public interface PeertubeService { //Timelines Authenticated //Subscriber timeline @GET("users/me/subscriptions/videos?sort=-publishedAt") - Call getSubscriptionVideos(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("languageOneOf") List languageOneOf); + Call getSubscriptionVideos(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count, @Query("languageOneOf") List languageOneOf); //Overview videos @GET("overviews/videos") @@ -124,31 +125,31 @@ public interface PeertubeService { //Most liked videos @GET("videos?sort=-likes") - Call getMostLikedVideos(@Query("start") String maxId, @Query("languageOneOf") List languageOneOf); + Call getMostLikedVideos(@Query("start") String maxId, @Query("count") String count, @Query("languageOneOf") List languageOneOf); //Most liked videos @GET("videos?sort=-trending") - Call getTrendingVideos(@Query("start") String maxId, @Query("languageOneOf") List languageOneOf); + Call getTrendingVideos(@Query("start") String maxId, @Query("count") String count, @Query("languageOneOf") List languageOneOf); //Recently added videos @GET("videos?sort=-publishedAt") - Call getRecentlyAddedVideos(@Query("start") String maxId, @Query("languageOneOf") List languageOneOf); + Call getRecentlyAddedVideos(@Query("start") String maxId, @Query("count") String count, @Query("languageOneOf") List languageOneOf); //Local videos @GET("videos?sort=-publishedAt&filter=local") - Call getLocalVideos(@Query("start") String maxId, @Query("languageOneOf") List languageOneOf); + Call getLocalVideos(@Query("start") String maxId, @Query("count") String count, @Query("languageOneOf") List languageOneOf); //History @GET("users/me/history/videos") - Call getHistory(@Header("Authorization") String credentials, @Query("start") String maxId); + Call getHistory(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count); //Search @GET("search/videos") - Call searchVideos(@Query("search") String search, @Query("start") String maxId); + Call searchVideos(@Query("search") String search, @Query("start") String maxId, @Query("count") String count); //Get notifications @GET("users/me/notifications") - Call getNotifications(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("since_id") String sinceId); + Call getNotifications(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count, @Query("since_id") String sinceId); //Get/Post/Update/Delete video //Get a video @@ -160,11 +161,11 @@ public interface PeertubeService { //Get my video @GET("users/me/videos?sort=-publishedAt") - Call getMyVideos(@Header("Authorization") String credentials, @Query("start") String maxId); + Call getMyVideos(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count); //Get my video @GET("accounts/{name}/videos?sort=-publishedAt") - Call getVideosForAccount(@Query("start") String maxId); + Call getVideosForAccount(@Query("start") String maxId, @Query("count") String count); @Multipart @PUT("videos/{id}") @@ -211,7 +212,7 @@ public interface PeertubeService { Call getAllChannels(); @GET("video-channels/{channelHandle}/videos") - Call getChannelVideos(@Path("channelHandle") String channelHandle, @Query("start") String maxId); + Call getChannelVideos(@Path("channelHandle") String channelHandle, @Query("start") String maxId, @Query("count") String count); @POST("video-channels") Call addChannel(@Header("Authorization") String credentials, @Body ChannelParams channelParams); @@ -235,7 +236,7 @@ public interface PeertubeService { Call getPlaylist(@Path("id") String id); @GET("video-playlists/{id}/videos") - Call getVideosPlayList(@Header("Authorization") String credentials, @Path("id") String id); + Call getVideosPlayList(@Header("Authorization") String credentials, @Path("id") String id, @Query("start") String maxId, @Query("count") String count); @GET("users/me/video-playlists/videos-exist") Call>> getVideoExistsInPlaylist(@Header("Authorization") String credentials, @Query("videoIds") List videoIds); @@ -287,7 +288,7 @@ public interface PeertubeService { //Subscribe/Unsubscribe //subscribers @GET("users/me/subscriptions") - Call getSubscription(@Header("Authorization") String credentials, @Query("start") String maxId); + Call getSubscription(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count); @GET("users/me/subscriptions/exist") Call> getSubscriptionsExist(@Header("Authorization") String credentials, @Query("uris") List uris); @@ -302,7 +303,7 @@ public interface PeertubeService { //Mute/Unmute //Muted accounts @GET("users/me/blocklist/accounts") - Call getMuted(@Header("Authorization") String credentials, @Query("start") String maxId); + Call getMuted(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count); @FormUrlEncoded @POST("users/me/blocklist/accounts") @@ -324,7 +325,7 @@ public interface PeertubeService { //Comment @GET("videos/{id}/comment-threads") - Call getComments(@Path("id") String id, @Query("start") String maxId); + Call getComments(@Path("id") String id, @Query("start") String maxId, @Query("count") String count); @GET("videos/{id}/comment-threads/{threadId}") Call getReplies(@Path("id") String id, @Path("threadId") String threadId); 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 fe731ba..9284679 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java @@ -21,6 +21,7 @@ import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; import android.os.Handler; import android.os.Looper; +import android.util.Log; import java.io.File; import java.io.IOException; @@ -86,6 +87,7 @@ public class RetrofitPeertubeAPI { private String instance; private String token; private Set selection; + private String count = String.valueOf(Helper.VIDEOS_PER_PAGE); public RetrofitPeertubeAPI(Context context) { _context = context; @@ -98,6 +100,8 @@ public class RetrofitPeertubeAPI { this.instance = instance; this.token = token; finalUrl = "https://" + instance + "/api/v1/"; + SharedPreferences sharedpreferences = _context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + 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) { @@ -232,7 +236,8 @@ public class RetrofitPeertubeAPI { public APIResponse getNotifications(String max_id, String since_id) { APIResponse apiResponse = new APIResponse(); PeertubeService peertubeService = init(); - Call notificationsCall = peertubeService.getNotifications("Bearer " + token, max_id, since_id); + + Call notificationsCall = peertubeService.getNotifications("Bearer " + token, max_id, count, since_id); try { Response response = notificationsCall.execute(); if (response.isSuccessful() && response.body() != null) { @@ -285,7 +290,7 @@ public class RetrofitPeertubeAPI { public APIResponse getVideosForChannel(String channelId, String max_id) { APIResponse apiResponse = new APIResponse(); PeertubeService peertubeService = init(); - Call videoCall = peertubeService.getChannelVideos(channelId, max_id); + Call videoCall = peertubeService.getChannelVideos(channelId, max_id, count); if (videoCall != null) { try { Response response = videoCall.execute(); @@ -311,25 +316,25 @@ public class RetrofitPeertubeAPI { ArrayList filter = selection != null ? new ArrayList<>(selection) : null; switch (timelineType) { case MY_VIDEOS: - videoCall = peertubeService.getMyVideos(getToken(), max_id); + videoCall = peertubeService.getMyVideos(getToken(), max_id, count); break; case SUBSCRIBTIONS: - videoCall = peertubeService.getSubscriptionVideos(getToken(), max_id, filter); + videoCall = peertubeService.getSubscriptionVideos(getToken(), max_id, count, filter); break; case MOST_LIKED: - videoCall = peertubeService.getMostLikedVideos(max_id, filter); + videoCall = peertubeService.getMostLikedVideos(max_id, count, filter); break; case LOCAL: - videoCall = peertubeService.getLocalVideos(max_id, filter); + videoCall = peertubeService.getLocalVideos(max_id, count, filter); break; case TRENDING: - videoCall = peertubeService.getTrendingVideos(max_id, filter); + videoCall = peertubeService.getTrendingVideos(max_id, count, filter); break; case HISTORY: - videoCall = peertubeService.getHistory(getToken(), max_id); + videoCall = peertubeService.getHistory(getToken(), max_id, count); break; case RECENT: - videoCall = peertubeService.getRecentlyAddedVideos(max_id, filter); + videoCall = peertubeService.getRecentlyAddedVideos(max_id, count, filter); break; } if (videoCall != null) { @@ -630,7 +635,7 @@ public class RetrofitPeertubeAPI { */ public APIResponse searchPeertube(String query, String max_id) { PeertubeService peertubeService = init(); - Call searchVideosCall = peertubeService.searchVideos(query, max_id); + Call searchVideosCall = peertubeService.searchVideos(query, max_id, count); APIResponse apiResponse = new APIResponse(); try { Response response = searchVideosCall.execute(); @@ -835,7 +840,7 @@ public class RetrofitPeertubeAPI { */ public APIResponse getMuted(String maxId) { PeertubeService peertubeService = init(); - Call accountDataCall = peertubeService.getMuted("Bearer " + token, maxId); + Call accountDataCall = peertubeService.getMuted("Bearer " + token, maxId, count); APIResponse apiResponse = new APIResponse(); if (accountDataCall != null) { try { @@ -863,7 +868,7 @@ public class RetrofitPeertubeAPI { */ public APIResponse getSubscribtions(String maxId) { PeertubeService peertubeService = init(); - Call accountDataCall = peertubeService.getSubscription("Bearer " + token, maxId); + Call accountDataCall = peertubeService.getSubscription("Bearer " + token, maxId, count); APIResponse apiResponse = new APIResponse(); if (accountDataCall != null) { try { @@ -1082,7 +1087,7 @@ public class RetrofitPeertubeAPI { * @param videoId String id of the video * @return APIResponse */ - public APIResponse playlistAction(PlaylistsVM.action type, String playlistId, String videoId, String acct) { + public APIResponse playlistAction(PlaylistsVM.action type, String playlistId, String videoId, String acct, String max_id) { PeertubeService peertubeService = init(); APIResponse apiResponse = new APIResponse(); @@ -1104,10 +1109,13 @@ public class RetrofitPeertubeAPI { if (response.isSuccessful() && response.body() != null) { apiResponse.setPlaylists(response.body().data); } else { + setError(apiResponse, response.code(), response.errorBody()); } } else if (type == PlaylistsVM.action.GET_LIST_VIDEOS) { - Call videosPlayList = peertubeService.getVideosPlayList(getToken(), playlistId); + Log.v(Helper.TAG,"playlistId: " + playlistId); + Log.v(Helper.TAG,"max_id2: " + max_id); + Call videosPlayList = peertubeService.getVideosPlayList(getToken(), playlistId, max_id, count); Response response = videosPlayList.execute(); if (response.isSuccessful() && response.body() != null) { apiResponse.setVideoPlaylist(response.body().data); @@ -1173,7 +1181,7 @@ public class RetrofitPeertubeAPI { APIResponse apiResponse = new APIResponse(); try { if (type == CommentVM.action.GET_THREAD) { - Call commentsCall = peertubeService.getComments(videoId, max_id); + Call commentsCall = peertubeService.getComments(videoId, max_id, count); Response response = commentsCall.execute(); if (response.isSuccessful() && response.body() != null) { apiResponse.setComments(response.body().data); diff --git a/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayVideosFragment.java b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayVideosFragment.java index e23a4c5..d4294ec 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayVideosFragment.java +++ b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayVideosFragment.java @@ -19,6 +19,7 @@ import android.content.SharedPreferences; import android.graphics.Rect; import android.os.Bundle; import android.os.Handler; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -201,6 +202,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) { if (!flag_loading) { flag_loading = true; + Log.v(Helper.TAG,"max_id: " + max_id); loadTimeline(max_id); nextElementLoader.setVisibility(View.VISIBLE); } @@ -318,8 +320,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta if (max_id == null) max_id = "0"; //max_id needs to work like an offset - int tootPerPage = sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE); - max_id = String.valueOf(Integer.parseInt(max_id) + tootPerPage); + int videoPerPage = sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE); + max_id = String.valueOf(Integer.parseInt(max_id) + videoPerPage); if (apiResponse.getPeertubes() == null && apiResponse.getVideoPlaylist() == null) { return; } @@ -459,7 +461,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta if (type == TimelineVM.TimelineType.USER_VIDEOS) { viewModelFeeds.getVideosInChannel(channelId, max_id).observe(this.requireActivity(), this::manageVIewVideos); } else if (type == TimelineVM.TimelineType.VIDEOS_IN_PLAYLIST) { - viewModelFeeds.loadVideosInPlaylist(playlistId).observe(this.requireActivity(), this::manageVIewVideos); + + viewModelFeeds.loadVideosInPlaylist(playlistId, max_id).observe(this.requireActivity(), this::manageVIewVideos); } else { viewModelFeeds.getVideos(type, max_id).observe(this.requireActivity(), this::manageVIewVideos); } diff --git a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java index 2b463a8..fb526a8 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java +++ b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java @@ -106,7 +106,7 @@ public class Helper { public static final String VIDEO_ID = "video_id_update"; public static final String APP_PREFS = "app_prefs"; - public static final int VIDEOS_PER_PAGE = 40; + public static final int VIDEOS_PER_PAGE = 10; public static final String INTENT_ADD_UPLOADED_MEDIA = "intent_add_uploaded_media"; public static final String RECEIVE_ACTION = "receive_action"; public static final String SET_UNFOLLOW_VALIDATION = "set_unfollow_validation"; diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java index 8e2260b..78739d9 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java @@ -82,7 +82,7 @@ public class PlaylistsVM extends AndroidViewModel { apiResponse = new APIResponse(); apiResponse.setPlaylists(new ArrayList<>()); } else { - apiResponse = new RetrofitPeertubeAPI(_mContext).playlistAction(apiAction, playlist != null ? playlist.getId() : null, videoId, account.getAcct()); + apiResponse = new RetrofitPeertubeAPI(_mContext).playlistAction(apiAction, playlist != null ? playlist.getId() : null, videoId, account.getAcct(), null); } Handler mainHandler = new Handler(Looper.getMainLooper()); if (apiResponse != null) { diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java index 47bfbd1..6111027 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java @@ -57,9 +57,9 @@ public class TimelineVM extends AndroidViewModel { return apiResponseMutableLiveData; } - public LiveData loadVideosInPlaylist(String playlistId) { + public LiveData loadVideosInPlaylist(String playlistId, String maxId) { apiResponseMutableLiveData = new MutableLiveData<>(); - loadVideosInPlayList(playlistId); + loadVideosInPlayList(playlistId, maxId); return apiResponseMutableLiveData; } @@ -112,12 +112,12 @@ public class TimelineVM extends AndroidViewModel { }).start(); } - private void loadVideosInPlayList(String playlistId) { + private void loadVideosInPlayList(String playlistId, String maxId) { Context _mContext = getApplication().getApplicationContext(); new Thread(() -> { try { RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext); - APIResponse apiResponse = retrofitPeertubeAPI.playlistAction(GET_LIST_VIDEOS, playlistId, null, null); + APIResponse apiResponse = retrofitPeertubeAPI.playlistAction(GET_LIST_VIDEOS, playlistId, null, null, maxId); Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);