This file contains hidden or 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 ResourceEvent<T> { | |
| public enum Status {SUCCESS, ERROR, LOADING} | |
| private Status mStatus; | |
| private T mData; | |
| private String mMessage; | |
| public ResourceEvent() { | |
| this(Status.LOADING, null, null); | |
| } |
This file contains hidden or 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 abstract class NetworkBoundTask<ResponseType, EventType extends ResourceEvent<ResponseType>> implements Runnable { | |
| EventBus mEventBus; | |
| public NetworkBoundTask(EventBus eventBus) { | |
| mEventBus = eventBus; | |
| mEventBus.post((EventType) getNewEventWithCachedData()); | |
| } | |
| @Override | |
| public void run() { |
This file contains hidden or 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 AppExecutors { | |
| private final Executor networkIO; | |
| private final Executor diskIO; | |
| private final Executor mainThread; | |
| public AppExecutors(Executor networkIO, Executor diskIO, Executor mainThread) { | |
| this.networkIO = networkIO; | |
| this.diskIO = diskIO; | |
| this.mainThread = mainThread; | |
| } |
This file contains hidden or 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
| <resources> | |
| <color name="system_ui_scrim_light">#E3ffffff</color> | |
| <color name="system_ui_scrim_dark">#C3000000</color> | |
| <color name="status_bar_scrim">@color/system_ui_scrim_dark</color> | |
| <color name="nav_bar_scrim">@color/status_bar_scrim</color> | |
| </resources> |
This file contains hidden or 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
| <resources> | |
| <color name="status_bar_scrim">@color/system_ui_scrim_dark</color> | |
| <!--nav_bar_scrim follows status_bar_scrim by default--> | |
| </resources> |
This file contains hidden or 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
| <resources> | |
| <color name="status_bar_scrim">@color/system_ui_scrim_light</color> | |
| <color name="nav_bar_scrim">@color/system_ui_scrim_dark</color> | |
| <!--navigationBar icons cannot be light so we can only use dark scrim--> | |
| </resources> |
This file contains hidden or 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
| <resources> | |
| <color name="nav_bar_scrim">@color/status_bar_scrim</color> | |
| </resources> |
This file contains hidden or 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
| // Using kotlin for this class as it will be a one-liner :). | |
| // - Immutable by default | |
| // Alternatively, it can also be a sealed class. (code_beauty++) | |
| data class ActivityState(val isLoading: Boolean, val result: Result?) |
This file contains hidden or 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 MyViewModel : ViewModel() { | |
| private val _isLoading = MutableLiveData(false) | |
| val isLoading: LiveData<Boolean> = _isLoading | |
| private val _result = MutableLiveData(Result.EMPTY) | |
| val result: LiveData<Result> = _result | |
| fun fetchData() { | |
| _isLoading.value = true | |
| // Fetch data |