1
0
mirror of https://framagit.org/tom79/fedilab-tube synced 2025-04-27 08:28:55 +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 java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import app.fedilab.fedilabtube.client.APIResponse;
@ -363,11 +365,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube_playlist.setVisibility(View.VISIBLE);
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);
feedsViewModel.getVideo(videoId).observe(PeertubeActivity.this, this::manageVIewVideo);
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);
add_comment_read.setOnClickListener(v -> {
if (isLoggedIn(PeertubeActivity.this)) {
add_comment_read.setVisibility(View.GONE);
@ -545,7 +541,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube_playlist.setOnClickListener(v -> {
if (playlists != null && peertube.getId() != null) {
if (playlists != null && videoId != null) {
PopupMenu popup = new PopupMenu(PeertubeActivity.this, peertube_playlist);
for (Playlist playlist : playlists) {
@ -586,7 +582,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
playlistForVideo.remove(playlist.getId());
} else {
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());
}
return false;
@ -846,7 +842,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
@Override
public void onDestroy() {
super.onDestroy();
@ -1074,19 +1069,23 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
if (actionType == GET_PLAYLISTS && apiResponse != null) {
playlists = apiResponse.getPlaylists();
playlistsViewModel.videoExists(videoId).observe(PeertubeActivity.this, this::manageVIewVideosExist);
}
}
public void manageVIewVideosExist(APIResponse apiResponse) {
playlistForVideo = new ArrayList<>();
if (apiResponse.getError() == null && apiResponse.getVideoExistPlaylist() != null) {
List<PlaylistExist.VideoId> videoIds = apiResponse.getVideoExistPlaylist();
for(PlaylistExist.VideoId videoId: videoIds) {
playlistForVideo.add(videoId.getPlaylistId());
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();
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.entities.Error;
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;
@SuppressWarnings({"unused", "RedundantSuppression"})
@ -41,7 +41,7 @@ public class APIResponse {
private String actionReturn = null;
private Rating rating;
private OverviewVideo overviewVideo = null;
private List<VideoId> videoExistPlaylist = null;
private Map<String, List<PlaylistExist>> videoExistPlaylist = null;
private List<VideoData.Video> peertubes = null;
private List<CommentData.Comment> comments = null;
private List<Block> muted;
@ -240,11 +240,11 @@ public class APIResponse {
this.videoPlaylist = videoPlaylist;
}
public List<VideoId> getVideoExistPlaylist() {
public Map<String, List<PlaylistExist>> getVideoExistPlaylist() {
return videoExistPlaylist;
}
public void setVideoExistPlaylist(List<VideoId> videoExistPlaylist) {
public void setVideoExistPlaylist(Map<String, List<PlaylistExist>> videoExistPlaylist) {
this.videoExistPlaylist = videoExistPlaylist;
}
}

View File

@ -238,7 +238,7 @@ public interface PeertubeService {
Call<VideoPlaylistData> getVideosPlayList(@Header("Authorization") String credentials, @Path("id") String id);
@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
@POST("video-playlists")
@ -264,7 +264,7 @@ public interface PeertubeService {
@FormUrlEncoded
@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}")

View File

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

View File

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

View File

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

View File

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

View File

@ -44,6 +44,14 @@ import es.dmoral.toasty.Toasty;
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 Context context;
private PeertubeNotificationsListAdapter peertubeNotificationsListAdapter;
@ -56,16 +64,6 @@ public class DisplayNotificationsFragment extends Fragment {
private RecyclerView lv_notifications;
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
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.MutableLiveData;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.data.AccountData.Account;
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.sqlite.AccountDAO;
import app.fedilab.fedilabtube.sqlite.Sqlite;
@ -53,13 +50,13 @@ public class PlaylistsVM extends AndroidViewModel {
return apiResponseMutableLiveData;
}
public LiveData<APIResponse> videoExists(List<String> videoIds) {
public LiveData<APIResponse> videoExists(String videoIds) {
apiResponseMutableLiveData = new MutableLiveData<>();
checkVideosExist(videoIds);
return apiResponseMutableLiveData;
}
private void checkVideosExist(List<String> videoIds) {
private void checkVideosExist(String videoIds) {
Context _mContext = getApplication().getApplicationContext();
new Thread(() -> {
APIResponse apiResponse = new RetrofitPeertubeAPI(_mContext).getVideosExist(videoIds);