First categories implementation

This commit is contained in:
Daniele
2021-09-22 22:47:56 +02:00
parent 760f7f572a
commit 7ac35f21cf
8 changed files with 92 additions and 17 deletions
@@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.MutableLiveData;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import it.danieleverducci.nextcloudmaps.api.ApiProvider;
@@ -24,6 +25,7 @@ public class GeofavoriteRepository {
private static final String TAG = "GeofavoriteRepository";
private static GeofavoriteRepository instance;
private MutableLiveData<List<Geofavorite>> mGeofavorites;
private MutableLiveData<HashSet<String>> mCategories = new MutableLiveData<HashSet<String>>();
private MutableLiveData<Boolean> mIsUpdating = new MutableLiveData<>(false);
private SingleLiveEvent<Boolean> mOnFinished = new SingleLiveEvent<>();
@@ -42,6 +44,10 @@ public class GeofavoriteRepository {
return mGeofavorites;
}
public MutableLiveData<HashSet<String>> getCategories() {
return mCategories;
}
public MutableLiveData<Boolean> isUpdating() {
return mIsUpdating;
}
@@ -59,6 +65,7 @@ public class GeofavoriteRepository {
public void onResponse(@NonNull Call<List<Geofavorite>> call, @NonNull Response<List<Geofavorite>> response) {
if (response.isSuccessful() && response.body() != null) {
mGeofavorites.postValue(response.body());
updateCategories(response.body());
mIsUpdating.postValue(false);
mOnFinished.postValue(true);
} else {
@@ -146,4 +153,12 @@ public class GeofavoriteRepository {
});
}
private void updateCategories(List<Geofavorite> geofavs) {
HashSet<String> categories = new HashSet<>();
for (Geofavorite g : geofavs) {
categories.add(g.getCategory());
}
mCategories.postValue(categories);
}
}