mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
Add a Clone Playlist action to the create playlist dialog
This commit is contained in:
parent
3434974efc
commit
5cdf670b15
@ -8,6 +8,7 @@ import androidx.lifecycle.lifecycleScope
|
|||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.api.PlaylistsHelper
|
import com.github.libretube.api.PlaylistsHelper
|
||||||
import com.github.libretube.databinding.DialogCreatePlaylistBinding
|
import com.github.libretube.databinding.DialogCreatePlaylistBinding
|
||||||
|
import com.github.libretube.util.TextUtils
|
||||||
import com.github.libretube.util.ThemeHelper
|
import com.github.libretube.util.ThemeHelper
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
|
||||||
@ -21,6 +22,15 @@ class CreatePlaylistDialog(
|
|||||||
|
|
||||||
binding.title.text = ThemeHelper.getStyledAppName(requireContext())
|
binding.title.text = ThemeHelper.getStyledAppName(requireContext())
|
||||||
|
|
||||||
|
binding.clonePlaylist.setOnClickListener {
|
||||||
|
val playlistUrl = binding.playlistUrl.text.toString()
|
||||||
|
if (!TextUtils.validateUrl(playlistUrl)) {
|
||||||
|
Toast.makeText(context, R.string.invalid_url, Toast.LENGTH_SHORT).show()
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
PlaylistsHelper.clonePlaylist(requireContext().applicationContext, playlistUrl)
|
||||||
|
}
|
||||||
|
|
||||||
binding.cancelButton.setOnClickListener {
|
binding.cancelButton.setOnClickListener {
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.github.libretube.util
|
package com.github.libretube.util
|
||||||
|
|
||||||
|
import java.net.URL
|
||||||
|
|
||||||
object TextUtils {
|
object TextUtils {
|
||||||
/**
|
/**
|
||||||
* Separator used for descriptions
|
* Separator used for descriptions
|
||||||
@ -14,4 +16,17 @@ object TextUtils {
|
|||||||
fun toTwoDecimalsString(num: Int): String {
|
fun toTwoDecimalsString(num: Int): String {
|
||||||
return if (num >= 10) num.toString() else "0$num"
|
return if (num >= 10) num.toString() else "0$num"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether an Url is valid
|
||||||
|
* @param url The url to test
|
||||||
|
* @return Whether the URL is valid
|
||||||
|
*/
|
||||||
|
fun validateUrl(url: String): Boolean {
|
||||||
|
runCatching {
|
||||||
|
URL(url).toURI()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
10
app/src/main/res/drawable/ic_copy.xml
Normal file
10
app/src/main/res/drawable/ic_copy.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<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:fillColor="@android:color/white"
|
||||||
|
android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z" />
|
||||||
|
</vector>
|
@ -4,7 +4,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -14,6 +13,27 @@
|
|||||||
android:text="@string/app_name"
|
android:text="@string/app_name"
|
||||||
android:textSize="20sp" />
|
android:textSize="20sp" />
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
style="@style/CustomDialogTextInputLayout"
|
||||||
|
android:hint="@string/playlistUrl">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/playlist_url"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="text" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/clone_playlist"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="end"
|
||||||
|
android:layout_marginEnd="20dp"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:drawableStart="@drawable/ic_copy"
|
||||||
|
android:text="@string/clonePlaylist" />
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
style="@style/CustomDialogTextInputLayout"
|
style="@style/CustomDialogTextInputLayout"
|
||||||
android:hint="@string/playlistName">
|
android:hint="@string/playlistName">
|
||||||
@ -25,7 +45,6 @@
|
|||||||
android:inputType="text" />
|
android:inputType="text" />
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
<string name="playlistCreated">Playlist created.</string>
|
<string name="playlistCreated">Playlist created.</string>
|
||||||
<string name="playlistName">Playlist name</string>
|
<string name="playlistName">Playlist name</string>
|
||||||
<string name="emptyPlaylistName">The playlist name can\'t be empty</string>
|
<string name="emptyPlaylistName">The playlist name can\'t be empty</string>
|
||||||
<string name="addToPlaylist">Add to playlist</string>
|
<string name="addToPlaylist">Add</string>
|
||||||
<string name="success">Done.</string>
|
<string name="success">Done.</string>
|
||||||
<string name="fail">Failed :(</string>
|
<string name="fail">Failed :(</string>
|
||||||
<string name="about">About</string>
|
<string name="about">About</string>
|
||||||
@ -420,6 +420,7 @@
|
|||||||
<string name="failed_fetching_instances">Failed to fetch available instances.</string>
|
<string name="failed_fetching_instances">Failed to fetch available instances.</string>
|
||||||
<string name="hide_watched_from_feed">Hide watched videos from feed</string>
|
<string name="hide_watched_from_feed">Hide watched videos from feed</string>
|
||||||
<string name="hide_watched_from_feed_summary">Don\'t show videos being watched more than 90% in the subscriptions tab.</string>
|
<string name="hide_watched_from_feed_summary">Don\'t show videos being watched more than 90% in the subscriptions tab.</string>
|
||||||
|
<string name="playlistUrl">Playlist URL</string>
|
||||||
|
|
||||||
<!-- Notification channel strings -->
|
<!-- Notification channel strings -->
|
||||||
<string name="download_channel_name">Download Service</string>
|
<string name="download_channel_name">Download Service</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user