fix subscriptions

This commit is contained in:
Bnyro 2022-08-06 11:55:17 +02:00
parent 61f1bf6fee
commit a975ba212f
2 changed files with 44 additions and 42 deletions

View File

@ -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)

View File

@ -22,7 +22,7 @@ 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)
@ -45,9 +45,6 @@ class ImportHelper(
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(",")
@ -57,10 +54,16 @@ class ImportHelper(
} }
} }
inputStream?.close() inputStream?.close()
}
} else {
throw IllegalArgumentException("unsupported type")
}
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
SubscriptionHelper.importSubscriptions(channels) SubscriptionHelper.importSubscriptions(channels)
} }
Toast.makeText(activity, R.string.importsuccess, Toast.LENGTH_SHORT).show()
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, e.toString()) Log.e(TAG, e.toString())
Toast.makeText( Toast.makeText(
@ -70,7 +73,6 @@ class ImportHelper(
).show() ).show()
} }
} }
}
private fun readTextFromUri(uri: Uri): String { private fun readTextFromUri(uri: Uri): String {
val stringBuilder = StringBuilder() val stringBuilder = StringBuilder()