mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
commit
9f7c90bdac
2
app/proguard-rules.pro
vendored
2
app/proguard-rules.pro
vendored
@ -24,4 +24,4 @@
|
|||||||
-keep class com.github.libretube.obj.** { *; }
|
-keep class com.github.libretube.obj.** { *; }
|
||||||
|
|
||||||
# prevents android from removing it
|
# prevents android from removing it
|
||||||
-keep class com.github.libretube.update.** { <fields>; }
|
-keep class com.github.libretube.update.** { *; }
|
||||||
|
@ -25,13 +25,25 @@ import com.github.libretube.util.RetrofitInstance
|
|||||||
|
|
||||||
class InstanceSettings : PreferenceFragmentCompat() {
|
class InstanceSettings : PreferenceFragmentCompat() {
|
||||||
val TAG = "InstanceSettings"
|
val TAG = "InstanceSettings"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* result listeners for importing and exporting subscriptions
|
||||||
|
*/
|
||||||
private lateinit var getContent: ActivityResultLauncher<String>
|
private lateinit var getContent: ActivityResultLauncher<String>
|
||||||
|
private lateinit var createFile: ActivityResultLauncher<String>
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
getContent =
|
getContent =
|
||||||
registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? ->
|
registerForActivityResult(
|
||||||
ImportHelper(requireActivity() as AppCompatActivity).importSubscriptions(uri)
|
ActivityResultContracts.GetContent()
|
||||||
|
) { uri: Uri? ->
|
||||||
|
ImportHelper(requireActivity()).importSubscriptions(uri)
|
||||||
}
|
}
|
||||||
|
createFile = registerForActivityResult(
|
||||||
|
ActivityResultContracts.CreateDocument()
|
||||||
|
) { uri: Uri? ->
|
||||||
|
ImportHelper(requireActivity()).exportSubscriptions(uri)
|
||||||
|
}
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
}
|
}
|
||||||
@ -126,8 +138,8 @@ class InstanceSettings : PreferenceFragmentCompat() {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
val importFromYt = findPreference<Preference>(PreferenceKeys.IMPORT_SUBS)
|
val importSubscriptions = findPreference<Preference>(PreferenceKeys.IMPORT_SUBS)
|
||||||
importFromYt?.setOnPreferenceClickListener {
|
importSubscriptions?.setOnPreferenceClickListener {
|
||||||
// check StorageAccess
|
// check StorageAccess
|
||||||
val accessGranted =
|
val accessGranted =
|
||||||
PermissionHelper.isStoragePermissionGranted(activity as AppCompatActivity)
|
PermissionHelper.isStoragePermissionGranted(activity as AppCompatActivity)
|
||||||
@ -137,6 +149,12 @@ class InstanceSettings : PreferenceFragmentCompat() {
|
|||||||
else PermissionHelper.requestReadWrite(activity as AppCompatActivity)
|
else PermissionHelper.requestReadWrite(activity as AppCompatActivity)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val exportSubscriptions = findPreference<Preference>(PreferenceKeys.EXPORT_SUBS)
|
||||||
|
exportSubscriptions?.setOnPreferenceClickListener {
|
||||||
|
createFile.launch("subscriptions.json")
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initCustomInstances(instancePref: ListPreference) {
|
private fun initCustomInstances(instancePref: ListPreference) {
|
||||||
|
@ -34,6 +34,7 @@ object PreferenceKeys {
|
|||||||
const val LOGIN_REGISTER = "login_register"
|
const val LOGIN_REGISTER = "login_register"
|
||||||
const val DELETE_ACCOUNT = "delete_account"
|
const val DELETE_ACCOUNT = "delete_account"
|
||||||
const val IMPORT_SUBS = "import_from_yt"
|
const val IMPORT_SUBS = "import_from_yt"
|
||||||
|
const val EXPORT_SUBS = "export_subs"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Player
|
* Player
|
||||||
|
@ -1,23 +1,27 @@
|
|||||||
package com.github.libretube.util
|
package com.github.libretube.util
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
|
import com.github.libretube.obj.NewPipeSubscription
|
||||||
import com.github.libretube.obj.NewPipeSubscriptions
|
import com.github.libretube.obj.NewPipeSubscriptions
|
||||||
|
import com.github.libretube.preferences.PreferenceHelper
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
|
import java.io.FileOutputStream
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipInputStream
|
import java.util.zip.ZipInputStream
|
||||||
|
|
||||||
class ImportHelper(
|
class ImportHelper(
|
||||||
private val activity: AppCompatActivity
|
private val activity: Activity
|
||||||
) {
|
) {
|
||||||
private val TAG = "ImportHelper"
|
private val TAG = "ImportHelper"
|
||||||
|
|
||||||
@ -87,4 +91,43 @@ class ImportHelper(
|
|||||||
}
|
}
|
||||||
return stringBuilder.toString()
|
return stringBuilder.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* write the text to the document
|
||||||
|
*/
|
||||||
|
fun exportSubscriptions(uri: Uri?) {
|
||||||
|
if (uri == null) return
|
||||||
|
try {
|
||||||
|
val mapper = ObjectMapper()
|
||||||
|
val token = PreferenceHelper.getToken()
|
||||||
|
runBlocking {
|
||||||
|
val subs = if (token != "") RetrofitInstance.authApi.subscriptions(token)
|
||||||
|
else RetrofitInstance.authApi.unauthenticatedSubscriptions(
|
||||||
|
SubscriptionHelper.getFormattedLocalSubscriptions()
|
||||||
|
)
|
||||||
|
val newPipeChannels = mutableListOf<NewPipeSubscription>()
|
||||||
|
subs.forEach {
|
||||||
|
newPipeChannels += NewPipeSubscription(
|
||||||
|
name = it.name,
|
||||||
|
service_id = 0,
|
||||||
|
url = "https://www.youtube.com" + it.url
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val newPipeSubscriptions = NewPipeSubscriptions(
|
||||||
|
subscriptions = newPipeChannels
|
||||||
|
)
|
||||||
|
|
||||||
|
val data = mapper.writeValueAsBytes(newPipeSubscriptions)
|
||||||
|
|
||||||
|
activity.contentResolver.openFileDescriptor(uri, "w")?.use {
|
||||||
|
FileOutputStream(it.fileDescriptor).use { fileOutputStream ->
|
||||||
|
fileOutputStream.write(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,10 @@ object NotificationHelper {
|
|||||||
val token = PreferenceHelper.getToken()
|
val token = PreferenceHelper.getToken()
|
||||||
runBlocking {
|
runBlocking {
|
||||||
val task = async {
|
val task = async {
|
||||||
RetrofitInstance.authApi.getFeed(token)
|
if (token != "") RetrofitInstance.authApi.getFeed(token)
|
||||||
|
else RetrofitInstance.authApi.getUnauthenticatedFeed(
|
||||||
|
SubscriptionHelper.getFormattedLocalSubscriptions()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
// fetch the users feed
|
// fetch the users feed
|
||||||
val videoFeed = try {
|
val videoFeed = try {
|
||||||
|
@ -291,4 +291,5 @@
|
|||||||
<string name="copied">Copied</string>
|
<string name="copied">Copied</string>
|
||||||
<string name="downloadsucceeded">Downloaded</string>
|
<string name="downloadsucceeded">Downloaded</string>
|
||||||
<string name="share_with_time">Share with start time</string>
|
<string name="share_with_time">Share with start time</string>
|
||||||
|
<string name="export_subscriptions">Export Subscriptions</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -59,11 +59,16 @@
|
|||||||
<PreferenceCategory app:title="@string/restore">
|
<PreferenceCategory app:title="@string/restore">
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:icon="@drawable/ic_upload"
|
android:icon="@drawable/ic_download_filled"
|
||||||
android:summary="@string/import_from_yt_summary"
|
android:summary="@string/import_from_yt_summary"
|
||||||
app:key="import_from_yt"
|
app:key="import_from_yt"
|
||||||
app:title="@string/import_from_yt" />
|
app:title="@string/import_from_yt" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:icon="@drawable/ic_upload"
|
||||||
|
app:key="export_subs"
|
||||||
|
app:title="@string/export_subscriptions" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user