mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Use takeWhile() extension.
This commit is contained in:
parent
c5e21b5f18
commit
99f031f155
@ -1,15 +0,0 @@
|
|||||||
package com.github.libretube.extensions
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a list of all items until the given condition is fulfilled
|
|
||||||
* @param predicate The condition which needs to be searched for
|
|
||||||
* @return a list of all items before the first true condition
|
|
||||||
*/
|
|
||||||
fun <T> List<T>.filterUntil(predicate: (T) -> Boolean): List<T>? {
|
|
||||||
val items = mutableListOf<T>()
|
|
||||||
this.forEach {
|
|
||||||
if (predicate(it)) return items
|
|
||||||
items.add(it)
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
@ -18,7 +18,6 @@ import com.github.libretube.constants.IntentData
|
|||||||
import com.github.libretube.constants.PUSH_CHANNEL_ID
|
import com.github.libretube.constants.PUSH_CHANNEL_ID
|
||||||
import com.github.libretube.constants.PreferenceKeys
|
import com.github.libretube.constants.PreferenceKeys
|
||||||
import com.github.libretube.extensions.TAG
|
import com.github.libretube.extensions.TAG
|
||||||
import com.github.libretube.extensions.filterUntil
|
|
||||||
import com.github.libretube.extensions.toID
|
import com.github.libretube.extensions.toID
|
||||||
import com.github.libretube.ui.activities.MainActivity
|
import com.github.libretube.ui.activities.MainActivity
|
||||||
import com.github.libretube.ui.views.TimePickerPreference
|
import com.github.libretube.ui.views.TimePickerPreference
|
||||||
@ -107,9 +106,7 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
// filter the new videos until the last seen video in the feed
|
// filter the new videos until the last seen video in the feed
|
||||||
val newStreams = videoFeed.filterUntil {
|
val newStreams = videoFeed.takeWhile { it.url!!.toID() != lastSeenStreamId }
|
||||||
it.url!!.toID() == lastSeenStreamId
|
|
||||||
} ?: return@runBlocking
|
|
||||||
|
|
||||||
// return if the previous video didn't get found
|
// return if the previous video didn't get found
|
||||||
if (newStreams.isEmpty()) return@runBlocking
|
if (newStreams.isEmpty()) return@runBlocking
|
||||||
|
Loading…
Reference in New Issue
Block a user