mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
custom instance frontend url
This commit is contained in:
parent
2673ff2e03
commit
4b0fdb9871
@ -2,7 +2,6 @@ package com.github.libretube.dialogs
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
@ -27,6 +26,8 @@ class CustomInstanceDialog : DialogFragment() {
|
||||
|
||||
val instanceNameEditText = view.findViewById<TextInputEditText>(R.id.instanceName)
|
||||
val instanceApiUrlEditText = view.findViewById<TextInputEditText>(R.id.instanceApiUrl)
|
||||
val instanceFrontendUrlEditText = view.findViewById<TextInputEditText>(R.id.instanceFrontendUrl)
|
||||
|
||||
val addInstanceButton = view.findViewById<Button>(R.id.addInstance)
|
||||
val cancelButton = view.findViewById<Button>(R.id.cancel)
|
||||
cancelButton.setOnClickListener {
|
||||
@ -36,12 +37,15 @@ class CustomInstanceDialog : DialogFragment() {
|
||||
addInstanceButton.setOnClickListener {
|
||||
val instanceName = instanceNameEditText.text.toString()
|
||||
val instanceApiUrl = instanceApiUrlEditText.text.toString()
|
||||
val instanceFrontendUrl = instanceFrontendUrlEditText.text.toString()
|
||||
|
||||
if (instanceName != "" && instanceApiUrl != "") {
|
||||
if (instanceName != "" && instanceApiUrl != "" && instanceFrontendUrl != "") {
|
||||
try {
|
||||
// check whether the URL is valid, otherwise catch
|
||||
val u = URL(instanceApiUrl).toURI()
|
||||
saveCustomInstance(instanceName, instanceApiUrl)
|
||||
URL(instanceApiUrl).toURI()
|
||||
URL(instanceFrontendUrl).toURI()
|
||||
|
||||
saveCustomInstance(instanceName, instanceApiUrl, instanceFrontendUrl)
|
||||
activity?.recreate()
|
||||
dismiss()
|
||||
} catch (e: Exception) {
|
||||
@ -72,7 +76,11 @@ class CustomInstanceDialog : DialogFragment() {
|
||||
} ?: throw IllegalStateException("Activity cannot be null")
|
||||
}
|
||||
|
||||
private fun saveCustomInstance(instanceName: String, instanceApiUrl: String) {
|
||||
private fun saveCustomInstance(
|
||||
instanceName: String,
|
||||
instanceApiUrl: String,
|
||||
instanceFrontendApiUrl: String
|
||||
) {
|
||||
val sharedPreferences = PreferenceManager
|
||||
.getDefaultSharedPreferences(requireContext())
|
||||
|
||||
@ -84,7 +92,7 @@ class CustomInstanceDialog : DialogFragment() {
|
||||
emptyList()
|
||||
}
|
||||
|
||||
// get the urls of the other custom instances
|
||||
// get the api urls of the other custom instances
|
||||
var customInstancesUrls = try {
|
||||
sharedPreferences
|
||||
.getStringSet("custom_instances_url", HashSet())!!.toList()
|
||||
@ -92,15 +100,24 @@ class CustomInstanceDialog : DialogFragment() {
|
||||
emptyList()
|
||||
}
|
||||
|
||||
// get the frontend urls of the other custom instances
|
||||
var customInstancesFrontendUrls = try {
|
||||
sharedPreferences
|
||||
.getStringSet("custom_instances_url", HashSet())!!.toList()
|
||||
} catch (e: Exception) {
|
||||
emptyList()
|
||||
}
|
||||
|
||||
// append new instance to the list
|
||||
customInstancesNames += instanceName
|
||||
customInstancesUrls += instanceApiUrl
|
||||
Log.e(TAG, customInstancesNames.toString())
|
||||
customInstancesFrontendUrls += instanceFrontendApiUrl
|
||||
|
||||
// save them to the shared preferences
|
||||
sharedPreferences.edit()
|
||||
.putStringSet("custom_instances_name", HashSet(customInstancesNames))
|
||||
.putStringSet("custom_instances_url", HashSet(customInstancesUrls))
|
||||
.putStringSet("custom_instances_frontend_url", HashSet(customInstancesFrontendUrls))
|
||||
.apply()
|
||||
}
|
||||
}
|
||||
|
@ -7,24 +7,20 @@ import androidx.fragment.app.DialogFragment
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.github.libretube.R
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import java.net.URLEncoder
|
||||
|
||||
class ShareDialog(private val videoId: String) : DialogFragment() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return activity?.let {
|
||||
val sharedPreferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
val instancePref = sharedPreferences.getString(
|
||||
"selectInstance",
|
||||
"https://pipedapi.kavin.rocks"
|
||||
)!!
|
||||
val instance = "&instance=${URLEncoder.encode(instancePref, "UTF-8")}"
|
||||
val shareOptions = arrayOf(
|
||||
context?.getString(R.string.piped),
|
||||
context?.getString(R.string.instance),
|
||||
context?.getString(R.string.youtube)
|
||||
var shareOptions = arrayOf(
|
||||
getString(R.string.piped),
|
||||
getString(R.string.youtube)
|
||||
)
|
||||
val instanceUrl = getCustomInstanceFrontendUrl()
|
||||
|
||||
// add instanceUrl option if custom instance frontend url available
|
||||
if (instanceUrl != "") shareOptions += getString(R.string.instance)
|
||||
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(context?.getString(R.string.share))
|
||||
.setItems(
|
||||
@ -32,8 +28,8 @@ class ShareDialog(private val videoId: String) : DialogFragment() {
|
||||
) { _, 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"
|
||||
1 -> "https://youtu.be/$videoId"
|
||||
2 -> "$instanceUrl/watch?v=$videoId" // only available for custom instances
|
||||
else -> "https://piped.kavin.rocks/watch?v=$videoId"
|
||||
}
|
||||
val intent = Intent()
|
||||
@ -47,4 +43,38 @@ class ShareDialog(private val videoId: String) : DialogFragment() {
|
||||
.show()
|
||||
} ?: throw IllegalStateException("Activity cannot be null")
|
||||
}
|
||||
|
||||
// get the frontend url if it's a custom instance
|
||||
private fun getCustomInstanceFrontendUrl(): String {
|
||||
val sharedPreferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
val instancePref = sharedPreferences.getString(
|
||||
"selectInstance",
|
||||
"https://pipedapi.kavin.rocks"
|
||||
)
|
||||
|
||||
// get the api urls of the other custom instances
|
||||
var customInstancesUrls = try {
|
||||
sharedPreferences
|
||||
.getStringSet("custom_instances_url", HashSet())!!.toList()
|
||||
} catch (e: Exception) {
|
||||
emptyList()
|
||||
}
|
||||
|
||||
// get the frontend urls of the other custom instances
|
||||
var customInstancesFrontendUrls = try {
|
||||
sharedPreferences
|
||||
.getStringSet("custom_instances_url", HashSet())!!.toList()
|
||||
} catch (e: Exception) {
|
||||
emptyList()
|
||||
}
|
||||
|
||||
// return the custom instance frontend url if available
|
||||
return if (customInstancesUrls.contains(instancePref)) {
|
||||
val index = customInstancesUrls.indexOf(instancePref)
|
||||
return customInstancesFrontendUrls[index]
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import com.github.libretube.R
|
||||
import com.github.libretube.adapters.PlaylistsAdapter
|
||||
import com.github.libretube.dialogs.CreatePlaylistDialog
|
||||
import com.github.libretube.util.RetrofitInstance
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import java.io.IOException
|
||||
import retrofit2.HttpException
|
||||
|
||||
@ -68,16 +69,7 @@ class Library : Fragment() {
|
||||
}
|
||||
} else {
|
||||
refreshLayout.isEnabled = false
|
||||
view.findViewById<com.google.android.material.floatingactionbutton
|
||||
.FloatingActionButton>(R.id.create_playlist).visibility = View.GONE
|
||||
with(view.findViewById<ImageView>(R.id.boogh2)) {
|
||||
visibility = View.VISIBLE
|
||||
setImageResource(R.drawable.ic_login)
|
||||
}
|
||||
with(view.findViewById<TextView>(R.id.textLike2)) {
|
||||
visibility = View.VISIBLE
|
||||
text = getString(R.string.please_login)
|
||||
}
|
||||
view.findViewById<FloatingActionButton>(R.id.create_playlist).visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,10 @@
|
||||
android:viewportHeight="24"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M10,11H4V3a1,1 0,0 1,1 -1h14a1,1 0,0 1,1 1v18a1,1 0,0 1,-1 1H5a1,1 0,0 1,-1 -1v-8h6v3l5,-4 -5,-4v3z"/>
|
||||
android:pathData="M9,3h8a2,2 0,0 1,2 2v14a2,2 0,0 1,-2 2H9m6,-9 l-4,-4m4,4 l-4,4m4,-4H5"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="@android:color/black"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
||||
|
10
app/src/main/res/drawable/ic_login_filled.xml
Normal file
10
app/src/main/res/drawable/ic_login_filled.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M10,11H4V3a1,1 0,0 1,1 -1h14a1,1 0,0 1,1 1v18a1,1 0,0 1,-1 1H5a1,1 0,0 1,-1 -1v-8h6v3l5,-4 -5,-4v3z"/>
|
||||
</vector>
|
@ -39,6 +39,30 @@
|
||||
android:padding="12dp" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:hintEnabled="false"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
|
||||
app:boxCornerRadiusBottomStart="15dp"
|
||||
app:boxCornerRadiusBottomEnd="15dp"
|
||||
app:boxCornerRadiusTopEnd="15dp"
|
||||
app:boxCornerRadiusTopStart="15dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/instanceFrontendUrl"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/instance_frontend_url"
|
||||
android:inputType="text"
|
||||
android:padding="12dp" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||
android:layout_width="match_parent"
|
||||
@ -52,9 +76,7 @@
|
||||
app:boxCornerRadiusBottomStart="15dp"
|
||||
app:boxCornerRadiusBottomEnd="15dp"
|
||||
app:boxCornerRadiusTopEnd="15dp"
|
||||
app:boxCornerRadiusTopStart="15dp"
|
||||
|
||||
>
|
||||
app:boxCornerRadiusTopStart="15dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/instanceApiUrl"
|
||||
|
@ -191,4 +191,5 @@
|
||||
<string name="downloading">Downloading</string>
|
||||
<string name="player_autoplay">Autoplay</string>
|
||||
<string name="hideTrendingPage">Hide trending page</string>
|
||||
<string name="instance_frontend_url">URL to instance frontend</string>
|
||||
</resources>
|
||||
|
@ -24,7 +24,7 @@
|
||||
android:icon="@drawable/ic_trash" />
|
||||
|
||||
<Preference
|
||||
android:icon="@drawable/ic_login"
|
||||
android:icon="@drawable/ic_login_filled"
|
||||
android:summary="@string/notgmail"
|
||||
app:key="login_register"
|
||||
app:title="@string/login_register" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user