Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/florent37/newandroidarchitecture-component-github
Sample project based on the new Android Component Architecture
https://github.com/florent37/newandroidarchitecture-component-github
2017 android architecture dagger google inject io livedata mvvm observable retrofit rx
Last synced: 13 days ago
JSON representation
Sample project based on the new Android Component Architecture
- Host: GitHub
- URL: https://github.com/florent37/newandroidarchitecture-component-github
- Owner: florent37
- License: apache-2.0
- Created: 2017-05-18T13:11:19.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-01T09:07:17.000Z (over 6 years ago)
- Last Synced: 2024-12-10T04:06:01.637Z (22 days ago)
- Topics: 2017, android, architecture, dagger, google, inject, io, livedata, mvvm, observable, retrofit, rx
- Language: Java
- Homepage: https://developer.android.com/topic/libraries/architecture/guide.html
- Size: 1.13 MB
- Stars: 222
- Watchers: 14
- Forks: 40
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NewAndroidArchitecture-Github
Sample project based on the new Android Component Architecture
Lifecycle, LiveData, MVVM, ViewModels, DataBinding, Dagger, Retrofit
https://developer.android.com/topic/libraries/architecture/guide.html
![Alt sample](https://raw.githubusercontent.com/florent37/NewAndroidArchitecture-Github/master/media/screen_small.png)
# LiveData as Observables !
LiveDatas works like RxJava's Observables,
they will notify the observer when the data is Available```java
@Override
public LiveData getUser(String userName){
final MutableLiveData liveData = new MutableLiveData<>();githubAPI.user(userName).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
if(response.isSuccessful()) {
liveData.setValue(response.body());
}
}@Override
public void onFailure(Call call, Throwable t) {}
});return liveData;
}
```# LifeCycle Owner
Use Support Fragment and AppCompatActivity to be attached to the application's state
```java
public class MainFragment extends Fragment {
```# DataBinding and ViewHolders
MainFragment.java
```java
reposAdapter = new ReposAdapter();
viewDataBinding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
viewDataBinding.recyclerView.setAdapter(reposAdapter);AppComponent.from(getContext()).inject(this);
//inject the viewmodel responding to User
//inject the viewmodel responding to List//fetch the user from the datasource
userViewModel.getUser("florent37")
.observe(this, new Observer() {
@Override
public void onChanged(@Nullable User user) {
viewDataBinding.setUser(user);
}
});//fetch the repos from the datasource
reposListViewModel.getRepos("florent37")
.observe(this, new Observer>() {
@Override
public void onChanged(@Nullable List repos) {
//when available, send it to the recyclerview
reposAdapter.setRepos(repos);
}
});
```# Dagger and Repository
```java
public class UserViewModel extends ViewModel {private final GithubRepository githubRepository;
@Inject
public UserViewModel(GithubRepository githubRepository) {
this.githubRepository = githubRepository;
}public LiveData getUser(String userName) {
//userLiveData will be notified when the user is fetched
return githubRepository.getUser(userName);
}
}
```Fiches Plateau Moto : [https://www.fiches-plateau-moto.fr/](https://www.fiches-plateau-moto.fr/)