First categories implementation
This commit is contained in:
@ -0,0 +1,24 @@
|
||||
package it.danieleverducci.nextcloudmaps.activity.detail;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public class CategoriesSpinnerAdapter extends ArrayAdapter<String> {
|
||||
|
||||
public CategoriesSpinnerAdapter(@NonNull Context context) {
|
||||
super(context, android.R.layout.simple_dropdown_item_1line);
|
||||
}
|
||||
|
||||
// TODO: implement colors
|
||||
|
||||
public void setCategoriesList(HashSet<String> categories) {
|
||||
clear();
|
||||
addAll(categories);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
}
|
@ -50,6 +50,7 @@ import org.threeten.bp.format.DateTimeFormatter;
|
||||
import org.threeten.bp.format.FormatStyle;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import it.danieleverducci.nextcloudmaps.R;
|
||||
@ -119,6 +120,12 @@ public class GeofavoriteDetailActivity extends AppCompatActivity implements Loca
|
||||
|
||||
mViewModel = new ViewModelProvider(this).get(GeofavoriteDetailActivityViewModel.class);
|
||||
mViewModel.init();
|
||||
mViewModel.getCategories().observe(this, new Observer<HashSet<String>>() {
|
||||
@Override
|
||||
public void onChanged(HashSet<String> categories) {
|
||||
mViewHolder.setCategories(categories);
|
||||
}
|
||||
});
|
||||
mViewModel.getIsUpdating().observe(this, new Observer<Boolean>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable Boolean updating) {
|
||||
@ -280,7 +287,9 @@ public class GeofavoriteDetailActivity extends AppCompatActivity implements Loca
|
||||
private OnSubmitListener listener;
|
||||
private Marker mapMarker;
|
||||
|
||||
|
||||
public ViewHolder(LayoutInflater inflater) {
|
||||
|
||||
this.binding = ActivityGeofavoriteDetailBinding.inflate(inflater);
|
||||
this.binding.submitBt.setOnClickListener(this);
|
||||
this.binding.mapBt.setOnClickListener(this);
|
||||
@ -289,6 +298,11 @@ public class GeofavoriteDetailActivity extends AppCompatActivity implements Loca
|
||||
this.binding.actionIconDelete.setOnClickListener(this);
|
||||
this.binding.actionIconNav.setOnClickListener(this);
|
||||
|
||||
// Set categories adapter
|
||||
CategoriesSpinnerAdapter categoriesAdapter = new CategoriesSpinnerAdapter(binding.root.getContext());
|
||||
this.binding.categoryAt.setAdapter(categoriesAdapter);
|
||||
this.binding.categoryAt.setText(Geofavorite.DEFAULT_CATEGORY);
|
||||
|
||||
// Set map properties
|
||||
this.binding.map.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.NEVER);
|
||||
this.binding.map.setMultiTouchControls(true);
|
||||
@ -310,7 +324,7 @@ public class GeofavoriteDetailActivity extends AppCompatActivity implements Loca
|
||||
binding.descriptionEt.setText(item.getComment());
|
||||
binding.createdTv.setText(item.getLocalDateCreated().format(dateFormatter));
|
||||
binding.modifiedTv.setText(item.getLocalDateCreated().format(dateFormatter));
|
||||
binding.categoryTv.setText(item.getCategory()); // TODO: Category spinner from existing categories
|
||||
binding.categoryAt.setText(item.getCategory());
|
||||
updateViewCoords(item);
|
||||
}
|
||||
|
||||
@ -330,6 +344,7 @@ public class GeofavoriteDetailActivity extends AppCompatActivity implements Loca
|
||||
public void updateModel(Geofavorite item) {
|
||||
item.setName(binding.nameEt.getText().toString());
|
||||
item.setComment(binding.descriptionEt.getText().toString());
|
||||
item.setCategory(binding.categoryAt.getText().toString());
|
||||
item.setDateModified(System.currentTimeMillis() / 1000);
|
||||
}
|
||||
|
||||
@ -347,6 +362,10 @@ public class GeofavoriteDetailActivity extends AppCompatActivity implements Loca
|
||||
binding.accuracyTv.setBackgroundColor(Color.rgb(red, green, 0.0f));
|
||||
}
|
||||
|
||||
public void setCategories(HashSet<String> categories) {
|
||||
((CategoriesSpinnerAdapter)binding.categoryAt.getAdapter()).setCategoriesList(categories);
|
||||
}
|
||||
|
||||
public void hideAccuracy() {
|
||||
binding.accuracyTv.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -4,6 +4,10 @@ import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import it.danieleverducci.nextcloudmaps.model.Geofavorite;
|
||||
import it.danieleverducci.nextcloudmaps.repository.GeofavoriteRepository;
|
||||
|
||||
@ -22,6 +26,9 @@ public class GeofavoriteDetailActivityViewModel extends ViewModel {
|
||||
mRepo.saveGeofavorite(geofav);
|
||||
}
|
||||
|
||||
public LiveData<HashSet<String>> getCategories(){
|
||||
return mRepo.getCategories();
|
||||
}
|
||||
|
||||
public LiveData<Boolean> getIsUpdating(){
|
||||
return mRepo.isUpdating();
|
||||
|
@ -166,7 +166,10 @@ public class Geofavorite implements Serializable {
|
||||
}
|
||||
|
||||
public boolean valid() {
|
||||
return getLat() != 0 && getLng() != 0 && getName() != null && getName().length() > 0;
|
||||
return
|
||||
getLat() != 0 && getLng() != 0 &&
|
||||
getName() != null && getName().length() > 0 &&
|
||||
getCategory() != null && getCategory().length() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user