diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index ccabdb1dc..99a74f443 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -39,7 +39,6 @@ import com.github.libretube.util.CronetHelper import com.github.libretube.util.LocaleHelper import com.github.libretube.util.RetrofitInstance import com.github.libretube.util.ThemeHelper -import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.color.DynamicColors class MainActivity : AppCompatActivity() { @@ -47,7 +46,6 @@ class MainActivity : AppCompatActivity() { lateinit var binding: ActivityMainBinding - private lateinit var bottomNavigationView: BottomNavigationView lateinit var navController: NavController override fun onCreate(savedInstanceState: Bundle?) { @@ -90,7 +88,7 @@ class MainActivity : AppCompatActivity() { // hide the trending page if enabled val hideTrendingPage = PreferenceHelper.getBoolean(this, "hide_trending_page", false) - if (hideTrendingPage) bottomNavigationView.menu.findItem(R.id.homeFragment).isVisible = + if (hideTrendingPage) binding.bottomNav.menu.findItem(R.id.homeFragment).isVisible = false // navigate to the default start tab diff --git a/app/src/main/java/com/github/libretube/activities/SettingsActivity.kt b/app/src/main/java/com/github/libretube/activities/SettingsActivity.kt index db89c7dd7..da25444cd 100644 --- a/app/src/main/java/com/github/libretube/activities/SettingsActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/SettingsActivity.kt @@ -68,7 +68,11 @@ class SettingsActivity : AppCompatActivity() { .beginTransaction() .replace(R.id.settings, MainSettings()) .commit() - binding.topBarTextView.text = getString(R.string.settings) + changeTopBarText(getString(R.string.settings)) } } + + fun changeTopBarText(text: String) { + if (this::binding.isInitialized) binding.topBarTextView.text = text + } } diff --git a/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt b/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt index 9f8c14fba..2e6575532 100644 --- a/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt @@ -1,14 +1,12 @@ package com.github.libretube.dialogs import android.app.Dialog -import android.content.Intent import android.os.Bundle import android.util.TypedValue import android.widget.Toast import androidx.core.text.HtmlCompat import androidx.fragment.app.DialogFragment import com.github.libretube.R -import com.github.libretube.activities.SettingsActivity import com.github.libretube.databinding.DialogCustomInstanceBinding import com.github.libretube.obj.CustomInstance import com.github.libretube.preferences.PreferenceHelper @@ -45,8 +43,7 @@ class CustomInstanceDialog : DialogFragment() { URL(customInstance.frontendUrl).toURI() PreferenceHelper.saveCustomInstance(requireContext(), customInstance) - val intent = Intent(context, SettingsActivity::class.java) - startActivity(intent) + activity?.recreate() dismiss() } catch (e: Exception) { // invalid URL 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 eccdafd9a..7f4171127 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -454,18 +454,12 @@ class PlayerFragment : Fragment() { relatedStreams = response.relatedStreams runOnUiThread { - if (response.chapters != null) initializeChapters(response.chapters) // set media sources for the player setResolutionAndSubtitles(view, response) - exoPlayer.prepare() prepareExoPlayerView() initializePlayerView(view, response) - // support for time stamped links - if (arguments?.getLong("timeStamp") != null) { - val position = arguments?.getLong("timeStamp")!! * 1000 - exoPlayer.seekTo(position) - } seekToWatchPosition() + exoPlayer.prepare() exoPlayer.play() exoPlayerView.useController = true initializePlayerNotification(requireContext()) @@ -485,12 +479,17 @@ class PlayerFragment : Fragment() { run() } - // seek to saved watch position if available private fun seekToWatchPosition() { + // seek to saved watch position if available val watchPositions = PreferenceHelper.getWatchPositions(requireContext()) watchPositions.forEach { if (it.videoId == videoId) exoPlayer.seekTo(it.position) } + // support for time stamped links + if (arguments?.getLong("timeStamp") != null) { + val position = arguments?.getLong("timeStamp")!! * 1000 + exoPlayer.seekTo(position) + } } // the function is working recursively @@ -658,6 +657,9 @@ class PlayerFragment : Fragment() { playerBinding.exoTitle.text = response.title + // init the chapters recyclerview + if (response.chapters != null) initializeChapters(response.chapters) + // Listener for play and pause icon change exoPlayer.addListener(object : Player.Listener { override fun onIsPlayingChanged(isPlaying: Boolean) { diff --git a/app/src/main/java/com/github/libretube/preferences/AboutFragment.kt b/app/src/main/java/com/github/libretube/preferences/AboutFragment.kt index 45682558d..0584e92be 100644 --- a/app/src/main/java/com/github/libretube/preferences/AboutFragment.kt +++ b/app/src/main/java/com/github/libretube/preferences/AboutFragment.kt @@ -34,7 +34,7 @@ class AboutFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val settingsActivity = activity as SettingsActivity - settingsActivity.binding.topBarTextView.text = getString(R.string.about) + settingsActivity.changeTopBarText(getString(R.string.about)) binding.website.setOnClickListener { openLinkFromHref(WEBSITE_URL) diff --git a/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt b/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt index b8f4dbdef..f80dbafd9 100644 --- a/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt @@ -1,6 +1,5 @@ package com.github.libretube.preferences -import android.content.Intent import android.os.Bundle import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat @@ -16,7 +15,7 @@ class AdvancedSettings : PreferenceFragmentCompat() { setPreferencesFromResource(R.xml.advanced_settings, rootKey) val settingsActivity = activity as SettingsActivity - settingsActivity.binding.topBarTextView.text = getString(R.string.advanced) + settingsActivity.changeTopBarText(getString(R.string.advanced)) // clear search history val clearHistory = findPreference("clear_history") @@ -50,8 +49,7 @@ class AdvancedSettings : PreferenceFragmentCompat() { PreferenceHelper.setToken(requireContext(), "") requireMainActivityRestart = true - val intent = Intent(context, SettingsActivity::class.java) - startActivity(intent) + activity?.recreate() } .setNegativeButton(getString(R.string.cancel)) { _, _ -> } .setTitle(R.string.reset) 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 0ec1da15d..2fe2136b3 100644 --- a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt @@ -1,6 +1,5 @@ package com.github.libretube.preferences -import android.content.Intent import android.os.Bundle import androidx.preference.ListPreference import androidx.preference.Preference @@ -17,20 +16,19 @@ class AppearanceSettings : PreferenceFragmentCompat() { setPreferencesFromResource(R.xml.appearance_settings, rootKey) val settingsActivity = activity as SettingsActivity - settingsActivity.binding.topBarTextView.text = getString(R.string.appearance) + settingsActivity.changeTopBarText(getString(R.string.appearance)) val themeToggle = findPreference("theme_togglee") themeToggle?.setOnPreferenceChangeListener { _, _ -> requireMainActivityRestart = true - ThemeHelper.restartMainActivity(requireContext()) + activity?.recreate() true } val accentColor = findPreference("accent_color") accentColor?.setOnPreferenceChangeListener { _, _ -> requireMainActivityRestart = true - val intent = Intent(context, SettingsActivity::class.java) - startActivity(intent) + activity?.recreate() true } diff --git a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt index bad5cad27..6e23c80e0 100644 --- a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt @@ -113,7 +113,7 @@ class InstanceSettings : PreferenceFragmentCompat() { setPreferencesFromResource(R.xml.instance_settings, rootKey) val settingsActivity = activity as SettingsActivity - settingsActivity.binding.topBarTextView.text = getString(R.string.instance) + settingsActivity.changeTopBarText(getString(R.string.instance)) val instance = findPreference("selectInstance") // fetchInstance() diff --git a/app/src/main/java/com/github/libretube/preferences/PlayerSettings.kt b/app/src/main/java/com/github/libretube/preferences/PlayerSettings.kt index 5fbcae5a9..c4d98e939 100644 --- a/app/src/main/java/com/github/libretube/preferences/PlayerSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/PlayerSettings.kt @@ -12,6 +12,6 @@ class PlayerSettings : PreferenceFragmentCompat() { setPreferencesFromResource(R.xml.player_settings, rootKey) val settingsActivity = activity as SettingsActivity - settingsActivity.binding.topBarTextView.text = getString(R.string.player) + settingsActivity.changeTopBarText(getString(R.string.player)) } } diff --git a/app/src/main/java/com/github/libretube/preferences/SponsorBlockSettings.kt b/app/src/main/java/com/github/libretube/preferences/SponsorBlockSettings.kt index 51cb7f77b..1feb8b1de 100644 --- a/app/src/main/java/com/github/libretube/preferences/SponsorBlockSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/SponsorBlockSettings.kt @@ -12,6 +12,6 @@ class SponsorBlockSettings : PreferenceFragmentCompat() { setPreferencesFromResource(R.xml.sponsorblock_settings, rootKey) val settingsActivity = activity as SettingsActivity - settingsActivity.binding.topBarTextView.text = getString(R.string.sponsorblock) + settingsActivity.changeTopBarText(getString(R.string.sponsorblock)) } }