some improvements

This commit is contained in:
Thomas 2020-11-16 18:54:59 +01:00
parent 8c95554d8e
commit 9c676d8002
9 changed files with 379 additions and 274 deletions

View File

@ -17,7 +17,6 @@ package app.fedilab.fedilabtube;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.app.PictureInPictureParams;
import android.content.BroadcastReceiver;
import android.content.Context;
@ -42,14 +41,12 @@ import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
@ -109,6 +106,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.MenuItemVideo;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.data.AccountData.Account;
import app.fedilab.fedilabtube.client.data.CaptionData.Caption;
@ -122,8 +120,8 @@ import app.fedilab.fedilabtube.client.entities.PlaylistExist;
import app.fedilab.fedilabtube.client.entities.Report;
import app.fedilab.fedilabtube.databinding.ActivityPeertubeBinding;
import app.fedilab.fedilabtube.drawer.CommentListAdapter;
import app.fedilab.fedilabtube.drawer.MenuAdapter;
import app.fedilab.fedilabtube.helper.CacheDataSourceFactory;
import app.fedilab.fedilabtube.helper.FullScreenMediaController;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.sqlite.AccountDAO;
import app.fedilab.fedilabtube.sqlite.Sqlite;
@ -150,16 +148,14 @@ import static app.fedilab.fedilabtube.helper.Helper.loadGiF;
import static com.google.android.exoplayer2.Player.MEDIA_ITEM_TRANSITION_REASON_AUTO;
public class PeertubeActivity extends AppCompatActivity implements CommentListAdapter.AllCommentRemoved, Player.EventListener, VideoListener, TorrentListener {
public class PeertubeActivity extends AppCompatActivity implements CommentListAdapter.AllCommentRemoved, Player.EventListener, VideoListener, TorrentListener, MenuAdapter.ItemClicked {
public static String video_id;
public static List<String> playedVideos = new ArrayList<>();
private String peertubeInstance, videoUuid;
private FullScreenMediaController.fullscreen fullscreen;
private ImageView fullScreenIcon;
private SimpleExoPlayer player;
private boolean fullScreenMode;
private Dialog fullScreenDialog;
private VideoData.Video peertube;
private int mode;
private Map<String, List<PlaylistExist>> playlists;
@ -183,6 +179,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private videoOrientation videoOrientationType;
private int initialOrientation;
public static void hideKeyboard(Activity activity) {
if (activity != null && activity.getWindow() != null) {
activity.getWindow().getDecorView();
@ -252,6 +249,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
.removeFilesAfterStop(true)
.build();
fullScreenMode = false;
torrentStream = TorrentStream.init(torrentOptions);
torrentStream.addListener(PeertubeActivity.this);
initialOrientation = getResources().getConfiguration().orientation;
@ -322,29 +320,12 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
MastalabWebChromeClient mastalabWebChromeClient = new MastalabWebChromeClient(PeertubeActivity.this, webview_video, binding.mainMediaFrame, binding.videoLayout);
mastalabWebChromeClient.setOnToggledFullscreen(fullscreen -> {
if (fullscreen) {
binding.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);
binding.peertubeInformationContainer.setVisibility(View.GONE);
if (videoOrientationType == videoOrientation.LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
} 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);
binding.videoLayout.setVisibility(View.GONE);
binding.peertubeInformationContainer.setVisibility(View.VISIBLE);
}
toogleFullscreen(fullscreen);
});
binding.webviewVideo.getSettings().setAllowFileAccess(true);
binding.webviewVideo.setWebChromeClient(mastalabWebChromeClient);
@ -361,21 +342,24 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
if (mode != Helper.VIDEO_MODE_WEBVIEW) {
binding.doubleTapPlayerView.setControllerShowTimeoutMs(1000);
binding.doubleTapPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
initFullscreenDialog();
initFullscreenButton();
// initFullscreenDialog();
initControllerButtons();
binding.doubleTapPlayerView
.setDoubleTapDelay(500);
binding.doubleTapPlayerView.setDoubleTapEnabled(true);
binding.doubleTapPlayerView.setControllerShowTimeoutMs(0);
binding.mediaVideo.performListener(new YouTubeOverlay.PerformListener() {
@Override
public void onAnimationStart() {
binding.mediaVideo.setVisibility(View.VISIBLE);
binding.doubleTapPlayerView.setUseController(false);
}
@Override
public void onAnimationEnd() {
binding.mediaVideo.setVisibility(View.GONE);
binding.doubleTapPlayerView.setUseController(true);
}
}).playerView(binding.doubleTapPlayerView).seekSeconds(10);
binding.doubleTapPlayerView.setPlayer(player);
@ -419,13 +403,18 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
registBroadcastReceiver();
if (autoFullscreen && autoPlay) {
openFullscreenDialog();
if (videoOrientationType == videoOrientation.LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
binding.postCommentButton.setOnClickListener(v -> openPostComment(null, 0));
List<MenuItemVideo> menuItemVideos = new ArrayList<>();
MenuItemVideo resolutionItem = new MenuItemVideo();
resolutionItem.setIcon(R.drawable.ic_baseline_settings_24);
resolutionItem.setTitle(getString(R.string.pickup_resolution));
resolutionItem.setAction(MenuItemVideo.actionType.RESOLUTION);
MenuAdapter menuAdapter = new MenuAdapter(menuItemVideos);
binding.mainOptionsVideo.setAdapter(menuAdapter);
}
private void manageVIewVideos(APIResponse apiResponse) {
@ -559,19 +548,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
show_more_content = null;
binding.peertubeDescriptionMore.setVisibility(View.GONE);
if (autoFullscreen && autoPlay) {
fullscreen = FullScreenMediaController.fullscreen.ON;
setFullscreen(FullScreenMediaController.fullscreen.ON);
fullScreenMode = true;
openFullscreenDialog();
if (videoOrientationType == videoOrientation.LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
} else {
fullscreen = FullScreenMediaController.fullscreen.OFF;
setFullscreen(FullScreenMediaController.fullscreen.OFF);
fullScreenMode = false;
}
binding.peertubePlaylist.setVisibility(View.VISIBLE);
binding.peertubeBookmark.setVisibility(View.GONE);
@ -608,20 +585,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}).start();
}
public void change() {
if (fullscreen == FullScreenMediaController.fullscreen.ON) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Objects.requireNonNull(getSupportActionBar()).hide();
binding.peertubeInformationContainer.setVisibility(View.GONE);
} else {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
Objects.requireNonNull(getSupportActionBar()).show();
binding.peertubeInformationContainer.setVisibility(View.VISIBLE);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
@ -671,13 +634,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
alertDialog2.show();
}
public FullScreenMediaController.fullscreen getFullscreen() {
return fullscreen;
}
public void setFullscreen(FullScreenMediaController.fullscreen fullscreen) {
this.fullscreen = fullscreen;
}
public void manageCaptions(APIResponse apiResponse) {
if (apiResponse == null || (apiResponse.getError() != null) || apiResponse.getCaptions() == null || apiResponse.getCaptions().size() == 0) {
@ -1069,7 +1025,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
if (mode != Helper.VIDEO_MODE_WEBVIEW) {
openFullscreenDialog();
}
setFullscreen(FullScreenMediaController.fullscreen.ON);
if (initialOrientation == Configuration.ORIENTATION_LANDSCAPE) {
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
ConstraintLayout.LayoutParams.MATCH_PARENT,
@ -1082,7 +1037,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
if (mode != Helper.VIDEO_MODE_WEBVIEW) {
closeFullscreenDialog();
}
setFullscreen(FullScreenMediaController.fullscreen.OFF);
if (initialOrientation == Configuration.ORIENTATION_LANDSCAPE) {
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
ConstraintLayout.LayoutParams.MATCH_PARENT,
@ -1092,7 +1046,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
binding.videoContainer.setLayoutParams(param);
}
}
change();
//change();
}
@Override
@ -1106,9 +1060,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
torrentStream.stopStream();
}
unregisterReceiver();
if (fullScreenDialog != null && fullScreenDialog.isShowing()) {
fullScreenDialog.dismiss();
}
}
@Override
@ -1152,6 +1103,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
if (player != null && isPlayInMinimized) {
if (!sharedpreferences.getBoolean(getString(R.string.set_play_screen_lock_choice), false)) {
player.setPlayWhenReady(false);
} else {
player.setWakeMode(C.WAKE_MODE_NETWORK);
}
}
}
@ -1161,15 +1114,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
private void unregisterReceiver() {
int apiLevel = Build.VERSION.SDK_INT;
if (apiLevel >= 7) {
try {
getApplicationContext().unregisterReceiver(mPowerKeyReceiver);
} catch (IllegalArgumentException e) {
mPowerKeyReceiver = null;
}
} else {
if (mPowerKeyReceiver != null) {
getApplicationContext().unregisterReceiver(mPowerKeyReceiver);
mPowerKeyReceiver = null;
}
@ -1198,25 +1143,31 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
@Override
public void onBackPressed() {
if (binding.mainOptionsVideo.getVisibility() == View.VISIBLE) {
closeMainMenuOptions();
return;
}
if (binding.postComment.getVisibility() == View.VISIBLE) {
closePostComment();
} else if (binding.replyThread.getVisibility() == View.VISIBLE) {
return;
}
if (binding.replyThread.getVisibility() == View.VISIBLE) {
closeCommentThread();
return;
}
if (playInMinimized && player != null) {
enterVideoMode();
} else {
if (playInMinimized && player != null) {
enterVideoMode();
} else {
super.onBackPressed();
}
super.onBackPressed();
}
}
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
if (isInPictureInPictureMode) {
setFullscreen(FullScreenMediaController.fullscreen.ON);
fullScreenMode = true;
} else {
setFullscreen(FullScreenMediaController.fullscreen.OFF);
fullScreenMode = false;
if (onStopCalled) {
isPlayInMinimized = false;
finishAndRemoveTask();
@ -1261,36 +1212,38 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
builderSingle.show();
}
private void initFullscreenDialog() {
private void toogleFullscreen(boolean fullscreen) {
fullScreenDialog = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen) {
public void onBackPressed() {
if (player != null && player.isPlaying() && fullScreenMode) {
player.setPlayWhenReady(false);
}
if (fullScreenMode) {
closeFullscreenDialog();
if (!Helper.isTablet(PeertubeActivity.this) && initialOrientation != Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Handler handler = new Handler();
handler.postDelayed(() -> setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR), 2000);
} else {
binding.peertubeInformationContainer.setVisibility(View.VISIBLE);
}
}
super.onBackPressed();
if (fullscreen) {
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);
binding.bottomVideo.setVisibility(View.GONE);
Objects.requireNonNull(getSupportActionBar()).hide();
if (videoOrientationType == videoOrientation.LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
};
} else {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
binding.bottomVideo.setVisibility(View.VISIBLE);
Objects.requireNonNull(getSupportActionBar()).show();
}
}
private void openFullscreenDialog() {
((ViewGroup) binding.doubleTapPlayerView.getParent()).removeView(binding.doubleTapPlayerView);
fullScreenDialog.addContentView(binding.doubleTapPlayerView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
fullScreenIcon.setImageDrawable(ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_fullscreen_exit_24));
fullScreenMode = true;
toogleFullscreen(true);
}
fullScreenDialog.show();
private void closeFullscreenDialog() {
fullScreenMode = false;
fullScreenIcon.setImageDrawable(ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_fullscreen_24));
toogleFullscreen(false);
}
public void openCommentThread(Comment comment) {
@ -1313,6 +1266,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
public void onAnimationEnd(Animation animation) {
binding.peertubeInformationContainer.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@ -1321,6 +1275,64 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
binding.replyThread.startAnimation(animate);
}
public void openMainMenuOptions() {
binding.videoParams.setVisibility(View.VISIBLE);
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
TranslateAnimation animate = new TranslateAnimation(
0,
0,
height,
height - binding.videoParams.getHeight());
animate.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
animate.setDuration(500);
binding.videoParams.startAnimation(animate);
}
public void closeMainMenuOptions() {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
TranslateAnimation animate = new TranslateAnimation(
0,
0,
height - binding.videoParams.getHeight(),
height);
animate.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
binding.videoParams.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
animate.setDuration(500);
binding.videoParams.startAnimation(animate);
}
private void sendComment(Comment comment, int position) {
if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
if (comment == null) {
@ -1480,16 +1492,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
private void closeFullscreenDialog() {
((ViewGroup) binding.doubleTapPlayerView.getParent()).removeView(binding.doubleTapPlayerView);
((FrameLayout) findViewById(R.id.main_media_frame)).addView(binding.doubleTapPlayerView);
fullScreenMode = false;
fullScreenDialog.dismiss();
fullScreenIcon.setImageDrawable(ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_fullscreen_24));
}
private void initFullscreenButton() {
private void initControllerButtons() {
PlayerControlView controlView = binding.doubleTapPlayerView.findViewById(R.id.exo_controller);
fullScreenIcon = controlView.findViewById(R.id.exo_fullscreen_icon);
@ -1497,11 +1501,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
fullScreenButton.setOnClickListener(v -> {
if (!fullScreenMode) {
openFullscreenDialog();
if (videoOrientationType == videoOrientation.LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
} else {
closeFullscreenDialog();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
@ -1510,20 +1509,25 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
});
ImageButton playButton = controlView.findViewById(R.id.exo_play);
playButton.setOnClickListener(v -> {
if (autoFullscreen && !fullScreenMode) {
openFullscreenDialog();
if (videoOrientationType == videoOrientation.LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
player.setPlayWhenReady(true);
});
View exo_next = controlView.findViewById(R.id.exo_next);
exo_next.setOnClickListener(v -> playNextVideo());
View exoSettings = controlView.findViewById(R.id.exo_settings);
exoSettings.setOnClickListener(v -> {
if (binding.videoParams.getVisibility() == View.VISIBLE) {
closeMainMenuOptions();
} else {
openMainMenuOptions();
}
});
}
private void initResolution() {
@ -1695,6 +1699,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
@Override
public void onItemClicked(MenuItemVideo.actionType action) {
}
enum videoOrientation {
LANDSCAPE,

View File

@ -0,0 +1,50 @@
package app.fedilab.fedilabtube.client;
/* 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>. */
public class MenuItemVideo {
int icon;
String title;
actionType action;
public int getIcon() {
return icon;
}
public void setIcon(int icon) {
this.icon = icon;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public actionType getAction() {
return action;
}
public void setAction(actionType action) {
this.action = action;
}
public enum actionType {
RESOLUTION
}
}

View File

@ -0,0 +1,96 @@
package app.fedilab.fedilabtube.drawer;
/* 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>. */
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import java.util.List;
import app.fedilab.fedilabtube.client.MenuItemVideo;
import app.fedilab.fedilabtube.databinding.DrawerMenuBinding;
public class MenuAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final List<MenuItemVideo> menuItemVideos;
public ItemClicked itemClicked;
private Context context;
public MenuAdapter(List<MenuItemVideo> menuItemVideos) {
this.menuItemVideos = menuItemVideos;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return menuItemVideos.size();
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
context = parent.getContext();
DrawerMenuBinding itemBinding = DrawerMenuBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
return new ViewHolder(itemBinding);
}
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int i) {
context = viewHolder.itemView.getContext();
final ViewHolder holder = (ViewHolder) viewHolder;
final MenuItemVideo menuItemVideo = menuItemVideos.get(i);
Glide.with(context).load(menuItemVideo.getIcon()).into(holder.binding.menuIcon);
holder.binding.title.setText(menuItemVideo.getTitle());
holder.binding.itemMenuContainer.setOnClickListener(v -> {
itemClicked.onItemClicked(menuItemVideo.getAction());
});
}
public interface ItemClicked {
void onItemClicked(MenuItemVideo.actionType actionType);
}
static class ViewHolder extends RecyclerView.ViewHolder {
DrawerMenuBinding binding;
ViewHolder(DrawerMenuBinding itemView) {
super(itemView.getRoot());
binding = itemView;
}
}
}

View File

@ -1,130 +0,0 @@
package app.fedilab.fedilabtube.helper;
/* 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>. */
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.MediaController;
import androidx.core.content.res.ResourcesCompat;
import app.fedilab.fedilabtube.PeertubeActivity;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.data.VideoData.Video;
/**
* Created by Thomas
* FullScreenMediaController. Inspired from the work at http://www.zoftino.com/android-videoview-playing-videos-full-screen
*/
public class FullScreenMediaController extends MediaController {
private final Context context;
private ImageButton fullScreen;
private Button resolution;
private Video peertube;
private String resolutionVal;
public FullScreenMediaController(Context context) {
super(context);
this.context = context;
}
@SuppressWarnings({"unused", "RedundantSuppression"})
public FullScreenMediaController(Context context, Video peertube) {
super(context);
this.peertube = peertube;
this.context = context;
}
@Override
public void setAnchorView(View view) {
super.setAnchorView(view);
//image button for full screen to be added to media controller
fullScreen = new ImageButton(context);
LayoutParams params =
new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.END;
params.rightMargin = 80;
params.topMargin = 22;
addView(fullScreen, params);
if (resolutionVal == null)
resolutionVal = peertube.getFiles().get(0).getResolutions().getLabel() + "p";
resolution = new Button(context);
resolution.setAllCaps(false);
resolution.setBackgroundColor(Color.TRANSPARENT);
resolution.setText(resolutionVal);
resolution.setPadding(0, 0, 0, 0);
LayoutParams paramsButton =
new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
paramsButton.gravity = Gravity.START;
paramsButton.rightMargin = 80;
paramsButton.topMargin = 22;
resolution.setOnClickListener(v -> ((PeertubeActivity) getContext()).displayResolution());
addView(resolution, paramsButton);
if (((PeertubeActivity) getContext()).getFullscreen() == fullscreen.ON) {
Resources resources = getResources();
fullScreen.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_baseline_fullscreen_exit_24, null));
} else {
Resources resources = getResources();
fullScreen.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_baseline_fullscreen_24, null));
}
//add listener to image button to handle full screen and exit full screen events
fullScreen.setOnClickListener(v -> {
if (((PeertubeActivity) getContext()).getFullscreen() == fullscreen.ON) {
((PeertubeActivity) getContext()).setFullscreen(fullscreen.OFF);
} else {
((PeertubeActivity) getContext()).setFullscreen(fullscreen.ON);
}
((PeertubeActivity) getContext()).change();
changeIcon();
});
}
@SuppressWarnings({"unused", "RedundantSuppression"})
public void setResolutionVal(String resolutionVal) {
this.resolutionVal = resolutionVal;
if (resolution != null)
resolution.setText(String.format("%sp", resolutionVal));
}
public void changeIcon() {
//fullscreen indicator from intent
if (((PeertubeActivity) getContext()).getFullscreen() == fullscreen.ON) {
Resources resources = getResources();
fullScreen.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_baseline_fullscreen_exit_24, null));
} else {
Resources resources = getResources();
fullScreen.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_baseline_fullscreen_24, null));
}
}
public enum fullscreen {
OFF,
ON
}
}

View File

@ -734,7 +734,15 @@ public class Helper {
if (video_quality == QUALITY_HIGH) {
return files.get(0);
} else if (video_quality == QUALITY_LOW) {
return files.get(files.size() - 1);
if (files.get(files.size() - 1).getResolutions().getLabel().trim().toLowerCase().compareTo("0p") != 0) {
return files.get(files.size() - 1);
} else {
if (files.size() > 1) {
return files.get(files.size() - 2);
} else {
return files.get(0);
}
}
} else {
if (files.size() < 3) {
return files.get(files.size() - 1);

View File

@ -40,6 +40,7 @@
android:layout_centerInParent="true"
android:layout_gravity="center"
android:background="#000000"
android:animateLayoutChanges="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
@ -47,6 +48,7 @@
<com.github.vkay94.dtpv.DoubleTapPlayerView
android:id="@+id/doubleTapPlayerView"
android:animateLayoutChanges="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:use_controller="true"
@ -487,4 +489,36 @@
android:background="@android:color/black"
android:visibility="gone" />
</LinearLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/video_params"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:colorBackground"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/main_options_video"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.core.widget.NestedScrollView>
<androidx.core.widget.NestedScrollView
android:id="@+id/video_params_suboptions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:colorBackground"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/sub_options_video"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_menu_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/menu_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:gravity="start|center_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/menu_icon"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -9,29 +9,36 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainMediaControllerContainer"
android:layout_gravity="bottom"
android:background="#CC000000"
android:layoutDirection="ltr"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageButton
android:id="@id/exo_settings"
style="@style/ExoStyledControls.Button.Bottom.Settings"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="4dp">
app:layout_constraintTop_toTopOf="parent">
<ImageButton
android:id="@id/exo_prev"
style="@style/ExoMediaButton.Previous" />
<ImageButton
android:id="@id/exo_rew"
style="@style/ExoMediaButton.Rewind" />
<ImageButton
android:id="@id/exo_play"
@ -41,9 +48,6 @@
android:id="@id/exo_pause"
style="@style/ExoMediaButton.Pause" />
<ImageButton
android:id="@id/exo_ffwd"
style="@style/ExoMediaButton.FastForward" />
<ImageButton
android:id="@id/exo_next"
@ -52,6 +56,10 @@
</LinearLayout>
<LinearLayout
android:id="@+id/seekbar_controller"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
@ -103,8 +111,8 @@
<ImageView
android:id="@+id/exo_fullscreen_icon"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:contentDescription="@string/fullscreen"
@ -113,4 +121,4 @@
</FrameLayout>
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -24,4 +24,5 @@
<style name="progress" parent="SpinKitView.Circle" />
<style name="progressBottom" parent="SpinKitView.ThreeBounce" />
</resources>