Merge pull request #674 from Bnyro/master

fix crash
This commit is contained in:
Bnyro 2022-07-03 12:19:11 +02:00 committed by GitHub
commit 3564b15b43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 26 additions and 29 deletions

View File

@ -39,7 +39,6 @@ import com.github.libretube.util.CronetHelper
import com.github.libretube.util.LocaleHelper import com.github.libretube.util.LocaleHelper
import com.github.libretube.util.RetrofitInstance import com.github.libretube.util.RetrofitInstance
import com.github.libretube.util.ThemeHelper import com.github.libretube.util.ThemeHelper
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.color.DynamicColors import com.google.android.material.color.DynamicColors
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
@ -47,7 +46,6 @@ class MainActivity : AppCompatActivity() {
lateinit var binding: ActivityMainBinding lateinit var binding: ActivityMainBinding
private lateinit var bottomNavigationView: BottomNavigationView
lateinit var navController: NavController lateinit var navController: NavController
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -90,7 +88,7 @@ class MainActivity : AppCompatActivity() {
// hide the trending page if enabled // hide the trending page if enabled
val hideTrendingPage = PreferenceHelper.getBoolean(this, "hide_trending_page", false) 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 false
// navigate to the default start tab // navigate to the default start tab

View File

@ -68,7 +68,11 @@ class SettingsActivity : AppCompatActivity() {
.beginTransaction() .beginTransaction()
.replace(R.id.settings, MainSettings()) .replace(R.id.settings, MainSettings())
.commit() .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
}
} }

View File

@ -1,14 +1,12 @@
package com.github.libretube.dialogs package com.github.libretube.dialogs
import android.app.Dialog import android.app.Dialog
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.util.TypedValue import android.util.TypedValue
import android.widget.Toast import android.widget.Toast
import androidx.core.text.HtmlCompat import androidx.core.text.HtmlCompat
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.activities.SettingsActivity
import com.github.libretube.databinding.DialogCustomInstanceBinding import com.github.libretube.databinding.DialogCustomInstanceBinding
import com.github.libretube.obj.CustomInstance import com.github.libretube.obj.CustomInstance
import com.github.libretube.preferences.PreferenceHelper import com.github.libretube.preferences.PreferenceHelper
@ -45,8 +43,7 @@ class CustomInstanceDialog : DialogFragment() {
URL(customInstance.frontendUrl).toURI() URL(customInstance.frontendUrl).toURI()
PreferenceHelper.saveCustomInstance(requireContext(), customInstance) PreferenceHelper.saveCustomInstance(requireContext(), customInstance)
val intent = Intent(context, SettingsActivity::class.java) activity?.recreate()
startActivity(intent)
dismiss() dismiss()
} catch (e: Exception) { } catch (e: Exception) {
// invalid URL // invalid URL

View File

@ -454,18 +454,12 @@ class PlayerFragment : Fragment() {
relatedStreams = response.relatedStreams relatedStreams = response.relatedStreams
runOnUiThread { runOnUiThread {
if (response.chapters != null) initializeChapters(response.chapters)
// set media sources for the player // set media sources for the player
setResolutionAndSubtitles(view, response) setResolutionAndSubtitles(view, response)
exoPlayer.prepare()
prepareExoPlayerView() prepareExoPlayerView()
initializePlayerView(view, response) initializePlayerView(view, response)
// support for time stamped links
if (arguments?.getLong("timeStamp") != null) {
val position = arguments?.getLong("timeStamp")!! * 1000
exoPlayer.seekTo(position)
}
seekToWatchPosition() seekToWatchPosition()
exoPlayer.prepare()
exoPlayer.play() exoPlayer.play()
exoPlayerView.useController = true exoPlayerView.useController = true
initializePlayerNotification(requireContext()) initializePlayerNotification(requireContext())
@ -485,12 +479,17 @@ class PlayerFragment : Fragment() {
run() run()
} }
// seek to saved watch position if available
private fun seekToWatchPosition() { private fun seekToWatchPosition() {
// seek to saved watch position if available
val watchPositions = PreferenceHelper.getWatchPositions(requireContext()) val watchPositions = PreferenceHelper.getWatchPositions(requireContext())
watchPositions.forEach { watchPositions.forEach {
if (it.videoId == videoId) exoPlayer.seekTo(it.position) 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 // the function is working recursively
@ -658,6 +657,9 @@ class PlayerFragment : Fragment() {
playerBinding.exoTitle.text = response.title playerBinding.exoTitle.text = response.title
// init the chapters recyclerview
if (response.chapters != null) initializeChapters(response.chapters)
// Listener for play and pause icon change // Listener for play and pause icon change
exoPlayer.addListener(object : Player.Listener { exoPlayer.addListener(object : Player.Listener {
override fun onIsPlayingChanged(isPlaying: Boolean) { override fun onIsPlayingChanged(isPlaying: Boolean) {

View File

@ -34,7 +34,7 @@ class AboutFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
val settingsActivity = activity as SettingsActivity val settingsActivity = activity as SettingsActivity
settingsActivity.binding.topBarTextView.text = getString(R.string.about) settingsActivity.changeTopBarText(getString(R.string.about))
binding.website.setOnClickListener { binding.website.setOnClickListener {
openLinkFromHref(WEBSITE_URL) openLinkFromHref(WEBSITE_URL)

View File

@ -1,6 +1,5 @@
package com.github.libretube.preferences package com.github.libretube.preferences
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
@ -16,7 +15,7 @@ class AdvancedSettings : PreferenceFragmentCompat() {
setPreferencesFromResource(R.xml.advanced_settings, rootKey) setPreferencesFromResource(R.xml.advanced_settings, rootKey)
val settingsActivity = activity as SettingsActivity val settingsActivity = activity as SettingsActivity
settingsActivity.binding.topBarTextView.text = getString(R.string.advanced) settingsActivity.changeTopBarText(getString(R.string.advanced))
// clear search history // clear search history
val clearHistory = findPreference<Preference>("clear_history") val clearHistory = findPreference<Preference>("clear_history")
@ -50,8 +49,7 @@ class AdvancedSettings : PreferenceFragmentCompat() {
PreferenceHelper.setToken(requireContext(), "") PreferenceHelper.setToken(requireContext(), "")
requireMainActivityRestart = true requireMainActivityRestart = true
val intent = Intent(context, SettingsActivity::class.java) activity?.recreate()
startActivity(intent)
} }
.setNegativeButton(getString(R.string.cancel)) { _, _ -> } .setNegativeButton(getString(R.string.cancel)) { _, _ -> }
.setTitle(R.string.reset) .setTitle(R.string.reset)

View File

@ -1,6 +1,5 @@
package com.github.libretube.preferences package com.github.libretube.preferences
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.preference.ListPreference import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
@ -17,20 +16,19 @@ class AppearanceSettings : PreferenceFragmentCompat() {
setPreferencesFromResource(R.xml.appearance_settings, rootKey) setPreferencesFromResource(R.xml.appearance_settings, rootKey)
val settingsActivity = activity as SettingsActivity val settingsActivity = activity as SettingsActivity
settingsActivity.binding.topBarTextView.text = getString(R.string.appearance) settingsActivity.changeTopBarText(getString(R.string.appearance))
val themeToggle = findPreference<ListPreference>("theme_togglee") val themeToggle = findPreference<ListPreference>("theme_togglee")
themeToggle?.setOnPreferenceChangeListener { _, _ -> themeToggle?.setOnPreferenceChangeListener { _, _ ->
requireMainActivityRestart = true requireMainActivityRestart = true
ThemeHelper.restartMainActivity(requireContext()) activity?.recreate()
true true
} }
val accentColor = findPreference<Preference>("accent_color") val accentColor = findPreference<Preference>("accent_color")
accentColor?.setOnPreferenceChangeListener { _, _ -> accentColor?.setOnPreferenceChangeListener { _, _ ->
requireMainActivityRestart = true requireMainActivityRestart = true
val intent = Intent(context, SettingsActivity::class.java) activity?.recreate()
startActivity(intent)
true true
} }

View File

@ -113,7 +113,7 @@ class InstanceSettings : PreferenceFragmentCompat() {
setPreferencesFromResource(R.xml.instance_settings, rootKey) setPreferencesFromResource(R.xml.instance_settings, rootKey)
val settingsActivity = activity as SettingsActivity val settingsActivity = activity as SettingsActivity
settingsActivity.binding.topBarTextView.text = getString(R.string.instance) settingsActivity.changeTopBarText(getString(R.string.instance))
val instance = findPreference<ListPreference>("selectInstance") val instance = findPreference<ListPreference>("selectInstance")
// fetchInstance() // fetchInstance()

View File

@ -12,6 +12,6 @@ class PlayerSettings : PreferenceFragmentCompat() {
setPreferencesFromResource(R.xml.player_settings, rootKey) setPreferencesFromResource(R.xml.player_settings, rootKey)
val settingsActivity = activity as SettingsActivity val settingsActivity = activity as SettingsActivity
settingsActivity.binding.topBarTextView.text = getString(R.string.player) settingsActivity.changeTopBarText(getString(R.string.player))
} }
} }

View File

@ -12,6 +12,6 @@ class SponsorBlockSettings : PreferenceFragmentCompat() {
setPreferencesFromResource(R.xml.sponsorblock_settings, rootKey) setPreferencesFromResource(R.xml.sponsorblock_settings, rootKey)
val settingsActivity = activity as SettingsActivity val settingsActivity = activity as SettingsActivity
settingsActivity.binding.topBarTextView.text = getString(R.string.sponsorblock) settingsActivity.changeTopBarText(getString(R.string.sponsorblock))
} }
} }