mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
add a share button
This commit is contained in:
parent
0b99bfdfa0
commit
7bdcf9e3bd
@ -3,9 +3,8 @@ package com.github.libretube.extensions
|
||||
/**
|
||||
* format a Piped route to an ID
|
||||
*/
|
||||
fun Any.toID(): String {
|
||||
fun String.toID(): String {
|
||||
return this
|
||||
.toString()
|
||||
.replace("/watch?v=", "") // videos
|
||||
.replace("/channel/", "") // channels
|
||||
.replace("/playlist?list=", "") // playlists
|
||||
|
@ -1,7 +1,8 @@
|
||||
package com.github.libretube.obj
|
||||
|
||||
data class ShareData(
|
||||
val currentChannel: String ? = null,
|
||||
val currentVideo: String ? = null,
|
||||
val currentPlaylist: String ? = null
|
||||
val currentChannel: String? = null,
|
||||
val currentVideo: String? = null,
|
||||
val currentPlaylist: String? = null,
|
||||
var currentPosition: Long? = null
|
||||
)
|
||||
|
@ -9,6 +9,7 @@ import android.view.ViewGroup
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.api.obj.PlaylistId
|
||||
import com.github.libretube.databinding.PlaylistRowBinding
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.extensions.setFormattedDuration
|
||||
@ -86,7 +87,7 @@ class PlaylistAdapter(
|
||||
try {
|
||||
RetrofitInstance.authApi.removeFromPlaylist(
|
||||
PreferenceHelper.getToken(),
|
||||
com.github.libretube.api.obj.PlaylistId(
|
||||
PlaylistId(
|
||||
playlistId = playlistId,
|
||||
index = position
|
||||
)
|
||||
|
@ -20,8 +20,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
class ShareDialog(
|
||||
private val id: String,
|
||||
private val shareObjectType: ShareObjectType,
|
||||
private val shareData: ShareData,
|
||||
private val position: Long? = null
|
||||
private val shareData: ShareData
|
||||
) : DialogFragment() {
|
||||
private var binding: DialogShareBinding? = null
|
||||
|
||||
@ -35,7 +34,7 @@ class ShareDialog(
|
||||
// add instanceUrl option if custom instance frontend url available
|
||||
if (instanceUrl != "") shareOptions += getString(R.string.instance)
|
||||
|
||||
if (shareObjectType == ShareObjectType.VIDEO && position != null) {
|
||||
if (shareObjectType == ShareObjectType.VIDEO) {
|
||||
setupTimeStampBinding()
|
||||
}
|
||||
|
||||
@ -57,7 +56,7 @@ class ShareDialog(
|
||||
}
|
||||
var url = "$host$path"
|
||||
|
||||
if (shareObjectType == ShareObjectType.VIDEO && position != null && binding!!.timeCodeSwitch.isChecked) {
|
||||
if (shareObjectType == ShareObjectType.VIDEO && binding!!.timeCodeSwitch.isChecked) {
|
||||
url += "&t=${binding!!.timeStamp.text}"
|
||||
}
|
||||
|
||||
@ -85,7 +84,7 @@ class ShareDialog(
|
||||
binding!!.timeCodeSwitch.setOnCheckedChangeListener { _, isChecked ->
|
||||
binding!!.timeStampLayout.visibility = if (isChecked) View.VISIBLE else View.GONE
|
||||
}
|
||||
binding!!.timeStamp.setText(position.toString())
|
||||
binding!!.timeStamp.setText((shareData.currentPosition ?: 0L).toString())
|
||||
if (binding!!.timeCodeSwitch.isChecked) binding!!.timeStampLayout.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
|
@ -363,12 +363,12 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
|
||||
// share button
|
||||
binding.relPlayerShare.setOnClickListener {
|
||||
shareData.currentPosition = exoPlayer.currentPosition / 1000
|
||||
val shareDialog =
|
||||
ShareDialog(
|
||||
videoId!!,
|
||||
ShareObjectType.VIDEO,
|
||||
shareData,
|
||||
exoPlayer.currentPosition / 1000
|
||||
shareData
|
||||
)
|
||||
shareDialog.show(childFragmentManager, ShareDialog::class.java.name)
|
||||
}
|
||||
|
@ -14,10 +14,13 @@ import com.github.libretube.R
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.databinding.FragmentPlaylistBinding
|
||||
import com.github.libretube.enums.ShareObjectType
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.obj.ShareData
|
||||
import com.github.libretube.ui.adapters.PlaylistAdapter
|
||||
import com.github.libretube.ui.base.BaseFragment
|
||||
import com.github.libretube.ui.dialogs.ShareDialog
|
||||
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
|
||||
import com.github.libretube.util.ImageHelper
|
||||
import com.github.libretube.util.NavigationHelper
|
||||
@ -99,11 +102,19 @@ class PlaylistFragment : BaseFragment() {
|
||||
binding.playAll.setOnClickListener {
|
||||
NavigationHelper.navigateVideo(
|
||||
requireContext(),
|
||||
response.relatedStreams?.first()?.toID(),
|
||||
response.relatedStreams?.first()?.url?.toID(),
|
||||
playlistId
|
||||
)
|
||||
}
|
||||
|
||||
binding.share.setOnClickListener {
|
||||
ShareDialog(
|
||||
playlistId!!,
|
||||
ShareObjectType.PLAYLIST,
|
||||
ShareData(currentPlaylist = response.name)
|
||||
).show(childFragmentManager, null)
|
||||
}
|
||||
|
||||
playlistAdapter = PlaylistAdapter(
|
||||
response.relatedStreams.orEmpty().toMutableList(),
|
||||
playlistId!!,
|
||||
|
12
app/src/main/res/drawable/ic_share_outlined.xml
Normal file
12
app/src/main/res/drawable/ic_share_outlined.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M14,9L14,5l8,7 -8,7L14,15S2,14.069 2,19.737C2,8.4 14,9 14,9Z"
|
||||
android:strokeWidth="1.5"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#000"/>
|
||||
</vector>
|
@ -3,7 +3,8 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="25dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -33,7 +34,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="25dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="25dp"
|
||||
android:hint="@string/time_code"
|
||||
android:visibility="gone">
|
||||
|
||||
|
@ -85,14 +85,14 @@
|
||||
app:icon="@drawable/ic_playlist" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/shuffle"
|
||||
android:id="@+id/share"
|
||||
style="@style/Widget.Material3.Button"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/shuffle"
|
||||
app:icon="@drawable/ic_shuffle" />
|
||||
android:text="@string/share"
|
||||
app:icon="@drawable/ic_share_outlined" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -359,7 +359,6 @@
|
||||
<string name="confirm_unsubscribe">Are you sure you want to unsubscribe %1$s?</string>
|
||||
<string name="confirm_unsubscribing">Confirm unsubscribing</string>
|
||||
<string name="confirm_unsubscribing_summary">Show a confirmation dialog before unsubscribing.</string>
|
||||
<string name="shuffle">Shuffle</string>
|
||||
<string name="play_all">Play all</string>
|
||||
|
||||
<!-- Notification channel strings -->
|
||||
|
Loading…
x
Reference in New Issue
Block a user