mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Filter out null comments returned from Piped API. (#3061)
* Made improvement to player double-tap further. * Minor fixes. * fix ktlint * Filter out null comments returned from Piped API.
This commit is contained in:
parent
582ab70bd1
commit
6053eae99b
@ -0,0 +1,7 @@
|
||||
package com.github.libretube.ui.extensions
|
||||
|
||||
import com.github.libretube.api.obj.Comment
|
||||
|
||||
fun List<Comment>.filterNonEmptyComments(): List<Comment> {
|
||||
return filter { !it.commentText.isNullOrEmpty() }
|
||||
}
|
@ -17,6 +17,7 @@ import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.databinding.FragmentCommentsBinding
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.ui.adapters.CommentsAdapter
|
||||
import com.github.libretube.ui.extensions.filterNonEmptyComments
|
||||
import com.github.libretube.ui.models.CommentsViewModel
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -97,6 +98,7 @@ class CommentsRepliesFragment : Fragment() {
|
||||
Log.e(TAG(), "IOException, you might not have internet connection")
|
||||
return@launch
|
||||
}
|
||||
repliesPage.comments = repliesPage.comments.filterNonEmptyComments()
|
||||
withContext(Dispatchers.Main) {
|
||||
onFinished.invoke(repliesPage)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.api.obj.CommentsPage
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.ui.extensions.filterNonEmptyComments
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@ -33,6 +34,7 @@ class CommentsViewModel : ViewModel() {
|
||||
return@launch
|
||||
}
|
||||
nextPage = response.nextpage
|
||||
response.comments = response.comments.filterNonEmptyComments()
|
||||
commentsPage.postValue(response)
|
||||
isLoading = false
|
||||
}
|
||||
@ -49,7 +51,7 @@ class CommentsViewModel : ViewModel() {
|
||||
return@launch
|
||||
}
|
||||
val updatedPage = commentsPage.value?.apply {
|
||||
comments += response.comments
|
||||
comments += response.comments.filterNonEmptyComments()
|
||||
}
|
||||
nextPage = response.nextpage
|
||||
commentsPage.postValue(updatedPage)
|
||||
|
Loading…
x
Reference in New Issue
Block a user