Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Anitaa Murthy anitaa1990

🎯
Focusing
View GitHub Profile
View motion_scene_part_iii.xml
<?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.
View motion_scene_part_i.xml
<?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.
View motion_scene_part_ii.xml
<?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.
View Resource.java
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 Dec 24, 2018
NetworkBoundSource.java using Observable - RxJava/RxAndroid
View NetworkBoundSource.java
/* 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()
View Status.kt
enum class Status {
SUCCESS,
ERROR,
LOADING
}
View Resource.kt
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 Dec 24, 2018
NetworkBoundSource.kt using RxJava/RxAndroid
View NetworkBoundSource.kt
/* 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 Dec 24, 2018
NetworkBoundResource.java in Android - using LiveData
View NetworkBoundSource.java
/* 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);
View MainActivity.kt
recyclerView.addOnScrollListener(object : RecyclerViewPaginator(recyclerView) {
override val isLastPage: Boolean
get() = viewModel.isLastPage()
override fun loadMore(page: Long) {
viewModel.loadData(page)
}
})
You can’t perform that action at this time.