-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a97e45
commit 31f1fcf
Showing
5 changed files
with
41 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
app/src/main/java/org/schabi/newpipe/viewmodels/CommentsViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.schabi.newpipe.viewmodels | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import androidx.paging.Pager | ||
import androidx.paging.PagingConfig | ||
import androidx.paging.cachedIn | ||
import org.schabi.newpipe.paging.CommentsSource | ||
import org.schabi.newpipe.util.KEY_SERVICE_ID | ||
import org.schabi.newpipe.util.KEY_URL | ||
import org.schabi.newpipe.util.NO_SERVICE_ID | ||
|
||
class CommentsViewModel(savedStateHandle: SavedStateHandle) : ViewModel() { | ||
private val serviceId = savedStateHandle[KEY_SERVICE_ID] ?: NO_SERVICE_ID | ||
private val url = savedStateHandle.get<String>(KEY_URL) | ||
|
||
val comments = Pager(PagingConfig(pageSize = 20, enablePlaceholders = false)) { | ||
CommentsSource(serviceId, url, null) | ||
}.flow | ||
.cachedIn(viewModelScope) | ||
} |