Change description + fix pagination
This commit is contained in:
parent
e771153f35
commit
7678da2bb6
|
@ -1 +1 @@
|
|||
TubeLab est une application Peertube pour les instances académiques.
|
||||
App for all Peertube instances
|
|
@ -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<PlaylistExist> playlistForVideo;
|
||||
private List<Playlist> playlists;
|
||||
private PlaylistsVM playlistsViewModel;
|
||||
private Map<String, List<PlaylistExist>> playlists;
|
||||
private boolean playInMinimized;
|
||||
private boolean onStopCalled;
|
||||
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);
|
||||
|
||||
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<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 -> {
|
||||
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<String> 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<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) {
|
||||
|
||||
PlaylistExist playlistExist = new PlaylistExist();
|
||||
playlistExist.setPlaylistId(playlistId);
|
||||
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
|
||||
public void onAllCommentRemoved() {
|
||||
|
|
|
@ -57,6 +57,7 @@ import retrofit2.http.QueryMap;
|
|||
|
||||
@SuppressWarnings({"unused", "RedundantSuppression"})
|
||||
public interface PeertubeService {
|
||||
|
||||
@GET("instances")
|
||||
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
|
||||
//Subscriber timeline
|
||||
@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
|
||||
@GET("overviews/videos")
|
||||
|
@ -124,31 +125,31 @@ public interface PeertubeService {
|
|||
|
||||
//Most liked videos
|
||||
@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
|
||||
@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
|
||||
@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
|
||||
@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
|
||||
@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
|
||||
@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("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 a video
|
||||
|
@ -160,11 +161,11 @@ public interface PeertubeService {
|
|||
|
||||
//Get my video
|
||||
@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("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
|
||||
@PUT("videos/{id}")
|
||||
|
@ -211,7 +212,7 @@ public interface PeertubeService {
|
|||
Call<ChannelData> getAllChannels();
|
||||
|
||||
@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")
|
||||
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);
|
||||
|
||||
@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")
|
||||
Call<Map<String, List<PlaylistExist>>> getVideoExistsInPlaylist(@Header("Authorization") String credentials, @Query("videoIds") List<String> videoIds);
|
||||
|
@ -287,7 +288,7 @@ public interface PeertubeService {
|
|||
//Subscribe/Unsubscribe
|
||||
//subscribers
|
||||
@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")
|
||||
Call<Map<String, Boolean>> getSubscriptionsExist(@Header("Authorization") String credentials, @Query("uris") List<String> uris);
|
||||
|
@ -302,7 +303,7 @@ public interface PeertubeService {
|
|||
//Mute/Unmute
|
||||
//Muted 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
|
||||
@POST("users/me/blocklist/accounts")
|
||||
|
@ -324,7 +325,7 @@ public interface PeertubeService {
|
|||
|
||||
//Comment
|
||||
@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}")
|
||||
Call<CommentData> getReplies(@Path("id") String id, @Path("threadId") String threadId);
|
||||
|
|
|
@ -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<String> 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<NotificationData> notificationsCall = peertubeService.getNotifications("Bearer " + token, max_id, since_id);
|
||||
|
||||
Call<NotificationData> notificationsCall = peertubeService.getNotifications("Bearer " + token, max_id, count, since_id);
|
||||
try {
|
||||
Response<NotificationData> 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<VideoData> videoCall = peertubeService.getChannelVideos(channelId, max_id);
|
||||
Call<VideoData> videoCall = peertubeService.getChannelVideos(channelId, max_id, count);
|
||||
if (videoCall != null) {
|
||||
try {
|
||||
Response<VideoData> response = videoCall.execute();
|
||||
|
@ -311,25 +316,25 @@ public class RetrofitPeertubeAPI {
|
|||
ArrayList<String> 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<VideoData> searchVideosCall = peertubeService.searchVideos(query, max_id);
|
||||
Call<VideoData> searchVideosCall = peertubeService.searchVideos(query, max_id, count);
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
try {
|
||||
Response<VideoData> response = searchVideosCall.execute();
|
||||
|
@ -835,7 +840,7 @@ public class RetrofitPeertubeAPI {
|
|||
*/
|
||||
public APIResponse getMuted(String maxId) {
|
||||
PeertubeService peertubeService = init();
|
||||
Call<BlockData> accountDataCall = peertubeService.getMuted("Bearer " + token, maxId);
|
||||
Call<BlockData> 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<AccountData> accountDataCall = peertubeService.getSubscription("Bearer " + token, maxId);
|
||||
Call<AccountData> 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<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();
|
||||
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<CommentData> commentsCall = peertubeService.getComments(videoId, max_id);
|
||||
Call<CommentData> commentsCall = peertubeService.getComments(videoId, max_id, count);
|
||||
Response<CommentData> response = commentsCall.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setComments(response.body().data);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -57,9 +57,9 @@ public class TimelineVM extends AndroidViewModel {
|
|||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> loadVideosInPlaylist(String playlistId) {
|
||||
public LiveData<APIResponse> 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);
|
||||
|
|
Loading…
Reference in New Issue