mirror of
https://framagit.org/tom79/fedilab-tube
synced 2025-02-10 17:10:50 +01:00
some fixes
This commit is contained in:
parent
8377f9bb8a
commit
752e3d50c1
@ -14,18 +14,26 @@ package app.fedilab.fedilabtube.drawer;
|
|||||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
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;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.widget.PopupMenu;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.lifecycle.ViewModelStoreOwner;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -34,24 +42,47 @@ import app.fedilab.fedilabtube.PeertubeActivity;
|
|||||||
import app.fedilab.fedilabtube.PeertubeEditUploadActivity;
|
import app.fedilab.fedilabtube.PeertubeEditUploadActivity;
|
||||||
import app.fedilab.fedilabtube.R;
|
import app.fedilab.fedilabtube.R;
|
||||||
import app.fedilab.fedilabtube.ShowChannelActivity;
|
import app.fedilab.fedilabtube.ShowChannelActivity;
|
||||||
|
import app.fedilab.fedilabtube.client.APIResponse;
|
||||||
|
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||||
|
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.Report;
|
||||||
import app.fedilab.fedilabtube.helper.Helper;
|
import app.fedilab.fedilabtube.helper.Helper;
|
||||||
|
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||||
|
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
|
||||||
|
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
||||||
|
import es.dmoral.toasty.Toasty;
|
||||||
|
|
||||||
|
import static app.fedilab.fedilabtube.viewmodel.TimelineVM.TimelineType.MY_VIDEOS;
|
||||||
|
import static app.fedilab.fedilabtube.viewmodel.TimelineVM.TimelineType.VIDEOS_IN_PLAYLIST;
|
||||||
|
|
||||||
|
|
||||||
public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
private List<VideoData.Video> videos;
|
private List<VideoData.Video> videos;
|
||||||
private Context context;
|
private Context context;
|
||||||
private boolean myVideos;
|
private TimelineVM.TimelineType timelineType;
|
||||||
|
private PlaylistData.Playlist playlist;
|
||||||
|
|
||||||
public PeertubeAdapter(List<VideoData.Video> videos, boolean myVideos) {
|
public PeertubeAdapter(List<VideoData.Video> videos, TimelineVM.TimelineType timelineType) {
|
||||||
this.videos = videos;
|
this.videos = videos;
|
||||||
this.myVideos = myVideos;
|
this.timelineType = timelineType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PeertubeAdapter(List<VideoData.Video> videos, PlaylistData.Playlist playlist) {
|
||||||
|
this.videos = videos;
|
||||||
|
this.playlist = playlist;
|
||||||
|
this.timelineType = VIDEOS_IN_PLAYLIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AllVideoRemoved allVideoRemoved;
|
||||||
|
|
||||||
|
public interface AllVideoRemoved{
|
||||||
|
void onAllVideoRemoved();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PeertubeAdapter(List<VideoData.Video> videos) {
|
public PeertubeAdapter(List<VideoData.Video> videos) {
|
||||||
this.videos = videos;
|
this.videos = videos;
|
||||||
this.myVideos = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -77,7 +108,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
|
|
||||||
|
|
||||||
boolean ownVideos;
|
boolean ownVideos;
|
||||||
if (myVideos) {
|
if (timelineType == TimelineVM.TimelineType.MY_VIDEOS) {
|
||||||
ownVideos = true;
|
ownVideos = true;
|
||||||
} else {
|
} else {
|
||||||
ownVideos = video.getAccount() != null && video.getAccount().getId() != null && video.getAccount().getHost().compareTo(Helper.getLiveInstance(context)) == 0 && video.getAccount().getId().compareTo(userId) == 0;
|
ownVideos = video.getAccount() != null && video.getAccount().getId() != null && video.getAccount().getHost().compareTo(Helper.getLiveInstance(context)) == 0 && video.getAccount().getId().compareTo(userId) == 0;
|
||||||
@ -119,6 +150,73 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
holder.more_actions.setOnClickListener(view -> {
|
||||||
|
PopupMenu popup = new PopupMenu(context, holder.more_actions);
|
||||||
|
popup.getMenuInflater()
|
||||||
|
.inflate(R.menu.video_drawer_menu, popup.getMenu());
|
||||||
|
if (timelineType == MY_VIDEOS) {
|
||||||
|
popup.getMenu().findItem(R.id.action_report).setVisible(false);
|
||||||
|
}else {
|
||||||
|
if( timelineType == VIDEOS_IN_PLAYLIST) {
|
||||||
|
popup.getMenu().findItem(R.id.action_edit).setVisible(false);
|
||||||
|
}else {
|
||||||
|
popup.getMenu().findItem(R.id.action_edit).setVisible(false);
|
||||||
|
popup.getMenu().findItem(R.id.action_remove_playlist).setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
popup.setOnMenuItemClickListener(item -> {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.action_remove_playlist:
|
||||||
|
new Thread(() -> {
|
||||||
|
PlaylistsVM playlistsViewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PlaylistsVM.class);
|
||||||
|
playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, playlist, video.getId());
|
||||||
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
|
Runnable myRunnable = () -> {
|
||||||
|
videos.remove(video);
|
||||||
|
notifyDataSetChanged();
|
||||||
|
if (videos.size() == 0) {
|
||||||
|
allVideoRemoved.onAllVideoRemoved();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
mainHandler.post(myRunnable);
|
||||||
|
}).start();
|
||||||
|
break;
|
||||||
|
case R.id.action_edit:
|
||||||
|
Intent intent = new Intent(context, PeertubeEditUploadActivity.class);
|
||||||
|
Bundle b = new Bundle();
|
||||||
|
b.putString("video_id", video.getUuid());
|
||||||
|
intent.putExtras(b);
|
||||||
|
context.startActivity(intent);
|
||||||
|
break;
|
||||||
|
case R.id.action_report:
|
||||||
|
androidx.appcompat.app.AlertDialog.Builder dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(context);
|
||||||
|
LayoutInflater inflater1 = ((Activity)context).getLayoutInflater();
|
||||||
|
View dialogView = inflater1.inflate(R.layout.popup_report, new LinearLayout(context), false);
|
||||||
|
dialogBuilder.setView(dialogView);
|
||||||
|
EditText report_content = dialogView.findViewById(R.id.report_content);
|
||||||
|
dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
||||||
|
dialogBuilder.setPositiveButton(R.string.report, (dialog, id) -> {
|
||||||
|
if (report_content.getText().toString().trim().length() == 0) {
|
||||||
|
Toasty.info(context, context.getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show();
|
||||||
|
} else {
|
||||||
|
PostActionsVM viewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PostActionsVM.class);
|
||||||
|
Report report = new Report();
|
||||||
|
Report.VideoReport videoReport = new Report.VideoReport();
|
||||||
|
videoReport.setId(video.getId());
|
||||||
|
report.setVideo(videoReport);
|
||||||
|
report.setReason(report_content.getText().toString());
|
||||||
|
viewModel.report(report).observe((LifecycleOwner) context, apiResponse -> manageVIewPostActions(RetrofitPeertubeAPI.ActionType.REPORT_VIDEO, apiResponse));
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
androidx.appcompat.app.AlertDialog alertDialog2 = dialogBuilder.create();
|
||||||
|
alertDialog2.show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
popup.show();
|
||||||
|
});
|
||||||
|
|
||||||
if (!ownVideos) {
|
if (!ownVideos) {
|
||||||
holder.bottom_container.setOnClickListener(v -> {
|
holder.bottom_container.setOnClickListener(v -> {
|
||||||
@ -158,11 +256,17 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, APIResponse apiResponse) {
|
||||||
|
if (statusAction == RetrofitPeertubeAPI.ActionType.REPORT_VIDEO) {
|
||||||
|
Toasty.success(context, context.getString(R.string.successful_video_report), Toasty.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
LinearLayout main_container, bottom_container;
|
LinearLayout main_container, bottom_container;
|
||||||
ImageView peertube_profile, peertube_video_image;
|
ImageView peertube_profile, peertube_video_image;
|
||||||
TextView peertube_account_name, peertube_views, peertube_duration;
|
TextView peertube_account_name, peertube_views, peertube_duration;
|
||||||
TextView peertube_title, peertube_date, header_title;
|
TextView peertube_title, peertube_date, header_title, more_actions;
|
||||||
|
|
||||||
public ViewHolder(@NonNull View itemView) {
|
public ViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
@ -176,6 +280,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
main_container = itemView.findViewById(R.id.main_container);
|
main_container = itemView.findViewById(R.id.main_container);
|
||||||
header_title = itemView.findViewById(R.id.header_title);
|
header_title = itemView.findViewById(R.id.header_title);
|
||||||
bottom_container = itemView.findViewById(R.id.bottom_container);
|
bottom_container = itemView.findViewById(R.id.bottom_container);
|
||||||
|
more_actions = itemView.findViewById(R.id.more_actions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ public class PlaylistsVM extends AndroidViewModel {
|
|||||||
apiResponse.setPlaylists(new ArrayList<>());
|
apiResponse.setPlaylists(new ArrayList<>());
|
||||||
} else {
|
} else {
|
||||||
Log.v(Helper.TAG,"managePlaylists: " + account);
|
Log.v(Helper.TAG,"managePlaylists: " + account);
|
||||||
apiResponse = new RetrofitPeertubeAPI(_mContext).playlistAction(apiAction, playlist != null ? playlist.getId() : null, videoId, account.getAcct());
|
apiResponse = new RetrofitPeertubeAPI(_mContext).playlistAction(apiAction, playlist != null ? playlist.getUuid() : null, videoId, account.getAcct());
|
||||||
}
|
}
|
||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
if (apiResponse != null) {
|
if (apiResponse != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user