some fixes

This commit is contained in:
Thomas 2020-10-06 18:49:15 +02:00
parent 6a762a8fd6
commit 7eef023277
9 changed files with 84 additions and 70 deletions

View File

@ -195,7 +195,7 @@ public class AllPlaylistsActivity extends AppCompatActivity {
Toasty.error(AllPlaylistsActivity.this, getString(R.string.error_channel_mandatory), Toast.LENGTH_LONG).show();
} else {
if (privacyToSend != null) {
playlistElement.setPrivacy((int) privacyItem.getId());
playlistElement.setPrivacy(privacyItem.getId());
}
new Thread(() -> {
String playlistId;
@ -310,7 +310,7 @@ public class AllPlaylistsActivity extends AppCompatActivity {
if (playlistToEdit != null) {
Item privacy = playlistToEdit.getPrivacy();
if (privacy.getId() > 0) {
set_upload_privacy.setSelection((int) privacy.getId() - 1);
set_upload_privacy.setSelection(privacy.getId() - 1);
}
} else {
set_upload_privacy.setSelection(2);
@ -345,7 +345,7 @@ public class AllPlaylistsActivity extends AppCompatActivity {
Item privacy = playlistToEdit.getPrivacy();
if (privacy.getId() > 0) {
set_upload_privacy.setSelection((int) privacy.getId() - 1);
set_upload_privacy.setSelection(privacy.getId() - 1);
}
}

View File

@ -133,7 +133,7 @@ import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_PLAYLISTS
public class PeertubeActivity extends AppCompatActivity implements CommentListAdapter.AllCommentRemoved {
public static String video_id;
private String peertubeInstance, videoId;
private String peertubeInstance, videoId, videoUuid;
private FullScreenMediaController.fullscreen fullscreen;
private RelativeLayout loader;
private TextView peertube_view_count, peertube_playlist, peertube_bookmark, peertube_like_count, peertube_dislike_count, peertube_description, peertube_title, more_actions;
@ -150,7 +150,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private ImageView send;
private TextView add_comment_read;
private EditText add_comment_write;
private List<String> playlistForVideo;
private List<PlaylistExist> playlistForVideo;
private List<Playlist> playlists;
private PlaylistsVM playlistsViewModel;
private boolean playInMinimized;
@ -231,6 +231,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
if (b != null) {
peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this));
videoId = b.getString("video_id", null);
videoUuid = b.getString("video_uuid", null);
}
playInMinimized = sharedpreferences.getBoolean(getString(R.string.set_video_minimize_choice), true);
@ -276,7 +277,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
webview_video.getSettings().setAppCacheEnabled(true);
webview_video.getSettings().setMediaPlaybackRequiresUserGesture(false);
webview_video.setWebViewClient(new MastalabWebViewClient(PeertubeActivity.this));
webview_video.loadUrl("https://" + peertubeInstance + "/videos/embed/" + videoId);
webview_video.loadUrl("https://" + peertubeInstance + "/videos/embed/" + videoUuid);
} else {
webview_video.setVisibility(View.GONE);
playerView.setVisibility(View.VISIBLE);
@ -307,7 +308,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
commentViewModel.getThread(videoId, max_id).observe(PeertubeActivity.this, apiresponse -> manageVIewComment(apiresponse));
commentViewModel.getThread(videoUuid, max_id).observe(PeertubeActivity.this, apiresponse -> manageVIewComment(apiresponse));
}
}
}
@ -347,6 +348,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
if (b != null) {
peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this));
videoId = b.getString("video_id", null);
videoUuid = b.getString("video_uuid", null);
playVideo();
}
}
@ -368,9 +370,9 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube_playlist.setVisibility(View.VISIBLE);
peertube_bookmark.setVisibility(View.GONE);
TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class);
feedsViewModel.getVideo(videoId).observe(PeertubeActivity.this, this::manageVIewVideo);
feedsViewModel.getVideo(videoUuid).observe(PeertubeActivity.this, this::manageVIewVideo);
CaptionsVM captionsViewModel = new ViewModelProvider(PeertubeActivity.this).get(CaptionsVM.class);
captionsViewModel.getCaptions(videoId).observe(PeertubeActivity.this, this::manageCaptions);
captionsViewModel.getCaptions(videoUuid).observe(PeertubeActivity.this, this::manageCaptions);
}
public void change() {
@ -543,18 +545,20 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube_playlist.setOnClickListener(v -> {
if (playlists != null && videoId != null) {
if (playlists != null && videoUuid != null) {
PopupMenu popup = new PopupMenu(PeertubeActivity.this, peertube_playlist);
for (Playlist playlist : playlists) {
String title = null;
boolean isPresent = false;
String elementId = null;
for (String playlistId : playlistForVideo) {
if (playlist.getId().compareTo(playlistId) == 0) {
PlaylistExist playlistExistTarget = null;
for (PlaylistExist playlistExist : playlistForVideo) {
if (playlist.getId().compareTo(playlistExist.getPlaylistId()) == 0) {
title = "" + playlist.getDisplayName();
isPresent = true;
elementId = playlistId;
playlistExistTarget = playlistExist;
elementId = playlistExist.getPlaylistElementId();
break;
}
}
@ -564,6 +568,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title);
boolean finalIsPresent = isPresent;
String finalElementId = elementId;
PlaylistExist finalPlaylistExistTarget = playlistExistTarget;
item.setOnMenuItemClickListener(item1 -> {
item1.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item1.setActionView(new View(PeertubeActivity.this));
@ -581,11 +586,10 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
if (finalIsPresent) {
item1.setTitle(playlist.getDisplayName());
playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, playlist, finalElementId).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.DELETE_VIDEOS, apiResponse3));
playlistForVideo.remove(playlist.getId());
playlistForVideo.remove(finalPlaylistExistTarget);
} else {
item1.setTitle("" + playlist.getDisplayName());
playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, playlist, videoId).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.ADD_VIDEOS, apiResponse3));
playlistForVideo.add(playlist.getId());
playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, playlist, videoUuid).observe(PeertubeActivity.this, apiResponse3 -> addElement(playlist.getId(), apiResponse3));
}
return false;
});
@ -597,7 +601,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
if (peertube.isCommentsEnabled()) {
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
commentViewModel.getThread(videoId, max_id).observe(PeertubeActivity.this, this::manageVIewComment);
commentViewModel.getThread(videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment);
write_comment_container.setVisibility(View.VISIBLE);
} else {
@ -672,7 +676,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
playerView.setPlayer(player);
loader.setVisibility(View.GONE);
if( apiResponse.getPeertubes().get(0).getFiles() != null && apiResponse.getPeertubes().get(0).getFiles().size() > 0) {
if (apiResponse.getPeertubes().get(0).getFiles() != null && apiResponse.getPeertubes().get(0).getFiles().size() > 0) {
if (video_cache == 0) {
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
Util.getUserAgent(PeertubeActivity.this, null), null);
@ -684,7 +688,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
}
player.prepare(videoSource);
}else{
} else {
HlsMediaSource hlsMediaSource = new HlsMediaSource.Factory(new DefaultHttpDataSourceFactory(System.getProperty("http.agent")))
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getStreamingPlaylists().get(0).getPlaylistUrl()));
player.prepare(hlsMediaSource);
@ -783,7 +787,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
itemsKeyLanguage[which]);
if( apiResponse.getPeertubes().get(0).getFiles() != null && apiResponse.getPeertubes().get(0).getFiles().size() > 0) {
if (apiResponse.getPeertubes().get(0).getFiles() != null && apiResponse.getPeertubes().get(0).getFiles().size() > 0) {
if (video_cache == 0) {
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
Util.getUserAgent(PeertubeActivity.this, null), null);
@ -984,7 +988,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
if (peertube.isCommentsEnabled() && statusAction == ADD_COMMENT) {
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
commentViewModel.getThread(videoId, max_id).observe(PeertubeActivity.this, this::manageVIewComment);
commentViewModel.getThread(videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment);
} else if (statusAction == RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT) {
Toasty.success(PeertubeActivity.this, getString(R.string.successful_report), Toasty.LENGTH_LONG).show();
} else if (statusAction == RetrofitPeertubeAPI.ActionType.REPORT_VIDEO) {
@ -1045,10 +1049,10 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private void initResolution() {
PlayerControlView controlView = playerView.findViewById(R.id.exo_controller);
resolution = controlView.findViewById(R.id.resolution);
if( peertube.getFiles() != null && peertube.getFiles().size() > 0) {
if (peertube.getFiles() != null && peertube.getFiles().size() > 0) {
resolution.setText(String.format("%s", Helper.defaultFile(PeertubeActivity.this, peertube.getFiles()).getResolutions().getLabel()));
resolution.setOnClickListener(v -> displayResolution());
}else{
} else {
resolution.setVisibility(View.GONE);
}
}
@ -1089,6 +1093,15 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
public void addElement(String playlistId, APIResponse apiResponse) {
if (apiResponse != null && apiResponse.getActionReturn() != null) {
PlaylistExist playlistExist = new PlaylistExist();
playlistExist.setPlaylistId(playlistId);
playlistExist.setPlaylistElementId(apiResponse.getActionReturn());
playlistForVideo.add(playlistExist);
}
}
public void manageVIewVideosExist(APIResponse apiResponse) {
if (apiResponse.getError() == null && apiResponse.getVideoExistPlaylist() != null) {
Map<String, List<PlaylistExist>> videoIds = apiResponse.getVideoExistPlaylist();
@ -1096,9 +1109,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
while (it.hasNext()) {
Map.Entry<String, List<PlaylistExist>> pair = it.next();
List<PlaylistExist> playlistExistVideo = pair.getValue();
for (PlaylistExist playlistExist : playlistExistVideo) {
playlistForVideo.add(playlistExist.getPlaylistId());
}
playlistForVideo.addAll(playlistExistVideo);
it.remove();
}
}

View File

@ -457,12 +457,12 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
videoParams.setDescription(description);
videoParams.setNsfw(isNSFW1);
videoParams.setCommentsEnabled(commentEnabled1);
videoParams.setCategory((int) finalCategoryToSend.getId());
videoParams.setCategory(finalCategoryToSend.getId());
videoParams.setLicence(String.valueOf(finalLicenseToSend.getId()));
videoParams.setLanguage(finalLanguageToSend.getId());
videoParams.setChannelId(channelToSendId);
videoParams.setPrivacy((int) finalPrivacyToSend.getId());
videoParams.setPrivacy(finalPrivacyToSend.getId());
List<String> tags = p_video_tags.getTags();
videoParams.setTags(tags);
set_upload_submit.setEnabled(false);

View File

@ -39,7 +39,6 @@ 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 {

View File

@ -545,10 +545,10 @@ public class RetrofitPeertubeAPI {
e.printStackTrace();
}
String lang = Locale.getDefault().getLanguage();
if( lang.contains("-")) {
if( !lang.split("-")[0].trim().toLowerCase().startsWith("zh")){
if (lang.contains("-")) {
if (!lang.split("-")[0].trim().toLowerCase().startsWith("zh")) {
lang = lang.split("-")[0];
}else {
} else {
lang = lang.split("-")[0] + "-" + lang.split("-")[1].toUpperCase();
}
}

View File

@ -183,33 +183,33 @@ public class VideoData {
public String getFileUrl(String resolution, Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean streamService = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL) == Helper.VIDEO_MODE_STREAMING;
if(files != null && files.size() > 0) {
if (resolution != null) {
for (File file : files) {
if (file.getResolutions().getLabel().compareTo(resolution) == 0) {
if (streamService) {
return file.getMagnetUri();
} else {
return file.getFileUrl();
if (files != null && files.size() > 0) {
if (resolution != null) {
for (File file : files) {
if (file.getResolutions().getLabel().compareTo(resolution) == 0) {
if (streamService) {
return file.getMagnetUri();
} else {
return file.getFileUrl();
}
}
}
}
File file = Helper.defaultFile(context, files);
if (file != null) {
if (streamService) {
return file.getMagnetUri();
} else {
return file.getFileUrl();
}
}
}
}
File file = Helper.defaultFile(context, files);
if (file != null) {
if (streamService) {
return file.getMagnetUri();
} else {
return file.getFileUrl();
}
} else {
return null;
}
}else if(streamingPlaylists != null && streamingPlaylists.size() > 0){
return streamingPlaylists.get(0).getPlaylistUrl();
}
}
} else {
return null;
}
} else if (streamingPlaylists != null && streamingPlaylists.size() > 0) {
return streamingPlaylists.get(0).getPlaylistUrl();
}
return null;
}

View File

@ -59,6 +59,7 @@ import static app.fedilab.fedilabtube.viewmodel.TimelineVM.TimelineType.VIDEOS_I
public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public AllVideoRemoved allVideoRemoved;
private List<VideoData.Video> videos;
private Context context;
private TimelineVM.TimelineType timelineType;
@ -75,12 +76,6 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
this.timelineType = VIDEOS_IN_PLAYLIST;
}
public AllVideoRemoved allVideoRemoved;
public interface AllVideoRemoved{
void onAllVideoRemoved();
}
public PeertubeAdapter(List<VideoData.Video> videos) {
this.videos = videos;
}
@ -150,15 +145,16 @@ 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 {
} else {
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);
}
}
@ -188,7 +184,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
break;
case R.id.action_report:
androidx.appcompat.app.AlertDialog.Builder dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(context);
LayoutInflater inflater1 = ((Activity)context).getLayoutInflater();
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);
@ -218,14 +214,16 @@ 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());
b.putString("video_uuid", 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();
b.putString("video_id", video.getUuid());
b.putString("video_id", video.getId());
b.putString("video_uuid", video.getUuid());
intent.putExtras(b);
context.startActivity(intent);
});
@ -242,13 +240,17 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
return videos.size();
}
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();
}
}
public interface AllVideoRemoved {
void onAllVideoRemoved();
}
static class ViewHolder extends RecyclerView.ViewHolder {
LinearLayout main_container, bottom_container;
ImageView peertube_profile, peertube_video_image;

View File

@ -109,6 +109,7 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
Bundle b = new Bundle();
b.putString("peertube_instance", finalAccountAction1.getHost());
b.putString("video_id", notification.getComment().getVideo().getId());
b.putString("video_uuid", notification.getComment().getVideo().getUuid());
intent.putExtras(b);
context.startActivity(intent);
});
@ -143,6 +144,7 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
Bundle b = new Bundle();
b.putString("peertube_instance", Helper.getLiveInstance(context));
b.putString("video_id", notification.getVideo().getId());
b.putString("video_uuid", notification.getVideo().getUuid());
intent.putExtras(b);
context.startActivity(intent);
});

View File

@ -585,7 +585,7 @@ public class Helper {
* @return File
*/
public static File defaultFile(Context context, List<File> files) {
if( files == null || files.size() == 0) {
if (files == null || files.size() == 0) {
return null;
}
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);