mirror of
https://framagit.org/tom79/fedilab-tube
synced 2025-02-21 06:20:44 +01:00
Improve menu for videos
This commit is contained in:
parent
0a84b75518
commit
bd0c59a69e
@ -193,11 +193,12 @@
|
|||||||
<string name="video_settings">Paramètres des vidéos</string>
|
<string name="video_settings">Paramètres des vidéos</string>
|
||||||
<string name="app_interface">Interface</string>
|
<string name="app_interface">Interface</string>
|
||||||
|
|
||||||
|
<string name="modify_playlists">Vidéo dans les listes de lecture</string>
|
||||||
|
|
||||||
<string-array name="settings_video_mode">
|
<string-array name="settings_video_mode">
|
||||||
<item>Normal</item>
|
<item>Normal</item>
|
||||||
<item>Streaming</item>
|
|
||||||
<item>Navigateur</item>
|
<item>Navigateur</item>
|
||||||
|
<item>Streaming</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string name="set_cache_mode">Cache</string>
|
<string name="set_cache_mode">Cache</string>
|
||||||
|
@ -235,6 +235,7 @@
|
|||||||
<string name="delete_channel">Remove channel</string>
|
<string name="delete_channel">Remove channel</string>
|
||||||
<string name="action_channel_confirm_delete">Are you sure to permanently delete this channel?</string>
|
<string name="action_channel_confirm_delete">Are you sure to permanently delete this channel?</string>
|
||||||
|
|
||||||
|
<string name="modify_playlists">Video in playlists</string>
|
||||||
<string name="no_muted">No muted accounts!</string>
|
<string name="no_muted">No muted accounts!</string>
|
||||||
|
|
||||||
<string name="error_display_name_channel">You must define a name and a display name for this channel!</string>
|
<string name="error_display_name_channel">You must define a name and a display name for this channel!</string>
|
||||||
|
@ -1087,7 +1087,9 @@ 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);
|
List<String> videoIds = new ArrayList<>();
|
||||||
|
videoIds.add(videoId);
|
||||||
|
playlistsViewModel.videoExists(videoIds).observe(PeertubeActivity.this, this::manageVIewVideosExist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public class ShowAccountActivity extends AppCompatActivity {
|
|||||||
private ViewPager mPager;
|
private ViewPager mPager;
|
||||||
private TabLayout tabLayout;
|
private TabLayout tabLayout;
|
||||||
private TextView account_note, subscriber_count;
|
private TextView account_note, subscriber_count;
|
||||||
private List<Map<String, Boolean>> relationship;
|
private Map<String, Boolean> relationship;
|
||||||
private ImageView account_pp;
|
private ImageView account_pp;
|
||||||
private TextView account_dn;
|
private TextView account_dn;
|
||||||
private Channel channel;
|
private Channel channel;
|
||||||
@ -312,7 +312,7 @@ public class ShowAccountActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
account_follow.setEnabled(true);
|
account_follow.setEnabled(true);
|
||||||
|
|
||||||
boolean isFollowing = relationship.get(0).get(channel.getAcct());
|
boolean isFollowing = relationship.get(channel.getAcct());
|
||||||
if (isFollowing) {
|
if (isFollowing) {
|
||||||
account_follow.setText(R.string.action_unfollow);
|
account_follow.setText(R.string.action_unfollow);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
@ -81,7 +81,7 @@ public class ShowChannelActivity extends AppCompatActivity {
|
|||||||
private ViewPager mPager;
|
private ViewPager mPager;
|
||||||
private TabLayout tabLayout;
|
private TabLayout tabLayout;
|
||||||
private TextView account_note, subscriber_count;
|
private TextView account_note, subscriber_count;
|
||||||
private List<Map<String, Boolean>> relationship;
|
private Map<String, Boolean> relationship;
|
||||||
private ImageView account_pp;
|
private ImageView account_pp;
|
||||||
private TextView account_dn;
|
private TextView account_dn;
|
||||||
private Channel channel;
|
private Channel channel;
|
||||||
@ -311,7 +311,7 @@ public class ShowChannelActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
account_follow.setEnabled(true);
|
account_follow.setEnabled(true);
|
||||||
|
|
||||||
boolean isFollowing = relationship.get(0).get(channel.getAcct());
|
boolean isFollowing = relationship.get(channel.getAcct());
|
||||||
if (isFollowing) {
|
if (isFollowing) {
|
||||||
account_follow.setText(R.string.action_unfollow);
|
account_follow.setText(R.string.action_unfollow);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
@ -49,7 +49,7 @@ public class APIResponse {
|
|||||||
private List<NotificationData.Notification> peertubeNotifications = null;
|
private List<NotificationData.Notification> peertubeNotifications = null;
|
||||||
private List<PlaylistData.Playlist> playlists = null;
|
private List<PlaylistData.Playlist> playlists = null;
|
||||||
private List<String> domains = null;
|
private List<String> domains = null;
|
||||||
private List<Map<String, Boolean>> relationships = null;
|
private Map<String, Boolean> relationships = null;
|
||||||
private List<CaptionData.Caption> captions = null;
|
private List<CaptionData.Caption> captions = null;
|
||||||
private Error error = null;
|
private Error error = null;
|
||||||
private String since_id, max_id;
|
private String since_id, max_id;
|
||||||
@ -152,11 +152,11 @@ public class APIResponse {
|
|||||||
this.statusCode = statusCode;
|
this.statusCode = statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Map<String, Boolean>> getRelationships() {
|
public Map<String, Boolean> getRelationships() {
|
||||||
return relationships;
|
return relationships;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRelationships(List<Map<String, Boolean>> relationships) {
|
public void setRelationships(Map<String, Boolean> relationships) {
|
||||||
this.relationships = relationships;
|
this.relationships = relationships;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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<Map<String, List<PlaylistExist>>> getVideoExistsInPlaylist(@Header("Authorization") String credentials, @Query("videoIds") String videoIds);
|
Call<Map<String, List<PlaylistExist>>> getVideoExistsInPlaylist(@Header("Authorization") String credentials, @Query("videoIds") List<String> videoIds);
|
||||||
|
|
||||||
@Multipart
|
@Multipart
|
||||||
@POST("video-playlists")
|
@POST("video-playlists")
|
||||||
@ -290,10 +290,7 @@ public interface PeertubeService {
|
|||||||
Call<AccountData> getSubscription(@Header("Authorization") String credentials, @Query("start") String maxId);
|
Call<AccountData> getSubscription(@Header("Authorization") String credentials, @Query("start") String maxId);
|
||||||
|
|
||||||
@GET("users/me/subscriptions/exist")
|
@GET("users/me/subscriptions/exist")
|
||||||
Call<List<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);
|
||||||
|
|
||||||
@GET("users/me/subscriptions/exist")
|
|
||||||
Call<Map<String, Boolean>> getSubscriptionExists(@Header("Authorization") String credentials, @Query("uris") String uris);
|
|
||||||
|
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@POST("users/me/subscriptions")
|
@POST("users/me/subscriptions")
|
||||||
|
@ -379,21 +379,19 @@ public class RetrofitPeertubeAPI {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if users via their uris are following the authenticated user
|
* Retrieves playlists for a video *synchronously*
|
||||||
*
|
*
|
||||||
* @param uris List<String>
|
* @param videoIds List<String> ids of videos
|
||||||
* @return APIResponse
|
* @return APIResponse
|
||||||
*/
|
*/
|
||||||
public APIResponse isFollowing(String uris) {
|
public APIResponse getVideosExist(List<String> videoIds) {
|
||||||
APIResponse apiResponse = new APIResponse();
|
|
||||||
PeertubeService peertubeService = init();
|
PeertubeService peertubeService = init();
|
||||||
Call<Map<String, Boolean>> followingCall = peertubeService.getSubscriptionExists(getToken(), uris);
|
APIResponse apiResponse = new APIResponse();
|
||||||
try {
|
try {
|
||||||
Response<Map<String, Boolean>> response = followingCall.execute();
|
Call<Map<String, List<PlaylistExist>>> videoExistsInPlaylist = peertubeService.getVideoExistsInPlaylist(getToken(), videoIds);
|
||||||
if (response.isSuccessful()) {
|
Response<Map<String, List<PlaylistExist>>> response = videoExistsInPlaylist.execute();
|
||||||
List<Map<String, Boolean>> relations = new ArrayList<>();
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
relations.add(response.body());
|
apiResponse.setVideoExistPlaylist(response.body());
|
||||||
apiResponse.setRelationships(relations);
|
|
||||||
} else {
|
} else {
|
||||||
setError(apiResponse, response.code(), response.errorBody());
|
setError(apiResponse, response.code(), response.errorBody());
|
||||||
}
|
}
|
||||||
@ -403,6 +401,7 @@ public class RetrofitPeertubeAPI {
|
|||||||
return apiResponse;
|
return apiResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if users via their uris are following the authenticated user
|
* Check if users via their uris are following the authenticated user
|
||||||
*
|
*
|
||||||
@ -412,9 +411,9 @@ public class RetrofitPeertubeAPI {
|
|||||||
public APIResponse areFollowing(List<String> uris) {
|
public APIResponse areFollowing(List<String> uris) {
|
||||||
APIResponse apiResponse = new APIResponse();
|
APIResponse apiResponse = new APIResponse();
|
||||||
PeertubeService peertubeService = init();
|
PeertubeService peertubeService = init();
|
||||||
Call<List<Map<String, Boolean>>> followingCall = peertubeService.getSubscriptionsExist(getToken(), uris);
|
Call<Map<String, Boolean>> followingCall = peertubeService.getSubscriptionsExist(getToken(), uris);
|
||||||
try {
|
try {
|
||||||
Response<List<Map<String, Boolean>>> response = followingCall.execute();
|
Response<Map<String, Boolean>> response = followingCall.execute();
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
apiResponse.setRelationships(response.body());
|
apiResponse.setRelationships(response.body());
|
||||||
} else {
|
} else {
|
||||||
@ -1075,30 +1074,6 @@ public class RetrofitPeertubeAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves playlists for a video *synchronously*
|
|
||||||
*
|
|
||||||
* @param videoIds List<String> ids of videos
|
|
||||||
* @return APIResponse
|
|
||||||
*/
|
|
||||||
public APIResponse getVideosExist(String videoIds) {
|
|
||||||
PeertubeService peertubeService = init();
|
|
||||||
APIResponse apiResponse = new APIResponse();
|
|
||||||
try {
|
|
||||||
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());
|
|
||||||
} else {
|
|
||||||
setError(apiResponse, response.code(), response.errorBody());
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return apiResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves playlist *synchronously*
|
* Retrieves playlist *synchronously*
|
||||||
*
|
*
|
||||||
|
@ -19,8 +19,6 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -36,7 +34,9 @@ import androidx.lifecycle.ViewModelProvider;
|
|||||||
import androidx.lifecycle.ViewModelStoreOwner;
|
import androidx.lifecycle.ViewModelStoreOwner;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import app.fedilab.fedilabtube.PeertubeActivity;
|
import app.fedilab.fedilabtube.PeertubeActivity;
|
||||||
import app.fedilab.fedilabtube.PeertubeEditUploadActivity;
|
import app.fedilab.fedilabtube.PeertubeEditUploadActivity;
|
||||||
@ -46,6 +46,7 @@ import app.fedilab.fedilabtube.client.APIResponse;
|
|||||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||||
import app.fedilab.fedilabtube.client.data.PlaylistData;
|
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.PlaylistExist;
|
||||||
import app.fedilab.fedilabtube.client.entities.Report;
|
import app.fedilab.fedilabtube.client.entities.Report;
|
||||||
import app.fedilab.fedilabtube.helper.Helper;
|
import app.fedilab.fedilabtube.helper.Helper;
|
||||||
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||||
@ -60,10 +61,12 @@ import static app.fedilab.fedilabtube.viewmodel.TimelineVM.TimelineType.VIDEOS_I
|
|||||||
public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
public AllVideoRemoved allVideoRemoved;
|
public AllVideoRemoved allVideoRemoved;
|
||||||
|
public RelationShipListener relationShipListener;
|
||||||
|
public PlaylistListener playlistListener;
|
||||||
|
public OwnerPlaylistsListener ownerPlaylistsListener;
|
||||||
private List<VideoData.Video> videos;
|
private List<VideoData.Video> videos;
|
||||||
private Context context;
|
private Context context;
|
||||||
private TimelineVM.TimelineType timelineType;
|
private TimelineVM.TimelineType timelineType;
|
||||||
private PlaylistData.Playlist playlist;
|
|
||||||
|
|
||||||
public PeertubeAdapter(List<VideoData.Video> videos, TimelineVM.TimelineType timelineType) {
|
public PeertubeAdapter(List<VideoData.Video> videos, TimelineVM.TimelineType timelineType) {
|
||||||
this.videos = videos;
|
this.videos = videos;
|
||||||
@ -72,7 +75,6 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
|
|
||||||
public PeertubeAdapter(List<VideoData.Video> videos, PlaylistData.Playlist playlist) {
|
public PeertubeAdapter(List<VideoData.Video> videos, PlaylistData.Playlist playlist) {
|
||||||
this.videos = videos;
|
this.videos = videos;
|
||||||
this.playlist = playlist;
|
|
||||||
this.timelineType = VIDEOS_IN_PLAYLIST;
|
this.timelineType = VIDEOS_IN_PLAYLIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,28 +154,68 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
.inflate(R.menu.video_drawer_menu, popup.getMenu());
|
.inflate(R.menu.video_drawer_menu, popup.getMenu());
|
||||||
if (timelineType == MY_VIDEOS) {
|
if (timelineType == MY_VIDEOS) {
|
||||||
popup.getMenu().findItem(R.id.action_report).setVisible(false);
|
popup.getMenu().findItem(R.id.action_report).setVisible(false);
|
||||||
|
popup.getMenu().findItem(R.id.action_follow).setVisible(false);
|
||||||
|
if (playlistListener == null || playlistListener.getPlaylist() == null || playlistListener.getPlaylist().size() == 0) {
|
||||||
|
popup.getMenu().findItem(R.id.action_playlist).setVisible(false);
|
||||||
|
} else {
|
||||||
|
popup.getMenu().findItem(R.id.action_playlist).setVisible(true);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
popup.getMenu().findItem(R.id.action_edit).setVisible(false);
|
popup.getMenu().findItem(R.id.action_edit).setVisible(false);
|
||||||
if (timelineType != VIDEOS_IN_PLAYLIST) {
|
if (timelineType != VIDEOS_IN_PLAYLIST) {
|
||||||
popup.getMenu().findItem(R.id.action_remove_playlist).setVisible(false);
|
if (relationShipListener == null || relationShipListener.getRelationShip() == null || relationShipListener.getRelationShip().size() == 0) {
|
||||||
|
popup.getMenu().findItem(R.id.action_follow).setVisible(false);
|
||||||
|
} else {
|
||||||
|
popup.getMenu().findItem(R.id.action_follow).setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (playlistListener == null || playlistListener.getPlaylist() == null || playlistListener.getPlaylist().size() == 0) {
|
||||||
|
popup.getMenu().findItem(R.id.action_playlist).setVisible(false);
|
||||||
|
} else {
|
||||||
|
popup.getMenu().findItem(R.id.action_playlist).setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
popup.setOnMenuItemClickListener(item -> {
|
popup.setOnMenuItemClickListener(item -> {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_remove_playlist:
|
case R.id.action_playlist:
|
||||||
new Thread(() -> {
|
|
||||||
PlaylistsVM playlistsViewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PlaylistsVM.class);
|
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(context);
|
||||||
playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, playlist, video.getIdInPlaylist());
|
builder.setTitle(R.string.modify_playlists);
|
||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
||||||
Runnable myRunnable = () -> {
|
List<PlaylistData.Playlist> ownerPlaylists = ownerPlaylistsListener.getOwnerPlaylists();
|
||||||
videos.remove(video);
|
String[] label = new String[ownerPlaylists.size()];
|
||||||
notifyDataSetChanged();
|
boolean[] checked = new boolean[ownerPlaylists.size()];
|
||||||
if (videos.size() == 0) {
|
int i = 0;
|
||||||
allVideoRemoved.onAllVideoRemoved();
|
List<PlaylistExist> playlistsForVideo = playlistListener.getPlaylist().get(video.getId());
|
||||||
|
|
||||||
|
if (playlistsForVideo != null) {
|
||||||
|
for (PlaylistData.Playlist playlist : ownerPlaylists) {
|
||||||
|
for (PlaylistExist playlistExist : playlistsForVideo) {
|
||||||
|
if (playlistExist != null && playlistExist.getPlaylistId().compareTo(playlist.getId()) == 0) {
|
||||||
|
checked[i] = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
mainHandler.post(myRunnable);
|
label[i] = playlist.getDisplayName();
|
||||||
}).start();
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.setMultiChoiceItems(label, checked, (dialog, which, isChecked) -> new Thread(() -> {
|
||||||
|
PlaylistsVM playlistsViewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PlaylistsVM.class);
|
||||||
|
if (isChecked) { //Add to playlist
|
||||||
|
playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, ownerPlaylistsListener.getOwnerPlaylists().get(which), video.getUuid()).observe((LifecycleOwner) context, apiResponse3 -> addElement(ownerPlaylistsListener.getOwnerPlaylists().get(which).getId(), video.getId(), apiResponse3));
|
||||||
|
} else { //Remove from playlist
|
||||||
|
playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, ownerPlaylistsListener.getOwnerPlaylists().get(which), video.getIdInPlaylist());
|
||||||
|
playlistListener.getPlaylist().remove(video.getId());
|
||||||
|
}
|
||||||
|
}).start());
|
||||||
|
builder.setPositiveButton(R.string.close, (dialog, which) -> {
|
||||||
|
dialog.dismiss();
|
||||||
|
});
|
||||||
|
androidx.appcompat.app.AlertDialog dialog = builder.create();
|
||||||
|
dialog.show();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case R.id.action_edit:
|
case R.id.action_edit:
|
||||||
Intent intent = new Intent(context, PeertubeEditUploadActivity.class);
|
Intent intent = new Intent(context, PeertubeEditUploadActivity.class);
|
||||||
@ -188,8 +230,8 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
View dialogView = inflater1.inflate(R.layout.popup_report, new LinearLayout(context), false);
|
View dialogView = inflater1.inflate(R.layout.popup_report, new LinearLayout(context), false);
|
||||||
dialogBuilder.setView(dialogView);
|
dialogBuilder.setView(dialogView);
|
||||||
EditText report_content = dialogView.findViewById(R.id.report_content);
|
EditText report_content = dialogView.findViewById(R.id.report_content);
|
||||||
dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
dialogBuilder.setNeutralButton(R.string.cancel, (dialog2, id) -> dialog2.dismiss());
|
||||||
dialogBuilder.setPositiveButton(R.string.report, (dialog, id) -> {
|
dialogBuilder.setPositiveButton(R.string.report, (dialog2, id) -> {
|
||||||
if (report_content.getText().toString().trim().length() == 0) {
|
if (report_content.getText().toString().trim().length() == 0) {
|
||||||
Toasty.info(context, context.getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show();
|
Toasty.info(context, context.getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show();
|
||||||
} else {
|
} else {
|
||||||
@ -200,7 +242,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
report.setVideo(videoReport);
|
report.setVideo(videoReport);
|
||||||
report.setReason(report_content.getText().toString());
|
report.setReason(report_content.getText().toString());
|
||||||
viewModel.report(report).observe((LifecycleOwner) context, apiResponse -> manageVIewPostActions(RetrofitPeertubeAPI.ActionType.REPORT_VIDEO, apiResponse));
|
viewModel.report(report).observe((LifecycleOwner) context, apiResponse -> manageVIewPostActions(RetrofitPeertubeAPI.ActionType.REPORT_VIDEO, apiResponse));
|
||||||
dialog.dismiss();
|
dialog2.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
androidx.appcompat.app.AlertDialog alertDialog2 = dialogBuilder.create();
|
androidx.appcompat.app.AlertDialog alertDialog2 = dialogBuilder.create();
|
||||||
@ -230,6 +272,20 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addElement(String playlistId, String videoId, APIResponse apiResponse) {
|
||||||
|
if (apiResponse != null && apiResponse.getActionReturn() != null) {
|
||||||
|
|
||||||
|
PlaylistExist playlistExist = new PlaylistExist();
|
||||||
|
playlistExist.setPlaylistId(playlistId);
|
||||||
|
List<PlaylistExist> playlistExistList = playlistListener.getPlaylist().get(videoId);
|
||||||
|
if (playlistExistList == null) {
|
||||||
|
playlistExistList = new ArrayList<>();
|
||||||
|
}
|
||||||
|
playlistExistList.add(playlistExist);
|
||||||
|
playlistListener.getPlaylist().put(videoId, playlistExistList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getItemId(int position) {
|
public long getItemId(int position) {
|
||||||
return position;
|
return position;
|
||||||
@ -246,6 +302,18 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface RelationShipListener {
|
||||||
|
Map<String, Boolean> getRelationShip();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface PlaylistListener {
|
||||||
|
Map<String, List<PlaylistExist>> getPlaylist();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OwnerPlaylistsListener {
|
||||||
|
List<PlaylistData.Playlist> getOwnerPlaylists();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface AllVideoRemoved {
|
public interface AllVideoRemoved {
|
||||||
void onAllVideoRemoved();
|
void onAllVideoRemoved();
|
||||||
|
@ -171,6 +171,8 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
|
|||||||
|
|
||||||
if (swiped) {
|
if (swiped) {
|
||||||
channelListAdapter = new ChannelListAdapter(this.channels);
|
channelListAdapter = new ChannelListAdapter(this.channels);
|
||||||
|
channelListAdapter.allChannelRemoved = DisplayChannelsFragment.this;
|
||||||
|
channelListAdapter.editAlertDialog = DisplayChannelsFragment.this;
|
||||||
lv_channels.setAdapter(channelListAdapter);
|
lv_channels.setAdapter(channelListAdapter);
|
||||||
swiped = false;
|
swiped = false;
|
||||||
}
|
}
|
||||||
|
@ -40,23 +40,29 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import app.fedilab.fedilabtube.R;
|
import app.fedilab.fedilabtube.R;
|
||||||
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;
|
||||||
import app.fedilab.fedilabtube.client.data.VideoData;
|
import app.fedilab.fedilabtube.client.data.VideoData;
|
||||||
|
import app.fedilab.fedilabtube.client.entities.PlaylistExist;
|
||||||
import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter;
|
import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter;
|
||||||
import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
|
import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
|
||||||
import app.fedilab.fedilabtube.helper.Helper;
|
import app.fedilab.fedilabtube.helper.Helper;
|
||||||
import app.fedilab.fedilabtube.viewmodel.AccountsVM;
|
import app.fedilab.fedilabtube.viewmodel.AccountsVM;
|
||||||
|
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||||
|
import app.fedilab.fedilabtube.viewmodel.RelationshipVM;
|
||||||
import app.fedilab.fedilabtube.viewmodel.SearchVM;
|
import app.fedilab.fedilabtube.viewmodel.SearchVM;
|
||||||
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
||||||
import es.dmoral.toasty.Toasty;
|
import es.dmoral.toasty.Toasty;
|
||||||
|
|
||||||
|
|
||||||
public class DisplayVideosFragment extends Fragment implements AccountsHorizontalListAdapter.EventListener, PeertubeAdapter.AllVideoRemoved {
|
public class DisplayVideosFragment extends Fragment implements AccountsHorizontalListAdapter.EventListener, PeertubeAdapter.AllVideoRemoved, PeertubeAdapter.RelationShipListener, PeertubeAdapter.PlaylistListener, PeertubeAdapter.OwnerPlaylistsListener {
|
||||||
|
|
||||||
|
|
||||||
private LinearLayoutManager mLayoutManager;
|
private LinearLayoutManager mLayoutManager;
|
||||||
@ -84,6 +90,9 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||||||
private SearchVM viewModelSearch;
|
private SearchVM viewModelSearch;
|
||||||
private AccountsVM viewModelAccounts;
|
private AccountsVM viewModelAccounts;
|
||||||
private String channelId;
|
private String channelId;
|
||||||
|
private Map<String, Boolean> relationship;
|
||||||
|
private Map<String, List<PlaylistExist>> playlists;
|
||||||
|
private List<PlaylistData.Playlist> ownerPlaylists;
|
||||||
|
|
||||||
public DisplayVideosFragment() {
|
public DisplayVideosFragment() {
|
||||||
}
|
}
|
||||||
@ -104,7 +113,6 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||||||
type = (TimelineVM.TimelineType) bundle.get("timelineType");
|
type = (TimelineVM.TimelineType) bundle.get("timelineType");
|
||||||
}
|
}
|
||||||
max_id = "0";
|
max_id = "0";
|
||||||
|
|
||||||
if (getArguments() != null && type == null) {
|
if (getArguments() != null && type == null) {
|
||||||
type = DisplayVideosFragmentArgs.fromBundle(getArguments()).getType();
|
type = DisplayVideosFragmentArgs.fromBundle(getArguments()).getType();
|
||||||
}
|
}
|
||||||
@ -132,6 +140,10 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||||||
nextElementLoader.setVisibility(View.GONE);
|
nextElementLoader.setVisibility(View.GONE);
|
||||||
|
|
||||||
peertubeAdapater = new PeertubeAdapter(this.peertubes, type);
|
peertubeAdapater = new PeertubeAdapter(this.peertubes, type);
|
||||||
|
peertubeAdapater.allVideoRemoved = this;
|
||||||
|
peertubeAdapater.playlistListener = this;
|
||||||
|
peertubeAdapater.relationShipListener = this;
|
||||||
|
peertubeAdapater.ownerPlaylistsListener = this;
|
||||||
lv_status.setAdapter(peertubeAdapater);
|
lv_status.setAdapter(peertubeAdapater);
|
||||||
|
|
||||||
accountsHorizontalListAdapter = new AccountsHorizontalListAdapter(this.accounts, this);
|
accountsHorizontalListAdapter = new AccountsHorizontalListAdapter(this.accounts, this);
|
||||||
@ -223,6 +235,10 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||||||
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
|
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
|
||||||
viewModel.getAccounts(RetrofitPeertubeAPI.DataType.SUBSCRIBER, max_id).observe(DisplayVideosFragment.this.requireActivity(), this::manageViewAccounts);
|
viewModel.getAccounts(RetrofitPeertubeAPI.DataType.SUBSCRIBER, max_id).observe(DisplayVideosFragment.this.requireActivity(), this::manageViewAccounts);
|
||||||
}
|
}
|
||||||
|
if (Helper.isLoggedIn(context)) {
|
||||||
|
PlaylistsVM viewModel = new ViewModelProvider(this).get(PlaylistsVM.class);
|
||||||
|
viewModel.manage(PlaylistsVM.action.GET_PLAYLISTS, null, null).observe(DisplayVideosFragment.this.requireActivity(), apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_PLAYLISTS, apiResponse));
|
||||||
|
}
|
||||||
loadTimeline(max_id);
|
loadTimeline(max_id);
|
||||||
display_all.setOnClickListener(v -> {
|
display_all.setOnClickListener(v -> {
|
||||||
forAccount = null;
|
forAccount = null;
|
||||||
@ -231,6 +247,22 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
|
||||||
|
if (apiResponse.getError() != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (actionType == PlaylistsVM.action.GET_PLAYLISTS) {
|
||||||
|
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
|
||||||
|
if (this.ownerPlaylists == null) {
|
||||||
|
this.ownerPlaylists = new ArrayList<>();
|
||||||
|
}
|
||||||
|
this.ownerPlaylists.addAll(apiResponse.getPlaylists());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
@ -318,6 +350,10 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||||||
//If no item were inserted previously the adapter is created
|
//If no item were inserted previously the adapter is created
|
||||||
if (previousPosition == 0) {
|
if (previousPosition == 0) {
|
||||||
peertubeAdapater = new PeertubeAdapter(this.peertubes, type);
|
peertubeAdapater = new PeertubeAdapter(this.peertubes, type);
|
||||||
|
peertubeAdapater.allVideoRemoved = DisplayVideosFragment.this;
|
||||||
|
peertubeAdapater.playlistListener = DisplayVideosFragment.this;
|
||||||
|
peertubeAdapater.relationShipListener = DisplayVideosFragment.this;
|
||||||
|
peertubeAdapater.ownerPlaylistsListener = DisplayVideosFragment.this;
|
||||||
lv_status.setAdapter(peertubeAdapater);
|
lv_status.setAdapter(peertubeAdapater);
|
||||||
} else
|
} else
|
||||||
peertubeAdapater.notifyItemRangeInserted(previousPosition, apiResponse.getPeertubes().size());
|
peertubeAdapater.notifyItemRangeInserted(previousPosition, apiResponse.getPeertubes().size());
|
||||||
@ -330,8 +366,48 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||||||
}
|
}
|
||||||
flag_loading = false;
|
flag_loading = false;
|
||||||
firstLoad = false;
|
firstLoad = false;
|
||||||
|
|
||||||
|
if (Helper.isLoggedIn(context)) {
|
||||||
|
List<String> uids = new ArrayList<>();
|
||||||
|
for (VideoData.Video video : apiResponse.getPeertubes()) {
|
||||||
|
uids.add(video.getChannel().getName() + "@" + video.getChannel().getHost());
|
||||||
|
}
|
||||||
|
if (uids.size() > 0) {
|
||||||
|
RelationshipVM viewModel = new ViewModelProvider(this).get(RelationshipVM.class);
|
||||||
|
viewModel.get(uids).observe(DisplayVideosFragment.this.requireActivity(), this::manageVIewRelationship);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<String> videoIds = new ArrayList<>();
|
||||||
|
for (VideoData.Video video : apiResponse.getPeertubes()) {
|
||||||
|
videoIds.add(video.getId());
|
||||||
|
}
|
||||||
|
if (videoIds.size() > 0) {
|
||||||
|
PlaylistsVM viewModel = new ViewModelProvider(this).get(PlaylistsVM.class);
|
||||||
|
viewModel.videoExists(videoIds).observe(DisplayVideosFragment.this.requireActivity(), this::manageVIewPlaylist);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void manageVIewPlaylist(APIResponse apiResponse) {
|
||||||
|
if (apiResponse.getError() != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (playlists == null) {
|
||||||
|
playlists = new HashMap<>();
|
||||||
|
}
|
||||||
|
playlists.putAll(apiResponse.getVideoExistPlaylist());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void manageVIewRelationship(APIResponse apiResponse) {
|
||||||
|
if (apiResponse.getError() != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (relationship == null) {
|
||||||
|
relationship = new HashMap<>();
|
||||||
|
}
|
||||||
|
relationship.putAll(apiResponse.getRelationships());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
@ -404,6 +480,21 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||||||
textviewNoAction.setVisibility(View.VISIBLE);
|
textviewNoAction.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Boolean> getRelationShip() {
|
||||||
|
return relationship;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, List<PlaylistExist>> getPlaylist() {
|
||||||
|
return playlists;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PlaylistData.Playlist> getOwnerPlaylists() {
|
||||||
|
return ownerPlaylists;
|
||||||
|
}
|
||||||
|
|
||||||
static class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
|
static class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
|
||||||
|
|
||||||
private int spanCount;
|
private int spanCount;
|
||||||
|
@ -27,6 +27,7 @@ import androidx.lifecycle.LiveData;
|
|||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
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;
|
||||||
@ -50,13 +51,13 @@ public class PlaylistsVM extends AndroidViewModel {
|
|||||||
return apiResponseMutableLiveData;
|
return apiResponseMutableLiveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<APIResponse> videoExists(String videoIds) {
|
public LiveData<APIResponse> videoExists(List<String> videoIds) {
|
||||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||||
checkVideosExist(videoIds);
|
checkVideosExist(videoIds);
|
||||||
return apiResponseMutableLiveData;
|
return apiResponseMutableLiveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkVideosExist(String videoIds) {
|
private void checkVideosExist(List<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);
|
||||||
|
@ -49,11 +49,7 @@ public class RelationshipVM extends AndroidViewModel {
|
|||||||
try {
|
try {
|
||||||
RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(_mContext);
|
RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(_mContext);
|
||||||
APIResponse apiResponse;
|
APIResponse apiResponse;
|
||||||
if (uris.size() == 1) {
|
|
||||||
apiResponse = api.isFollowing(uris.get(0));
|
|
||||||
} else {
|
|
||||||
apiResponse = api.areFollowing(uris);
|
apiResponse = api.areFollowing(uris);
|
||||||
}
|
|
||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||||
mainHandler.post(myRunnable);
|
mainHandler.post(myRunnable);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:width="24dp"
|
android:width="24dp"
|
||||||
android:height="24dp"
|
android:height="24dp"
|
||||||
android:tint="?attr/colorControlNormal"
|
|
||||||
android:viewportWidth="24"
|
android:viewportWidth="24"
|
||||||
android:viewportHeight="24">
|
android:viewportHeight="24"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
<path
|
<path
|
||||||
android:fillColor="@android:color/white"
|
android:fillColor="@android:color/white"
|
||||||
android:pathData="M15,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM6,10L6,7L4,7v3L1,10v2h3v3h2v-3h3v-2L6,10zM15,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
|
android:pathData="M15,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM6,10L6,7L4,7v3L1,10v2h3v3h2v-3h3v-2L6,10zM15,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
|
||||||
|
@ -7,9 +7,14 @@
|
|||||||
android:title="@string/report"
|
android:title="@string/report"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_remove_playlist"
|
android:id="@+id/action_playlist"
|
||||||
android:icon="@drawable/ic_baseline_playlist_play_24"
|
android:icon="@drawable/ic_baseline_playlist_play_24"
|
||||||
android:title="@string/remove_from_playlist"
|
android:title="@string/playlists"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_follow"
|
||||||
|
android:icon="@drawable/ic_baseline_person_add_24"
|
||||||
|
android:title="@string/action_follow"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_edit"
|
android:id="@+id/action_edit"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user