forked from ahmedeltaher/MVVM-Kotlin-Android-Architecture
-
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.
- Loading branch information
1 parent
396f958
commit f39dbd5
Showing
8 changed files
with
63 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
package com.task.data | ||
|
||
import com.task.data.remote.Data | ||
|
||
/** | ||
* Created by ahmedeltaher on 3/23/17. | ||
*/ | ||
|
||
interface DataSource { | ||
fun requestNews(): Data? | ||
fun requestNews(): DataStatus | ||
} |
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,10 @@ | ||
package com.task.data | ||
|
||
import com.task.data.remote.Data | ||
import com.task.data.remote.Error | ||
|
||
sealed class DataStatus { | ||
object LoadingState : DataStatus() | ||
class FailureState(val error: Error) : DataStatus() | ||
class SuccessState(val data: Data) : DataStatus() | ||
} |
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,11 @@ | ||
package com.task.data | ||
|
||
// A generic class that contains data and status about loading this data. | ||
sealed class Resource<T>( | ||
val data: T? = null, | ||
val message: String? = null | ||
) { | ||
class Success<T>(data: T) : Resource<T>(data) | ||
class Loading<T>(data: T? = null) : Resource<T>(data) | ||
class Error<T>(message: String, data: T? = null) : Resource<T>(data, message) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package com.task.data.remote | ||
|
||
import com.task.data.DataStatus | ||
|
||
/** | ||
* Created by ahmedEltaher on 3/23/17. | ||
*/ | ||
|
||
internal interface RemoteSource { | ||
fun requestNews(): Data? | ||
fun requestNews(): DataStatus | ||
} |
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