diff --git a/app/src/acad/res/values/strings.xml b/app/src/acad/res/values/strings.xml index 0a7efae..6bb166b 100644 --- a/app/src/acad/res/values/strings.xml +++ b/app/src/acad/res/values/strings.xml @@ -64,6 +64,8 @@ Vidéo plein écran + Supprimer de la liste de lecture + Commenter Valider Supprimer le commentaire diff --git a/app/src/full/res/values/strings.xml b/app/src/full/res/values/strings.xml index 7d472aa..f0e310b 100644 --- a/app/src/full/res/values/strings.xml +++ b/app/src/full/res/values/strings.xml @@ -36,7 +36,7 @@ Download Profile picture Update video - + Remove from playlist %d s %d m diff --git a/app/src/main/java/app/fedilab/fedilabtube/PlaylistsActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PlaylistsActivity.java index 197a372..cf36145 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PlaylistsActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PlaylistsActivity.java @@ -39,6 +39,7 @@ import app.fedilab.fedilabtube.viewmodel.PlaylistsVM; import es.dmoral.toasty.Toasty; import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_LIST_VIDEOS; +import static app.fedilab.fedilabtube.viewmodel.TimelineVM.TimelineType.VIDEOS_IN_PLAYLIST; public class PlaylistsActivity extends AppCompatActivity { @@ -84,12 +85,6 @@ public class PlaylistsActivity extends AppCompatActivity { mainLoader.setVisibility(View.VISIBLE); nextElementLoader.setVisibility(View.GONE); - peertubeAdapter = new PeertubeAdapter(this.peertubes); - - lv_playlist.setAdapter(peertubeAdapter); - mLayoutManager = new LinearLayoutManager(PlaylistsActivity.this); - lv_playlist.setLayoutManager(mLayoutManager); - Bundle b = getIntent().getExtras(); if (b != null) { playlist = b.getParcelable("playlist"); @@ -97,6 +92,13 @@ public class PlaylistsActivity extends AppCompatActivity { Toasty.error(PlaylistsActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); return; } + + peertubeAdapter = new PeertubeAdapter(this.peertubes, playlist); + + lv_playlist.setAdapter(peertubeAdapter); + mLayoutManager = new LinearLayoutManager(PlaylistsActivity.this); + lv_playlist.setLayoutManager(mLayoutManager); + if (getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java index 111c267..ff1d2b4 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java @@ -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; @@ -1111,7 +1112,7 @@ public class RetrofitPeertubeAPI { APIResponse apiResponse = new APIResponse(); try { - + Log.v(Helper.TAG,"type: " + type); if (type == PlaylistsVM.action.GET_PLAYLIST_INFO) { Call playlistCall = peertubeService.getPlaylist(playlistId); Response response = playlistCall.execute(); @@ -1156,11 +1157,15 @@ public class RetrofitPeertubeAPI { setError(apiResponse, response.code(), response.errorBody()); } } else if (type == PlaylistsVM.action.DELETE_VIDEOS) { + Log.v(Helper.TAG,"playlistId: " + playlistId); + Log.v(Helper.TAG,"videoId: " + videoId); Call stringCall = peertubeService.deleteVideoInPlaylist(getToken(), playlistId, videoId); Response response = stringCall.execute(); if (response.isSuccessful()) { + Log.v(Helper.TAG,"ok: " + response.body()); apiResponse.setActionReturn(response.body()); } else { + Log.v(Helper.TAG,"err: " + response.errorBody().string()); setError(apiResponse, response.code(), response.errorBody()); } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/data/VideoData.java b/app/src/main/java/app/fedilab/fedilabtube/client/data/VideoData.java index eaabeda..68ccd87 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/data/VideoData.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/data/VideoData.java @@ -194,11 +194,16 @@ public class VideoData { } } } - if (streamService) { - return Helper.defaultFile(context, files).getMagnetUri(); - } else { - return Helper.defaultFile(context, files).getFileUrl(); + File file = Helper.defaultFile(context, files); + if( file != null) { + if (streamService) { + return file.getMagnetUri(); + } else { + return file.getFileUrl(); + } + }else{ + return null; } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java index 5ded4eb..8decaff 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java @@ -14,18 +14,29 @@ package app.fedilab.fedilabtube.drawer; * You should have received a copy of the GNU General Public License along with TubeLab; if not, * see . */ +import android.app.Activity; +import android.app.AlertDialog; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import android.widget.Toast; 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 java.util.List; @@ -34,24 +45,38 @@ import app.fedilab.fedilabtube.PeertubeActivity; import app.fedilab.fedilabtube.PeertubeEditUploadActivity; import app.fedilab.fedilabtube.R; 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.entities.Report; 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; public class PeertubeAdapter extends RecyclerView.Adapter { private List videos; private Context context; - private boolean myVideos; + TimelineVM.TimelineType timelineType; + PlaylistData.Playlist playlist; - public PeertubeAdapter(List videos, boolean myVideos) { + public PeertubeAdapter(List videos, TimelineVM.TimelineType timelineType) { this.videos = videos; - this.myVideos = myVideos; + this.timelineType = timelineType; + } + + public PeertubeAdapter(List videos, PlaylistData.Playlist playlist) { + this.videos = videos; + this.timelineType = TimelineVM.TimelineType.VIDEOS_IN_PLAYLIST; + this.playlist = playlist; } public PeertubeAdapter(List videos) { this.videos = videos; - this.myVideos = false; } @NonNull @@ -62,6 +87,12 @@ public class PeertubeAdapter extends RecyclerView.Adapter { - Intent intent = new Intent(context, PeertubeActivity.class); - Bundle b = new Bundle(); - b.putString("video_id", video.getUuid()); - intent.putExtras(b); - context.startActivity(intent); - }); - } else { - holder.bottom_container.setOnClickListener(v -> { - Intent intent = new Intent(context, PeertubeEditUploadActivity.class); - Bundle b = new Bundle(); - b.putString("video_id", video.getUuid()); - intent.putExtras(b); - context.startActivity(intent); - }); - } + holder.bottom_container.setOnClickListener(v -> { + Intent intent = new Intent(context, PeertubeActivity.class); + Bundle b = new Bundle(); + b.putString("video_id", video.getUuid()); + intent.putExtras(b); + context.startActivity(intent); + }); holder.peertube_video_image.setOnClickListener(v -> { Intent intent = new Intent(context, PeertubeActivity.class); Bundle b = new Bundle(); @@ -145,6 +166,85 @@ public class PeertubeAdapter extends RecyclerView.Adapter { + PopupMenu popup = new PopupMenu(context, holder.more_actions); + popup.getMenuInflater() + .inflate(R.menu.video_drawer_menu, popup.getMenu()); + if (timelineType != TimelineVM.TimelineType.MY_VIDEOS) { + popup.getMenu().findItem(R.id.action_edit).setVisible(false); + if (timelineType != TimelineVM.TimelineType.VIDEOS_IN_PLAYLIST) { + popup.getMenu().findItem(R.id.action_remove_playlist).setVisible(false); + } + } else { + popup.getMenu().findItem(R.id.action_report).setVisible(false); + popup.getMenu().findItem(R.id.action_remove_playlist).setVisible(false); + } + popup.setOnMenuItemClickListener(item -> { + switch (item.getItemId()) { + case R.id.action_remove_playlist: + Log.v(Helper.TAG,"action_remove_playlist"); + PlaylistsVM playlistsViewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PlaylistsVM.class); + playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, playlist, video.getId()); + Log.v(Helper.TAG,"playlist.getUuid(): " + playlist.getUuid()); + Log.v(Helper.TAG,"video.getId(): " + video.getId()); + Handler mainHandler = new Handler(Looper.getMainLooper()); + Runnable myRunnable = () -> { + videos.remove(video); + notifyDataSetChanged(); + if (videos.size() == 0) { + allVideoRemoved.onAllVideoRemoved(); + } + }; + mainHandler.post(myRunnable); + 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(); + }); + + } + + public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, APIResponse apiResponse) { + + if (apiResponse.getError() != null) { + Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); + return; + } + if (statusAction == RetrofitPeertubeAPI.ActionType.REPORT_COMMENT) { + Toasty.success(context, context.getString(R.string.successful_report_comment), Toasty.LENGTH_LONG).show(); + } } @Override @@ -162,7 +262,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter files){ + if( files == null || files.size() == 0){ + return null; + } SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); int video_quality = sharedpreferences.getInt(Helper.SET_QUALITY_MODE, Helper.QUALITY_HIGH); if( video_quality == QUALITY_HIGH) { diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java index 34661b8..fb07bb0 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java @@ -20,6 +20,7 @@ import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; import android.os.Handler; import android.os.Looper; +import android.util.Log; import androidx.annotation.NonNull; import androidx.lifecycle.AndroidViewModel; @@ -84,7 +85,8 @@ public class PlaylistsVM extends AndroidViewModel { apiResponse = new APIResponse(); apiResponse.setPlaylists(new ArrayList<>()); } else { - apiResponse = new RetrofitPeertubeAPI(_mContext).playlistAction(apiAction, playlist != null ? playlist.getUuid() : null, videoId, account.getAcct()); + Log.v(Helper.TAG,"managePlaylists: " + account); + apiResponse = new RetrofitPeertubeAPI(_mContext).playlistAction(apiAction, playlist != null ? playlist.getId() : null, videoId, account.getAcct()); } Handler mainHandler = new Handler(Looper.getMainLooper()); if (apiResponse != null) { diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java index 6d1dff9..da28bd6 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java @@ -147,6 +147,7 @@ public class TimelineVM extends AndroidViewModel { TRENDING, MOST_LIKED, HISTORY, - RECENT + RECENT, + VIDEOS_IN_PLAYLIST } } diff --git a/app/src/main/res/layout/drawer_peertube.xml b/app/src/main/res/layout/drawer_peertube.xml index 812d0b8..7f21632 100644 --- a/app/src/main/res/layout/drawer_peertube.xml +++ b/app/src/main/res/layout/drawer_peertube.xml @@ -87,13 +87,13 @@ android:scaleType="fitCenter" /> - + \ No newline at end of file diff --git a/app/src/main/res/menu/video_drawer_menu.xml b/app/src/main/res/menu/video_drawer_menu.xml new file mode 100644 index 0000000..47a64a4 --- /dev/null +++ b/app/src/main/res/menu/video_drawer_menu.xml @@ -0,0 +1,19 @@ + + + + + +