From 142b800c7be19172156c3eb58a16be2a6cc5f76f Mon Sep 17 00:00:00 2001 From: LagradOst Date: Sat, 4 Sep 2021 13:38:35 +0200 Subject: [PATCH] watch quality --- .../cloudstream3/ui/player/PlayerFragment.kt | 63 ++++++++++++------- .../ui/settings/SettingsFragment.kt | 63 +++++++++++++------ .../main/res/drawable/ic_baseline_hd_24.xml | 5 ++ app/src/main/res/layout/fragment_result.xml | 4 ++ app/src/main/res/values-sv/strings.xml | 2 + app/src/main/res/values/array.xml | 17 +++++ app/src/main/res/values/strings.xml | 3 + app/src/main/res/xml/settings.xml | 7 ++- 8 files changed, 122 insertions(+), 42 deletions(-) create mode 100644 app/src/main/res/drawable/ic_baseline_hd_24.xml diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt index 08bbb8ba..3d33710a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt @@ -82,6 +82,7 @@ import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.fromSaveToStyle import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.getAutoSelectLanguageISO639_1 import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.getCurrentSavedStyle +import com.lagradost.cloudstream3.utils.* import com.lagradost.cloudstream3.utils.AppUtils.getFocusRequest import com.lagradost.cloudstream3.utils.AppUtils.getVideoContentUri import com.lagradost.cloudstream3.utils.AppUtils.isCastApiAvailable @@ -92,9 +93,7 @@ import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStore.setKey import com.lagradost.cloudstream3.utils.DataStoreHelper.setLastWatched import com.lagradost.cloudstream3.utils.DataStoreHelper.setViewPos -import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog -import com.lagradost.cloudstream3.utils.SubtitleHelper import com.lagradost.cloudstream3.utils.UIHelper.getNavigationBarHeight import com.lagradost.cloudstream3.utils.UIHelper.getStatusBarHeight import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard @@ -102,8 +101,6 @@ import com.lagradost.cloudstream3.utils.UIHelper.hideSystemUI import com.lagradost.cloudstream3.utils.UIHelper.popCurrentPage import com.lagradost.cloudstream3.utils.UIHelper.showSystemUI import com.lagradost.cloudstream3.utils.UIHelper.toPx -import com.lagradost.cloudstream3.utils.VIDEO_PLAYER_BRIGHTNESS -import com.lagradost.cloudstream3.utils.VideoDownloadManager import com.lagradost.cloudstream3.utils.VideoDownloadManager.getId import kotlinx.android.synthetic.main.fragment_player.* import kotlinx.android.synthetic.main.player_custom_layout.* @@ -351,20 +348,24 @@ class PlayerFragment : Fragment() { click_overlay?.isVisible = !isShowing val titleMove = if (isShowing) 0f else -50.toPx.toFloat() - ObjectAnimator.ofFloat(video_title, "translationY", titleMove).apply { - duration = 200 - start() + video_title?.let { + ObjectAnimator.ofFloat(it, "translationY", titleMove).apply { + duration = 200 + start() + } } - - ObjectAnimator.ofFloat(video_title_rez, "translationY", titleMove).apply { - duration = 200 - start() + video_title_rez?.let { + ObjectAnimator.ofFloat(it, "translationY", titleMove).apply { + duration = 200 + start() + } } - val playerBarMove = if (isShowing) 0f else 50.toPx.toFloat() - ObjectAnimator.ofFloat(bottom_player_bar, "translationY", playerBarMove).apply { - duration = 200 - start() + bottom_player_bar?.let { + ObjectAnimator.ofFloat(it, "translationY", playerBarMove).apply { + duration = 200 + start() + } } changeSkip() @@ -398,10 +399,10 @@ class PlayerFragment : Fragment() { //player_pause_holder?.alpha = 0f } - bottom_player_bar.startAnimation(fadeAnimation) - player_top_holder.startAnimation(fadeAnimation) + bottom_player_bar?.startAnimation(fadeAnimation) + player_top_holder?.startAnimation(fadeAnimation) // video_holder?.startAnimation(fadeAnimation) - player_torrent_info?.isVisible = (isTorrent && isShowing) + player_torrent_info?.isVisible = (isTorrent && isShowing) // player_torrent_info?.startAnimation(fadeAnimation) //video_lock_holder?.startAnimation(fadeAnimation) } @@ -1561,7 +1562,8 @@ class PlayerFragment : Fragment() { initPlayer() } - private fun setMirrorId(id: Int) { + private fun setMirrorId(id: Int?) { + if (id == null) return val copy = playerData.copy(mirrorId = id) playerData = copy //initPlayer() @@ -1930,6 +1932,10 @@ class PlayerFragment : Fragment() { if (isDownloadedFile || currentUrl?.name == null) "${width}x${height}" else "${currentUrl.name} - ${width}x${height}" if (!hasUsedFirstRender) { // DON'T WANT TO SET MULTIPLE MESSAGES + if (!isDownloadedFile && !isTorrent && exoPlayer.duration in 5_000..10_000) { + // if(getapi apiName ) + showToast(activity, R.string.vpn_might_be_needed, LENGTH_SHORT) + } changeSkip() exoPlayer .createMessage { _, _ -> @@ -2031,6 +2037,20 @@ class PlayerFragment : Fragment() { } } + fun preferedQuality(tempCurrentUrls: List?): Int? { + if (tempCurrentUrls.isNullOrEmpty()) return null + val sortedUrls = sortUrls(tempCurrentUrls).reversed() + val currentQuality = + settingsManager.getInt(getString(R.string.watch_quality_pref), Qualities.values().last().value) + + var currentId = sortedUrls.first().getId() // lowest quality + for (url in sortedUrls) { + if (url.quality > currentQuality) break + currentId = url.getId() + } + return currentId + } + //http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4 @SuppressLint("ClickableViewAccessibility") private fun initPlayer() { @@ -2041,7 +2061,8 @@ class PlayerFragment : Fragment() { view?.setOnTouchListener { _, _ -> return@setOnTouchListener true } // VERY IMPORTANT https://stackoverflow.com/questions/28818926/prevent-clicking-on-a-button-in-an-activity-while-showing-a-fragment val tempCurrentUrls = getUrls() if (tempCurrentUrls != null) { - setMirrorId(sortUrls(tempCurrentUrls).first().getId()) // BECAUSE URLS CANT BE REORDERED + setMirrorId(preferedQuality(tempCurrentUrls)) + //setMirrorId(sortedUrls.first().getId()) // BECAUSE URLS CANT BE REORDERED } val tempUrl = getCurrentUrl() println("TEMP:" + tempUrl?.name) @@ -2053,7 +2074,7 @@ class PlayerFragment : Fragment() { val currentUrls = getUrls() if (currentUrls != null && currentUrls.isNotEmpty()) { if (!isCurrentlyPlaying) { - setMirrorId(sortUrls(currentUrls).first().getId()) // BECAUSE URLS CANT BE REORDERED + setMirrorId(preferedQuality(currentUrls)) initPlayer(getCurrentUrl()) } } else { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt index 1331a635..68cd2096 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt @@ -11,13 +11,25 @@ import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate +import com.lagradost.cloudstream3.utils.Qualities +import com.lagradost.cloudstream3.utils.SingleSelectionHelper +import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard import kotlin.concurrent.thread class SettingsFragment : PreferenceFragmentCompat() { - var count = 0 + private var beneneCount = 0 + + private val languages = arrayListOf( + Triple("\uD83C\uDDEC\uD83C\uDDE7", "English", "en"), + Triple("\uD83C\uDDF3\uD83C\uDDF1", "Dutch", "nl"), + Triple("\uD83C\uDDEB\uD83C\uDDF7", "French", "fr"), + Triple("\uD83C\uDDEC\uD83C\uDDF7", "Greek", "gr"), + Triple("\uD83C\uDDF8\uD83C\uDDEA", "Swedish", "sv"), + Triple("\uD83C\uDDF5\uD83C\uDDED", "Tagalog", "tl"), + ) // idk, if you find a way of automating this it would be great override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { hideKeyboard() @@ -25,21 +37,39 @@ class SettingsFragment : PreferenceFragmentCompat() { val updatePreference = findPreference(getString(R.string.manual_check_update_key))!! val localePreference = findPreference(getString(R.string.locale_key))!! val benenePreference = findPreference(getString(R.string.benene_count))!! + val watchQualityPreference = findPreference(getString(R.string.quality_pref_key))!! + + watchQualityPreference.setOnPreferenceClickListener { + val prefNames = resources.getStringArray(R.array.quality_pref) + val prefValues = resources.getIntArray(R.array.quality_pref_values) + val settingsManager = PreferenceManager.getDefaultSharedPreferences(context) + + val currentQuality = settingsManager.getInt(getString(R.string.watch_quality_pref), Qualities.values().last().value) + context?.showBottomDialog( + prefNames.toList(), + prefValues.indexOf(currentQuality), + getString(R.string.watch_quality_pref), + true, + {}) { + settingsManager.edit().putInt(getString(R.string.watch_quality_pref), prefValues[it]).apply() + } + return@setOnPreferenceClickListener true + } try { val settingsManager = PreferenceManager.getDefaultSharedPreferences(context) - count = settingsManager.getInt(getString(R.string.benene_count), 0) + beneneCount = settingsManager.getInt(getString(R.string.benene_count), 0) benenePreference.summary = - if (count <= 0) getString(R.string.benene_count_text_none) else getString(R.string.benene_count_text).format( - count + if (beneneCount <= 0) getString(R.string.benene_count_text_none) else getString(R.string.benene_count_text).format( + beneneCount ) benenePreference.setOnPreferenceClickListener { try { - count++ - settingsManager.edit().putInt(getString(R.string.benene_count), count).apply() - it.summary = getString(R.string.benene_count_text).format(count) + beneneCount++ + settingsManager.edit().putInt(getString(R.string.benene_count), beneneCount).apply() + it.summary = getString(R.string.benene_count_text).format(beneneCount) } catch (e: Exception) { e.printStackTrace() } @@ -62,20 +92,13 @@ class SettingsFragment : PreferenceFragmentCompat() { } localePreference.setOnPreferenceClickListener { pref -> - val languages = arrayListOf( - Triple("\uD83C\uDDEC\uD83C\uDDE7", "English", "en"), - Triple("\uD83C\uDDF3\uD83C\uDDF1", "Dutch", "nl"), - Triple("\uD83C\uDDEB\uD83C\uDDF7", "French", "fr"), - Triple("\uD83C\uDDEC\uD83C\uDDF7", "Greek", "gr"), - Triple("\uD83C\uDDF8\uD83C\uDDEA", "Swedish", "sv"), - Triple("\uD83C\uDDF5\uD83C\uDDED", "Tagalog", "tl"), - ) // idk, if you find a way of automating this it would be great - if (count > 100) { - languages.add(Triple("\uD83E\uDD8D", "mmmm... monke", "mo")) + val tempLangs = languages + if (beneneCount > 100) { + tempLangs.add(Triple("\uD83E\uDD8D", "mmmm... monke", "mo")) } val current = getCurrentLocale() - val languageCodes = languages.map { it.third } - val languageNames = languages.map { "${it.first} ${it.second}" } + val languageCodes = tempLangs.map { it.third } + val languageNames = tempLangs.map { "${it.first} ${it.second}" } val index = languageCodes.indexOf(current) pref?.context?.showDialog( languageNames, index, getString(R.string.app_language), true, { } @@ -104,7 +127,7 @@ class SettingsFragment : PreferenceFragmentCompat() { override fun onPreferenceTreeClick(preference: Preference?): Boolean { if (preference != null) { - if (preference.key == "subtitle_settings_key") { + if (preference.key == getString(R.string.subtitle_settings_key)) { SubtitlesFragment.push(activity, false) } } diff --git a/app/src/main/res/drawable/ic_baseline_hd_24.xml b/app/src/main/res/drawable/ic_baseline_hd_24.xml new file mode 100644 index 00000000..02a314e9 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_hd_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/fragment_result.xml b/app/src/main/res/layout/fragment_result.xml index 9977bef5..ee8139fd 100644 --- a/app/src/main/res/layout/fragment_result.xml +++ b/app/src/main/res/layout/fragment_result.xml @@ -313,6 +313,8 @@ android:layout_height="wrap_content"> Pausa Återuppta Ett nerladdningsfel uppstod, kolla om appen har lagringsbehörigheter + Föredragen videokvalitet + diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 322e014e..febfea2d 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -14,6 +14,23 @@ @id/cast_button_type_forward_30_seconds + + 2160p + 1440p + 1080p + 720p + 480p + 360p + + + 4 + 3 + 2 + 1 + -1 + -2 + + @string/episode_action_chomecast_episode @string/episode_action_chomecast_mirror diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1663e405..ac1b8c59 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,6 +10,8 @@ manual_check_update fast_forward_button_time benene_count + subtitle_settings_key + quality_pref_key %d %s | %sMB @@ -240,4 +242,5 @@ Don\'t show again Update + Preferred watch quality diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 52b0bbc8..13c3964f 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -8,11 +8,16 @@ app:isPreferenceVisible="true" > + +