refactor: replace View#setVisibility with kotlin visibility extension

This commit is contained in:
Bnyro 2023-08-03 14:52:37 +02:00
parent 3a106c449b
commit 05fa57b912
38 changed files with 159 additions and 134 deletions

View File

@ -1,6 +1,6 @@
package com.github.libretube.api
import java.util.*
import java.util.LinkedList
import kotlin.reflect.KProperty
class ResettableLazyManager {

View File

@ -5,10 +5,10 @@ import android.util.Log
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.widget.PopupMenu
import androidx.core.view.forEach
import androidx.core.view.get
import androidx.core.view.isGone
import androidx.core.view.size
import com.github.libretube.R
import com.github.libretube.constants.PreferenceKeys
@ -107,7 +107,7 @@ object NavBarHelper {
).icon = menuItem.icon
}
}
if (navBarItems.filter { it.isVisible }.isEmpty()) bottomNav.visibility = View.GONE
if (navBarItems.none { it.isVisible }) bottomNav.isGone = true
return getStartFragmentId(bottomNav.context)
}

View File

@ -31,7 +31,6 @@ import androidx.media3.exoplayer.trackselection.DefaultTrackSelector
import androidx.media3.ui.CaptionStyleCompat
import com.github.libretube.R
import com.github.libretube.api.obj.ChapterSegment
import com.github.libretube.api.obj.PreviewFrames
import com.github.libretube.api.obj.Segment
import com.github.libretube.api.obj.Streams
import com.github.libretube.constants.PreferenceKeys
@ -39,7 +38,6 @@ import com.github.libretube.db.DatabaseHolder
import com.github.libretube.enums.PlayerEvent
import com.github.libretube.enums.SbSkipOptions
import com.github.libretube.extensions.updateParameters
import com.github.libretube.obj.PreviewFrame
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.util.Locale
import kotlin.math.absoluteValue

View File

@ -15,7 +15,6 @@ import com.github.libretube.R
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.ui.adapters.IconsSheetAdapter
import com.google.android.material.color.DynamicColors
import java.lang.IllegalArgumentException
object ThemeHelper {

View File

@ -3,7 +3,6 @@ package com.github.libretube.services
import android.app.NotificationManager
import android.app.Service
import android.content.Intent
import android.os.IBinder
import androidx.core.content.getSystemService
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID

View File

@ -28,7 +28,6 @@ import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID
import com.github.libretube.db.DatabaseHolder.Database
import com.github.libretube.db.obj.WatchPosition
import com.github.libretube.enums.SbSkipOptions
import com.github.libretube.extensions.parcelableExtra
import com.github.libretube.extensions.setMetadata
import com.github.libretube.extensions.toID

View File

@ -7,7 +7,6 @@ import android.content.res.Configuration
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.ScrollView
import androidx.activity.addCallback
@ -16,6 +15,7 @@ import androidx.appcompat.widget.SearchView
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.os.bundleOf
import androidx.core.view.children
import androidx.core.view.isVisible
import androidx.core.widget.NestedScrollView
import androidx.navigation.NavController
import androidx.navigation.findNavController
@ -311,7 +311,10 @@ class MainActivity : BaseActivity() {
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
navController.navigate(R.id.searchResultFragment, bundleOf(IntentData.query to query))
navController.navigate(
R.id.searchResultFragment,
bundleOf(IntentData.query to query)
)
searchView.clearFocus()
return true
}
@ -337,7 +340,10 @@ class MainActivity : BaseActivity() {
}
if (navController.currentDestination?.id != R.id.searchFragment) {
navController.navigate(R.id.searchFragment, bundleOf(IntentData.query to newText))
navController.navigate(
R.id.searchFragment,
bundleOf(IntentData.query to newText)
)
} else {
searchViewModel.setQuery(newText)
}
@ -482,7 +488,7 @@ class MainActivity : BaseActivity() {
supportFragmentManager.fragments.forEach { fragment ->
(fragment as? PlayerFragment)?.binding?.apply {
mainContainer.isClickable = false
linLayout.visibility = View.VISIBLE
linLayout.isVisible = true
playerMotionLayout.setTransitionDuration(250)
playerMotionLayout.transitionToEnd()
playerMotionLayout.getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)

View File

@ -1,7 +1,6 @@
package com.github.libretube.ui.activities
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.util.Log
@ -97,7 +96,9 @@ class RouterActivity : BaseActivity() {
private fun handleSendText(uri: Uri) {
Log.i(TAG(), uri.toString())
val intent = this.packageManager.getLaunchIntentForPackage(this.packageName)!!.resolveType(uri)
val intent = this.packageManager.getLaunchIntentForPackage(
this.packageName
)!!.resolveType(uri)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)
finishAndRemoveTask()

View File

@ -2,10 +2,7 @@ package com.github.libretube.ui.activities
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.VideoTagRowBinding
import com.github.libretube.ui.viewholders.VideoTagsViewHolder

View File

@ -3,13 +3,14 @@ package com.github.libretube.ui.adapters
import android.annotation.SuppressLint
import android.text.method.LinkMovementMethod
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams
import android.widget.Toast
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.os.bundleOf
import androidx.core.text.parseAsHtml
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
@ -79,10 +80,10 @@ class CommentsAdapter(
ImageHelper.loadImage(comment.thumbnail, commentorImage)
likesTextView.text = comment.likeCount.formatShort()
if (comment.verified) verifiedImageView.visibility = View.VISIBLE
if (comment.pinned) pinnedImageView.visibility = View.VISIBLE
if (comment.hearted) heartedImageView.visibility = View.VISIBLE
if (comment.repliesPage != null) repliesCount.visibility = View.VISIBLE
if (comment.verified) verifiedImageView.isVisible = true
if (comment.pinned) pinnedImageView.isVisible = true
if (comment.hearted) heartedImageView.isVisible = true
if (comment.repliesPage != null) repliesCount.isVisible = true
if (comment.replyCount > 0L) {
repliesCount.text = comment.replyCount.formatShort()
}
@ -93,7 +94,7 @@ class CommentsAdapter(
}
if (isRepliesAdapter) {
repliesCount.visibility = View.GONE
repliesCount.isGone = true
// highlight the comment that is being replied to
if (comment == comments.firstOrNull()) {

View File

@ -4,9 +4,10 @@ import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R
import com.github.libretube.constants.IntentData
@ -64,11 +65,11 @@ class DownloadsAdapter(
context.getString(R.string.unknown)
}
if (downloadSize > currentSize) {
downloadOverlay.visibility = View.VISIBLE
downloadOverlay.isVisible = true
resumePauseBtn.setImageResource(R.drawable.ic_download)
fileSize.text = "${currentSize.formatAsFileSize()} / $totalSizeInfo"
} else {
downloadOverlay.visibility = View.GONE
downloadOverlay.isGone = true
fileSize.text = totalSizeInfo
}

View File

@ -4,8 +4,8 @@ import android.app.Activity
import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isGone
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.api.PlaylistsHelper
import com.github.libretube.api.obj.StreamItem
@ -67,7 +67,7 @@ class PlaylistAdapter(
holder.binding.apply {
videoTitle.text = streamItem.title
videoInfo.text = streamItem.uploaderName
channelImage.visibility = View.GONE
channelImage.isGone = true
thumbnailDuration.setFormattedDuration(streamItem.duration!!, streamItem.isShort)
ImageHelper.loadImage(streamItem.thumbnail, thumbnail)

View File

@ -1,9 +1,9 @@
package com.github.libretube.ui.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R
import com.github.libretube.databinding.PlaylistBookmarkRowBinding
@ -87,7 +87,7 @@ class PlaylistBookmarkAdapter(
}
}
}
bookmarkPlaylist.visibility = View.VISIBLE
bookmarkPlaylist.isVisible = true
root.setOnClickListener {
NavigationHelper.navigatePlaylist(

View File

@ -1,9 +1,9 @@
package com.github.libretube.ui.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.SearchView
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.SuggestionRowBinding
import com.github.libretube.db.DatabaseHolder.Database
@ -33,7 +33,7 @@ class SearchHistoryAdapter(
holder.binding.apply {
suggestionText.text = historyQuery
deleteHistory.visibility = View.VISIBLE
deleteHistory.isVisible = true
deleteHistory.setOnClickListener {
historyList -= historyQuery

View File

@ -5,10 +5,10 @@ import android.os.Bundle
import android.text.InputFilter
import android.text.format.Formatter
import android.util.Log
import android.view.View
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isGone
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
@ -112,7 +112,7 @@ class DownloadDialog(
.filter { !it.url.isNullOrEmpty() && !it.name.isNullOrEmpty() }
.sortedBy { it.name }
if (subtitles.isEmpty()) binding.subtitleSpinner.visibility = View.GONE
if (subtitles.isEmpty()) binding.subtitleSpinner.isGone = true
// initialize the video sources
val videoArrayAdapter = ArrayAdapter(

View File

@ -3,7 +3,6 @@ package com.github.libretube.ui.dialogs
import android.app.Dialog
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.core.view.isVisible
import androidx.fragment.app.DialogFragment
import com.github.libretube.R
@ -87,7 +86,7 @@ class ShareDialog(
}
binding.timeStamp.setText((shareData.currentPosition ?: 0L).toString())
if (binding.timeCodeSwitch.isChecked) {
binding.timeStampLayout.visibility = View.VISIBLE
binding.timeStampLayout.isVisible = true
}
}

View File

@ -4,6 +4,8 @@ import android.graphics.Color
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.graphics.ColorUtils
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import com.github.libretube.db.DatabaseHolder.Database
import com.github.libretube.helpers.ThemeHelper
@ -19,11 +21,19 @@ fun View.setWatchProgressLength(videoId: String, duration: Long) {
updateLayoutParams<ConstraintLayout.LayoutParams> {
matchConstraintPercentWidth = 0f
}
var backgroundColor = MaterialColors.getColor(this, com.google.android.material.R.attr.colorPrimaryDark)
var backgroundColor = MaterialColors.getColor(
this,
com.google.android.material.R.attr.colorPrimaryDark
)
// increase the brightness for better contrast in light mode
if (!ThemeHelper.isDarkMode(context)) backgroundColor = ColorUtils.blendARGB(backgroundColor, Color.WHITE, 0.4f)
if (!ThemeHelper.isDarkMode(
context
)
) {
backgroundColor = ColorUtils.blendARGB(backgroundColor, Color.WHITE, 0.4f)
}
setBackgroundColor(backgroundColor)
visibility = View.GONE
isGone = true
val progress = try {
runBlocking {
@ -41,5 +51,5 @@ fun View.setWatchProgressLength(videoId: String, duration: Long) {
updateLayoutParams<ConstraintLayout.LayoutParams> {
matchConstraintPercentWidth = progress / duration.toFloat()
}
visibility = View.VISIBLE
isVisible = true
}

View File

@ -1,7 +1,8 @@
package com.github.libretube.ui.extensions
import android.view.View
import android.widget.TextView
import androidx.core.view.isGone
import androidx.core.view.isVisible
import com.github.libretube.R
import com.github.libretube.api.SubscriptionHelper
import com.google.android.material.button.MaterialButton
@ -28,9 +29,9 @@ fun TextView.setupSubscriptionButton(
if (subscribed == true) {
this@setupSubscriptionButton.text = context.getString(R.string.unsubscribe)
} else {
notificationBell?.visibility = View.GONE
notificationBell?.isGone = true
}
this@setupSubscriptionButton.visibility = View.VISIBLE
this@setupSubscriptionButton.isVisible = true
}
}
@ -39,14 +40,14 @@ fun TextView.setupSubscriptionButton(
if (subscribed == true) {
SubscriptionHelper.handleUnsubscribe(context, channelId, channelName) {
this.text = context.getString(R.string.subscribe)
notificationBell?.visibility = View.GONE
notificationBell?.isGone = true
subscribed = false
}
} else {
runBlocking {
SubscriptionHelper.subscribe(channelId)
text = context.getString(R.string.unsubscribe)
notificationBell?.visibility = View.VISIBLE
notificationBell?.isVisible = true
subscribed = true
}
}

View File

@ -15,6 +15,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.constraintlayout.motion.widget.TransitionAdapter
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
@ -204,7 +205,7 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
@SuppressLint("ClickableViewAccessibility")
private fun initializeTransitionLayout() {
mainActivity.binding.container.visibility = View.VISIBLE
mainActivity.binding.container.isVisible = true
val mainMotionLayout = mainActivity.binding.mainMotionLayout
binding.playerMotionLayout.addTransitionListener(object : TransitionAdapter() {
@ -259,14 +260,14 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
}
private fun updateThumbnailAsync(thumbnailUrl: String) {
binding.progress.visibility = View.VISIBLE
binding.thumbnail.visibility = View.GONE
binding.progress.isVisible = true
binding.thumbnail.isGone = true
ImageHelper.getAsync(requireContext(), thumbnailUrl) {
binding.thumbnail.setImageBitmap(it)
binding.miniPlayerThumbnail.setImageBitmap(it)
binding.thumbnail.visibility = View.VISIBLE
binding.progress.visibility = View.GONE
binding.thumbnail.isVisible = true
binding.progress.isGone = true
}
}
@ -348,19 +349,19 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
}
override fun onSwipe(distanceY: Float) {
binding.volumeControls.visibility = View.VISIBLE
binding.volumeControls.isVisible = true
updateVolume(distanceY)
}
override fun onSwipeEnd() {
binding.volumeControls.visibility = View.GONE
binding.volumeControls.isGone = true
}
private fun updateVolume(distance: Float) {
val bar = binding.volumeProgressBar
binding.volumeControls.apply {
if (visibility == View.GONE) {
visibility = View.VISIBLE
isVisible = true
// Volume could be changed using other mediums, sync progress
// bar with new value.
bar.progress = audioHelper.getVolumeWithScale(bar.max)

View File

@ -7,6 +7,8 @@ import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.view.children
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
@ -164,7 +166,7 @@ class ChannelFragment : Fragment() {
isLoading = false
binding.channelRefresh.isRefreshing = false
binding.channelScrollView.visibility = View.VISIBLE
binding.channelScrollView.isVisible = true
binding.channelName.text = response.name
if (response.verified) {
binding.channelName.setCompoundDrawablesWithIntrinsicBounds(
@ -179,7 +181,7 @@ class ChannelFragment : Fragment() {
response.subscriberCount.formatShort()
)
if (response.description.orEmpty().isBlank()) {
binding.channelDescription.visibility = View.GONE
binding.channelDescription.isGone = true
} else {
binding.channelDescription.text = response.description.orEmpty().trim()
}
@ -209,7 +211,7 @@ class ChannelFragment : Fragment() {
binding.tabChips.children.forEach { chip ->
val resourceTab = possibleTabs.firstOrNull { it.chipId == chip.id }
resourceTab?.let { resTab ->
if (tabs.any { it.name == resTab.identifierName }) chip.visibility = View.VISIBLE
if (tabs.any { it.name == resTab.identifierName }) chip.isVisible = true
}
}

View File

@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
@ -65,7 +66,7 @@ class CommentsMainFragment : Fragment() {
commentsAdapter = CommentsAdapter(
this,
viewModel.videoId!!,
viewModel.videoId ?: return,
viewModel.commentsPage.value?.comments.orEmpty().toMutableList(),
handleLink = viewModel.handleLink
) {
@ -74,7 +75,7 @@ class CommentsMainFragment : Fragment() {
binding.commentsRV.adapter = commentsAdapter
if (viewModel.commentsPage.value?.comments.orEmpty().isEmpty()) {
binding.progress.visibility = View.VISIBLE
binding.progress.isVisible = true
viewModel.fetchComments()
} else {
binding.commentsRV.scrollToPosition(viewModel.currentCommentsPosition)
@ -83,9 +84,9 @@ class CommentsMainFragment : Fragment() {
// listen for new comments to be loaded
viewModel.commentsPage.observe(viewLifecycleOwner) {
if (it == null) return@observe
binding.progress.visibility = View.GONE
binding.progress.isGone = true
if (it.disabled) {
binding.errorTV.visibility = View.VISIBLE
binding.errorTV.isVisible = true
return@observe
}
(parentFragment as CommentsSheet).updateFragmentInfo(
@ -94,7 +95,7 @@ class CommentsMainFragment : Fragment() {
)
if (it.comments.isEmpty()) {
binding.errorTV.text = getString(R.string.no_comments_available)
binding.errorTV.visibility = View.VISIBLE
binding.errorTV.isVisible = true
return@observe
}
commentsAdapter.updateItems(

View File

@ -5,6 +5,8 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
@ -94,10 +96,10 @@ class CommentsRepliesFragment : Fragment() {
nextPage: String,
repliesAdapter: CommentsAdapter
) {
binding.progress.visibility = View.VISIBLE
binding.progress.isVisible = true
fetchReplies(videoId, nextPage) {
repliesAdapter.updateItems(it.comments)
binding.progress.visibility = View.GONE
binding.progress.isGone = true
}
}

View File

@ -9,6 +9,8 @@ import android.os.IBinder
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.ItemTouchHelper
@ -80,8 +82,8 @@ class DownloadsFragment : Fragment() {
downloads.clear()
downloads.addAll(dbDownloads)
binding.downloadsEmpty.visibility = View.GONE
binding.downloads.visibility = View.VISIBLE
binding.downloadsEmpty.isGone = true
binding.downloads.isVisible = true
binding.downloads.layoutManager = LinearLayoutManager(context)
@ -139,8 +141,8 @@ class DownloadsFragment : Fragment() {
super.onItemRangeRemoved(positionStart, itemCount)
val binding = _binding ?: return
if (binding.downloads.adapter?.itemCount == 0) {
binding.downloads.visibility = View.GONE
binding.downloadsEmpty.visibility = View.VISIBLE
binding.downloads.isGone = true
binding.downloadsEmpty.isVisible = true
}
}
}
@ -185,13 +187,13 @@ class DownloadsFragment : Fragment() {
}
DownloadStatus.Completed -> {
downloadOverlay.visibility = View.GONE
downloadOverlay.isGone = true
}
DownloadStatus.Stopped -> Unit
is DownloadStatus.Progress -> {
downloadOverlay.visibility = View.VISIBLE
downloadOverlay.isVisible = true
resumePauseBtn.setImageResource(R.drawable.ic_pause)
if (progressBar.isIndeterminate) return
progressBar.incrementProgressBy(status.progress.toInt())

View File

@ -201,8 +201,8 @@ class HomeFragment : Fragment() {
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
super.onItemRangeRemoved(positionStart, itemCount)
if (itemCount == 0) {
binding.playlistsRV.visibility = View.GONE
binding.playlistsTV.visibility = View.GONE
binding.playlistsRV.isGone = true
binding.playlistsTV.isGone = true
}
}
})

View File

@ -7,6 +7,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams
import android.widget.Toast
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.fragment.app.Fragment
@ -65,7 +66,7 @@ class LibraryFragment : Fragment() {
val watchHistoryEnabled =
PreferenceHelper.getBoolean(PreferenceKeys.WATCH_HISTORY_TOGGLE, true)
if (!watchHistoryEnabled) {
binding.watchHistory.visibility = View.GONE
binding.watchHistory.isGone = true
} else {
binding.watchHistory.setOnClickListener {
findNavController().navigate(R.id.watchHistoryFragment)
@ -78,7 +79,7 @@ class LibraryFragment : Fragment() {
val navBarItems = NavBarHelper.getNavBarItems(requireContext())
if (navBarItems.filter { it.isVisible }.any { it.itemId == R.id.downloadsFragment }) {
binding.downloads.visibility = View.GONE
binding.downloads.isGone = true
}
fetchPlaylists()
@ -156,10 +157,10 @@ class LibraryFragment : Fragment() {
}
})
binding.nothingHere.visibility = View.GONE
binding.nothingHere.isGone = true
binding.playlistRecView.adapter = playlistsAdapter
} else {
binding.nothingHere.visibility = View.VISIBLE
binding.nothingHere.isVisible = true
}
}
}

View File

@ -307,7 +307,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
@SuppressLint("ClickableViewAccessibility")
private fun initializeTransitionLayout() {
mainActivity.binding.container.visibility = View.VISIBLE
mainActivity.binding.container.isVisible = true
val mainMotionLayout = mainActivity.binding.mainMotionLayout
binding.playerMotionLayout.addTransitionListener(object : TransitionAdapter() {
@ -381,7 +381,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
BackgroundHelper.stopBackgroundPlay(requireContext())
killPlayerFragment()
}
playerBinding.autoPlay.visibility = View.VISIBLE
playerBinding.autoPlay.isVisible = true
binding.playImageView.setOnClickListener {
when {
@ -407,7 +407,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
CommentsSheet().show(childFragmentManager)
}
playerBinding.queueToggle.visibility = View.VISIBLE
playerBinding.queueToggle.isVisible = true
playerBinding.queueToggle.setOnClickListener {
PlayingQueueSheet().show(childFragmentManager, null)
}
@ -532,10 +532,10 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
windowInsetsControllerCompat.isAppearanceLightStatusBars = false
binding.mainContainer.isClickable = true
binding.linLayout.visibility = View.GONE
binding.linLayout.isGone = true
commentsViewModel.setCommentSheetExpand(null)
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen_exit)
playerBinding.exoTitle.visibility = View.VISIBLE
playerBinding.exoTitle.isVisible = true
updateFullscreenOrientation()
viewModel.isFullscreen.value = true
@ -558,9 +558,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
}
binding.mainContainer.isClickable = false
binding.linLayout.visibility = View.VISIBLE
binding.linLayout.isVisible = true
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen)
playerBinding.exoTitle.visibility = View.INVISIBLE
playerBinding.exoTitle.isInvisible = true
if (!PlayerHelper.autoRotationEnabled) {
// switch back to portrait mode if autorotation disabled
@ -582,14 +582,14 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
if (binding.descLinLayout.isVisible) {
// hide the description and chapters
binding.playerDescriptionArrow.animate().rotation(0F).setDuration(250).start()
binding.descLinLayout.visibility = View.GONE
binding.descLinLayout.isGone = true
// limit the title height to two lines
binding.playerTitle.maxLines = 2
} else {
// show the description and chapters
binding.playerDescriptionArrow.animate().rotation(180F).setDuration(250).start()
binding.descLinLayout.visibility = View.VISIBLE
binding.descLinLayout.isVisible = true
// show the whole title
binding.playerTitle.maxLines = Int.MAX_VALUE
@ -688,7 +688,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
private fun playVideo() {
// reset the player view
playerBinding.exoProgress.clearSegments()
playerBinding.sbToggle.visibility = View.GONE
playerBinding.sbToggle.isGone = true
// reset the comments to become reloaded later
commentsViewModel.reset()
@ -743,7 +743,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
withContext(Dispatchers.Main) {
// hide the button to skip SponsorBlock segments manually
binding.sbSkipBtn.visibility = View.GONE
binding.sbSkipBtn.isGone = true
// set media sources for the player
initStreamSources()
@ -799,7 +799,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
withContext(Dispatchers.Main) {
playerBinding.exoProgress.setSegments(segments)
playerBinding.sbToggle.visibility = View.VISIBLE
playerBinding.sbToggle.isVisible = true
updateDisplayedDuration()
}
segments.firstOrNull { it.category == SPONSOR_HIGHLIGHT_CATEGORY }?.let {
@ -1041,7 +1041,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
binding.autoplayCountdown.setHideSelfListener {
// could fail if the video already got closed before
runCatching {
binding.autoplayCountdown.visibility = View.GONE
binding.autoplayCountdown.isGone = true
binding.player.useController = true
}
}
@ -1154,13 +1154,13 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
private fun initializeChapters() {
if (chapters.isEmpty()) {
binding.chaptersRecView.visibility = View.GONE
playerBinding.chapterLL.visibility = View.INVISIBLE
binding.chaptersRecView.isGone = true
playerBinding.chapterLL.isInvisible = true
return
}
// show the chapter layouts
binding.chaptersRecView.visibility = View.VISIBLE
playerBinding.chapterLL.visibility = View.VISIBLE
binding.chaptersRecView.isVisible = true
playerBinding.chapterLL.isVisible = true
// enable chapters in the video description
binding.chaptersRecView.layoutManager =
@ -1525,7 +1525,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
getConstraintSet(R.id.start).constrainHeight(R.id.player, -1)
enableTransition(R.id.yt_transition, false)
}
binding.linLayout.visibility = View.GONE
binding.linLayout.isGone = true
updateCaptionsLanguage(null)
} else {
@ -1542,7 +1542,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)
enableTransition(R.id.yt_transition, true)
}
binding.linLayout.visibility = View.VISIBLE
binding.linLayout.isVisible = true
}
updateCaptionsLanguage(captionLanguage)
@ -1582,7 +1582,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
.build()
private fun setupSeekbarPreview() {
playerBinding.seekbarPreview.visibility = View.GONE
playerBinding.seekbarPreview.isGone = true
playerBinding.exoProgress.addListener(
SeekbarPreviewListener(
OnlineTimeFrameReceiver(requireContext(), streams.previewFrames),

View File

@ -7,6 +7,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
@ -90,7 +91,7 @@ class PlaylistFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
binding.playlistRecView.layoutManager = LinearLayoutManager(context)
binding.playlistProgress.visibility = View.VISIBLE
binding.playlistProgress.isVisible = true
isBookmarked = runBlocking(Dispatchers.IO) {
DatabaseHolder.Database.playlistBookmarkDao().includes(playlistId!!)
@ -118,7 +119,7 @@ class PlaylistFragment : Fragment() {
}
private fun fetchPlaylist() {
binding.playlistScrollview.visibility = View.GONE
binding.playlistScrollview.isGone = true
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.CREATED) {
val response = try {
@ -132,12 +133,12 @@ class PlaylistFragment : Fragment() {
val binding = _binding ?: return@repeatOnLifecycle
playlistFeed = response.relatedStreams.toMutableList()
binding.playlistScrollview.visibility = View.VISIBLE
binding.playlistScrollview.isVisible = true
nextPage = response.nextpage
playlistName = response.name
isLoading = false
ImageHelper.loadImage(response.thumbnailUrl, binding.thumbnail)
binding.playlistProgress.visibility = View.GONE
binding.playlistProgress.isGone = true
binding.playlistName.text = response.name
binding.playlistName.setOnClickListener {

View File

@ -5,6 +5,8 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Lifecycle
@ -63,8 +65,8 @@ class SearchFragment : Fragment() {
private fun showData(query: String?) {
// fetch search suggestions if enabled or show the search history
binding.historyEmpty.visibility = View.GONE
binding.suggestionsRecycler.visibility = View.VISIBLE
binding.historyEmpty.isGone = true
binding.suggestionsRecycler.isVisible = true
if (query.isNullOrEmpty()) {
showHistory()
} else if (PreferenceHelper.getBoolean(PreferenceKeys.SEARCH_SUGGESTIONS, true)) {
@ -106,8 +108,8 @@ class SearchFragment : Fragment() {
(activity as MainActivity).searchView
)
} else {
binding.suggestionsRecycler.visibility = View.GONE
binding.historyEmpty.visibility = View.VISIBLE
binding.suggestionsRecycler.isGone = true
binding.historyEmpty.isVisible = true
}
}
}

View File

@ -7,6 +7,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.view.isGone
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
@ -75,7 +76,7 @@ class TrendsFragment : Fragment() {
val binding = _binding ?: return@repeatOnLifecycle
binding.homeRefresh.isRefreshing = false
binding.progressBar.visibility = View.GONE
binding.progressBar.isGone = true
// show a [SnackBar] if there are no trending videos available
if (response.isEmpty()) {

View File

@ -7,6 +7,8 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.postDelayed
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
@ -71,8 +73,8 @@ class WatchHistoryFragment : Fragment() {
.setTitle(R.string.clear_history)
.setMessage(R.string.irreversible)
.setPositiveButton(R.string.okay) { _, _ ->
binding.historyScrollView.visibility = View.GONE
binding.historyEmpty.visibility = View.VISIBLE
binding.historyScrollView.isGone = true
binding.historyEmpty.isVisible = true
lifecycleScope.launch(Dispatchers.IO) {
Database.watchHistoryDao().deleteAll()
}
@ -110,8 +112,8 @@ class WatchHistoryFragment : Fragment() {
binding.watchHistoryRecView.layoutManager = LinearLayoutManager(context)
binding.watchHistoryRecView.adapter = watchHistoryAdapter
binding.historyEmpty.visibility = View.GONE
binding.historyScrollView.visibility = View.VISIBLE
binding.historyEmpty.isGone = true
binding.historyScrollView.isVisible = true
val itemTouchCallback = object : ItemTouchHelper.SimpleCallback(
0,
@ -142,8 +144,8 @@ class WatchHistoryFragment : Fragment() {
RecyclerView.AdapterDataObserver() {
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
if (watchHistoryAdapter.itemCount == 0) {
binding.historyScrollView.visibility = View.GONE
binding.historyEmpty.visibility = View.VISIBLE
binding.historyScrollView.isGone = true
binding.historyEmpty.isVisible = true
}
}
})

View File

@ -1,20 +1,20 @@
package com.github.libretube.ui.listeners
import android.text.format.DateUtils
import android.util.Log
import android.view.View
import android.view.ViewGroup.MarginLayoutParams
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.media3.common.util.UnstableApi
import androidx.media3.ui.TimeBar
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
import com.github.libretube.ui.interfaces.TimeFrameReceiver
import kotlin.math.absoluteValue
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.math.absoluteValue
@UnstableApi
class SeekbarPreviewListener(
@ -69,7 +69,7 @@ class SeekbarPreviewListener(
.translationYBy(30f)
.setDuration(200)
.withEndAction {
playerBinding.seekbarPreview.visibility = View.GONE
playerBinding.seekbarPreview.isGone = true
playerBinding.seekbarPreview.translationY -= 30f
playerBinding.seekbarPreview.alpha = 1f
}

View File

@ -5,9 +5,9 @@ import android.os.Handler
import android.os.Looper
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import androidx.core.os.postDelayed
import androidx.core.view.isVisible
import com.github.libretube.R
import com.github.libretube.databinding.AutoplayCountdownBinding
@ -34,7 +34,7 @@ class AutoplayCountdownView(
}
fun startCountdown(onEnd: () -> Unit) {
this.visibility = View.VISIBLE
this.isVisible = true
onCountdownEnd = {
hideSelf.invoke()
onEnd.invoke()

View File

@ -275,7 +275,7 @@ open class CustomExoPlayerView(
if (PlayerHelper.doubleTapToSeek) return
listOf(binding.forwardBTN, binding.rewindBTN).forEach {
it.visibility = View.VISIBLE
it.isVisible = true
}
}
@ -372,7 +372,7 @@ open class CustomExoPlayerView(
// start callback to hide the button
runnableHandler.removeCallbacksAndMessages(HIDE_REWIND_BUTTON_TOKEN)
runnableHandler.postDelayed(700, HIDE_REWIND_BUTTON_TOKEN) {
rewindBTN.visibility = View.GONE
rewindBTN.isGone = true
}
}
}
@ -387,7 +387,7 @@ open class CustomExoPlayerView(
// start callback to hide the button
runnableHandler.removeCallbacksAndMessages(HIDE_FORWARD_BUTTON_TOKEN)
runnableHandler.postDelayed(700, HIDE_FORWARD_BUTTON_TOKEN) {
forwardBTN.visibility = View.GONE
forwardBTN.isGone = true
}
}
}
@ -398,7 +398,7 @@ open class CustomExoPlayerView(
textView: TextView,
isRewind: Boolean
) {
container.visibility = View.VISIBLE
container.isVisible = true
// the direction of the action
val direction = if (isRewind) -1 else 1
@ -452,7 +452,7 @@ open class CustomExoPlayerView(
}
private fun updateBrightness(distance: Float) {
gestureViewBinding.brightnessControlView.visibility = View.VISIBLE
gestureViewBinding.brightnessControlView.isVisible = true
val bar = gestureViewBinding.brightnessProgressBar
if (bar.progress == 0) {
@ -477,7 +477,7 @@ open class CustomExoPlayerView(
val bar = gestureViewBinding.volumeProgressBar
gestureViewBinding.volumeControlView.apply {
if (visibility == View.GONE) {
visibility = View.VISIBLE
isVisible = true
// Volume could be changed using other mediums, sync progress
// bar with new value.
bar.progress = audioHelper.getVolumeWithScale(bar.max)
@ -679,8 +679,8 @@ open class CustomExoPlayerView(
}
override fun onSwipeEnd() {
gestureViewBinding.brightnessControlView.visibility = View.GONE
gestureViewBinding.volumeControlView.visibility = View.GONE
gestureViewBinding.brightnessControlView.isGone = true
gestureViewBinding.volumeControlView.isGone = true
}
override fun onZoom() {

View File

@ -11,7 +11,6 @@ import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import androidx.media3.ui.DefaultTimeBar
import com.github.libretube.api.obj.Segment
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.extensions.dpToPx
import com.github.libretube.helpers.PreferenceHelper
import com.github.libretube.helpers.ThemeHelper