forked from penguin86/nextcloud-maps-client
Conversion to MVVM completed
This commit is contained in:
+5
-5
@@ -125,14 +125,14 @@ public class GeofavoriteDetailActivity extends AppCompatActivity implements Loca
|
||||
mViewHolder.setUpdating(updating);
|
||||
}
|
||||
});
|
||||
mViewModel.getIsFailed().observe(this, new Observer<Boolean>() {
|
||||
mViewModel.getOnFinished().observe(this, new Observer<Boolean>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable Boolean failed) {
|
||||
if(failed){
|
||||
Toast.makeText(GeofavoriteDetailActivity.this, R.string.error_saving_geofavorite, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
public void onChanged(@Nullable Boolean success) {
|
||||
if(success){
|
||||
Toast.makeText(GeofavoriteDetailActivity.this, R.string.geofavorite_saved, Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
} else {
|
||||
Toast.makeText(GeofavoriteDetailActivity.this, R.string.error_saving_geofavorite, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+4
-22
@@ -7,14 +7,11 @@ import androidx.lifecycle.ViewModel;
|
||||
import it.danieleverducci.nextcloudmaps.model.Geofavorite;
|
||||
import it.danieleverducci.nextcloudmaps.repository.GeofavoriteRepository;
|
||||
|
||||
public class GeofavoriteDetailActivityViewModel extends ViewModel implements GeofavoriteRepository.OnFinished {
|
||||
public class GeofavoriteDetailActivityViewModel extends ViewModel {
|
||||
private GeofavoriteRepository mRepo;
|
||||
private MutableLiveData<Boolean> mIsUpdating = new MutableLiveData<>();
|
||||
private MutableLiveData<Boolean> mIsFailed = new MutableLiveData<>();
|
||||
|
||||
public void init() {
|
||||
mRepo = GeofavoriteRepository.getInstance();
|
||||
mRepo.setOnFinishedListener(this);
|
||||
}
|
||||
|
||||
public Geofavorite getGeofavorite(int id) {
|
||||
@@ -27,26 +24,11 @@ public class GeofavoriteDetailActivityViewModel extends ViewModel implements Geo
|
||||
|
||||
|
||||
public LiveData<Boolean> getIsUpdating(){
|
||||
return mIsUpdating;
|
||||
return mRepo.isUpdating();
|
||||
}
|
||||
|
||||
public LiveData<Boolean> getIsFailed(){
|
||||
return mIsFailed;
|
||||
public LiveData<Boolean> getOnFinished(){
|
||||
return mRepo.onFinished();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoading() {
|
||||
mIsUpdating.postValue(true);
|
||||
}
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
mIsUpdating.postValue(false);
|
||||
mIsFailed.postValue(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
mIsUpdating.postValue(false);
|
||||
mIsFailed.postValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,10 +144,10 @@ public class MainActivity extends AppCompatActivity implements OnSortingOrderLis
|
||||
}
|
||||
}
|
||||
});
|
||||
mMainActivityViewModel.getIsFailed().observe(this, new Observer<Boolean>() {
|
||||
mMainActivityViewModel.getOnFinished().observe(this, new Observer<Boolean>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable Boolean aBoolean) {
|
||||
if(aBoolean){
|
||||
public void onChanged(@Nullable Boolean success) {
|
||||
if(!success){
|
||||
Toast.makeText(MainActivity.this, R.string.list_geofavorite_connection_error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
+4
-22
@@ -9,14 +9,11 @@ import java.util.List;
|
||||
import it.danieleverducci.nextcloudmaps.model.Geofavorite;
|
||||
import it.danieleverducci.nextcloudmaps.repository.GeofavoriteRepository;
|
||||
|
||||
public class MainActivityViewModel extends ViewModel implements GeofavoriteRepository.OnFinished {
|
||||
public class MainActivityViewModel extends ViewModel {
|
||||
private GeofavoriteRepository mRepo;
|
||||
private MutableLiveData<Boolean> mIsUpdating = new MutableLiveData<>();
|
||||
private MutableLiveData<Boolean> mIsFailed = new MutableLiveData<>();
|
||||
|
||||
public void init() {
|
||||
mRepo = GeofavoriteRepository.getInstance();
|
||||
mRepo.setOnFinishedListener(this);
|
||||
}
|
||||
|
||||
public LiveData<List<Geofavorite>> getGeofavorites(){
|
||||
@@ -33,26 +30,11 @@ public class MainActivityViewModel extends ViewModel implements GeofavoriteRepos
|
||||
}
|
||||
|
||||
public LiveData<Boolean> getIsUpdating(){
|
||||
return mIsUpdating;
|
||||
return mRepo.isUpdating();
|
||||
}
|
||||
|
||||
public LiveData<Boolean> getIsFailed(){
|
||||
return mIsFailed;
|
||||
public LiveData<Boolean> getOnFinished(){
|
||||
return mRepo.onFinished();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoading() {
|
||||
mIsUpdating.postValue(true);
|
||||
}
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
mIsUpdating.postValue(false);
|
||||
mIsFailed.postValue(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
mIsUpdating.postValue(false);
|
||||
mIsFailed.postValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user