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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@ package com.github.libretube.extensions
/**
* format a Piped route to an ID
*/
fun Any?.toID(): String {
fun Any.toID(): String {
return this
.toString()
.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.api.RetrofitInstance
import com.github.libretube.api.SubscriptionHelper
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.FragmentChannelBinding
import com.github.libretube.extensions.BaseFragment
import com.github.libretube.extensions.TAG
@ -34,8 +35,8 @@ class ChannelFragment : BaseFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
channelId = it.getString("channel_id").toID()
channelName = it.getString("channel_name")
channelId = it.getString(IntentData.channelId)?.toID()
channelName = it.getString(IntentData.channelName)
?.replace("/c/", "")
?.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.RetrofitInstance
import com.github.libretube.api.SubscriptionHelper
import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.constants.PreferenceRanges
import com.github.libretube.databinding.DialogSliderBinding
@ -193,8 +194,8 @@ class PlayerFragment : BaseFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
videoId = it.getString("videoId").toID()
playlistId = it.getString("playlistId")
videoId = it.getString(IntentData.videoId)!!.toID()
playlistId = it.getString(IntentData.playlistId)
}
}
@ -979,7 +980,7 @@ class PlayerFragment : BaseFragment() {
// seek to saved watch position if available
private fun seekToWatchPosition() {
// support for time stamped links
val timeStamp: Long? = arguments?.getLong("timeStamp")
val timeStamp: Long? = arguments?.getLong(IntentData.timeStamp)
if (timeStamp != null && timeStamp != 0L) {
exoPlayer.seekTo(timeStamp * 1000)
return
@ -1205,7 +1206,7 @@ class PlayerFragment : BaseFragment() {
binding.playerChannel.setOnClickListener {
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.binding.mainMotionLayout.transitionToEnd()
binding.playerMotionLayout.transitionToEnd()
@ -1218,7 +1219,7 @@ class PlayerFragment : BaseFragment() {
binding.relPlayerSave.setOnClickListener {
val newFragment = AddToPlaylistDialog()
val bundle = Bundle()
bundle.putString("videoId", videoId)
bundle.putString(IntentData.videoId, videoId)
newFragment.arguments = bundle
newFragment.show(childFragmentManager, AddToPlaylistDialog::class.java.name)
}
@ -1599,7 +1600,7 @@ class PlayerFragment : BaseFragment() {
private fun isSubscribed() {
fun run() {
val channelId = streams.uploaderUrl.toID()
val channelId = streams.uploaderUrl!!.toID()
lifecycleScope.launchWhenCreated {
isSubscribed = SubscriptionHelper.isSubscribed(channelId)

View File

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

View File

@ -48,7 +48,7 @@ class SubscriptionsViewModel : ViewModel() {
this@SubscriptionsViewModel.videoFeed.postValue(videoFeed)
if (videoFeed.isNotEmpty()) {
// 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.api.RetrofitInstance
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.PreferenceKeys
import com.github.libretube.extensions.toID
@ -120,9 +121,9 @@ class BackgroundMode : Service() {
Globals.playingQueue.clear()
// get the intent arguments
videoId = intent?.getStringExtra("videoId")!!
playlistId = intent.getStringExtra("playlistId")
val position = intent.getLongExtra("position", 0L)
videoId = intent?.getStringExtra(IntentData.videoId)!!
playlistId = intent.getStringExtra(IntentData.playlistId)
val position = intent.getLongExtra(IntentData.position, 0L)
// initialize the playlist autoPlay Helper
autoPlayHelper = AutoPlayHelper(playlistId)
@ -220,7 +221,7 @@ class BackgroundMode : Service() {
*/
private fun setNextStream() {
if (streams!!.relatedStreams!!.isNotEmpty()) {
nextStreamId = streams?.relatedStreams!![0].url.toID()
nextStreamId = streams?.relatedStreams!![0].url!!.toID()
}
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) {
index += 1
} else {
@ -94,7 +94,7 @@ class AutoPlayHelper(
)
}
// 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
playlistNextPage = playlist.nextpage
return@withContext getNextPlaylistVideoId(currentVideoId)

View File

@ -3,6 +3,7 @@ package com.github.libretube.util
import android.content.Context
import android.content.Intent
import android.os.Build
import com.github.libretube.constants.IntentData
import com.github.libretube.services.BackgroundMode
/**
@ -17,8 +18,8 @@ object BackgroundHelper {
) {
// create an intent for the background mode service
val intent = Intent(context, BackgroundMode::class.java)
intent.putExtra("videoId", videoId)
if (playlistId != null) intent.putExtra("playlistId", playlistId)
intent.putExtra(IntentData.videoId, videoId)
if (playlistId != null) intent.putExtra(IntentData.playlistId, playlistId)
if (position != null) intent.putExtra("position", position)
// 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 com.github.libretube.R
import com.github.libretube.activities.MainActivity
import com.github.libretube.constants.IntentData
import com.github.libretube.extensions.toID
import com.github.libretube.fragments.PlayerFragment
@ -17,7 +18,7 @@ object NavigationHelper {
) {
if (channelId != null) {
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)
try {
val mainMotionLayout =
@ -39,8 +40,8 @@ object NavigationHelper {
) {
if (videoId != null) {
val bundle = Bundle()
bundle.putString("videoId", videoId.toID())
if (playlistId != null) bundle.putString("playlistId", playlistId)
bundle.putString(IntentData.videoId, videoId.toID())
if (playlistId != null) bundle.putString(IntentData.playlistId, playlistId)
val frag = PlayerFragment()
frag.arguments = bundle
val activity = context as AppCompatActivity
@ -61,7 +62,7 @@ object NavigationHelper {
if (playlistId != null) {
val activity = context as MainActivity
val bundle = Bundle()
bundle.putString("playlist_id", playlistId)
bundle.putString(IntentData.playlistId, playlistId)
bundle.putBoolean("isOwner", isOwner)
activity.navController.navigate(R.id.playlistFragment, bundle)
}

View File

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