Merge pull request #1529 from Bnyro/channelshare

Backup of sharing channels by @GilesMunn
This commit is contained in:
Bnyro 2022-10-09 22:13:56 +02:00 committed by GitHub
commit abc86aabc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 45 additions and 8 deletions

View File

@ -0,0 +1,7 @@
package com.github.libretube.constants
object ShareObjectType {
const val VIDEO = 0
const val PLAYLIST = 1
const val CHANNEL = 2
}

View File

@ -6,6 +6,7 @@ import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R
import com.github.libretube.api.obj.StreamItem import com.github.libretube.api.obj.StreamItem
import com.github.libretube.databinding.VideoRowBinding import com.github.libretube.databinding.VideoRowBinding
import com.github.libretube.extensions.formatShort import com.github.libretube.extensions.formatShort
@ -46,8 +47,9 @@ class ChannelAdapter(
videoTitle.text = video.title videoTitle.text = video.title
videoInfo.text = videoInfo.text =
video.views.formatShort() + "" + video.views.formatShort() + " " +
DateUtils.getRelativeTimeSpanString(video.uploaded!!) root.context.getString(R.string.views_placeholder) +
"" + DateUtils.getRelativeTimeSpanString(video.uploaded!!)
thumbnailDuration.text = thumbnailDuration.text =
DateUtils.formatElapsedTime(video.duration!!) DateUtils.formatElapsedTime(video.duration!!)

View File

@ -7,6 +7,7 @@ import androidx.fragment.app.DialogFragment
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.constants.PIPED_FRONTEND_URL import com.github.libretube.constants.PIPED_FRONTEND_URL
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.constants.ShareObjectType
import com.github.libretube.constants.YOUTUBE_FRONTEND_URL import com.github.libretube.constants.YOUTUBE_FRONTEND_URL
import com.github.libretube.databinding.DialogShareBinding import com.github.libretube.databinding.DialogShareBinding
import com.github.libretube.db.DatabaseHolder.Companion.Database import com.github.libretube.db.DatabaseHolder.Companion.Database
@ -16,7 +17,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
class ShareDialog( class ShareDialog(
private val id: String, private val id: String,
private val isPlaylist: Boolean, private val shareObjectType: Int,
private val position: Long? = null private val position: Long? = null
) : DialogFragment() { ) : DialogFragment() {
private var binding: DialogShareBinding? = null private var binding: DialogShareBinding? = null
@ -50,7 +51,11 @@ class ShareDialog(
// only available for custom instances // only available for custom instances
else -> instanceUrl else -> instanceUrl
} }
val path = if (!isPlaylist) "/watch?v=$id" else "/playlist?list=$id" var path = when (shareObjectType) {
ShareObjectType.VIDEO -> "/watch?v=$id"
ShareObjectType.PLAYLIST -> "/playlist?list=$id"
else -> "/c/$id"
}
var url = "$host$path" var url = "$host$path"
if (binding != null && binding!!.timeCodeSwitch.isChecked) { if (binding != null && binding!!.timeCodeSwitch.isChecked) {

View File

@ -11,12 +11,14 @@ import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.SubscriptionHelper import com.github.libretube.api.SubscriptionHelper
import com.github.libretube.constants.IntentData import com.github.libretube.constants.IntentData
import com.github.libretube.constants.ShareObjectType
import com.github.libretube.databinding.FragmentChannelBinding import com.github.libretube.databinding.FragmentChannelBinding
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.formatShort import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.ui.adapters.ChannelAdapter import com.github.libretube.ui.adapters.ChannelAdapter
import com.github.libretube.ui.base.BaseFragment import com.github.libretube.ui.base.BaseFragment
import com.github.libretube.ui.dialogs.ShareDialog
import com.github.libretube.util.ImageHelper import com.github.libretube.util.ImageHelper
import retrofit2.HttpException import retrofit2.HttpException
import java.io.IOException import java.io.IOException
@ -123,6 +125,11 @@ class ChannelFragment : BaseFragment() {
getString(R.string.unsubscribe) getString(R.string.unsubscribe)
} }
} }
binding.channelShare.setOnClickListener {
val shareDialog = ShareDialog(response.name!!, ShareObjectType.CHANNEL)
shareDialog.show(childFragmentManager, ShareDialog::class.java.name)
}
} }
nextPage = response.nextpage nextPage = response.nextpage

View File

@ -40,6 +40,7 @@ import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.SubscriptionHelper import com.github.libretube.api.SubscriptionHelper
import com.github.libretube.constants.IntentData import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.constants.ShareObjectType
import com.github.libretube.databinding.DoubleTapOverlayBinding import com.github.libretube.databinding.DoubleTapOverlayBinding
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
import com.github.libretube.databinding.FragmentPlayerBinding import com.github.libretube.databinding.FragmentPlayerBinding
@ -425,7 +426,7 @@ class PlayerFragment : BaseFragment() {
// share button // share button
binding.relPlayerShare.setOnClickListener { binding.relPlayerShare.setOnClickListener {
val shareDialog = ShareDialog(videoId!!, false, exoPlayer.currentPosition / 1000) val shareDialog = ShareDialog(videoId!!, ShareObjectType.VIDEO, exoPlayer.currentPosition / 1000)
shareDialog.show(childFragmentManager, ShareDialog::class.java.name) shareDialog.show(childFragmentManager, ShareDialog::class.java.name)
} }

View File

@ -6,6 +6,7 @@ import android.util.Log
import android.widget.Toast import android.widget.Toast
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.constants.ShareObjectType
import com.github.libretube.databinding.DialogTextPreferenceBinding import com.github.libretube.databinding.DialogTextPreferenceBinding
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
@ -74,7 +75,7 @@ class PlaylistOptionsBottomSheet(
} }
// share the playlist // share the playlist
context?.getString(R.string.share) -> { context?.getString(R.string.share) -> {
val shareDialog = ShareDialog(playlistId, true) val shareDialog = ShareDialog(playlistId, ShareObjectType.PLAYLIST)
// using parentFragmentManager, childFragmentManager doesn't work here // using parentFragmentManager, childFragmentManager doesn't work here
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name) shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
} }

View File

@ -4,6 +4,7 @@ import android.os.Bundle
import android.widget.Toast import android.widget.Toast
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.constants.IntentData 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.AddToPlaylistDialog
import com.github.libretube.ui.dialogs.DownloadDialog import com.github.libretube.ui.dialogs.DownloadDialog
import com.github.libretube.ui.dialogs.ShareDialog import com.github.libretube.ui.dialogs.ShareDialog
@ -73,7 +74,7 @@ class VideoOptionsBottomSheet(
downloadDialog.show(parentFragmentManager, DownloadDialog::class.java.name) downloadDialog.show(parentFragmentManager, DownloadDialog::class.java.name)
} }
context?.getString(R.string.share) -> { context?.getString(R.string.share) -> {
val shareDialog = ShareDialog(videoId, false) val shareDialog = ShareDialog(videoId, ShareObjectType.VIDEO)
// using parentFragmentManager is important here // using parentFragmentManager is important here
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name) shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
} }

View File

@ -2,7 +2,6 @@ package com.github.libretube.util
import android.content.Context import android.content.Context
import android.os.Build import android.os.Build
import com.github.libretube.BuildConfig
import com.github.libretube.constants.DownloadType import com.github.libretube.constants.DownloadType
import com.github.libretube.obj.DownloadedFile import com.github.libretube.obj.DownloadedFile
import java.io.File import java.io.File

View File

@ -73,6 +73,20 @@
</LinearLayout> </LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/channel_share"
style="@style/Widget.Material3.Button.IconButton.Filled.Tonal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:drawableTint="?android:attr/textColorPrimary"
android:paddingHorizontal="15dp"
android:stateListAnimator="@null"
app:cornerRadius="20dp"
app:elevation="20dp"
app:icon="@drawable/ic_share"
tools:targetApi="m" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/channel_subscribe" android:id="@+id/channel_subscribe"
style="@style/Widget.Material3.Button.ElevatedButton" style="@style/Widget.Material3.Button.ElevatedButton"