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 abstract class BaseActivity extends DaggerAppCompatActivity { | |
@LayoutRes | |
protected abstract int layoutRes(); | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(layoutRes()); | |
ButterKnife.bind(this); |
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
def supportVersion = '27.1.1' | |
def retrofitVersion = '2.3.0' | |
def rxJavaVersion = '2.0.1' | |
def butterKnifeVersion = '8.8.1' | |
def daggerVersion = '2.13' | |
dependencies { | |
... | |
implementation "android.arch.lifecycle:extensions:1.1.1" |
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
@Singleton | |
public class ViewModelFactory implements ViewModelProvider.Factory { | |
private final Map<Class<? extends ViewModel>, Provider<ViewModel>> creators; | |
@Inject | |
public ViewModelFactory(Map<Class<? extends ViewModel>, Provider<ViewModel>> creators) { | |
this.creators = creators; | |
} |
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 ListFragment extends BaseFragment implements RepoSelectedListener { | |
@BindView(R.id.recyclerView) RecyclerView listView; | |
@BindView(R.id.tv_error) TextView errorTextView; | |
@BindView(R.id.loading_view) View loadingView; | |
@Inject ViewModelFactory viewModelFactory; | |
private ListViewModel viewModel; | |
@Override |
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 RepoListAdapter extends RecyclerView.Adapter<RepoListAdapter.RepoViewHolder>{ | |
private RepoSelectedListener repoSelectedListener; | |
private final List<Repo> data = new ArrayList<>(); | |
RepoListAdapter(ListViewModel viewModel, LifecycleOwner lifecycleOwner, RepoSelectedListener repoSelectedListener) { | |
this.repoSelectedListener = repoSelectedListener; | |
viewModel.getRepos().observe(lifecycleOwner, repos -> { | |
data.clear(); | |
if (repos != null) { |
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 ListViewModel extends ViewModel { | |
private final RepoRepository repoRepository; | |
private CompositeDisposable disposable; | |
private final MutableLiveData<List<Repo>> repos = new MutableLiveData<>(); | |
private final MutableLiveData<Boolean> repoLoadError = new MutableLiveData<>(); | |
private final MutableLiveData<Boolean> loading = new MutableLiveData<>(); | |
@Inject |
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 interface RepoService { | |
@GET("orgs/Google/repos") | |
Single<List<Repo>> getRepositories(); | |
@GET("repos/{owner}/{name}") | |
Single<Repo> getRepo(@Path("owner") String owner, @Path("name") String name); | |
} |
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
@Singleton | |
@Component(modules = {ContextModule.class, ApplicationModule.class, AndroidSupportInjectionModule.class, ActivityBindingModule.class}) | |
public interface ApplicationComponent extends AndroidInjector<DaggerApplication> { | |
void inject(BaseApplication application); | |
@Component.Builder | |
interface Builder { | |
@BindsInstance | |
Builder application(Application application); |
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
@Module | |
public abstract class ContextModule { | |
@Binds | |
abstract Context provideContext(Application application); | |
} |
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
@Singleton | |
@Module(includes = ViewModelModule.class) | |
public class ApplicationModule { | |
private static final String BASE_URL = "https://api.github.com/"; | |
@Singleton | |
@Provides | |
static Retrofit provideRetrofit() { | |
return new Retrofit.Builder().baseUrl(BASE_URL) |