Skip to content

Commit 0becd75

Browse files
committed
update
1 parent bbdb14e commit 0becd75

File tree

1 file changed

+51
-2
lines changed
  • domain/src/main/java/com/aykuttasil/domain/util

1 file changed

+51
-2
lines changed

domain/src/main/java/com/aykuttasil/domain/util/Resource.kt

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,62 @@ enum class Status {
66
ERROR
77
}
88

9+
910
sealed class Resource<out T>(val status: Status, val message: String? = null) {
1011
class Loading<out T> : Resource<T>(
1112
Status.LOADING
1213
)
14+
1315
data class Success<out T>(val data: T?) : Resource<T>(
1416
Status.SUCCESS
1517
)
16-
data class Error<out T>(val throwable: Throwable? = null, val msg: String? = "Error") : Resource<T>(
17-
Status.ERROR, msg)
18+
19+
data class Error<out T>(val throwable: Throwable? = null, val msg: String? = "Error") :
20+
Resource<T>(
21+
Status.ERROR, msg
22+
)
23+
}
24+
25+
26+
data class Resource1<out T>(val status: Status, val data: T?, val message: String?) {
27+
28+
companion object {
29+
30+
fun <T> success(data: T?): Resource1<T> {
31+
return Resource1(Status.SUCCESS, data, null)
32+
}
33+
34+
fun <T> error(msg: String, data: T?): Resource1<T> {
35+
return Resource1(Status.ERROR, data, msg)
36+
}
37+
38+
fun <T> loading(data: T?): Resource1<T> {
39+
return Resource1(Status.LOADING, data, null)
40+
}
41+
42+
}
43+
}
44+
45+
fun a() {
46+
val a = Resource1.success("")
47+
when (a.status) {
48+
Status.LOADING -> {
49+
50+
}
51+
Status.SUCCESS -> {
52+
53+
}
54+
}
55+
56+
57+
val b: Resource<String> = Resource.Success("selam")
58+
59+
when (b) {
60+
is Resource.Success -> {
61+
b.data
62+
}
63+
is Resource.Loading -> {
64+
65+
}
66+
}
1867
}

0 commit comments

Comments
 (0)