From 11484a55c941d1edc9e9dc379fd9b32e67452b01 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 12 Jun 2022 17:44:15 +0200 Subject: [PATCH 1/3] theme bug fix --- .../com/github/libretube/preferences/AppearanceSettings.kt | 2 +- app/src/main/res/values/strings.xml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt index 46a9ad30a..cb269fb28 100644 --- a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt @@ -19,8 +19,8 @@ class AppearanceSettings : PreferenceFragmentCompat() { val themeToggle = findPreference("theme_togglee") themeToggle?.setOnPreferenceChangeListener { _, _ -> - activity?.recreate() requireMainActivityRestart = true + ThemeHelper().restartMainActivity(requireContext()) true } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 46aa5e817..edaa7a5b6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -60,8 +60,8 @@ Language System System - Luminating light - Dissapearing dark + Light theme + Dark theme %1$s subscribers Settings Location @@ -107,7 +107,7 @@ Yeeting yellow Groovy green Pleasurable purple - Blind black + Black theme Mystic Material 3 Notifications Icon From abb76d3ea5c6edf447d870af44048c49e6d91614 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 12 Jun 2022 19:26:38 +0200 Subject: [PATCH 2/3] related streams toggle --- .../libretube/fragments/PlayerFragment.kt | 41 ++++++++++++++----- app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/advanced_settings.xml | 11 +++++ 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index e3002e85d..d508c5841 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -49,6 +49,7 @@ import com.github.libretube.dialogs.AddtoPlaylistDialog import com.github.libretube.dialogs.DownloadDialog import com.github.libretube.dialogs.ShareDialog import com.github.libretube.hideKeyboard +import com.github.libretube.obj.ChapterSegment import com.github.libretube.obj.PipedStream import com.github.libretube.obj.Segment import com.github.libretube.obj.Segments @@ -80,6 +81,7 @@ import com.google.android.exoplayer2.upstream.DefaultDataSource import com.google.android.exoplayer2.upstream.DefaultHttpDataSource import com.google.android.exoplayer2.util.RepeatModeUtil import com.google.android.material.button.MaterialButton +import com.google.android.material.card.MaterialCardView import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.squareup.picasso.Picasso import java.io.IOException @@ -112,6 +114,7 @@ class PlayerFragment : Fragment() { private lateinit var motionLayout: MotionLayout private lateinit var exoPlayer: ExoPlayer private lateinit var segmentData: Segments + private var relatedStreamsEnabled = true private lateinit var relDownloadVideo: LinearLayout @@ -259,13 +262,9 @@ class PlayerFragment : Fragment() { } } - view.findViewById(R.id.comments_toggle) + view.findViewById(R.id.comments_toggle) .setOnClickListener { - commentsRecView.visibility = - if (commentsRecView.isVisible) View.GONE else View.VISIBLE - relatedRecView.visibility = - if (relatedRecView.isVisible) View.GONE else View.VISIBLE - if (!commentsLoaded!!) fetchComments() + toggleComments() } // FullScreen button trigger @@ -328,6 +327,14 @@ class PlayerFragment : Fragment() { GridLayoutManager(view.context, resources.getInteger(R.integer.grid_items)) } + private fun toggleComments() { + commentsRecView.visibility = + if (commentsRecView.isVisible) View.GONE else View.VISIBLE + relatedRecView.visibility = + if (relatedRecView.isVisible) View.GONE else View.VISIBLE + if (!commentsLoaded!!) fetchComments() + } + override fun onDestroy() { super.onDestroy() try { @@ -418,13 +425,18 @@ class PlayerFragment : Fragment() { } } } + // check whether related streams are enabled + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) + relatedStreamsEnabled = sharedPreferences.getBoolean("related_streams_toggle", true) runOnUiThread { createExoPlayer(view) prepareExoPlayerView() + if (response.chapters != null) initializeChapters(response.chapters) setResolutionAndSubtitles(view, response) exoPlayer.prepare() exoPlayer.play() initializePlayerView(view, response) + if (!relatedStreamsEnabled) toggleComments() } } } @@ -540,11 +552,12 @@ class PlayerFragment : Fragment() { } } } - - relatedRecView.adapter = TrendingAdapter( - response.relatedStreams!!, - childFragmentManager - ) + if (relatedStreamsEnabled) { + relatedRecView.adapter = TrendingAdapter( + response.relatedStreams!!, + childFragmentManager + ) + } val description = response.description!! view.findViewById(R.id.player_description).text = // detect whether the description is html formatted @@ -582,6 +595,12 @@ class PlayerFragment : Fragment() { } } + private fun initializeChapters(chapters: List) { + chapters.forEach { chapter -> + Log.e(TAG, chapter.title!!) + } + } + private fun setResolutionAndSubtitles(view: View, response: Streams) { var videosNameArray: Array = arrayOf() videosNameArray += "HLS" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index edaa7a5b6..1a794f795 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -171,4 +171,6 @@ Please enter a valid url Version %1$s Get to know team LibreTube and how it all happens. + Related streams + Show related streams to videos. diff --git a/app/src/main/res/xml/advanced_settings.xml b/app/src/main/res/xml/advanced_settings.xml index db249037b..957631450 100644 --- a/app/src/main/res/xml/advanced_settings.xml +++ b/app/src/main/res/xml/advanced_settings.xml @@ -68,4 +68,15 @@ + + + + + + \ No newline at end of file From 3ca0e81ce4922054f17e4363a6d2e63b315b3bdf Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 12 Jun 2022 19:28:39 +0200 Subject: [PATCH 3/3] ktlint --- .../main/java/com/github/libretube/fragments/PlayerFragment.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index d508c5841..cfec34244 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -426,7 +426,8 @@ class PlayerFragment : Fragment() { } } // check whether related streams are enabled - val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) + val sharedPreferences = PreferenceManager + .getDefaultSharedPreferences(requireContext()) relatedStreamsEnabled = sharedPreferences.getBoolean("related_streams_toggle", true) runOnUiThread { createExoPlayer(view)