functionality

This commit is contained in:
Bnyro 2022-06-20 21:47:35 +02:00
parent bf232e71cd
commit 9f8b314013
7 changed files with 44 additions and 19 deletions

View File

@ -23,7 +23,6 @@ import com.squareup.picasso.Picasso
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import java.io.IOException
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import retrofit2.HttpException

View File

@ -51,7 +51,7 @@ class PlaylistOptionsDialog(
}
// share the playlist
1 -> {
val shareDialog = ShareDialog(playlistId)
val shareDialog = ShareDialog(playlistId, true)
// using parentFragmentManager is important here
shareDialog.show(parentFragmentManager, "ShareDialog")
}

View File

@ -3,12 +3,17 @@ package com.github.libretube.dialogs
import android.app.Dialog
import android.content.Intent
import android.os.Bundle
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.fragment.app.DialogFragment
import androidx.preference.PreferenceManager
import com.github.libretube.R
import com.github.libretube.util.RetrofitInstance.url
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class ShareDialog(private val videoId: String) : DialogFragment() {
class ShareDialog(
private val id: String,
private val isPlaylist: Boolean
) : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return activity?.let {
@ -25,17 +30,22 @@ class ShareDialog(private val videoId: String) : DialogFragment() {
.setTitle(context?.getString(R.string.share))
.setItems(
shareOptions
) { _, id ->
val url = when (id) {
0 -> "https://piped.kavin.rocks/watch?v=$videoId"
1 -> "https://youtu.be/$videoId"
2 -> "$instanceUrl/watch?v=$videoId" // only available for custom instances
else -> "https://piped.kavin.rocks/watch?v=$videoId"
) { _, which ->
val host = when (which) {
0 -> "https://piped.kavin.rocks"
1 -> "https://youtube.com"
// only available for custom instances
else -> instanceUrl
}
val path = if (!isPlaylist) "/watch?v=$id" else "/playlist?list=$id"
val url = "$host$path"
val intent = Intent()
intent.action = Intent.ACTION_SEND
intent.putExtra(Intent.EXTRA_TEXT, url)
intent.type = "text/plain"
intent.apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, url)
type = "text/plain"
}
context?.startActivity(
Intent.createChooser(intent, context?.getString(R.string.shareTo))
)

View File

@ -66,7 +66,7 @@ class VideoOptionsDialog(private val videoId: String, context: Context) : Dialog
}
}
2 -> {
val shareDialog = ShareDialog(videoId)
val shareDialog = ShareDialog(videoId, false)
// using parentFragmentManager is important here
shareDialog.show(parentFragmentManager, "ShareDialog")
}

View File

@ -564,7 +564,7 @@ class PlayerFragment : Fragment() {
// share button
view.findViewById<LinearLayout>(R.id.relPlayer_share).setOnClickListener {
val shareDialog = ShareDialog(videoId!!)
val shareDialog = ShareDialog(videoId!!, false)
shareDialog.show(childFragmentManager, "ShareDialog")
}
// check if livestream

View File

@ -6,6 +6,7 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ProgressBar
import android.widget.ScrollView
import android.widget.TextView
import androidx.fragment.app.Fragment
@ -45,10 +46,11 @@ class PlaylistFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
playlistId = playlistId!!.replace("/playlist?list=", "")
view.findViewById<TextView>(R.id.playlist_name).text = playlistId
val recyclerView = view.findViewById<RecyclerView>(R.id.playlist_recView)
recyclerView.layoutManager = LinearLayoutManager(context)
val progressBar = view.findViewById<ProgressBar>(R.id.playlist_progress)
progressBar.visibility = View.VISIBLE
fetchPlaylist(view)
}
@ -68,6 +70,7 @@ class PlaylistFragment : Fragment() {
nextPage = response.nextpage
isLoading = false
runOnUiThread {
view.findViewById<ProgressBar>(R.id.playlist_progress).visibility = View.GONE
view.findViewById<TextView>(R.id.playlist_name).text = response.name
view.findViewById<TextView>(R.id.playlist_uploader).text = response.uploader
view.findViewById<TextView>(R.id.playlist_totVideos).text =

View File

@ -1,10 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.PlaylistFragment"
android:id="@+id/playlist_scrollview">
tools:context=".fragments.PlaylistFragment">
<ProgressBar
android:id="@+id/playlist_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/playlist_scrollview">
<LinearLayout
android:orientation="vertical"
@ -47,5 +59,6 @@
</LinearLayout>
</ScrollView>
</ScrollView>
</RelativeLayout>