1
0
mirror of https://framagit.org/tom79/fedilab-tube synced 2025-02-16 12:00:42 +01:00

Change description + fix pagination

This commit is contained in:
Thomas 2020-10-08 18:13:04 +02:00
parent e771153f35
commit 7678da2bb6
8 changed files with 143 additions and 131 deletions

View File

@ -1 +1 @@
TubeLab est une application Peertube pour les instances académiques. App for all Peertube instances

View File

@ -31,6 +31,7 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.media.session.MediaSessionCompat;
import android.text.Html; import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -88,7 +89,7 @@ import com.google.android.exoplayer2.util.Util;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; 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.AccountData.Account;
import app.fedilab.fedilabtube.client.data.CaptionData.Caption; import app.fedilab.fedilabtube.client.data.CaptionData.Caption;
import app.fedilab.fedilabtube.client.data.CommentData.Comment; 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.data.VideoData;
import app.fedilab.fedilabtube.client.entities.File; import app.fedilab.fedilabtube.client.entities.File;
import app.fedilab.fedilabtube.client.entities.ItemStr; 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.getAttColor;
import static app.fedilab.fedilabtube.helper.Helper.getLiveInstance; import static app.fedilab.fedilabtube.helper.Helper.getLiveInstance;
import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn; 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 class PeertubeActivity extends AppCompatActivity implements CommentListAdapter.AllCommentRemoved {
public static String video_id; public static String video_id;
private String peertubeInstance, videoId, videoUuid; private String peertubeInstance, videoUuid;
private FullScreenMediaController.fullscreen fullscreen; private FullScreenMediaController.fullscreen fullscreen;
private RelativeLayout loader; private RelativeLayout loader;
private TextView peertube_view_count, peertube_playlist, peertube_bookmark, peertube_like_count, peertube_dislike_count, peertube_description, peertube_title, more_actions; 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 ImageView send;
private TextView add_comment_read; private TextView add_comment_read;
private EditText add_comment_write; private EditText add_comment_write;
private List<PlaylistExist> playlistForVideo; private Map<String, List<PlaylistExist>> playlists;
private List<Playlist> playlists;
private PlaylistsVM playlistsViewModel;
private boolean playInMinimized; private boolean playInMinimized;
private boolean onStopCalled; private boolean onStopCalled;
private List<Caption> captions; private List<Caption> captions;
@ -222,19 +220,14 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
mode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL); 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(); Bundle b = getIntent().getExtras();
if (b != null) { if (b != null) {
peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this)); peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this));
videoId = b.getString("video_id", null);
videoUuid = b.getString("video_uuid", null); videoUuid = b.getString("video_uuid", null);
isMyVideo = b.getBoolean("isMyVideo", false); isMyVideo = b.getBoolean("isMyVideo", false);
} }
playInMinimized = sharedpreferences.getBoolean(getString(R.string.set_video_minimize_choice), true); playInMinimized = sharedpreferences.getBoolean(getString(R.string.set_video_minimize_choice), true);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N
&& !getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) { && !getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
@ -346,7 +339,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
Bundle b = intent.getExtras(); Bundle b = intent.getExtras();
if (b != null) { if (b != null) {
peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this)); peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this));
videoId = b.getString("video_id", null);
videoUuid = b.getString("video_uuid", null); videoUuid = b.getString("video_uuid", null);
playVideo(); playVideo();
} }
@ -512,6 +504,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube = apiResponse.getPeertubes().get(0); peertube = apiResponse.getPeertubes().get(0);
List<String> 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 -> { add_comment_read.setOnClickListener(v -> {
if (isLoggedIn(PeertubeActivity.this)) { if (isLoggedIn(PeertubeActivity.this)) {
@ -529,8 +526,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
if (isLoggedIn(PeertubeActivity.this)) { if (isLoggedIn(PeertubeActivity.this)) {
String comment = add_comment_write.getText().toString(); String comment = add_comment_write.getText().toString();
if (comment.trim().length() > 0) { if (comment.trim().length() > 0) {
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); PostActionsVM viewModelComment = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
viewModel.comment(ADD_COMMENT, peertube.getId(), null, comment).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(ADD_COMMENT, apiResponse1)); viewModelComment.comment(ADD_COMMENT, peertube.getId(), null, comment).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(ADD_COMMENT, apiResponse1));
add_comment_write.setText(""); add_comment_write.setText("");
add_comment_read.setVisibility(View.VISIBLE); add_comment_read.setVisibility(View.VISIBLE);
add_comment_write.setVisibility(View.GONE); add_comment_write.setVisibility(View.GONE);
@ -544,57 +541,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube_playlist.setOnClickListener(v -> { peertube_playlist.setOnClickListener(v -> {
if (playlists != null && videoUuid != null) { PlaylistsVM viewModelOwnerPlaylist = new ViewModelProvider(PeertubeActivity.this).get(PlaylistsVM.class);
PopupMenu popup = new PopupMenu(PeertubeActivity.this, peertube_playlist); viewModelOwnerPlaylist.manage(PlaylistsVM.action.GET_PLAYLISTS, null, null).observe(PeertubeActivity.this, this::manageVIewPlaylists);
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();
}
}
}); });
no_action_text = findViewById(R.id.no_action_text); 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 -> { peertube_like_count.setOnClickListener(v -> {
if (isLoggedIn(PeertubeActivity.this)) { if (isLoggedIn(PeertubeActivity.this)) {
String newState = peertube.getMyRating().equals("like") ? "none" : "like"; String newState = peertube.getMyRating().equals("like") ? "none" : "like";
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); PostActionsVM viewModelLike = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
viewModel.post(RATEVIDEO, peertube.getId(), newState).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(RATEVIDEO, apiResponse1)); viewModelLike.post(RATEVIDEO, peertube.getId(), newState).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(RATEVIDEO, apiResponse1));
peertube.setMyRating(newState); peertube.setMyRating(newState);
int count = Integer.parseInt(peertube_like_count.getText().toString()); int count = Integer.parseInt(peertube_like_count.getText().toString());
if (newState.compareTo("none") == 0) { if (newState.compareTo("none") == 0) {
@ -646,8 +594,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube_dislike_count.setOnClickListener(v -> { peertube_dislike_count.setOnClickListener(v -> {
if (isLoggedIn(PeertubeActivity.this)) { if (isLoggedIn(PeertubeActivity.this)) {
String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike"; String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike";
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); PostActionsVM viewModelLike = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
viewModel.post(RATEVIDEO, peertube.getId(), newState).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(RATEVIDEO, apiResponse1)); viewModelLike.post(RATEVIDEO, peertube.getId(), newState).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(RATEVIDEO, apiResponse1));
peertube.setMyRating(newState); peertube.setMyRating(newState);
int count = Integer.parseInt(peertube_dislike_count.getText().toString()); int count = Integer.parseInt(peertube_dislike_count.getText().toString());
if (newState.compareTo("none") == 0) { if (newState.compareTo("none") == 0) {
@ -1085,36 +1033,88 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube_dislike_count.setCompoundDrawablesWithIntrinsicBounds(null, thumbDown, null, null); peertube_dislike_count.setCompoundDrawablesWithIntrinsicBounds(null, thumbDown, null, null);
} }
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) { public void manageVIewPlaylists(APIResponse apiResponse) {
if (actionType == GET_PLAYLISTS && apiResponse != null) { Log.v(Helper.TAG,"manageVIewPlaylists: " + apiResponse);
playlists = apiResponse.getPlaylists(); if (apiResponse.getError() != null) {
List<String> videoIds = new ArrayList<>(); return;
videoIds.add(videoId); }
playlistsViewModel.videoExists(videoIds).observe(PeertubeActivity.this, this::manageVIewVideosExist); 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<PlaylistData.Playlist> ownerPlaylists = apiResponse.getPlaylists();
if( ownerPlaylists == null){
return;
}
String[] label = new String[ownerPlaylists.size()];
boolean[] checked = new boolean[ownerPlaylists.size()];
int i = 0;
List<PlaylistExist> 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) { if (apiResponse != null && apiResponse.getActionReturn() != null) {
PlaylistExist playlistExist = new PlaylistExist(); PlaylistExist playlistExist = new PlaylistExist();
playlistExist.setPlaylistId(playlistId); playlistExist.setPlaylistId(playlistId);
playlistExist.setPlaylistElementId(apiResponse.getActionReturn()); playlistExist.setPlaylistElementId(apiResponse.getActionReturn());
playlistForVideo.add(playlistExist); List<PlaylistExist> 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<String, List<PlaylistExist>> videoIds = apiResponse.getVideoExistPlaylist();
Iterator<Map.Entry<String, List<PlaylistExist>>> it = videoIds.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, List<PlaylistExist>> pair = it.next();
List<PlaylistExist> playlistExistVideo = pair.getValue();
playlistForVideo.addAll(playlistExistVideo);
it.remove();
}
}
}
@Override @Override
public void onAllCommentRemoved() { public void onAllCommentRemoved() {

View File

@ -57,6 +57,7 @@ import retrofit2.http.QueryMap;
@SuppressWarnings({"unused", "RedundantSuppression"}) @SuppressWarnings({"unused", "RedundantSuppression"})
public interface PeertubeService { public interface PeertubeService {
@GET("instances") @GET("instances")
Call<InstanceData> getInstances(@QueryMap Map<String, String> params, @Query("nsfwPolicy[]") String nsfwPolicy, @Query("categoriesOr[]") List<Integer> categories, @Query("languagesOr[]") List<String> languages); Call<InstanceData> getInstances(@QueryMap Map<String, String> params, @Query("nsfwPolicy[]") String nsfwPolicy, @Query("categoriesOr[]") List<Integer> categories, @Query("languagesOr[]") List<String> languages);
@ -116,7 +117,7 @@ public interface PeertubeService {
//Timelines Authenticated //Timelines Authenticated
//Subscriber timeline //Subscriber timeline
@GET("users/me/subscriptions/videos?sort=-publishedAt") @GET("users/me/subscriptions/videos?sort=-publishedAt")
Call<VideoData> getSubscriptionVideos(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("languageOneOf") List<String> languageOneOf); Call<VideoData> getSubscriptionVideos(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count, @Query("languageOneOf") List<String> languageOneOf);
//Overview videos //Overview videos
@GET("overviews/videos") @GET("overviews/videos")
@ -124,31 +125,31 @@ public interface PeertubeService {
//Most liked videos //Most liked videos
@GET("videos?sort=-likes") @GET("videos?sort=-likes")
Call<VideoData> getMostLikedVideos(@Query("start") String maxId, @Query("languageOneOf") List<String> languageOneOf); Call<VideoData> getMostLikedVideos(@Query("start") String maxId, @Query("count") String count, @Query("languageOneOf") List<String> languageOneOf);
//Most liked videos //Most liked videos
@GET("videos?sort=-trending") @GET("videos?sort=-trending")
Call<VideoData> getTrendingVideos(@Query("start") String maxId, @Query("languageOneOf") List<String> languageOneOf); Call<VideoData> getTrendingVideos(@Query("start") String maxId, @Query("count") String count, @Query("languageOneOf") List<String> languageOneOf);
//Recently added videos //Recently added videos
@GET("videos?sort=-publishedAt") @GET("videos?sort=-publishedAt")
Call<VideoData> getRecentlyAddedVideos(@Query("start") String maxId, @Query("languageOneOf") List<String> languageOneOf); Call<VideoData> getRecentlyAddedVideos(@Query("start") String maxId, @Query("count") String count, @Query("languageOneOf") List<String> languageOneOf);
//Local videos //Local videos
@GET("videos?sort=-publishedAt&filter=local") @GET("videos?sort=-publishedAt&filter=local")
Call<VideoData> getLocalVideos(@Query("start") String maxId, @Query("languageOneOf") List<String> languageOneOf); Call<VideoData> getLocalVideos(@Query("start") String maxId, @Query("count") String count, @Query("languageOneOf") List<String> languageOneOf);
//History //History
@GET("users/me/history/videos") @GET("users/me/history/videos")
Call<VideoData> getHistory(@Header("Authorization") String credentials, @Query("start") String maxId); Call<VideoData> getHistory(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count);
//Search //Search
@GET("search/videos") @GET("search/videos")
Call<VideoData> searchVideos(@Query("search") String search, @Query("start") String maxId); Call<VideoData> searchVideos(@Query("search") String search, @Query("start") String maxId, @Query("count") String count);
//Get notifications //Get notifications
@GET("users/me/notifications") @GET("users/me/notifications")
Call<NotificationData> getNotifications(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("since_id") String sinceId); Call<NotificationData> getNotifications(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count, @Query("since_id") String sinceId);
//Get/Post/Update/Delete video //Get/Post/Update/Delete video
//Get a video //Get a video
@ -160,11 +161,11 @@ public interface PeertubeService {
//Get my video //Get my video
@GET("users/me/videos?sort=-publishedAt") @GET("users/me/videos?sort=-publishedAt")
Call<VideoData> getMyVideos(@Header("Authorization") String credentials, @Query("start") String maxId); Call<VideoData> getMyVideos(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count);
//Get my video //Get my video
@GET("accounts/{name}/videos?sort=-publishedAt") @GET("accounts/{name}/videos?sort=-publishedAt")
Call<VideoData.Video> getVideosForAccount(@Query("start") String maxId); Call<VideoData.Video> getVideosForAccount(@Query("start") String maxId, @Query("count") String count);
@Multipart @Multipart
@PUT("videos/{id}") @PUT("videos/{id}")
@ -211,7 +212,7 @@ public interface PeertubeService {
Call<ChannelData> getAllChannels(); Call<ChannelData> getAllChannels();
@GET("video-channels/{channelHandle}/videos") @GET("video-channels/{channelHandle}/videos")
Call<VideoData> getChannelVideos(@Path("channelHandle") String channelHandle, @Query("start") String maxId); Call<VideoData> getChannelVideos(@Path("channelHandle") String channelHandle, @Query("start") String maxId, @Query("count") String count);
@POST("video-channels") @POST("video-channels")
Call<ChannelData.ChannelCreation> addChannel(@Header("Authorization") String credentials, @Body ChannelParams channelParams); Call<ChannelData.ChannelCreation> addChannel(@Header("Authorization") String credentials, @Body ChannelParams channelParams);
@ -235,7 +236,7 @@ public interface PeertubeService {
Call<PlaylistData.Playlist> getPlaylist(@Path("id") String id); Call<PlaylistData.Playlist> getPlaylist(@Path("id") String id);
@GET("video-playlists/{id}/videos") @GET("video-playlists/{id}/videos")
Call<VideoPlaylistData> getVideosPlayList(@Header("Authorization") String credentials, @Path("id") String id); Call<VideoPlaylistData> getVideosPlayList(@Header("Authorization") String credentials, @Path("id") String id, @Query("start") String maxId, @Query("count") String count);
@GET("users/me/video-playlists/videos-exist") @GET("users/me/video-playlists/videos-exist")
Call<Map<String, List<PlaylistExist>>> getVideoExistsInPlaylist(@Header("Authorization") String credentials, @Query("videoIds") List<String> videoIds); Call<Map<String, List<PlaylistExist>>> getVideoExistsInPlaylist(@Header("Authorization") String credentials, @Query("videoIds") List<String> videoIds);
@ -287,7 +288,7 @@ public interface PeertubeService {
//Subscribe/Unsubscribe //Subscribe/Unsubscribe
//subscribers //subscribers
@GET("users/me/subscriptions") @GET("users/me/subscriptions")
Call<AccountData> getSubscription(@Header("Authorization") String credentials, @Query("start") String maxId); Call<AccountData> getSubscription(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count);
@GET("users/me/subscriptions/exist") @GET("users/me/subscriptions/exist")
Call<Map<String, Boolean>> getSubscriptionsExist(@Header("Authorization") String credentials, @Query("uris") List<String> uris); Call<Map<String, Boolean>> getSubscriptionsExist(@Header("Authorization") String credentials, @Query("uris") List<String> uris);
@ -302,7 +303,7 @@ public interface PeertubeService {
//Mute/Unmute //Mute/Unmute
//Muted accounts //Muted accounts
@GET("users/me/blocklist/accounts") @GET("users/me/blocklist/accounts")
Call<BlockData> getMuted(@Header("Authorization") String credentials, @Query("start") String maxId); Call<BlockData> getMuted(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count);
@FormUrlEncoded @FormUrlEncoded
@POST("users/me/blocklist/accounts") @POST("users/me/blocklist/accounts")
@ -324,7 +325,7 @@ public interface PeertubeService {
//Comment //Comment
@GET("videos/{id}/comment-threads") @GET("videos/{id}/comment-threads")
Call<CommentData> getComments(@Path("id") String id, @Query("start") String maxId); Call<CommentData> getComments(@Path("id") String id, @Query("start") String maxId, @Query("count") String count);
@GET("videos/{id}/comment-threads/{threadId}") @GET("videos/{id}/comment-threads/{threadId}")
Call<CommentData> getReplies(@Path("id") String id, @Path("threadId") String threadId); Call<CommentData> getReplies(@Path("id") String id, @Path("threadId") String threadId);

View File

@ -21,6 +21,7 @@ import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Log;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -86,6 +87,7 @@ public class RetrofitPeertubeAPI {
private String instance; private String instance;
private String token; private String token;
private Set<String> selection; private Set<String> selection;
private String count = String.valueOf(Helper.VIDEOS_PER_PAGE);
public RetrofitPeertubeAPI(Context context) { public RetrofitPeertubeAPI(Context context) {
_context = context; _context = context;
@ -98,6 +100,8 @@ public class RetrofitPeertubeAPI {
this.instance = instance; this.instance = instance;
this.token = token; this.token = token;
finalUrl = "https://" + instance + "/api/v1/"; 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) { 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) { public APIResponse getNotifications(String max_id, String since_id) {
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
Call<NotificationData> notificationsCall = peertubeService.getNotifications("Bearer " + token, max_id, since_id);
Call<NotificationData> notificationsCall = peertubeService.getNotifications("Bearer " + token, max_id, count, since_id);
try { try {
Response<NotificationData> response = notificationsCall.execute(); Response<NotificationData> response = notificationsCall.execute();
if (response.isSuccessful() && response.body() != null) { if (response.isSuccessful() && response.body() != null) {
@ -285,7 +290,7 @@ public class RetrofitPeertubeAPI {
public APIResponse getVideosForChannel(String channelId, String max_id) { public APIResponse getVideosForChannel(String channelId, String max_id) {
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
Call<VideoData> videoCall = peertubeService.getChannelVideos(channelId, max_id); Call<VideoData> videoCall = peertubeService.getChannelVideos(channelId, max_id, count);
if (videoCall != null) { if (videoCall != null) {
try { try {
Response<VideoData> response = videoCall.execute(); Response<VideoData> response = videoCall.execute();
@ -311,25 +316,25 @@ public class RetrofitPeertubeAPI {
ArrayList<String> filter = selection != null ? new ArrayList<>(selection) : null; ArrayList<String> filter = selection != null ? new ArrayList<>(selection) : null;
switch (timelineType) { switch (timelineType) {
case MY_VIDEOS: case MY_VIDEOS:
videoCall = peertubeService.getMyVideos(getToken(), max_id); videoCall = peertubeService.getMyVideos(getToken(), max_id, count);
break; break;
case SUBSCRIBTIONS: case SUBSCRIBTIONS:
videoCall = peertubeService.getSubscriptionVideos(getToken(), max_id, filter); videoCall = peertubeService.getSubscriptionVideos(getToken(), max_id, count, filter);
break; break;
case MOST_LIKED: case MOST_LIKED:
videoCall = peertubeService.getMostLikedVideos(max_id, filter); videoCall = peertubeService.getMostLikedVideos(max_id, count, filter);
break; break;
case LOCAL: case LOCAL:
videoCall = peertubeService.getLocalVideos(max_id, filter); videoCall = peertubeService.getLocalVideos(max_id, count, filter);
break; break;
case TRENDING: case TRENDING:
videoCall = peertubeService.getTrendingVideos(max_id, filter); videoCall = peertubeService.getTrendingVideos(max_id, count, filter);
break; break;
case HISTORY: case HISTORY:
videoCall = peertubeService.getHistory(getToken(), max_id); videoCall = peertubeService.getHistory(getToken(), max_id, count);
break; break;
case RECENT: case RECENT:
videoCall = peertubeService.getRecentlyAddedVideos(max_id, filter); videoCall = peertubeService.getRecentlyAddedVideos(max_id, count, filter);
break; break;
} }
if (videoCall != null) { if (videoCall != null) {
@ -630,7 +635,7 @@ public class RetrofitPeertubeAPI {
*/ */
public APIResponse searchPeertube(String query, String max_id) { public APIResponse searchPeertube(String query, String max_id) {
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
Call<VideoData> searchVideosCall = peertubeService.searchVideos(query, max_id); Call<VideoData> searchVideosCall = peertubeService.searchVideos(query, max_id, count);
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
try { try {
Response<VideoData> response = searchVideosCall.execute(); Response<VideoData> response = searchVideosCall.execute();
@ -835,7 +840,7 @@ public class RetrofitPeertubeAPI {
*/ */
public APIResponse getMuted(String maxId) { public APIResponse getMuted(String maxId) {
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
Call<BlockData> accountDataCall = peertubeService.getMuted("Bearer " + token, maxId); Call<BlockData> accountDataCall = peertubeService.getMuted("Bearer " + token, maxId, count);
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
if (accountDataCall != null) { if (accountDataCall != null) {
try { try {
@ -863,7 +868,7 @@ public class RetrofitPeertubeAPI {
*/ */
public APIResponse getSubscribtions(String maxId) { public APIResponse getSubscribtions(String maxId) {
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
Call<AccountData> accountDataCall = peertubeService.getSubscription("Bearer " + token, maxId); Call<AccountData> accountDataCall = peertubeService.getSubscription("Bearer " + token, maxId, count);
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
if (accountDataCall != null) { if (accountDataCall != null) {
try { try {
@ -1082,7 +1087,7 @@ public class RetrofitPeertubeAPI {
* @param videoId String id of the video * @param videoId String id of the video
* @return APIResponse * @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(); PeertubeService peertubeService = init();
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
@ -1104,10 +1109,13 @@ public class RetrofitPeertubeAPI {
if (response.isSuccessful() && response.body() != null) { if (response.isSuccessful() && response.body() != null) {
apiResponse.setPlaylists(response.body().data); apiResponse.setPlaylists(response.body().data);
} else { } else {
setError(apiResponse, response.code(), response.errorBody()); setError(apiResponse, response.code(), response.errorBody());
} }
} else if (type == PlaylistsVM.action.GET_LIST_VIDEOS) { } else if (type == PlaylistsVM.action.GET_LIST_VIDEOS) {
Call<VideoPlaylistData> videosPlayList = peertubeService.getVideosPlayList(getToken(), playlistId); Log.v(Helper.TAG,"playlistId: " + playlistId);
Log.v(Helper.TAG,"max_id2: " + max_id);
Call<VideoPlaylistData> videosPlayList = peertubeService.getVideosPlayList(getToken(), playlistId, max_id, count);
Response<VideoPlaylistData> response = videosPlayList.execute(); Response<VideoPlaylistData> response = videosPlayList.execute();
if (response.isSuccessful() && response.body() != null) { if (response.isSuccessful() && response.body() != null) {
apiResponse.setVideoPlaylist(response.body().data); apiResponse.setVideoPlaylist(response.body().data);
@ -1173,7 +1181,7 @@ public class RetrofitPeertubeAPI {
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
try { try {
if (type == CommentVM.action.GET_THREAD) { if (type == CommentVM.action.GET_THREAD) {
Call<CommentData> commentsCall = peertubeService.getComments(videoId, max_id); Call<CommentData> commentsCall = peertubeService.getComments(videoId, max_id, count);
Response<CommentData> response = commentsCall.execute(); Response<CommentData> response = commentsCall.execute();
if (response.isSuccessful() && response.body() != null) { if (response.isSuccessful() && response.body() != null) {
apiResponse.setComments(response.body().data); apiResponse.setComments(response.body().data);

View File

@ -19,6 +19,7 @@ import android.content.SharedPreferences;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -201,6 +202,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) { if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
if (!flag_loading) { if (!flag_loading) {
flag_loading = true; flag_loading = true;
Log.v(Helper.TAG,"max_id: " + max_id);
loadTimeline(max_id); loadTimeline(max_id);
nextElementLoader.setVisibility(View.VISIBLE); nextElementLoader.setVisibility(View.VISIBLE);
} }
@ -318,8 +320,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
if (max_id == null) if (max_id == null)
max_id = "0"; max_id = "0";
//max_id needs to work like an offset //max_id needs to work like an offset
int tootPerPage = sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE); int videoPerPage = sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE);
max_id = String.valueOf(Integer.parseInt(max_id) + tootPerPage); max_id = String.valueOf(Integer.parseInt(max_id) + videoPerPage);
if (apiResponse.getPeertubes() == null && apiResponse.getVideoPlaylist() == null) { if (apiResponse.getPeertubes() == null && apiResponse.getVideoPlaylist() == null) {
return; return;
} }
@ -459,7 +461,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
if (type == TimelineVM.TimelineType.USER_VIDEOS) { if (type == TimelineVM.TimelineType.USER_VIDEOS) {
viewModelFeeds.getVideosInChannel(channelId, max_id).observe(this.requireActivity(), this::manageVIewVideos); viewModelFeeds.getVideosInChannel(channelId, max_id).observe(this.requireActivity(), this::manageVIewVideos);
} else if (type == TimelineVM.TimelineType.VIDEOS_IN_PLAYLIST) { } 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 { } else {
viewModelFeeds.getVideos(type, max_id).observe(this.requireActivity(), this::manageVIewVideos); viewModelFeeds.getVideos(type, max_id).observe(this.requireActivity(), this::manageVIewVideos);
} }

View File

@ -106,7 +106,7 @@ public class Helper {
public static final String VIDEO_ID = "video_id_update"; public static final String VIDEO_ID = "video_id_update";
public static final String APP_PREFS = "app_prefs"; 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 INTENT_ADD_UPLOADED_MEDIA = "intent_add_uploaded_media";
public static final String RECEIVE_ACTION = "receive_action"; public static final String RECEIVE_ACTION = "receive_action";
public static final String SET_UNFOLLOW_VALIDATION = "set_unfollow_validation"; public static final String SET_UNFOLLOW_VALIDATION = "set_unfollow_validation";

View File

@ -82,7 +82,7 @@ public class PlaylistsVM extends AndroidViewModel {
apiResponse = new APIResponse(); apiResponse = new APIResponse();
apiResponse.setPlaylists(new ArrayList<>()); apiResponse.setPlaylists(new ArrayList<>());
} else { } 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()); Handler mainHandler = new Handler(Looper.getMainLooper());
if (apiResponse != null) { if (apiResponse != null) {

View File

@ -57,9 +57,9 @@ public class TimelineVM extends AndroidViewModel {
return apiResponseMutableLiveData; return apiResponseMutableLiveData;
} }
public LiveData<APIResponse> loadVideosInPlaylist(String playlistId) { public LiveData<APIResponse> loadVideosInPlaylist(String playlistId, String maxId) {
apiResponseMutableLiveData = new MutableLiveData<>(); apiResponseMutableLiveData = new MutableLiveData<>();
loadVideosInPlayList(playlistId); loadVideosInPlayList(playlistId, maxId);
return apiResponseMutableLiveData; return apiResponseMutableLiveData;
} }
@ -112,12 +112,12 @@ public class TimelineVM extends AndroidViewModel {
}).start(); }).start();
} }
private void loadVideosInPlayList(String playlistId) { private void loadVideosInPlayList(String playlistId, String maxId) {
Context _mContext = getApplication().getApplicationContext(); Context _mContext = getApplication().getApplicationContext();
new Thread(() -> { new Thread(() -> {
try { try {
RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext); 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()); Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse); Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);