Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Jun 9, 2022
1 parent dbf3552 commit 8faf202
Show file tree
Hide file tree
Showing 45 changed files with 1,625 additions and 456 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
see LICENSE.txt in assets folder
see LICENSE.txt in src/main/assets
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void readAndSaveCustomBugs() {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream is = loader.getResourceAsStream("customBug.json");
assertNotNull(is);
TransferTasks.readCustomBugs(main, is, false, new SignalHandler(signal1));
TransferTasks.readTodos(main, is, false, new SignalHandler(signal1));
try {
signal1.await(ApiTest.TIMEOUT, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Expand All @@ -115,8 +115,8 @@ public void readAndSaveCustomBugs() {
}
List<Task> tasks = ts.getTasks();
assertEquals(2, tasks.size());
assertTrue(tasks.get(0) instanceof CustomBug);
CustomBug bug = (CustomBug) tasks.get(0);
assertTrue(tasks.get(0) instanceof Todo);
Todo bug = (Todo) tasks.get(0);
bug.close();
try {
assertTrue(TestUtils.clickMenuButton(device, main.getString(R.string.menu_transfer), false, true));
Expand All @@ -135,7 +135,7 @@ public void readAndSaveCustomBugs() {
//
tasks = ts.getTasks();
assertEquals(1, tasks.size());
assertTrue(tasks.get(0) instanceof CustomBug);
assertTrue(tasks.get(0) instanceof Todo);
} finally {
TestUtils.deleteFile(main, TEST_JSON);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/assets/LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Roulette Wheel by Bakunetsu Kaito from the Noun Project

The material design lightbulb from Austin Andrews SIL Open Font License 1.1

The "todo" icon is available on MIT terms from gitlab

The de.blau.android.util.egm96.EGM96.java file is derived from code from NASAs Worldwind and is available on Terms of the NASA OPEN SOURCE AGREEMENT VERSION 1.3, see the directory for the full licence text.

The full license texts are also available online:
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/de/blau/android/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2276,29 +2276,28 @@ public boolean read(Uri fileUri) {
}
});
return true;
case R.id.menu_transfer_read_custom_bugs:
case R.id.menu_transfer_read_todos:
descheduleAutoLock();
SelectFile.read(this, R.string.config_osmPreferredDir_key, new ReadFile() {

private static final long serialVersionUID = 1L;

@Override
public boolean read(Uri fileUri) {
TransferTasks.readCustomBugs(Main.this, fileUri, false, new PostFileReadCallback(Main.this, fileUri.toString()));
TransferTasks.readTodos(Main.this, fileUri, false, new PostFileReadCallback(Main.this, fileUri.toString()));
SelectFile.savePref(prefs, R.string.config_osmPreferredDir_key, fileUri);
map.invalidate();
return true;
}
});
return true;
case R.id.menu_transfer_write_custom_bugs:
case R.id.menu_transfer_write_todos:
descheduleAutoLock();
SelectFile.save(this, R.string.config_osmPreferredDir_key, new SaveFile() {
private static final long serialVersionUID = 1L;

@Override
public boolean save(Uri fileUri) {
TransferTasks.writeCustomBugFile(Main.this, fileUri, null);
TransferTasks.writeTodoFile(Main.this, fileUri, "", true, null);
SelectFile.savePref(prefs, R.string.config_osmPreferredDir_key, fileUri);
return true;
}
Expand Down Expand Up @@ -3351,7 +3350,7 @@ void onSelected() {
*
* @return the description
*/
String getDescription() {
SpannableString getDescription() {
return layer.getDescription(object);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.SubMenu;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ArrayAdapter;
Expand All @@ -28,6 +34,7 @@
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AlertDialog.Builder;
import androidx.appcompat.view.ActionMode;
import androidx.appcompat.widget.PopupMenu;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
Expand All @@ -52,9 +59,13 @@
import de.blau.android.presets.PresetItem;
import de.blau.android.search.Search;
import de.blau.android.services.TrackerService;
import de.blau.android.tasks.BugFragment;
import de.blau.android.tasks.TaskStorage;
import de.blau.android.tasks.Todo;
import de.blau.android.util.Snack;
import de.blau.android.util.ThemeUtils;
import de.blau.android.util.Util;
import de.blau.android.views.CustomAutoCompleteTextView;
import me.zed.elementhistorydialog.ElementHistoryDialog;

/**
Expand All @@ -69,26 +80,31 @@ public abstract class ElementSelectionActionModeCallback extends EasyEditActionM
private static final String DEBUG_TAG = "ElementSelectionActi...";
private static final int MENUITEM_UNDO = 0;
static final int MENUITEM_TAG = 1;
static final int MENUITEM_DELETE = 2;
private static final int MENUITEM_HISTORY_WEB = 3;
private static final int MENUITEM_HISTORY = 4;
static final int MENUITEM_COPY = 5;
static final int MENUITEM_CUT = 6;
private static final int MENUITEM_PASTE_TAGS = 7;
private static final int MENUITEM_CREATE_RELATION = 8;
private static final int MENUITEM_ADD_RELATION_MEMBERS = 9;
private static final int MENUITEM_EXTEND_SELECTION = 10;
private static final int MENUITEM_ELEMENT_INFO = 11;
static final int MENUITEM_TASK = 2;
static final int MENUITEM_DELETE = 3;
private static final int MENUITEM_HISTORY_WEB = 4;
private static final int MENUITEM_HISTORY = 5;
static final int MENUITEM_COPY = 6;
static final int MENUITEM_CUT = 7;
private static final int MENUITEM_PASTE_TAGS = 8;
private static final int MENUITEM_CREATE_RELATION = 9;
private static final int MENUITEM_ADD_RELATION_MEMBERS = 10;
private static final int MENUITEM_EXTEND_SELECTION = 11;
private static final int MENUITEM_ELEMENT_INFO = 12;
protected static final int LAST_REGULAR_MENUITEM = MENUITEM_ELEMENT_INFO;

private static final int MENUITEM_UPLOAD = 31;
static final int MENUITEM_UPLOAD = 31;
protected static final int MENUITEM_SHARE_POSITION = 32;
private static final int MENUITEM_TAG_LAST = 33;
private static final int MENUITEM_ZOOM_TO_SELECTION = 34;
private static final int MENUITEM_SEARCH_OBJECTS = 35;
static final int MENUITEM_ZOOM_TO_SELECTION = 34;
static final int MENUITEM_SEARCH_OBJECTS = 35;
private static final int MENUITEM_CALIBRATE_BAROMETER = 36;
static final int MENUITEM_PREFERENCES = 37;
static final int MENUITEM_JS_CONSOLE = 38;
static final int MENUITEM_ADD_TO_TODO = 39;

private static final int MENUITEM_TODO_CLOSE_AND_NEXT = 70;
private static final int MENUITEM_TASK_CLOSE_ALL = 71;

OsmElement element = null;

Expand Down Expand Up @@ -136,6 +152,15 @@ public boolean onCreateActionMode(ActionMode mode, Menu menu) {
undoView.setOnLongClickListener(undoListener);

menu.add(Menu.NONE, MENUITEM_TAG, Menu.NONE, R.string.menu_tags).setIcon(ThemeUtils.getResIdFromAttribute(main, R.attr.menu_tags));

de.blau.android.layer.tasks.MapOverlay taskLayer = main.getMap().getTaskLayer();
if (taskLayer != null && App.getTaskStorage().hasTasksForElement(element)) {
SubMenu taskMenu = menu.addSubMenu(Menu.NONE, MENUITEM_TASK, Menu.NONE, R.string.layer_tasks)
.setIcon(ThemeUtils.getResIdFromAttribute(main, R.attr.menu_bug));
taskMenu.add(Menu.NONE, MENUITEM_TODO_CLOSE_AND_NEXT, Menu.NONE, "Close and goto next");
taskMenu.add(Menu.NONE, MENUITEM_TASK_CLOSE_ALL, Menu.NONE, "Close all tasks");
}

menu.add(Menu.NONE, MENUITEM_DELETE, Menu.CATEGORY_SYSTEM, R.string.delete).setIcon(ThemeUtils.getResIdFromAttribute(main, R.attr.menu_delete));
if (!(element instanceof Relation)) {
menu.add(Menu.NONE, MENUITEM_COPY, Menu.CATEGORY_SECONDARY, R.string.menu_copy).setIcon(ThemeUtils.getResIdFromAttribute(main, R.attr.menu_copy));
Expand Down Expand Up @@ -163,6 +188,7 @@ public boolean onCreateActionMode(ActionMode mode, Menu menu) {
.setIcon(ThemeUtils.getResIdFromAttribute(main, R.attr.menu_information));
menu.add(GROUP_BASE, MENUITEM_ZOOM_TO_SELECTION, Menu.CATEGORY_SYSTEM | 10, R.string.menu_zoom_to_selection);
menu.add(GROUP_BASE, MENUITEM_SEARCH_OBJECTS, Menu.CATEGORY_SYSTEM | 10, R.string.search_objects_title);
menu.add(GROUP_BASE, MENUITEM_ADD_TO_TODO, Menu.CATEGORY_SYSTEM | 10, R.string.menu_add_to_todo);

uploadItem = menu.add(GROUP_BASE, MENUITEM_UPLOAD, Menu.CATEGORY_SYSTEM | 10, R.string.menu_upload_element);

Expand Down Expand Up @@ -270,6 +296,7 @@ public static boolean setItemVisibility(boolean condition, @NonNull MenuItem ite
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
super.onActionItemClicked(mode, item);
final TaskStorage taskStorage = App.getTaskStorage();
switch (item.getItemId()) {
case MENUITEM_TAG:
main.performTagEdit(element, null, false, false);
Expand Down Expand Up @@ -347,6 +374,9 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
main.descheduleAutoLock();
Search.search(main);
break;
case MENUITEM_ADD_TO_TODO:
addToTodoList(main, Util.wrapInList(element));
break;
case MENUITEM_CALIBRATE_BAROMETER:
Intent intent = new Intent(main, TrackerService.class);
intent.putExtra(TrackerService.CALIBRATE_KEY, true);
Expand All @@ -360,6 +390,28 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
case MENUITEM_JS_CONSOLE:
Main.showJsConsole(main);
break;
case MENUITEM_TODO_CLOSE_AND_NEXT:
final List<Todo> todos = taskStorage.getTodosForElement(element);
if (todos.size() == 1) {
closeTodoAndNext(taskStorage, todos.get(0));
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(main);
builder.setTitle(R.string.select_todo_list);
String[] listNames = new String[todos.size()];
for (int i = 0; i < todos.size(); i++) {
listNames[i] = todos.get(i).getListName(main);
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(main, R.layout.dialog_list_item, listNames);
builder.setAdapter(adapter, (DialogInterface dialog, int which) -> {
closeTodoAndNext(taskStorage, todos.get(which));
});
builder.show();
}
break;
case MENUITEM_TASK_CLOSE_ALL:
taskStorage.closeTasksForElement(element);
main.invalidateMap();
break;
case R.id.undo_action:
// should not happen
Log.d(DEBUG_TAG, "menu undo clicked");
Expand All @@ -371,6 +423,48 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return true;
}

/**
* Close a Todo and start editing the next/nearest one // NOSONAR
*
* @param taskStorage the current TaskStorage
* @param todo the Todo //NOSONAR
*/
private void closeTodoAndNext(@NonNull final TaskStorage taskStorage, @NonNull final Todo todo) {
todo.close();
List<Todo> todoList = taskStorage.getTodos(main, todo.getListName(main));
if (todoList.isEmpty()) {
Snack.toastTopInfo(main, "All todos in the list done");
main.invalidateMap();
} else {
Todo next = todo.getNearest(todoList);
taskStorage.setDirty();
BugFragment.gotoAndEditElement(main, App.getDelegator(), next.getElements().get(0), next.getLon(), next.getLat());
}
}

public static void addToTodoList(FragmentActivity activity, @NonNull List<OsmElement> elements) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("Add element to todo list");
View layout = activity.getLayoutInflater().inflate(R.layout.add_todo, null);
CustomAutoCompleteTextView todoList = layout.findViewById(R.id.todoList);
List<String> todoLists = App.getTaskStorage().getTodoLists(activity);
todoList.setAdapter(new ArrayAdapter<>(activity, R.layout.autocomplete_row, todoLists));
builder.setView(layout);
builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(R.string.add, (DialogInterface dialog, int which) -> {
TaskStorage storage = App.getTaskStorage();
final String name = todoList.getText().toString();
for (OsmElement e : elements) {
Todo todo = new Todo(name, e);
storage.add(todo);
}
if (activity instanceof Main) {
((Main)activity).invalidateMap();
}
});
builder.show();
}

/**
* Element specific delete action
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import de.blau.android.osm.Way;
import de.blau.android.prefs.PrefEditor;
import de.blau.android.search.Search;
import de.blau.android.tasks.TaskStorage;
import de.blau.android.tasks.Todo;
import de.blau.android.util.BentleyOttmannForOsm;
import de.blau.android.util.Coordinates;
import de.blau.android.util.GeoMath;
Expand All @@ -45,9 +47,10 @@ public class ExtendSelectionActionModeCallback extends EasyEditActionModeCallbac
private static final int MENUITEM_ADD_RELATION_MEMBERS = ElementSelectionActionModeCallback.LAST_REGULAR_MENUITEM + 3;
private static final int MENUITEM_ORTHOGONALIZE = ElementSelectionActionModeCallback.LAST_REGULAR_MENUITEM + 4;
private static final int MENUITEM_INTERSECT = ElementSelectionActionModeCallback.LAST_REGULAR_MENUITEM + 5;
private static final int MENUITEM_UPLOAD = 31;
private static final int MENUITEM_ZOOM_TO_SELECTION = 34;
private static final int MENUITEM_SEARCH_OBJECTS = 35;
private static final int MENUITEM_UPLOAD = ElementSelectionActionModeCallback.MENUITEM_UPLOAD;
private static final int MENUITEM_ZOOM_TO_SELECTION = ElementSelectionActionModeCallback.MENUITEM_ZOOM_TO_SELECTION;
private static final int MENUITEM_SEARCH_OBJECTS = ElementSelectionActionModeCallback.MENUITEM_SEARCH_OBJECTS;
private static final int MENUITEM_ADD_TO_TODO = ElementSelectionActionModeCallback.MENUITEM_ADD_TO_TODO;

private List<OsmElement> selection;
private List<OsmElement> sortedWays;
Expand Down Expand Up @@ -204,6 +207,7 @@ public boolean onCreateActionMode(@NonNull ActionMode mode, @NonNull Menu menu)

menu.add(GROUP_BASE, MENUITEM_ZOOM_TO_SELECTION, Menu.CATEGORY_SYSTEM | 10, R.string.menu_zoom_to_selection);
menu.add(GROUP_BASE, MENUITEM_SEARCH_OBJECTS, Menu.CATEGORY_SYSTEM | 10, R.string.search_objects_title);
menu.add(GROUP_BASE, MENUITEM_ADD_TO_TODO, Menu.CATEGORY_SYSTEM | 10, R.string.menu_add_to_todo);

uploadItem = menu.add(GROUP_BASE, MENUITEM_UPLOAD, Menu.CATEGORY_SYSTEM | 10, R.string.menu_upload_elements);

Expand Down Expand Up @@ -342,6 +346,8 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
case MENUITEM_SEARCH_OBJECTS:
Search.search(main);
break;
case MENUITEM_ADD_TO_TODO:
ElementSelectionActionModeCallback.addToTodoList(main, selection);
case MENUITEM_UPLOAD:
main.descheduleAutoLock();
main.confirmUpload(ElementSelectionActionModeCallback.addRequiredElements(main, new ArrayList<>(selection)));
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/blau/android/layer/ClickableInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import android.text.SpannableString;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
Expand Down Expand Up @@ -55,5 +56,5 @@ public interface ClickableInterface<V> {
* @param object the Object from this layer
* @return the description
*/
String getDescription(@NonNull final V object);
SpannableString getDescription(@NonNull final V object);
}
5 changes: 3 additions & 2 deletions src/main/java/de/blau/android/layer/geojson/MapOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import android.graphics.Path;
import android.net.Uri;
import android.os.Bundle;
import android.text.SpannableString;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -809,15 +810,15 @@ public void onSelected(FragmentActivity activity, Feature f) {
}

@Override
public String getDescription(Feature f) {
public SpannableString getDescription(Feature f) {
String label = getLabel(f);
if (label == null || "".equals(label)) {
Geometry g = f.geometry();
if (g != null) {
label = g.type();
}
}
return map.getContext().getString(R.string.geojson_object, label, getName());
return new SpannableString(map.getContext().getString(R.string.geojson_object, label, getName()));
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/de/blau/android/layer/gpx/MapOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.location.Location;
import android.location.LocationManager;
import android.net.Uri;
import android.text.SpannableString;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -349,8 +350,8 @@ public void onSelected(FragmentActivity activity, WayPoint wp) {
}

@Override
public String getDescription(WayPoint wp) {
return wp.getShortDescription(map.getContext());
public SpannableString getDescription(WayPoint wp) {
return new SpannableString(wp.getShortDescription(map.getContext()));
}

@Override
Expand Down
Loading

0 comments on commit 8faf202

Please sign in to comment.