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 class AppModule { | |
public static final String BASE_URL = "https://api.github.com/"; | |
@Provides | |
@Singleton | |
GithubApiService provideGithubApiService() { | |
return new Retrofit.Builder() | |
.addConverterFactory(GsonConverterFactory.create()) | |
.baseUrl(BASE_URL) |
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 ListIssuesViewModel extends ViewModel { | |
private IssueRepository mIssueRepository; | |
// Other member declarations | |
public ListIssuesViewModel(IssueRepository repository) { | |
mIssueRepository = repository; | |
// Other code | |
} | |
// Other code |
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 ListIssuesViewModel extends ViewModel { | |
private IssueRepository mIssueRepository; | |
// Other member declarations | |
public ListIssuesViewModel() { | |
mIssueRepository = new IssueRepositoryImpl(); | |
// Other code | |
} | |
// Other code |
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 MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
mViewModel = ViewModelProviders.of(this).get(ListIssuesViewModel.class); | |
setupView(); | |
// Handle changes emitted by LiveData | |
mViewModel.getRes().observe(this, apiResponse -> { |
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 ListIssuesViewModel extends ViewModel { | |
private MediatorLiveData<ApiResponse> mApiResponse; | |
private IssueRepository mIssueRepository; | |
// No argument constructor | |
public ListIssuesViewModel() { | |
mApiResponse = new MediatorLiveData<>(); | |
mIssueRepository = new IssueRepositoryImpl(); | |
} |
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 IssueRepositoryImpl implements IssueRepository { | |
public static final String BASE_URL = "https://api.github.com/"; | |
private GithubApiService mApiService; | |
public IssueRepositoryImpl() { | |
Retrofit retrofit = new Retrofit.Builder() | |
.addConverterFactory(GsonConverterFactory.create()) | |
.baseUrl(BASE_URL) | |
.build(); |
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 IssueRepository { | |
LiveData<ApiResponse> getIssues(String owner, String repo); | |
} |
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 GithubApiService { | |
@GET("/repos/{owner}/{repo}/issues") | |
Call<List<Issue>> getIssues(@Path("owner") String owner, @Path("repo") String repo); | |
} |
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
compile 'com.squareup.retrofit2:retrofit:2.1.0' | |
compile 'com.squareup.retrofit2:converter-gson:2.1.0' | |
compile 'android.arch.lifecycle:runtime:1.0.0' | |
compile 'android.arch.lifecycle:extensions:1.0.0-alpha9-1' | |
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0-alpha9-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
allprojects { | |
repositories { | |
jcenter() | |
maven { url 'https://maven.google.com' } | |
} | |
} |