From eeb87c05d8827346a058209560eec40f16f635fd Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 6 Dec 2022 11:26:27 +0100 Subject: [PATCH 1/3] Fix the option to disable watch positions --- .../java/com/github/libretube/ui/fragments/PlayerFragment.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index 2b6cc9742..0944ca697 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -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() } From 50f5ca561007d7f1cececb6c54e107ed3bbedce0 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 6 Dec 2022 11:34:06 +0100 Subject: [PATCH 2/3] improve the conversion from dp to px --- .../main/java/com/github/libretube/extensions/ToDp.kt | 8 -------- .../java/com/github/libretube/extensions/ToPixel.kt | 10 ++++++++++ .../libretube/ui/adapters/PlaylistBookmarkAdapter.kt | 4 ++-- .../com/github/libretube/ui/adapters/VideosAdapter.kt | 6 +++--- .../github/libretube/ui/fragments/LibraryFragment.kt | 4 ++-- .../github/libretube/ui/fragments/PlaylistFragment.kt | 4 ++-- .../libretube/ui/fragments/WatchHistoryFragment.kt | 4 ++-- .../github/libretube/ui/views/CustomExoPlayerView.kt | 6 +++--- 8 files changed, 24 insertions(+), 22 deletions(-) delete mode 100644 app/src/main/java/com/github/libretube/extensions/ToDp.kt create mode 100644 app/src/main/java/com/github/libretube/extensions/ToPixel.kt diff --git a/app/src/main/java/com/github/libretube/extensions/ToDp.kt b/app/src/main/java/com/github/libretube/extensions/ToDp.kt deleted file mode 100644 index 5523fee74..000000000 --- a/app/src/main/java/com/github/libretube/extensions/ToDp.kt +++ /dev/null @@ -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 -} diff --git a/app/src/main/java/com/github/libretube/extensions/ToPixel.kt b/app/src/main/java/com/github/libretube/extensions/ToPixel.kt new file mode 100644 index 000000000..1af59c65c --- /dev/null +++ b/app/src/main/java/com/github/libretube/extensions/ToPixel.kt @@ -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 +} diff --git a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistBookmarkAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistBookmarkAdapter.kt index 3dc6be6f6..bbb6c4cb2 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistBookmarkAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistBookmarkAdapter.kt @@ -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 } diff --git a/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt index f67dff7fb..5b009b8d2 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt @@ -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 diff --git a/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt index b1b1bb14c..d266180db 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt @@ -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 } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt index 3ab9b72e2..cb98de13a 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt @@ -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 ) } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt index a74fed717..09856670a 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt @@ -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 ) } diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index 690e06c5f..6d73d0f16 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -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 { From 3c3d313bec9f40559b38d05ff3185a52bc330a84 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 6 Dec 2022 11:39:33 +0100 Subject: [PATCH 3/3] fix the parsing of the videoID when importing playlists in some cases --- .../main/java/com/github/libretube/api/PlaylistsHelper.kt | 5 +++-- .../java/com/github/libretube/ui/fragments/PlayerFragment.kt | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt b/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt index 4036d97df..1698c9645 100644 --- a/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt +++ b/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt @@ -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 diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index 0944ca697..42385f3fb 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -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