1
0
mirror of https://framagit.org/tom79/fedilab-tube synced 2025-04-27 16:38:51 +02:00

Last fixes

This commit is contained in:
Thomas 2020-10-03 18:37:34 +02:00
parent 48fe22c8db
commit c774dcee96
16 changed files with 115 additions and 122 deletions

View File

@ -86,7 +86,9 @@ 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.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.APIResponse;
@ -363,11 +365,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube_playlist.setVisibility(View.VISIBLE); peertube_playlist.setVisibility(View.VISIBLE);
peertube_bookmark.setVisibility(View.GONE); peertube_bookmark.setVisibility(View.GONE);
List<String> videoIds = new ArrayList<>();
videoIds.add(videoId);
if (Helper.isLoggedIn(PeertubeActivity.this)) {
playlistsViewModel.videoExists(videoIds).observe(PeertubeActivity.this, this::manageVIewVideosExist);
}
TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class); TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class);
feedsViewModel.getVideo(videoId).observe(PeertubeActivity.this, this::manageVIewVideo); feedsViewModel.getVideo(videoId).observe(PeertubeActivity.this, this::manageVIewVideo);
CaptionsVM captionsViewModel = new ViewModelProvider(PeertubeActivity.this).get(CaptionsVM.class); CaptionsVM captionsViewModel = new ViewModelProvider(PeertubeActivity.this).get(CaptionsVM.class);
@ -513,7 +510,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube = apiResponse.getPeertubes().get(0); peertube = apiResponse.getPeertubes().get(0);
add_comment_read.setOnClickListener(v -> { add_comment_read.setOnClickListener(v -> {
if (isLoggedIn(PeertubeActivity.this)) { if (isLoggedIn(PeertubeActivity.this)) {
add_comment_read.setVisibility(View.GONE); add_comment_read.setVisibility(View.GONE);
@ -545,7 +541,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube_playlist.setOnClickListener(v -> { peertube_playlist.setOnClickListener(v -> {
if (playlists != null && peertube.getId() != null) { if (playlists != null && videoId != null) {
PopupMenu popup = new PopupMenu(PeertubeActivity.this, peertube_playlist); PopupMenu popup = new PopupMenu(PeertubeActivity.this, peertube_playlist);
for (Playlist playlist : playlists) { for (Playlist playlist : playlists) {
@ -586,7 +582,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
playlistForVideo.remove(playlist.getId()); playlistForVideo.remove(playlist.getId());
} else { } else {
item1.setTitle("" + playlist.getDisplayName()); item1.setTitle("" + playlist.getDisplayName());
playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, playlist, peertube.getId()).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.ADD_VIDEOS, apiResponse3)); playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, playlist, videoId).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.ADD_VIDEOS, apiResponse3));
playlistForVideo.add(playlist.getId()); playlistForVideo.add(playlist.getId());
} }
return false; return false;
@ -846,7 +842,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -1074,19 +1069,23 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
} }
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) { public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
if (actionType == GET_PLAYLISTS && apiResponse != null) { if (actionType == GET_PLAYLISTS && apiResponse != null) {
playlists = apiResponse.getPlaylists(); playlists = apiResponse.getPlaylists();
playlistsViewModel.videoExists(videoId).observe(PeertubeActivity.this, this::manageVIewVideosExist);
} }
} }
public void manageVIewVideosExist(APIResponse apiResponse) { public void manageVIewVideosExist(APIResponse apiResponse) {
playlistForVideo = new ArrayList<>();
if (apiResponse.getError() == null && apiResponse.getVideoExistPlaylist() != null) { if (apiResponse.getError() == null && apiResponse.getVideoExistPlaylist() != null) {
Map<String, List<PlaylistExist>> videoIds = apiResponse.getVideoExistPlaylist();
List<PlaylistExist.VideoId> videoIds = apiResponse.getVideoExistPlaylist(); Iterator<Map.Entry<String, List<PlaylistExist>>> it = videoIds.entrySet().iterator();
for(PlaylistExist.VideoId videoId: videoIds) { while (it.hasNext()) {
playlistForVideo.add(videoId.getPlaylistId()); Map.Entry<String, List<PlaylistExist>> pair = it.next();
List<PlaylistExist> playlistExistVideo = pair.getValue();
for (PlaylistExist playlistExist : playlistExistVideo) {
playlistForVideo.add(playlistExist.getPlaylistId());
}
it.remove();
} }
} }
} }

View File

@ -29,7 +29,7 @@ import app.fedilab.fedilabtube.client.data.VideoData;
import app.fedilab.fedilabtube.client.data.VideoPlaylistData.VideoPlaylist; import app.fedilab.fedilabtube.client.data.VideoPlaylistData.VideoPlaylist;
import app.fedilab.fedilabtube.client.entities.Error; import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.OverviewVideo; import app.fedilab.fedilabtube.client.entities.OverviewVideo;
import app.fedilab.fedilabtube.client.entities.PlaylistExist.VideoId; import app.fedilab.fedilabtube.client.entities.PlaylistExist;
import app.fedilab.fedilabtube.client.entities.Rating; import app.fedilab.fedilabtube.client.entities.Rating;
@SuppressWarnings({"unused", "RedundantSuppression"}) @SuppressWarnings({"unused", "RedundantSuppression"})
@ -41,7 +41,7 @@ public class APIResponse {
private String actionReturn = null; private String actionReturn = null;
private Rating rating; private Rating rating;
private OverviewVideo overviewVideo = null; private OverviewVideo overviewVideo = null;
private List<VideoId> videoExistPlaylist = null; private Map<String, List<PlaylistExist>> videoExistPlaylist = null;
private List<VideoData.Video> peertubes = null; private List<VideoData.Video> peertubes = null;
private List<CommentData.Comment> comments = null; private List<CommentData.Comment> comments = null;
private List<Block> muted; private List<Block> muted;
@ -240,11 +240,11 @@ public class APIResponse {
this.videoPlaylist = videoPlaylist; this.videoPlaylist = videoPlaylist;
} }
public List<VideoId> getVideoExistPlaylist() { public Map<String, List<PlaylistExist>> getVideoExistPlaylist() {
return videoExistPlaylist; return videoExistPlaylist;
} }
public void setVideoExistPlaylist(List<VideoId> videoExistPlaylist) { public void setVideoExistPlaylist(Map<String, List<PlaylistExist>> videoExistPlaylist) {
this.videoExistPlaylist = videoExistPlaylist; this.videoExistPlaylist = videoExistPlaylist;
} }
} }

View File

@ -238,7 +238,7 @@ public interface PeertubeService {
Call<VideoPlaylistData> getVideosPlayList(@Header("Authorization") String credentials, @Path("id") String id); Call<VideoPlaylistData> getVideosPlayList(@Header("Authorization") String credentials, @Path("id") String id);
@GET("users/me/video-playlists/videos-exist") @GET("users/me/video-playlists/videos-exist")
Call<PlaylistExist> getVideoExistsInPlaylist(@Header("Authorization") String credentials, @Query("videoIds") List<String> videoIds); Call<Map<String, List<PlaylistExist>>> getVideoExistsInPlaylist(@Header("Authorization") String credentials, @Query("videoIds") String videoIds);
@Multipart @Multipart
@POST("video-playlists") @POST("video-playlists")
@ -264,7 +264,7 @@ public interface PeertubeService {
@FormUrlEncoded @FormUrlEncoded
@POST("video-playlists/{id}/videos") @POST("video-playlists/{id}/videos")
Call<String> addVideoInPlaylist(@Header("Authorization") String credentials, @Path("id") String id, @Field("videoId") String videoId); Call<VideoPlaylistData.PlaylistElement> addVideoInPlaylist(@Header("Authorization") String credentials, @Path("id") String id, @Field("videoId") String videoId);
@DELETE("video-playlists/{id}") @DELETE("video-playlists/{id}")

View File

@ -1060,14 +1060,14 @@ public class RetrofitPeertubeAPI {
* @param videoIds List<String> ids of videos * @param videoIds List<String> ids of videos
* @return APIResponse * @return APIResponse
*/ */
public APIResponse getVideosExist(List<String> videoIds) { public APIResponse getVideosExist(String videoIds) {
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
try { try {
Call<PlaylistExist> videoExistsInPlaylist = peertubeService.getVideoExistsInPlaylist(getToken(), videoIds); Call<Map<String, List<PlaylistExist>>> videoExistsInPlaylist = peertubeService.getVideoExistsInPlaylist(getToken(), videoIds);
Response<PlaylistExist> response = videoExistsInPlaylist.execute(); Response<Map<String, List<PlaylistExist>>> response = videoExistsInPlaylist.execute();
if (response.isSuccessful() && response.body() != null) { if (response.isSuccessful() && response.body() != null) {
apiResponse.setVideoExistPlaylist(response.body().getVideoId()); apiResponse.setVideoExistPlaylist(response.body());
} else { } else {
setError(apiResponse, response.code(), response.errorBody()); setError(apiResponse, response.code(), response.errorBody());
} }
@ -1128,10 +1128,10 @@ public class RetrofitPeertubeAPI {
setError(apiResponse, response.code(), response.errorBody()); setError(apiResponse, response.code(), response.errorBody());
} }
} else if (type == PlaylistsVM.action.ADD_VIDEOS) { } else if (type == PlaylistsVM.action.ADD_VIDEOS) {
Call<String> stringCall = peertubeService.addVideoInPlaylist(getToken(), playlistId, videoId); Call<VideoPlaylistData.PlaylistElement> stringCall = peertubeService.addVideoInPlaylist(getToken(), playlistId, videoId);
Response<String> response = stringCall.execute(); Response<VideoPlaylistData.PlaylistElement> response = stringCall.execute();
if (response.isSuccessful()) { if (response.isSuccessful() && response.body() != null) {
apiResponse.setActionReturn(response.body()); apiResponse.setActionReturn(response.body().getVideoPlaylistElement().getId());
} else { } else {
setError(apiResponse, response.code(), response.errorBody()); setError(apiResponse, response.code(), response.errorBody());
} }

View File

@ -120,6 +120,19 @@ public class VideoPlaylistData {
} }
} }
public static class PlaylistElement {
@SerializedName("videoPlaylistElement")
private VideoPlaylistCreationItem videoPlaylistElement;
public VideoPlaylistCreationItem getVideoPlaylistElement() {
return videoPlaylistElement;
}
public void setVideoPlaylistElement(VideoPlaylistCreationItem videoPlaylistElement) {
this.videoPlaylistElement = videoPlaylistElement;
}
}
public static class VideoPlaylistCreationItem { public static class VideoPlaylistCreationItem {
@SerializedName("id") @SerializedName("id")
String id; String id;

View File

@ -16,22 +16,10 @@ package app.fedilab.fedilabtube.client.entities;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.util.List;
@SuppressWarnings({"unused", "RedundantSuppression"})
public class PlaylistExist { public class PlaylistExist {
@SerializedName("videoId")
private List<VideoId> videoId;
public List<VideoId> getVideoId() {
return videoId;
}
public void setVideoId(List<VideoId> videoId) {
this.videoId = videoId;
}
public static class VideoId {
@SerializedName("playlistElementId") @SerializedName("playlistElementId")
private String playlistElementId; private String playlistElementId;
@SerializedName("playlistId") @SerializedName("playlistId")
@ -73,4 +61,3 @@ public class PlaylistExist {
this.stopTimestamp = stopTimestamp; this.stopTimestamp = stopTimestamp;
} }
} }
}

View File

@ -124,7 +124,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
holder.bottom_container.setOnClickListener(v -> { holder.bottom_container.setOnClickListener(v -> {
Intent intent = new Intent(context, PeertubeActivity.class); Intent intent = new Intent(context, PeertubeActivity.class);
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putString("video_id", video.getUuid()); b.putString("video_id", video.getId());
intent.putExtras(b); intent.putExtras(b);
context.startActivity(intent); context.startActivity(intent);
}); });
@ -140,7 +140,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
holder.peertube_video_image.setOnClickListener(v -> { holder.peertube_video_image.setOnClickListener(v -> {
Intent intent = new Intent(context, PeertubeActivity.class); Intent intent = new Intent(context, PeertubeActivity.class);
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putString("video_id", video.getUuid()); b.putString("video_id", video.getId());
intent.putExtras(b); intent.putExtras(b);
context.startActivity(intent); context.startActivity(intent);
}); });

View File

@ -108,7 +108,7 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
Intent intent = new Intent(context, PeertubeActivity.class); Intent intent = new Intent(context, PeertubeActivity.class);
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putString("peertube_instance", finalAccountAction1.getHost()); b.putString("peertube_instance", finalAccountAction1.getHost());
b.putString("video_id", notification.getComment().getVideo().getUuid()); b.putString("video_id", notification.getComment().getVideo().getId());
intent.putExtras(b); intent.putExtras(b);
context.startActivity(intent); context.startActivity(intent);
}); });
@ -142,7 +142,7 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
Intent intent = new Intent(context, PeertubeActivity.class); Intent intent = new Intent(context, PeertubeActivity.class);
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putString("peertube_instance", Helper.getLiveInstance(context)); b.putString("peertube_instance", Helper.getLiveInstance(context));
b.putString("video_id", notification.getVideo().getUuid()); b.putString("video_id", notification.getVideo().getId());
intent.putExtras(b); intent.putExtras(b);
context.startActivity(intent); context.startActivity(intent);
}); });

View File

@ -44,6 +44,14 @@ import es.dmoral.toasty.Toasty;
public class DisplayNotificationsFragment extends Fragment { public class DisplayNotificationsFragment extends Fragment {
//Peertube notification type
public static int NEW_VIDEO_FROM_SUBSCRIPTION = 1;
public static int NEW_REPORT = 3;
public static int BLACKLIST_ON_MY_VIDEO = 4;
public static int UNBLACKLIST_ON_MY_VIDEO = 5;
public static int MY_VIDEO_PUBLISHED = 6;
public static int MY_VIDEO_IMPORT_SUCCESS = 7;
public static int MY_VIDEO_IMPORT_ERROR = 8;
private boolean flag_loading; private boolean flag_loading;
private Context context; private Context context;
private PeertubeNotificationsListAdapter peertubeNotificationsListAdapter; private PeertubeNotificationsListAdapter peertubeNotificationsListAdapter;
@ -56,16 +64,6 @@ public class DisplayNotificationsFragment extends Fragment {
private RecyclerView lv_notifications; private RecyclerView lv_notifications;
private View rootView; private View rootView;
//Peertube notification type
public static int NEW_VIDEO_FROM_SUBSCRIPTION = 1;
public static int NEW_REPORT = 3;
public static int BLACKLIST_ON_MY_VIDEO = 4;
public static int UNBLACKLIST_ON_MY_VIDEO = 5;
public static int MY_VIDEO_PUBLISHED = 6;
public static int MY_VIDEO_IMPORT_SUCCESS = 7;
public static int MY_VIDEO_IMPORT_ERROR = 8;
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View File

@ -348,5 +348,4 @@ public class AccountDAO {
} }
} }

View File

@ -26,15 +26,12 @@ import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI; 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.PlaylistData.Playlist; import app.fedilab.fedilabtube.client.data.PlaylistData.Playlist;
import app.fedilab.fedilabtube.client.entities.PlaylistParams;
import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.sqlite.AccountDAO; import app.fedilab.fedilabtube.sqlite.AccountDAO;
import app.fedilab.fedilabtube.sqlite.Sqlite; import app.fedilab.fedilabtube.sqlite.Sqlite;
@ -53,13 +50,13 @@ public class PlaylistsVM extends AndroidViewModel {
return apiResponseMutableLiveData; return apiResponseMutableLiveData;
} }
public LiveData<APIResponse> videoExists(List<String> videoIds) { public LiveData<APIResponse> videoExists(String videoIds) {
apiResponseMutableLiveData = new MutableLiveData<>(); apiResponseMutableLiveData = new MutableLiveData<>();
checkVideosExist(videoIds); checkVideosExist(videoIds);
return apiResponseMutableLiveData; return apiResponseMutableLiveData;
} }
private void checkVideosExist(List<String> videoIds) { private void checkVideosExist(String videoIds) {
Context _mContext = getApplication().getApplicationContext(); Context _mContext = getApplication().getApplicationContext();
new Thread(() -> { new Thread(() -> {
APIResponse apiResponse = new RetrofitPeertubeAPI(_mContext).getVideosExist(videoIds); APIResponse apiResponse = new RetrofitPeertubeAPI(_mContext).getVideosExist(videoIds);