Merge pull request #2266 from Bnyro/master

Fix the option to disable watch positions and playlist import
This commit is contained in:
Bnyro 2022-12-06 11:40:52 +01:00 committed by GitHub
commit eb1c9a4247
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 29 additions and 29 deletions

View File

@ -1,6 +1,7 @@
package com.github.libretube.api
import android.content.Context
import android.net.Uri
import android.util.Log
import com.github.libretube.R
import com.github.libretube.api.obj.Playlist
@ -195,7 +196,7 @@ object PlaylistsHelper {
addToPlaylist(
playlistId,
*playlist.videos.map {
it.substringAfter("=")
Uri.parse(it).getQueryParameter("v")!!
}.toTypedArray()
)
}
@ -231,7 +232,7 @@ object PlaylistsHelper {
return if (loggedIn()) PlaylistType.PRIVATE else PlaylistType.LOCAL
}
fun getPrivatePlaylistType(playlistId: String): PlaylistType {
private fun getPrivatePlaylistType(playlistId: String): PlaylistType {
if (playlistId.all { it.isDigit() }) return PlaylistType.LOCAL
if (playlistId.matches(pipedPlaylistRegex)) return PlaylistType.PRIVATE
return PlaylistType.PUBLIC

View File

@ -1,8 +0,0 @@
package com.github.libretube.extensions
import android.content.res.Resources
fun Int.toDp(resources: Resources): Float {
val scale = resources.displayMetrics.density
return this * scale + 0.5f
}

View File

@ -0,0 +1,10 @@
package com.github.libretube.extensions
import android.content.res.Resources
/**
* Convert DP to pixels
*/
fun Int.toPixel(): Float {
return this * Resources.getSystem().displayMetrics.density + 0.5f
}

View File

@ -7,7 +7,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.PlaylistBookmarkRowBinding
import com.github.libretube.db.obj.PlaylistBookmark
import com.github.libretube.enums.PlaylistType
import com.github.libretube.extensions.toDp
import com.github.libretube.extensions.toPixel
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
import com.github.libretube.ui.viewholders.PlaylistBookmarkViewHolder
import com.github.libretube.util.ImageHelper
@ -31,7 +31,7 @@ class PlaylistBookmarkAdapter(
holder.binding.apply {
if (bookmarkMode == BookmarkMode.HOME) {
val params = root.layoutParams
params.width = (210).toDp(root.context.resources).toInt()
params.width = (210).toPixel().toInt()
root.layoutParams = params
}

View File

@ -17,7 +17,7 @@ import com.github.libretube.databinding.AllCaughtUpRowBinding
import com.github.libretube.databinding.TrendingRowBinding
import com.github.libretube.databinding.VideoRowBinding
import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.toDp
import com.github.libretube.extensions.toPixel
import com.github.libretube.extensions.toID
import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.extensions.setFormattedDuration
@ -91,8 +91,8 @@ class VideosAdapter(
// set a fixed width for better visuals
val params = root.layoutParams
when (forceMode) {
ForceMode.RELATED -> params.width = (180).toDp(root.context.resources).toInt()
ForceMode.HOME -> params.width = (250).toDp(root.context.resources).toInt()
ForceMode.RELATED -> params.width = (180).toPixel().toInt()
ForceMode.HOME -> params.width = (250).toPixel().toInt()
else -> {}
}
root.layoutParams = params

View File

@ -16,7 +16,7 @@ import com.github.libretube.api.PlaylistsHelper
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.databinding.FragmentLibraryBinding
import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.toDp
import com.github.libretube.extensions.toPixel
import com.github.libretube.ui.adapters.PlaylistsAdapter
import com.github.libretube.ui.base.BaseFragment
import com.github.libretube.ui.dialogs.CreatePlaylistDialog
@ -91,7 +91,7 @@ class LibraryFragment : BaseFragment() {
// optimize CreatePlaylistFab bottom margin if miniPlayer active
val bottomMargin = if (isMiniPlayerVisible) 64 else 16
val layoutParams = binding.createPlaylist.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.bottomMargin = bottomMargin.toDp(resources).toInt()
layoutParams.bottomMargin = bottomMargin.toPixel().toInt()
binding.createPlaylist.layoutParams = layoutParams
}

View File

@ -463,7 +463,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
binding.playerDescriptionArrow.animate().rotation(0F).setDuration(250).start()
binding.descLinLayout.visibility = View.GONE
// show formated short view count
// show formatted short view count
viewInfo = getString(R.string.views, streams.views.formatShort()) + viewInfo
} else {
// show the description and chapters
@ -880,10 +880,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
// save the watch position when paused
if (playbackState == PlaybackState.STATE_PAUSED) {
val watchPosition = WatchPosition(videoId!!, exoPlayer.currentPosition)
query {
Database.watchPositionDao().insertAll(watchPosition)
}
saveWatchPosition()
disableAutoPiP()
}

View File

@ -23,7 +23,7 @@ import com.github.libretube.enums.PlaylistType
import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.awaitQuery
import com.github.libretube.extensions.query
import com.github.libretube.extensions.toDp
import com.github.libretube.extensions.toPixel
import com.github.libretube.extensions.toID
import com.github.libretube.ui.adapters.PlaylistAdapter
import com.github.libretube.ui.base.BaseFragment
@ -81,7 +81,7 @@ class PlaylistFragment : BaseFragment() {
playerViewModel.isMiniPlayerVisible.observe(viewLifecycleOwner) {
binding.playlistRecView.updatePadding(
bottom = if (it) (64).toDp(resources).toInt() else 0
bottom = if (it) (64).toPixel().toInt() else 0
)
}

View File

@ -12,7 +12,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.FragmentWatchHistoryBinding
import com.github.libretube.db.DatabaseHolder.Companion.Database
import com.github.libretube.extensions.awaitQuery
import com.github.libretube.extensions.toDp
import com.github.libretube.extensions.toPixel
import com.github.libretube.ui.adapters.WatchHistoryAdapter
import com.github.libretube.ui.base.BaseFragment
import com.github.libretube.ui.models.PlayerViewModel
@ -37,7 +37,7 @@ class WatchHistoryFragment : BaseFragment() {
playerViewModel.isMiniPlayerVisible.observe(viewLifecycleOwner) {
binding.watchHistoryRecView.updatePadding(
bottom = if (it) (64).toDp(resources).toInt() else 0
bottom = if (it) (64).toPixel().toInt() else 0
)
}

View File

@ -14,7 +14,7 @@ import com.github.libretube.databinding.DoubleTapOverlayBinding
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
import com.github.libretube.databinding.PlayerGestureControlsViewBinding
import com.github.libretube.extensions.normalize
import com.github.libretube.extensions.toDp
import com.github.libretube.extensions.toPixel
import com.github.libretube.obj.BottomSheetItem
import com.github.libretube.ui.activities.MainActivity
import com.github.libretube.ui.base.BaseActivity
@ -494,8 +494,8 @@ internal class CustomExoPlayerView(
super.onConfigurationChanged(newConfig)
val offset = when (newConfig?.orientation) {
Configuration.ORIENTATION_LANDSCAPE -> 20.toDp(resources)
else -> 10.toDp(resources)
Configuration.ORIENTATION_LANDSCAPE -> 20.toPixel()
else -> 10.toPixel()
}
binding.progressBar.let {