mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Merge pull request #1529 from Bnyro/channelshare
Backup of sharing channels by @GilesMunn
This commit is contained in:
commit
abc86aabc4
@ -0,0 +1,7 @@
|
||||
package com.github.libretube.constants
|
||||
|
||||
object ShareObjectType {
|
||||
const val VIDEO = 0
|
||||
const val PLAYLIST = 1
|
||||
const val CHANNEL = 2
|
||||
}
|
@ -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
|
||||
@ -46,8 +47,9 @@ class ChannelAdapter(
|
||||
videoTitle.text = video.title
|
||||
|
||||
videoInfo.text =
|
||||
video.views.formatShort() + " • " +
|
||||
DateUtils.getRelativeTimeSpanString(video.uploaded!!)
|
||||
video.views.formatShort() + " " +
|
||||
root.context.getString(R.string.views_placeholder) +
|
||||
" • " + DateUtils.getRelativeTimeSpanString(video.uploaded!!)
|
||||
|
||||
thumbnailDuration.text =
|
||||
DateUtils.formatElapsedTime(video.duration!!)
|
||||
|
@ -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,7 +17,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class ShareDialog(
|
||||
private val id: String,
|
||||
private val isPlaylist: Boolean,
|
||||
private val shareObjectType: Int,
|
||||
private val position: Long? = null
|
||||
) : DialogFragment() {
|
||||
private var binding: DialogShareBinding? = null
|
||||
@ -50,7 +51,11 @@ class ShareDialog(
|
||||
// only available for custom instances
|
||||
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"
|
||||
|
||||
if (binding != null && binding!!.timeCodeSwitch.isChecked) {
|
||||
|
@ -11,12 +11,14 @@ 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
|
||||
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 +125,11 @@ class ChannelFragment : BaseFragment() {
|
||||
getString(R.string.unsubscribe)
|
||||
}
|
||||
}
|
||||
|
||||
binding.channelShare.setOnClickListener {
|
||||
val shareDialog = ShareDialog(response.name!!, ShareObjectType.CHANNEL)
|
||||
shareDialog.show(childFragmentManager, ShareDialog::class.java.name)
|
||||
}
|
||||
}
|
||||
|
||||
nextPage = response.nextpage
|
||||
|
@ -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, exoPlayer.currentPosition / 1000)
|
||||
val shareDialog = ShareDialog(videoId!!, ShareObjectType.VIDEO, exoPlayer.currentPosition / 1000)
|
||||
shareDialog.show(childFragmentManager, ShareDialog::class.java.name)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
val shareDialog = ShareDialog(playlistId, ShareObjectType.PLAYLIST)
|
||||
// using parentFragmentManager, childFragmentManager doesn't work here
|
||||
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
|
||||
}
|
||||
|
@ -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)
|
||||
val shareDialog = ShareDialog(videoId, ShareObjectType.VIDEO)
|
||||
// using parentFragmentManager is important here
|
||||
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -73,6 +73,20 @@
|
||||
|
||||
</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
|
||||
android:id="@+id/channel_subscribe"
|
||||
style="@style/Widget.Material3.Button.ElevatedButton"
|
||||
|
Loading…
Reference in New Issue
Block a user