From 039f898556438bf3c86e034b8152e154fb2c91da Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 26 Nov 2022 18:45:55 +0100 Subject: [PATCH] replace `open with` with PiP --- .../libretube/constants/PreferenceKeys.kt | 1 - .../libretube/ui/fragments/PlayerFragment.kt | 47 ++++--------------- app/src/main/res/layout/fragment_player.xml | 4 +- app/src/main/res/values-az/strings.xml | 2 - app/src/main/res/values-es/strings.xml | 2 - app/src/main/res/values-hi/strings.xml | 2 - app/src/main/res/values-in/strings.xml | 2 - app/src/main/res/values-lt/strings.xml | 2 - app/src/main/res/values-nb-rNO/strings.xml | 2 - app/src/main/res/values-pl/strings.xml | 2 - app/src/main/res/values-uk/strings.xml | 2 - app/src/main/res/values-vi/strings.xml | 2 - app/src/main/res/values/strings.xml | 4 +- app/src/main/res/xml/player_settings.xml | 7 --- 14 files changed, 14 insertions(+), 67 deletions(-) diff --git a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt index 8565f98af..548b33efe 100644 --- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt @@ -85,7 +85,6 @@ object PreferenceKeys { const val QUEUE_AUTO_INSERT_RELATED = "queue_insert_related_videos" const val PLAYER_SWIPE_CONTROLS = "player_swipe_controls" const val PLAYER_SCREEN_BRIGHTNESS = "player_screen_brightness" - const val SHOW_OPEN_WITH = "show_open_with" /** * Background mode diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index 4b9983b9f..7cc4f946a 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -4,7 +4,6 @@ import android.annotation.SuppressLint import android.app.ActivityManager import android.app.PictureInPictureParams import android.content.Context -import android.content.Intent import android.content.pm.ActivityInfo import android.content.res.Configuration import android.media.session.PlaybackState @@ -153,11 +152,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { private lateinit var exoPlayerView: StyledPlayerView private var subtitles = mutableListOf() - /** - * user preferences - */ - private var videoShownInExternalPlayer = false - /** * for the player notification */ @@ -283,6 +277,11 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { } if (usePiP()) (activity as MainActivity).setPictureInPictureParams(getPipParams()) + + if (SDK_INT < Build.VERSION_CODES.O) { + binding.relPlayerPip.visibility = View.GONE + binding.optionsLL.weightSum = 4f + } } // actions that don't depend on video information @@ -388,11 +387,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { LinearLayoutManager.HORIZONTAL, false ) - - if (!PreferenceHelper.getBoolean(PreferenceKeys.SHOW_OPEN_WITH, false)) { - binding.relPlayerOpen.visibility = View.GONE - binding.optionsLL.weightSum = 4f - } } private fun setFullscreen() { @@ -459,13 +453,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { } } - override fun onStart() { - super.onStart() - - // Assuming the video is not playing in external player when returning to app - videoShownInExternalPlayer = false - } - override fun onPause() { // pauses the player if the screen is turned off @@ -889,25 +876,12 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { } if (response.hls != null) { - binding.relPlayerOpen.setOnClickListener { - // Do not start picture in picture when playing in external player - videoShownInExternalPlayer = true - - // start an intent with video as mimetype using the hls stream - val uri: Uri = Uri.parse(response.hls) - val intent = Intent() - - intent.action = Intent.ACTION_VIEW - intent.setDataAndType(uri, "video/*") - intent.putExtra(Intent.EXTRA_TITLE, streams.title) - intent.putExtra("title", streams.title) - intent.putExtra("artist", streams.uploader) - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - + binding.relPlayerPip.setOnClickListener { + if (SDK_INT < Build.VERSION_CODES.O) return@setOnClickListener try { - startActivity(intent) + activity?.enterPictureInPictureMode(getPipParams()) } catch (e: Exception) { - Toast.makeText(context, R.string.no_player_found, Toast.LENGTH_SHORT).show() + e.printStackTrace() } } } @@ -1388,8 +1362,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { private fun shouldStartPiP(): Boolean { if (!PlayerHelper.pipEnabled || - exoPlayer.playbackState == PlaybackState.STATE_PAUSED || - videoShownInExternalPlayer + exoPlayer.playbackState == PlaybackState.STATE_PAUSED ) { return false } diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index 123e3be31..dc93ce903 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -184,7 +184,7 @@ @@ -198,7 +198,7 @@ style="@style/PlayerActionsText" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/open" /> + android:text="@string/pop_up" /> Parlaqlığı və səs səviyyəsini nizamlamaq üçün sürüşdürmə jesti istifadə et. Səs səviyyəsi Sürüşdürmə nəzarətləri - İlə aç Defolt - Videonu oynadıcıda 3-cü tərəf tətbiq ilə açmaq üçün düymə göstər. \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index a3f7a6382..28a82da45 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -401,6 +401,4 @@ Brillo Use el gesto de deslizar para ajustar el brillo y el volumen. Por defecto - Abrir con - Mostrar un botón para abrir el vídeo con una aplicación de terceros en el reproductor. \ No newline at end of file diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index 74fc31e86..c43c49800 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -314,7 +314,6 @@ नए परिवर्तनों का उपयोग करने के लिए ऐप को पुनरारंभ करें। कोई बाहरी प्लेयर नहीं मिला। कृपया सुनिश्चित करें कि आपके पास एक इन्स्टाल है। डिफ़ॉल्टस - के साथ खोलें सबसे पुराने प्लेयर के लिए विडिओ फॉर्मेट विडियो नहीं @@ -402,5 +401,4 @@ ऑडियो गुणवत्ता श्रेष्ठ न्यूनतम - वीडियो को तीसरे पक्ष के ऐप्लिकेशन के साथ प्लेयर पर खोलने के लिए बटन दिखाएं। \ No newline at end of file diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 3e9405ff8..927aa836f 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -399,8 +399,6 @@ Otomatis Kendali usap Gunakan gestur usap untuk mengatur kecerahan dan volume. - Buka Dengan Bawaan - Tampilkan tombol dalam pemain untuk membuka video dengan aplikasi pihak ketiga. Kecerahan \ No newline at end of file diff --git a/app/src/main/res/values-lt/strings.xml b/app/src/main/res/values-lt/strings.xml index d09416692..dd2ab4375 100644 --- a/app/src/main/res/values-lt/strings.xml +++ b/app/src/main/res/values-lt/strings.xml @@ -401,6 +401,4 @@ Garsas Braukimo gestu sureguliuokite ryškumą ir garsumą. Numatyti - Atidaryti naudojant - Rodyti mygtuką grotuve, kad galima būtų atidaryti vaizdo įrašą naudojant trečiosios šalies programėlę. \ No newline at end of file diff --git a/app/src/main/res/values-nb-rNO/strings.xml b/app/src/main/res/values-nb-rNO/strings.xml index a3c4b9d40..bdebb4585 100644 --- a/app/src/main/res/values-nb-rNO/strings.xml +++ b/app/src/main/res/values-nb-rNO/strings.xml @@ -397,10 +397,8 @@ Velg en annen startfane først. Dragningskontroller Bruk dragnings-håndvendinger for å justere lys- og lydstyrke. - Åpne med Forvalg Lysstyrke Lydstyrke Auto - Vis en knapp i avspilleren for å åpne video med tredjepartsprogram. \ No newline at end of file diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index ee4130974..1ec0cbb6d 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -401,6 +401,4 @@ Sterowanie gestami Steruj jasnością i głośnością za pomocą gestów. Domyślne - Przycisk „Otwórz w…” - Pozwala pzekierować odtwarzanie do zewnętrznej aplikacji. \ No newline at end of file diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 807e9aaec..82a842c96 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -401,6 +401,4 @@ Для регулювання яскравості та гучності використовувати жест посування. Гучність Типові - Відкрити в - Показувати на програвачі кнопку для відкриття відео за допомогою стороннього застосунку. \ No newline at end of file diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index cf0a7bf27..f426dcd70 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -396,11 +396,9 @@ Độ sáng Âm lượng Tự động - Mở với Mặc định Vui lòng chọn một tab bắt đầu khác trước tiên! Điều khiển vuốt Sử dụng thao tác vuốt để điều chỉnh độ sáng và âm lượng. - Hiển thị một nút trong trình phát để mở video bằng ứng dụng của bên thứ ba. Đánh dấu trang \ 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 f87d400bc..8f26d0f3f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -395,8 +395,8 @@ Swipe controls Use swipe gesture to adjust the brightness and volume. Defaults - Open With - Show a button in the player to open the video with a third-party app. + Pop-Up + Download Service Shows a notification when downloading media. diff --git a/app/src/main/res/xml/player_settings.xml b/app/src/main/res/xml/player_settings.xml index fa490ca54..0d4b6c3c6 100644 --- a/app/src/main/res/xml/player_settings.xml +++ b/app/src/main/res/xml/player_settings.xml @@ -134,13 +134,6 @@ app:key="pause_screen_off" app:title="@string/pauseOnScreenOff" /> - - \ No newline at end of file