diff --git a/.idea/.name b/.idea/.name
index 4916992..d259ab2 100644
--- a/.idea/.name
+++ b/.idea/.name
@@ -1 +1 @@
-Notes Tutorial
\ No newline at end of file
+Nextcloud Maps Geofavorites
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 121650a..59f6372 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 1cedfb0..e1d83a5 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -22,7 +22,7 @@ android {
defaultConfig {
applicationId "it.danieleverducci.nextcloudmaps"
- minSdkVersion 21
+ minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 21e492f..a6fa9fe 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -21,6 +21,7 @@
package="it.danieleverducci.nextcloudmaps">
+
@@ -46,6 +47,10 @@
+
+
.
+ */
+
+package it.danieleverducci.nextcloudmaps.activity.main;
+
+import android.Manifest;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.location.Location;
+import android.location.LocationListener;
+import android.location.LocationManager;
+import android.os.Bundle;
+import android.util.Log;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.app.ActivityCompat;
+
+import it.danieleverducci.nextcloudmaps.R;
+
+public class GeofavoriteDetailActivity extends AppCompatActivity implements LocationListener, ActivityCompat.OnRequestPermissionsResultCallback {
+
+ public static final String ARG_GEOFAVORITE_ID = "geofavid";
+ private static final int PERMISSION_REQUEST_CODE = 9999;
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.activity_geofavorite_detail);
+
+ int id = getIntent().getIntExtra(ARG_GEOFAVORITE_ID, 0);
+ if (id == 0) {
+ // New geofavorite: precompile location
+ getLocation();
+ }
+
+ }
+
+ /**
+ * Obtains the current location (requesting user's permission, if necessary)
+ * and calls updateLocationField()
+ */
+ private void getLocation() {
+ // Check if user granted location permission
+ if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+ // User didn't grant permission. Ask it.
+ requestPermissions(new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQUEST_CODE);
+ return;
+ }
+
+ LocationManager locationManager = (LocationManager)
+ getSystemService(Context.LOCATION_SERVICE);
+ // Try to use last available location
+ Location lastKnown = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+ if (lastKnown != null)
+ updateLocationField(lastKnown);
+ // Register for location updates in case the user moves before saving
+ locationManager.requestLocationUpdates(
+ LocationManager.GPS_PROVIDER, 5000, 10, this
+ );
+ }
+
+ /**
+ * Compiles the geofavorite location field with the provided location object
+ * @param location to set in the geofavorite
+ */
+ private void updateLocationField(Location location) {
+ Log.d("Location", location.toString());
+ }
+
+
+ /** Location updates callbacks **/
+
+ @Override
+ public void onLocationChanged(@NonNull Location location) {
+ updateLocationField(location);
+ }
+
+ @Override
+ public void onStatusChanged(String provider, int status, Bundle extras) {}
+
+ @Override
+ public void onProviderEnabled(@NonNull String provider) {}
+
+ @Override
+ public void onProviderDisabled(@NonNull String provider) {}
+
+ @Override
+ public void onPointerCaptureChanged(boolean hasCapture) {}
+
+
+ /** Position permission request result **/
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ if (requestCode == PERMISSION_REQUEST_CODE && permissions[0].equals(Manifest.permission.ACCESS_FINE_LOCATION)) {
+ if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ getLocation();
+ } else {
+ Toast.makeText(this, R.string.location_permission_required, Toast.LENGTH_LONG).show();
+ finish();
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java
index f0f6755..f8f8be8 100644
--- a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java
+++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java
@@ -64,9 +64,9 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti
private static final int INTENT_ADD = 100;
private static final int INTENT_EDIT = 200;
- public static final String NAVIGATION_KEY_ADD_NOTE = "add";
- public static final String NAVIGATION_KEY_SHOW_ABOUT = "about";
- public static final String NAVIGATION_KEY_SWITCH_ACCOUNT = "switch_account";
+ private static final String NAVIGATION_KEY_ADD_GEOFAVORITE = "add";
+ private static final String NAVIGATION_KEY_SHOW_ABOUT = "about";
+ private static final String NAVIGATION_KEY_SWITCH_ACCOUNT = "switch_account";
private SharedPreferences preferences;
@@ -120,7 +120,7 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti
swipeRefresh.setOnRefreshListener(() -> presenter.getGeofavorites());
fab = findViewById(R.id.add);
- fab.setOnClickListener(view -> add_note());
+ fab.setOnClickListener(view -> addGeofavorite());
toolbar = findViewById(R.id.toolbar);
homeToolbar = findViewById(R.id.home_toolbar);
@@ -177,8 +177,8 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti
navigationCommonAdapter = new NavigationAdapter(this, item -> {
switch (item.id) {
- case NAVIGATION_KEY_ADD_NOTE:
- add_note();
+ case NAVIGATION_KEY_ADD_GEOFAVORITE:
+ addGeofavorite();
break;
case NAVIGATION_KEY_SHOW_ABOUT:
show_about();
@@ -189,7 +189,7 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti
}
});
- navItems.add(new NavigationItem(NAVIGATION_KEY_ADD_NOTE, getString(R.string.new_geobookmark), R.drawable.ic_add));
+ navItems.add(new NavigationItem(NAVIGATION_KEY_ADD_GEOFAVORITE, getString(R.string.new_geobookmark), R.drawable.ic_add));
navItems.add(new NavigationItem(NAVIGATION_KEY_SHOW_ABOUT, getString(R.string.about), R.drawable.ic_info_grey));
navItems.add(new NavigationItem(NAVIGATION_KEY_SWITCH_ACCOUNT, getString(R.string.switch_account), R.drawable.ic_logout_grey));
navigationCommonAdapter.setItems(navItems);
@@ -224,11 +224,9 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti
}
}
- private void add_note() {
- /*startActivityForResult(
- new Intent(this, EditorActivity.class), INTENT_ADD);
-
- */
+ private void addGeofavorite() {
+ startActivityForResult(
+ new Intent(this, GeofavoriteDetailActivity.class), INTENT_ADD);
}
private void show_about() {
diff --git a/app/src/main/res/layout/activity_geofavorite_detail.xml b/app/src/main/res/layout/activity_geofavorite_detail.xml
new file mode 100644
index 0000000..63a580e
--- /dev/null
+++ b/app/src/main/res/layout/activity_geofavorite_detail.xml
@@ -0,0 +1,68 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 040f725..c0c83be 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -36,6 +36,13 @@
Newest first
Distance
+
+ Name
+ Description
+ Created
+ Coordinates
+ Location permission is required to create a geofavorite.
+
Version
You are currently using <strong>%1$s</strong>