From 8d7063ee78e46264d8294a7ffcd8c020b5a3ea7d Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sat, 4 Jul 2020 22:30:00 +0200 Subject: [PATCH 01/19] Added VideoPlayerService#getPlayBackSpeed --- .../schueller/peertube/service/VideoPlayerService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java index d3aa9a8..b01ab4d 100644 --- a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java +++ b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java @@ -178,11 +178,18 @@ public class VideoPlayerService extends Service { //Playback speed control public void setPlayBackSpeed(float speed) { - Log.v(TAG, "setPlayBackSpeed..."); player.setPlaybackParameters(new PlaybackParameters(speed)); } + /** + * Returns the current playback speed of the player. + * @return the current playback speed of the player. + */ + public float getPlayBackSpeed() { + return player.getPlaybackParameters().speed; + } + public void playVideo() { Context context = this; From 70593c17ee201b6936f6aeb77d172d4b5b4eaeae Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sat, 4 Jul 2020 22:30:58 +0200 Subject: [PATCH 02/19] Added preview of the current playback speed and video quality in the VideoOptionsFragment --- .../peertube/fragment/VideoOptionsFragment.java | 17 +++++++++++++++-- app/src/main/res/values-ar/strings.xml | 6 +++--- app/src/main/res/values-bn/strings.xml | 4 ++-- app/src/main/res/values-de/strings.xml | 4 ++-- app/src/main/res/values-es/strings.xml | 4 ++-- app/src/main/res/values-fi/strings.xml | 4 ++-- app/src/main/res/values-fr/strings.xml | 4 ++-- app/src/main/res/values-gd/strings.xml | 4 ++-- app/src/main/res/values-it/strings.xml | 4 ++-- app/src/main/res/values-ja/strings.xml | 4 ++-- app/src/main/res/values-nb-rNO/strings.xml | 4 ++-- app/src/main/res/values-nl/strings.xml | 4 ++-- app/src/main/res/values-pl/strings.xml | 4 ++-- app/src/main/res/values-ru/strings.xml | 4 ++-- app/src/main/res/values-sv/strings.xml | 4 ++-- app/src/main/res/values-tr/strings.xml | 4 ++-- app/src/main/res/values-zh-rCN/strings.xml | 4 ++-- app/src/main/res/values-zh-rTW/strings.xml | 4 ++-- app/src/main/res/values/strings.xml | 4 ++-- 19 files changed, 52 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java index 212c2d2..01da654 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java @@ -18,7 +18,9 @@ package net.schueller.peertube.fragment; import android.annotation.SuppressLint; +import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -65,7 +67,7 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment { LinearLayout menuRow = (LinearLayout) inflater.inflate(R.layout.row_popup_menu, null); TextView iconView = menuRow.findViewById(R.id.video_quality_icon); TextView textView = menuRow.findViewById(R.id.video_quality_text); - textView.setText(getString(R.string.menu_video_options_playback_speed)); + textView.setText(String.format(getString(R.string.menu_video_options_playback_speed), videoPlayerService.getPlayBackSpeed())); iconView.setText(R.string.video_option_speed_icon); new Iconics.IconicsBuilder().ctx(getContext()).on(iconView).build(); textView.setOnClickListener(view1 -> { @@ -80,7 +82,7 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment { LinearLayout menuRow2 = (LinearLayout) inflater.inflate(R.layout.row_popup_menu, null); TextView iconView2 = menuRow2.findViewById(R.id.video_quality_icon); TextView textView2 = menuRow2.findViewById(R.id.video_quality_text); - textView2.setText(getString(R.string.menu_video_options_quality)); + textView2.setText(String.format(getString(R.string.menu_video_options_quality), getCurrentVideoQuality(files))); iconView2.setText(R.string.video_option_quality_icon); new Iconics.IconicsBuilder().ctx(getContext()).on(iconView2).build(); textView2.setOnClickListener(view1 -> { @@ -95,4 +97,15 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment { } + private String getCurrentVideoQuality(ArrayList files) { + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); + Integer videoQuality = sharedPref.getInt("pref_quality", 0); + + for (File file : files) { + if (videoQuality.equals(file.getResolution().getId())) { + return file.getResolution().getLabel(); + } + } + return "Auto"; + } } \ No newline at end of file diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 571c662..fbb0413 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -143,9 +143,9 @@ الرخصة اللغة العلامات - سرعة التشغيل - الجودة - الفيديو + سرعة التشغيل + (%s) الجودة + الفيديو (s%) القنوات حول الحساب: diff --git a/app/src/main/res/values-bn/strings.xml b/app/src/main/res/values-bn/strings.xml index 0420e84..5fa6e20 100644 --- a/app/src/main/res/values-bn/strings.xml +++ b/app/src/main/res/values-bn/strings.xml @@ -285,8 +285,8 @@ গাঢ় বেগুনি অ্যাকাউন্ট সাম্প্রতিক - প্লেব্যাক এর গতি - কোয়ালিটি + প্লেব্যাক এর গতি (%s) + কোয়ালিটি (%s) ভিডিও চ্যানেলগুলি সম্পর্কিত diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index aae549c..8171a43 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -276,8 +276,8 @@ Lizenz Sprache Tags - Wiedergabegeschwindigkeit - Qualität + Wiedergabegeschwindigkeit (%s) + Qualität (%s) Videos Kanäle Über diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 8c61319..c34ccb4 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -96,8 +96,8 @@ Licencia Idioma Etiquetas - Velocidad de reproducción - Calidad + Velocidad de reproducción (%s) + Calidad (%s) Vídeos Canales Acerca de diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 78b7b91..8071156 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -103,7 +103,7 @@ maori oriya (makrokieli) bislama - Laatu + Laatu (%s) Jotain meni pieleen, yritä myöhemmin! bulgaria uzbekki @@ -204,7 +204,7 @@ navajo kanuri sunda - Toistonopeus + Toistonopeus (%s) sichuanin-yi Punainen Videon esikatselukuva diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index d1dab69..a39fbef 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -99,8 +99,8 @@ Licence Langue Étiquettes - Vitesse de lecture - Qualité + Vitesse de lecture (%s) + Qualité (%s) Vidéos Chaînes À propos diff --git a/app/src/main/res/values-gd/strings.xml b/app/src/main/res/values-gd/strings.xml index d338263..69b4a36 100644 --- a/app/src/main/res/values-gd/strings.xml +++ b/app/src/main/res/values-gd/strings.xml @@ -285,8 +285,8 @@ Ceadachas Cànan Tagaichean - Luaths na cluiche - Càileachd + Luaths na cluiche (%s) + Càileachd (%s) Videothan Seanailean Mu dhèidhinn diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 9f0d2e8..7c482cf 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -286,8 +286,8 @@ Licenza Lingua Parole chiave - Velocità di riproduzione - Qualità + Velocità di riproduzione (%s) + Qualità (%s) Video Canali A proposito diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index c9616a4..f993ef9 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -88,8 +88,8 @@ ラインセンス 言語 タグ - 再生速度 - クオリティ + 再生速度 (%s) + クオリティ(%s) ビデオ チャンネル 情報 diff --git a/app/src/main/res/values-nb-rNO/strings.xml b/app/src/main/res/values-nb-rNO/strings.xml index abfcf6f..8288fd7 100644 --- a/app/src/main/res/values-nb-rNO/strings.xml +++ b/app/src/main/res/values-nb-rNO/strings.xml @@ -51,8 +51,8 @@ Lisens Språk Etiketter - Avspillingshastighet - Kvalitet + Avspillingshastighet (%s) + Kvalitet (%s) Videoer Kanaler Om diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 591194e..97f079d 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -275,8 +275,8 @@ Licentie Taal Labels - Afspeelsnelheid - Kwaliteit + Afspeelsnelheid (%s) + Kwaliteit (%s) Video\'s Kanalen Over diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 9367e80..3cc2890 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -48,8 +48,8 @@ Konto: Kanały Filmy - Jakość - Prędkość odtwarzania + Jakość (%s) + Prędkość odtwarzania (%s) Znaczniki Język Licencja diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 2807285..719be8e 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -277,8 +277,8 @@ Лицензия Язык Теги - Скорость воспроизведения - Качество + Скорость воспроизведения (%s) + Качество (%s) Описание: Что-то пошло не так, пожалуйста, попробуйте позже! Выберите сервер diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 6a7f958..f3989a9 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -272,8 +272,8 @@ Licens Språk Taggar - Uppspelningshastighet - Kvalitet + Uppspelningshastighet (%s) + Kvalitet (%s) Videor Kanaler Om diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index dcb7795..77350d6 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -291,8 +291,8 @@ Lisans Dil Etiketler - Oynatma hızı - Kalite + Oynatma hızı (%s) + Kalite (%s) Hesap Yeniler diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 91e491e..e7835eb 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -112,8 +112,8 @@ 类别 许可 标签 - 播放速度 - 画质 + 播放速度 (%s) + 画质 (%s) 视频 频道 关于 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 039b46c..b8c74d4 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -279,8 +279,8 @@ 授權條款 語言 標籤 - 播放速度 - 畫質 + 播放速度 (%s) + 畫質 (%s) 影片 頻道 關於 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 543c2a3..4bee5e8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -324,8 +324,8 @@ License Language Tags - Playback speed - Quality + Playback speed (%s) + Quality (%s) Videos Channels About From fd3a7c87d1f9c2181876a88a5d35b540b4ef07b1 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sat, 4 Jul 2020 22:46:52 +0200 Subject: [PATCH 03/19] Fixed typo in ar strings.xml --- app/src/main/res/values-ar/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index fbb0413..cf2e631 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -143,9 +143,9 @@ الرخصة اللغة العلامات - سرعة التشغيل + سرعة التشغيل (s%) (%s) الجودة - الفيديو (s%) + الفيديو القنوات حول الحساب: From d631193311d1d56befaf26555a2f4fea1eb6628d Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sun, 5 Jul 2020 09:38:03 +0200 Subject: [PATCH 04/19] Made the "Automated" video quality translatable --- .../peertube/fragment/VideoMenuQualityFragment.java | 5 +++-- .../schueller/peertube/fragment/VideoOptionsFragment.java | 5 +++-- app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoMenuQualityFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoMenuQualityFragment.java index 45420d9..da55956 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoMenuQualityFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoMenuQualityFragment.java @@ -17,6 +17,7 @@ */ package net.schueller.peertube.fragment; +import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; @@ -44,7 +45,7 @@ public class VideoMenuQualityFragment extends BottomSheetDialogFragment { public static final String TAG = "VideoMenuQuality"; private static File autoQualityFile; - public static VideoMenuQualityFragment newInstance(ArrayList files) { + public static VideoMenuQualityFragment newInstance(Context context, ArrayList files) { mFiles = files; @@ -53,7 +54,7 @@ public class VideoMenuQualityFragment extends BottomSheetDialogFragment { autoQualityFile = new File(); Resolution autoQualityResolution = new Resolution(); autoQualityResolution.setId(0); - autoQualityResolution.setLabel("Auto"); + autoQualityResolution.setLabel(context.getString(R.string.menu_video_options_quality_automated)); autoQualityFile.setId(0); autoQualityFile.setResolution(autoQualityResolution); } diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java index 01da654..f27080c 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java @@ -87,7 +87,7 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment { new Iconics.IconicsBuilder().ctx(getContext()).on(iconView2).build(); textView2.setOnClickListener(view1 -> { VideoMenuQualityFragment videoMenuQualityFragment = - VideoMenuQualityFragment.newInstance(files); + VideoMenuQualityFragment.newInstance(getContext(), files); videoMenuQualityFragment.show(getActivity().getSupportFragmentManager(), videoMenuQualityFragment.TAG); }); @@ -106,6 +106,7 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment { return file.getResolution().getLabel(); } } - return "Auto"; + // Returning Automated as a placeholder + return getString(R.string.menu_video_options_quality_automated); } } \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index a39fbef..52397c7 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -343,4 +343,5 @@ Sélectionner un serveur Retirer un serveur Voulez-vous vraiment retirer ce serveur de votre carnet d\'adresses ? + Automatique \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4bee5e8..f000c8c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -384,6 +384,7 @@ pref_token_type pref_auth_username pref_auth_password + Automated \ No newline at end of file From 9a91c2140adb7bf3c6f3263675ebd9ddadccc9a9 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sun, 5 Jul 2020 11:07:35 +0200 Subject: [PATCH 05/19] Made use of existing strings for the video speed display --- .../peertube/fragment/VideoOptionsFragment.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java index f27080c..08c54c6 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java @@ -37,6 +37,7 @@ import net.schueller.peertube.service.VideoPlayerService; import java.util.ArrayList; import androidx.annotation.Nullable; +import androidx.annotation.StringRes; public class VideoOptionsFragment extends BottomSheetDialogFragment { @@ -67,7 +68,7 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment { LinearLayout menuRow = (LinearLayout) inflater.inflate(R.layout.row_popup_menu, null); TextView iconView = menuRow.findViewById(R.id.video_quality_icon); TextView textView = menuRow.findViewById(R.id.video_quality_text); - textView.setText(String.format(getString(R.string.menu_video_options_playback_speed), videoPlayerService.getPlayBackSpeed())); + textView.setText(String.format(getString(R.string.menu_video_options_playback_speed), getCurrentVideoPlaybackSpeedString(videoPlayerService.getPlayBackSpeed()))); iconView.setText(R.string.video_option_speed_icon); new Iconics.IconicsBuilder().ctx(getContext()).on(iconView).build(); textView.setOnClickListener(view1 -> { @@ -109,4 +110,14 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment { // Returning Automated as a placeholder return getString(R.string.menu_video_options_quality_automated); } + + private String getCurrentVideoPlaybackSpeedString(float playbackSpeed) { + String speed = String.valueOf(playbackSpeed); + // Remove all non-digit characters from the string + speed = speed.replaceAll("[^0-9]", ""); + + // Dynamically get the localized string corresponding to the speed + @StringRes int stringId = getResources().getIdentifier("video_speed_" + speed, "string", videoPlayerService.getPackageName()); + return getString(stringId); + } } \ No newline at end of file From b2a8cf857da14f92df726c37468b921af65feca1 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sun, 5 Jul 2020 11:07:57 +0200 Subject: [PATCH 06/19] Removed unusued imports in VideoOptionsFragment.java --- .../net/schueller/peertube/fragment/VideoOptionsFragment.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java index 08c54c6..2e9c3b4 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java @@ -17,11 +17,9 @@ */ package net.schueller.peertube.fragment; -import android.annotation.SuppressLint; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; From 9609447aaef02456f314c18bd7cd52d4d5d70764 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sun, 5 Jul 2020 11:52:40 +0200 Subject: [PATCH 07/19] Automated code cleanup in VideoPlayActivity Removed unused imports, redundancy, useless checks ; code formatting --- .../peertube/activity/VideoPlayActivity.java | 71 ++++++------------- 1 file changed, 23 insertions(+), 48 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 f241d8b..7df9ca5 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -56,9 +56,9 @@ import net.schueller.peertube.service.VideoPlayerService; import java.util.ArrayList; -import java.util.Objects; import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; //import static net.schueller.peertube.helper.Constants.BACKGROUND_PLAY_PREF_KEY; @@ -119,8 +119,8 @@ public class VideoPlayActivity extends AppCompatActivity { .setActions(actions) .build(); setPictureInPictureParams(params); - } + public void changedToPipMode() { FragmentManager fragmentManager = getSupportFragmentManager(); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); @@ -164,6 +164,7 @@ public class VideoPlayActivity extends AppCompatActivity { floatMode=true; videoPlayerFragment.showControls(false); } + public void changedToNormalMode(){ FragmentManager fragmentManager = getSupportFragmentManager(); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); @@ -175,6 +176,7 @@ public class VideoPlayActivity extends AppCompatActivity { Log.v(TAG,"switched to normal"); floatMode=false; } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -226,7 +228,6 @@ public class VideoPlayActivity extends AppCompatActivity { assert videoPlayerFragment != null; String videoUuid = intent.getStringExtra(VideoListActivity.EXTRA_VIDEOID); Log.v(TAG, "new intent click: " + videoUuid +" is trying to replace: "+videoPlayerFragment.getVideoUuid()); - assert videoPlayerFragment != null; String playingVideo = videoPlayerFragment.getVideoUuid(); if (TextUtils.isEmpty(playingVideo)){ @@ -245,12 +246,10 @@ public class VideoPlayActivity extends AppCompatActivity { if (orientation == Configuration.ORIENTATION_LANDSCAPE) { setOrientation(true); } - } @Override public void onConfigurationChanged(Configuration newConfig) { - Log.v(TAG, "onConfigurationChanged()..."); super.onConfigurationChanged(newConfig); @@ -263,58 +262,43 @@ public class VideoPlayActivity extends AppCompatActivity { } } - - private void setOrientation(Boolean isLandscape) { - FragmentManager fragmentManager = getSupportFragmentManager(); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); VideoMetaDataFragment videoMetaFragment = (VideoMetaDataFragment) fragmentManager.findFragmentById(R.id.video_meta_data_fragment); - if (isLandscape) { - 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; - videoPlayerFragment.getView().setLayoutParams(params); + assert videoPlayerFragment != null; + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) videoPlayerFragment.requireView().getLayoutParams(); + params.width = FrameLayout.LayoutParams.MATCH_PARENT; + params.height = isLandscape ? FrameLayout.LayoutParams.MATCH_PARENT : (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250, getResources().getDisplayMetrics()); + videoPlayerFragment.getView().setLayoutParams(params); - if (videoMetaFragment != null) { - fragmentManager.beginTransaction() - .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out) - .hide(videoMetaFragment) - .commit(); + if (videoMetaFragment != null) { + FragmentTransaction transaction = fragmentManager.beginTransaction() + .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out); + + if (isLandscape) { + transaction.hide(videoMetaFragment); + } else { + transaction.show(videoMetaFragment); } - videoPlayerFragment.setIsFullscreen(true); - } else { - 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()); - videoPlayerFragment.getView().setLayoutParams(params); - - if (videoMetaFragment != null) { - fragmentManager.beginTransaction() - .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out) - .show(videoMetaFragment) - .commit(); - } - videoPlayerFragment.setIsFullscreen(false); + transaction.commit(); } + videoPlayerFragment.setIsFullscreen(isLandscape); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); } @Override protected void onDestroy() { - VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) getSupportFragmentManager().findFragmentById(R.id.video_player_fragment); assert videoPlayerFragment != null; videoPlayerFragment.destroyVideo(); - super.onDestroy(); Log.v(TAG, "onDestroy..."); } @@ -335,15 +319,6 @@ public class VideoPlayActivity extends AppCompatActivity { protected void onStop() { super.onStop(); -// SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); -// -// Log.v(TAG, "" + sharedPref.getBoolean(BACKGROUND_PLAY_PREF_KEY, false)); -// -// if (!sharedPref.getBoolean(BACKGROUND_PLAY_PREF_KEY, false)) { -// Log.v(TAG, "BACKGROUND_PLAY_PREF_KEY..."); -// stopService(new Intent(this, VideoPlayerService.class)); -// } - VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) getSupportFragmentManager().findFragmentById(R.id.video_player_fragment); @@ -366,7 +341,6 @@ public class VideoPlayActivity extends AppCompatActivity { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); FragmentManager fragmentManager = getSupportFragmentManager(); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); - VideoMetaDataFragment videoMetaFragment = (VideoMetaDataFragment) fragmentManager.findFragmentById(R.id.video_meta_data_fragment); String backgroundBehavior = sharedPref.getString("pref_background_behavior","backgroundStop"); switch(backgroundBehavior){ @@ -397,7 +371,6 @@ public class VideoPlayActivity extends AppCompatActivity { // @RequiresApi(api = Build.VERSION_CODES.O) @SuppressLint("NewApi") public void onBackPressed() { - SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) getSupportFragmentManager().findFragmentById(R.id.video_player_fragment); @@ -410,7 +383,6 @@ public class VideoPlayActivity extends AppCompatActivity { } if (sharedPref.getBoolean("pref_back_pause", true)) { - assert videoPlayerFragment != null; videoPlayerFragment.pauseVideo(); } @@ -452,6 +424,7 @@ public class VideoPlayActivity extends AppCompatActivity { } Log.v(TAG, "onBackPressed()..."); } + public boolean canEnterPipMode(Context context) { Log.v(TAG,"api version "+Build.VERSION.SDK_INT); if (Build.VERSION.SDK_INT<28){ @@ -460,6 +433,7 @@ public class VideoPlayActivity extends AppCompatActivity { AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); return (AppOpsManager.MODE_ALLOWED== appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_PICTURE_IN_PICTURE, android.os.Process.myUid(), context.getPackageName())); } + @RequiresApi(api = Build.VERSION_CODES.O) public void enterPipMode() { Rational rational = new Rational(239, 100); @@ -472,6 +446,7 @@ public class VideoPlayActivity extends AppCompatActivity { enterPictureInPictureMode(mParams); } + @Override public void onPictureInPictureModeChanged (boolean isInPictureInPictureMode, Configuration newConfig) { FragmentManager fragmentManager = getSupportFragmentManager(); From ded16379f12c2cf11884960192a57123f399feff Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Sun, 5 Jul 2020 13:16:50 +0200 Subject: [PATCH 08/19] Code Format --- .../peertube/activity/VideoPlayActivity.java | 90 +++++++++---------- 1 file changed, 45 insertions(+), 45 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 7df9ca5..e705a45 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -61,7 +61,6 @@ import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; -//import static net.schueller.peertube.helper.Constants.BACKGROUND_PLAY_PREF_KEY; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PAUSE; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PLAY; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_STOP; @@ -76,6 +75,7 @@ public class VideoPlayActivity extends AppCompatActivity { private static boolean floatMode = false; private static final int REQUEST_CODE = 101; private BroadcastReceiver receiver; + //This can only be called when in entering pip mode which can't happen if the device doesn't support pip mode. @SuppressLint("NewApi") public void makePipControls() { @@ -96,15 +96,15 @@ public class VideoPlayActivity extends AppCompatActivity { remoteAction = new RemoteAction(icon, "play", "stop the media", pendingIntent); actions.add(remoteAction); - if (videoPlayerFragment.isPaused()){ - Log.e(TAG,"setting actions with play button"); + if (videoPlayerFragment.isPaused()) { + Log.e(TAG, "setting actions with play button"); actionIntent = new Intent(ACTION_PLAY); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0); icon = Icon.createWithResource(getApplicationContext(), com.google.android.exoplayer2.ui.R.drawable.exo_notification_play); remoteAction = new RemoteAction(icon, "play", "play the media", pendingIntent); actions.add(remoteAction); } else { - Log.e(TAG,"setting actions with pause button"); + Log.e(TAG, "setting actions with pause button"); actionIntent = new Intent(ACTION_PAUSE); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0); icon = Icon.createWithResource(getApplicationContext(), com.google.android.exoplayer2.ui.R.drawable.exo_notification_pause); @@ -161,11 +161,11 @@ public class VideoPlayActivity extends AppCompatActivity { registerReceiver(receiver, filter); Log.v(TAG, "switched to pip "); - floatMode=true; + floatMode = true; videoPlayerFragment.showControls(false); } - public void changedToNormalMode(){ + public void changedToNormalMode() { FragmentManager fragmentManager = getSupportFragmentManager(); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); @@ -173,8 +173,8 @@ public class VideoPlayActivity extends AppCompatActivity { if (receiver != null) { unregisterReceiver(receiver); } - Log.v(TAG,"switched to normal"); - floatMode=false; + Log.v(TAG, "switched to normal"); + floatMode = false; } @Override @@ -199,17 +199,17 @@ public class VideoPlayActivity extends AppCompatActivity { assert videoPlayerFragment != null; String playingVideo = videoPlayerFragment.getVideoUuid(); - Log.v(TAG, "oncreate click: " + videoUuid +" is trying to replace: "+playingVideo); + Log.v(TAG, "oncreate click: " + videoUuid + " is trying to replace: " + playingVideo); - if (TextUtils.isEmpty(playingVideo)){ - Log.v(TAG,"oncreate no video currently playing"); + if (TextUtils.isEmpty(playingVideo)) { + Log.v(TAG, "oncreate no video currently playing"); videoPlayerFragment.start(videoUuid); - } else if(!playingVideo.equals(videoUuid)){ - Log.v(TAG,"oncreate different video playing currently"); + } else if (!playingVideo.equals(videoUuid)) { + Log.v(TAG, "oncreate different video playing currently"); videoPlayerFragment.stopVideo(); videoPlayerFragment.start(videoUuid); } else { - Log.v(TAG,"oncreate same video playing currently"); + Log.v(TAG, "oncreate same video playing currently"); } // if we are in landscape set the video to fullscreen @@ -227,18 +227,18 @@ public class VideoPlayActivity extends AppCompatActivity { getSupportFragmentManager().findFragmentById(R.id.video_player_fragment); assert videoPlayerFragment != null; String videoUuid = intent.getStringExtra(VideoListActivity.EXTRA_VIDEOID); - Log.v(TAG, "new intent click: " + videoUuid +" is trying to replace: "+videoPlayerFragment.getVideoUuid()); + Log.v(TAG, "new intent click: " + videoUuid + " is trying to replace: " + videoPlayerFragment.getVideoUuid()); String playingVideo = videoPlayerFragment.getVideoUuid(); - if (TextUtils.isEmpty(playingVideo)){ - Log.v(TAG,"new intent no video currently playing"); + if (TextUtils.isEmpty(playingVideo)) { + Log.v(TAG, "new intent no video currently playing"); videoPlayerFragment.start(videoUuid); - } else if(!playingVideo.equals(videoUuid)){ - Log.v(TAG,"new intent different video playing currently"); + } else if (!playingVideo.equals(videoUuid)) { + Log.v(TAG, "new intent different video playing currently"); videoPlayerFragment.stopVideo(); videoPlayerFragment.start(videoUuid); } else { - Log.v(TAG,"new intent same video playing currently"); + Log.v(TAG, "new intent same video playing currently"); } // if we are in landscape set the video to fullscreen @@ -337,25 +337,25 @@ public class VideoPlayActivity extends AppCompatActivity { @SuppressLint("NewApi") @Override - public void onUserLeaveHint () { + public void onUserLeaveHint() { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); FragmentManager fragmentManager = getSupportFragmentManager(); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); - String backgroundBehavior = sharedPref.getString("pref_background_behavior","backgroundStop"); + String backgroundBehavior = sharedPref.getString("pref_background_behavior", "backgroundStop"); - switch(backgroundBehavior){ + switch (backgroundBehavior) { case "backgroundStop": - Log.v(TAG,"stop the video"); + Log.v(TAG, "stop the video"); videoPlayerFragment.pauseVideo(); stopService(new Intent(this, VideoPlayerService.class)); super.onBackPressed(); break; case "backgroundAudio": - Log.v(TAG,"play the Audio"); + Log.v(TAG, "play the Audio"); super.onBackPressed(); break; case "backgroundFloat": - Log.v(TAG,"play in floating video"); + Log.v(TAG, "play in floating video"); //canEnterPIPMode makes sure API level is high enough if (canEnterPipMode(this)) { Log.v(TAG, "enabling pip"); @@ -368,7 +368,7 @@ public class VideoPlayActivity extends AppCompatActivity { Log.v(TAG, "onUserLeaveHint()..."); } - // @RequiresApi(api = Build.VERSION_CODES.O) + // @RequiresApi(api = Build.VERSION_CODES.O) @SuppressLint("NewApi") public void onBackPressed() { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); @@ -376,8 +376,8 @@ public class VideoPlayActivity extends AppCompatActivity { getSupportFragmentManager().findFragmentById(R.id.video_player_fragment); //copying Youtube behavior to have back button exit full screen. - if (videoPlayerFragment.getIsFullscreen()){ - Log.v(TAG,"exiting full screen"); + if (videoPlayerFragment.getIsFullscreen()) { + Log.v(TAG, "exiting full screen"); videoPlayerFragment.fullScreenToggle(); return; } @@ -386,24 +386,24 @@ public class VideoPlayActivity extends AppCompatActivity { videoPlayerFragment.pauseVideo(); } - String backgroundBehavior = sharedPref.getString("pref_background_behavior","backgroundStop"); + String backgroundBehavior = sharedPref.getString("pref_background_behavior", "backgroundStop"); // Log.v(TAG,"backgroundBehavior: " + backgroundBehavior); - switch (backgroundBehavior){ + switch (backgroundBehavior) { case "backgroundStop": - Log.v(TAG,"stop the video"); + Log.v(TAG, "stop the video"); videoPlayerFragment.pauseVideo(); stopService(new Intent(this, VideoPlayerService.class)); super.onBackPressed(); break; case "backgroundAudio": - Log.v(TAG,"play the Audio"); - super.onBackPressed(); - break; + Log.v(TAG, "play the Audio"); + super.onBackPressed(); + break; case "backgroundFloat": - Log.v(TAG,"play in floating video"); + Log.v(TAG, "play in floating video"); //canEnterPIPMode makes sure API level is high enough if (canEnterPipMode(this)) { Log.v(TAG, "enabling pip"); @@ -412,13 +412,13 @@ public class VideoPlayActivity extends AppCompatActivity { Intent intentSettings = new Intent(this, VideoListActivity.class); this.startActivity(intentSettings); } else { - Log.v(TAG,"Unable to enter PIP mode"); + Log.v(TAG, "Unable to enter PIP mode"); super.onBackPressed(); } break; default: // Deal with bad entries from older version - Log.v(TAG,"No setting, fallback"); + Log.v(TAG, "No setting, fallback"); super.onBackPressed(); break; } @@ -426,18 +426,18 @@ public class VideoPlayActivity extends AppCompatActivity { } public boolean canEnterPipMode(Context context) { - Log.v(TAG,"api version "+Build.VERSION.SDK_INT); - if (Build.VERSION.SDK_INT<28){ + Log.v(TAG, "api version " + Build.VERSION.SDK_INT); + if (Build.VERSION.SDK_INT < 28) { return false; } AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); - return (AppOpsManager.MODE_ALLOWED== appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_PICTURE_IN_PICTURE, android.os.Process.myUid(), context.getPackageName())); + return (AppOpsManager.MODE_ALLOWED == appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_PICTURE_IN_PICTURE, android.os.Process.myUid(), context.getPackageName())); } @RequiresApi(api = Build.VERSION_CODES.O) public void enterPipMode() { Rational rational = new Rational(239, 100); - Log.v(TAG,rational.toString()); + Log.v(TAG, rational.toString()); PictureInPictureParams mParams = new PictureInPictureParams.Builder() .setAspectRatio(rational) @@ -448,17 +448,17 @@ public class VideoPlayActivity extends AppCompatActivity { } @Override - public void onPictureInPictureModeChanged (boolean isInPictureInPictureMode, Configuration newConfig) { + public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) { FragmentManager fragmentManager = getSupportFragmentManager(); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); if (isInPictureInPictureMode) { changedToPipMode(); - Log.v(TAG,"switched to pip "); + Log.v(TAG, "switched to pip "); videoPlayerFragment.useController(false); } else { changedToNormalMode(); - Log.v(TAG,"switched to normal"); + Log.v(TAG, "switched to normal"); videoPlayerFragment.useController(true); } } From a56dc559212d5c29b7becfa7f01dc4e356bc468a Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Sun, 5 Jul 2020 13:56:17 +0200 Subject: [PATCH 09/19] Code cleanup --- .../peertube/activity/VideoPlayActivity.java | 175 ++++++++++-------- .../res/values/{array.xml => constants.xml} | 9 +- 2 files changed, 108 insertions(+), 76 deletions(-) rename app/src/main/res/values/{array.xml => constants.xml} (97%) 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 e705a45..e76ba92 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -36,6 +36,7 @@ import android.os.Bundle; import android.preference.PreferenceManager; +import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; import androidx.appcompat.app.AppCompatActivity; @@ -72,7 +73,8 @@ public class VideoPlayActivity extends AppCompatActivity { private static final String TAG = "VideoPlayActivity"; - private static boolean floatMode = false; + static boolean floatMode = false; + private static final int REQUEST_CODE = 101; private BroadcastReceiver receiver; @@ -96,21 +98,21 @@ public class VideoPlayActivity extends AppCompatActivity { remoteAction = new RemoteAction(icon, "play", "stop the media", pendingIntent); actions.add(remoteAction); + assert videoPlayerFragment != null; if (videoPlayerFragment.isPaused()) { Log.e(TAG, "setting actions with play button"); actionIntent = new Intent(ACTION_PLAY); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0); icon = Icon.createWithResource(getApplicationContext(), com.google.android.exoplayer2.ui.R.drawable.exo_notification_play); remoteAction = new RemoteAction(icon, "play", "play the media", pendingIntent); - actions.add(remoteAction); } else { Log.e(TAG, "setting actions with pause button"); actionIntent = new Intent(ACTION_PAUSE); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0); icon = Icon.createWithResource(getApplicationContext(), com.google.android.exoplayer2.ui.R.drawable.exo_notification_pause); remoteAction = new RemoteAction(icon, "pause", "pause the media", pendingIntent); - actions.add(remoteAction); } + actions.add(remoteAction); //add custom actions to pip window @@ -125,6 +127,7 @@ public class VideoPlayActivity extends AppCompatActivity { FragmentManager fragmentManager = getSupportFragmentManager(); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); + assert videoPlayerFragment != null; videoPlayerFragment.showControls(false); //create custom actions makePipControls(); @@ -139,6 +142,7 @@ public class VideoPlayActivity extends AppCompatActivity { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); + assert action != null; if (action.equals(ACTION_PAUSE)) { videoPlayerFragment.pauseVideo(); makePipControls(); @@ -169,6 +173,7 @@ public class VideoPlayActivity extends AppCompatActivity { FragmentManager fragmentManager = getSupportFragmentManager(); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); + assert videoPlayerFragment != null; videoPlayerFragment.showControls(true); if (receiver != null) { unregisterReceiver(receiver); @@ -249,7 +254,7 @@ public class VideoPlayActivity extends AppCompatActivity { } @Override - public void onConfigurationChanged(Configuration newConfig) { + public void onConfigurationChanged(@NonNull Configuration newConfig) { Log.v(TAG, "onConfigurationChanged()..."); super.onConfigurationChanged(newConfig); @@ -271,7 +276,8 @@ public class VideoPlayActivity extends AppCompatActivity { RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) videoPlayerFragment.requireView().getLayoutParams(); params.width = FrameLayout.LayoutParams.MATCH_PARENT; params.height = isLandscape ? FrameLayout.LayoutParams.MATCH_PARENT : (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250, getResources().getDisplayMetrics()); - videoPlayerFragment.getView().setLayoutParams(params); + + videoPlayerFragment.requireView().setLayoutParams(params); if (videoMetaFragment != null) { FragmentTransaction transaction = fragmentManager.beginTransaction() @@ -338,100 +344,117 @@ public class VideoPlayActivity extends AppCompatActivity { @SuppressLint("NewApi") @Override public void onUserLeaveHint() { + + Log.v(TAG, "onUserLeaveHint()..."); + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); FragmentManager fragmentManager = getSupportFragmentManager(); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); - String backgroundBehavior = sharedPref.getString("pref_background_behavior", "backgroundStop"); - switch (backgroundBehavior) { - case "backgroundStop": - Log.v(TAG, "stop the video"); - videoPlayerFragment.pauseVideo(); - stopService(new Intent(this, VideoPlayerService.class)); - super.onBackPressed(); - break; - case "backgroundAudio": - Log.v(TAG, "play the Audio"); - super.onBackPressed(); - break; - case "backgroundFloat": - Log.v(TAG, "play in floating video"); - //canEnterPIPMode makes sure API level is high enough - if (canEnterPipMode(this)) { - Log.v(TAG, "enabling pip"); - enterPipMode(); - } else { - Log.v(TAG, "unable to use pip"); - } - break; + String backgroundBehavior = sharedPref.getString("pref_background_behavior", getString(R.string.pref_background_stop_key)); + + assert videoPlayerFragment != null; + assert backgroundBehavior != null; + + if (backgroundBehavior.equals(getString(R.string.pref_background_stop_key))) { + Log.v(TAG, "stop the video"); + + videoPlayerFragment.pauseVideo(); + stopService(new Intent(this, VideoPlayerService.class)); + super.onBackPressed(); + + } else if (backgroundBehavior.equals(getString(R.string.pref_background_audio_key))) { + Log.v(TAG, "play the Audio"); + super.onBackPressed(); + + } else if (backgroundBehavior.equals(getString(R.string.pref_background_float_key))) { + Log.v(TAG, "play in floating video"); + //canEnterPIPMode makes sure API level is high enough + if (canEnterPipMode(this)) { + Log.v(TAG, "enabling pip"); + enterPipMode(); + } else { + Log.v(TAG, "unable to use pip"); + } + + } else { + // Deal with bad entries from older version + Log.v(TAG, "No setting, fallback"); + super.onBackPressed(); + } - Log.v(TAG, "onUserLeaveHint()..."); + + } // @RequiresApi(api = Build.VERSION_CODES.O) @SuppressLint("NewApi") public void onBackPressed() { + + Log.v(TAG, "onBackPressed()..."); + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) getSupportFragmentManager().findFragmentById(R.id.video_player_fragment); - //copying Youtube behavior to have back button exit full screen. + assert videoPlayerFragment != null; + + // copying Youtube behavior to have back button exit full screen. if (videoPlayerFragment.getIsFullscreen()) { Log.v(TAG, "exiting full screen"); videoPlayerFragment.fullScreenToggle(); return; } - + // pause video if pref is enabled if (sharedPref.getBoolean("pref_back_pause", true)) { videoPlayerFragment.pauseVideo(); } - String backgroundBehavior = sharedPref.getString("pref_background_behavior", "backgroundStop"); + String backgroundBehavior = sharedPref.getString("pref_background_behavior", getString(R.string.pref_background_stop_key)); + assert backgroundBehavior != null; - // Log.v(TAG,"backgroundBehavior: " + backgroundBehavior); + if (backgroundBehavior.equals(getString(R.string.pref_background_stop_key))) { + Log.v(TAG, "stop the video"); + videoPlayerFragment.pauseVideo(); + stopService(new Intent(this, VideoPlayerService.class)); + super.onBackPressed(); - switch (backgroundBehavior) { - case "backgroundStop": - Log.v(TAG, "stop the video"); - videoPlayerFragment.pauseVideo(); - stopService(new Intent(this, VideoPlayerService.class)); + } else if (backgroundBehavior.equals(getString(R.string.pref_background_audio_key))) { + Log.v(TAG, "play the Audio"); + super.onBackPressed(); + + } else if (backgroundBehavior.equals(getString(R.string.pref_background_float_key))) { + Log.v(TAG, "play in floating video"); + //canEnterPIPMode makes sure API level is high enough + if (canEnterPipMode(this)) { + Log.v(TAG, "enabling pip"); + enterPipMode(); + //fixes problem where back press doesn't bring up video list after returning from PIP mode + Intent intentSettings = new Intent(this, VideoListActivity.class); + this.startActivity(intentSettings); + } else { + Log.v(TAG, "Unable to enter PIP mode"); super.onBackPressed(); - break; - case "backgroundAudio": - Log.v(TAG, "play the Audio"); - super.onBackPressed(); - break; - case "backgroundFloat": - Log.v(TAG, "play in floating video"); - //canEnterPIPMode makes sure API level is high enough - if (canEnterPipMode(this)) { - Log.v(TAG, "enabling pip"); - enterPipMode(); - //fixes problem where back press doesn't bring up video list after returning from PIP mode - Intent intentSettings = new Intent(this, VideoListActivity.class); - this.startActivity(intentSettings); - } else { - Log.v(TAG, "Unable to enter PIP mode"); - super.onBackPressed(); - } - break; - default: - // Deal with bad entries from older version - Log.v(TAG, "No setting, fallback"); - super.onBackPressed(); - break; + } + + } else { + // Deal with bad entries from older version + Log.v(TAG, "No setting, fallback"); + super.onBackPressed(); + } - Log.v(TAG, "onBackPressed()..."); + + } public boolean canEnterPipMode(Context context) { Log.v(TAG, "api version " + Build.VERSION.SDK_INT); - if (Build.VERSION.SDK_INT < 28) { - return false; + if (Build.VERSION.SDK_INT > 27) { + AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); + return (AppOpsManager.MODE_ALLOWED == appOpsManager.checkOp(AppOpsManager.OPSTR_PICTURE_IN_PICTURE, android.os.Process.myUid(), context.getPackageName())); } - AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); - return (AppOpsManager.MODE_ALLOWED == appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_PICTURE_IN_PICTURE, android.os.Process.myUid(), context.getPackageName())); + return false; } @RequiresApi(api = Build.VERSION_CODES.O) @@ -452,14 +475,20 @@ public class VideoPlayActivity extends AppCompatActivity { FragmentManager fragmentManager = getSupportFragmentManager(); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); - if (isInPictureInPictureMode) { - changedToPipMode(); - Log.v(TAG, "switched to pip "); - videoPlayerFragment.useController(false); + if (videoPlayerFragment != null) { + + if (isInPictureInPictureMode) { + changedToPipMode(); + Log.v(TAG, "switched to pip "); + videoPlayerFragment.useController(false); + } else { + changedToNormalMode(); + Log.v(TAG, "switched to normal"); + videoPlayerFragment.useController(true); + } + } else { - changedToNormalMode(); - Log.v(TAG, "switched to normal"); - videoPlayerFragment.useController(true); + Log.e(TAG, "videoPlayerFragment is NULL"); } } diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/constants.xml similarity index 97% rename from app/src/main/res/values/array.xml rename to app/src/main/res/values/constants.xml index a74e65b..ce3bf6e 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/constants.xml @@ -1,6 +1,9 @@ + backgroundAudio + backgroundStop + backgroundFloat @string/pref_background_audio @@ -9,9 +12,9 @@ - backgroundAudio - backgroundStop - backgroundFloat + @string/pref_background_audio_key + @string/pref_background_stop_key + @string/pref_background_float_key From db560bb3405ea54f295030fa9991e2df8b70dcdf Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Sun, 5 Jul 2020 14:15:48 +0200 Subject: [PATCH 10/19] Code cleanup --- .../activity/AppCompatPreferenceActivity.java | 145 ------------------ .../peertube/activity/CommonActivity.java | 20 ++- .../activity/SelectServerActivity.java | 12 -- .../peertube/activity/VideoPlayActivity.java | 14 +- .../schueller/peertube/helper/Constants.java | 25 --- app/src/main/res/values/constants.xml | 45 +++++- app/src/main/res/values/strings.xml | 34 +--- 7 files changed, 65 insertions(+), 230 deletions(-) delete mode 100644 app/src/main/java/net/schueller/peertube/activity/AppCompatPreferenceActivity.java delete mode 100644 app/src/main/java/net/schueller/peertube/helper/Constants.java diff --git a/app/src/main/java/net/schueller/peertube/activity/AppCompatPreferenceActivity.java b/app/src/main/java/net/schueller/peertube/activity/AppCompatPreferenceActivity.java deleted file mode 100644 index 36d5fe0..0000000 --- a/app/src/main/java/net/schueller/peertube/activity/AppCompatPreferenceActivity.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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.activity; - -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.os.Bundle; -import android.preference.PreferenceActivity; -import androidx.annotation.LayoutRes; -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.app.AppCompatDelegate; - -import android.preference.PreferenceManager; -import android.view.MenuInflater; -import android.view.View; -import android.view.ViewGroup; - -import static net.schueller.peertube.helper.Constants.DEFAULT_THEME; -import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; - -/** - * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls - * to be used with AppCompat. - */ -public abstract class AppCompatPreferenceActivity extends PreferenceActivity { - - private AppCompatDelegate mDelegate; - - @Override - protected void onCreate(Bundle savedInstanceState) { - getDelegate().installViewFactory(); - getDelegate().onCreate(savedInstanceState); - super.onCreate(savedInstanceState); - - // TODO: cleanup this duplication - - // Set Night Mode - SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); - AppCompatDelegate.setDefaultNightMode(sharedPref.getBoolean("pref_dark_mode", false) ? - AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO); - - // Set theme - setTheme(getResources().getIdentifier( - sharedPref.getString(THEME_PREF_KEY, DEFAULT_THEME), - "style", - getPackageName()) - ); - } - - @Override - protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - getDelegate().onPostCreate(savedInstanceState); - } - - public ActionBar getSupportActionBar() { - return getDelegate().getSupportActionBar(); - } - -// public void setSupportActionBar(@Nullable Toolbar toolbar) { -// getDelegate().setSupportActionBar(toolbar); -// } - - @Override - public MenuInflater getMenuInflater() { - return getDelegate().getMenuInflater(); - } - - @Override - public void setContentView(@LayoutRes int layoutResID) { - getDelegate().setContentView(layoutResID); - } - - @Override - public void setContentView(View view) { - getDelegate().setContentView(view); - } - - @Override - public void setContentView(View view, ViewGroup.LayoutParams params) { - getDelegate().setContentView(view, params); - } - - @Override - public void addContentView(View view, ViewGroup.LayoutParams params) { - getDelegate().addContentView(view, params); - } - - @Override - protected void onPostResume() { - super.onPostResume(); - getDelegate().onPostResume(); - } - - @Override - protected void onTitleChanged(CharSequence title, int color) { - super.onTitleChanged(title, color); - getDelegate().setTitle(title); - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - getDelegate().onConfigurationChanged(newConfig); - } - - @Override - protected void onStop() { - super.onStop(); - getDelegate().onStop(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - getDelegate().onDestroy(); - } - - public void invalidateOptionsMenu() { - getDelegate().invalidateOptionsMenu(); - } - - private AppCompatDelegate getDelegate() { - if (mDelegate == null) { - mDelegate = AppCompatDelegate.create(this, null); - } - return mDelegate; - } -} diff --git a/app/src/main/java/net/schueller/peertube/activity/CommonActivity.java b/app/src/main/java/net/schueller/peertube/activity/CommonActivity.java index a733fca..9f7ada0 100644 --- a/app/src/main/java/net/schueller/peertube/activity/CommonActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/CommonActivity.java @@ -26,10 +26,9 @@ import android.preference.PreferenceManager; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatDelegate; -import java.util.Locale; +import net.schueller.peertube.R; -import static net.schueller.peertube.helper.Constants.DEFAULT_THEME; -import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; +import java.util.Locale; public class CommonActivity extends AppCompatActivity { @@ -44,18 +43,23 @@ public class CommonActivity extends AppCompatActivity { // Set theme setTheme(getResources().getIdentifier( - sharedPref.getString(THEME_PREF_KEY, DEFAULT_THEME), + sharedPref.getString( + getString(R.string.pref_theme_key), + getString(R.string.app_default_theme) + ), "style", getPackageName()) ); // Set language - String countryCode=sharedPref.getString("pref_language_app","en"); - Locale locale=new Locale(countryCode);; + String countryCode = sharedPref.getString("pref_language_app", "en"); + assert countryCode != null; + Locale locale = new Locale(countryCode); + //Neither Chinese language choice was working, found this fix on stack overflow - if(countryCode.equals("zh-rCN")) + if (countryCode.equals("zh-rCN")) locale = Locale.SIMPLIFIED_CHINESE; - if(countryCode.equals("zh-rTW")) + if (countryCode.equals("zh-rTW")) locale = Locale.TRADITIONAL_CHINESE; Locale.setDefault(locale); diff --git a/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java b/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java index a4c6186..1706108 100644 --- a/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java @@ -18,7 +18,6 @@ package net.schueller.peertube.activity; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -27,33 +26,22 @@ import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; -import android.content.Intent; -import android.content.SharedPreferences; import android.os.Bundle; -import android.preference.PreferenceManager; import android.util.Log; -import android.util.Patterns; import android.view.View; -import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import net.schueller.peertube.R; import net.schueller.peertube.adapter.ServerAdapter; -import net.schueller.peertube.adapter.VideoAdapter; import net.schueller.peertube.helper.APIUrlHelper; import net.schueller.peertube.model.ServerList; -import net.schueller.peertube.model.VideoList; import net.schueller.peertube.network.GetServerListDataService; -import net.schueller.peertube.network.GetVideoDataService; import net.schueller.peertube.network.RetrofitInstance; import java.util.ArrayList; import java.util.Objects; -import static net.schueller.peertube.helper.Constants.DEFAULT_THEME; -import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; - public class SelectServerActivity extends CommonActivity { private ServerAdapter serverAdapter; 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 e76ba92..9460e74 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -65,9 +65,6 @@ import androidx.fragment.app.FragmentTransaction; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PAUSE; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PLAY; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_STOP; -import static net.schueller.peertube.helper.Constants.BACKGROUND_AUDIO; -import static net.schueller.peertube.helper.Constants.DEFAULT_THEME; -import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; public class VideoPlayActivity extends AppCompatActivity { @@ -86,7 +83,7 @@ public class VideoPlayActivity extends AppCompatActivity { ArrayList actions = new ArrayList<>(); - Intent actionIntent = new Intent(BACKGROUND_AUDIO); + Intent actionIntent = new Intent(getString(R.string.app_background_audio)); PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0); @SuppressLint({"NewApi", "LocalSuppress"}) Icon icon = Icon.createWithResource(getApplicationContext(), android.R.drawable.stat_sys_speakerphone); @SuppressLint({"NewApi", "LocalSuppress"}) RemoteAction remoteAction = new RemoteAction(icon, "close pip", "from pip window custom command", pendingIntent); @@ -137,7 +134,7 @@ public class VideoPlayActivity extends AppCompatActivity { filter.addAction(ACTION_STOP); filter.addAction(ACTION_PAUSE); filter.addAction(ACTION_PLAY); - filter.addAction((BACKGROUND_AUDIO)); + filter.addAction((getString(R.string.app_background_audio))); receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -152,7 +149,7 @@ public class VideoPlayActivity extends AppCompatActivity { makePipControls(); } - if (action.equals(BACKGROUND_AUDIO)) { + if (action.equals(getString(R.string.app_background_audio))) { unregisterReceiver(receiver); finish(); } @@ -189,7 +186,10 @@ public class VideoPlayActivity extends AppCompatActivity { // Set theme SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); setTheme(getResources().getIdentifier( - sharedPref.getString(THEME_PREF_KEY, DEFAULT_THEME), + sharedPref.getString( + getString(R.string.pref_theme_key), + getString(R.string.app_default_theme) + ), "style", getPackageName()) ); diff --git a/app/src/main/java/net/schueller/peertube/helper/Constants.java b/app/src/main/java/net/schueller/peertube/helper/Constants.java deleted file mode 100644 index 0e87a3f..0000000 --- a/app/src/main/java/net/schueller/peertube/helper/Constants.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.helper; - -public class Constants { - public static final String THEME_PREF_KEY = "pref_theme"; - public static final String DEFAULT_THEME = "AppTheme.BLUE"; - public static final String BACKGROUND_PLAY_PREF_KEY = "pref_background_play"; - public static final String BACKGROUND_AUDIO = "BACKGROUND_AUDIO"; -} diff --git a/app/src/main/res/values/constants.xml b/app/src/main/res/values/constants.xml index ce3bf6e..0cfa51f 100644 --- a/app/src/main/res/values/constants.xml +++ b/app/src/main/res/values/constants.xml @@ -1,9 +1,50 @@ + Thorium + + pref_token_access + pref_token_refresh + pref_token_expiration + pref_token_type + pref_auth_username + pref_auth_password backgroundAudio backgroundStop backgroundFloat + https://troll.tv + pref_theme + + 1.0.0-alpha.7 + + AppTheme.BLUE + BACKGROUND_AUDIO + + none + like + dislike + + {faw-play-circle} + {faw-cog} + {faw-check} + {faw-check} + {faw-expand} + {faw-compress} + {faw-ellipsis-v} + {faw-thumbs-up} + {faw-thumbs-down} + {faw-share} + {faw-download} + {faw-save} + + \@ + \u0020-\u0020 + + VideoPlayActivity + + PeerTube + + PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser with WebTorrent and Angular. @string/pref_background_audio @@ -478,7 +519,7 @@ zh-rTW - + @string/ar @string/bn @string/bn_rBD @@ -505,7 +546,7 @@ - + Low diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f000c8c..d66a185 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,7 +1,6 @@ - Thorium - VideoPlayActivity + Settings Sign in @@ -29,9 +28,7 @@ Account - \u0020-\u0020 \u0020Views - \@ Video Thumbnail Account Avatar UrlVideoPlayActivity @@ -40,7 +37,6 @@ No Results More Share - PeerTube Invalid URL. Dark Mode @@ -56,7 +52,6 @@ Show NSFW content Language filter Select a video language, instead of showing all videos in all languages. - https://troll.tv PeerTube Server Background Playback If enabled, continues to play video in background. @@ -292,18 +287,7 @@ Normal 1.5x 2x - {faw-play-circle} - {faw-cog} - {faw-check} - {faw-check} - {faw-expand} - {faw-compress} - {faw-ellipsis-v} - {faw-thumbs-up} - {faw-thumbs-down} - {faw-share} - {faw-download} - {faw-save} + Select Server Signup Allowed: %s Yes @@ -352,10 +336,7 @@ Password Add Has Login - none - like - dislike - 1.0.0-alpha.7 + Current Server Address Book 0.75x @@ -372,18 +353,9 @@ About - PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser with WebTorrent and Angular. NSFW Instance Videos: %s, Local Videos: %s - - - pref_token_access - pref_token_refresh - pref_token_expiration - pref_token_type - pref_auth_username - pref_auth_password Automated From 3ac28ef4d97d1bf76a6201b4777d9027a3be3d6a Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sun, 5 Jul 2020 02:17:31 +0000 Subject: [PATCH 11/19] Translated using Weblate (French) Currently translated at 100.0% (368 of 368 strings) Translation: PeerTube/Android Translate-URL: https://hosted.weblate.org/projects/peertube/android/fr/ --- app/src/main/res/values-fr/strings.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index d1dab69..97b7520 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -343,4 +343,7 @@ Sélectionner un serveur Retirer un serveur Voulez-vous vraiment retirer ce serveur de votre carnet d\'adresses ? + Instance avec du contenu adulte + Bonjour ! Fragment vide + Vidéos : %s, Vidéos locales : %s \ No newline at end of file From a41049e8dd0de2b480a4f76bca724ed227be3fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fuz=20Ersen?= Date: Sat, 4 Jul 2020 18:54:20 +0000 Subject: [PATCH 12/19] Translated using Weblate (Turkish) Currently translated at 99.7% (367 of 368 strings) Translation: PeerTube/Android Translate-URL: https://hosted.weblate.org/projects/peertube/android/tr/ --- app/src/main/res/values-tr/strings.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index dcb7795..b768928 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -353,4 +353,6 @@ Arka planda oynatma yapılandırması Tüm oynatmaları durdur Arka planda ses akışı olarak devam et + İş Yeri İçin Uygun Olmayan (NSFW) Örnek + Video: %s, Yerel Video: %s \ No newline at end of file From 0c3d508a53cbcd74f4a741e14d1a8292cf964d78 Mon Sep 17 00:00:00 2001 From: Jeff Huang Date: Sun, 5 Jul 2020 03:53:05 +0000 Subject: [PATCH 13/19] Translated using Weblate (Chinese (Traditional)) Currently translated at 100.0% (368 of 368 strings) Translation: PeerTube/Android Translate-URL: https://hosted.weblate.org/projects/peertube/android/zh_Hant/ --- app/src/main/res/values-zh-rTW/strings.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 039b46c..773aa99 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -339,4 +339,6 @@ 繼續以懸浮視窗播放影片 停止所有播放 以背景音訊串流繼續 + 影片:%s,本地影片:%s + NSFW 站臺 \ No newline at end of file From ed8c46a79a18d944c50f747bc3480ae7560da65f Mon Sep 17 00:00:00 2001 From: "J. Lavoie" Date: Sun, 5 Jul 2020 02:21:06 +0000 Subject: [PATCH 14/19] Translated using Weblate (German) Currently translated at 93.7% (345 of 368 strings) Translation: PeerTube/Android Translate-URL: https://hosted.weblate.org/projects/peertube/android/de/ --- app/src/main/res/values-de/strings.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index aae549c..31b1694 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -314,4 +314,8 @@ Suchverlauf löschen Wählen Sie die Sprache für die Anwendungsschnittstelle aus. Starten Sie die Anwendung neu, damit die Änderung wirksam wird. Sprache der Anwendung + Über + Videowiedergabe + Videoliste + Videos: %s, Lokale Videos: %s \ No newline at end of file From b01807d2a9b31348f6af2ab2cfea7f589aa8b246 Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Sun, 5 Jul 2020 14:25:28 +0200 Subject: [PATCH 15/19] Code cleanup, renamed serverlist to search server --- app/src/main/AndroidManifest.xml | 2 +- ...erActivity.java => SearchServerActivity.java} | 16 ++++++++-------- .../peertube/adapter/ServerListAdapter.java | 8 -------- ...rverAdapter.java => ServerSearchAdapter.java} | 8 ++++---- .../peertube/fragment/AddServerFragment.java | 4 ++-- ..._selection.xml => activity_search_server.xml} | 2 +- app/src/main/res/values/strings.xml | 2 +- 7 files changed, 17 insertions(+), 25 deletions(-) rename app/src/main/java/net/schueller/peertube/activity/{SelectServerActivity.java => SearchServerActivity.java} (92%) rename app/src/main/java/net/schueller/peertube/adapter/{ServerAdapter.java => ServerSearchAdapter.java} (95%) rename app/src/main/res/layout/{activity_server_selection.xml => activity_search_server.xml} (97%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ee09a9b..3091705 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -49,7 +49,7 @@ android:label="@string/title_activity_settings" android:theme="@style/AppTheme.NoActionBar" /> (), this); + serverAdapter = new ServerSearchAdapter(new ArrayList<>(), this); recyclerView.setAdapter(serverAdapter); loadServers(currentStart, count); @@ -132,7 +132,7 @@ public class SelectServerActivity extends CommonActivity { isLoading = true; GetServerListDataService service = RetrofitInstance.getRetrofitInstance( - APIUrlHelper.getServerIndexUrl(SelectServerActivity.this) + APIUrlHelper.getServerIndexUrl(SearchServerActivity.this) ).create(GetServerListDataService.class); @@ -171,7 +171,7 @@ public class SelectServerActivity extends CommonActivity { @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { Log.wtf("err", t.fillInStackTrace()); - Toast.makeText(SelectServerActivity.this, getString(R.string.api_error), Toast.LENGTH_SHORT).show(); + Toast.makeText(SearchServerActivity.this, getString(R.string.api_error), Toast.LENGTH_SHORT).show(); isLoading = false; swipeRefreshLayout.setRefreshing(false); } diff --git a/app/src/main/java/net/schueller/peertube/adapter/ServerListAdapter.java b/app/src/main/java/net/schueller/peertube/adapter/ServerListAdapter.java index f7225df..b5a575a 100644 --- a/app/src/main/java/net/schueller/peertube/adapter/ServerListAdapter.java +++ b/app/src/main/java/net/schueller/peertube/adapter/ServerListAdapter.java @@ -18,15 +18,11 @@ package net.schueller.peertube.adapter; import android.app.Activity; -import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; -import android.provider.SearchRecentSuggestions; import android.text.TextUtils; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -39,12 +35,8 @@ import androidx.recyclerview.widget.RecyclerView; import net.schueller.peertube.R; -import net.schueller.peertube.activity.SelectServerActivity; -import net.schueller.peertube.activity.ServerAddressBookActivity; -import net.schueller.peertube.activity.VideoListActivity; import net.schueller.peertube.database.Server; import net.schueller.peertube.helper.APIUrlHelper; -import net.schueller.peertube.provider.SearchSuggestionsProvider; import net.schueller.peertube.service.LoginService; diff --git a/app/src/main/java/net/schueller/peertube/adapter/ServerAdapter.java b/app/src/main/java/net/schueller/peertube/adapter/ServerSearchAdapter.java similarity index 95% rename from app/src/main/java/net/schueller/peertube/adapter/ServerAdapter.java rename to app/src/main/java/net/schueller/peertube/adapter/ServerSearchAdapter.java index 4798032..f605cf8 100644 --- a/app/src/main/java/net/schueller/peertube/adapter/ServerAdapter.java +++ b/app/src/main/java/net/schueller/peertube/adapter/ServerSearchAdapter.java @@ -27,7 +27,7 @@ import android.widget.Toast; import net.schueller.peertube.R; -import net.schueller.peertube.activity.SelectServerActivity; +import net.schueller.peertube.activity.SearchServerActivity; import net.schueller.peertube.helper.APIUrlHelper; import net.schueller.peertube.model.Server; @@ -41,14 +41,14 @@ import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import static android.app.Activity.RESULT_OK; -public class ServerAdapter extends RecyclerView.Adapter { +public class ServerSearchAdapter extends RecyclerView.Adapter { private ArrayList serverList; - private SelectServerActivity activity; + private SearchServerActivity activity; private String baseUrl; - public ServerAdapter(ArrayList serverList, SelectServerActivity activity) { + public ServerSearchAdapter(ArrayList serverList, SearchServerActivity activity) { this.serverList = serverList; this.activity = activity; } diff --git a/app/src/main/java/net/schueller/peertube/fragment/AddServerFragment.java b/app/src/main/java/net/schueller/peertube/fragment/AddServerFragment.java index 6e15a2b..4c90721 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/AddServerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/AddServerFragment.java @@ -38,7 +38,7 @@ import android.widget.EditText; import android.widget.Toast; import net.schueller.peertube.R; -import net.schueller.peertube.activity.SelectServerActivity; +import net.schueller.peertube.activity.SearchServerActivity; import net.schueller.peertube.activity.ServerAddressBookActivity; import net.schueller.peertube.helper.APIUrlHelper; @@ -128,7 +128,7 @@ public class AddServerFragment extends Fragment { Button pickServerUrl = mView.findViewById(R.id.pickServerUrl); pickServerUrl.setOnClickListener(view -> { - Intent intentServer = new Intent(getActivity(), SelectServerActivity.class); + Intent intentServer = new Intent(getActivity(), SearchServerActivity.class); this.startActivityForResult(intentServer, PICK_SERVER); }); diff --git a/app/src/main/res/layout/activity_server_selection.xml b/app/src/main/res/layout/activity_search_server.xml similarity index 97% rename from app/src/main/res/layout/activity_server_selection.xml rename to app/src/main/res/layout/activity_search_server.xml index 9a91455..1860129 100644 --- a/app/src/main/res/layout/activity_server_selection.xml +++ b/app/src/main/res/layout/activity_search_server.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".activity.SelectServerActivity"> + tools:context=".activity.SearchServerActivity"> Remove Server Are you sure you want to remove this server from the address book? - Select Server + Search Server Account SettingsActivity2 From 6cbf35972bb62303248fbae924007678c63adc1d Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Sun, 5 Jul 2020 14:31:19 +0200 Subject: [PATCH 16/19] Code cleanup --- .../java/net/schueller/peertube/adapter/ServerListAdapter.java | 2 +- .../net/schueller/peertube/adapter/ServerSearchAdapter.java | 2 +- .../main/java/net/schueller/peertube/adapter/VideoAdapter.java | 2 +- app/src/main/res/layout/content_server_address_book.xml | 2 +- .../main/res/layout/{row_server.xml => row_search_server.xml} | 0 .../layout/{row_serverbook.xml => row_server_address_book.xml} | 0 app/src/main/res/layout/{row_video.xml => row_video_list.xml} | 0 7 files changed, 4 insertions(+), 4 deletions(-) rename app/src/main/res/layout/{row_server.xml => row_search_server.xml} (100%) rename app/src/main/res/layout/{row_serverbook.xml => row_server_address_book.xml} (100%) rename app/src/main/res/layout/{row_video.xml => row_video_list.xml} (100%) diff --git a/app/src/main/java/net/schueller/peertube/adapter/ServerListAdapter.java b/app/src/main/java/net/schueller/peertube/adapter/ServerListAdapter.java index b5a575a..cbefba9 100644 --- a/app/src/main/java/net/schueller/peertube/adapter/ServerListAdapter.java +++ b/app/src/main/java/net/schueller/peertube/adapter/ServerListAdapter.java @@ -57,7 +57,7 @@ public class ServerListAdapter extends RecyclerView.Adapter + tools:listitem="@layout/row_server_address_book" /> diff --git a/app/src/main/res/layout/row_server.xml b/app/src/main/res/layout/row_search_server.xml similarity index 100% rename from app/src/main/res/layout/row_server.xml rename to app/src/main/res/layout/row_search_server.xml diff --git a/app/src/main/res/layout/row_serverbook.xml b/app/src/main/res/layout/row_server_address_book.xml similarity index 100% rename from app/src/main/res/layout/row_serverbook.xml rename to app/src/main/res/layout/row_server_address_book.xml diff --git a/app/src/main/res/layout/row_video.xml b/app/src/main/res/layout/row_video_list.xml similarity index 100% rename from app/src/main/res/layout/row_video.xml rename to app/src/main/res/layout/row_video_list.xml From cee233db3920d1071206df6d6782d603e1df820c Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Sun, 5 Jul 2020 15:07:50 +0200 Subject: [PATCH 17/19] Code cleanup --- .../peertube/activity/VideoPlayActivity.java | 14 +- .../peertube/fragment/AddServerFragment.java | 7 +- .../fragment/VideoOptionsFragment.java | 18 ++- .../fragment/VideoPlayerFragment.java | 135 +++++++++--------- .../peertube/helper/VideoHelper.java | 40 ++++++ app/src/main/res/values-ar/strings.xml | 4 +- app/src/main/res/values-bn/strings.xml | 4 +- app/src/main/res/values-de/strings.xml | 4 +- app/src/main/res/values-es/strings.xml | 4 +- app/src/main/res/values-fi/strings.xml | 2 +- app/src/main/res/values-fr/strings.xml | 4 +- app/src/main/res/values-gd/strings.xml | 4 +- app/src/main/res/values-it/strings.xml | 4 +- app/src/main/res/values-ja/strings.xml | 4 +- app/src/main/res/values-nb-rNO/strings.xml | 4 +- app/src/main/res/values-nl/strings.xml | 4 +- app/src/main/res/values-pl/strings.xml | 4 +- app/src/main/res/values-ru/strings.xml | 4 +- app/src/main/res/values-sv/strings.xml | 4 +- app/src/main/res/values-tr/strings.xml | 4 +- app/src/main/res/values-zh-rCN/strings.xml | 4 +- app/src/main/res/values-zh-rTW/strings.xml | 4 +- app/src/main/res/values/constants.xml | 1 + app/src/main/res/values/strings.xml | 4 +- app/src/main/res/xml/root_preferences.xml | 2 +- 25 files changed, 166 insertions(+), 121 deletions(-) create mode 100644 app/src/main/java/net/schueller/peertube/helper/VideoHelper.java 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 9460e74..159b942 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -65,6 +65,7 @@ import androidx.fragment.app.FragmentTransaction; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PAUSE; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PLAY; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_STOP; +import static net.schueller.peertube.helper.VideoHelper.canEnterPipMode; public class VideoPlayActivity extends AppCompatActivity { @@ -351,7 +352,7 @@ public class VideoPlayActivity extends AppCompatActivity { FragmentManager fragmentManager = getSupportFragmentManager(); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); - String backgroundBehavior = sharedPref.getString("pref_background_behavior", getString(R.string.pref_background_stop_key)); + String backgroundBehavior = sharedPref.getString(getString(R.string.pref_background_behavior_key), getString(R.string.pref_background_stop_key)); assert videoPlayerFragment != null; assert backgroundBehavior != null; @@ -410,7 +411,7 @@ public class VideoPlayActivity extends AppCompatActivity { videoPlayerFragment.pauseVideo(); } - String backgroundBehavior = sharedPref.getString("pref_background_behavior", getString(R.string.pref_background_stop_key)); + String backgroundBehavior = sharedPref.getString(getString(R.string.pref_background_behavior_key), getString(R.string.pref_background_stop_key)); assert backgroundBehavior != null; @@ -448,15 +449,6 @@ public class VideoPlayActivity extends AppCompatActivity { } - public boolean canEnterPipMode(Context context) { - Log.v(TAG, "api version " + Build.VERSION.SDK_INT); - if (Build.VERSION.SDK_INT > 27) { - AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); - return (AppOpsManager.MODE_ALLOWED == appOpsManager.checkOp(AppOpsManager.OPSTR_PICTURE_IN_PICTURE, android.os.Process.myUid(), context.getPackageName())); - } - return false; - } - @RequiresApi(api = Build.VERSION_CODES.O) public void enterPipMode() { Rational rational = new Rational(239, 100); diff --git a/app/src/main/java/net/schueller/peertube/fragment/AddServerFragment.java b/app/src/main/java/net/schueller/peertube/fragment/AddServerFragment.java index 4c90721..9f761a8 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/AddServerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/AddServerFragment.java @@ -42,6 +42,8 @@ import net.schueller.peertube.activity.SearchServerActivity; import net.schueller.peertube.activity.ServerAddressBookActivity; import net.schueller.peertube.helper.APIUrlHelper; +import java.util.Objects; + import static android.app.Activity.RESULT_OK; @@ -78,14 +80,15 @@ public class AddServerFragment extends Fragment { Activity act = getActivity(); - Boolean formValid = true; + boolean formValid = true; // close keyboard try { + assert act != null; InputMethodManager inputManager = (InputMethodManager) act.getSystemService(Context.INPUT_METHOD_SERVICE); - inputManager.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), + inputManager.hideSoftInputFromWindow(Objects.requireNonNull(act.getCurrentFocus()).getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } catch (Exception e) { diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java index 2e9c3b4..ada3fdf 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java @@ -28,6 +28,7 @@ import android.widget.TextView; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import com.mikepenz.iconics.Iconics; + import net.schueller.peertube.R; import net.schueller.peertube.model.File; import net.schueller.peertube.service.VideoPlayerService; @@ -66,13 +67,22 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment { LinearLayout menuRow = (LinearLayout) inflater.inflate(R.layout.row_popup_menu, null); TextView iconView = menuRow.findViewById(R.id.video_quality_icon); TextView textView = menuRow.findViewById(R.id.video_quality_text); - textView.setText(String.format(getString(R.string.menu_video_options_playback_speed), getCurrentVideoPlaybackSpeedString(videoPlayerService.getPlayBackSpeed()))); + + textView.setText( + getString( + R.string.menu_video_options_playback_speed, + getCurrentVideoPlaybackSpeedString(videoPlayerService.getPlayBackSpeed() + ) + ) + ); + + iconView.setText(R.string.video_option_speed_icon); new Iconics.IconicsBuilder().ctx(getContext()).on(iconView).build(); textView.setOnClickListener(view1 -> { VideoMenuSpeedFragment videoMenuSpeedFragment = VideoMenuSpeedFragment.newInstance(videoPlayerService); - videoMenuSpeedFragment.show(getActivity().getSupportFragmentManager(), + videoMenuSpeedFragment.show(requireActivity().getSupportFragmentManager(), VideoMenuSpeedFragment.TAG); }); menuHolder.addView(menuRow); @@ -87,8 +97,8 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment { textView2.setOnClickListener(view1 -> { VideoMenuQualityFragment videoMenuQualityFragment = VideoMenuQualityFragment.newInstance(getContext(), files); - videoMenuQualityFragment.show(getActivity().getSupportFragmentManager(), - videoMenuQualityFragment.TAG); + videoMenuQualityFragment.show(requireActivity().getSupportFragmentManager(), + VideoMenuQualityFragment.TAG); }); menuHolder.addView(menuRow2); 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 9fad3b3..16c75cf 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java @@ -18,7 +18,6 @@ package net.schueller.peertube.fragment; import android.app.Activity; -import android.app.AppOpsManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -66,15 +65,16 @@ import net.schueller.peertube.network.GetVideoDataService; import net.schueller.peertube.network.RetrofitInstance; import net.schueller.peertube.service.VideoPlayerService; -import java.util.Objects; - import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; import androidx.fragment.app.Fragment; + import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; +import static net.schueller.peertube.helper.VideoHelper.canEnterPipMode; + public class VideoPlayerFragment extends Fragment implements VideoRendererEventListener { private String mVideoUuid; @@ -134,6 +134,7 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL progressBar = activity.findViewById(R.id.torrent_progress); progressBar.setMax(100); + assert context != null; simpleExoPlayerView = new PlayerView(context); simpleExoPlayerView = activity.findViewById(R.id.video_view); @@ -195,23 +196,24 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL @Override public void onFailure(@NonNull Call