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;
|
|
|
|
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-07-21 18:49:13 +02:00
|
|
|
import android.view.LayoutInflater;
|
2020-06-26 08:50:49 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
import android.widget.ArrayAdapter;
|
2020-07-21 18:49:13 +02:00
|
|
|
import android.widget.Button;
|
2020-06-26 08:50:49 +02:00
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.ScrollView;
|
|
|
|
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.AppCompatImageView;
|
|
|
|
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.ui.PlayerView;
|
|
|
|
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-03 18:37:34 +02:00
|
|
|
import java.util.Iterator;
|
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;
|
|
|
|
import app.fedilab.fedilabtube.client.data.CommentData.Comment;
|
|
|
|
import app.fedilab.fedilabtube.client.data.PlaylistData.Playlist;
|
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-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-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;
|
|
|
|
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-09-26 10:22:11 +02:00
|
|
|
import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_PLAYLISTS;
|
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-06 18:49:15 +02:00
|
|
|
private String peertubeInstance, videoId, videoUuid;
|
2020-06-26 08:50:49 +02:00
|
|
|
private FullScreenMediaController.fullscreen fullscreen;
|
|
|
|
private RelativeLayout loader;
|
2020-09-20 11:07:28 +02:00
|
|
|
private TextView peertube_view_count, peertube_playlist, peertube_bookmark, peertube_like_count, peertube_dislike_count, peertube_description, peertube_title, more_actions;
|
2020-06-26 08:50:49 +02:00
|
|
|
private ScrollView peertube_information_container;
|
2020-09-25 18:58:04 +02:00
|
|
|
private VideoData.Video peertube;
|
2020-06-26 08:50:49 +02:00
|
|
|
private PlayerView playerView;
|
|
|
|
private SimpleExoPlayer player;
|
|
|
|
private boolean fullScreenMode;
|
|
|
|
private Dialog fullScreenDialog;
|
|
|
|
private AppCompatImageView fullScreenIcon;
|
|
|
|
private TextView resolution;
|
|
|
|
private int mode;
|
|
|
|
private LinearLayout write_comment_container;
|
|
|
|
private ImageView send;
|
|
|
|
private TextView add_comment_read;
|
|
|
|
private EditText add_comment_write;
|
2020-10-06 18:49:15 +02:00
|
|
|
private List<PlaylistExist> playlistForVideo;
|
2020-06-26 08:50:49 +02:00
|
|
|
private List<Playlist> playlists;
|
2020-09-07 16:57:00 +02:00
|
|
|
private PlaylistsVM playlistsViewModel;
|
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-01 17:42:03 +02:00
|
|
|
private TextView no_action_text;
|
2020-10-02 18:22:19 +02:00
|
|
|
private String max_id;
|
2020-10-03 18:37:34 +02:00
|
|
|
private RecyclerView lv_comments;
|
2020-10-02 18:22:19 +02:00
|
|
|
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;
|
|
|
|
private CommentListAdapter commentListAdapter;
|
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);
|
|
|
|
setContentView(R.layout.activity_peertube);
|
2020-09-19 16:50:20 +02:00
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
peertube_view_count = findViewById(R.id.peertube_view_count);
|
|
|
|
peertube_bookmark = findViewById(R.id.peertube_bookmark);
|
|
|
|
peertube_like_count = findViewById(R.id.peertube_like_count);
|
|
|
|
peertube_dislike_count = findViewById(R.id.peertube_dislike_count);
|
2020-09-20 11:07:28 +02:00
|
|
|
more_actions = findViewById(R.id.more_actions);
|
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
peertube_description = findViewById(R.id.peertube_description);
|
|
|
|
peertube_title = findViewById(R.id.peertube_title);
|
|
|
|
peertube_information_container = findViewById(R.id.peertube_information_container);
|
|
|
|
add_comment_read = findViewById(R.id.add_comment_read);
|
|
|
|
add_comment_write = findViewById(R.id.add_comment_write);
|
|
|
|
peertube_playlist = findViewById(R.id.peertube_playlist);
|
|
|
|
send = findViewById(R.id.send);
|
2020-09-19 16:50:20 +02:00
|
|
|
CustomWebview webview_video = findViewById(R.id.webview_video);
|
|
|
|
playerView = findViewById(R.id.media_video);
|
|
|
|
write_comment_container = findViewById(R.id.write_comment_container);
|
|
|
|
|
2020-10-02 18:22:19 +02:00
|
|
|
max_id = "0";
|
2020-09-19 16:50:20 +02:00
|
|
|
loader = findViewById(R.id.loader);
|
|
|
|
ImageView my_pp = findViewById(R.id.my_pp);
|
|
|
|
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-03 18:37:34 +02:00
|
|
|
if (Helper.isLoggedIn(PeertubeActivity.this)) {
|
2020-10-02 15:14:08 +02:00
|
|
|
Account account = new AccountDAO(PeertubeActivity.this, db).getAccountByToken(token);
|
|
|
|
Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, my_pp);
|
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
|
|
|
|
|
2020-07-22 10:55:59 +02:00
|
|
|
if (Helper.isTablet(PeertubeActivity.this)) {
|
2020-07-09 18:08:43 +02:00
|
|
|
RelativeLayout video_container = findViewById(R.id.video_container);
|
|
|
|
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
0,
|
|
|
|
2.0f
|
|
|
|
);
|
|
|
|
video_container.setLayoutParams(param);
|
|
|
|
}
|
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);
|
|
|
|
|
|
|
|
playlistForVideo = new ArrayList<>();
|
|
|
|
playlistsViewModel = new ViewModelProvider(PeertubeActivity.this).get(PlaylistsVM.class);
|
|
|
|
if (Helper.isLoggedIn(PeertubeActivity.this)) {
|
2020-09-26 10:22:11 +02:00
|
|
|
playlistsViewModel.manage(GET_PLAYLISTS, null, null).observe(PeertubeActivity.this, apiResponse -> manageVIewPlaylists(GET_PLAYLISTS, apiResponse));
|
2020-09-19 16:50:20 +02:00
|
|
|
}
|
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-06-26 08:50:49 +02:00
|
|
|
videoId = b.getString("video_id", null);
|
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-06-26 08:50:49 +02:00
|
|
|
}
|
2020-06-27 11:21:25 +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) {
|
|
|
|
webview_video.setVisibility(View.VISIBLE);
|
|
|
|
playerView.setVisibility(View.GONE);
|
|
|
|
webview_video = Helper.initializeWebview(PeertubeActivity.this, R.id.webview_video, null);
|
|
|
|
FrameLayout webview_container = findViewById(R.id.main_media_frame);
|
|
|
|
final ViewGroup videoLayout = findViewById(R.id.videoLayout);
|
|
|
|
|
|
|
|
MastalabWebChromeClient mastalabWebChromeClient = new MastalabWebChromeClient(PeertubeActivity.this, webview_video, webview_container, videoLayout);
|
|
|
|
mastalabWebChromeClient.setOnToggledFullscreen(fullscreen -> {
|
|
|
|
|
|
|
|
if (fullscreen) {
|
|
|
|
videoLayout.setVisibility(View.VISIBLE);
|
|
|
|
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);
|
|
|
|
peertube_information_container.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);
|
|
|
|
videoLayout.setVisibility(View.GONE);
|
|
|
|
peertube_information_container.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
webview_video.getSettings().setAllowFileAccess(true);
|
|
|
|
webview_video.setWebChromeClient(mastalabWebChromeClient);
|
|
|
|
webview_video.getSettings().setDomStorageEnabled(true);
|
|
|
|
webview_video.getSettings().setAppCacheEnabled(true);
|
|
|
|
webview_video.getSettings().setMediaPlaybackRequiresUserGesture(false);
|
|
|
|
webview_video.setWebViewClient(new MastalabWebViewClient(PeertubeActivity.this));
|
2020-10-06 18:49:15 +02:00
|
|
|
webview_video.loadUrl("https://" + peertubeInstance + "/videos/embed/" + videoUuid);
|
2020-06-26 08:50:49 +02:00
|
|
|
} else {
|
|
|
|
webview_video.setVisibility(View.GONE);
|
|
|
|
playerView.setVisibility(View.VISIBLE);
|
|
|
|
loader.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode != Helper.VIDEO_MODE_WEBVIEW) {
|
|
|
|
playerView.setControllerShowTimeoutMs(1000);
|
|
|
|
playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
|
|
|
|
initFullscreenDialog();
|
|
|
|
initFullscreenButton();
|
|
|
|
}
|
2020-10-02 18:22:19 +02:00
|
|
|
flag_loading = true;
|
|
|
|
comments = new ArrayList<>();
|
|
|
|
lv_comments = findViewById(R.id.peertube_comments);
|
|
|
|
commentListAdapter = new CommentListAdapter(comments);
|
|
|
|
commentListAdapter.allCommentRemoved = PeertubeActivity.this;
|
|
|
|
LinearLayoutManager mLayoutManager = new LinearLayoutManager(PeertubeActivity.this);
|
|
|
|
lv_comments.setLayoutManager(mLayoutManager);
|
|
|
|
lv_comments.setNestedScrollingEnabled(false);
|
|
|
|
lv_comments.setAdapter(commentListAdapter);
|
|
|
|
lv_comments.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
|
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-06 18:49:15 +02:00
|
|
|
commentViewModel.getThread(videoUuid, max_id).observe(PeertubeActivity.this, apiresponse -> manageVIewComment(apiresponse));
|
2020-10-02 18:22:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-09-19 16:50:20 +02:00
|
|
|
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) {
|
|
|
|
lv_comments.setVisibility(View.VISIBLE);
|
|
|
|
commentListAdapter.notifyItemRangeInserted(oldSize, newComments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
videoId = b.getString("video_id", null);
|
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);
|
|
|
|
playerView.setPlayer(player);
|
|
|
|
loader.setVisibility(View.GONE);
|
|
|
|
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;
|
|
|
|
|
|
|
|
peertube_playlist.setVisibility(View.VISIBLE);
|
|
|
|
peertube_bookmark.setVisibility(View.GONE);
|
2020-09-25 18:58:04 +02:00
|
|
|
TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class);
|
2020-10-08 17:16:42 +02:00
|
|
|
feedsViewModel.getVideo(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-06 18:49:15 +02:00
|
|
|
captionsViewModel.getCaptions(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();
|
|
|
|
peertube_information_container.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
|
|
|
|
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
|
|
|
|
Objects.requireNonNull(getSupportActionBar()).show();
|
|
|
|
peertube_information_container.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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()) {
|
|
|
|
add_comment_read.setVisibility(View.VISIBLE);
|
|
|
|
add_comment_write.setVisibility(View.GONE);
|
|
|
|
send.setVisibility(View.GONE);
|
|
|
|
hideKeyboard(PeertubeActivity.this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.dispatchTouchEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
|
2020-07-21 18:49:13 +02:00
|
|
|
getMenuInflater().inflate(R.menu.main_peertube, menu);
|
2020-06-26 08:50:49 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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-07-22 10:55:59 +02:00
|
|
|
} else if (item.getItemId() == R.id.action_report) {
|
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_choice, new LinearLayout(PeertubeActivity.this), false);
|
|
|
|
dialogBuilder.setView(dialogView);
|
|
|
|
Button report_video = dialogView.findViewById(R.id.report_video);
|
|
|
|
Button report_account = dialogView.findViewById(R.id.report_account);
|
|
|
|
dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
|
|
|
androidx.appcompat.app.AlertDialog alertDialog = dialogBuilder.create();
|
|
|
|
alertDialog.show();
|
2020-09-26 16:46:51 +02:00
|
|
|
report_video.setOnClickListener(v -> reportAlert(REPORT_VIDEO, alertDialog));
|
|
|
|
report_account.setOnClickListener(v -> reportAlert(REPORT_ACCOUNT, alertDialog));
|
2020-07-21 18:49:13 +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);
|
|
|
|
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) -> {
|
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-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();
|
|
|
|
loader.setVisibility(View.GONE);
|
|
|
|
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();
|
|
|
|
loader.setVisibility(View.GONE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-19 16:50:20 +02:00
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
peertube = apiResponse.getPeertubes().get(0);
|
2020-10-03 16:22:19 +02:00
|
|
|
|
|
|
|
|
2020-06-27 19:08:52 +02:00
|
|
|
add_comment_read.setOnClickListener(v -> {
|
|
|
|
if (isLoggedIn(PeertubeActivity.this)) {
|
|
|
|
add_comment_read.setVisibility(View.GONE);
|
|
|
|
add_comment_write.setVisibility(View.VISIBLE);
|
|
|
|
send.setVisibility(View.VISIBLE);
|
|
|
|
add_comment_write.requestFocus();
|
|
|
|
add_comment_write.setSelection(add_comment_write.getText().length());
|
|
|
|
} 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-27 19:08:52 +02:00
|
|
|
});
|
|
|
|
send.setOnClickListener(v -> {
|
|
|
|
if (isLoggedIn(PeertubeActivity.this)) {
|
|
|
|
String comment = add_comment_write.getText().toString();
|
|
|
|
if (comment.trim().length() > 0) {
|
2020-09-07 16:57:00 +02:00
|
|
|
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
2020-09-26 16:46:51 +02:00
|
|
|
viewModel.comment(ADD_COMMENT, peertube.getId(), null, comment).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(ADD_COMMENT, apiResponse1));
|
2020-06-27 19:08:52 +02:00
|
|
|
add_comment_write.setText("");
|
|
|
|
add_comment_read.setVisibility(View.VISIBLE);
|
|
|
|
add_comment_write.setVisibility(View.GONE);
|
|
|
|
send.setVisibility(View.GONE);
|
|
|
|
add_comment_read.requestFocus();
|
2020-06-27 11:21:25 +02:00
|
|
|
}
|
2020-06-27 19:08:52 +02:00
|
|
|
} 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
|
|
|
|
|
|
|
peertube_playlist.setOnClickListener(v -> {
|
2020-10-06 18:49:15 +02:00
|
|
|
if (playlists != null && videoUuid != null) {
|
2020-06-26 08:50:49 +02:00
|
|
|
PopupMenu popup = new PopupMenu(PeertubeActivity.this, peertube_playlist);
|
|
|
|
|
|
|
|
for (Playlist playlist : playlists) {
|
|
|
|
String title = null;
|
2020-06-30 19:06:54 +02:00
|
|
|
boolean isPresent = false;
|
|
|
|
String elementId = null;
|
2020-10-06 18:49:15 +02:00
|
|
|
PlaylistExist playlistExistTarget = null;
|
|
|
|
for (PlaylistExist playlistExist : playlistForVideo) {
|
|
|
|
if (playlist.getId().compareTo(playlistExist.getPlaylistId()) == 0) {
|
2020-06-26 08:50:49 +02:00
|
|
|
title = "✔ " + playlist.getDisplayName();
|
2020-06-30 19:06:54 +02:00
|
|
|
isPresent = true;
|
2020-10-06 18:49:15 +02:00
|
|
|
playlistExistTarget = playlistExist;
|
|
|
|
elementId = playlistExist.getPlaylistElementId();
|
2020-06-26 08:50:49 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (title == null) {
|
|
|
|
title = playlist.getDisplayName();
|
|
|
|
}
|
|
|
|
MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title);
|
2020-06-30 19:06:54 +02:00
|
|
|
boolean finalIsPresent = isPresent;
|
|
|
|
String finalElementId = elementId;
|
2020-10-06 18:49:15 +02:00
|
|
|
PlaylistExist finalPlaylistExistTarget = playlistExistTarget;
|
2020-06-26 08:50:49 +02:00
|
|
|
item.setOnMenuItemClickListener(item1 -> {
|
|
|
|
item1.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
|
|
|
|
item1.setActionView(new View(PeertubeActivity.this));
|
|
|
|
item1.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemActionExpand(MenuItem item1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemActionCollapse(MenuItem item1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2020-06-30 19:06:54 +02:00
|
|
|
if (finalIsPresent) {
|
2020-06-26 08:50:49 +02:00
|
|
|
item1.setTitle(playlist.getDisplayName());
|
2020-09-26 10:22:11 +02:00
|
|
|
playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, playlist, finalElementId).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.DELETE_VIDEOS, apiResponse3));
|
2020-10-06 18:49:15 +02:00
|
|
|
playlistForVideo.remove(finalPlaylistExistTarget);
|
2020-06-26 08:50:49 +02:00
|
|
|
} else {
|
|
|
|
item1.setTitle("✔ " + playlist.getDisplayName());
|
2020-10-06 18:49:15 +02:00
|
|
|
playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, playlist, videoUuid).observe(PeertubeActivity.this, apiResponse3 -> addElement(playlist.getId(), apiResponse3));
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
popup.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-10-01 17:42:03 +02:00
|
|
|
no_action_text = findViewById(R.id.no_action_text);
|
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-06 18:49:15 +02:00
|
|
|
commentViewModel.getThread(videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment);
|
2020-06-26 08:50:49 +02:00
|
|
|
write_comment_container.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
RelativeLayout no_action = findViewById(R.id.no_action);
|
2020-10-01 17:42:03 +02:00
|
|
|
|
2020-06-26 08:50:49 +02:00
|
|
|
no_action_text.setText(getString(R.string.comment_no_allowed_peertube));
|
|
|
|
no_action.setVisibility(View.VISIBLE);
|
|
|
|
write_comment_container.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
2020-06-27 11:21:25 +02:00
|
|
|
setTitle(peertube.getName());
|
2020-06-26 08:50:49 +02:00
|
|
|
peertube_description.setText(peertube.getDescription());
|
|
|
|
peertube_title.setText(peertube.getName());
|
2020-09-25 18:58:04 +02:00
|
|
|
peertube_dislike_count.setText(String.valueOf(peertube.getDislikes()));
|
|
|
|
peertube_like_count.setText(String.valueOf(peertube.getLikes()));
|
|
|
|
peertube_view_count.setText(String.valueOf(peertube.getViews()));
|
2020-06-26 08:50:49 +02:00
|
|
|
video_id = peertube.getId();
|
|
|
|
|
|
|
|
changeColor();
|
|
|
|
initResolution();
|
|
|
|
|
|
|
|
peertube_like_count.setOnClickListener(v -> {
|
2020-06-27 19:08:52 +02:00
|
|
|
if (isLoggedIn(PeertubeActivity.this)) {
|
2020-06-27 11:21:25 +02:00
|
|
|
String newState = peertube.getMyRating().equals("like") ? "none" : "like";
|
2020-09-07 16:57:00 +02:00
|
|
|
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
2020-09-26 16:46:51 +02:00
|
|
|
viewModel.post(RATEVIDEO, peertube.getId(), newState).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(RATEVIDEO, apiResponse1));
|
2020-06-27 11:21:25 +02:00
|
|
|
peertube.setMyRating(newState);
|
2020-06-29 17:59:36 +02:00
|
|
|
int count = Integer.parseInt(peertube_like_count.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++;
|
|
|
|
}
|
|
|
|
peertube_like_count.setText(String.valueOf(count));
|
2020-06-27 11:21:25 +02:00
|
|
|
changeColor();
|
2020-06-27 19:08:52 +02:00
|
|
|
} else {
|
2020-06-27 11:21:25 +02:00
|
|
|
Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
});
|
|
|
|
peertube_dislike_count.setOnClickListener(v -> {
|
2020-06-27 19:08:52 +02:00
|
|
|
if (isLoggedIn(PeertubeActivity.this)) {
|
2020-06-27 11:21:25 +02:00
|
|
|
String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike";
|
2020-09-07 16:57:00 +02:00
|
|
|
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
2020-09-26 16:46:51 +02:00
|
|
|
viewModel.post(RATEVIDEO, peertube.getId(), newState).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(RATEVIDEO, apiResponse1));
|
2020-06-27 11:21:25 +02:00
|
|
|
peertube.setMyRating(newState);
|
2020-06-29 17:59:36 +02:00
|
|
|
int count = Integer.parseInt(peertube_dislike_count.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++;
|
|
|
|
}
|
|
|
|
peertube_dislike_count.setText(String.valueOf(count));
|
2020-06-27 11:21:25 +02:00
|
|
|
changeColor();
|
2020-06-27 19:08:52 +02:00
|
|
|
} else {
|
2020-06-27 11:21:25 +02:00
|
|
|
Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
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);
|
|
|
|
playerView.setPlayer(player);
|
|
|
|
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-09-20 11:07:28 +02:00
|
|
|
more_actions.setOnClickListener(view -> {
|
|
|
|
PopupMenu popup = new PopupMenu(PeertubeActivity.this, more_actions);
|
|
|
|
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 -> {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case 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);
|
|
|
|
} else {
|
2020-09-25 18:58:04 +02:00
|
|
|
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null));
|
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
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R.id.action_share:
|
|
|
|
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.shared_via));
|
|
|
|
String url;
|
|
|
|
|
2020-09-25 18:58:04 +02:00
|
|
|
url = peertube.getFiles().get(0).getFileDownloadUrl();
|
2020-09-20 11:07:28 +02:00
|
|
|
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 (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();
|
|
|
|
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)));
|
|
|
|
break;
|
|
|
|
case 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) {
|
2020-10-01 17:42:03 +02:00
|
|
|
ItemStr lang = caption.getLanguage();
|
|
|
|
itemsLabelLanguage[i] = lang.getLabel();
|
|
|
|
itemsKeyLanguage[i] = lang.getId();
|
2020-09-20 11:07:28 +02:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dialogBuilder.setSingleChoiceItems(itemsLabelLanguage, i, (dialog, which) -> {
|
2020-09-20 12:16:10 +02:00
|
|
|
|
|
|
|
Uri uri = null;
|
|
|
|
if (which > 0) {
|
|
|
|
uri = Uri.parse("https://" + getLiveInstance(PeertubeActivity.this) + captions.get(which - 1).getCaptionPath());
|
|
|
|
}
|
|
|
|
|
2020-09-20 12:06:38 +02:00
|
|
|
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
|
|
|
|
|
|
|
long position = player.getCurrentPosition();
|
|
|
|
|
|
|
|
if (player != null)
|
|
|
|
player.release();
|
|
|
|
|
2020-09-20 15:14:48 +02:00
|
|
|
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory());
|
2020-09-20 12:06:38 +02:00
|
|
|
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this, trackSelector);
|
|
|
|
ProgressiveMediaSource videoSource;
|
2020-09-20 12:16:10 +02:00
|
|
|
MediaSource subtitleSource = null;
|
2020-09-20 12:06:38 +02:00
|
|
|
Format subtitleFormat = Format.createTextSampleFormat(
|
|
|
|
null,
|
2020-09-20 12:16:10 +02:00
|
|
|
MimeTypes.TEXT_VTT,
|
2020-09-20 12:06:38 +02:00
|
|
|
Format.NO_VALUE,
|
2020-09-20 12:16:10 +02:00
|
|
|
itemsKeyLanguage[which]);
|
|
|
|
|
2020-09-20 15:14:48 +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)));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
playerView.setPlayer(player);
|
|
|
|
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 12:06:38 +02:00
|
|
|
}
|
2020-09-20 12:16:10 +02:00
|
|
|
|
2020-09-20 12:06:38 +02:00
|
|
|
|
2020-09-20 15:14:48 +02:00
|
|
|
dialog.dismiss();
|
2020-09-20 11:07:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
dialogBuilder.setOnDismissListener(dialogInterface -> {
|
|
|
|
|
|
|
|
});
|
2020-09-20 15:14:48 +02:00
|
|
|
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
2020-09-20 11:07:28 +02:00
|
|
|
|
|
|
|
androidx.appcompat.app.AlertDialog alertDialog = dialogBuilder.create();
|
|
|
|
alertDialog.setTitle(getString(R.string.pickup_captions));
|
|
|
|
alertDialog.show();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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-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);
|
|
|
|
playerView.setControllerAutoShow(false);
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (playerView != null) {
|
|
|
|
loader.setVisibility(View.VISIBLE);
|
|
|
|
long position = player.getCurrentPosition();
|
|
|
|
PlayerControlView controlView = playerView.findViewById(R.id.exo_controller);
|
|
|
|
resolution = controlView.findViewById(R.id.resolution);
|
|
|
|
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);
|
|
|
|
playerView.setPlayer(player);
|
|
|
|
loader.setVisibility(View.GONE);
|
|
|
|
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-09-07 16:57:00 +02:00
|
|
|
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
|
2020-10-06 18:49:15 +02:00
|
|
|
commentViewModel.getThread(videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment);
|
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() {
|
|
|
|
|
|
|
|
((ViewGroup) playerView.getParent()).removeView(playerView);
|
|
|
|
fullScreenDialog.addContentView(playerView, 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void closeFullscreenDialog() {
|
|
|
|
|
|
|
|
((ViewGroup) playerView.getParent()).removeView(playerView);
|
|
|
|
((FrameLayout) findViewById(R.id.main_media_frame)).addView(playerView);
|
|
|
|
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() {
|
|
|
|
|
|
|
|
PlayerControlView controlView = playerView.findViewById(R.id.exo_controller);
|
|
|
|
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() {
|
|
|
|
PlayerControlView controlView = playerView.findViewById(R.id.exo_controller);
|
|
|
|
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-06-29 17:59:36 +02:00
|
|
|
peertube_like_count.setCompoundDrawablesWithIntrinsicBounds(null, thumbUp, null, null);
|
|
|
|
peertube_dislike_count.setCompoundDrawablesWithIntrinsicBounds(null, thumbDown, null, null);
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
|
2020-09-07 16:57:00 +02:00
|
|
|
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
|
2020-10-03 16:22:19 +02:00
|
|
|
if (actionType == GET_PLAYLISTS && apiResponse != null) {
|
2020-06-26 08:50:49 +02:00
|
|
|
playlists = apiResponse.getPlaylists();
|
2020-10-07 17:46:15 +02:00
|
|
|
List<String> videoIds = new ArrayList<>();
|
|
|
|
videoIds.add(videoId);
|
|
|
|
playlistsViewModel.videoExists(videoIds).observe(PeertubeActivity.this, this::manageVIewVideosExist);
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-06 18:49:15 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-03 16:22:19 +02:00
|
|
|
public void manageVIewVideosExist(APIResponse apiResponse) {
|
2020-10-03 18:37:34 +02:00
|
|
|
if (apiResponse.getError() == null && apiResponse.getVideoExistPlaylist() != null) {
|
|
|
|
Map<String, List<PlaylistExist>> videoIds = apiResponse.getVideoExistPlaylist();
|
|
|
|
Iterator<Map.Entry<String, List<PlaylistExist>>> it = videoIds.entrySet().iterator();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Map.Entry<String, List<PlaylistExist>> pair = it.next();
|
|
|
|
List<PlaylistExist> playlistExistVideo = pair.getValue();
|
2020-10-06 18:49:15 +02:00
|
|
|
playlistForVideo.addAll(playlistExistVideo);
|
2020-10-03 18:37:34 +02:00
|
|
|
it.remove();
|
2020-10-03 16:22:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-01 17:42:03 +02:00
|
|
|
@Override
|
|
|
|
public void onAllCommentRemoved() {
|
|
|
|
no_action_text.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2020-06-26 08:50:49 +02:00
|
|
|
}
|