-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated to use domain layer in a smart way
- Loading branch information
Showing
5 changed files
with
36 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
23 changes: 0 additions & 23 deletions
23
app/src/main/java/com/stephenbain/pagingsamples/data/domain/GetMyPlaylists.kt
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/stephenbain/pagingsamples/data/domain/UpdatePlaylists.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,28 @@ | ||
package com.stephenbain.pagingsamples.data.domain | ||
|
||
import com.stephenbain.pagingsamples.data.db.PlaylistDao | ||
import com.stephenbain.pagingsamples.data.repo.TokenRepository | ||
import com.stephenbain.pagingsamples.data.retrofit.SpotifyService | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
|
||
|
||
class UpdatePlaylists @Inject constructor( | ||
private val spotifyService: SpotifyService, | ||
private val playlistDao: PlaylistDao, | ||
private val tokenRepository: TokenRepository | ||
) { | ||
|
||
suspend operator fun invoke(limit: Int) { | ||
withContext(Dispatchers.IO) { | ||
val paging = spotifyService.getMyPlaylists( | ||
token = "Bearer ${tokenRepository.token}", | ||
offset = playlistDao.getItemCount(), | ||
limit = limit | ||
).await() | ||
playlistDao.insertAll(paging.items) | ||
} | ||
} | ||
|
||
} |
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