Skip to content

Commit

Permalink
Pre-release
Browse files Browse the repository at this point in the history
  • Loading branch information
penguin86 committed Sep 15, 2021
1 parent f21e522 commit c7212fb
Show file tree
Hide file tree
Showing 20 changed files with 224 additions and 79 deletions.
17 changes: 0 additions & 17 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ dependencies {
implementation "com.github.nextcloud:Android-SingleSignOn:0.5.6"

// OSMDroid
compile 'org.osmdroid:osmdroid-android:6.1.10'
implementation 'org.osmdroid:osmdroid-android:6.1.10'

//Threeten-Backport (ports Java 8 Date API on Java 6+)
implementation 'org.threeten:threetenbp:1.5.1'

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.location.Location;
Expand All @@ -43,13 +44,17 @@
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.CustomZoomButtonsController;
import org.osmdroid.views.overlay.Marker;
import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.FormatStyle;

import java.util.Date;

import it.danieleverducci.nextcloudmaps.R;
import it.danieleverducci.nextcloudmaps.activity.main.MainActivity;
import it.danieleverducci.nextcloudmaps.api.ApiProvider;
import it.danieleverducci.nextcloudmaps.databinding.ActivityGeofavoriteDetailBinding;
import it.danieleverducci.nextcloudmaps.model.Geofavorite;
import it.danieleverducci.nextcloudmaps.utils.IntentGenerator;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
Expand Down Expand Up @@ -81,6 +86,21 @@ public void onBackPressed() {
finish();
}

@Override
public void onActionIconShareClicked() {
startActivity(Intent.createChooser(IntentGenerator.newShareIntent(GeofavoriteDetailActivity.this, mGeofavorite), getString(R.string.share_via)));
}

@Override
public void onActionIconNavClicked() {
startActivity(IntentGenerator.newGeoUriIntent(GeofavoriteDetailActivity.this, mGeofavorite));
}

@Override
public void onActionIconDeleteClicked() {
// TODO
}

@Override
public void onSubmit() {
saveGeofavorite();
Expand All @@ -102,6 +122,8 @@ public void onMapClicked() {
mGeofavorite.setCategory(DEFAULT_CATEGORY);
mGeofavorite.setDateCreated(System.currentTimeMillis());
mGeofavorite.setDateModified(System.currentTimeMillis());
mViewHolder.hideActions();

// Precompile location
getLocation();
}
Expand Down Expand Up @@ -255,6 +277,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis

private class ViewHolder implements View.OnClickListener {
private final ActivityGeofavoriteDetailBinding binding;
private DateTimeFormatter dateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);
private OnSubmitListener listener;
private Marker mapMarker;

Expand All @@ -263,6 +286,9 @@ public ViewHolder(LayoutInflater inflater) {
this.binding.submitBt.setOnClickListener(this);
this.binding.mapBt.setOnClickListener(this);
this.binding.backBt.setOnClickListener(this);
this.binding.actionIconShare.setOnClickListener(this);
this.binding.actionIconDelete.setOnClickListener(this);
this.binding.actionIconNav.setOnClickListener(this);

// Set map properties
this.binding.map.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.NEVER);
Expand All @@ -283,8 +309,8 @@ public void updateView(Geofavorite item) {
binding.collapsingToolbar.setTitle(item.getName() != null ? item.getName() : getString(R.string.new_geobookmark));
binding.nameEt.setText(item.getName());
binding.descriptionEt.setText(item.getComment());
binding.createdTv.setText(new Date(item.getDateCreated() * 1000).toString());
binding.modifiedTv.setText(new Date(item.getDateModified() * 1000).toString());
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
updateViewCoords(item);
}
Expand Down Expand Up @@ -322,6 +348,10 @@ public void hideAccuracy() {
binding.accuracyTv.setVisibility(View.GONE);
}

public void hideActions() {
binding.actionIcons.setVisibility(View.GONE);
}

public void setOnSubmitListener(OnSubmitListener listener) {
this.listener = listener;
}
Expand All @@ -345,12 +375,26 @@ public void onClick(View v) {
if (v.getId() == R.id.back_bt && this.listener != null) {
this.listener.onBackPressed();
}

// Actions
if (v.getId() == R.id.action_icon_share && this.listener != null) {
this.listener.onActionIconShareClicked();
}
if (v.getId() == R.id.action_icon_nav && this.listener != null) {
this.listener.onActionIconNavClicked();
}
if (v.getId() == R.id.action_icon_delete && this.listener != null) {
this.listener.onActionIconDeleteClicked();
}
}
}

protected interface OnSubmitListener {
void onSubmit();
void onMapClicked();
void onBackPressed();
void onActionIconShareClicked();
void onActionIconNavClicked();
void onActionIconDeleteClicked();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@
package it.danieleverducci.nextcloudmaps.activity.main;

import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -40,6 +36,9 @@
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.FormatStyle;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -57,6 +56,7 @@ public class GeofavoriteAdapter extends RecyclerView.Adapter<GeofavoriteAdapter.

private Context context;
private ItemClickListener itemClickListener;
private DateTimeFormatter dateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);

private List<Geofavorite> geofavoriteList = new ArrayList<>();
private List<Geofavorite> geofavoriteListFiltered = new ArrayList<>();
Expand Down Expand Up @@ -117,6 +117,7 @@ public void onBindViewHolder(@NonNull GeofavoriteViewHolder holder, int position

holder.tv_title.setText(Html.fromHtml(geofavorite.getName()));
holder.tv_content.setText(geofavorite.getComment());
holder.tv_date.setText(geofavorite.getLocalDateCreated().format(dateFormatter));
}

@Override
Expand Down Expand Up @@ -164,9 +165,9 @@ protected void publishResults(CharSequence charSequence, FilterResults filterRes
};

class GeofavoriteViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView tv_title, tv_content;
TextView tv_title, tv_content, tv_date;
ImageView bt_context_menu;
ImageView bt_share;
ImageView bt_nav;

ItemClickListener itemClickListener;

Expand All @@ -176,14 +177,15 @@ class GeofavoriteViewHolder extends RecyclerView.ViewHolder implements View.OnCl

tv_title = itemView.findViewById(R.id.title);
tv_content = itemView.findViewById(R.id.content);
tv_date = itemView.findViewById(R.id.date);
bt_context_menu = itemView.findViewById(R.id.geofav_context_menu_bt);
bt_share = itemView.findViewById(R.id.geofav_share_bt);
bt_nav = itemView.findViewById(R.id.geofav_nav_bt);

this.itemClickListener = itemClickListener;
itemView.setOnClickListener(this);

bt_context_menu.setOnClickListener(this);
bt_share.setOnClickListener(this);
bt_nav.setOnClickListener(this);
}

@Override
Expand All @@ -192,9 +194,9 @@ public void onClick(View view) {
case R.id.geofav_context_menu_bt:
onOverflowIconClicked(view, getAdapterPosition());
break;
case R.id.geofav_share_bt:
case R.id.geofav_nav_bt:
if (itemClickListener != null)
itemClickListener.onItemShareClick(get(getAdapterPosition()));
itemClickListener.onItemNavClick(get(getAdapterPosition()));
break;
default:
if (itemClickListener != null)
Expand Down Expand Up @@ -229,17 +231,17 @@ private boolean optionsItemSelected(MenuItem item) {
}
Geofavorite gf = get(overflowMenuSelectedPosition);
overflowMenuSelectedPosition = -1;
if (item.getItemId() == R.id.list_context_menu_detail && itemClickListener != null)
itemClickListener.onItemDetailsClick(gf);
if (item.getItemId() == R.id.list_context_menu_delete)
if (item.getItemId() == R.id.list_context_menu_share && itemClickListener != null)
itemClickListener.onItemShareClick(gf);
if (item.getItemId() == R.id.list_context_menu_delete && itemClickListener != null)
itemClickListener.onItemDeleteClick(gf);
return true;
}

public interface ItemClickListener {
void onItemClick(Geofavorite item);
void onItemShareClick(Geofavorite item);
void onItemDetailsClick(Geofavorite item);
void onItemNavClick(Geofavorite item);
void onItemDeleteClick(Geofavorite item);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import it.danieleverducci.nextcloudmaps.activity.main.NavigationAdapter.NavigationItem;
import it.danieleverducci.nextcloudmaps.activity.main.SortingOrderDialogFragment.OnSortingOrderListener;
import it.danieleverducci.nextcloudmaps.model.Geofavorite;
import it.danieleverducci.nextcloudmaps.utils.IntentGenerator;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;
Expand Down Expand Up @@ -107,28 +108,18 @@ protected void onCreate(Bundle savedInstanceState) {

rvItemClickListener = new ItemClickListener() {
@Override
public void onItemClick(Geofavorite geofavorite) {
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(geofavorite.getGeoUri());
startActivity(i);
public void onItemClick(Geofavorite item) {
showGeofavoriteDetailActivity(item);
}

@Override
public void onItemShareClick(Geofavorite item) {
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.setType("text/plain");
String shareMessage = getString(R.string.share_message)
.replace("{lat}", ""+item.getLat())
.replace("{lng}", ""+item.getLng());
i.putExtra(Intent.EXTRA_TEXT, shareMessage );
startActivity(Intent.createChooser(i, getString(R.string.share_via)));
startActivity(Intent.createChooser(IntentGenerator.newShareIntent(MainActivity.this, item), getString(R.string.share_via)));
}

@Override
public void onItemDetailsClick(Geofavorite item) {
showGeofavoriteDetailActivity(item);
public void onItemNavClick(Geofavorite item) {
startActivity(IntentGenerator.newGeoUriIntent(MainActivity.this, item));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import org.threeten.bp.Instant;
import org.threeten.bp.LocalDate;
import org.threeten.bp.ZoneId;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Date;
Expand Down Expand Up @@ -102,10 +106,17 @@ public long getDateModified() {
public void setDateModified(long dateModified) {
this.dateModified = dateModified;
}
public LocalDate getLocalDateModified() {
return Instant.ofEpochSecond(getDateCreated()).atZone(ZoneId.systemDefault()).toLocalDate();
}

public long getDateCreated() {
return dateCreated;
}
public LocalDate getLocalDateCreated() {
return Instant.ofEpochSecond(getDateCreated()).atZone(ZoneId.systemDefault()).toLocalDate();
}

public void setDateCreated(long dateCreated) {
this.dateCreated = dateCreated;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package it.danieleverducci.nextcloudmaps.utils;

import android.content.Context;
import android.content.Intent;

import it.danieleverducci.nextcloudmaps.R;
import it.danieleverducci.nextcloudmaps.model.Geofavorite;

public class IntentGenerator {
public static Intent newShareIntent(Context context, Geofavorite item) {
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.setType("text/plain");
String shareMessage = context.getString(R.string.share_message)
.replace("{lat}", ""+item.getLat())
.replace("{lng}", ""+item.getLng());
i.putExtra(Intent.EXTRA_TEXT, shareMessage );
return i;
}

public static Intent newGeoUriIntent(Context context, Geofavorite item) {
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(item.getGeoUri());
return i;
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_edit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#0082C9"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_nav.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M20.5,3l-0.16,0.03L15,5.1 9,3 3.36,4.9c-0.21,0.07 -0.36,0.25 -0.36,0.48V20.5c0,0.28 0.22,0.5 0.5,0.5l0.16,-0.03L9,18.9l6,2.1 5.64,-1.9c0.21,-0.07 0.36,-0.25 0.36,-0.48V3.5c0,-0.28 -0.22,-0.5 -0.5,-0.5zM15,19l-6,-2.11V5l6,2.11V19z"/>
</vector>
Loading

0 comments on commit c7212fb

Please sign in to comment.