From 9fa7a3bbc7cbaa11ff3cfabf60a6710d5ea8b22d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Schu=CC=88ller?= Date: Sun, 6 Jan 2019 02:22:55 +0100 Subject: [PATCH] - Moved video playback into fragment --- .../peertube/activity/VideoPlayActivity.java | 101 ++++++------------ .../fragment/VideoMetaDataFragment.java | 17 +++ .../fragment/VideoPlayerFragment.java | 17 +++ 3 files changed, 65 insertions(+), 70 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java index eb80540..d0022f5 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -18,73 +18,34 @@ package net.schueller.peertube.activity; -import android.app.Activity; -import android.content.ComponentName; -import android.content.Context; + import android.content.Intent; -import android.content.ServiceConnection; import android.content.SharedPreferences; -import android.content.pm.ActivityInfo; import android.content.res.Configuration; -import android.net.Uri; import android.os.Bundle; -import android.os.Environment; -import android.os.IBinder; import android.preference.PreferenceManager; -import androidx.annotation.NonNull; + import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.PopupMenu; + import android.util.Log; import android.util.TypedValue; -import android.view.Surface; -import android.view.View; -import android.view.ViewGroup; -import android.view.WindowManager; -import android.widget.Button; -import android.widget.FrameLayout; -import android.widget.ImageButton; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.RelativeLayout; -import android.widget.TextView; -import android.widget.Toast; -import com.github.se_bastiaan.torrentstream.StreamStatus; -import com.github.se_bastiaan.torrentstream.Torrent; -import com.github.se_bastiaan.torrentstream.TorrentOptions; -import com.github.se_bastiaan.torrentstream.TorrentStream; -import com.github.se_bastiaan.torrentstream.listeners.TorrentListener; -import com.google.android.exoplayer2.Format; -import com.google.android.exoplayer2.decoder.DecoderCounters; -import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; -import com.google.android.exoplayer2.ui.PlayerView; -import com.google.android.exoplayer2.util.Util; -import com.google.android.exoplayer2.video.VideoRendererEventListener; -import com.mikepenz.iconics.Iconics; -import com.squareup.picasso.Picasso; +import android.view.WindowManager; +import android.widget.FrameLayout; + +import android.widget.RelativeLayout; + import net.schueller.peertube.R; -import net.schueller.peertube.fragment.VideoMetaDataFragment; -import net.schueller.peertube.fragment.VideoOptionsFragment; import net.schueller.peertube.fragment.VideoPlayerFragment; -import net.schueller.peertube.helper.APIUrlHelper; -import net.schueller.peertube.helper.MetaDataHelper; -import net.schueller.peertube.intents.Intents; -import net.schueller.peertube.model.Account; -import net.schueller.peertube.model.Avatar; -import net.schueller.peertube.model.Video; -import net.schueller.peertube.network.GetVideoDataService; -import net.schueller.peertube.network.RetrofitInstance; -import net.schueller.peertube.service.VideoPlayerService; + +import java.util.Objects; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; -import static net.schueller.peertube.helper.Constants.BACKGROUND_PLAY_PREF_KEY; + +//import static net.schueller.peertube.helper.Constants.BACKGROUND_PLAY_PREF_KEY; import static net.schueller.peertube.helper.Constants.DEFAULT_THEME; import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; @@ -121,7 +82,6 @@ public class VideoPlayActivity extends AppCompatActivity { } - @Override public void onConfigurationChanged(Configuration newConfig) { @@ -132,39 +92,40 @@ public class VideoPlayActivity extends AppCompatActivity { FragmentManager fragmentManager = getSupportFragmentManager(); Fragment videoPlayerFragment = fragmentManager.findFragmentById(R.id.video_player_fragment); - -// LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT); -// params.weight = 3.0f; -// fragment.getView().setLayoutParams(params); + Fragment videoMetaFragment = fragmentManager.findFragmentById(R.id.video_meta_data_fragment); // Checking the orientation of the screen if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) videoPlayerFragment.getView().getLayoutParams(); + assert videoPlayerFragment != null; + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) Objects.requireNonNull(videoPlayerFragment.getView()).getLayoutParams(); params.width = FrameLayout.LayoutParams.MATCH_PARENT; params.height = FrameLayout.LayoutParams.MATCH_PARENT; - //simpleExoPlayerView.setLayoutParams(params); - videoPlayerFragment.getView().setLayoutParams(params); - fragmentManager.beginTransaction() - .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out) - .hide(fragmentManager.findFragmentById(R.id.video_meta_data_fragment)) - .commit(); + if (videoMetaFragment != null) { + fragmentManager.beginTransaction() + .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out) + .hide(videoMetaFragment) + .commit(); + } getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) videoPlayerFragment.getView().getLayoutParams(); + + assert videoPlayerFragment != null; + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) Objects.requireNonNull(videoPlayerFragment.getView()).getLayoutParams(); params.width = FrameLayout.LayoutParams.MATCH_PARENT; params.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250, getResources().getDisplayMetrics()); - //simpleExoPlayerView.setLayoutParams(params); - videoPlayerFragment.getView().setLayoutParams(params); - fragmentManager.beginTransaction() - .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out) - .show(fragmentManager.findFragmentById(R.id.video_meta_data_fragment)) - .commit(); + + if (videoMetaFragment != null) { + fragmentManager.beginTransaction() + .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out) + .show(videoMetaFragment) + .commit(); + } getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); } diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java index 0a717f2..f97ebf7 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java @@ -1,3 +1,20 @@ +/* + * Copyright 2018 Stefan Schüller + * + * License: GPL-3.0+ + * 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. + * + * This program 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 this program. If not, see . + */ package net.schueller.peertube.fragment; import android.Manifest; diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java index c234598..4bdc28a 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java @@ -1,3 +1,20 @@ +/* + * Copyright 2018 Stefan Schüller + * + * License: GPL-3.0+ + * 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. + * + * This program 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 this program. If not, see . + */ package net.schueller.peertube.fragment; import android.app.Activity;