From 34ed36f9ae7a7f3310a0ee4aefd0b75c976431b6 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 2 Oct 2020 15:14:08 +0200 Subject: [PATCH] Fix issue --- .../fedilab/fedilabtube/PeertubeActivity.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index 1ec54f0..1c0aa91 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -19,6 +19,7 @@ import android.app.Activity; import android.app.Dialog; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.database.sqlite.SQLiteDatabase; @@ -29,6 +30,7 @@ import android.os.Build; import android.os.Bundle; import android.support.v4.media.session.MediaSessionCompat; import android.text.Html; +import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -56,6 +58,7 @@ import androidx.appcompat.widget.PopupMenu; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; +import androidx.core.view.WindowCompat; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -187,8 +190,10 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); - Account account = new AccountDAO(PeertubeActivity.this, db).getAccountByToken(token); - Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, my_pp); + if( Helper.isLoggedIn(PeertubeActivity.this)) { + Account account = new AccountDAO(PeertubeActivity.this, db).getAccountByToken(token); + Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, my_pp); + } if (Helper.isTablet(PeertubeActivity.this)) { @@ -243,6 +248,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd getWindow().setAttributes(attrs); getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); peertube_information_container.setVisibility(View.GONE); + setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + WindowCompat.setDecorFitsSystemWindows(getWindow(), false); } else { WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN; @@ -251,6 +258,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); videoLayout.setVisibility(View.GONE); peertube_information_container.setVisibility(View.VISIBLE); + WindowCompat.setDecorFitsSystemWindows(getWindow(), true); } }); webview_video.getSettings().setAllowFileAccess(true); @@ -315,11 +323,13 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); Objects.requireNonNull(getSupportActionBar()).hide(); peertube_information_container.setVisibility(View.GONE); + WindowCompat.setDecorFitsSystemWindows(getWindow(), true); } 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); + WindowCompat.setDecorFitsSystemWindows(getWindow(), false); } } @@ -771,6 +781,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd @Override public void onConfigurationChanged(@NotNull Configuration newConfig) { super.onConfigurationChanged(newConfig); + Log.v(Helper.TAG,"onConfigurationChanged: " + newConfig.orientation); if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { if (mode != Helper.VIDEO_MODE_WEBVIEW) { openFullscreenDialog(); @@ -958,8 +969,9 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd fullScreenDialog = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen) { public void onBackPressed() { - if (fullScreenMode) + if (fullScreenMode) { closeFullscreenDialog(); + } super.onBackPressed(); } }; @@ -990,18 +1002,19 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd fullScreenIcon = controlView.findViewById(R.id.exo_fullscreen_icon); View fullScreenButton = controlView.findViewById(R.id.exo_fullscreen_button); fullScreenButton.setOnClickListener(v -> { - if (!fullScreenMode) + if (!fullScreenMode) { openFullscreenDialog(); - else + setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + }else { closeFullscreenDialog(); + } }); } private void initResolution() { - //TODO: add in settings a way to pick up the lower/medium/Highest resolution and init it there PlayerControlView controlView = playerView.findViewById(R.id.exo_controller); resolution = controlView.findViewById(R.id.resolution); - resolution.setText(String.format("%s", peertube.getFiles().get(0).getResolutions().getLabel())); + resolution.setText(String.format("%s", Helper.defaultFile(PeertubeActivity.this, peertube.getFiles()).getResolutions().getLabel())); resolution.setOnClickListener(v -> displayResolution()); }