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
@Component(modules = {AppModule.class}) | |
public interface AppComponent { | |
void inject(MainActivity mainActivity); | |
} |
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 { | |
@Inject | |
GithubApiService mApiService; | |
@Inject | |
public IssueRepositoryImpl() { | |
} | |
// Other code remains unchanged ... | |
} |
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; | |
@Inject | |
public ListIssuesViewModel(IssueRepository issueRepository) { | |
mApiResponse = new MediatorLiveData<>(); | |
mIssueRepository = issueRepository; | |
} |
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 ViewModelFactory implements ViewModelProvider.Factory { | |
private ListIssuesViewModel mViewModel; | |
@Inject | |
public ViewModelFactory(ListIssuesViewModel viewModel) { | |
this.mViewModel = viewModel; | |
} | |
@Override | |
public <T extends ViewModel> T create(Class<T> modelClass) { |
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 IssuesApplication extends Application { | |
AppComponent mAppComponent; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
mAppComponent = DaggerAppComponent.builder().build(); | |
} | |
public AppComponent getAppComponent() { | |
return mAppComponent; |
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
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 MainActivity extends AppCompatActivity { | |
@Inject | |
ViewModelProvider.Factory mViewModelFactory; | |
// Other fields | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); |
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
# Edit ~/.bash_profile | |
export GOPATH=/Users/username/go | |
export PATH=$GOPATH/bin:$PATH | |
# Reload profile : source ~/.bash_profile |