diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index 2d7876eac..79176eea4 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -62,8 +62,11 @@ class MainActivity : BaseActivity() { autoRotationEnabled = PreferenceHelper.getBoolean(PreferenceKeys.AUTO_ROTATION, false) // enable auto rotation if turned on - requestedOrientation = if (autoRotationEnabled) ActivityInfo.SCREEN_ORIENTATION_USER - else ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + requestedOrientation = if (autoRotationEnabled) { + ActivityInfo.SCREEN_ORIENTATION_USER + } else { + ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + } // start service that gets called on closure try { @@ -98,8 +101,10 @@ class MainActivity : BaseActivity() { // hide the trending page if enabled val hideTrendingPage = PreferenceHelper.getBoolean(PreferenceKeys.HIDE_TRENDING_PAGE, false) - if (hideTrendingPage) binding.bottomNav.menu.findItem(R.id.homeFragment).isVisible = - false + if (hideTrendingPage) { + binding.bottomNav.menu.findItem(R.id.homeFragment).isVisible = + false + } // save start tab fragment id startFragmentId = @@ -166,14 +171,18 @@ class MainActivity : BaseActivity() { PreferenceKeys.BREAK_REMINDER_TOGGLE, false ) - ) return + ) { + return + } val breakReminderPref = PreferenceHelper.getString( PreferenceKeys.BREAK_REMINDER, "0" ) if (!breakReminderPref.all { Character.isDigit(it) } || breakReminderPref == "" || breakReminderPref == "0" - ) return + ) { + return + } Handler(Looper.getMainLooper()).postDelayed( { try { @@ -403,8 +412,11 @@ class MainActivity : BaseActivity() { ) { Log.i(TAG(), "Uri Type: Channel") - val bundle = if (channelId != null) bundleOf("channel_id" to channelId) - else bundleOf("channel_name" to channelName) + val bundle = if (channelId != null) { + bundleOf("channel_id" to channelId) + } else { + bundleOf("channel_name" to channelName) + } navController.navigate(R.id.channelFragment, bundle) } @@ -452,8 +464,11 @@ class MainActivity : BaseActivity() { findViewById(R.id.linLayout).visibility = View.VISIBLE val playerViewModel = ViewModelProvider(this)[PlayerViewModel::class.java] playerViewModel.isFullscreen.value = false - requestedOrientation = if (autoRotationEnabled) ActivityInfo.SCREEN_ORIENTATION_USER - else ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + requestedOrientation = if (autoRotationEnabled) { + ActivityInfo.SCREEN_ORIENTATION_USER + } else { + ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + } } override fun onConfigurationChanged(newConfig: Configuration) { diff --git a/app/src/main/java/com/github/libretube/adapters/ChaptersAdapter.kt b/app/src/main/java/com/github/libretube/adapters/ChaptersAdapter.kt index 9a333403d..f85c6536c 100644 --- a/app/src/main/java/com/github/libretube/adapters/ChaptersAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/ChaptersAdapter.kt @@ -33,7 +33,9 @@ class ChaptersAdapter( val color = ThemeHelper.getThemeColor(root.context, android.R.attr.colorControlHighlight) chapterLL.setBackgroundColor(color) - } else chapterLL.setBackgroundColor(Color.TRANSPARENT) + } else { + chapterLL.setBackgroundColor(Color.TRANSPARENT) + } root.setOnClickListener { updateSelectedPosition(position) val chapterStart = chapter.start!! * 1000 // s -> ms diff --git a/app/src/main/java/com/github/libretube/adapters/LegacySubscriptionAdapter.kt b/app/src/main/java/com/github/libretube/adapters/LegacySubscriptionAdapter.kt new file mode 100644 index 000000000..b76b76c36 --- /dev/null +++ b/app/src/main/java/com/github/libretube/adapters/LegacySubscriptionAdapter.kt @@ -0,0 +1,49 @@ +package com.github.libretube.adapters + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.github.libretube.databinding.LegacySubscriptionChannelBinding +import com.github.libretube.obj.Subscription +import com.github.libretube.util.ImageHelper +import com.github.libretube.util.NavigationHelper +import com.github.libretube.util.toID + +class LegacySubscriptionAdapter( + private val subscriptions: List +) : RecyclerView.Adapter() { + + override fun onCreateViewHolder( + parent: ViewGroup, + viewType: Int + ): LegacySubscriptionViewHolder { + val layoutInflater = LayoutInflater.from(parent.context) + val binding = LegacySubscriptionChannelBinding.inflate(layoutInflater, parent, false) + return LegacySubscriptionViewHolder(binding) + } + + override fun onBindViewHolder(holder: LegacySubscriptionViewHolder, position: Int) { + val subscription = subscriptions[position] + holder.binding.apply { + channelName.text = subscription.name + ImageHelper.loadImage( + subscription.avatar, + channelAvatar + ) + root.setOnClickListener { + NavigationHelper.navigateChannel( + root.context, + subscription.url.toID() + ) + } + } + } + + override fun getItemCount(): Int { + return subscriptions.size + } +} + +class LegacySubscriptionViewHolder( + val binding: LegacySubscriptionChannelBinding +) : RecyclerView.ViewHolder(binding.root) diff --git a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt index 97635d6d8..174889726 100644 --- a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt @@ -63,9 +63,11 @@ class SearchAdapter( val channelRowBinding = holder.channelRowBinding val playlistRowBinding = holder.playlistRowBinding - if (videoRowBinding != null) bindWatch(searchItem, videoRowBinding) - else if (channelRowBinding != null) bindChannel(searchItem, channelRowBinding) - else if (playlistRowBinding != null) bindPlaylist(searchItem, playlistRowBinding) + if (videoRowBinding != null) { + bindWatch(searchItem, videoRowBinding) + } else if (channelRowBinding != null) { + bindChannel(searchItem, channelRowBinding) + } else if (playlistRowBinding != null) bindPlaylist(searchItem, playlistRowBinding) } override fun getItemViewType(position: Int): Int { diff --git a/app/src/main/java/com/github/libretube/adapters/TrendingAdapter.kt b/app/src/main/java/com/github/libretube/adapters/TrendingAdapter.kt index 9d79304b4..238d04c82 100644 --- a/app/src/main/java/com/github/libretube/adapters/TrendingAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/TrendingAdapter.kt @@ -24,9 +24,13 @@ class TrendingAdapter( var index = 10 override fun getItemCount(): Int { - return if (showAllAtOne) streamItems.size - else if (index >= streamItems.size) streamItems.size - 1 - else index + return if (showAllAtOne) { + streamItems.size + } else if (index >= streamItems.size) { + streamItems.size - 1 + } else { + index + } } fun updateItems() { diff --git a/app/src/main/java/com/github/libretube/dialogs/AddToPlaylistDialog.kt b/app/src/main/java/com/github/libretube/dialogs/AddToPlaylistDialog.kt index 29511a227..a74e80ee4 100644 --- a/app/src/main/java/com/github/libretube/dialogs/AddToPlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/AddToPlaylistDialog.kt @@ -72,8 +72,10 @@ class AddToPlaylistDialog : DialogFragment() { if (viewModel.lastSelectedPlaylistId != null) { var selectionIndex = 0 response.forEachIndexed { index, playlist -> - if (playlist.id == viewModel.lastSelectedPlaylistId) selectionIndex = - index + if (playlist.id == viewModel.lastSelectedPlaylistId) { + selectionIndex = + index + } } binding.playlistsSpinner.setSelection(selectionIndex) } diff --git a/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt b/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt index a7c682af2..644f064ea 100644 --- a/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt @@ -56,8 +56,11 @@ class PlaylistOptionsDialog( context?.getString(R.string.playOnBackground) -> { runBlocking { val playlist = - if (isOwner) RetrofitInstance.authApi.getPlaylist(playlistId) - else RetrofitInstance.api.getPlaylist(playlistId) + if (isOwner) { + RetrofitInstance.authApi.getPlaylist(playlistId) + } else { + RetrofitInstance.api.getPlaylist(playlistId) + } BackgroundHelper.playOnBackground( context = requireContext(), videoId = playlist.relatedStreams!![0].url.toID(), diff --git a/app/src/main/java/com/github/libretube/extensions/SetFormattedDuration.kt b/app/src/main/java/com/github/libretube/extensions/SetFormattedDuration.kt index 0551ee066..31008c669 100644 --- a/app/src/main/java/com/github/libretube/extensions/SetFormattedDuration.kt +++ b/app/src/main/java/com/github/libretube/extensions/SetFormattedDuration.kt @@ -8,7 +8,10 @@ fun TextView?.setFormattedDuration(duration: Long) { val text = if (duration < 0L) { this!!.setBackgroundColor(R.attr.colorPrimaryDark) this.context.getString(R.string.live) - } else if (duration == 0L) this!!.context.getString(R.string.yt_shorts) - else DateUtils.formatElapsedTime(duration) + } else if (duration == 0L) { + this!!.context.getString(R.string.yt_shorts) + } else { + DateUtils.formatElapsedTime(duration) + } this!!.text = text } diff --git a/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt b/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt index 9f8a5e338..c23814656 100644 --- a/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt @@ -110,8 +110,11 @@ class ChannelFragment : BaseFragment() { fun run() { lifecycleScope.launchWhenCreated { val response = try { - if (channelId != null) RetrofitInstance.api.getChannel(channelId!!) - else RetrofitInstance.api.getChannelByName(channelName!!) + if (channelId != null) { + RetrofitInstance.api.getChannel(channelId!!) + } else { + RetrofitInstance.api.getChannelByName(channelName!!) + } } catch (e: IOException) { binding.channelRefresh.isRefreshing = false println(e) diff --git a/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt b/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt index ff3a583ea..c9923c6bc 100644 --- a/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt @@ -53,7 +53,9 @@ class HomeFragment : BaseFragment() { LocaleHelper .getDetectedCountry(requireContext(), "UK") .uppercase() - } else regionPref + } else { + regionPref + } binding.recview.layoutManager = GridLayoutManager(view.context, grid.toInt()) fetchJson() diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index df4d1907c..4ff7a8835 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -585,13 +585,18 @@ class PlayerFragment : BaseFragment() { val bottomSheetFragment = PlayerOptionsBottomSheet().apply { setOnClickListeners(playerOptionsInterface) // set the auto play mode - currentAutoplayMode = if (autoplayEnabled) context.getString(R.string.enabled) - else context.getString(R.string.disabled) + currentAutoplayMode = if (autoplayEnabled) { + context.getString(R.string.enabled) + } else { + context.getString(R.string.disabled) + } // set the current caption language currentCaptions = if (trackSelector.parameters.preferredTextLanguages.isNotEmpty()) { trackSelector.parameters.preferredTextLanguages[0] - } else context.getString(R.string.none) + } else { + context.getString(R.string.none) + } // set the playback speed val playbackSpeeds = context.resources.getStringArray(R.array.playbackSpeed) val playbackSpeedValues = @@ -603,14 +608,19 @@ class PlayerFragment : BaseFragment() { val quality = exoPlayer.videoSize.height if (quality != 0) { currentQuality = - if (isAdaptive) "${context.getString(R.string.hls)} • ${quality}p" - else "${quality}p" + if (isAdaptive) { + "${context.getString(R.string.hls)} • ${quality}p" + } else { + "${quality}p" + } } // set the repeat mode currentRepeatMode = if (exoPlayer.repeatMode == RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE) { context.getString(R.string.repeat_mode_none) - } else context.getString(R.string.repeat_mode_current) + } else { + context.getString(R.string.repeat_mode_current) + } // set the aspect ratio mode currentResizeMode = when (exoPlayerView.resizeMode) { AspectRatioFrameLayout.RESIZE_MODE_FIT -> context.getString(R.string.resize_mode_fit) @@ -729,9 +739,12 @@ class PlayerFragment : BaseFragment() { "ratio" -> { val videoSize = exoPlayer.videoSize // probably a youtube shorts video - if (videoSize.height > videoSize.width) ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT - // a video with normal aspect ratio - else ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE + if (videoSize.height > videoSize.width) { + ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + } // a video with normal aspect ratio + else { + ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE + } } "auto" -> ActivityInfo.SCREEN_ORIENTATION_SENSOR "landscape" -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE @@ -816,8 +829,11 @@ class PlayerFragment : BaseFragment() { saveWatchPosition() nowPlayingNotification.destroy() activity?.requestedOrientation = - if ((activity as MainActivity).autoRotationEnabled) ActivityInfo.SCREEN_ORIENTATION_USER - else ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + if ((activity as MainActivity).autoRotationEnabled) { + ActivityInfo.SCREEN_ORIENTATION_USER + } else { + ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + } } catch (e: Exception) { } } @@ -1199,7 +1215,11 @@ class PlayerFragment : BaseFragment() { // next and previous buttons playerBinding.skipPrev.visibility = if ( skipButtonsEnabled && Globals.playingQueue.indexOf(videoId!!) != 0 - ) View.VISIBLE else View.INVISIBLE + ) { + View.VISIBLE + } else { + View.INVISIBLE + } playerBinding.skipNext.visibility = if (skipButtonsEnabled) View.VISIBLE else View.INVISIBLE playerBinding.skipPrev.setOnClickListener { @@ -1545,7 +1565,11 @@ class PlayerFragment : BaseFragment() { playerBinding.exoTitle.visibility = if (isLocked && viewModel.isFullscreen.value == true - ) View.VISIBLE else View.INVISIBLE + ) { + View.VISIBLE + } else { + View.INVISIBLE + } // disable double tap to seek when the player is locked if (isLocked) { diff --git a/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt index 3db6baac5..6c310798c 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt @@ -61,8 +61,11 @@ class PlaylistFragment : BaseFragment() { lifecycleScope.launchWhenCreated { val response = try { // load locally stored playlists with the auth api - if (isOwner) RetrofitInstance.authApi.getPlaylist(playlistId!!) - else RetrofitInstance.api.getPlaylist(playlistId!!) + if (isOwner) { + RetrofitInstance.authApi.getPlaylist(playlistId!!) + } else { + RetrofitInstance.api.getPlaylist(playlistId!!) + } } catch (e: IOException) { println(e) Log.e(TAG(), "IOException, you might not have internet connection") @@ -163,13 +166,17 @@ class PlaylistFragment : BaseFragment() { lifecycleScope.launchWhenCreated { val response = try { // load locally stored playlists with the auth api - if (isOwner) RetrofitInstance.authApi.getPlaylistNextPage( - playlistId!!, - nextPage!! - ) else RetrofitInstance.api.getPlaylistNextPage( - playlistId!!, - nextPage!! - ) + if (isOwner) { + RetrofitInstance.authApi.getPlaylistNextPage( + playlistId!!, + nextPage!! + ) + } else { + RetrofitInstance.api.getPlaylistNextPage( + playlistId!!, + nextPage!! + ) + } } catch (e: IOException) { println(e) Log.e(TAG(), "IOException, you might not have internet connection") diff --git a/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt b/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt index 3e65e37d7..b1ab2bfdd 100644 --- a/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt @@ -56,8 +56,11 @@ class SearchFragment() : BaseFragment() { // fetch the search or history binding.historyEmpty.visibility = View.GONE binding.suggestionsRecycler.visibility = View.VISIBLE - if (query == null || query == "") showHistory() - else fetchSuggestions(query) + if (query == null || query == "") { + showHistory() + } else { + fetchSuggestions(query) + } } private fun fetchSuggestions(query: String) { diff --git a/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt b/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt index ce8c2e646..53abbd033 100644 --- a/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt @@ -11,6 +11,7 @@ import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import com.github.libretube.R +import com.github.libretube.adapters.LegacySubscriptionAdapter import com.github.libretube.adapters.SubscriptionChannelAdapter import com.github.libretube.adapters.TrendingAdapter import com.github.libretube.api.RetrofitInstance @@ -125,10 +126,13 @@ class SubscriptionsFragment : BaseFragment() { fun run() { lifecycleScope.launchWhenCreated { feed = try { - if (token != "") RetrofitInstance.authApi.getFeed(token) - else RetrofitInstance.authApi.getUnauthenticatedFeed( - SubscriptionHelper.getFormattedLocalSubscriptions() - ) + if (token != "") { + RetrofitInstance.authApi.getFeed(token) + } else { + RetrofitInstance.authApi.getUnauthenticatedFeed( + SubscriptionHelper.getFormattedLocalSubscriptions() + ) + } } catch (e: IOException) { Log.e(TAG(), e.toString()) Log.e(TAG(), "IOException, you might not have internet connection") @@ -175,10 +179,13 @@ class SubscriptionsFragment : BaseFragment() { fun run() { lifecycleScope.launchWhenCreated { val response = try { - if (token != "") RetrofitInstance.authApi.subscriptions(token) - else RetrofitInstance.authApi.unauthenticatedSubscriptions( - SubscriptionHelper.getFormattedLocalSubscriptions() - ) + if (token != "") { + RetrofitInstance.authApi.subscriptions(token) + } else { + RetrofitInstance.authApi.unauthenticatedSubscriptions( + SubscriptionHelper.getFormattedLocalSubscriptions() + ) + } } catch (e: IOException) { Log.e(TAG(), e.toString()) Log.e(TAG(), "IOException, you might not have internet connection") @@ -191,7 +198,22 @@ class SubscriptionsFragment : BaseFragment() { } if (response.isNotEmpty()) { binding.subChannels.adapter = - SubscriptionChannelAdapter(response.toMutableList()) + if (PreferenceHelper.getBoolean( + PreferenceKeys.LEGACY_SUBSCRIPTIONS, + false + ) + ) { + binding.subChannels.layoutManager = GridLayoutManager( + context, + PreferenceHelper.getString( + PreferenceKeys.LEGACY_SUBSCRIPTIONS_COLUMNS, + "4" + ).toInt() + ) + LegacySubscriptionAdapter(response) + } else { + SubscriptionChannelAdapter(response.toMutableList()) + } } else { Toast.makeText(context, R.string.subscribeIsEmpty, Toast.LENGTH_SHORT).show() } diff --git a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt index 4eac15ab5..3d4d5a335 100644 --- a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt @@ -77,6 +77,14 @@ class AppearanceSettings : MaterialPreferenceFragment() { } true } + + val legacySubscriptionView = findPreference(PreferenceKeys.LEGACY_SUBSCRIPTIONS) + val legacySubscriptionColumns = findPreference(PreferenceKeys.LEGACY_SUBSCRIPTIONS_COLUMNS) + legacySubscriptionColumns?.isVisible = legacySubscriptionView?.isChecked!! + legacySubscriptionView.setOnPreferenceChangeListener { _, newValue -> + legacySubscriptionColumns?.isVisible = newValue as Boolean + true + } } // remove material you from accent color option if not available diff --git a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt index 893452912..e2bdfc5ab 100644 --- a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt @@ -89,8 +89,11 @@ class InstanceSettings : MaterialPreferenceFragment() { authInstance.isVisible = newValue == true logout() // either use new auth url or the normal api url if auth instance disabled - RetrofitInstance.authUrl = if (newValue == false) RetrofitInstance.url - else authInstance.value + RetrofitInstance.authUrl = if (newValue == false) { + RetrofitInstance.url + } else { + authInstance.value + } RetrofitInstance.lazyMgr.reset() activity?.recreate() true @@ -144,9 +147,12 @@ class InstanceSettings : MaterialPreferenceFragment() { val accessGranted = PermissionHelper.isStoragePermissionGranted(requireActivity()) // import subscriptions - if (accessGranted) getContent.launch("*/*") - // request permissions if not granted - else PermissionHelper.requestReadWrite(requireActivity()) + if (accessGranted) { + getContent.launch("*/*") + } // request permissions if not granted + else { + PermissionHelper.requestReadWrite(requireActivity()) + } true } diff --git a/app/src/main/java/com/github/libretube/preferences/MainSettings.kt b/app/src/main/java/com/github/libretube/preferences/MainSettings.kt index 4f464bfdb..ec6e16927 100644 --- a/app/src/main/java/com/github/libretube/preferences/MainSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/MainSettings.kt @@ -79,8 +79,11 @@ class MainSettings : MaterialPreferenceFragment() { val update = findPreference("update") // set the version of the update preference - val versionString = if (BuildConfig.DEBUG) "${BuildConfig.VERSION_NAME} Debug" - else getString(R.string.version, BuildConfig.VERSION_NAME) + val versionString = if (BuildConfig.DEBUG) { + "${BuildConfig.VERSION_NAME} Debug" + } else { + getString(R.string.version, BuildConfig.VERSION_NAME) + } update?.title = versionString // checking for update: yes -> dialog, no -> snackBar diff --git a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt index 4ff0e6b23..c35622a02 100644 --- a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt @@ -31,6 +31,8 @@ object PreferenceKeys { const val LABEL_VISIBILITY = "label_visibility" const val HIDE_TRENDING_PAGE = "hide_trending_page" const val APP_ICON = "icon_change" + const val LEGACY_SUBSCRIPTIONS = "legacy_subscriptions" + const val LEGACY_SUBSCRIPTIONS_COLUMNS = "legacy_subscriptions_columns" /** * Instance diff --git a/app/src/main/java/com/github/libretube/services/DownloadService.kt b/app/src/main/java/com/github/libretube/services/DownloadService.kt index 9d897c3b7..8f00d9971 100644 --- a/app/src/main/java/com/github/libretube/services/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt @@ -53,9 +53,13 @@ class DownloadService : Service() { videoUrl = intent.getStringExtra("videoUrl")!! audioUrl = intent.getStringExtra("audioUrl")!! - downloadType = if (audioUrl != "") DownloadType.AUDIO - else if (videoUrl != "") DownloadType.VIDEO - else DownloadType.NONE + downloadType = if (audioUrl != "") { + DownloadType.AUDIO + } else if (videoUrl != "") { + DownloadType.VIDEO + } else { + DownloadType.NONE + } if (downloadType != DownloadType.NONE) { downloadNotification(intent) downloadManager() diff --git a/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt b/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt index a60567725..76e8c704f 100644 --- a/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt +++ b/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt @@ -23,12 +23,16 @@ class AutoPlayHelper( return if (Globals.playingQueue.last() != currentVideoId) { val currentVideoIndex = Globals.playingQueue.indexOf(currentVideoId) Globals.playingQueue[currentVideoIndex + 1] - } else if (playlistId == null) getNextTrendingVideoId( - currentVideoId, - relatedStreams - ) else getNextPlaylistVideoId( - currentVideoId - ) + } else if (playlistId == null) { + getNextTrendingVideoId( + currentVideoId, + relatedStreams + ) + } else { + getNextPlaylistVideoId( + currentVideoId + ) + } } /** @@ -51,8 +55,11 @@ class AutoPlayHelper( ) ) { nextStreamId = relatedStreams[index].url.toID() - if (index + 1 < relatedStreams.size) index += 1 - else break + if (index + 1 < relatedStreams.size) { + index += 1 + } else { + break + } } return nextStreamId } @@ -65,19 +72,26 @@ class AutoPlayHelper( if (playlistStreamIds.contains(currentVideoId)) { val index = playlistStreamIds.indexOf(currentVideoId) // check whether there's a next video - return if (index + 1 < playlistStreamIds.size) playlistStreamIds[index + 1] - else if (playlistNextPage == null) null - else getNextPlaylistVideoId(currentVideoId) + return if (index + 1 < playlistStreamIds.size) { + playlistStreamIds[index + 1] + } else if (playlistNextPage == null) { + null + } else { + getNextPlaylistVideoId(currentVideoId) + } } else if (playlistStreamIds.isEmpty() || playlistNextPage != null) { // fetch the next page of the playlist return withContext(Dispatchers.IO) { // fetch the playlists or its nextPage's videos val playlist = - if (playlistNextPage == null) RetrofitInstance.authApi.getPlaylist(playlistId!!) - else RetrofitInstance.authApi.getPlaylistNextPage( - playlistId!!, - playlistNextPage!! - ) + if (playlistNextPage == null) { + RetrofitInstance.authApi.getPlaylist(playlistId!!) + } else { + RetrofitInstance.authApi.getPlaylistNextPage( + playlistId!!, + playlistNextPage!! + ) + } // save the playlist urls to the list playlistStreamIds += playlist.relatedStreams!!.map { it.url.toID() } // save playlistNextPage for usage if video is not contained @@ -98,6 +112,8 @@ class AutoPlayHelper( return if (Globals.playingQueue.last() != currentVideoId) { val currentVideoIndex = Globals.playingQueue.indexOf(currentVideoId) Globals.playingQueue[currentVideoIndex + 1] - } else null + } else { + null + } } } diff --git a/app/src/main/java/com/github/libretube/util/BackupHelper.kt b/app/src/main/java/com/github/libretube/util/BackupHelper.kt index de418dcb6..55d96ecd2 100644 --- a/app/src/main/java/com/github/libretube/util/BackupHelper.kt +++ b/app/src/main/java/com/github/libretube/util/BackupHelper.kt @@ -66,11 +66,15 @@ class BackupHelper( // decide for each preference which type it is and save it to the preferences for ((key, value) in entries) { - if (value is Boolean) editor.putBoolean(key, value) - else if (value is Float) editor.putFloat(key, value) - else if (value is Int) editor.putInt(key, value) - else if (value is Long) editor.putLong(key, value) - else if (value is String) editor.putString(key, value) + if (value is Boolean) { + editor.putBoolean(key, value) + } else if (value is Float) { + editor.putFloat(key, value) + } else if (value is Int) { + editor.putInt(key, value) + } else if (value is Long) { + editor.putLong(key, value) + } else if (value is String) editor.putString(key, value) } editor.commit() } catch (e: Exception) { diff --git a/app/src/main/java/com/github/libretube/util/DoubleTapListener.kt b/app/src/main/java/com/github/libretube/util/DoubleTapListener.kt index 324319054..5a96b4539 100644 --- a/app/src/main/java/com/github/libretube/util/DoubleTapListener.kt +++ b/app/src/main/java/com/github/libretube/util/DoubleTapListener.kt @@ -34,7 +34,9 @@ abstract class DoubleTapListener : View.OnClickListener { private val runnable = Runnable { if (!isSingleEvent || SystemClock.elapsedRealtime() - timeStampLastDoubleClick < maximumTimeDifference - ) return@Runnable + ) { + return@Runnable + } onSingleClick() } } diff --git a/app/src/main/java/com/github/libretube/util/ImportHelper.kt b/app/src/main/java/com/github/libretube/util/ImportHelper.kt index 5fca15b42..e8d49963e 100644 --- a/app/src/main/java/com/github/libretube/util/ImportHelper.kt +++ b/app/src/main/java/com/github/libretube/util/ImportHelper.kt @@ -99,10 +99,13 @@ class ImportHelper( val mapper = ObjectMapper() val token = PreferenceHelper.getToken() runBlocking { - val subs = if (token != "") RetrofitInstance.authApi.subscriptions(token) - else RetrofitInstance.authApi.unauthenticatedSubscriptions( - SubscriptionHelper.getFormattedLocalSubscriptions() - ) + val subs = if (token != "") { + RetrofitInstance.authApi.subscriptions(token) + } else { + RetrofitInstance.authApi.unauthenticatedSubscriptions( + SubscriptionHelper.getFormattedLocalSubscriptions() + ) + } val newPipeChannels = mutableListOf() subs.forEach { newPipeChannels += NewPipeSubscription( diff --git a/app/src/main/java/com/github/libretube/util/LocaleHelper.kt b/app/src/main/java/com/github/libretube/util/LocaleHelper.kt index a638c37b0..0b294e1e7 100644 --- a/app/src/main/java/com/github/libretube/util/LocaleHelper.kt +++ b/app/src/main/java/com/github/libretube/util/LocaleHelper.kt @@ -11,8 +11,9 @@ object LocaleHelper { fun updateLanguage(context: Context) { val languageName = PreferenceHelper.getString(PreferenceKeys.LANGUAGE, "sys") - if (languageName == "sys") updateLocaleConf(context, Locale.getDefault()) - else if (languageName?.contains("-") == true) { + if (languageName == "sys") { + updateLocaleConf(context, Locale.getDefault()) + } else if (languageName?.contains("-") == true) { val languageParts = languageName.split("-") val locale = Locale( languageParts[0], diff --git a/app/src/main/java/com/github/libretube/util/NotificationHelper.kt b/app/src/main/java/com/github/libretube/util/NotificationHelper.kt index c11f76d49..c0d9bbc1b 100644 --- a/app/src/main/java/com/github/libretube/util/NotificationHelper.kt +++ b/app/src/main/java/com/github/libretube/util/NotificationHelper.kt @@ -93,10 +93,13 @@ object NotificationHelper { val token = PreferenceHelper.getToken() runBlocking { val task = async { - if (token != "") RetrofitInstance.authApi.getFeed(token) - else RetrofitInstance.authApi.getUnauthenticatedFeed( - SubscriptionHelper.getFormattedLocalSubscriptions() - ) + if (token != "") { + RetrofitInstance.authApi.getFeed(token) + } else { + RetrofitInstance.authApi.getUnauthenticatedFeed( + SubscriptionHelper.getFormattedLocalSubscriptions() + ) + } } // fetch the users feed val videoFeed = try { @@ -110,8 +113,9 @@ object NotificationHelper { val latestFeedStreamId = videoFeed[0].url.toID() // first time notifications enabled - if (lastSeenStreamId == "") PreferenceHelper.setLatestVideoId(lastSeenStreamId) - else if (lastSeenStreamId != latestFeedStreamId) { + if (lastSeenStreamId == "") { + PreferenceHelper.setLatestVideoId(lastSeenStreamId) + } else if (lastSeenStreamId != latestFeedStreamId) { // get the index of the last user-seen video var newStreamIndex = -1 videoFeed.forEachIndexed { index, stream -> diff --git a/app/src/main/java/com/github/libretube/util/ThemeHelper.kt b/app/src/main/java/com/github/libretube/util/ThemeHelper.kt index f3197cebe..5121f0a1e 100644 --- a/app/src/main/java/com/github/libretube/util/ThemeHelper.kt +++ b/app/src/main/java/com/github/libretube/util/ThemeHelper.kt @@ -43,8 +43,11 @@ object ThemeHelper { ) { "my" -> { applyDynamicColors(activity) - if (pureThemeEnabled) R.style.BaseTheme_Pure - else R.style.BaseTheme + if (pureThemeEnabled) { + R.style.BaseTheme_Pure + } else { + R.style.BaseTheme + } } // set the theme, use the pure theme if enabled "red" -> if (pureThemeEnabled) R.style.Theme_Red_Pure else R.style.Theme_Red @@ -85,8 +88,11 @@ object ThemeHelper { // Disable Old Icon(s) for (activityAlias in activityAliases) { val activityClass = "com.github.libretube." + - if (activityAlias == activityAliases[0]) "activities.MainActivity" // default icon/activity - else activityAlias + if (activityAlias == activityAliases[0]) { + "activities.MainActivity" // default icon/activity + } else { + activityAlias + } // remove old icons context.packageManager.setComponentEnabledSetting( @@ -98,8 +104,11 @@ object ThemeHelper { // set the class name for the activity alias val newLogoActivityClass = "com.github.libretube." + - if (newLogoActivityAlias == activityAliases[0]) "activities.MainActivity" // default icon/activity - else newLogoActivityAlias + if (newLogoActivityAlias == activityAliases[0]) { + "activities.MainActivity" // default icon/activity + } else { + newLogoActivityAlias + } // Enable New Icon context.packageManager.setComponentEnabledSetting( ComponentName(context.packageName, newLogoActivityClass), diff --git a/app/src/main/res/layout/legacy_subscription_channel.xml b/app/src/main/res/layout/legacy_subscription_channel.xml new file mode 100644 index 000000000..074fe8b15 --- /dev/null +++ b/app/src/main/res/layout/legacy_subscription_channel.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c2dd962d8..3613bada4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -311,4 +311,5 @@ Copied to clipboard Open Minutes before being reminded + Legacy subscriptions view diff --git a/app/src/main/res/xml/appearance_settings.xml b/app/src/main/res/xml/appearance_settings.xml index ca44e1203..03bf1ac9b 100644 --- a/app/src/main/res/xml/appearance_settings.xml +++ b/app/src/main/res/xml/appearance_settings.xml @@ -77,4 +77,23 @@ + + + + + + + + \ No newline at end of file