From 22c7ebcc9ccc5bc1ab303ee224c46f4a399c4915 Mon Sep 17 00:00:00 2001 From: GilesMunn Date: Sun, 9 Oct 2022 14:34:39 +0100 Subject: [PATCH 1/5] Added share button for channels. Closes #1510 --- .../github/libretube/ui/dialogs/ShareDialog.kt | 11 ++++++++++- .../libretube/ui/fragments/ChannelFragment.kt | 6 ++++++ .../libretube/ui/fragments/PlayerFragment.kt | 2 +- .../ui/sheets/PlaylistOptionsBottomSheet.kt | 2 +- .../ui/sheets/VideoOptionsBottomSheet.kt | 2 +- app/src/main/res/layout/fragment_channel.xml | 17 +++++++++++++++++ 6 files changed, 36 insertions(+), 4 deletions(-) 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 6a12e33e7..1295d02b8 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 @@ -17,6 +17,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder class ShareDialog( private val id: String, private val isPlaylist: Boolean, + private val isChannel: Boolean, private val position: Long? = null ) : DialogFragment() { private var binding: DialogShareBinding? = null @@ -50,7 +51,15 @@ class ShareDialog( // only available for custom instances else -> instanceUrl } - val path = if (!isPlaylist) "/watch?v=$id" else "/playlist?list=$id" + var path = if (!isChannel) { + if (!isPlaylist) { + "/watch?v=$id" + } else { + "/playlist?list=$id" + } + } else { + "/c/$id" + } var url = "$host$path" if (binding != null && binding!!.timeCodeSwitch.isChecked) { 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 e3c9c67bb..4d3ea21f6 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 @@ -17,6 +17,7 @@ import com.github.libretube.extensions.formatShort import com.github.libretube.extensions.toID import com.github.libretube.ui.adapters.ChannelAdapter import com.github.libretube.ui.base.BaseFragment +import com.github.libretube.ui.dialogs.ShareDialog import com.github.libretube.util.ImageHelper import retrofit2.HttpException import java.io.IOException @@ -123,6 +124,11 @@ class ChannelFragment : BaseFragment() { getString(R.string.unsubscribe) } } + + binding.channelShare.setOnClickListener { + val shareDialog = ShareDialog(response.name!!, false, true) + shareDialog.show(childFragmentManager, ShareDialog::class.java.name) + } } nextPage = response.nextpage 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 c924ef1a2..c470fc99c 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 @@ -425,7 +425,7 @@ class PlayerFragment : BaseFragment() { // share button binding.relPlayerShare.setOnClickListener { - val shareDialog = ShareDialog(videoId!!, false, exoPlayer.currentPosition / 1000) + val shareDialog = ShareDialog(videoId!!, false, false,exoPlayer.currentPosition / 1000) shareDialog.show(childFragmentManager, ShareDialog::class.java.name) } diff --git a/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt index 52ad712e6..803d53414 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt @@ -74,7 +74,7 @@ class PlaylistOptionsBottomSheet( } // share the playlist context?.getString(R.string.share) -> { - val shareDialog = ShareDialog(playlistId, true) + val shareDialog = ShareDialog(playlistId, true, false) // using parentFragmentManager, childFragmentManager doesn't work here shareDialog.show(parentFragmentManager, ShareDialog::class.java.name) } diff --git a/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt index 8c4a49f8c..f54509045 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt @@ -73,7 +73,7 @@ class VideoOptionsBottomSheet( downloadDialog.show(parentFragmentManager, DownloadDialog::class.java.name) } context?.getString(R.string.share) -> { - val shareDialog = ShareDialog(videoId, false) + val shareDialog = ShareDialog(videoId, false, false) // using parentFragmentManager is important here shareDialog.show(parentFragmentManager, ShareDialog::class.java.name) } diff --git a/app/src/main/res/layout/fragment_channel.xml b/app/src/main/res/layout/fragment_channel.xml index 7b8d14da6..021ae777e 100644 --- a/app/src/main/res/layout/fragment_channel.xml +++ b/app/src/main/res/layout/fragment_channel.xml @@ -73,6 +73,22 @@ + + Date: Sun, 9 Oct 2022 14:39:27 +0100 Subject: [PATCH 2/5] Ktlint formatting. --- .../java/com/github/libretube/ui/fragments/ChannelFragment.kt | 2 +- .../java/com/github/libretube/ui/fragments/PlayerFragment.kt | 2 +- app/src/main/java/com/github/libretube/util/DownloadHelper.kt | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) 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 4d3ea21f6..7c8d6864d 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 @@ -126,7 +126,7 @@ class ChannelFragment : BaseFragment() { } binding.channelShare.setOnClickListener { - val shareDialog = ShareDialog(response.name!!, false, true) + val shareDialog = ShareDialog(response.name!!, false, true) shareDialog.show(childFragmentManager, ShareDialog::class.java.name) } } 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 c470fc99c..86835bedc 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 @@ -425,7 +425,7 @@ class PlayerFragment : BaseFragment() { // share button binding.relPlayerShare.setOnClickListener { - val shareDialog = ShareDialog(videoId!!, false, false,exoPlayer.currentPosition / 1000) + val shareDialog = ShareDialog(videoId!!, false, false, exoPlayer.currentPosition / 1000) shareDialog.show(childFragmentManager, ShareDialog::class.java.name) } diff --git a/app/src/main/java/com/github/libretube/util/DownloadHelper.kt b/app/src/main/java/com/github/libretube/util/DownloadHelper.kt index c93c83af7..3633f93c5 100644 --- a/app/src/main/java/com/github/libretube/util/DownloadHelper.kt +++ b/app/src/main/java/com/github/libretube/util/DownloadHelper.kt @@ -2,7 +2,6 @@ package com.github.libretube.util import android.content.Context import android.os.Build -import com.github.libretube.BuildConfig import com.github.libretube.constants.DownloadType import com.github.libretube.obj.DownloadedFile import java.io.File From 93ebedc3287149431ec5c5900c3521ee73edcf1c Mon Sep 17 00:00:00 2001 From: GilesMunn Date: Sun, 9 Oct 2022 15:06:18 +0100 Subject: [PATCH 3/5] Added views placeholder to channel view. --- .../com/github/libretube/ui/adapters/ChannelAdapter.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/ChannelAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/ChannelAdapter.kt index c5e74b2fb..1aca3e56a 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/ChannelAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/ChannelAdapter.kt @@ -6,6 +6,7 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.RecyclerView +import com.github.libretube.R import com.github.libretube.api.obj.StreamItem import com.github.libretube.databinding.VideoRowBinding import com.github.libretube.extensions.formatShort @@ -15,6 +16,7 @@ import com.github.libretube.ui.sheets.VideoOptionsBottomSheet import com.github.libretube.ui.viewholders.ChannelViewHolder import com.github.libretube.util.ImageHelper import com.github.libretube.util.NavigationHelper +import org.chromium.base.ContextUtils class ChannelAdapter( private val videoFeed: MutableList, @@ -46,8 +48,9 @@ class ChannelAdapter( videoTitle.text = video.title videoInfo.text = - video.views.formatShort() + " • " + - DateUtils.getRelativeTimeSpanString(video.uploaded!!) + video.views.formatShort() + " " + + ContextUtils.getApplicationContext().resources.getString(R.string.views_placeholder) + + " • " + DateUtils.getRelativeTimeSpanString(video.uploaded!!) thumbnailDuration.text = DateUtils.formatElapsedTime(video.duration!!) From 6d9b55e5194fb04e9f3007de9eda3758b6691ed2 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 9 Oct 2022 18:43:11 +0200 Subject: [PATCH 4/5] use proper kotlin syntax --- .../libretube/constants/ShareObjectType.kt | 7 +++++++ .../libretube/ui/adapters/ChannelAdapter.kt | 2 +- .../github/libretube/ui/dialogs/ShareDialog.kt | 16 ++++++---------- .../libretube/ui/fragments/ChannelFragment.kt | 3 ++- .../libretube/ui/fragments/PlayerFragment.kt | 3 ++- .../ui/sheets/PlaylistOptionsBottomSheet.kt | 3 ++- .../ui/sheets/VideoOptionsBottomSheet.kt | 3 ++- 7 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/com/github/libretube/constants/ShareObjectType.kt diff --git a/app/src/main/java/com/github/libretube/constants/ShareObjectType.kt b/app/src/main/java/com/github/libretube/constants/ShareObjectType.kt new file mode 100644 index 000000000..175585f65 --- /dev/null +++ b/app/src/main/java/com/github/libretube/constants/ShareObjectType.kt @@ -0,0 +1,7 @@ +package com.github.libretube.constants + +object ShareObjectType { + const val VIDEO = 0 + const val PLAYLIST = 1 + const val CHANNEL = 2 +} diff --git a/app/src/main/java/com/github/libretube/ui/adapters/ChannelAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/ChannelAdapter.kt index 1aca3e56a..f8dcf4668 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/ChannelAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/ChannelAdapter.kt @@ -49,7 +49,7 @@ class ChannelAdapter( videoInfo.text = video.views.formatShort() + " " + - ContextUtils.getApplicationContext().resources.getString(R.string.views_placeholder) + + root.context.getString(R.string.views_placeholder) + " • " + DateUtils.getRelativeTimeSpanString(video.uploaded!!) thumbnailDuration.text = 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 1295d02b8..3c39f4670 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 @@ -7,6 +7,7 @@ import androidx.fragment.app.DialogFragment import com.github.libretube.R import com.github.libretube.constants.PIPED_FRONTEND_URL import com.github.libretube.constants.PreferenceKeys +import com.github.libretube.constants.ShareObjectType import com.github.libretube.constants.YOUTUBE_FRONTEND_URL import com.github.libretube.databinding.DialogShareBinding import com.github.libretube.db.DatabaseHolder.Companion.Database @@ -16,8 +17,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder class ShareDialog( private val id: String, - private val isPlaylist: Boolean, - private val isChannel: Boolean, + private val shareObjectType: Int, private val position: Long? = null ) : DialogFragment() { private var binding: DialogShareBinding? = null @@ -51,14 +51,10 @@ class ShareDialog( // only available for custom instances else -> instanceUrl } - var path = if (!isChannel) { - if (!isPlaylist) { - "/watch?v=$id" - } else { - "/playlist?list=$id" - } - } else { - "/c/$id" + var path = when (shareObjectType) { + ShareObjectType.VIDEO -> "/watch?v=$id" + ShareObjectType.PLAYLIST -> "/playlist?list=$id" + else -> "/c/$id" } var url = "$host$path" 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 7c8d6864d..3cc22c92c 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 @@ -11,6 +11,7 @@ import com.github.libretube.R import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.SubscriptionHelper import com.github.libretube.constants.IntentData +import com.github.libretube.constants.ShareObjectType import com.github.libretube.databinding.FragmentChannelBinding import com.github.libretube.extensions.TAG import com.github.libretube.extensions.formatShort @@ -126,7 +127,7 @@ class ChannelFragment : BaseFragment() { } binding.channelShare.setOnClickListener { - val shareDialog = ShareDialog(response.name!!, false, true) + val shareDialog = ShareDialog(response.name!!, ShareObjectType.CHANNEL) shareDialog.show(childFragmentManager, ShareDialog::class.java.name) } } 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 86835bedc..131e2c2f8 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 @@ -40,6 +40,7 @@ import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.SubscriptionHelper import com.github.libretube.constants.IntentData import com.github.libretube.constants.PreferenceKeys +import com.github.libretube.constants.ShareObjectType import com.github.libretube.databinding.DoubleTapOverlayBinding import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding import com.github.libretube.databinding.FragmentPlayerBinding @@ -425,7 +426,7 @@ class PlayerFragment : BaseFragment() { // share button binding.relPlayerShare.setOnClickListener { - val shareDialog = ShareDialog(videoId!!, false, false, exoPlayer.currentPosition / 1000) + val shareDialog = ShareDialog(videoId!!, ShareObjectType.VIDEO, exoPlayer.currentPosition / 1000) shareDialog.show(childFragmentManager, ShareDialog::class.java.name) } diff --git a/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt index 803d53414..8c50750c1 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt @@ -6,6 +6,7 @@ import android.util.Log import android.widget.Toast import com.github.libretube.R import com.github.libretube.api.RetrofitInstance +import com.github.libretube.constants.ShareObjectType import com.github.libretube.databinding.DialogTextPreferenceBinding import com.github.libretube.extensions.TAG import com.github.libretube.extensions.toID @@ -74,7 +75,7 @@ class PlaylistOptionsBottomSheet( } // share the playlist context?.getString(R.string.share) -> { - val shareDialog = ShareDialog(playlistId, true, false) + val shareDialog = ShareDialog(playlistId, ShareObjectType.PLAYLIST) // using parentFragmentManager, childFragmentManager doesn't work here shareDialog.show(parentFragmentManager, ShareDialog::class.java.name) } diff --git a/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt index f54509045..f174e2a33 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt @@ -4,6 +4,7 @@ import android.os.Bundle import android.widget.Toast import com.github.libretube.R import com.github.libretube.constants.IntentData +import com.github.libretube.constants.ShareObjectType import com.github.libretube.ui.dialogs.AddToPlaylistDialog import com.github.libretube.ui.dialogs.DownloadDialog import com.github.libretube.ui.dialogs.ShareDialog @@ -73,7 +74,7 @@ class VideoOptionsBottomSheet( downloadDialog.show(parentFragmentManager, DownloadDialog::class.java.name) } context?.getString(R.string.share) -> { - val shareDialog = ShareDialog(videoId, false, false) + val shareDialog = ShareDialog(videoId, ShareObjectType.VIDEO) // using parentFragmentManager is important here shareDialog.show(parentFragmentManager, ShareDialog::class.java.name) } From 94e4f90a018d21446b22df5ab16a2e01c0424800 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 9 Oct 2022 22:13:41 +0200 Subject: [PATCH 5/5] UI improvements --- .../github/libretube/ui/adapters/ChannelAdapter.kt | 1 - app/src/main/res/layout/fragment_channel.xml | 11 ++++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/ChannelAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/ChannelAdapter.kt index f8dcf4668..d0467ad4b 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/ChannelAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/ChannelAdapter.kt @@ -16,7 +16,6 @@ import com.github.libretube.ui.sheets.VideoOptionsBottomSheet import com.github.libretube.ui.viewholders.ChannelViewHolder import com.github.libretube.util.ImageHelper import com.github.libretube.util.NavigationHelper -import org.chromium.base.ContextUtils class ChannelAdapter( private val videoFeed: MutableList, diff --git a/app/src/main/res/layout/fragment_channel.xml b/app/src/main/res/layout/fragment_channel.xml index 021ae777e..36af85617 100644 --- a/app/src/main/res/layout/fragment_channel.xml +++ b/app/src/main/res/layout/fragment_channel.xml @@ -75,18 +75,16 @@