diff --git a/README.md b/README.md
index 5dec2c9..5bf197f 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,9 @@
# Nextcloud Maps Geobookmarks Android app
+[](https://play.google.com/store/apps/details?id=it.danieleverducci.nextcloudmaps)
+[](https://github.com/penguin86/nextcloud-maps-client/releases/latest)
+
Android app to show your Nextcloud Maps geobookmarks list. Geobookmarks can be opened in all apps supporting geo links (i.e. Google Maps, Organic Maps etc...).
A new geobookmark can be created on current location.
diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/detail/CategoriesSpinnerAdapter.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/detail/CategoriesSpinnerAdapter.java
new file mode 100644
index 0000000..01a86fa
--- /dev/null
+++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/detail/CategoriesSpinnerAdapter.java
@@ -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 {
+
+ public CategoriesSpinnerAdapter(@NonNull Context context) {
+ super(context, android.R.layout.simple_dropdown_item_1line);
+ }
+
+ // TODO: implement colors
+
+ public void setCategoriesList(HashSet categories) {
+ clear();
+ addAll(categories);
+ notifyDataSetChanged();
+ }
+
+}
diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/detail/GeofavoriteDetailActivity.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/detail/GeofavoriteDetailActivity.java
index 25e0269..725d125 100644
--- a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/detail/GeofavoriteDetailActivity.java
+++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/detail/GeofavoriteDetailActivity.java
@@ -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>() {
+ @Override
+ public void onChanged(HashSet categories) {
+ mViewHolder.setCategories(categories);
+ }
+ });
mViewModel.getIsUpdating().observe(this, new Observer() {
@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 categories) {
+ ((CategoriesSpinnerAdapter)binding.categoryAt.getAdapter()).setCategoriesList(categories);
+ }
+
public void hideAccuracy() {
binding.accuracyTv.setVisibility(View.GONE);
}
diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/detail/GeofavoriteDetailActivityViewModel.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/detail/GeofavoriteDetailActivityViewModel.java
index 71c2011..2d0d5e9 100644
--- a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/detail/GeofavoriteDetailActivityViewModel.java
+++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/detail/GeofavoriteDetailActivityViewModel.java
@@ -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> getCategories(){
+ return mRepo.getCategories();
+ }
public LiveData getIsUpdating(){
return mRepo.isUpdating();
diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/model/Geofavorite.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/model/Geofavorite.java
index 21cbf17..207d4ca 100644
--- a/app/src/main/java/it/danieleverducci/nextcloudmaps/model/Geofavorite.java
+++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/model/Geofavorite.java
@@ -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;
}
/**
diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/repository/GeofavoriteRepository.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/repository/GeofavoriteRepository.java
index ce95c44..9dee4ab 100644
--- a/app/src/main/java/it/danieleverducci/nextcloudmaps/repository/GeofavoriteRepository.java
+++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/repository/GeofavoriteRepository.java
@@ -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> mGeofavorites;
+ private MutableLiveData> mCategories = new MutableLiveData>();
private MutableLiveData mIsUpdating = new MutableLiveData<>(false);
private SingleLiveEvent mOnFinished = new SingleLiveEvent<>();
@@ -42,6 +44,10 @@ public class GeofavoriteRepository {
return mGeofavorites;
}
+ public MutableLiveData> getCategories() {
+ return mCategories;
+ }
+
public MutableLiveData isUpdating() {
return mIsUpdating;
}
@@ -59,6 +65,7 @@ public class GeofavoriteRepository {
public void onResponse(@NonNull Call> call, @NonNull Response> 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 geofavs) {
+ HashSet categories = new HashSet<>();
+ for (Geofavorite g : geofavs) {
+ categories.add(g.getCategory());
+ }
+ mCategories.postValue(categories);
+ }
+
}
diff --git a/app/src/main/res/layout/activity_geofavorite_detail.xml b/app/src/main/res/layout/activity_geofavorite_detail.xml
index 85daeb0..29ed4e1 100644
--- a/app/src/main/res/layout/activity_geofavorite_detail.xml
+++ b/app/src/main/res/layout/activity_geofavorite_detail.xml
@@ -138,7 +138,8 @@
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:background="@android:color/transparent"
android:drawableLeft="@drawable/ic_edit"
- android:drawablePadding="5dp"/>
+ android:drawablePadding="5dp"
+ android:drawableTint="@color/defaultBrand"/>
+
+
-
-
-
-
Save
Unable to save geofavorite
Geofavorite saved
- Incomplete geofavorite: Name and GPS coordinates are mandatory
+ Incomplete geofavorite: Name and category are mandatory
Version