mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20: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>() {
|
||||
val TAG = "SubChannelAdapter"
|
||||
|
||||
private var subscribed = true
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return subscriptions.size
|
||||
}
|
||||
@ -30,6 +28,8 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscrip
|
||||
|
||||
override fun onBindViewHolder(holder: SubscriptionChannelViewHolder, position: Int) {
|
||||
val subscription = subscriptions[position]
|
||||
var subscribed = true
|
||||
|
||||
holder.binding.apply {
|
||||
subscriptionChannelName.text = subscription.name
|
||||
ConnectionHelper.loadImage(subscription.avatar, subscriptionChannelImage)
|
||||
|
@ -22,53 +22,55 @@ class ImportHelper(
|
||||
private val TAG = "ImportHelper"
|
||||
|
||||
fun importSubscriptions(uri: Uri?) {
|
||||
if (uri != null) {
|
||||
try {
|
||||
val type = activity.contentResolver.getType(uri)
|
||||
if (uri == null) return
|
||||
try {
|
||||
val type = activity.contentResolver.getType(uri)
|
||||
|
||||
var inputStream: InputStream? = activity.contentResolver.openInputStream(uri)
|
||||
var channels = ArrayList<String>()
|
||||
if (type == "application/json") {
|
||||
val mapper = ObjectMapper()
|
||||
val json = readTextFromUri(uri)
|
||||
val subscriptions = mapper.readValue(json, NewPipeSubscriptions::class.java)
|
||||
channels = subscriptions.subscriptions?.map {
|
||||
it.url?.replace("https://www.youtube.com/channel/", "")!!
|
||||
} as ArrayList<String>
|
||||
} else if (type == "application/zip") {
|
||||
val zis = ZipInputStream(inputStream)
|
||||
var entry: ZipEntry? = zis.nextEntry
|
||||
var inputStream: InputStream? = activity.contentResolver.openInputStream(uri)
|
||||
var channels = ArrayList<String>()
|
||||
if (type == "application/json") {
|
||||
val mapper = ObjectMapper()
|
||||
val json = readTextFromUri(uri)
|
||||
val subscriptions = mapper.readValue(json, NewPipeSubscriptions::class.java)
|
||||
channels = subscriptions.subscriptions?.map {
|
||||
it.url?.replace("https://www.youtube.com/channel/", "")!!
|
||||
} as ArrayList<String>
|
||||
} else if (type == "application/zip") {
|
||||
val zis = ZipInputStream(inputStream)
|
||||
var entry: ZipEntry? = zis.nextEntry
|
||||
|
||||
while (entry != null) {
|
||||
if (entry.name.endsWith(".csv")) {
|
||||
inputStream = zis
|
||||
break
|
||||
}
|
||||
entry = zis.nextEntry
|
||||
while (entry != null) {
|
||||
if (entry.name.endsWith(".csv")) {
|
||||
inputStream = zis
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
inputStream?.bufferedReader()?.readLines()?.forEach {
|
||||
if (it.isNotBlank()) {
|
||||
val channelId = it.substringBefore(",")
|
||||
if (channelId.length == 24) {
|
||||
channels.add(channelId)
|
||||
entry = zis.nextEntry
|
||||
inputStream?.bufferedReader()?.readLines()?.forEach {
|
||||
if (it.isNotBlank()) {
|
||||
val channelId = it.substringBefore(",")
|
||||
if (channelId.length == 24) {
|
||||
channels.add(channelId)
|
||||
}
|
||||
}
|
||||
}
|
||||
inputStream?.close()
|
||||
}
|
||||
inputStream?.close()
|
||||
|
||||
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()
|
||||
} else {
|
||||
throw IllegalArgumentException("unsupported type")
|
||||
}
|
||||
|
||||
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