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
<?xml version="1.0" encoding="utf-8"?> | |
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:motion="http://schemas.android.com/apk/res-auto"> | |
<!-- Basically with the below code, we are specifying: | |
1. To create a Transition Animation. This displays | |
the starting layout start, to begin with. | |
2. Then when user swipes the button or drags the button | |
to the right, we need to animate the button to the right. |
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
<?xml version="1.0" encoding="utf-8"?> | |
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:motion="http://schemas.android.com/apk/res-auto"> | |
<!-- Basically with the below code, we are specifying: | |
1. To create a Transition Animation. This displays | |
the starting layout start, to begin with. | |
2. Then when user swipes the button or drags the button | |
to the right, we need to animate the button to the right. |
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
<?xml version="1.0" encoding="utf-8"?> | |
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:motion="http://schemas.android.com/apk/res-auto"> | |
<!-- Basically with the below code, we are specifying: | |
1. To create a Transition Animation. This displays | |
the starting layout start, to begin with. | |
2. Then when user swipes the button or drags the button | |
to the right, we need to animate the button to the right. |
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
public class Resource<T> { | |
@NonNull | |
public final Status status; | |
@Nullable | |
public final T data; | |
@Nullable public final String message; | |
private Resource(@NonNull Status status, @Nullable T data, @Nullable String message) { | |
this.status = status; | |
this.data = data; | |
this.message = 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
/* NetworkBoundSource.java using Observable */ | |
public abstract class NetworkBoundResource<ResultType, RequestType> { | |
private Observable<Resource<ResultType>> result; | |
@MainThread | |
protected NetworkBoundResource() { | |
Observable<Resource<ResultType>> source; | |
if (shouldFetch()) { | |
source = createCall() |
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
enum class Status { | |
SUCCESS, | |
ERROR, | |
LOADING | |
} |
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
class Resource<T> private constructor(val status: Status, val data: T?, val message: String?) { | |
val isSuccess: Boolean | |
get() = status === Status.SUCCESS && data != null | |
val isLoading: Boolean | |
get() = status === Status.LOADING | |
val isLoaded: Boolean | |
get() = status !== Status.LOADING |
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
/* NetworkBoundSource - using Observable in RxJava/RxAndroid */ | |
abstract class NetworkBoundResource<ResultType, RequestType> @MainThread | |
protected constructor() { | |
private val asObservable: Observable<Resource<ResultType>> | |
init { | |
val source: Observable<Resource<ResultType>> | |
if (shouldFetch()) { |
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
/* Returns LiveData */ | |
public abstract class NetworkBoundResource<ResultType, RequestType> { | |
private final MediatorLiveData<Resource<ResultType>> result = new MediatorLiveData<>(); | |
@MainThread | |
protected NetworkBoundResource() { | |
result.setValue(Resource.loading(null)); | |
LiveData<ResultType> dbSource = loadFromDb(); | |
result.addSource(dbSource, data -> { | |
result.removeSource(dbSource); |
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
recyclerView.addOnScrollListener(object : RecyclerViewPaginator(recyclerView) { | |
override val isLastPage: Boolean | |
get() = viewModel.isLastPage() | |
override fun loadMore(page: Long) { | |
viewModel.loadData(page) | |
} | |
}) |
NewerOlder