mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-01-06 17:40:30 +05:30
fix subscriptions
This commit is contained in:
parent
61f1bf6fee
commit
a975ba212f
@ -15,8 +15,6 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscrip
|
|||||||
RecyclerView.Adapter<SubscriptionChannelViewHolder>() {
|
RecyclerView.Adapter<SubscriptionChannelViewHolder>() {
|
||||||
val TAG = "SubChannelAdapter"
|
val TAG = "SubChannelAdapter"
|
||||||
|
|
||||||
private var subscribed = true
|
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
override fun getItemCount(): Int {
|
||||||
return subscriptions.size
|
return subscriptions.size
|
||||||
}
|
}
|
||||||
@ -30,6 +28,8 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscrip
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: SubscriptionChannelViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: SubscriptionChannelViewHolder, position: Int) {
|
||||||
val subscription = subscriptions[position]
|
val subscription = subscriptions[position]
|
||||||
|
var subscribed = true
|
||||||
|
|
||||||
holder.binding.apply {
|
holder.binding.apply {
|
||||||
subscriptionChannelName.text = subscription.name
|
subscriptionChannelName.text = subscription.name
|
||||||
ConnectionHelper.loadImage(subscription.avatar, subscriptionChannelImage)
|
ConnectionHelper.loadImage(subscription.avatar, subscriptionChannelImage)
|
||||||
|
@ -22,53 +22,55 @@ class ImportHelper(
|
|||||||
private val TAG = "ImportHelper"
|
private val TAG = "ImportHelper"
|
||||||
|
|
||||||
fun importSubscriptions(uri: Uri?) {
|
fun importSubscriptions(uri: Uri?) {
|
||||||
if (uri != null) {
|
if (uri == null) return
|
||||||
try {
|
try {
|
||||||
val type = activity.contentResolver.getType(uri)
|
val type = activity.contentResolver.getType(uri)
|
||||||
|
|
||||||
var inputStream: InputStream? = activity.contentResolver.openInputStream(uri)
|
var inputStream: InputStream? = activity.contentResolver.openInputStream(uri)
|
||||||
var channels = ArrayList<String>()
|
var channels = ArrayList<String>()
|
||||||
if (type == "application/json") {
|
if (type == "application/json") {
|
||||||
val mapper = ObjectMapper()
|
val mapper = ObjectMapper()
|
||||||
val json = readTextFromUri(uri)
|
val json = readTextFromUri(uri)
|
||||||
val subscriptions = mapper.readValue(json, NewPipeSubscriptions::class.java)
|
val subscriptions = mapper.readValue(json, NewPipeSubscriptions::class.java)
|
||||||
channels = subscriptions.subscriptions?.map {
|
channels = subscriptions.subscriptions?.map {
|
||||||
it.url?.replace("https://www.youtube.com/channel/", "")!!
|
it.url?.replace("https://www.youtube.com/channel/", "")!!
|
||||||
} as ArrayList<String>
|
} as ArrayList<String>
|
||||||
} else if (type == "application/zip") {
|
} else if (type == "application/zip") {
|
||||||
val zis = ZipInputStream(inputStream)
|
val zis = ZipInputStream(inputStream)
|
||||||
var entry: ZipEntry? = zis.nextEntry
|
var entry: ZipEntry? = zis.nextEntry
|
||||||
|
|
||||||
while (entry != null) {
|
while (entry != null) {
|
||||||
if (entry.name.endsWith(".csv")) {
|
if (entry.name.endsWith(".csv")) {
|
||||||
inputStream = zis
|
inputStream = zis
|
||||||
break
|
break
|
||||||
}
|
|
||||||
entry = zis.nextEntry
|
|
||||||
}
|
}
|
||||||
}
|
entry = zis.nextEntry
|
||||||
|
inputStream?.bufferedReader()?.readLines()?.forEach {
|
||||||
inputStream?.bufferedReader()?.readLines()?.forEach {
|
if (it.isNotBlank()) {
|
||||||
if (it.isNotBlank()) {
|
val channelId = it.substringBefore(",")
|
||||||
val channelId = it.substringBefore(",")
|
if (channelId.length == 24) {
|
||||||
if (channelId.length == 24) {
|
channels.add(channelId)
|
||||||
channels.add(channelId)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
inputStream?.close()
|
||||||
}
|
}
|
||||||
inputStream?.close()
|
} else {
|
||||||
|
throw IllegalArgumentException("unsupported type")
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
|
||||||
SubscriptionHelper.importSubscriptions(channels)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e(TAG, e.toString())
|
|
||||||
Toast.makeText(
|
|
||||||
activity,
|
|
||||||
R.string.error,
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
SubscriptionHelper.importSubscriptions(channels)
|
||||||
|
}
|
||||||
|
|
||||||
|
Toast.makeText(activity, R.string.importsuccess, Toast.LENGTH_SHORT).show()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, e.toString())
|
||||||
|
Toast.makeText(
|
||||||
|
activity,
|
||||||
|
R.string.error,
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user