From 05fa57b912fde284c7b1206c7cf7b2b038e50ac6 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 3 Aug 2023 14:52:37 +0200 Subject: [PATCH] refactor: replace View#setVisibility with kotlin visibility extension --- .../github/libretube/api/ResettableLazy.kt | 2 +- .../github/libretube/helpers/NavBarHelper.kt | 4 +- .../github/libretube/helpers/PlayerHelper.kt | 2 - .../github/libretube/helpers/ThemeHelper.kt | 1 - .../libretube/services/ClosingService.kt | 1 - .../libretube/services/OnlinePlayerService.kt | 1 - .../libretube/ui/activities/MainActivity.kt | 14 ++++-- .../libretube/ui/activities/RouterActivity.kt | 5 +- .../ui/activities/VideoTagsAdapter.kt | 5 +- .../libretube/ui/adapters/CommentsAdapter.kt | 13 +++--- .../libretube/ui/adapters/DownloadsAdapter.kt | 7 +-- .../libretube/ui/adapters/PlaylistAdapter.kt | 4 +- .../ui/adapters/PlaylistBookmarkAdapter.kt | 4 +- .../ui/adapters/SearchHistoryAdapter.kt | 4 +- .../libretube/ui/dialogs/DownloadDialog.kt | 4 +- .../libretube/ui/dialogs/ShareDialog.kt | 3 +- .../ui/extensions/SetWatchProgressLength.kt | 18 ++++++-- .../ui/extensions/SetupSubscriptionButton.kt | 11 +++-- .../ui/fragments/AudioPlayerFragment.kt | 17 +++---- .../libretube/ui/fragments/ChannelFragment.kt | 8 ++-- .../ui/fragments/CommentsMainFragment.kt | 11 +++-- .../ui/fragments/CommentsRepliesFragment.kt | 6 ++- .../ui/fragments/DownloadsFragment.kt | 14 +++--- .../libretube/ui/fragments/HomeFragment.kt | 4 +- .../libretube/ui/fragments/LibraryFragment.kt | 9 ++-- .../libretube/ui/fragments/PlayerFragment.kt | 46 +++++++++---------- .../ui/fragments/PlaylistFragment.kt | 9 ++-- .../libretube/ui/fragments/SearchFragment.kt | 10 ++-- .../libretube/ui/fragments/TrendsFragment.kt | 3 +- .../ui/fragments/WatchHistoryFragment.kt | 14 +++--- .../ui/interfaces/TimeFrameReceiver.kt | 2 +- .../ui/listeners/SeekbarPreviewListener.kt | 6 +-- .../ui/viewholders/VideoTagsViewHolder.kt | 2 +- .../ui/views/AutoplayCountdownView.kt | 4 +- .../libretube/ui/views/CustomExoPlayerView.kt | 16 +++---- .../libretube/ui/views/MarkableTimeBar.kt | 1 - .../util/OfflineTimeFrameReceiver.kt | 4 +- .../libretube/util/OnlineTimeFrameReceiver.kt | 4 +- 38 files changed, 159 insertions(+), 134 deletions(-) diff --git a/app/src/main/java/com/github/libretube/api/ResettableLazy.kt b/app/src/main/java/com/github/libretube/api/ResettableLazy.kt index bd6e1120c..0160af7a5 100644 --- a/app/src/main/java/com/github/libretube/api/ResettableLazy.kt +++ b/app/src/main/java/com/github/libretube/api/ResettableLazy.kt @@ -1,6 +1,6 @@ package com.github.libretube.api -import java.util.* +import java.util.LinkedList import kotlin.reflect.KProperty class ResettableLazyManager { diff --git a/app/src/main/java/com/github/libretube/helpers/NavBarHelper.kt b/app/src/main/java/com/github/libretube/helpers/NavBarHelper.kt index e2788b5b3..c250cfea5 100644 --- a/app/src/main/java/com/github/libretube/helpers/NavBarHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/NavBarHelper.kt @@ -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) } diff --git a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt index d4c60968b..fc9f63d65 100644 --- a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt @@ -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 diff --git a/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt b/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt index c99a99b48..768dc6130 100644 --- a/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt @@ -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 { diff --git a/app/src/main/java/com/github/libretube/services/ClosingService.kt b/app/src/main/java/com/github/libretube/services/ClosingService.kt index 33aadc0d4..7cf45f11b 100644 --- a/app/src/main/java/com/github/libretube/services/ClosingService.kt +++ b/app/src/main/java/com/github/libretube/services/ClosingService.kt @@ -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 diff --git a/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt b/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt index f0b4c1e1b..c9fb025da 100644 --- a/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt +++ b/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt @@ -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 diff --git a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt index f4810e9a2..e188c4c14 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt @@ -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) diff --git a/app/src/main/java/com/github/libretube/ui/activities/RouterActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/RouterActivity.kt index 3709172ad..09b4d0335 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/RouterActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/RouterActivity.kt @@ -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() diff --git a/app/src/main/java/com/github/libretube/ui/activities/VideoTagsAdapter.kt b/app/src/main/java/com/github/libretube/ui/activities/VideoTagsAdapter.kt index 578469e13..bb8ff28e7 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/VideoTagsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/VideoTagsAdapter.kt @@ -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 @@ -30,4 +27,4 @@ class VideoTagsAdapter(private val tags: List) : } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt index fb15b7d9e..90b4f4195 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt @@ -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()) { diff --git a/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt index b7c9e9410..b0ab208c4 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt @@ -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 } diff --git a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt index 4909a101d..aa57a6eb5 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt @@ -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) 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 ad0edf26a..22451b400 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 @@ -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( diff --git a/app/src/main/java/com/github/libretube/ui/adapters/SearchHistoryAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/SearchHistoryAdapter.kt index 1fe0ac59a..7054f4a6e 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/SearchHistoryAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/SearchHistoryAdapter.kt @@ -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 diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt index 0b8405f85..761e6461f 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt @@ -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( diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt index 8604c0c55..8d7ac21b2 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt @@ -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 } } diff --git a/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt b/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt index 1963c8b16..5db1a5fba 100644 --- a/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt +++ b/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt @@ -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 { 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 { matchConstraintPercentWidth = progress / duration.toFloat() } - visibility = View.VISIBLE + isVisible = true } diff --git a/app/src/main/java/com/github/libretube/ui/extensions/SetupSubscriptionButton.kt b/app/src/main/java/com/github/libretube/ui/extensions/SetupSubscriptionButton.kt index aa836e34e..7b6f22889 100644 --- a/app/src/main/java/com/github/libretube/ui/extensions/SetupSubscriptionButton.kt +++ b/app/src/main/java/com/github/libretube/ui/extensions/SetupSubscriptionButton.kt @@ -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 } } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt index 9345acf1e..f1041e7fe 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt @@ -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) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt index 8b1ba7950..c2a2eb2a5 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt @@ -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 } } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/CommentsMainFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/CommentsMainFragment.kt index e9588c8c8..5d2eaa5dc 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/CommentsMainFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/CommentsMainFragment.kt @@ -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( diff --git a/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt index 7bf6b487c..a79afd55e 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt @@ -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 } } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/DownloadsFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/DownloadsFragment.kt index 7960fb04e..cf84b2f76 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/DownloadsFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/DownloadsFragment.kt @@ -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()) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt index 15b2f6d22..d84b51913 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt @@ -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 } } }) 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 337d96f3d..0433157a8 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 @@ -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 } } } 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 2ab74a84e..6780ac66f 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 @@ -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() @@ -761,7 +761,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { if (binding.playerMotionLayout.progress != 1.0f) { // show controllers when not in picture in picture mode val inPipMode = PlayerHelper.pipEnabled && - PictureInPictureCompat.isInPictureInPictureMode(requireActivity()) + PictureInPictureCompat.isInPictureInPictureMode(requireActivity()) if (!inPipMode) { binding.player.useController = true } @@ -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 { @@ -991,8 +991,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { }.orEmpty() binding.additionalVideoInfo.text = "${context?.getString(R.string.category)}: ${streams.category}\n" + - "${context?.getString(R.string.license)}: ${streams.license}\n" + - "${context?.getString(R.string.visibility)}: $visibility" + "${context?.getString(R.string.license)}: ${streams.license}\n" + + "${context?.getString(R.string.visibility)}: $visibility" if (streams.tags.isNotEmpty()) { binding.tagsRecycler.layoutManager = @@ -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), 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 bbb097d4f..a2b671108 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 @@ -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 { diff --git a/app/src/main/java/com/github/libretube/ui/fragments/SearchFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/SearchFragment.kt index 4885eeccd..c42c8d40c 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/SearchFragment.kt @@ -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 } } } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/TrendsFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/TrendsFragment.kt index e2e85faef..9ae8d14fa 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/TrendsFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/TrendsFragment.kt @@ -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()) { 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 cdc0f6238..4f23555c4 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 @@ -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 } } }) diff --git a/app/src/main/java/com/github/libretube/ui/interfaces/TimeFrameReceiver.kt b/app/src/main/java/com/github/libretube/ui/interfaces/TimeFrameReceiver.kt index 3400a0582..0a645b327 100644 --- a/app/src/main/java/com/github/libretube/ui/interfaces/TimeFrameReceiver.kt +++ b/app/src/main/java/com/github/libretube/ui/interfaces/TimeFrameReceiver.kt @@ -4,4 +4,4 @@ import android.graphics.Bitmap abstract class TimeFrameReceiver { abstract suspend fun getFrameAtTime(position: Long): Bitmap? -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/ui/listeners/SeekbarPreviewListener.kt b/app/src/main/java/com/github/libretube/ui/listeners/SeekbarPreviewListener.kt index cb29aeed1..a3cb19559 100644 --- a/app/src/main/java/com/github/libretube/ui/listeners/SeekbarPreviewListener.kt +++ b/app/src/main/java/com/github/libretube/ui/listeners/SeekbarPreviewListener.kt @@ -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 } diff --git a/app/src/main/java/com/github/libretube/ui/viewholders/VideoTagsViewHolder.kt b/app/src/main/java/com/github/libretube/ui/viewholders/VideoTagsViewHolder.kt index 93ec15500..9e9e497a3 100644 --- a/app/src/main/java/com/github/libretube/ui/viewholders/VideoTagsViewHolder.kt +++ b/app/src/main/java/com/github/libretube/ui/viewholders/VideoTagsViewHolder.kt @@ -5,4 +5,4 @@ import com.github.libretube.databinding.VideoTagRowBinding class VideoTagsViewHolder( val binding: VideoTagRowBinding -): RecyclerView.ViewHolder(binding.root) +) : RecyclerView.ViewHolder(binding.root) diff --git a/app/src/main/java/com/github/libretube/ui/views/AutoplayCountdownView.kt b/app/src/main/java/com/github/libretube/ui/views/AutoplayCountdownView.kt index 2f58ca2e4..c0bd3ad2a 100644 --- a/app/src/main/java/com/github/libretube/ui/views/AutoplayCountdownView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/AutoplayCountdownView.kt @@ -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() 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 7424de151..f663141be 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 @@ -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() { diff --git a/app/src/main/java/com/github/libretube/ui/views/MarkableTimeBar.kt b/app/src/main/java/com/github/libretube/ui/views/MarkableTimeBar.kt index 356dcd69a..2fad96046 100644 --- a/app/src/main/java/com/github/libretube/ui/views/MarkableTimeBar.kt +++ b/app/src/main/java/com/github/libretube/ui/views/MarkableTimeBar.kt @@ -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 diff --git a/app/src/main/java/com/github/libretube/util/OfflineTimeFrameReceiver.kt b/app/src/main/java/com/github/libretube/util/OfflineTimeFrameReceiver.kt index 536c5e83b..c2541bdcc 100644 --- a/app/src/main/java/com/github/libretube/util/OfflineTimeFrameReceiver.kt +++ b/app/src/main/java/com/github/libretube/util/OfflineTimeFrameReceiver.kt @@ -10,11 +10,11 @@ import java.nio.file.Path class OfflineTimeFrameReceiver( private val context: Context, private val videoSource: Path -): TimeFrameReceiver() { +) : TimeFrameReceiver() { private val metadataRetriever = MediaMetadataRetriever().apply { setDataSource(context, videoSource.toAndroidUri()) } override suspend fun getFrameAtTime(position: Long): Bitmap? { return metadataRetriever.getFrameAtTime(position * 1000) } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/util/OnlineTimeFrameReceiver.kt b/app/src/main/java/com/github/libretube/util/OnlineTimeFrameReceiver.kt index 061975fbc..d7c209ac3 100644 --- a/app/src/main/java/com/github/libretube/util/OnlineTimeFrameReceiver.kt +++ b/app/src/main/java/com/github/libretube/util/OnlineTimeFrameReceiver.kt @@ -11,7 +11,7 @@ import com.github.libretube.ui.interfaces.TimeFrameReceiver class OnlineTimeFrameReceiver( private val context: Context, private val previewFrames: List -): TimeFrameReceiver() { +) : TimeFrameReceiver() { override suspend fun getFrameAtTime(position: Long): Bitmap? { val previewFrame = getPreviewFrame(previewFrames, position) ?: return null val drawable = ImageHelper.getImage(context, previewFrame.previewUrl).drawable ?: return null @@ -52,4 +52,4 @@ class OnlineTimeFrameReceiver( } return null } -} \ No newline at end of file +}