WIP add geobookmark
This commit is contained in:
parent
f1d7acb71c
commit
db4d1314eb
@ -1 +1 @@
|
|||||||
Notes Tutorial
|
Nextcloud Maps Geofavorites
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="false" project-jdk-name="11" project-jdk-type="JavaSDK" />
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK" />
|
||||||
</project>
|
</project>
|
@ -22,7 +22,7 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "it.danieleverducci.nextcloudmaps"
|
applicationId "it.danieleverducci.nextcloudmaps"
|
||||||
minSdkVersion 21
|
minSdkVersion 23
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
package="it.danieleverducci.nextcloudmaps">
|
package="it.danieleverducci.nextcloudmaps">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
|
|
||||||
<queries>
|
<queries>
|
||||||
<package android:name="com.nextcloud.client" />
|
<package android:name="com.nextcloud.client" />
|
||||||
@ -46,6 +47,10 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".activity.main.GeofavoriteDetailActivity"
|
||||||
|
android:theme="@style/AppTheme"/>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.about.AboutActivity"
|
android:name=".activity.about.AboutActivity"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
|
@ -92,8 +92,8 @@ public class GeofavoriteAdapter extends RecyclerView.Adapter<GeofavoriteAdapter.
|
|||||||
public void onBindViewHolder(@NonNull RecyclerViewAdapter holder, int position) {
|
public void onBindViewHolder(@NonNull RecyclerViewAdapter holder, int position) {
|
||||||
Geofavorite geofavorite = geofavoriteListFiltered.get(position);
|
Geofavorite geofavorite = geofavoriteListFiltered.get(position);
|
||||||
|
|
||||||
holder.tv_title.setText(Html.fromHtml(geofavorite.getName().trim()));
|
holder.tv_title.setText(Html.fromHtml(geofavorite.getName()));
|
||||||
holder.tv_content.setText(geofavorite.getComment().trim());
|
holder.tv_content.setText(geofavorite.getComment());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* Nextcloud Maps Geofavorites for Android
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -64,9 +64,9 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti
|
|||||||
private static final int INTENT_ADD = 100;
|
private static final int INTENT_ADD = 100;
|
||||||
private static final int INTENT_EDIT = 200;
|
private static final int INTENT_EDIT = 200;
|
||||||
|
|
||||||
public static final String NAVIGATION_KEY_ADD_NOTE = "add";
|
private static final String NAVIGATION_KEY_ADD_GEOFAVORITE = "add";
|
||||||
public static final String NAVIGATION_KEY_SHOW_ABOUT = "about";
|
private static final String NAVIGATION_KEY_SHOW_ABOUT = "about";
|
||||||
public static final String NAVIGATION_KEY_SWITCH_ACCOUNT = "switch_account";
|
private static final String NAVIGATION_KEY_SWITCH_ACCOUNT = "switch_account";
|
||||||
|
|
||||||
private SharedPreferences preferences;
|
private SharedPreferences preferences;
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti
|
|||||||
swipeRefresh.setOnRefreshListener(() -> presenter.getGeofavorites());
|
swipeRefresh.setOnRefreshListener(() -> presenter.getGeofavorites());
|
||||||
|
|
||||||
fab = findViewById(R.id.add);
|
fab = findViewById(R.id.add);
|
||||||
fab.setOnClickListener(view -> add_note());
|
fab.setOnClickListener(view -> addGeofavorite());
|
||||||
|
|
||||||
toolbar = findViewById(R.id.toolbar);
|
toolbar = findViewById(R.id.toolbar);
|
||||||
homeToolbar = findViewById(R.id.home_toolbar);
|
homeToolbar = findViewById(R.id.home_toolbar);
|
||||||
@ -177,8 +177,8 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti
|
|||||||
|
|
||||||
navigationCommonAdapter = new NavigationAdapter(this, item -> {
|
navigationCommonAdapter = new NavigationAdapter(this, item -> {
|
||||||
switch (item.id) {
|
switch (item.id) {
|
||||||
case NAVIGATION_KEY_ADD_NOTE:
|
case NAVIGATION_KEY_ADD_GEOFAVORITE:
|
||||||
add_note();
|
addGeofavorite();
|
||||||
break;
|
break;
|
||||||
case NAVIGATION_KEY_SHOW_ABOUT:
|
case NAVIGATION_KEY_SHOW_ABOUT:
|
||||||
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_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));
|
navItems.add(new NavigationItem(NAVIGATION_KEY_SWITCH_ACCOUNT, getString(R.string.switch_account), R.drawable.ic_logout_grey));
|
||||||
navigationCommonAdapter.setItems(navItems);
|
navigationCommonAdapter.setItems(navItems);
|
||||||
@ -224,11 +224,9 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void add_note() {
|
private void addGeofavorite() {
|
||||||
/*startActivityForResult(
|
startActivityForResult(
|
||||||
new Intent(this, EditorActivity.class), INTENT_ADD);
|
new Intent(this, GeofavoriteDetailActivity.class), INTENT_ADD);
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void show_about() {
|
private void show_about() {
|
||||||
|
68
app/src/main/res/layout/activity_geofavorite_detail.xml
Normal file
68
app/src/main/res/layout/activity_geofavorite_detail.xml
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/map"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="200dp"
|
||||||
|
android:padding="50dp"
|
||||||
|
app:srcCompat="@drawable/ic_app"
|
||||||
|
android:background="@color/defaultBrand"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="20dp">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/name_et"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="@string/name" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/description_et"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10"
|
||||||
|
android:gravity="start|top"
|
||||||
|
android:inputType="textMultiLine"
|
||||||
|
android:hint="@string/description" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:text="@string/created" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/created_tv"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAlignment="textEnd"
|
||||||
|
android:text="" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:text="@string/coords"
|
||||||
|
android:textStyle="bold"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/coords_tv"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAlignment="textEnd"
|
||||||
|
android:text="" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -36,6 +36,13 @@
|
|||||||
<string name="menu_item_sort_by_date_newest_first">Newest first</string>
|
<string name="menu_item_sort_by_date_newest_first">Newest first</string>
|
||||||
<string name="menu_item_sort_by_distance">Distance</string>
|
<string name="menu_item_sort_by_distance">Distance</string>
|
||||||
|
|
||||||
|
<!-- Geobookmarks detail -->
|
||||||
|
<string name="name">Name</string>
|
||||||
|
<string name="description">Description</string>
|
||||||
|
<string name="created">Created</string>
|
||||||
|
<string name="coords">Coordinates</string>
|
||||||
|
<string name="location_permission_required">Location permission is required to create a geofavorite.</string>
|
||||||
|
|
||||||
<!-- About -->
|
<!-- About -->
|
||||||
<string name="about_version_title">Version</string>
|
<string name="about_version_title">Version</string>
|
||||||
<string name="about_version">You are currently using <strong>%1$s</strong></string>
|
<string name="about_version">You are currently using <strong>%1$s</strong></string>
|
||||||
|
Loading…
Reference in New Issue
Block a user