Added share button for channels. Closes #1510

This commit is contained in:
GilesMunn 2022-10-09 14:34:39 +01:00
parent cf64fa281d
commit 22c7ebcc9c
6 changed files with 36 additions and 4 deletions

View File

@ -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) {

View File

@ -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

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -73,6 +73,22 @@
</LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/channel_share"
style="@style/Widget.Material3.Button.ElevatedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTint="?android:attr/textColorPrimary"
android:stateListAnimator="@null"
android:layout_marginEnd="10dp"
app:icon="@drawable/ic_share"
android:text="@string/share"
android:textColor="?android:attr/textColorPrimary"
android:textSize="12sp"
app:cornerRadius="20dp"
app:elevation="20dp"
tools:targetApi="m" />
<com.google.android.material.button.MaterialButton
android:id="@+id/channel_subscribe"
style="@style/Widget.Material3.Button.ElevatedButton"
@ -80,6 +96,7 @@
android:layout_height="wrap_content"
android:drawableTint="?android:attr/textColorPrimary"
android:stateListAnimator="@null"
app:icon="@drawable/ic_add"
android:text="@string/subscribe"
android:textColor="?android:attr/textColorPrimary"
android:textSize="12sp"