2018-10-14 15:20:05 +02:00
|
|
|
/* Copyright 2017 Thomas Schneider
|
|
|
|
*
|
|
|
|
* This file is a part of Mastalab
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Mastalab 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 Mastalab; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
package fr.gouv.etalab.mastodon.activities;
|
|
|
|
|
|
|
|
|
2018-10-17 14:34:29 +02:00
|
|
|
import android.Manifest;
|
2018-11-03 17:02:44 +01:00
|
|
|
import android.annotation.SuppressLint;
|
2019-01-25 16:15:35 +01:00
|
|
|
import android.app.Activity;
|
2019-01-06 13:20:06 +01:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.Dialog;
|
2018-10-14 15:20:05 +02:00
|
|
|
import android.content.Context;
|
2018-10-21 16:18:59 +02:00
|
|
|
import android.content.DialogInterface;
|
2018-10-14 15:20:05 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2018-10-17 14:34:29 +02:00
|
|
|
import android.content.pm.PackageManager;
|
2019-01-05 09:44:45 +01:00
|
|
|
import android.content.res.Configuration;
|
2018-10-21 18:43:57 +02:00
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2018-10-14 15:20:05 +02:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.AsyncTask;
|
2018-10-17 14:34:29 +02:00
|
|
|
import android.os.Build;
|
2018-10-14 15:20:05 +02:00
|
|
|
import android.os.Bundle;
|
2018-10-17 14:34:29 +02:00
|
|
|
import android.support.v4.content.ContextCompat;
|
2018-11-03 17:02:44 +01:00
|
|
|
import android.support.v7.app.ActionBar;
|
2019-01-06 13:20:06 +01:00
|
|
|
import android.support.v7.widget.AppCompatImageView;
|
2018-10-17 11:32:16 +02:00
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
2018-11-03 12:06:44 +01:00
|
|
|
import android.support.v7.widget.Toolbar;
|
2018-10-17 14:34:29 +02:00
|
|
|
import android.text.Html;
|
2018-11-03 17:02:44 +01:00
|
|
|
import android.view.LayoutInflater;
|
2018-10-14 15:20:05 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2019-01-25 16:15:35 +01:00
|
|
|
import android.view.MotionEvent;
|
2018-10-14 16:17:25 +02:00
|
|
|
import android.view.View;
|
2018-11-03 17:02:44 +01:00
|
|
|
import android.view.ViewGroup;
|
2018-10-14 15:20:05 +02:00
|
|
|
import android.view.WindowManager;
|
2019-01-25 16:15:35 +01:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2019-01-06 16:06:18 +01:00
|
|
|
import android.webkit.WebView;
|
2018-10-21 16:18:59 +02:00
|
|
|
import android.widget.ArrayAdapter;
|
2019-01-04 16:41:47 +01:00
|
|
|
import android.widget.EditText;
|
2019-01-06 13:20:06 +01:00
|
|
|
import android.widget.FrameLayout;
|
2018-11-03 17:02:44 +01:00
|
|
|
import android.widget.ImageView;
|
2019-01-04 16:41:47 +01:00
|
|
|
import android.widget.LinearLayout;
|
2018-10-14 16:17:25 +02:00
|
|
|
import android.widget.RelativeLayout;
|
2018-10-17 11:32:16 +02:00
|
|
|
import android.widget.ScrollView;
|
|
|
|
import android.widget.TextView;
|
2018-10-14 15:20:05 +02:00
|
|
|
import android.widget.Toast;
|
2018-11-25 10:45:16 +01:00
|
|
|
|
2019-01-05 19:34:32 +01:00
|
|
|
import com.google.android.exoplayer2.ExoPlayerFactory;
|
|
|
|
import com.google.android.exoplayer2.SimpleExoPlayer;
|
|
|
|
import com.google.android.exoplayer2.source.ExtractorMediaSource;
|
2019-01-06 13:20:06 +01:00
|
|
|
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
2019-01-05 19:34:32 +01:00
|
|
|
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
2019-01-06 13:20:06 +01:00
|
|
|
import com.google.android.exoplayer2.ui.PlaybackControlView;
|
|
|
|
import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
|
2019-01-05 19:34:32 +01:00
|
|
|
import com.google.android.exoplayer2.upstream.DataSource;
|
|
|
|
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
|
|
|
import com.google.android.exoplayer2.util.Util;
|
2019-01-05 16:56:11 +01:00
|
|
|
|
2018-10-14 15:20:05 +02:00
|
|
|
import java.lang.ref.WeakReference;
|
|
|
|
import java.security.KeyManagementException;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
|
|
|
2018-11-25 10:45:16 +01:00
|
|
|
import es.dmoral.toasty.Toasty;
|
2018-10-14 15:20:05 +02:00
|
|
|
import fr.gouv.etalab.mastodon.R;
|
2019-01-04 16:41:47 +01:00
|
|
|
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
|
2018-10-17 11:32:16 +02:00
|
|
|
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
2018-10-14 16:17:25 +02:00
|
|
|
import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeSingleAsyncTask;
|
2018-10-17 11:32:16 +02:00
|
|
|
import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeSingleCommentsAsyncTask;
|
2019-01-04 16:41:47 +01:00
|
|
|
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
|
2018-10-14 15:20:05 +02:00
|
|
|
import fr.gouv.etalab.mastodon.client.API;
|
2018-10-14 16:17:25 +02:00
|
|
|
import fr.gouv.etalab.mastodon.client.APIResponse;
|
2019-01-25 16:15:35 +01:00
|
|
|
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
2019-01-04 16:41:47 +01:00
|
|
|
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
2018-10-17 11:32:16 +02:00
|
|
|
import fr.gouv.etalab.mastodon.client.Entities.Peertube;
|
2018-10-14 15:20:05 +02:00
|
|
|
import fr.gouv.etalab.mastodon.client.Entities.Results;
|
2018-10-17 11:32:16 +02:00
|
|
|
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
2018-10-14 15:20:05 +02:00
|
|
|
import fr.gouv.etalab.mastodon.client.TLSSocketFactory;
|
2018-10-17 11:32:16 +02:00
|
|
|
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
|
2018-10-14 15:20:05 +02:00
|
|
|
import fr.gouv.etalab.mastodon.helper.FullScreenMediaController;
|
|
|
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
2019-01-04 16:41:47 +01:00
|
|
|
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
2018-10-14 16:17:25 +02:00
|
|
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeInterface;
|
2019-01-25 16:15:35 +01:00
|
|
|
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
2018-10-21 18:43:57 +02:00
|
|
|
import fr.gouv.etalab.mastodon.sqlite.PeertubeFavoritesDAO;
|
|
|
|
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
2019-01-06 16:06:18 +01:00
|
|
|
import fr.gouv.etalab.mastodon.webview.MastalabWebChromeClient;
|
|
|
|
import fr.gouv.etalab.mastodon.webview.MastalabWebViewClient;
|
2018-10-14 15:20:05 +02:00
|
|
|
|
2018-11-03 12:06:44 +01:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
|
2019-01-10 16:05:48 +01:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.VIDEO_MODE_DIRECT;
|
2019-01-06 17:16:02 +01:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.VIDEO_MODE_WEBVIEW;
|
2019-01-04 16:41:47 +01:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
2018-10-17 14:34:29 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.manageDownloads;
|
2018-10-17 11:32:16 +02:00
|
|
|
|
2018-10-14 15:20:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 14/10/20178.
|
|
|
|
* Peertube activity
|
|
|
|
*/
|
|
|
|
|
2019-01-06 13:44:04 +01:00
|
|
|
public class PeertubeActivity extends BaseActivity implements OnRetrievePeertubeInterface, OnPostActionInterface {
|
2018-10-14 15:20:05 +02:00
|
|
|
|
2018-10-14 17:36:18 +02:00
|
|
|
private String peertubeInstance, videoId;
|
2018-10-14 15:20:05 +02:00
|
|
|
private FullScreenMediaController.fullscreen fullscreen;
|
2018-10-14 16:17:25 +02:00
|
|
|
private RelativeLayout loader;
|
2018-10-21 18:43:57 +02:00
|
|
|
private TextView peertube_view_count, peertube_bookmark, peertube_like_count, peertube_dislike_count, peertube_share, peertube_download, peertube_description, peertube_title;
|
2018-10-17 11:32:16 +02:00
|
|
|
private ScrollView peertube_information_container;
|
2018-10-20 10:56:35 +02:00
|
|
|
private int stopPosition;
|
2018-10-20 15:16:57 +02:00
|
|
|
private Peertube peertube;
|
2018-11-03 17:02:44 +01:00
|
|
|
private TextView toolbar_title;
|
2019-01-04 16:41:47 +01:00
|
|
|
public static String video_id;
|
2019-01-06 13:20:06 +01:00
|
|
|
private SimpleExoPlayerView playerView;
|
2019-01-05 19:34:32 +01:00
|
|
|
private SimpleExoPlayer player;
|
2019-01-06 13:20:06 +01:00
|
|
|
private boolean fullScreenMode;
|
|
|
|
private Dialog fullScreenDialog;
|
|
|
|
private AppCompatImageView fullScreenIcon;
|
2019-01-06 13:44:04 +01:00
|
|
|
private TextView resolution;
|
2019-01-06 13:20:06 +01:00
|
|
|
private DefaultTrackSelector trackSelector;
|
2019-01-06 16:06:18 +01:00
|
|
|
private int mode;
|
2019-01-25 16:15:35 +01:00
|
|
|
private LinearLayout write_comment_container;
|
|
|
|
private ImageView my_pp, send;
|
|
|
|
private TextView add_comment_read;
|
|
|
|
private EditText add_comment_write;
|
2019-01-06 16:06:18 +01:00
|
|
|
|
2018-10-14 15:20:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
fullscreen = FullScreenMediaController.fullscreen.OFF;
|
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
|
|
|
switch (theme){
|
|
|
|
case Helper.THEME_LIGHT:
|
|
|
|
setTheme(R.style.AppTheme);
|
|
|
|
break;
|
|
|
|
case Helper.THEME_DARK:
|
|
|
|
setTheme(R.style.AppThemeDark);
|
|
|
|
break;
|
|
|
|
case Helper.THEME_BLACK:
|
|
|
|
setTheme(R.style.AppThemeBlack);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
setTheme(R.style.AppThemeDark);
|
|
|
|
}
|
2019-01-06 13:20:06 +01:00
|
|
|
fullScreenMode = false;
|
2018-10-14 15:20:05 +02:00
|
|
|
setContentView(R.layout.activity_peertube);
|
2018-10-14 16:17:25 +02:00
|
|
|
loader = findViewById(R.id.loader);
|
2018-10-17 11:32:16 +02:00
|
|
|
peertube_view_count = findViewById(R.id.peertube_view_count);
|
2018-10-21 18:43:57 +02:00
|
|
|
peertube_bookmark = findViewById(R.id.peertube_bookmark);
|
2018-10-17 11:32:16 +02:00
|
|
|
peertube_like_count = findViewById(R.id.peertube_like_count);
|
|
|
|
peertube_dislike_count = findViewById(R.id.peertube_dislike_count);
|
|
|
|
peertube_share = findViewById(R.id.peertube_share);
|
|
|
|
peertube_download = findViewById(R.id.peertube_download);
|
|
|
|
peertube_description = findViewById(R.id.peertube_description);
|
|
|
|
peertube_title = findViewById(R.id.peertube_title);
|
|
|
|
peertube_information_container = findViewById(R.id.peertube_information_container);
|
2019-01-10 17:56:19 +01:00
|
|
|
WebView webview_video = findViewById(R.id.webview_video);
|
2019-01-06 16:06:18 +01:00
|
|
|
playerView = findViewById(R.id.media_video);
|
2019-01-25 16:15:35 +01:00
|
|
|
write_comment_container = findViewById(R.id.write_comment_container);
|
|
|
|
my_pp = findViewById(R.id.my_pp);
|
|
|
|
add_comment_read = findViewById(R.id.add_comment_read);
|
|
|
|
add_comment_write = findViewById(R.id.add_comment_write);
|
|
|
|
send = findViewById(R.id.send);
|
|
|
|
add_comment_read.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
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());
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Helper.changeDrawableColor(getApplicationContext(), send, R.color.mastodonC4);
|
|
|
|
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
|
|
|
|
write_comment_container.setVisibility(View.GONE);
|
|
|
|
}
|
2018-10-17 11:32:16 +02:00
|
|
|
|
2019-01-25 16:15:35 +01:00
|
|
|
send.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
String comment = add_comment_write.getText().toString();
|
|
|
|
if( comment.trim().length() > 0 ) {
|
|
|
|
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.PEERTUBECOMMENT, peertube.getId(), null, comment, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
add_comment_write.setText("");
|
|
|
|
add_comment_read.setVisibility(View.VISIBLE);
|
|
|
|
add_comment_write.setVisibility(View.GONE);
|
|
|
|
send.setVisibility(View.GONE);
|
|
|
|
add_comment_read.requestFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
|
|
|
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
|
|
Account account = new AccountDAO(getApplicationContext(), db).getAccountByToken(prefKeyOauthTokenT);
|
|
|
|
Helper.loadGiF(getApplicationContext(), account.getAvatar(), my_pp);
|
2018-10-14 15:20:05 +02:00
|
|
|
Bundle b = getIntent().getExtras();
|
|
|
|
if(b != null) {
|
2018-10-14 16:17:25 +02:00
|
|
|
peertubeInstance = b.getString("peertube_instance", null);
|
|
|
|
videoId = b.getString("video_id", null);
|
2018-10-14 15:20:05 +02:00
|
|
|
}
|
|
|
|
if( getSupportActionBar() != null)
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
2018-11-03 17:02:44 +01:00
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
if( actionBar != null ) {
|
|
|
|
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
assert inflater != null;
|
|
|
|
@SuppressLint("InflateParams") View view = inflater.inflate(R.layout.simple_bar, null);
|
|
|
|
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
|
|
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
|
|
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
|
|
|
|
toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
|
|
|
|
toolbar_close.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (theme == THEME_LIGHT){
|
|
|
|
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
|
|
|
|
Helper.colorizeToolbar(toolbar, R.color.black, PeertubeActivity.this);
|
|
|
|
}
|
2018-11-03 12:06:44 +01:00
|
|
|
}
|
2019-01-05 19:34:32 +01:00
|
|
|
|
2019-01-05 16:56:11 +01:00
|
|
|
|
2019-01-09 16:06:36 +01:00
|
|
|
mode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_DIRECT);
|
2019-01-18 14:48:42 +01:00
|
|
|
if( mode != Helper.VIDEO_MODE_WEBVIEW && mode != Helper.VIDEO_MODE_DIRECT)
|
|
|
|
mode = VIDEO_MODE_DIRECT;
|
2019-01-06 17:16:02 +01: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);
|
|
|
|
FrameLayout webview_container = findViewById(R.id.main_media_frame);
|
|
|
|
final ViewGroup videoLayout = findViewById(R.id.videoLayout);
|
|
|
|
|
2019-01-10 17:56:19 +01:00
|
|
|
MastalabWebChromeClient mastalabWebChromeClient = new MastalabWebChromeClient(PeertubeActivity.this, webview_video, webview_container, videoLayout);
|
2019-01-06 17:16:02 +01:00
|
|
|
mastalabWebChromeClient.setOnToggledFullscreen(new MastalabWebChromeClient.ToggledFullscreenCallback() {
|
|
|
|
@Override
|
|
|
|
public void toggledFullscreen(boolean 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);
|
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2019-01-18 14:48:42 +01:00
|
|
|
webview_video.getSettings().setAllowFileAccess(true);
|
2019-01-06 17:16:02 +01:00
|
|
|
webview_video.setWebChromeClient(mastalabWebChromeClient);
|
2019-01-18 14:48:42 +01:00
|
|
|
webview_video.getSettings().setDomStorageEnabled(true);
|
|
|
|
webview_video.getSettings().setAppCacheEnabled(true);
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
|
|
|
webview_video.getSettings().setMediaPlaybackRequiresUserGesture(false);
|
|
|
|
}
|
2019-01-06 17:16:02 +01:00
|
|
|
webview_video.setWebViewClient(new MastalabWebViewClient(PeertubeActivity.this));
|
|
|
|
webview_video.loadUrl("https://" + peertubeInstance + "/videos/embed/" + videoId);
|
|
|
|
}else {
|
|
|
|
webview_video.setVisibility(View.GONE);
|
|
|
|
playerView.setVisibility(View.VISIBLE);
|
2019-01-06 17:38:35 +01:00
|
|
|
loader.setVisibility(View.VISIBLE);
|
2019-01-06 17:16:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( mode != Helper.VIDEO_MODE_WEBVIEW){
|
|
|
|
playerView.setControllerShowTimeoutMs(1000);
|
|
|
|
playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
|
|
|
|
initFullscreenDialog();
|
|
|
|
initFullscreenButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-14 16:17:25 +02:00
|
|
|
new RetrievePeertubeSingleAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2018-10-14 15:20:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void change(){
|
|
|
|
if(fullscreen == FullScreenMediaController.fullscreen.ON){
|
2018-12-20 18:07:05 +01:00
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
|
|
|
|
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
2018-10-14 15:20:05 +02:00
|
|
|
Objects.requireNonNull(getSupportActionBar()).hide();
|
2018-10-17 11:32:16 +02:00
|
|
|
peertube_information_container.setVisibility(View.GONE);
|
2018-10-14 15:20:05 +02:00
|
|
|
}else{
|
|
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
|
|
|
|
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
|
|
|
|
Objects.requireNonNull(getSupportActionBar()).show();
|
2018-10-17 11:32:16 +02:00
|
|
|
peertube_information_container.setVisibility(View.VISIBLE);
|
2018-10-14 15:20:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-25 16:15:35 +01: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()) {
|
|
|
|
add_comment_read.setVisibility(View.VISIBLE);
|
|
|
|
add_comment_write.setVisibility(View.GONE);
|
|
|
|
send.setVisibility(View.GONE);
|
|
|
|
hideKeyboard(PeertubeActivity.this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.dispatchTouchEvent(ev);
|
|
|
|
}
|
2018-10-20 10:56:35 +02:00
|
|
|
|
2019-01-25 16:15:35 +01:00
|
|
|
public static void hideKeyboard(Activity activity) {
|
|
|
|
if (activity != null && activity.getWindow() != null && activity.getWindow().getDecorView() != null) {
|
|
|
|
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
|
|
|
|
}
|
|
|
|
}
|
2018-10-20 10:56:35 +02:00
|
|
|
|
2018-10-14 15:20:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
getMenuInflater().inflate(R.menu.main_webview, menu);
|
2018-10-14 17:36:18 +02:00
|
|
|
menu.findItem(R.id.action_go).setVisible(false);
|
|
|
|
menu.findItem(R.id.action_comment).setVisible(true);
|
2018-11-03 17:02:44 +01:00
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
|
|
|
if( theme == THEME_LIGHT)
|
|
|
|
Helper.colorizeIconMenu(menu, R.color.black);
|
2019-01-25 16:15:35 +01:00
|
|
|
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
|
|
|
|
MenuItem item = menu.findItem(R.id.action_comment);
|
|
|
|
if( item != null)
|
|
|
|
item.setVisible(false);
|
|
|
|
}
|
2018-10-14 15:20:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
case R.id.action_comment:
|
2019-01-04 16:41:47 +01:00
|
|
|
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
|
|
|
|
Toasty.info(PeertubeActivity.this, getString(R.string.retrieve_remote_status), Toast.LENGTH_LONG).show();
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
2018-10-14 15:20:05 +02:00
|
|
|
|
2019-01-04 16:41:47 +01:00
|
|
|
private List<fr.gouv.etalab.mastodon.client.Entities.Status> remoteStatuses;
|
|
|
|
private WeakReference<Context> contextReference = new WeakReference<>(PeertubeActivity.this);
|
2018-10-14 15:20:05 +02:00
|
|
|
|
2019-01-04 16:41:47 +01:00
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... voids) {
|
2018-10-14 15:20:05 +02:00
|
|
|
|
2019-01-04 16:41:47 +01:00
|
|
|
if (peertube != null) {
|
|
|
|
Results search = new API(contextReference.get()).search("https://" + peertube.getAccount().getHost() + "/videos/watch/" + peertube.getUuid());
|
|
|
|
if (search != null) {
|
|
|
|
remoteStatuses = search.getStatuses();
|
|
|
|
}
|
2018-10-14 15:20:05 +02:00
|
|
|
}
|
2019-01-04 16:41:47 +01:00
|
|
|
return null;
|
2018-10-14 15:20:05 +02:00
|
|
|
}
|
|
|
|
|
2019-01-04 16:41:47 +01:00
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void result) {
|
|
|
|
Intent intent = new Intent(contextReference.get(), TootActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
if (remoteStatuses == null || remoteStatuses.size() == 0) {
|
|
|
|
Toasty.error(contextReference.get(), getString(R.string.toast_error), Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (remoteStatuses.get(0).getReblog() != null) {
|
|
|
|
b.putParcelable("tootReply", remoteStatuses.get(0).getReblog());
|
|
|
|
} else {
|
|
|
|
b.putParcelable("tootReply", remoteStatuses.get(0));
|
|
|
|
}
|
|
|
|
intent.putExtras(b); //Put your id to your next Intent
|
|
|
|
contextReference.get().startActivity(intent);
|
2018-10-14 15:20:05 +02:00
|
|
|
}
|
2019-01-04 16:41:47 +01:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
|
|
|
|
if(! peertube.isCommentsEnabled()) {
|
|
|
|
Toasty.info(PeertubeActivity.this, getString(R.string.comment_no_allowed_peertube),Toast.LENGTH_LONG).show();
|
|
|
|
return true;
|
2018-10-14 15:20:05 +02:00
|
|
|
}
|
2019-01-04 16:41:47 +01:00
|
|
|
int style;
|
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
|
|
|
if (theme == Helper.THEME_DARK) {
|
|
|
|
style = R.style.DialogDark;
|
|
|
|
} else if (theme == Helper.THEME_BLACK){
|
|
|
|
style = R.style.DialogBlack;
|
|
|
|
}else {
|
|
|
|
style = R.style.Dialog;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builderInner;
|
|
|
|
builderInner = new AlertDialog.Builder(PeertubeActivity.this, style);
|
|
|
|
builderInner.setTitle(R.string.comment);
|
|
|
|
EditText input = new EditText(PeertubeActivity.this);
|
|
|
|
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
|
input.setLayoutParams(lp);
|
|
|
|
builderInner.setView(input);
|
|
|
|
builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,int which) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builderInner.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,int which) {
|
|
|
|
String comment = input.getText().toString();
|
|
|
|
if( comment.trim().length() > 0 ) {
|
|
|
|
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.PEERTUBECOMMENT, peertube.getId(), null, comment, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builderInner.show();
|
|
|
|
}
|
2018-10-14 15:20:05 +02:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public FullScreenMediaController.fullscreen getFullscreen() {
|
|
|
|
return fullscreen;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFullscreen(FullScreenMediaController.fullscreen fullscreen) {
|
|
|
|
this.fullscreen = fullscreen;
|
|
|
|
}
|
2018-10-14 16:17:25 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRetrievePeertube(APIResponse apiResponse) {
|
|
|
|
|
|
|
|
if( apiResponse == null || (apiResponse.getError() != null) || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0){
|
2018-11-25 10:45:16 +01:00
|
|
|
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error),Toast.LENGTH_LONG).show();
|
2018-10-14 16:17:25 +02:00
|
|
|
loader.setVisibility(View.GONE);
|
|
|
|
return;
|
|
|
|
}
|
2018-10-20 14:39:24 +02:00
|
|
|
if( apiResponse.getPeertubes() == null || apiResponse.getPeertubes().get(0) == null || apiResponse.getPeertubes().get(0).getFileUrl(null) == null){
|
2018-11-25 10:45:16 +01:00
|
|
|
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error),Toast.LENGTH_LONG).show();
|
2018-10-14 16:17:25 +02:00
|
|
|
loader.setVisibility(View.GONE);
|
|
|
|
return;
|
|
|
|
}
|
2018-10-20 18:23:57 +02:00
|
|
|
|
2018-10-20 15:16:57 +02:00
|
|
|
peertube = apiResponse.getPeertubes().get(0);
|
2019-01-25 16:15:35 +01:00
|
|
|
if( peertube.isCommentsEnabled()) {
|
2018-10-20 18:23:57 +02:00
|
|
|
new RetrievePeertubeSingleCommentsAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2019-01-25 16:15:35 +01:00
|
|
|
write_comment_container.setVisibility(View.VISIBLE);
|
|
|
|
}else {
|
2018-10-20 18:23:57 +02:00
|
|
|
RelativeLayout no_action = findViewById(R.id.no_action);
|
|
|
|
TextView no_action_text = findViewById(R.id.no_action_text);
|
|
|
|
no_action_text.setText(getString(R.string.comment_no_allowed_peertube));
|
|
|
|
no_action.setVisibility(View.VISIBLE);
|
2019-01-25 16:15:35 +01:00
|
|
|
write_comment_container.setVisibility(View.GONE);
|
2018-10-20 18:23:57 +02:00
|
|
|
}
|
2018-10-17 11:32:16 +02:00
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
|
2018-11-03 17:02:44 +01:00
|
|
|
toolbar_title.setText(peertube.getName());
|
2018-10-17 11:32:16 +02:00
|
|
|
peertube_description.setText(peertube.getDescription());
|
|
|
|
peertube_title.setText(peertube.getName());
|
|
|
|
peertube_dislike_count.setText(String.valueOf(peertube.getDislike()));
|
|
|
|
peertube_like_count.setText(String.valueOf(peertube.getLike()));
|
|
|
|
peertube_view_count.setText(String.valueOf(peertube.getView()));
|
2019-01-04 16:41:47 +01:00
|
|
|
video_id = peertube.getId();
|
|
|
|
|
|
|
|
changeColor();
|
2019-01-06 13:44:04 +01:00
|
|
|
initResolution();
|
2019-01-04 16:41:47 +01:00
|
|
|
|
|
|
|
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
|
|
|
|
peertube_like_count.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
String newState = peertube.getMyRating().equals("like")?"none":"like";
|
|
|
|
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.RATEVIDEO, peertube.getId(), null, newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
peertube.setMyRating(newState);
|
|
|
|
changeColor();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
peertube_dislike_count.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
String newState = peertube.getMyRating().equals("dislike")?"none":"dislike";
|
|
|
|
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.RATEVIDEO, peertube.getId(), null, newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
peertube.setMyRating(newState);
|
|
|
|
changeColor();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-10-14 16:17:25 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
HttpsURLConnection.setDefaultSSLSocketFactory(new TLSSocketFactory());
|
|
|
|
} catch (KeyManagementException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2019-01-05 16:56:11 +01:00
|
|
|
|
2019-01-18 14:48:42 +01:00
|
|
|
if( mode == Helper.VIDEO_MODE_DIRECT){
|
2019-01-06 16:06:18 +01:00
|
|
|
|
|
|
|
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(),
|
|
|
|
Util.getUserAgent(getApplicationContext(), "Mastalab"), null);
|
|
|
|
|
|
|
|
ExtractorMediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
|
2019-01-06 17:16:02 +01:00
|
|
|
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null)));
|
2019-01-06 16:06:18 +01:00
|
|
|
|
|
|
|
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this);
|
|
|
|
playerView.setPlayer(player);
|
|
|
|
loader.setVisibility(View.GONE);
|
|
|
|
|
2019-01-06 17:16:02 +01:00
|
|
|
player.prepare(videoSource);
|
2019-01-06 16:06:18 +01:00
|
|
|
player.setPlayWhenReady(true);
|
|
|
|
}
|
2019-01-05 16:56:11 +01:00
|
|
|
|
2018-10-21 16:18:59 +02:00
|
|
|
|
2018-10-20 10:56:35 +02:00
|
|
|
|
2018-10-17 11:32:16 +02:00
|
|
|
peertube_download.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2018-10-17 14:34:29 +02:00
|
|
|
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) {
|
|
|
|
} else {
|
2018-10-20 10:56:35 +02:00
|
|
|
manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null));
|
2018-10-17 14:34:29 +02:00
|
|
|
}
|
|
|
|
}else{
|
2018-10-20 10:56:35 +02:00
|
|
|
manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null));
|
2018-10-17 14:34:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2018-10-21 18:43:57 +02:00
|
|
|
SQLiteDatabase db = Sqlite.getInstance(PeertubeActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
|
|
List<Peertube> peertubes = new PeertubeFavoritesDAO(PeertubeActivity.this, db).getSinglePeertube(peertube);
|
|
|
|
|
|
|
|
Drawable img;
|
|
|
|
|
|
|
|
if( peertubes == null || peertubes.size() == 0)
|
|
|
|
img = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube_border);
|
|
|
|
else
|
|
|
|
img = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube);
|
|
|
|
peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds(null, img, null, null);
|
|
|
|
|
|
|
|
peertube_bookmark.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
List<Peertube> peertubes = new PeertubeFavoritesDAO(PeertubeActivity.this, db).getSinglePeertube(peertube);
|
|
|
|
if( peertubes == null || peertubes.size() == 0){
|
|
|
|
new PeertubeFavoritesDAO(PeertubeActivity.this, db).insert(peertube);
|
2018-11-25 10:45:16 +01:00
|
|
|
Toasty.success(PeertubeActivity.this,getString(R.string.bookmark_add_peertube), Toast.LENGTH_SHORT).show();
|
2018-10-21 18:43:57 +02:00
|
|
|
}else{
|
|
|
|
new PeertubeFavoritesDAO(PeertubeActivity.this, db).remove(peertube);
|
2018-11-25 10:45:16 +01:00
|
|
|
Toasty.success(PeertubeActivity.this,getString(R.string.bookmark_remove_peertube), Toast.LENGTH_SHORT).show();
|
2018-10-21 18:43:57 +02:00
|
|
|
}
|
|
|
|
if( peertubes != null && peertubes.size() > 0) //Was initially in cache
|
|
|
|
peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds( null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube_border), null ,null);
|
|
|
|
else
|
|
|
|
peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds( null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube), null ,null);
|
|
|
|
}
|
|
|
|
});
|
2018-10-17 14:34:29 +02:00
|
|
|
|
|
|
|
peertube_share.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.shared_via));
|
|
|
|
String url;
|
|
|
|
|
|
|
|
url = "https://" +peertube.getInstance() + "/videos/watch/"+ peertube.getUuid();
|
|
|
|
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" + Helper.shortnameToUnicode(":link:", true) + " " + 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
|
|
|
|
//noinspection deprecation
|
|
|
|
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)));
|
2018-10-14 16:17:25 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-10-17 11:32:16 +02:00
|
|
|
|
2019-01-06 13:20:06 +01:00
|
|
|
|
2019-01-05 09:44:45 +01:00
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
|
2019-01-06 17:16:02 +01:00
|
|
|
if( mode != VIDEO_MODE_WEBVIEW) {
|
|
|
|
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
openFullscreenDialog();
|
|
|
|
setFullscreen(FullScreenMediaController.fullscreen.ON);
|
|
|
|
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
|
|
closeFullscreenDialog();
|
|
|
|
setFullscreen(FullScreenMediaController.fullscreen.OFF);
|
|
|
|
}
|
|
|
|
change();
|
|
|
|
}else {
|
|
|
|
final ViewGroup videoLayout = findViewById(R.id.videoLayout);
|
|
|
|
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
setFullscreen(FullScreenMediaController.fullscreen.ON);
|
|
|
|
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
|
|
setFullscreen(FullScreenMediaController.fullscreen.OFF);
|
|
|
|
}
|
|
|
|
change();
|
|
|
|
|
|
|
|
|
2019-01-05 09:44:45 +01:00
|
|
|
}
|
2019-01-06 17:16:02 +01:00
|
|
|
|
2019-01-05 09:44:45 +01:00
|
|
|
}
|
|
|
|
|
2018-10-17 11:32:16 +02:00
|
|
|
@Override
|
|
|
|
public void onRetrievePeertubeComments(APIResponse apiResponse) {
|
|
|
|
if( apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404) ){
|
|
|
|
if( apiResponse == null)
|
2018-11-25 10:45:16 +01:00
|
|
|
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error),Toast.LENGTH_LONG).show();
|
2018-10-17 11:32:16 +02:00
|
|
|
else
|
2018-11-25 10:45:16 +01:00
|
|
|
Toasty.error(PeertubeActivity.this, apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
2018-10-17 11:32:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
List<Status> statuses = apiResponse.getStatuses();
|
2019-01-05 09:48:14 +01:00
|
|
|
RecyclerView lv_comments = findViewById(R.id.peertube_comments);
|
2018-10-17 11:32:16 +02:00
|
|
|
if( statuses == null || statuses.size() == 0){
|
|
|
|
lv_comments.setVisibility(View.GONE);
|
|
|
|
}else {
|
2019-01-05 09:48:14 +01:00
|
|
|
lv_comments.setVisibility(View.VISIBLE);
|
2018-10-17 11:32:16 +02:00
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
boolean isOnWifi = Helper.isOnWIFI(PeertubeActivity.this);
|
|
|
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
2018-12-16 14:29:23 +01:00
|
|
|
StatusListAdapter statusListAdapter = new StatusListAdapter(PeertubeActivity.this, RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE, userId, isOnWifi, statuses);
|
2018-10-17 11:32:16 +02:00
|
|
|
LinearLayoutManager mLayoutManager = new LinearLayoutManager(PeertubeActivity.this);
|
|
|
|
lv_comments.setLayoutManager(mLayoutManager);
|
|
|
|
lv_comments.setNestedScrollingEnabled(false);
|
|
|
|
lv_comments.setAdapter(statusListAdapter);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2018-10-20 10:56:35 +02:00
|
|
|
|
2019-01-07 19:16:15 +01:00
|
|
|
@Override
|
|
|
|
public void onRetrievePeertubeChannels(APIResponse apiResponse) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-05 17:43:37 +01:00
|
|
|
@Override
|
2019-01-06 13:20:06 +01:00
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
2019-01-05 17:43:37 +01:00
|
|
|
}
|
|
|
|
|
2018-10-20 10:56:35 +02:00
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
2019-01-06 13:20:06 +01:00
|
|
|
if( player != null) {
|
|
|
|
player.setPlayWhenReady(false);
|
|
|
|
}
|
2018-10-20 10:56:35 +02:00
|
|
|
}
|
|
|
|
|
2019-01-05 16:56:11 +01:00
|
|
|
|
2018-10-20 10:56:35 +02:00
|
|
|
@Override
|
|
|
|
public void onResume(){
|
|
|
|
super.onResume();
|
2019-01-06 13:20:06 +01:00
|
|
|
if( player != null) {
|
|
|
|
player.setPlayWhenReady(true);
|
|
|
|
}
|
2018-10-20 10:56:35 +02:00
|
|
|
}
|
2018-10-21 16:18:59 +02:00
|
|
|
|
|
|
|
public void displayResolution(){
|
2018-11-03 14:45:55 +01:00
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
|
|
|
int style;
|
|
|
|
if (theme == Helper.THEME_DARK) {
|
|
|
|
style = R.style.DialogDark;
|
|
|
|
} else if (theme == Helper.THEME_BLACK){
|
|
|
|
style = R.style.DialogBlack;
|
|
|
|
}else {
|
|
|
|
style = R.style.Dialog;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builderSingle = new AlertDialog.Builder(PeertubeActivity.this, style);
|
2018-10-21 16:18:59 +02:00
|
|
|
builderSingle.setTitle(R.string.pickup_resolution);
|
|
|
|
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(PeertubeActivity.this, android.R.layout.select_dialog_item);
|
|
|
|
for(String resolution: peertube.getResolution())
|
|
|
|
arrayAdapter.add(resolution+"p");
|
|
|
|
builderSingle.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
String res = arrayAdapter.getItem(which).substring(0, arrayAdapter.getItem(which).length() - 1);
|
2019-01-06 17:16:02 +01:00
|
|
|
|
2019-01-05 19:34:32 +01:00
|
|
|
if( playerView != null) {
|
2019-01-05 16:56:11 +01:00
|
|
|
loader.setVisibility(View.VISIBLE);
|
2019-01-05 19:34:32 +01:00
|
|
|
long position = player.getCurrentPosition();
|
2019-01-10 16:05:48 +01:00
|
|
|
PlaybackControlView controlView = playerView.findViewById(R.id.exo_controller);
|
|
|
|
resolution = controlView.findViewById(R.id.resolution);
|
|
|
|
resolution.setText(String.format("%sp",res));
|
2019-01-18 14:48:42 +01:00
|
|
|
if( mode == VIDEO_MODE_DIRECT){
|
2019-01-10 16:05:48 +01:00
|
|
|
|
|
|
|
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this);
|
|
|
|
playerView.setPlayer(player);
|
|
|
|
loader.setVisibility(View.GONE);
|
|
|
|
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(),
|
|
|
|
Util.getUserAgent(getApplicationContext(), "Mastalab"), null);
|
|
|
|
|
|
|
|
ExtractorMediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
|
|
|
|
.createMediaSource(Uri.parse(peertube.getFileUrl(res)));
|
|
|
|
player.prepare(videoSource);
|
|
|
|
player.seekTo(0, position);
|
|
|
|
player.setPlayWhenReady(true);
|
|
|
|
}
|
2018-10-21 16:18:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builderSingle.show();
|
2018-10-20 10:56:35 +02:00
|
|
|
}
|
2019-01-04 16:41:47 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error) {
|
|
|
|
|
|
|
|
if( peertube.isCommentsEnabled() && statusAction == API.StatusAction.PEERTUBECOMMENT)
|
|
|
|
new RetrievePeertubeSingleCommentsAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-06 13:20:06 +01:00
|
|
|
private void initFullscreenDialog() {
|
|
|
|
|
|
|
|
fullScreenDialog = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen) {
|
|
|
|
public void onBackPressed() {
|
|
|
|
if (fullScreenMode)
|
|
|
|
closeFullscreenDialog();
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private void openFullscreenDialog() {
|
|
|
|
|
|
|
|
((ViewGroup) playerView.getParent()).removeView(playerView);
|
|
|
|
fullScreenDialog.addContentView(playerView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
|
|
fullScreenIcon.setImageDrawable(ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_fullscreen_exit));
|
|
|
|
fullScreenMode = true;
|
|
|
|
fullScreenDialog.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void closeFullscreenDialog() {
|
|
|
|
|
|
|
|
((ViewGroup) playerView.getParent()).removeView(playerView);
|
|
|
|
((FrameLayout) findViewById(R.id.main_media_frame)).addView(playerView);
|
|
|
|
fullScreenMode = false;
|
|
|
|
fullScreenDialog.dismiss();
|
|
|
|
fullScreenIcon.setImageDrawable(ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_fullscreen));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initFullscreenButton() {
|
|
|
|
|
|
|
|
PlaybackControlView 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(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (!fullScreenMode)
|
|
|
|
openFullscreenDialog();
|
|
|
|
else
|
|
|
|
closeFullscreenDialog();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-06 13:44:04 +01:00
|
|
|
private void initResolution() {
|
|
|
|
PlaybackControlView controlView = playerView.findViewById(R.id.exo_controller);
|
|
|
|
resolution = controlView.findViewById(R.id.resolution);
|
2019-01-10 16:05:48 +01:00
|
|
|
resolution.setText(String.format("%sp",peertube.getResolution().get(0)));
|
2019-01-06 13:44:04 +01:00
|
|
|
resolution.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
displayResolution();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-04 16:41:47 +01:00
|
|
|
private void changeColor(){
|
|
|
|
if( peertube.getMyRating() != null && peertube.getMyRating().equals("like")){
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_up_peertube,R.color.positive_thumbs);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_down_peertube,R.color.neutral_thumbs);
|
|
|
|
}else if( peertube.getMyRating() != null && peertube.getMyRating().equals("dislike")){
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_up_peertube,R.color.neutral_thumbs);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_down_peertube,R.color.negative_thumbs);
|
|
|
|
}else {
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_up_peertube,R.color.neutral_thumbs);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_down_peertube,R.color.neutral_thumbs);
|
|
|
|
}
|
|
|
|
Drawable thumbUp = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_thumb_up_peertube);
|
|
|
|
Drawable thumbDown = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_thumb_down_peertube);
|
|
|
|
peertube_like_count.setCompoundDrawablesWithIntrinsicBounds( null, thumbUp, null, null);
|
|
|
|
peertube_dislike_count.setCompoundDrawablesWithIntrinsicBounds( null, thumbDown, null, null);
|
|
|
|
}
|
2018-10-14 15:20:05 +02:00
|
|
|
}
|