From 16cccc0a5d31302d4e256f428f09889d8df2a6ee Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 30 May 2022 17:41:16 +0200 Subject: [PATCH] share in videooptionsdialog --- .../github/libretube/VideoOptionsDialog.kt | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/VideoOptionsDialog.kt b/app/src/main/java/com/github/libretube/VideoOptionsDialog.kt index da8fe5fd2..4422dcb82 100644 --- a/app/src/main/java/com/github/libretube/VideoOptionsDialog.kt +++ b/app/src/main/java/com/github/libretube/VideoOptionsDialog.kt @@ -2,12 +2,14 @@ package com.github.libretube import android.app.Dialog import android.content.Context +import android.content.Intent import android.os.Bundle import android.widget.ArrayAdapter import android.widget.Toast import androidx.fragment.app.DialogFragment import androidx.preference.PreferenceManager import com.google.android.material.dialog.MaterialAlertDialogBuilder +import java.net.URLEncoder /** * Dialog with different options for a selected video. @@ -20,7 +22,8 @@ class VideoOptionsDialog(private val videoId: String, context: Context) : Dialog */ private val list = listOf( context.getString(R.string.playOnBackground), - context.getString(R.string.addToPlaylist) + context.getString(R.string.addToPlaylist), + context.getString(R.string.share) ) /** @@ -61,6 +64,47 @@ class VideoOptionsDialog(private val videoId: String, context: Context) : Dialog Toast.makeText(context, R.string.login_first, Toast.LENGTH_SHORT).show() } } + 2 -> { + val sharedPreferences = + PreferenceManager.getDefaultSharedPreferences(requireContext()) + val instancePref = sharedPreferences.getString( + "instance", + "https://pipedapi.kavin.rocks" + )!! + val instance = "&instance=${URLEncoder.encode(instancePref, "UTF-8")}" + val shareOptions = arrayOf( + getString(R.string.piped), + getString(R.string.instance), + getString(R.string.youtube) + ) + /* + // crashes + MaterialAlertDialogBuilder(requireContext()) + .setTitle(getString(R.string.share)) + .setItems( + shareOptions + ) { _, id -> + val url = when (id) { + 0 -> "https://piped.kavin.rocks/watch?v=$videoId" + 1 -> "https://piped.kavin.rocks/watch?v=$videoId$instance" + 2 -> "https://youtu.be/$videoId" + else -> "https://piped.kavin.rocks/watch?v=$videoId" + } + dismiss() + val intent = Intent() + intent.action = Intent.ACTION_SEND + intent.putExtra(Intent.EXTRA_TEXT, url) + intent.type = "text/plain" + startActivity(Intent.createChooser(intent, "Share Url To:")) + } + .show() + */ + val intent = Intent() + intent.action = Intent.ACTION_SEND + intent.putExtra(Intent.EXTRA_TEXT, "https://piped.kavin.rocks/watch?v=$videoId") + intent.type = "text/plain" + startActivity(Intent.createChooser(intent, "Share Url To:")) + } else -> { dialog.dismiss() }