This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from johsoe/master
Async/await interactors
- Loading branch information
Showing
27 changed files
with
293 additions
and
442 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
104 changes: 0 additions & 104 deletions
104
app/src/androidTest/java/dk/nodes/template/SampleActivityTest.kt
This file was deleted.
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
6 changes: 6 additions & 0 deletions
6
app/src/main/java/dk/nodes/template/domain/interactors/BaseAsyncInteractor.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,6 @@ | ||
package dk.nodes.template.domain.interactors | ||
|
||
|
||
interface BaseAsyncInteractor<O> { | ||
suspend fun run(): O | ||
} |
16 changes: 0 additions & 16 deletions
16
app/src/main/java/dk/nodes/template/domain/interactors/GetPostsInteractor.kt
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
app/src/main/java/dk/nodes/template/domain/interactors/GetPostsInteractorImpl.kt
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
app/src/main/java/dk/nodes/template/domain/interactors/PostsInteractor.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,23 @@ | ||
package dk.nodes.template.domain.interactors | ||
|
||
import dk.nodes.template.domain.models.Post | ||
import dk.nodes.template.domain.models.Result | ||
import dk.nodes.template.domain.repositories.PostRepository | ||
import dk.nodes.template.domain.repositories.RepositoryException | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Dispatchers | ||
import javax.inject.Inject | ||
|
||
class PostsInteractor @Inject constructor( | ||
private val postRepository: PostRepository | ||
): BaseAsyncInteractor<Result<List<Post>>> { | ||
|
||
override suspend fun run(): Result<List<Post>> { | ||
return try { | ||
val posts = postRepository.getPosts(true) | ||
Result.Success(posts) | ||
} catch (e: RepositoryException) { | ||
Result.Error(e) | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/dk/nodes/template/domain/models/Result.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,17 @@ | ||
package dk.nodes.template.domain.models | ||
|
||
/** | ||
* From: https://github.com/nickbutcher/plaid/blob/master/core/src/main/java/io/plaidapp/core/data/Result.kt | ||
*/ | ||
sealed class Result<out T : Any> { | ||
|
||
data class Success<out T : Any>(val data: T) : Result<T>() | ||
data class Error(val exception: Exception) : Result<Nothing>() | ||
|
||
override fun toString(): String { | ||
return when (this) { | ||
is Success<*> -> "Success[data=$data]" | ||
is Error -> "Error[exception=$exception]" | ||
} | ||
} | ||
} |
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
10 changes: 2 additions & 8 deletions
10
app/src/main/java/dk/nodes/template/injection/components/AppComponent.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
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
Oops, something went wrong.