This commit is contained in:
Thomas 2020-10-06 15:30:15 +02:00
parent 6164ff9163
commit 50aeb075b1
12 changed files with 198 additions and 42 deletions

View File

@ -64,6 +64,8 @@
<string name="fullscreen">Vidéo plein écran</string>
<string name="remove_from_playlist">Supprimer de la liste de lecture</string>
<string name="comment">Commenter</string>
<string name="validate">Valider</string>
<string name="delete_comment">Supprimer le commentaire</string>

View File

@ -36,7 +36,7 @@
<string name="download">Download</string>
<string name="profile_picture">Profile picture</string>
<string name="update_video">Update video</string>
<string name="remove_from_playlist">Remove from playlist</string>
<string name="date_seconds">%d s</string>
<string name="date_minutes">%d m</string>

View File

@ -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);

View File

@ -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<PlaylistData.Playlist> playlistCall = peertubeService.getPlaylist(playlistId);
Response<PlaylistData.Playlist> 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<String> stringCall = peertubeService.deleteVideoInPlaylist(getToken(), playlistId, videoId);
Response<String> 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());
}
}

View File

@ -194,12 +194,17 @@ public class VideoData {
}
}
}
File file = Helper.defaultFile(context, files);
if( file != null) {
if (streamService) {
return Helper.defaultFile(context, files).getMagnetUri();
return file.getMagnetUri();
} else {
return Helper.defaultFile(context, files).getFileUrl();
return file.getFileUrl();
}
}else{
return null;
}
}
public String getTorrentUrl(String resolution, Context context) {

View File

@ -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 <http://www.gnu.org/licenses>. */
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<RecyclerView.ViewHolder> {
private List<VideoData.Video> videos;
private Context context;
private boolean myVideos;
TimelineVM.TimelineType timelineType;
PlaylistData.Playlist playlist;
public PeertubeAdapter(List<VideoData.Video> videos, boolean myVideos) {
public PeertubeAdapter(List<VideoData.Video> videos, TimelineVM.TimelineType timelineType) {
this.videos = videos;
this.myVideos = myVideos;
this.timelineType = timelineType;
}
public PeertubeAdapter(List<VideoData.Video> videos, PlaylistData.Playlist playlist) {
this.videos = videos;
this.timelineType = TimelineVM.TimelineType.VIDEOS_IN_PLAYLIST;
this.playlist = playlist;
}
public PeertubeAdapter(List<VideoData.Video> videos) {
this.videos = videos;
this.myVideos = false;
}
@NonNull
@ -62,6 +87,12 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_peertube, parent, false));
}
public PeertubeAdapter.AllVideoRemoved allVideoRemoved;
public interface AllVideoRemoved {
void onAllVideoRemoved();
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
@ -77,7 +108,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
boolean ownVideos;
if (myVideos) {
if (timelineType != null && timelineType == TimelineVM.TimelineType.MY_VIDEOS) {
ownVideos = true;
} else {
ownVideos = video.getAccount() != null && video.getAccount().getId() != null && video.getAccount().getHost().compareTo(Helper.getLiveInstance(context)) == 0 && video.getAccount().getId().compareTo(userId) == 0;
@ -120,7 +151,6 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
if (!ownVideos) {
holder.bottom_container.setOnClickListener(v -> {
Intent intent = new Intent(context, PeertubeActivity.class);
Bundle b = new Bundle();
@ -128,15 +158,6 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
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.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<RecyclerView.ViewHolde
context.startActivity(intent);
});
holder.more_actions.setOnClickListener(v -> {
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<RecyclerView.ViewHolde
LinearLayout main_container, bottom_container;
ImageView peertube_profile, peertube_video_image;
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) {
super(itemView);
@ -176,6 +276,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
main_container = itemView.findViewById(R.id.main_container);
header_title = itemView.findViewById(R.id.header_title);
bottom_container = itemView.findViewById(R.id.bottom_container);
more_actions = itemView.findViewById(R.id.more_actions);
}
}

View File

@ -56,7 +56,7 @@ import app.fedilab.fedilabtube.viewmodel.TimelineVM;
import es.dmoral.toasty.Toasty;
public class DisplayVideosFragment extends Fragment implements AccountsHorizontalListAdapter.EventListener {
public class DisplayVideosFragment extends Fragment implements AccountsHorizontalListAdapter.EventListener, PeertubeAdapter.AllVideoRemoved {
private LinearLayoutManager mLayoutManager;
@ -131,7 +131,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
peertubeAdapater = new PeertubeAdapter(this.peertubes, type == TimelineVM.TimelineType.MY_VIDEOS);
peertubeAdapater = new PeertubeAdapter(this.peertubes, TimelineVM.TimelineType.MY_VIDEOS);
lv_status.setAdapter(peertubeAdapater);
accountsHorizontalListAdapter = new AccountsHorizontalListAdapter(this.accounts, this);
@ -317,7 +317,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
this.peertubes.addAll(apiResponse.getPeertubes());
//If no item were inserted previously the adapter is created
if (previousPosition == 0) {
peertubeAdapater = new PeertubeAdapter(this.peertubes, type == TimelineVM.TimelineType.MY_VIDEOS);
peertubeAdapater = new PeertubeAdapter(this.peertubes, TimelineVM.TimelineType.MY_VIDEOS);
lv_status.setAdapter(peertubeAdapater);
} else
peertubeAdapater.notifyItemRangeInserted(previousPosition, apiResponse.getPeertubes().size());
@ -399,6 +399,11 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
}
}
@Override
public void onAllVideoRemoved() {
textviewNoAction.setVisibility(View.VISIBLE);
}
static class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
private int spanCount;

View File

@ -700,6 +700,9 @@ public class Helper {
* @return File
*/
public static File defaultFile(Context context, List<File> 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) {

View File

@ -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) {

View File

@ -147,6 +147,7 @@ public class TimelineVM extends AndroidViewModel {
TRENDING,
MOST_LIKED,
HISTORY,
RECENT
RECENT,
VIDEOS_IN_PLAYLIST
}
}

View File

@ -87,13 +87,13 @@
android:scaleType="fitCenter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<TextView
android:id="@+id/peertube_title"
android:layout_width="match_parent"
@ -127,5 +127,16 @@
android:layout_marginStart="5dp" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/more_actions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:drawablePadding="5dp"
android:gravity="center_horizontal"
android:text=""
app:drawableTopCompat="@drawable/ic_baseline_more_vert_24" />
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_report"
android:icon="@drawable/ic_baseline_report_24"
android:title="@string/report"
app:showAsAction="never" />
<item
android:id="@+id/action_remove_playlist"
android:icon="@drawable/ic_baseline_playlist_play_24"
android:title="@string/remove_from_playlist"
app:showAsAction="never" />
<item
android:id="@+id/action_edit"
android:icon="@drawable/ic_baseline_edit_24"
android:title="@string/edit_video"
app:showAsAction="never" />
</menu>