2020-06-26 08:50:49 +02:00
|
|
|
package app.fedilab.fedilabtube;
|
2020-07-01 16:36:08 +02:00
|
|
|
/* Copyright 2020 Thomas Schneider
|
|
|
|
*
|
|
|
|
* This file is a part of TubeLab
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2020-06-26 08:50:49 +02:00
|
|
|
|
|
|
|
import android.Manifest;
|
2020-10-13 18:11:53 +02:00
|
|
|
import android.annotation.SuppressLint;
|
2020-06-26 08:50:49 +02:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.Dialog;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2020-10-02 15:14:08 +02:00
|
|
|
import android.content.pm.ActivityInfo;
|
2020-06-26 08:50:49 +02:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
2020-06-29 17:59:36 +02:00
|
|
|
import android.graphics.PorterDuff;
|
2020-06-26 08:50:49 +02:00
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
2020-10-02 15:23:36 +02:00
|
|
|
import android.os.Handler;
|
2020-09-19 18:19:59 +02:00
|
|
|
import android.support.v4.media.session.MediaSessionCompat;
|
2020-06-26 08:50:49 +02:00
|
|
|
import android.text.Html;
|
2020-10-15 15:16:41 +02:00
|
|
|
import android.text.Spanned;
|
2020-07-21 18:49:13 +02:00
|
|
|
import android.view.LayoutInflater;
|
2020-06-26 08:50:49 +02:00
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.WindowManager;
|
2020-10-15 15:16:41 +02:00
|
|
|
import android.view.animation.Animation;
|
|
|
|
import android.view.animation.TranslateAnimation;
|
2020-06-26 08:50:49 +02:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2020-10-02 18:22:19 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2020-09-19 14:56:10 +02:00
|
|
|
import androidx.annotation.RequiresApi;
|
2020-09-20 11:07:28 +02:00
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2020-06-26 08:50:49 +02:00
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.widget.PopupMenu;
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
import androidx.core.content.ContextCompat;
|
2020-06-29 17:59:36 +02:00
|
|
|
import androidx.core.graphics.drawable.DrawableCompat;
|
2020-09-07 16:57:00 +02:00
|
|
|
import androidx.lifecycle.ViewModelProvider;
|
2020-06-26 08:50:49 +02:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2020-09-20 12:06:38 +02:00
|
|
|
import com.google.android.exoplayer2.C;
|
2020-06-26 08:50:49 +02:00
|
|
|
import com.google.android.exoplayer2.ExoPlayerFactory;
|
2020-09-20 12:06:38 +02:00
|
|
|
import com.google.android.exoplayer2.Format;
|
2020-06-26 08:50:49 +02:00
|
|
|
import com.google.android.exoplayer2.SimpleExoPlayer;
|
2020-09-19 18:19:59 +02:00
|
|
|
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
|
2020-09-20 12:06:38 +02:00
|
|
|
import com.google.android.exoplayer2.source.MediaSource;
|
|
|
|
import com.google.android.exoplayer2.source.MergingMediaSource;
|
2020-06-26 08:50:49 +02:00
|
|
|
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
|
2020-09-20 12:06:38 +02:00
|
|
|
import com.google.android.exoplayer2.source.SingleSampleMediaSource;
|
2020-10-06 17:11:25 +02:00
|
|
|
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
|
2020-09-20 12:06:38 +02:00
|
|
|
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
|
|
|
|
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
|
|
|
import com.google.android.exoplayer2.trackselection.TrackSelector;
|
2020-06-26 08:50:49 +02:00
|
|
|
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
|
|
|
import com.google.android.exoplayer2.ui.PlayerControlView;
|
|
|
|
import com.google.android.exoplayer2.upstream.DataSource;
|
|
|
|
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
2020-10-06 17:11:25 +02:00
|
|
|
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
|
2020-09-20 12:06:38 +02:00
|
|
|
import com.google.android.exoplayer2.util.MimeTypes;
|
2020-06-26 08:50:49 +02:00
|
|
|
import com.google.android.exoplayer2.util.Util;
|
|
|
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
2020-09-25 18:58:04 +02:00
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
import java.util.ArrayList;
|
2020-10-08 18:13:04 +02:00
|
|
|
import java.util.HashMap;
|
2020-06-26 08:50:49 +02:00
|
|
|
import java.util.List;
|
2020-10-03 18:37:34 +02:00
|
|
|
import java.util.Map;
|
2020-06-26 08:50:49 +02:00
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
import app.fedilab.fedilabtube.client.APIResponse;
|
2020-09-25 18:58:04 +02:00
|
|
|
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
2020-09-26 10:22:11 +02:00
|
|
|
import app.fedilab.fedilabtube.client.data.AccountData.Account;
|
|
|
|
import app.fedilab.fedilabtube.client.data.CaptionData.Caption;
|
2020-10-15 15:16:41 +02:00
|
|
|
import app.fedilab.fedilabtube.client.data.CommentData;
|
2020-09-26 10:22:11 +02:00
|
|
|
import app.fedilab.fedilabtube.client.data.CommentData.Comment;
|
2020-10-08 18:13:04 +02:00
|
|
|
import app.fedilab.fedilabtube.client.data.PlaylistData;
|
2020-09-25 18:58:04 +02:00
|
|
|
import app.fedilab.fedilabtube.client.data.VideoData;
|
|
|
|
import app.fedilab.fedilabtube.client.entities.File;
|
2020-10-01 17:42:03 +02:00
|
|
|
import app.fedilab.fedilabtube.client.entities.ItemStr;
|
2020-10-03 16:22:19 +02:00
|
|
|
import app.fedilab.fedilabtube.client.entities.PlaylistExist;
|
2020-09-26 10:22:11 +02:00
|
|
|
import app.fedilab.fedilabtube.client.entities.Report;
|
2020-10-15 15:16:41 +02:00
|
|
|
import app.fedilab.fedilabtube.databinding.ActivityPeertubeBinding;
|
2020-09-25 18:58:04 +02:00
|
|
|
import app.fedilab.fedilabtube.drawer.CommentListAdapter;
|
2020-06-26 14:34:39 +02:00
|
|
|
import app.fedilab.fedilabtube.helper.CacheDataSourceFactory;
|
2020-06-26 08:50:49 +02:00
|
|
|
import app.fedilab.fedilabtube.helper.FullScreenMediaController;
|
|
|
|
import app.fedilab.fedilabtube.helper.Helper;
|
|
|
|
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
|
|
|
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
2020-09-20 11:07:28 +02:00
|
|
|
import app.fedilab.fedilabtube.viewmodel.CaptionsVM;
|
2020-09-07 16:57:00 +02:00
|
|
|
import app.fedilab.fedilabtube.viewmodel.CommentVM;
|
|
|
|
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
|
|
|
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
|
2020-10-13 11:04:35 +02:00
|
|
|
import app.fedilab.fedilabtube.viewmodel.SearchVM;
|
2020-09-27 16:33:43 +02:00
|
|
|
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
2020-06-26 08:50:49 +02:00
|
|
|
import app.fedilab.fedilabtube.webview.CustomWebview;
|
|
|
|
import app.fedilab.fedilabtube.webview.MastalabWebChromeClient;
|
|
|
|
import app.fedilab.fedilabtube.webview.MastalabWebViewClient;
|
|
|
|
import es.dmoral.toasty.Toasty;
|
|
|
|
|
2020-09-26 16:46:51 +02:00
|
|
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.ADD_COMMENT;
|
|
|
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.RATEVIDEO;
|
2020-10-15 15:16:41 +02:00
|
|
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPLY;
|
2020-09-26 16:46:51 +02:00
|
|
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT;
|
|
|
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPORT_VIDEO;
|
2020-06-29 17:59:36 +02:00
|
|
|
import static app.fedilab.fedilabtube.helper.Helper.getAttColor;
|
2020-09-20 12:06:38 +02:00
|
|
|
import static app.fedilab.fedilabtube.helper.Helper.getLiveInstance;
|
2020-06-27 11:21:25 +02:00
|
|
|
import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
|
2020-06-26 08:50:49 +02:00
|
|
|
|
|
|
|
|
2020-10-01 17:42:03 +02:00
|
|
|
public class PeertubeActivity extends AppCompatActivity implements CommentListAdapter.AllCommentRemoved {
|
2020-06-26 08:50:49 +02:00
|
|
|
|
|
|
|
public static String video_id;
|
2020-10-08 18:13:04 +02:00
|
|
|
private String peertubeInstance, videoUuid;
|
2020-06-26 08:50:49 +02:00
|
|
|
private FullScreenMediaController.fullscreen fullscreen;
|
2020-10-15 15:16:41 +02:00
|
|
|
private ImageView fullScreenIcon;
|
2020-06-26 08:50:49 +02:00
|
|
|
private SimpleExoPlayer player;
|
|
|
|
private boolean fullScreenMode;
|
|
|
|
private Dialog fullScreenDialog;
|
2020-10-15 15:16:41 +02:00
|
|
|
private VideoData.Video peertube;
|
2020-06-26 08:50:49 +02:00
|
|
|
private int mode;
|
2020-10-08 18:13:04 +02:00
|
|
|
private Map<String, List<PlaylistExist>> playlists;
|
2020-09-19 14:56:10 +02:00
|
|
|
private boolean playInMinimized;
|
|
|
|
private boolean onStopCalled;
|
2020-09-20 11:07:28 +02:00
|
|
|
private List<Caption> captions;
|
2020-10-02 18:22:19 +02:00
|
|
|
private String max_id;
|
|
|
|
private boolean flag_loading;
|
2020-10-08 17:16:42 +02:00
|
|
|
private boolean isMyVideo;
|
2020-10-02 18:22:19 +02:00
|
|
|
private List<Comment> comments;
|
2020-10-15 15:16:41 +02:00
|
|
|
private CommentListAdapter commentListAdapter, commentReplyListAdapter;
|
2020-10-09 18:22:05 +02:00
|
|
|
private boolean sepiaSearch;
|
2020-10-15 15:16:41 +02:00
|
|
|
private ActivityPeertubeBinding binding;
|
2020-06-26 08:50:49 +02:00
|
|
|
|
|
|
|
public static void hideKeyboard(Activity activity) {
|
|
|
|
if (activity != null && activity.getWindow() != null) {
|
|
|
|
activity.getWindow().getDecorView();
|
|
|
|
InputMethodManager imm = (InputMethodManager) activity.getSystemService(INPUT_METHOD_SERVICE);
|
|
|
|
assert imm != null;
|
|
|
|
imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2020-10-15 15:16:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
binding = ActivityPeertubeBinding.inflate(getLayoutInflater());
|
|
|
|
View view = binding.getRoot();
|
|
|
|
setContentView(view);
|
2020-09-19 16:50:20 +02:00
|
|
|
|
2020-10-02 18:22:19 +02:00
|
|
|
max_id = "0";
|
2020-10-15 15:16:41 +02:00
|
|
|
|
2020-09-19 16:50:20 +02:00
|
|
|
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
2020-10-01 17:42:03 +02:00
|
|
|
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
2020-10-09 18:22:05 +02:00
|
|
|
if (Helper.isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
|
2020-10-02 15:14:08 +02:00
|
|
|
Account account = new AccountDAO(PeertubeActivity.this, db).getAccountByToken(token);
|
2020-10-15 15:16:41 +02:00
|
|
|
Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, binding.myPp);
|
|
|
|
Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, binding.myPpReply);
|
2020-10-02 15:14:08 +02:00
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
|
|
|
|
|
2020-07-22 10:55:59 +02:00
|
|
|
if (Helper.isTablet(PeertubeActivity.this)) {
|
2020-10-15 15:16:41 +02:00
|
|
|
|
2020-07-09 18:08:43 +02:00
|
|
|
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
0,
|
|
|
|
2.0f
|
|
|
|
);
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.videoContainer.setLayoutParams(param);
|
2020-07-09 18:08:43 +02:00
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
|
2020-09-19 16:50:20 +02:00
|
|
|
if (getSupportActionBar() != null)
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
|
|
|
mode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
|
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
Bundle b = getIntent().getExtras();
|
|
|
|
if (b != null) {
|
2020-06-27 11:21:25 +02:00
|
|
|
peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this));
|
2020-10-06 18:49:15 +02:00
|
|
|
videoUuid = b.getString("video_uuid", null);
|
2020-10-08 17:16:42 +02:00
|
|
|
isMyVideo = b.getBoolean("isMyVideo", false);
|
2020-10-09 18:22:05 +02:00
|
|
|
sepiaSearch = b.getBoolean("sepia_search", false);
|
2020-10-13 11:04:35 +02:00
|
|
|
peertube = b.getParcelable("video");
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
2020-06-27 11:21:25 +02:00
|
|
|
|
2020-10-08 18:13:04 +02:00
|
|
|
|
2020-09-19 16:50:20 +02:00
|
|
|
playInMinimized = sharedpreferences.getBoolean(getString(R.string.set_video_minimize_choice), true);
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N
|
|
|
|
&& !getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
|
|
|
|
playInMinimized = false;
|
|
|
|
}
|
2020-10-07 09:25:58 +02:00
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
if (mode == Helper.VIDEO_MODE_WEBVIEW) {
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.webviewVideo.setVisibility(View.VISIBLE);
|
|
|
|
binding.mediaVideo.setVisibility(View.GONE);
|
|
|
|
CustomWebview webview_video = Helper.initializeWebview(PeertubeActivity.this, R.id.webview_video, null);
|
2020-06-26 08:50:49 +02:00
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
MastalabWebChromeClient mastalabWebChromeClient = new MastalabWebChromeClient(PeertubeActivity.this, webview_video, binding.mainMediaFrame, binding.videoLayout);
|
2020-06-26 08:50:49 +02:00
|
|
|
mastalabWebChromeClient.setOnToggledFullscreen(fullscreen -> {
|
|
|
|
|
|
|
|
if (fullscreen) {
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.videoLayout.setVisibility(View.VISIBLE);
|
2020-06-26 08:50:49 +02:00
|
|
|
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
|
|
|
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
|
|
|
attrs.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
|
|
|
|
getWindow().setAttributes(attrs);
|
|
|
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.peertubeInformationContainer.setVisibility(View.GONE);
|
2020-10-03 18:37:34 +02:00
|
|
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
2020-06-26 08:50:49 +02:00
|
|
|
} else {
|
|
|
|
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
|
|
|
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
|
|
|
attrs.flags &= ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
|
|
|
|
getWindow().setAttributes(attrs);
|
|
|
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.videoLayout.setVisibility(View.GONE);
|
|
|
|
binding.peertubeInformationContainer.setVisibility(View.VISIBLE);
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
});
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.webviewVideo.getSettings().setAllowFileAccess(true);
|
|
|
|
binding.webviewVideo.setWebChromeClient(mastalabWebChromeClient);
|
|
|
|
binding.webviewVideo.getSettings().setDomStorageEnabled(true);
|
|
|
|
binding.webviewVideo.getSettings().setAppCacheEnabled(true);
|
|
|
|
binding.webviewVideo.getSettings().setMediaPlaybackRequiresUserGesture(false);
|
|
|
|
binding.webviewVideo.setWebViewClient(new MastalabWebViewClient(PeertubeActivity.this));
|
|
|
|
binding.webviewVideo.loadUrl("https://" + peertubeInstance + "/videos/embed/" + videoUuid);
|
2020-06-26 08:50:49 +02:00
|
|
|
} else {
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.webviewVideo.setVisibility(View.GONE);
|
|
|
|
binding.mediaVideo.setVisibility(View.VISIBLE);
|
|
|
|
binding.loader.setVisibility(View.VISIBLE);
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mode != Helper.VIDEO_MODE_WEBVIEW) {
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.mediaVideo.setControllerShowTimeoutMs(1000);
|
|
|
|
binding.mediaVideo.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
|
2020-06-26 08:50:49 +02:00
|
|
|
initFullscreenDialog();
|
|
|
|
initFullscreenButton();
|
|
|
|
}
|
2020-10-02 18:22:19 +02:00
|
|
|
flag_loading = true;
|
|
|
|
comments = new ArrayList<>();
|
2020-10-15 15:16:41 +02:00
|
|
|
|
|
|
|
binding.closeReply.setOnClickListener(v->closeCommentThread());
|
|
|
|
|
2020-10-13 17:50:52 +02:00
|
|
|
commentListAdapter = new CommentListAdapter(comments, Helper.isVideoOwner(PeertubeActivity.this, peertube));
|
2020-10-02 18:22:19 +02:00
|
|
|
commentListAdapter.allCommentRemoved = PeertubeActivity.this;
|
|
|
|
LinearLayoutManager mLayoutManager = new LinearLayoutManager(PeertubeActivity.this);
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.peertubeComments.setLayoutManager(mLayoutManager);
|
|
|
|
binding.peertubeComments.setNestedScrollingEnabled(false);
|
|
|
|
binding.peertubeComments.setAdapter(commentListAdapter);
|
|
|
|
binding.peertubeComments.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
2020-10-02 18:22:19 +02:00
|
|
|
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
|
|
|
if (dy > 0) {
|
|
|
|
int visibleItemCount = mLayoutManager.getChildCount();
|
|
|
|
int totalItemCount = mLayoutManager.getItemCount();
|
|
|
|
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
|
|
|
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
|
|
|
if (!flag_loading) {
|
|
|
|
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
|
2020-10-09 18:22:05 +02:00
|
|
|
commentViewModel.getThread(sepiaSearch?peertubeInstance:null, videoUuid, max_id).observe(PeertubeActivity.this, apiresponse -> manageVIewComment(apiresponse));
|
2020-10-02 18:22:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-10-13 11:04:35 +02:00
|
|
|
if( peertube != null && sepiaSearch && peertube.getEmbedUrl() != null && Helper.isLoggedIn(PeertubeActivity.this)) {
|
|
|
|
SearchVM viewModelSearch = new ViewModelProvider(PeertubeActivity.this).get(SearchVM.class);
|
|
|
|
viewModelSearch.getVideos("0", peertube.getEmbedUrl()).observe(PeertubeActivity.this, this::manageVIewVideos);
|
|
|
|
}else {
|
|
|
|
playVideo();
|
|
|
|
}
|
2020-09-19 16:50:20 +02:00
|
|
|
}
|
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
|
|
|
|
|
2020-10-13 11:04:35 +02:00
|
|
|
private void manageVIewVideos(APIResponse apiResponse) {
|
|
|
|
if( apiResponse == null || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
|
|
|
|
playVideo();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
peertube = apiResponse.getPeertubes().get(0);
|
|
|
|
sepiaSearch = false;
|
|
|
|
playVideo();
|
|
|
|
}
|
2020-10-02 18:22:19 +02:00
|
|
|
|
|
|
|
public void manageVIewComment(APIResponse apiResponse) {
|
|
|
|
flag_loading = false;
|
|
|
|
if (apiResponse == null || (apiResponse.getError() != null)) {
|
|
|
|
if (apiResponse == null)
|
|
|
|
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
|
|
|
else
|
|
|
|
Toasty.error(PeertubeActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int oldSize = comments.size();
|
|
|
|
int newComments = 0;
|
|
|
|
for (Comment comment : apiResponse.getComments()) {
|
|
|
|
if (comment.getText() != null && comment.getText().trim().length() > 0) {
|
|
|
|
comments.add(comment);
|
|
|
|
newComments++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (comments.size() > 0) {
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.peertubeComments.setVisibility(View.VISIBLE);
|
2020-10-02 18:22:19 +02:00
|
|
|
commentListAdapter.notifyItemRangeInserted(oldSize, newComments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
|
|
|
|
public void manageVIewCommentReply(APIResponse apiResponse) {
|
|
|
|
if (apiResponse == null || apiResponse.getError() != null || apiResponse.getCommentThreadData() == null) {
|
|
|
|
if (apiResponse == null || apiResponse.getError() == null)
|
|
|
|
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
|
|
|
else
|
|
|
|
Toasty.error(PeertubeActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
List<CommentData.CommentThreadData> commentThreadDataList = apiResponse.getCommentThreadData().getChildren();
|
|
|
|
List<Comment> comments = generateCommentReply(commentThreadDataList, new ArrayList<>());
|
|
|
|
if (comments.size() > 0) {
|
|
|
|
commentReplyListAdapter = new CommentListAdapter(comments, Helper.isVideoOwner(PeertubeActivity.this, peertube));
|
|
|
|
LinearLayoutManager mLayoutManager = new LinearLayoutManager(PeertubeActivity.this);
|
|
|
|
binding.peertubeReply.setLayoutManager(mLayoutManager);
|
|
|
|
binding.peertubeReply.setNestedScrollingEnabled(false);
|
|
|
|
binding.peertubeReply.setAdapter(commentReplyListAdapter);
|
|
|
|
binding.peertubeReply.setVisibility(View.VISIBLE);
|
|
|
|
commentReplyListAdapter.notifyItemRangeInserted(0, comments.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<Comment> generateCommentReply(List<CommentData.CommentThreadData> commentThreadDataList, List<Comment> comments) {
|
|
|
|
for (CommentData.CommentThreadData commentThreadData : commentThreadDataList) {
|
|
|
|
if (commentThreadData.getComment().getText() != null && commentThreadData.getComment().getText().trim().length() > 0) {
|
|
|
|
commentThreadData.getComment().setReply(true);
|
|
|
|
comments.add(commentThreadData.getComment());
|
|
|
|
}
|
|
|
|
if( commentThreadData.getChildren() != null && commentThreadData.getChildren().size() >0) {
|
|
|
|
generateCommentReply(commentThreadData.getChildren(), comments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return comments;
|
|
|
|
}
|
|
|
|
|
2020-09-19 16:50:20 +02:00
|
|
|
@Override
|
|
|
|
public void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
Bundle b = intent.getExtras();
|
|
|
|
if (b != null) {
|
|
|
|
peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this));
|
2020-10-06 18:49:15 +02:00
|
|
|
videoUuid = b.getString("video_uuid", null);
|
2020-09-19 16:50:20 +02:00
|
|
|
playVideo();
|
2020-06-30 13:45:32 +02:00
|
|
|
}
|
2020-09-19 16:50:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void playVideo() {
|
|
|
|
if (player != null) {
|
|
|
|
player.setPlayWhenReady(false);
|
|
|
|
player.release();
|
|
|
|
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this);
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.mediaVideo.setPlayer(player);
|
|
|
|
binding.loader.setVisibility(View.GONE);
|
2020-09-19 16:50:20 +02:00
|
|
|
player.setPlayWhenReady(true);
|
2020-09-20 11:07:28 +02:00
|
|
|
captions = null;
|
2020-09-19 16:50:20 +02:00
|
|
|
}
|
|
|
|
fullscreen = FullScreenMediaController.fullscreen.OFF;
|
|
|
|
setFullscreen(FullScreenMediaController.fullscreen.OFF);
|
|
|
|
fullScreenMode = false;
|
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.peertubePlaylist.setVisibility(View.VISIBLE);
|
|
|
|
binding.peertubeBookmark.setVisibility(View.GONE);
|
2020-09-25 18:58:04 +02:00
|
|
|
TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class);
|
2020-10-09 18:22:05 +02:00
|
|
|
feedsViewModel.getVideo(sepiaSearch?peertubeInstance:null, videoUuid, isMyVideo).observe(PeertubeActivity.this, this::manageVIewVideo);
|
2020-09-20 11:07:28 +02:00
|
|
|
CaptionsVM captionsViewModel = new ViewModelProvider(PeertubeActivity.this).get(CaptionsVM.class);
|
2020-10-09 18:22:05 +02:00
|
|
|
captionsViewModel.getCaptions(sepiaSearch?peertubeInstance:null, videoUuid).observe(PeertubeActivity.this, this::manageCaptions);
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void change() {
|
|
|
|
if (fullscreen == FullScreenMediaController.fullscreen.ON) {
|
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
|
|
|
|
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
Objects.requireNonNull(getSupportActionBar()).hide();
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.peertubeInformationContainer.setVisibility(View.GONE);
|
2020-06-26 08:50:49 +02:00
|
|
|
} else {
|
|
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
|
|
|
|
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
|
|
|
|
Objects.requireNonNull(getSupportActionBar()).show();
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.peertubeInformationContainer.setVisibility(View.VISIBLE);
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
|
View v = getCurrentFocus();
|
|
|
|
|
|
|
|
if ((ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_MOVE) &&
|
|
|
|
v instanceof EditText &&
|
|
|
|
v.getId() == R.id.add_comment_write) {
|
|
|
|
int[] scrcoords = new int[2];
|
|
|
|
v.getLocationOnScreen(scrcoords);
|
|
|
|
float x = ev.getRawX() + v.getLeft() - scrcoords[0];
|
|
|
|
float y = ev.getRawY() + v.getTop() - scrcoords[1];
|
|
|
|
|
|
|
|
if (x < v.getLeft() || x > v.getRight() || y < v.getTop() || y > v.getBottom()) {
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.addCommentRead.setVisibility(View.VISIBLE);
|
|
|
|
binding.addCommentWrite.setVisibility(View.GONE);
|
|
|
|
binding.send.setVisibility(View.GONE);
|
2020-06-26 08:50:49 +02:00
|
|
|
hideKeyboard(PeertubeActivity.this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.dispatchTouchEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2020-06-26 14:34:39 +02:00
|
|
|
if (item.getItemId() == android.R.id.home) {
|
2020-09-20 15:14:48 +02:00
|
|
|
if (playInMinimized && player != null) {
|
|
|
|
enterVideoMode();
|
|
|
|
} else {
|
|
|
|
finish();
|
|
|
|
}
|
2020-06-26 14:34:39 +02:00
|
|
|
return true;
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
2020-06-26 14:34:39 +02:00
|
|
|
return super.onOptionsItemSelected(item);
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
|
2020-09-26 10:22:11 +02:00
|
|
|
private void reportAlert(RetrofitPeertubeAPI.ActionType type, androidx.appcompat.app.AlertDialog alertDialog) {
|
2020-07-21 18:49:13 +02:00
|
|
|
androidx.appcompat.app.AlertDialog.Builder dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(PeertubeActivity.this);
|
|
|
|
LayoutInflater inflater1 = getLayoutInflater();
|
|
|
|
View dialogView = inflater1.inflate(R.layout.popup_report, new LinearLayout(PeertubeActivity.this), false);
|
|
|
|
dialogBuilder.setView(dialogView);
|
|
|
|
dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
2020-10-15 15:16:41 +02:00
|
|
|
EditText report_content = dialogView.findViewById(R.id.report_content);
|
2020-07-21 18:49:13 +02:00
|
|
|
dialogBuilder.setPositiveButton(R.string.report, (dialog, id) -> {
|
2020-07-22 10:55:59 +02:00
|
|
|
if (report_content.getText().toString().trim().length() == 0) {
|
|
|
|
Toasty.info(PeertubeActivity.this, getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show();
|
|
|
|
} else {
|
2020-09-26 10:22:11 +02:00
|
|
|
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
|
|
|
if (type == RetrofitPeertubeAPI.ActionType.REPORT_VIDEO) {
|
|
|
|
Report report = new Report();
|
|
|
|
Report.VideoReport videoReport = new Report.VideoReport();
|
|
|
|
videoReport.setId(peertube.getId());
|
|
|
|
report.setVideo(videoReport);
|
|
|
|
report.setReason(report_content.getText().toString());
|
|
|
|
viewModel.report(report).observe(PeertubeActivity.this, apiResponse -> manageVIewPostActions(RetrofitPeertubeAPI.ActionType.REPORT_VIDEO, apiResponse));
|
2020-07-22 10:55:59 +02:00
|
|
|
alertDialog.dismiss();
|
|
|
|
dialog.dismiss();
|
2020-09-26 10:22:11 +02:00
|
|
|
} else if (type == RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT) {
|
|
|
|
Report report = new Report();
|
|
|
|
Report.AccountReport accountReport = new Report.AccountReport();
|
|
|
|
accountReport.setId(peertube.getAccount().getId());
|
|
|
|
report.setAccount(accountReport);
|
|
|
|
report.setReason(report_content.getText().toString());
|
|
|
|
viewModel.report(report).observe(PeertubeActivity.this, apiResponse -> manageVIewPostActions(RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT, apiResponse));
|
2020-07-22 10:55:59 +02:00
|
|
|
alertDialog.dismiss();
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
2020-07-21 18:49:13 +02:00
|
|
|
}
|
|
|
|
});
|
2020-07-22 10:55:59 +02:00
|
|
|
androidx.appcompat.app.AlertDialog alertDialog2 = dialogBuilder.create();
|
2020-07-21 18:49:13 +02:00
|
|
|
alertDialog2.show();
|
|
|
|
}
|
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
public FullScreenMediaController.fullscreen getFullscreen() {
|
|
|
|
return fullscreen;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFullscreen(FullScreenMediaController.fullscreen fullscreen) {
|
|
|
|
this.fullscreen = fullscreen;
|
|
|
|
}
|
|
|
|
|
2020-09-20 11:07:28 +02:00
|
|
|
|
|
|
|
public void manageCaptions(APIResponse apiResponse) {
|
|
|
|
if (apiResponse == null || (apiResponse.getError() != null) || apiResponse.getCaptions() == null || apiResponse.getCaptions().size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
captions = apiResponse.getCaptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-13 18:11:53 +02:00
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
2020-09-07 16:57:00 +02:00
|
|
|
public void manageVIewVideo(APIResponse apiResponse) {
|
2020-06-26 08:50:49 +02:00
|
|
|
|
|
|
|
if (apiResponse == null || (apiResponse.getError() != null) || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
|
|
|
|
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.loader.setVisibility(View.GONE);
|
2020-06-26 08:50:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-09-03 19:08:53 +02:00
|
|
|
if (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().get(0) == null || apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this) == null) {
|
2020-06-26 08:50:49 +02:00
|
|
|
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.loader.setVisibility(View.GONE);
|
2020-06-26 08:50:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-19 16:50:20 +02:00
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
peertube = apiResponse.getPeertubes().get(0);
|
2020-10-09 18:22:05 +02:00
|
|
|
if( sepiaSearch) {
|
|
|
|
peertubeInstance = peertube.getAccount().getHost();
|
|
|
|
}
|
2020-10-08 18:13:04 +02:00
|
|
|
List<String> videoIds = new ArrayList<>();
|
|
|
|
videoIds.add(peertube.getId());
|
|
|
|
PlaylistsVM viewModel = new ViewModelProvider(this).get(PlaylistsVM.class);
|
|
|
|
viewModel.videoExists(videoIds).observe(this, this::manageVIewPlaylist);
|
|
|
|
|
2020-10-03 16:22:19 +02:00
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.writeCommentContainer.setOnClickListener(v -> {
|
2020-10-09 18:22:05 +02:00
|
|
|
if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.addCommentRead.setVisibility(View.GONE);
|
|
|
|
binding.addCommentWrite.setVisibility(View.VISIBLE);
|
|
|
|
binding.send.setVisibility(View.VISIBLE);
|
|
|
|
binding.addCommentWrite.requestFocus();
|
|
|
|
binding.addCommentWrite.setSelection( binding.addCommentWrite.getText().length());
|
2020-06-27 19:08:52 +02:00
|
|
|
} else {
|
2020-10-13 11:04:35 +02:00
|
|
|
if( sepiaSearch) {
|
|
|
|
Toasty.info(PeertubeActivity.this, getString(R.string.federation_issue), Toasty.LENGTH_SHORT).show();
|
|
|
|
}else {
|
|
|
|
Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2020-06-27 19:08:52 +02:00
|
|
|
}
|
2020-06-27 11:21:25 +02:00
|
|
|
|
2020-06-27 19:08:52 +02:00
|
|
|
});
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.writeCommentContainerReply.setOnClickListener(v -> {
|
|
|
|
if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
|
|
|
|
binding.addCommentReadReply.setVisibility(View.GONE);
|
|
|
|
binding.addCommentWriteReply.setVisibility(View.VISIBLE);
|
|
|
|
binding.send.setVisibility(View.VISIBLE);
|
|
|
|
binding.addCommentWriteReply.requestFocus();
|
|
|
|
binding.addCommentWriteReply.setSelection( binding.addCommentWriteReply.getText().length());
|
|
|
|
} else {
|
|
|
|
if( sepiaSearch) {
|
|
|
|
Toasty.info(PeertubeActivity.this, getString(R.string.federation_issue), Toasty.LENGTH_SHORT).show();
|
|
|
|
}else {
|
|
|
|
Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
binding.send.setOnClickListener(v -> {
|
2020-10-09 18:22:05 +02:00
|
|
|
if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
|
2020-10-15 15:16:41 +02:00
|
|
|
String comment = binding.addCommentWrite.getText().toString();
|
2020-06-27 19:08:52 +02:00
|
|
|
if (comment.trim().length() > 0) {
|
2020-10-08 18:13:04 +02:00
|
|
|
PostActionsVM viewModelComment = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
|
|
|
viewModelComment.comment(ADD_COMMENT, peertube.getId(), null, comment).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(ADD_COMMENT, apiResponse1));
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.addCommentWrite.setText("");
|
|
|
|
binding.addCommentRead.setVisibility(View.VISIBLE);
|
|
|
|
binding.addCommentWrite.setVisibility(View.GONE);
|
|
|
|
binding.sendReply.setVisibility(View.GONE);
|
|
|
|
binding.addCommentRead.requestFocus();
|
2020-06-27 11:21:25 +02:00
|
|
|
}
|
2020-06-27 19:08:52 +02:00
|
|
|
} else {
|
2020-10-13 11:04:35 +02:00
|
|
|
if( sepiaSearch) {
|
|
|
|
Toasty.info(PeertubeActivity.this, getString(R.string.federation_issue), Toasty.LENGTH_SHORT).show();
|
|
|
|
}else {
|
|
|
|
Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2020-06-27 19:08:52 +02:00
|
|
|
}
|
|
|
|
});
|
2020-06-27 11:21:25 +02:00
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.peertubePlaylist.setOnClickListener(v -> {
|
2020-10-08 18:13:04 +02:00
|
|
|
PlaylistsVM viewModelOwnerPlaylist = new ViewModelProvider(PeertubeActivity.this).get(PlaylistsVM.class);
|
|
|
|
viewModelOwnerPlaylist.manage(PlaylistsVM.action.GET_PLAYLISTS, null, null).observe(PeertubeActivity.this, this::manageVIewPlaylists);
|
2020-06-26 08:50:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (peertube.isCommentsEnabled()) {
|
2020-09-07 16:57:00 +02:00
|
|
|
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
|
2020-10-09 18:22:05 +02:00
|
|
|
commentViewModel.getThread(sepiaSearch?peertubeInstance:null, videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment);
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.writeCommentContainer.setVisibility(View.VISIBLE);
|
2020-06-26 08:50:49 +02:00
|
|
|
|
|
|
|
} else {
|
2020-10-01 17:42:03 +02:00
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
|
|
|
|
binding.noActionText.setText(getString(R.string.comment_no_allowed_peertube));
|
|
|
|
binding.noAction.setVisibility(View.VISIBLE);
|
|
|
|
binding.writeCommentContainer.setVisibility(View.GONE);
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
2020-06-27 11:21:25 +02:00
|
|
|
setTitle(peertube.getName());
|
2020-10-13 18:11:53 +02:00
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.peertubeDescription.setText(peertube.getDescription());
|
2020-10-13 18:11:53 +02:00
|
|
|
|
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.peertubeTitle.setText(peertube.getName());
|
|
|
|
binding.peertubeDislikeCount.setText(String.valueOf(peertube.getDislikes()));
|
|
|
|
binding.peertubeLikeCount.setText(String.valueOf(peertube.getLikes()));
|
|
|
|
binding.peertubeViewCount.setText(String.valueOf(peertube.getViews()));
|
2020-06-26 08:50:49 +02:00
|
|
|
video_id = peertube.getId();
|
|
|
|
|
|
|
|
changeColor();
|
|
|
|
initResolution();
|
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.peertubeLikeCount.setOnClickListener(v -> {
|
2020-10-09 18:22:05 +02:00
|
|
|
if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
|
2020-06-27 11:21:25 +02:00
|
|
|
String newState = peertube.getMyRating().equals("like") ? "none" : "like";
|
2020-10-08 18:13:04 +02:00
|
|
|
PostActionsVM viewModelLike = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
|
|
|
viewModelLike.post(RATEVIDEO, peertube.getId(), newState).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(RATEVIDEO, apiResponse1));
|
2020-06-27 11:21:25 +02:00
|
|
|
peertube.setMyRating(newState);
|
2020-10-15 15:16:41 +02:00
|
|
|
int count = Integer.parseInt(binding.peertubeLikeCount.getText().toString());
|
2020-06-30 13:33:43 +02:00
|
|
|
if (newState.compareTo("none") == 0) {
|
2020-06-29 17:59:36 +02:00
|
|
|
count--;
|
2020-06-30 13:33:43 +02:00
|
|
|
if (count - 1 < 0) {
|
2020-06-29 17:59:36 +02:00
|
|
|
count = 0;
|
|
|
|
}
|
2020-06-30 13:33:43 +02:00
|
|
|
} else {
|
2020-06-29 17:59:36 +02:00
|
|
|
count++;
|
|
|
|
}
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.peertubeLikeCount.setText(String.valueOf(count));
|
2020-06-27 11:21:25 +02:00
|
|
|
changeColor();
|
2020-06-27 19:08:52 +02:00
|
|
|
} else {
|
2020-10-13 11:04:35 +02:00
|
|
|
if( sepiaSearch) {
|
|
|
|
Toasty.info(PeertubeActivity.this, getString(R.string.federation_issue), Toasty.LENGTH_SHORT).show();
|
|
|
|
}else {
|
|
|
|
Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2020-06-27 11:21:25 +02:00
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
});
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.peertubeDislikeCount.setOnClickListener(v -> {
|
2020-10-09 18:22:05 +02:00
|
|
|
if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
|
2020-06-27 11:21:25 +02:00
|
|
|
String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike";
|
2020-10-08 18:13:04 +02:00
|
|
|
PostActionsVM viewModelLike = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
|
|
|
viewModelLike.post(RATEVIDEO, peertube.getId(), newState).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(RATEVIDEO, apiResponse1));
|
2020-06-27 11:21:25 +02:00
|
|
|
peertube.setMyRating(newState);
|
2020-10-15 15:16:41 +02:00
|
|
|
int count = Integer.parseInt(binding.peertubeDislikeCount.getText().toString());
|
2020-06-30 13:33:43 +02:00
|
|
|
if (newState.compareTo("none") == 0) {
|
2020-06-29 17:59:36 +02:00
|
|
|
count--;
|
2020-06-30 13:33:43 +02:00
|
|
|
if (count - 1 < 0) {
|
2020-06-29 17:59:36 +02:00
|
|
|
count = 0;
|
|
|
|
}
|
2020-06-30 13:33:43 +02:00
|
|
|
} else {
|
2020-06-29 17:59:36 +02:00
|
|
|
count++;
|
|
|
|
}
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.peertubeDislikeCount.setText(String.valueOf(count));
|
2020-06-27 11:21:25 +02:00
|
|
|
changeColor();
|
2020-06-27 19:08:52 +02:00
|
|
|
} else {
|
2020-10-13 11:04:35 +02:00
|
|
|
if( sepiaSearch) {
|
|
|
|
Toasty.info(PeertubeActivity.this, getString(R.string.federation_issue), Toasty.LENGTH_SHORT).show();
|
|
|
|
}else {
|
|
|
|
Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2020-06-27 11:21:25 +02:00
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
});
|
2020-06-27 11:21:25 +02:00
|
|
|
|
2020-09-26 10:22:11 +02:00
|
|
|
|
2020-09-03 19:08:53 +02:00
|
|
|
if (mode == Helper.VIDEO_MODE_NORMAL) {
|
2020-06-26 08:50:49 +02:00
|
|
|
|
|
|
|
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
|
|
|
ProgressiveMediaSource videoSource;
|
|
|
|
|
|
|
|
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this);
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.mediaVideo.setPlayer(player);
|
|
|
|
binding.loader.setVisibility(View.GONE);
|
2020-10-06 17:11:25 +02:00
|
|
|
|
2020-10-06 18:49:15 +02:00
|
|
|
if (apiResponse.getPeertubes().get(0).getFiles() != null && apiResponse.getPeertubes().get(0).getFiles().size() > 0) {
|
2020-10-06 17:11:25 +02:00
|
|
|
if (video_cache == 0) {
|
|
|
|
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
|
|
|
|
Util.getUserAgent(PeertubeActivity.this, null), null);
|
|
|
|
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
|
|
|
|
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
|
|
|
|
} else {
|
|
|
|
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
|
|
|
|
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
|
|
|
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
|
|
|
|
}
|
|
|
|
player.prepare(videoSource);
|
2020-10-06 18:49:15 +02:00
|
|
|
} else {
|
2020-10-06 17:11:25 +02:00
|
|
|
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);
|
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
player.setPlayWhenReady(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.moreActions.setOnClickListener(view -> {
|
|
|
|
PopupMenu popup = new PopupMenu(PeertubeActivity.this, binding.moreActions);
|
2020-09-20 11:07:28 +02:00
|
|
|
popup.getMenuInflater()
|
|
|
|
.inflate(R.menu.main_video, popup.getMenu());
|
|
|
|
|
|
|
|
if (captions == null) {
|
|
|
|
popup.getMenu().findItem(R.id.action_captions).setEnabled(false);
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
2020-09-20 11:07:28 +02:00
|
|
|
popup.setOnMenuItemClickListener(item -> {
|
2020-10-14 10:31:02 +02:00
|
|
|
int itemId = item.getItemId();
|
|
|
|
if (itemId == R.id.action_download) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
|
|
if (ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
ActivityCompat.requestPermissions(PeertubeActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
|
2020-09-20 11:07:28 +02:00
|
|
|
} else {
|
2020-09-25 18:58:04 +02:00
|
|
|
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null));
|
2020-09-20 11:07:28 +02:00
|
|
|
}
|
2020-10-14 10:31:02 +02:00
|
|
|
} else {
|
|
|
|
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null));
|
|
|
|
}
|
|
|
|
} else if (itemId == R.id.action_share) {
|
|
|
|
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.shared_via));
|
|
|
|
String url;
|
|
|
|
|
|
|
|
url = peertube.getFiles().get(0).getFileDownloadUrl();
|
|
|
|
boolean share_details = sharedpreferences.getBoolean(Helper.SET_SHARE_DETAILS, true);
|
|
|
|
String extra_text;
|
|
|
|
if (share_details) {
|
|
|
|
extra_text = "@" + peertube.getAccount().getAcct();
|
|
|
|
extra_text += "\r\n\r\n" + peertube.getName();
|
|
|
|
extra_text += "\n\n\uD83D\uDD17 " + url + "\r\n-\n";
|
|
|
|
final String contentToot;
|
|
|
|
if (peertube.getDescription() != null) {
|
2020-09-20 11:07:28 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
|
|
|
contentToot = Html.fromHtml(peertube.getDescription(), Html.FROM_HTML_MODE_LEGACY).toString();
|
|
|
|
else
|
|
|
|
contentToot = Html.fromHtml(peertube.getDescription()).toString();
|
|
|
|
} else {
|
2020-10-14 10:31:02 +02:00
|
|
|
contentToot = "";
|
2020-09-20 11:07:28 +02:00
|
|
|
}
|
2020-10-14 10:31:02 +02:00
|
|
|
extra_text += contentToot;
|
|
|
|
} else {
|
|
|
|
extra_text = url;
|
|
|
|
}
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text);
|
|
|
|
sendIntent.setType("text/plain");
|
|
|
|
startActivity(Intent.createChooser(sendIntent, getString(R.string.share_with)));
|
|
|
|
} else if (itemId == R.id.action_captions) {
|
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PeertubeActivity.this);
|
|
|
|
if (captions == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
String[] itemsKeyLanguage = new String[captions.size() + 1];
|
|
|
|
String[] itemsLabelLanguage = new String[captions.size() + 1];
|
|
|
|
itemsLabelLanguage[0] = getString(R.string.none);
|
|
|
|
itemsKeyLanguage[0] = "null";
|
|
|
|
int i = 1;
|
|
|
|
if (captions.size() > 0) {
|
|
|
|
for (Caption caption : captions) {
|
|
|
|
ItemStr lang = caption.getLanguage();
|
|
|
|
itemsLabelLanguage[i] = lang.getLabel();
|
|
|
|
itemsKeyLanguage[i] = lang.getId();
|
|
|
|
i++;
|
2020-09-20 11:07:28 +02:00
|
|
|
}
|
2020-10-14 10:31:02 +02:00
|
|
|
}
|
|
|
|
dialogBuilder.setSingleChoiceItems(itemsLabelLanguage, i, (dialog, which) -> {
|
2020-09-20 11:07:28 +02:00
|
|
|
|
2020-10-14 10:31:02 +02:00
|
|
|
Uri uri = null;
|
|
|
|
if (which > 0) {
|
|
|
|
if (!sepiaSearch) {
|
|
|
|
uri = Uri.parse("https://" + getLiveInstance(PeertubeActivity.this) + captions.get(which - 1).getCaptionPath());
|
|
|
|
} else {
|
|
|
|
uri = Uri.parse("https://" + peertubeInstance + captions.get(which - 1).getCaptionPath());
|
2020-09-20 11:07:28 +02:00
|
|
|
}
|
|
|
|
}
|
2020-09-20 12:16:10 +02:00
|
|
|
|
2020-10-14 10:31:02 +02:00
|
|
|
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
2020-09-20 12:16:10 +02:00
|
|
|
|
2020-10-14 10:31:02 +02:00
|
|
|
long position = player.getCurrentPosition();
|
2020-09-20 12:06:38 +02:00
|
|
|
|
2020-10-14 10:31:02 +02:00
|
|
|
if (player != null)
|
|
|
|
player.release();
|
2020-09-20 11:07:28 +02:00
|
|
|
|
2020-10-14 10:31:02 +02:00
|
|
|
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory());
|
|
|
|
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this, trackSelector);
|
|
|
|
ProgressiveMediaSource videoSource;
|
|
|
|
MediaSource subtitleSource = null;
|
|
|
|
Format subtitleFormat = Format.createTextSampleFormat(
|
|
|
|
null,
|
|
|
|
MimeTypes.TEXT_VTT,
|
|
|
|
Format.NO_VALUE,
|
|
|
|
itemsKeyLanguage[which]);
|
2020-09-20 11:07:28 +02:00
|
|
|
|
|
|
|
|
2020-10-14 10:31:02 +02:00
|
|
|
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);
|
|
|
|
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
|
|
|
|
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
|
|
|
|
if (uri != null)
|
|
|
|
subtitleSource = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(uri, subtitleFormat, C.TIME_UNSET);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
|
|
|
|
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
|
|
|
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
|
|
|
|
if (uri != null)
|
|
|
|
subtitleSource = new SingleSampleMediaSource.Factory(cacheDataSourceFactory).createMediaSource(uri, subtitleFormat, C.TIME_UNSET);
|
|
|
|
}
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.mediaVideo.setPlayer(player);
|
2020-10-14 10:31:02 +02:00
|
|
|
if (which > 0 && subtitleSource != null) {
|
|
|
|
MergingMediaSource mergedSource =
|
|
|
|
new MergingMediaSource(videoSource, subtitleSource);
|
|
|
|
player.prepare(mergedSource);
|
|
|
|
} else {
|
|
|
|
player.prepare(videoSource);
|
|
|
|
}
|
|
|
|
player.seekTo(0, position);
|
|
|
|
player.setPlayWhenReady(true);
|
|
|
|
}
|
2020-09-20 11:07:28 +02:00
|
|
|
|
2020-10-13 17:50:52 +02:00
|
|
|
|
2020-10-14 10:31:02 +02:00
|
|
|
dialog.dismiss();
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogBuilder.setOnDismissListener(dialogInterface -> {
|
|
|
|
|
|
|
|
});
|
|
|
|
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
|
|
|
|
|
|
|
AlertDialog alertDialog = dialogBuilder.create();
|
|
|
|
alertDialog.setTitle(getString(R.string.pickup_captions));
|
|
|
|
alertDialog.show();
|
|
|
|
} else if (itemId == R.id.action_report) {
|
|
|
|
AlertDialog alertDialog;
|
|
|
|
AlertDialog.Builder dialogBuilder;
|
|
|
|
dialogBuilder = new AlertDialog.Builder(PeertubeActivity.this);
|
|
|
|
LayoutInflater inflater1 = getLayoutInflater();
|
|
|
|
View dialogView = inflater1.inflate(R.layout.popup_report_choice, new LinearLayout(PeertubeActivity.this), false);
|
|
|
|
dialogBuilder.setView(dialogView);
|
2020-10-15 15:16:41 +02:00
|
|
|
|
2020-10-14 10:31:02 +02:00
|
|
|
dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
|
|
|
alertDialog = dialogBuilder.create();
|
|
|
|
alertDialog.show();
|
2020-10-15 15:16:41 +02:00
|
|
|
dialogView.findViewById(R.id.report_video).setOnClickListener(v -> reportAlert(REPORT_VIDEO, alertDialog));
|
|
|
|
dialogView.findViewById(R.id.report_account).setOnClickListener(v -> reportAlert(REPORT_ACCOUNT, alertDialog));
|
2020-09-20 11:07:28 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
popup.show();
|
2020-06-26 08:50:49 +02:00
|
|
|
});
|
2020-09-20 11:07:28 +02:00
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(@NotNull Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
if (mode != Helper.VIDEO_MODE_WEBVIEW) {
|
|
|
|
openFullscreenDialog();
|
|
|
|
}
|
|
|
|
setFullscreen(FullScreenMediaController.fullscreen.ON);
|
|
|
|
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
|
|
if (mode != Helper.VIDEO_MODE_WEBVIEW) {
|
|
|
|
closeFullscreenDialog();
|
|
|
|
}
|
|
|
|
setFullscreen(FullScreenMediaController.fullscreen.OFF);
|
|
|
|
}
|
|
|
|
change();
|
|
|
|
}
|
|
|
|
|
2020-09-20 12:06:38 +02:00
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
2020-10-15 15:16:41 +02:00
|
|
|
binding = null;
|
2020-09-19 14:56:10 +02:00
|
|
|
if (player != null) {
|
|
|
|
player.setPlayWhenReady(false);
|
2020-06-26 08:50:49 +02:00
|
|
|
player.release();
|
2020-09-19 14:56:10 +02:00
|
|
|
}
|
2020-09-19 15:06:24 +02:00
|
|
|
if (fullScreenDialog != null && fullScreenDialog.isShowing()) {
|
|
|
|
fullScreenDialog.dismiss();
|
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
2020-09-19 14:56:10 +02:00
|
|
|
if (player != null && !playInMinimized) {
|
2020-06-26 08:50:49 +02:00
|
|
|
player.setPlayWhenReady(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-19 14:56:10 +02:00
|
|
|
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
|
|
@Override
|
|
|
|
public void onUserLeaveHint() {
|
2020-09-19 16:50:20 +02:00
|
|
|
enterVideoMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void enterVideoMode() {
|
2020-09-19 18:22:44 +02:00
|
|
|
if (playInMinimized && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && player != null) {
|
2020-09-19 18:19:59 +02:00
|
|
|
MediaSessionCompat mediaSession = new MediaSessionCompat(this, getPackageName());
|
|
|
|
MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(mediaSession);
|
|
|
|
mediaSessionConnector.setPlayer(player);
|
2020-10-15 15:16:41 +02:00
|
|
|
PlayerControlView controlView = binding.mediaVideo.findViewById(R.id.exo_controller);
|
2020-10-13 16:35:51 +02:00
|
|
|
controlView.hide();
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.mediaVideo.setControllerAutoShow(false);
|
2020-09-19 18:19:59 +02:00
|
|
|
mediaSession.setActive(true);
|
2020-09-19 14:56:10 +02:00
|
|
|
enterPictureInPictureMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-19 16:50:20 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2020-09-19 18:22:44 +02:00
|
|
|
if (playInMinimized && player != null) {
|
2020-09-19 16:50:20 +02:00
|
|
|
enterVideoMode();
|
|
|
|
} else {
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-19 14:56:10 +02:00
|
|
|
@Override
|
|
|
|
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
|
|
|
|
if (isInPictureInPictureMode) {
|
|
|
|
setFullscreen(FullScreenMediaController.fullscreen.ON);
|
|
|
|
} else {
|
|
|
|
setFullscreen(FullScreenMediaController.fullscreen.OFF);
|
|
|
|
if (onStopCalled) {
|
2020-09-20 15:14:48 +02:00
|
|
|
finishAndRemoveTask();
|
2020-09-19 14:56:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
onStopCalled = true;
|
|
|
|
}
|
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2020-09-19 14:56:10 +02:00
|
|
|
onStopCalled = false;
|
|
|
|
if (player != null && !playInMinimized) {
|
2020-06-26 08:50:49 +02:00
|
|
|
player.setPlayWhenReady(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void displayResolution() {
|
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
2020-06-26 14:34:39 +02:00
|
|
|
|
|
|
|
AlertDialog.Builder builderSingle = new AlertDialog.Builder(PeertubeActivity.this);
|
2020-06-26 08:50:49 +02:00
|
|
|
builderSingle.setTitle(R.string.pickup_resolution);
|
|
|
|
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(PeertubeActivity.this, android.R.layout.select_dialog_item);
|
2020-09-25 18:58:04 +02:00
|
|
|
for (File file : peertube.getFiles()) {
|
|
|
|
if (file.getResolutions() != null) {
|
2020-10-03 18:37:34 +02:00
|
|
|
if (file.getResolutions().getLabel().compareTo("0p") != 0) {
|
2020-10-02 07:03:36 +02:00
|
|
|
arrayAdapter.add(file.getResolutions().getLabel());
|
|
|
|
}
|
2020-09-25 18:58:04 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
builderSingle.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
|
|
|
builderSingle.setAdapter(arrayAdapter, (dialog, which) -> {
|
|
|
|
String res = Objects.requireNonNull(arrayAdapter.getItem(which)).substring(0, Objects.requireNonNull(arrayAdapter.getItem(which)).length() - 1);
|
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
if (binding.mediaVideo != null) {
|
|
|
|
binding.loader.setVisibility(View.VISIBLE);
|
2020-06-26 08:50:49 +02:00
|
|
|
long position = player.getCurrentPosition();
|
2020-10-15 15:16:41 +02:00
|
|
|
PlayerControlView controlView = binding.mediaVideo.findViewById(R.id.exo_controller);
|
|
|
|
TextView resolution = controlView.findViewById(R.id.resolution);
|
2020-06-26 08:50:49 +02:00
|
|
|
resolution.setText(String.format("%sp", res));
|
2020-09-03 19:08:53 +02:00
|
|
|
if (mode == Helper.VIDEO_MODE_NORMAL) {
|
2020-06-26 08:50:49 +02:00
|
|
|
if (player != null)
|
|
|
|
player.release();
|
|
|
|
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this);
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.mediaVideo.setPlayer(player);
|
|
|
|
binding.loader.setVisibility(View.GONE);
|
2020-06-26 08:50:49 +02:00
|
|
|
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
|
|
|
ProgressiveMediaSource videoSource;
|
|
|
|
if (video_cache == 0) {
|
|
|
|
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
|
2020-06-30 12:00:55 +02:00
|
|
|
Util.getUserAgent(PeertubeActivity.this, null), null);
|
2020-06-26 08:50:49 +02:00
|
|
|
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
|
2020-09-03 19:08:53 +02:00
|
|
|
.createMediaSource(Uri.parse(peertube.getFileUrl(res, PeertubeActivity.this)));
|
2020-06-26 08:50:49 +02:00
|
|
|
} else {
|
|
|
|
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
|
|
|
|
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
2020-09-03 19:08:53 +02:00
|
|
|
.createMediaSource(Uri.parse(peertube.getFileUrl(res, PeertubeActivity.this)));
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
player.prepare(videoSource);
|
|
|
|
player.seekTo(0, position);
|
|
|
|
player.setPlayWhenReady(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
builderSingle.show();
|
|
|
|
}
|
|
|
|
|
2020-09-19 16:50:20 +02:00
|
|
|
@SuppressWarnings({"unused", "RedundantSuppression"})
|
2020-09-26 10:22:11 +02:00
|
|
|
public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, APIResponse apiResponse) {
|
2020-09-07 16:57:00 +02:00
|
|
|
|
2020-09-26 16:46:51 +02:00
|
|
|
if (peertube.isCommentsEnabled() && statusAction == ADD_COMMENT) {
|
2020-10-14 16:06:17 +02:00
|
|
|
if( apiResponse.getComments() != null && apiResponse.getComments().size() > 0 ) {
|
|
|
|
comments.add(0, apiResponse.getComments().get(0));
|
|
|
|
commentListAdapter.notifyItemInserted(0);
|
|
|
|
}
|
2020-09-26 10:22:11 +02:00
|
|
|
} else if (statusAction == RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT) {
|
2020-07-21 18:49:13 +02:00
|
|
|
Toasty.success(PeertubeActivity.this, getString(R.string.successful_report), Toasty.LENGTH_LONG).show();
|
2020-09-26 10:22:11 +02:00
|
|
|
} else if (statusAction == RetrofitPeertubeAPI.ActionType.REPORT_VIDEO) {
|
2020-07-21 18:49:13 +02:00
|
|
|
Toasty.success(PeertubeActivity.this, getString(R.string.successful_video_report), Toasty.LENGTH_LONG).show();
|
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initFullscreenDialog() {
|
|
|
|
|
|
|
|
fullScreenDialog = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen) {
|
|
|
|
public void onBackPressed() {
|
2020-10-02 15:14:08 +02:00
|
|
|
if (fullScreenMode) {
|
2020-06-26 08:50:49 +02:00
|
|
|
closeFullscreenDialog();
|
2020-10-02 15:14:08 +02:00
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private void openFullscreenDialog() {
|
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
((ViewGroup) binding.mediaVideo.getParent()).removeView(binding.mediaVideo);
|
|
|
|
fullScreenDialog.addContentView(binding.mediaVideo, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
2020-06-26 14:34:39 +02:00
|
|
|
fullScreenIcon.setImageDrawable(ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_fullscreen_exit_24));
|
2020-06-26 08:50:49 +02:00
|
|
|
fullScreenMode = true;
|
2020-09-19 15:06:24 +02:00
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
fullScreenDialog.show();
|
|
|
|
}
|
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
public void openCommentThread(Comment comment){
|
|
|
|
|
|
|
|
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
|
|
|
|
binding.peertubeReply.setVisibility(View.GONE);
|
|
|
|
commentViewModel.getRepliesComment(videoUuid, comment.getId()).observe(PeertubeActivity.this, this::manageVIewCommentReply);
|
|
|
|
|
|
|
|
Account account = comment.getAccount();
|
|
|
|
Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, binding.commentAccountProfile);
|
|
|
|
binding.commentAccountDisplayname.setText(account.getDisplayName());
|
|
|
|
binding.commentAccountUsername.setText(account.getAcct());
|
|
|
|
Spanned commentSpan;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
|
|
|
commentSpan = Html.fromHtml(comment.getText(), Html.FROM_HTML_MODE_COMPACT);
|
|
|
|
else
|
|
|
|
commentSpan = Html.fromHtml(comment.getText());
|
|
|
|
binding.commentContent.setText(commentSpan);
|
|
|
|
binding.commentDate.setText(Helper.dateDiff(PeertubeActivity.this, comment.getCreatedAt()));
|
|
|
|
binding.replyThread.setVisibility(View.VISIBLE);
|
|
|
|
TranslateAnimation animate = new TranslateAnimation(
|
|
|
|
binding.peertubeInformationContainer.getWidth(),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
animate.setAnimationListener(new Animation.AnimationListener() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Animation animation) {}
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animation animation) {
|
|
|
|
binding.peertubeInformationContainer.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onAnimationRepeat(Animation animation) {}
|
|
|
|
});
|
|
|
|
animate.setDuration(500);
|
|
|
|
binding.replyThread.startAnimation(animate);
|
|
|
|
binding.sendReply.setOnClickListener(null);
|
|
|
|
binding.sendReply.setOnClickListener(v -> {
|
|
|
|
if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
|
|
|
|
String commentView = binding.addCommentWriteReply.getText().toString();
|
|
|
|
if (commentView.trim().length() > 0) {
|
|
|
|
PostActionsVM viewModelComment = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
|
|
|
viewModelComment.comment(REPLY, peertube.getId(), comment.getId(), commentView).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(ADD_COMMENT, apiResponse1));
|
|
|
|
binding.addCommentWriteReply.setText("");
|
|
|
|
binding.addCommentReadReply.setVisibility(View.VISIBLE);
|
|
|
|
binding.addCommentWriteReply.setVisibility(View.GONE);
|
|
|
|
binding.sendReply.setVisibility(View.GONE);
|
|
|
|
binding.addCommentReadReply.requestFocus();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if( sepiaSearch) {
|
|
|
|
Toasty.info(PeertubeActivity.this, getString(R.string.federation_issue), Toasty.LENGTH_SHORT).show();
|
|
|
|
}else {
|
|
|
|
Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void closeCommentThread(){
|
|
|
|
binding.peertubeInformationContainer.setVisibility(View.VISIBLE);
|
|
|
|
TranslateAnimation animate = new TranslateAnimation(
|
|
|
|
0,
|
|
|
|
binding.replyThread.getWidth(),
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
animate.setAnimationListener(new Animation.AnimationListener() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Animation animation) {}
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animation animation) {
|
|
|
|
binding.replyThread.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onAnimationRepeat(Animation animation) {}
|
|
|
|
});
|
|
|
|
animate.setDuration(500);
|
|
|
|
binding.replyThread.startAnimation(animate);
|
|
|
|
}
|
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
private void closeFullscreenDialog() {
|
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
((ViewGroup) binding.mediaVideo.getParent()).removeView(binding.mediaVideo);
|
|
|
|
((FrameLayout) findViewById(R.id.main_media_frame)).addView(binding.mediaVideo);
|
2020-06-26 08:50:49 +02:00
|
|
|
fullScreenMode = false;
|
|
|
|
fullScreenDialog.dismiss();
|
2020-06-26 14:34:39 +02:00
|
|
|
fullScreenIcon.setImageDrawable(ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_fullscreen_24));
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initFullscreenButton() {
|
|
|
|
|
2020-10-15 15:16:41 +02:00
|
|
|
PlayerControlView controlView = binding.mediaVideo.findViewById(R.id.exo_controller);
|
2020-06-26 08:50:49 +02:00
|
|
|
fullScreenIcon = controlView.findViewById(R.id.exo_fullscreen_icon);
|
|
|
|
View fullScreenButton = controlView.findViewById(R.id.exo_fullscreen_button);
|
|
|
|
fullScreenButton.setOnClickListener(v -> {
|
2020-10-02 15:14:08 +02:00
|
|
|
if (!fullScreenMode) {
|
2020-06-26 08:50:49 +02:00
|
|
|
openFullscreenDialog();
|
2020-10-03 18:37:34 +02:00
|
|
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
|
|
} else {
|
2020-06-26 08:50:49 +02:00
|
|
|
closeFullscreenDialog();
|
2020-10-03 18:37:34 +02:00
|
|
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
2020-10-02 15:23:36 +02:00
|
|
|
Handler handler = new Handler();
|
|
|
|
handler.postDelayed(() -> setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR), 2000);
|
|
|
|
|
2020-10-02 15:14:08 +02:00
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initResolution() {
|
2020-10-15 15:16:41 +02:00
|
|
|
PlayerControlView controlView = binding.mediaVideo.findViewById(R.id.exo_controller);
|
|
|
|
TextView resolution = controlView.findViewById(R.id.resolution);
|
2020-10-06 18:49:15 +02:00
|
|
|
if (peertube.getFiles() != null && peertube.getFiles().size() > 0) {
|
2020-10-06 17:11:25 +02:00
|
|
|
resolution.setText(String.format("%s", Helper.defaultFile(PeertubeActivity.this, peertube.getFiles()).getResolutions().getLabel()));
|
|
|
|
resolution.setOnClickListener(v -> displayResolution());
|
2020-10-06 18:49:15 +02:00
|
|
|
} else {
|
2020-10-06 17:11:25 +02:00
|
|
|
resolution.setVisibility(View.GONE);
|
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void changeColor() {
|
2020-06-29 17:59:36 +02:00
|
|
|
|
|
|
|
Drawable thumbUp = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_thumb_up_alt_24);
|
|
|
|
Drawable thumbDown = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_thumb_down_alt_24);
|
|
|
|
int color = getAttColor(this, android.R.attr.colorControlNormal);
|
|
|
|
|
2020-06-30 13:33:43 +02:00
|
|
|
if (thumbUp != null) {
|
2020-06-29 17:59:36 +02:00
|
|
|
thumbUp.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
|
|
|
DrawableCompat.setTint(thumbUp, color);
|
|
|
|
}
|
2020-06-30 13:33:43 +02:00
|
|
|
if (thumbDown != null) {
|
2020-06-29 17:59:36 +02:00
|
|
|
thumbDown.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
|
|
|
DrawableCompat.setTint(thumbDown, color);
|
|
|
|
}
|
|
|
|
if (peertube.getMyRating() != null && peertube.getMyRating().compareTo("like") == 0) {
|
2020-06-30 13:33:43 +02:00
|
|
|
if (thumbUp != null) {
|
2020-06-29 17:59:36 +02:00
|
|
|
thumbUp.setColorFilter(getResources().getColor(R.color.positive_thumbs), PorterDuff.Mode.SRC_ATOP);
|
|
|
|
DrawableCompat.setTint(thumbUp, getResources().getColor(R.color.positive_thumbs));
|
|
|
|
}
|
2020-06-30 13:33:43 +02:00
|
|
|
} else if (peertube.getMyRating() != null && peertube.getMyRating().compareTo("dislike") == 0) {
|
|
|
|
if (thumbDown != null) {
|
2020-06-29 17:59:36 +02:00
|
|
|
thumbDown.setColorFilter(getResources().getColor(R.color.negative_thumbs), PorterDuff.Mode.SRC_ATOP);
|
|
|
|
DrawableCompat.setTint(thumbDown, getResources().getColor(R.color.negative_thumbs));
|
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.peertubeLikeCount.setCompoundDrawablesWithIntrinsicBounds(null, thumbUp, null, null);
|
|
|
|
binding.peertubeDislikeCount.setCompoundDrawablesWithIntrinsicBounds(null, thumbDown, null, null);
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 18:13:04 +02:00
|
|
|
public void manageVIewPlaylists(APIResponse apiResponse) {
|
|
|
|
if (apiResponse.getError() != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
|
|
|
|
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(PeertubeActivity.this);
|
|
|
|
builder.setTitle(R.string.modify_playlists);
|
|
|
|
|
|
|
|
List<PlaylistData.Playlist> ownerPlaylists = apiResponse.getPlaylists();
|
|
|
|
if( ownerPlaylists == null){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String[] label = new String[ownerPlaylists.size()];
|
|
|
|
boolean[] checked = new boolean[ownerPlaylists.size()];
|
|
|
|
int i = 0;
|
|
|
|
List<PlaylistExist> playlistsForVideo = playlists.get(peertube.getId());
|
|
|
|
|
|
|
|
|
|
|
|
for (PlaylistData.Playlist playlist : ownerPlaylists) {
|
|
|
|
checked[i] = false;
|
|
|
|
if (playlistsForVideo != null) {
|
|
|
|
for (PlaylistExist playlistExist : playlistsForVideo) {
|
|
|
|
if (playlistExist != null && playlistExist.getPlaylistId().compareTo(playlist.getId()) == 0) {
|
|
|
|
checked[i] = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
label[i] = playlist.getDisplayName();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.setMultiChoiceItems(label, checked, (dialog, which, isChecked) -> {
|
|
|
|
PlaylistsVM playlistsViewModel = new ViewModelProvider(PeertubeActivity.this).get(PlaylistsVM.class);
|
|
|
|
if (isChecked) { //Add to playlist
|
|
|
|
playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, ownerPlaylists.get(which), peertube.getUuid()).observe(PeertubeActivity.this, apiResponse3 -> addElement(ownerPlaylists.get(which).getId(), peertube.getId(), apiResponse3));
|
|
|
|
} else { //Remove from playlist
|
|
|
|
String elementInPlaylistId = null;
|
|
|
|
for (PlaylistExist playlistExist : peertube.getPlaylistExists()) {
|
|
|
|
if (playlistExist.getPlaylistId().compareTo(ownerPlaylists.get(which).getId()) == 0) {
|
|
|
|
elementInPlaylistId = playlistExist.getPlaylistElementId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, ownerPlaylists.get(which), elementInPlaylistId);
|
|
|
|
playlists.remove(peertube.getId());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss());
|
|
|
|
androidx.appcompat.app.AlertDialog dialog = builder.create();
|
|
|
|
dialog.show();
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
}
|
2020-10-08 18:13:04 +02:00
|
|
|
public void manageVIewPlaylist(APIResponse apiResponse) {
|
|
|
|
if (apiResponse.getError() != null || apiResponse.getVideoExistPlaylist() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (playlists == null) {
|
|
|
|
playlists = new HashMap<>();
|
|
|
|
}
|
|
|
|
playlists.putAll(apiResponse.getVideoExistPlaylist());
|
|
|
|
peertube.setPlaylistExists(playlists.get(peertube.getId()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
|
2020-10-08 18:13:04 +02:00
|
|
|
public void addElement(String playlistId, String videoId, APIResponse apiResponse) {
|
2020-10-06 18:49:15 +02:00
|
|
|
if (apiResponse != null && apiResponse.getActionReturn() != null) {
|
2020-10-08 18:13:04 +02:00
|
|
|
|
2020-10-06 18:49:15 +02:00
|
|
|
PlaylistExist playlistExist = new PlaylistExist();
|
|
|
|
playlistExist.setPlaylistId(playlistId);
|
|
|
|
playlistExist.setPlaylistElementId(apiResponse.getActionReturn());
|
2020-10-08 18:13:04 +02:00
|
|
|
List<PlaylistExist> playlistExistList = playlists.get(videoId);
|
|
|
|
if (playlistExistList == null) {
|
|
|
|
playlistExistList = new ArrayList<>();
|
2020-10-03 16:22:19 +02:00
|
|
|
}
|
2020-10-08 18:13:04 +02:00
|
|
|
playlistExistList.add(playlistExist);
|
|
|
|
playlists.put(videoId, playlistExistList);
|
2020-10-03 16:22:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-08 18:13:04 +02:00
|
|
|
|
2020-10-01 17:42:03 +02:00
|
|
|
@Override
|
|
|
|
public void onAllCommentRemoved() {
|
2020-10-15 15:16:41 +02:00
|
|
|
binding.noActionText.setVisibility(View.VISIBLE);
|
2020-10-01 17:42:03 +02:00
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|