bug fixes

This commit is contained in:
Bnyro 2022-09-08 20:19:44 +02:00
parent b23f22146a
commit f8dabbda4e
20 changed files with 59 additions and 64 deletions

View File

@ -316,14 +316,23 @@ class MainActivity : BaseActivity() {
super.onStart() super.onStart()
// check whether an URI got submitted over the intent data and load it // check whether an URI got submitted over the intent data and load it
when { when {
intent?.getStringExtra(IntentData.channelId) != null -> loadChannel( intent?.getStringExtra(IntentData.channelId) != null -> navController.navigate(
channelId = intent?.getStringExtra(IntentData.channelId) R.id.channelFragment,
bundleOf(
IntentData.channelName to intent?.getStringExtra(IntentData.channelId)!!
) )
intent?.getStringExtra(IntentData.userId) != null -> loadChannel(
channelName = intent?.getStringExtra(IntentData.userId)
) )
intent?.getStringExtra(IntentData.playlistId) != null -> loadPlaylist( intent?.getStringExtra(IntentData.channelName) != null -> navController.navigate(
intent?.getStringExtra(IntentData.playlistId)!! R.id.channelFragment,
bundleOf(
IntentData.channelId to intent?.getStringExtra(IntentData.channelName)
)
)
intent?.getStringExtra(IntentData.playlistId) != null -> navController.navigate(
R.id.playlistFragment,
bundleOf(
IntentData.playlistId to intent?.getStringExtra(IntentData.playlistId)!!
)
) )
intent?.getStringExtra(IntentData.videoId) != null -> loadVideo( intent?.getStringExtra(IntentData.videoId) != null -> loadVideo(
videoId = intent?.getStringExtra(IntentData.videoId)!!, videoId = intent?.getStringExtra(IntentData.videoId)!!,
@ -335,8 +344,8 @@ class MainActivity : BaseActivity() {
private fun loadVideo(videoId: String, timeStamp: Long?) { private fun loadVideo(videoId: String, timeStamp: Long?) {
val bundle = Bundle() val bundle = Bundle()
bundle.putString("videoId", videoId) bundle.putString(IntentData.videoId, videoId)
if (timeStamp != null) bundle.putLong("timeStamp", timeStamp) if (timeStamp != null) bundle.putLong(IntentData.timeStamp, timeStamp)
val frag = PlayerFragment() val frag = PlayerFragment()
frag.arguments = bundle frag.arguments = bundle
@ -354,23 +363,6 @@ class MainActivity : BaseActivity() {
}, 100) }, 100)
} }
private fun loadChannel(
channelId: String? = null,
channelName: String? = null
) {
val bundle = if (channelId != null) {
bundleOf("channel_id" to channelId)
} else {
bundleOf("channel_name" to channelName)
}
navController.navigate(R.id.channelFragment, bundle)
}
private fun loadPlaylist(playlistId: String) {
val bundle = bundleOf("playlist_id" to playlistId)
navController.navigate(R.id.playlistFragment, bundle)
}
private fun minimizePlayer() { private fun minimizePlayer() {
binding.mainMotionLayout.transitionToEnd() binding.mainMotionLayout.transitionToEnd()
findViewById<ConstraintLayout>(R.id.main_container).isClickable = false findViewById<ConstraintLayout>(R.id.main_container).isClickable = false

View File

@ -52,7 +52,7 @@ class RouterActivity : BaseActivity() {
.replace("/c/", "") .replace("/c/", "")
.replace("/user/", "") .replace("/user/", "")
intent.putExtra(IntentData.userId, channelName) intent.putExtra(IntentData.channelName, channelName)
} }
uri.path!!.contains("/playlist") -> { uri.path!!.contains("/playlist") -> {
var playlistId = uri.query!! var playlistId = uri.query!!

View File

@ -49,7 +49,7 @@ class ChannelAdapter(
root.setOnClickListener { root.setOnClickListener {
NavigationHelper.navigateVideo(root.context, trending.url) NavigationHelper.navigateVideo(root.context, trending.url)
} }
val videoId = trending.url.toID() val videoId = trending.url!!.toID()
root.setOnLongClickListener { root.setOnLongClickListener {
VideoOptionsDialog(videoId) VideoOptionsDialog(videoId)
.show(childFragmentManager, VideoOptionsDialog::class.java.name) .show(childFragmentManager, VideoOptionsDialog::class.java.name)

View File

@ -33,7 +33,7 @@ class LegacySubscriptionAdapter(
root.setOnClickListener { root.setOnClickListener {
NavigationHelper.navigateChannel( NavigationHelper.navigateChannel(
root.context, root.context,
subscription.url.toID() subscription.url!!.toID()
) )
} }
} }

View File

@ -97,7 +97,7 @@ class SearchAdapter(
root.setOnClickListener { root.setOnClickListener {
NavigationHelper.navigateVideo(root.context, item.url) NavigationHelper.navigateVideo(root.context, item.url)
} }
val videoId = item.url.toID() val videoId = item.url!!.toID()
root.setOnLongClickListener { root.setOnLongClickListener {
VideoOptionsDialog(videoId) VideoOptionsDialog(videoId)
.show(childFragmentManager, VideoOptionsDialog::class.java.name) .show(childFragmentManager, VideoOptionsDialog::class.java.name)
@ -121,7 +121,7 @@ class SearchAdapter(
root.setOnClickListener { root.setOnClickListener {
NavigationHelper.navigateChannel(root.context, item.url) NavigationHelper.navigateChannel(root.context, item.url)
} }
val channelId = item.url.toID() val channelId = item.url!!.toID()
isSubscribed(channelId, binding) isSubscribed(channelId, binding)
} }

View File

@ -36,7 +36,7 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscrip
NavigationHelper.navigateChannel(root.context, subscription.url) NavigationHelper.navigateChannel(root.context, subscription.url)
} }
subscriptionSubscribe.setOnClickListener { subscriptionSubscribe.setOnClickListener {
val channelId = subscription.url.toID() val channelId = subscription.url!!.toID()
if (subscribed) { if (subscribed) {
subscriptionSubscribe.text = root.context.getString(R.string.subscribe) subscriptionSubscribe.text = root.context.getString(R.string.subscribe)
SubscriptionHelper.unsubscribe(channelId) SubscriptionHelper.unsubscribe(channelId)

View File

@ -3,7 +3,8 @@ package com.github.libretube.constants
object IntentData { object IntentData {
const val videoId = "videoId" const val videoId = "videoId"
const val channelId = "channelId" const val channelId = "channelId"
const val userId = "userId" const val channelName = "channelName"
const val playlistId = "playlistId" const val playlistId = "playlistId"
const val timeStamp = "timeStamp" const val timeStamp = "timeStamp"
const val position = "position"
} }

View File

@ -11,6 +11,7 @@ import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.DialogAddtoplaylistBinding import com.github.libretube.databinding.DialogAddtoplaylistBinding
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.models.PlaylistViewModel import com.github.libretube.models.PlaylistViewModel
@ -29,7 +30,7 @@ class AddToPlaylistDialog : DialogFragment() {
private lateinit var token: String private lateinit var token: String
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
videoId = arguments?.getString("videoId")!! videoId = arguments?.getString(IntentData.videoId)!!
binding = DialogAddtoplaylistBinding.inflate(layoutInflater) binding = DialogAddtoplaylistBinding.inflate(layoutInflater)
binding.title.text = ThemeHelper.getStyledAppName(requireContext()) binding.title.text = ThemeHelper.getStyledAppName(requireContext())

View File

@ -63,7 +63,7 @@ class PlaylistOptionsDialog(
} }
BackgroundHelper.playOnBackground( BackgroundHelper.playOnBackground(
context = requireContext(), context = requireContext(),
videoId = playlist.relatedStreams!![0].url.toID(), videoId = playlist.relatedStreams!![0].url!!.toID(),
playlistId = playlistId playlistId = playlistId
) )
} }

View File

@ -9,6 +9,7 @@ import android.widget.Toast
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import com.github.libretube.Globals import com.github.libretube.Globals
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID import com.github.libretube.constants.PLAYER_NOTIFICATION_ID
import com.github.libretube.util.BackgroundHelper import com.github.libretube.util.BackgroundHelper
import com.github.libretube.util.PreferenceHelper import com.github.libretube.util.PreferenceHelper
@ -79,7 +80,7 @@ class VideoOptionsDialog(
if (token != "") { if (token != "") {
val newFragment = AddToPlaylistDialog() val newFragment = AddToPlaylistDialog()
val bundle = Bundle() val bundle = Bundle()
bundle.putString("videoId", videoId) bundle.putString(IntentData.videoId, videoId)
newFragment.arguments = bundle newFragment.arguments = bundle
newFragment.show( newFragment.show(
parentFragmentManager, parentFragmentManager,

View File

@ -3,7 +3,7 @@ package com.github.libretube.extensions
/** /**
* format a Piped route to an ID * format a Piped route to an ID
*/ */
fun Any?.toID(): String { fun Any.toID(): String {
return this return this
.toString() .toString()
.replace("/watch?v=", "") // videos .replace("/watch?v=", "") // videos

View File

@ -11,6 +11,7 @@ import com.github.libretube.R
import com.github.libretube.adapters.ChannelAdapter import com.github.libretube.adapters.ChannelAdapter
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.SubscriptionHelper import com.github.libretube.api.SubscriptionHelper
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.FragmentChannelBinding import com.github.libretube.databinding.FragmentChannelBinding
import com.github.libretube.extensions.BaseFragment import com.github.libretube.extensions.BaseFragment
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
@ -34,8 +35,8 @@ class ChannelFragment : BaseFragment() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
arguments?.let { arguments?.let {
channelId = it.getString("channel_id").toID() channelId = it.getString(IntentData.channelId)?.toID()
channelName = it.getString("channel_name") channelName = it.getString(IntentData.channelName)
?.replace("/c/", "") ?.replace("/c/", "")
?.replace("/user/", "") ?.replace("/user/", "")
} }

View File

@ -44,6 +44,7 @@ import com.github.libretube.adapters.TrendingAdapter
import com.github.libretube.api.CronetHelper import com.github.libretube.api.CronetHelper
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.SubscriptionHelper import com.github.libretube.api.SubscriptionHelper
import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.constants.PreferenceRanges import com.github.libretube.constants.PreferenceRanges
import com.github.libretube.databinding.DialogSliderBinding import com.github.libretube.databinding.DialogSliderBinding
@ -193,8 +194,8 @@ class PlayerFragment : BaseFragment() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
arguments?.let { arguments?.let {
videoId = it.getString("videoId").toID() videoId = it.getString(IntentData.videoId)!!.toID()
playlistId = it.getString("playlistId") playlistId = it.getString(IntentData.playlistId)
} }
} }
@ -979,7 +980,7 @@ class PlayerFragment : BaseFragment() {
// seek to saved watch position if available // seek to saved watch position if available
private fun seekToWatchPosition() { private fun seekToWatchPosition() {
// support for time stamped links // support for time stamped links
val timeStamp: Long? = arguments?.getLong("timeStamp") val timeStamp: Long? = arguments?.getLong(IntentData.timeStamp)
if (timeStamp != null && timeStamp != 0L) { if (timeStamp != null && timeStamp != 0L) {
exoPlayer.seekTo(timeStamp * 1000) exoPlayer.seekTo(timeStamp * 1000)
return return
@ -1205,7 +1206,7 @@ class PlayerFragment : BaseFragment() {
binding.playerChannel.setOnClickListener { binding.playerChannel.setOnClickListener {
val activity = view?.context as MainActivity val activity = view?.context as MainActivity
val bundle = bundleOf("channel_id" to response.uploaderUrl) val bundle = bundleOf(IntentData.channelId to response.uploaderUrl)
activity.navController.navigate(R.id.channelFragment, bundle) activity.navController.navigate(R.id.channelFragment, bundle)
activity.binding.mainMotionLayout.transitionToEnd() activity.binding.mainMotionLayout.transitionToEnd()
binding.playerMotionLayout.transitionToEnd() binding.playerMotionLayout.transitionToEnd()
@ -1218,7 +1219,7 @@ class PlayerFragment : BaseFragment() {
binding.relPlayerSave.setOnClickListener { binding.relPlayerSave.setOnClickListener {
val newFragment = AddToPlaylistDialog() val newFragment = AddToPlaylistDialog()
val bundle = Bundle() val bundle = Bundle()
bundle.putString("videoId", videoId) bundle.putString(IntentData.videoId, videoId)
newFragment.arguments = bundle newFragment.arguments = bundle
newFragment.show(childFragmentManager, AddToPlaylistDialog::class.java.name) newFragment.show(childFragmentManager, AddToPlaylistDialog::class.java.name)
} }
@ -1599,7 +1600,7 @@ class PlayerFragment : BaseFragment() {
private fun isSubscribed() { private fun isSubscribed() {
fun run() { fun run() {
val channelId = streams.uploaderUrl.toID() val channelId = streams.uploaderUrl!!.toID()
lifecycleScope.launchWhenCreated { lifecycleScope.launchWhenCreated {
isSubscribed = SubscriptionHelper.isSubscribed(channelId) isSubscribed = SubscriptionHelper.isSubscribed(channelId)

View File

@ -12,6 +12,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.adapters.PlaylistAdapter import com.github.libretube.adapters.PlaylistAdapter
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.FragmentPlaylistBinding import com.github.libretube.databinding.FragmentPlaylistBinding
import com.github.libretube.dialogs.PlaylistOptionsDialog import com.github.libretube.dialogs.PlaylistOptionsDialog
import com.github.libretube.extensions.BaseFragment import com.github.libretube.extensions.BaseFragment
@ -32,7 +33,7 @@ class PlaylistFragment : BaseFragment() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
arguments?.let { arguments?.let {
playlistId = it.getString("playlist_id") playlistId = it.getString(IntentData.playlistId)
isOwner = it.getBoolean("isOwner") isOwner = it.getBoolean("isOwner")
} }
} }

View File

@ -48,7 +48,7 @@ class SubscriptionsViewModel : ViewModel() {
this@SubscriptionsViewModel.videoFeed.postValue(videoFeed) this@SubscriptionsViewModel.videoFeed.postValue(videoFeed)
if (videoFeed.isNotEmpty()) { if (videoFeed.isNotEmpty()) {
// save the last recent video to the prefs for the notification worker // save the last recent video to the prefs for the notification worker
PreferenceHelper.setLatestVideoId(videoFeed[0].url.toID()) PreferenceHelper.setLatestVideoId(videoFeed[0].url!!.toID())
} }
} }
} }

View File

@ -15,6 +15,7 @@ import com.github.libretube.Globals
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.constants.BACKGROUND_CHANNEL_ID import com.github.libretube.constants.BACKGROUND_CHANNEL_ID
import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID import com.github.libretube.constants.PLAYER_NOTIFICATION_ID
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
@ -120,9 +121,9 @@ class BackgroundMode : Service() {
Globals.playingQueue.clear() Globals.playingQueue.clear()
// get the intent arguments // get the intent arguments
videoId = intent?.getStringExtra("videoId")!! videoId = intent?.getStringExtra(IntentData.videoId)!!
playlistId = intent.getStringExtra("playlistId") playlistId = intent.getStringExtra(IntentData.playlistId)
val position = intent.getLongExtra("position", 0L) val position = intent.getLongExtra(IntentData.position, 0L)
// initialize the playlist autoPlay Helper // initialize the playlist autoPlay Helper
autoPlayHelper = AutoPlayHelper(playlistId) autoPlayHelper = AutoPlayHelper(playlistId)
@ -220,7 +221,7 @@ class BackgroundMode : Service() {
*/ */
private fun setNextStream() { private fun setNextStream() {
if (streams!!.relatedStreams!!.isNotEmpty()) { if (streams!!.relatedStreams!!.isNotEmpty()) {
nextStreamId = streams?.relatedStreams!![0].url.toID() nextStreamId = streams?.relatedStreams!![0].url!!.toID()
} }
if (playlistId == null) return if (playlistId == null) return

View File

@ -55,7 +55,7 @@ class AutoPlayHelper(
) )
) )
) { ) {
nextStreamId = relatedStreams[index].url.toID() nextStreamId = relatedStreams[index].url!!.toID()
if (index + 1 < relatedStreams.size) { if (index + 1 < relatedStreams.size) {
index += 1 index += 1
} else { } else {
@ -94,7 +94,7 @@ class AutoPlayHelper(
) )
} }
// save the playlist urls to the list // save the playlist urls to the list
playlistStreamIds += playlist.relatedStreams!!.map { it.url.toID() } playlistStreamIds += playlist.relatedStreams!!.map { it.url!!.toID() }
// save playlistNextPage for usage if video is not contained // save playlistNextPage for usage if video is not contained
playlistNextPage = playlist.nextpage playlistNextPage = playlist.nextpage
return@withContext getNextPlaylistVideoId(currentVideoId) return@withContext getNextPlaylistVideoId(currentVideoId)

View File

@ -3,6 +3,7 @@ package com.github.libretube.util
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import com.github.libretube.constants.IntentData
import com.github.libretube.services.BackgroundMode import com.github.libretube.services.BackgroundMode
/** /**
@ -17,8 +18,8 @@ object BackgroundHelper {
) { ) {
// create an intent for the background mode service // create an intent for the background mode service
val intent = Intent(context, BackgroundMode::class.java) val intent = Intent(context, BackgroundMode::class.java)
intent.putExtra("videoId", videoId) intent.putExtra(IntentData.videoId, videoId)
if (playlistId != null) intent.putExtra("playlistId", playlistId) if (playlistId != null) intent.putExtra(IntentData.playlistId, playlistId)
if (position != null) intent.putExtra("position", position) if (position != null) intent.putExtra("position", position)
// start the background mode as foreground service // start the background mode as foreground service

View File

@ -7,6 +7,7 @@ import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.activities.MainActivity import com.github.libretube.activities.MainActivity
import com.github.libretube.constants.IntentData
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.fragments.PlayerFragment import com.github.libretube.fragments.PlayerFragment
@ -17,7 +18,7 @@ object NavigationHelper {
) { ) {
if (channelId != null) { if (channelId != null) {
val activity = context as MainActivity val activity = context as MainActivity
val bundle = bundleOf("channel_id" to channelId) val bundle = bundleOf(IntentData.channelId to channelId)
activity.navController.navigate(R.id.channelFragment, bundle) activity.navController.navigate(R.id.channelFragment, bundle)
try { try {
val mainMotionLayout = val mainMotionLayout =
@ -39,8 +40,8 @@ object NavigationHelper {
) { ) {
if (videoId != null) { if (videoId != null) {
val bundle = Bundle() val bundle = Bundle()
bundle.putString("videoId", videoId.toID()) bundle.putString(IntentData.videoId, videoId.toID())
if (playlistId != null) bundle.putString("playlistId", playlistId) if (playlistId != null) bundle.putString(IntentData.playlistId, playlistId)
val frag = PlayerFragment() val frag = PlayerFragment()
frag.arguments = bundle frag.arguments = bundle
val activity = context as AppCompatActivity val activity = context as AppCompatActivity
@ -61,7 +62,7 @@ object NavigationHelper {
if (playlistId != null) { if (playlistId != null) {
val activity = context as MainActivity val activity = context as MainActivity
val bundle = Bundle() val bundle = Bundle()
bundle.putString("playlist_id", playlistId) bundle.putString(IntentData.playlistId, playlistId)
bundle.putBoolean("isOwner", isOwner) bundle.putBoolean("isOwner", isOwner)
activity.navController.navigate(R.id.playlistFragment, bundle) activity.navController.navigate(R.id.playlistFragment, bundle)
} }

View File

@ -35,18 +35,12 @@
android:name="com.github.libretube.fragments.ChannelFragment" android:name="com.github.libretube.fragments.ChannelFragment"
android:label="channel" android:label="channel"
tools:layout="@layout/fragment_channel"> tools:layout="@layout/fragment_channel">
<argument
android:name="channel_id"
app:argType="string" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/playlistFragment" android:id="@+id/playlistFragment"
android:name="com.github.libretube.fragments.PlaylistFragment" android:name="com.github.libretube.fragments.PlaylistFragment"
android:label="fragment_playlist" android:label="fragment_playlist"
tools:layout="@layout/fragment_playlist"> tools:layout="@layout/fragment_playlist">
<argument
android:name="playlist_id"
app:argType="string" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/watchHistoryFragment" android:id="@+id/watchHistoryFragment"