Skip to content

Instantly share code, notes, and snippets.

View anitaa1990's full-sized avatar
🎯
Focusing

Anitaa Murthy anitaa1990

🎯
Focusing
  • Chennai
View GitHub Profile
<?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.
<?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.
<?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.
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;
@anitaa1990
anitaa1990 / NetworkBoundSource.java
Created December 24, 2018 05:57
NetworkBoundSource.java using Observable - RxJava/RxAndroid
/* 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()
enum class Status {
SUCCESS,
ERROR,
LOADING
}
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
@anitaa1990
anitaa1990 / NetworkBoundSource.kt
Created December 24, 2018 05:56
NetworkBoundSource.kt using RxJava/RxAndroid
/* 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()) {
@anitaa1990
anitaa1990 / NetworkBoundSource.java
Created December 24, 2018 05:54
NetworkBoundResource.java in Android - using LiveData
/* 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);
recyclerView.addOnScrollListener(object : RecyclerViewPaginator(recyclerView) {
override val isLastPage: Boolean
get() = viewModel.isLastPage()
override fun loadMore(page: Long) {
viewModel.loadData(page)
}
})