Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object PlaylistsHelper {

suspend fun getPlaylist(playlistId: String): Playlist {
// load locally stored playlists with the auth api
return when (getPrivatePlaylistType(playlistId)) {
return when (getPlaylistType(playlistId)) {
PlaylistType.PUBLIC -> MediaServiceRepository.instance.getPlaylist(playlistId)
else -> playlistsRepository.getPlaylist(playlistId)
}.apply {
Expand Down Expand Up @@ -94,7 +94,7 @@ object PlaylistsHelper {
return if (loggedIn) PlaylistType.PRIVATE else PlaylistType.LOCAL
}

private fun getPrivatePlaylistType(playlistId: String): PlaylistType {
fun getPlaylistType(playlistId: String): PlaylistType {
return if (playlistId.isDigitsOnly()) {
PlaylistType.LOCAL
} else if (playlistId.matches(pipedPlaylistRegex)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object PreferenceKeys {
// General
const val LANGUAGE = "language"
const val REGION = "region"
const val TRENDING_CATEGORY = "trending_category"
const val ORIENTATION = "orientation"
const val NAVBAR_ITEMS = "navbar_items"
const val START_FRAGMENT = "start_fragment"
Expand Down Expand Up @@ -134,7 +135,6 @@ object PreferenceKeys {

// History
const val WATCH_HISTORY_SIZE = "watch_history_size"
const val SELECTED_HISTORY_TYPE_FILTER = "filter_history_type"
const val SELECTED_HISTORY_STATUS_FILTER = "filter_history_status"

// Internally saved data / not a preference
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/github/libretube/db/DatabaseHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ object DatabaseHelper {
}
}

/**
* @param unfinished If true, only returns unfinished videos. If false, only returns finished videos.
*/
suspend fun filterByWatchStatus(
watchHistoryItem: WatchHistoryItem,
unfinished: Boolean = true
Expand Down
13 changes: 1 addition & 12 deletions app/src/main/java/com/github/libretube/helpers/LocaleHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object LocaleHelper {
}
}

private fun getDetectedCountry(context: Context): String {
fun getDetectedCountry(context: Context): String {
return detectSIMCountry(context)
?: detectNetworkCountry(context)
?: detectLocaleCountry(context)
Expand Down Expand Up @@ -60,15 +60,4 @@ object LocaleHelper {
.map { Country(it.displayLanguage, it.language) }
.sortedBy { it.name }
}

fun getTrendingRegion(context: Context): String {
val regionPref = PreferenceHelper.getString(PreferenceKeys.REGION, "sys")

// get the system default country if auto region selected
return if (regionPref == "sys") {
getDetectedCountry(context).uppercase()
} else {
regionPref
}
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.github.libretube.LibreTubeApp
import com.github.libretube.R
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.enums.SbSkipOptions
import com.github.libretube.helpers.LocaleHelper.getDetectedCountry

object PreferenceHelper {
private val TAG = PreferenceHelper::class.simpleName
Expand Down Expand Up @@ -207,6 +208,17 @@ object PreferenceHelper {
return uuid
}

fun getTrendingRegion(context: Context): String {
val regionPref = PreferenceHelper.getString(PreferenceKeys.REGION, "sys")

// get the system default country if auto region selected
return if (regionPref == "sys") {
getDetectedCountry(context).uppercase()
} else {
regionPref
}
}

private fun getDefaultSharedPreferences(context: Context): SharedPreferences {
return PreferenceManager.getDefaultSharedPreferences(context)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.github.libretube.ui.adapters

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.ListAdapter
import com.github.libretube.api.PlaylistsHelper
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.CarouselPlaylistThumbnailBinding
import com.github.libretube.helpers.ImageHelper
import com.github.libretube.helpers.NavigationHelper
import com.github.libretube.ui.adapters.callbacks.DiffUtilItemCallback
import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
import com.github.libretube.ui.viewholders.CarouselPlaylistViewHolder

data class CarouselPlaylist(
val id: String,
val title: String?,
val thumbnail: String?
)

class CarouselPlaylistAdapter : ListAdapter<CarouselPlaylist, CarouselPlaylistViewHolder>(
DiffUtilItemCallback()
) {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): CarouselPlaylistViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
return CarouselPlaylistViewHolder(CarouselPlaylistThumbnailBinding.inflate(layoutInflater))
}

override fun onBindViewHolder(
holder: CarouselPlaylistViewHolder,
position: Int
) {
val item = getItem(position)!!

with(holder.binding) {
playlistName.text = item.title
ImageHelper.loadImage(item.thumbnail, thumbnail)

val type = PlaylistsHelper.getPlaylistType(item.id)
root.setOnClickListener {
NavigationHelper.navigatePlaylist(root.context, item.id, type)
}

root.setOnLongClickListener {
val playlistOptionsDialog = PlaylistOptionsBottomSheet()
playlistOptionsDialog.arguments = bundleOf(
IntentData.playlistId to item.id,
IntentData.playlistName to item.title,
IntentData.playlistType to type
)
playlistOptionsDialog.show((root.context as BaseActivity).supportFragmentManager)

true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.core.view.isVisible
import androidx.recyclerview.widget.ListAdapter
import com.github.libretube.R
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.PlaylistBookmarkRowBinding
import com.github.libretube.databinding.PlaylistsRowBinding
import com.github.libretube.db.DatabaseHolder
import com.github.libretube.db.obj.PlaylistBookmark
Expand All @@ -23,24 +22,16 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class PlaylistBookmarkAdapter(
private val bookmarkMode: BookmarkMode = BookmarkMode.FRAGMENT
) : ListAdapter<PlaylistBookmark, PlaylistBookmarkViewHolder>(
class PlaylistBookmarkAdapter: ListAdapter<PlaylistBookmark, PlaylistBookmarkViewHolder>(
DiffUtilItemCallback(
areItemsTheSame = { oldItem, newItem -> oldItem.playlistId == newItem.playlistId }
)
) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistBookmarkViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
return when (bookmarkMode) {
BookmarkMode.HOME -> PlaylistBookmarkViewHolder(
PlaylistBookmarkRowBinding.inflate(layoutInflater, parent, false)
)

BookmarkMode.FRAGMENT -> PlaylistBookmarkViewHolder(
PlaylistsRowBinding.inflate(layoutInflater, parent, false)
)
}
return PlaylistBookmarkViewHolder(
PlaylistsRowBinding.inflate(layoutInflater, parent, false)
)
}

private fun showPlaylistOptions(context: Context, bookmark: PlaylistBookmark) {
Expand All @@ -57,26 +48,8 @@ class PlaylistBookmarkAdapter(

override fun onBindViewHolder(holder: PlaylistBookmarkViewHolder, position: Int) {
val bookmark = getItem(holder.bindingAdapterPosition)
holder.playlistBookmarkBinding?.apply {
ImageHelper.loadImage(bookmark.thumbnailUrl, thumbnail)
playlistName.text = bookmark.playlistName
uploaderName.text = bookmark.uploader

root.setOnClickListener {
NavigationHelper.navigatePlaylist(
root.context,
bookmark.playlistId,
PlaylistType.PUBLIC
)
}

root.setOnLongClickListener {
showPlaylistOptions(root.context, bookmark)
true
}
}

holder.playlistsBinding?.apply {
with(holder.binding) {
var isBookmarked = true

ImageHelper.loadImage(bookmark.thumbnailUrl, playlistThumbnail)
Expand Down Expand Up @@ -114,11 +87,4 @@ class PlaylistBookmarkAdapter(
}
}
}

companion object {
enum class BookmarkMode {
HOME,
FRAGMENT
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.github.libretube.api.obj.Subscription
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.ChannelSubscriptionRowBinding
import com.github.libretube.extensions.toID
import com.github.libretube.helpers.ContextHelper
import com.github.libretube.helpers.ImageHelper
import com.github.libretube.helpers.NavigationHelper
import com.github.libretube.ui.adapters.callbacks.DiffUtilItemCallback
Expand Down Expand Up @@ -45,7 +46,8 @@ class SubscriptionChannelAdapter :
IntentData.channelName to subscription.name,
IntentData.isSubscribed to true
)
channelOptionsSheet.show((root.context as BaseActivity).supportFragmentManager)
val activity = ContextHelper.unwrapActivity<BaseActivity>(root.context)
channelOptionsSheet.show(activity.supportFragmentManager)
true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fun View.setWatchProgressLength(videoId: String, duration: Long) {

var backgroundColor = ThemeHelper.getThemeColor(
context,
com.google.android.material.R.attr.colorPrimaryDark
com.google.android.material.R.attr.colorPrimaryVariant
)
// increase the brightness for better contrast in light mode
if (!ThemeHelper.isDarkMode(context)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,10 @@ class AudioPlayerFragment : Fragment(R.layout.fragment_audio_player), AudioPlaye
playerController?.navigateVideo(PlayingQueue.getNext() ?: return@setOnClickListener)
}

listOf(binding.forwardTV, binding.rewindTV).forEach {
it.text = (PlayerHelper.seekIncrement / 1000).toString()
}
binding.rewindFL.setOnClickListener {
binding.rewindBTN.setOnClickListener {
playerController?.seekBy(-PlayerHelper.seekIncrement)
}
binding.forwardFL.setOnClickListener {
binding.forwardBTN.setOnClickListener {
playerController?.seekBy(PlayerHelper.seekIncrement)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@ import com.github.libretube.api.obj.ChannelTab
import com.github.libretube.api.obj.StreamItem
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.FragmentChannelBinding
import com.github.libretube.enums.ShareObjectType
import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.toID
import com.github.libretube.extensions.toastFromMainDispatcher
import com.github.libretube.helpers.ClipboardHelper
import com.github.libretube.helpers.ImageHelper
import com.github.libretube.helpers.NavigationHelper
import com.github.libretube.obj.ShareData
import com.github.libretube.ui.adapters.VideosAdapter
import com.github.libretube.ui.dialogs.ShareDialog
import com.github.libretube.ui.extensions.setupFragmentAnimation
import com.github.libretube.ui.extensions.setupSubscriptionButton
import com.github.libretube.ui.sheets.AddChannelToGroupSheet
import com.github.libretube.ui.sheets.ChannelOptionsBottomSheet
import com.github.libretube.util.deArrow
import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -138,42 +134,30 @@ class ChannelFragment : Fragment(R.layout.fragment_channel) {
// needed if the channel gets loaded by the ID
channelId = response.id
channelName = response.name
val shareData = ShareData(currentChannel = response.name)

val channelId = channelId ?: return@launch

var isSubscribed = false
binding.channelSubscribe.setupSubscriptionButton(
channelId,
response.name.orEmpty(),
response.avatarUrl,
response.verified,
binding.notificationBell
) { isSubscribed ->
_binding?.addToGroup?.isVisible = isSubscribed
) {
isSubscribed = it
}

binding.channelShare.setOnClickListener {
val bundle = bundleOf(
IntentData.id to channelId.toID(),
IntentData.shareObjectType to ShareObjectType.CHANNEL,
IntentData.shareData to shareData
)
val newShareDialog = ShareDialog()
newShareDialog.arguments = bundle
newShareDialog.show(childFragmentManager, ShareDialog::class.java.name)
}

binding.addToGroup.setOnClickListener {
AddChannelToGroupSheet().apply {
arguments = bundleOf(IntentData.channelId to channelId)
}.show(childFragmentManager)
}

binding.playAll.setOnClickListener {
val firstVideoId =
response.relatedStreams.firstOrNull()?.url?.toID() ?: return@setOnClickListener

NavigationHelper.navigateVideo(requireContext(), firstVideoId, channelId = channelId)
binding.showMore.setOnClickListener {
ChannelOptionsBottomSheet()
.apply {
arguments = bundleOf(
IntentData.channelId to channelId,
IntentData.channelName to channelName,
IntentData.isSubscribed to isSubscribed
)
}
.show(childFragmentManager)
}

nextPages[0] = response.nextpage
Expand Down
Loading
Loading