Skip to content

Commit 93f5c83

Browse files
committed
Merge branch 'dev'
2 parents 6a8912d + 608c32b commit 93f5c83

File tree

32 files changed

+604
-84
lines changed

32 files changed

+604
-84
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ See the [OSM Wiki page](https://wiki.openstreetmap.org/wiki/GeoNotes) for detail
2222

2323
* Create, move and delete notes
2424
* Attach photos to note
25+
* List of all notes
2526
* Export all notes in GeoJson format
2627
* Show and follow current location
2728

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "de.hauke_stieler.geonotes"
1111
minSdkVersion 16
1212
targetSdkVersion 30
13-
versionCode 1003002
14-
versionName "1.3.2"
13+
versionCode 1004000
14+
versionName "1.4.0"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
}
@@ -37,7 +37,7 @@ android {
3737
dependencies {
3838
implementation 'org.osmdroid:osmdroid-android:6.1.8'
3939

40-
implementation 'androidx.appcompat:appcompat:1.2.0'
40+
implementation 'androidx.appcompat:appcompat:1.3.0'
4141
implementation 'com.google.android.material:material:1.3.0'
4242
implementation 'androidx.preference:preference:1.1.1'
4343
implementation 'org.apache.commons:commons-text:1.9'

app/src/androidTest/java/de/hauke_stieler/geonotes/ExampleInstrumentedTest.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
android:roundIcon="@mipmap/ic_launcher"
2121
android:supportsRtl="true"
2222
android:theme="@style/Theme.GeoNotes">
23+
<activity android:name=".note_list.NoteListActivity"></activity>
2324
<activity
2425
android:name=".settings.SettingsActivity"
2526
android:label="@string/title_activity_settings" />

app/src/main/java/de/hauke_stieler/geonotes/Injector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface ClassBuilder<T> {
2828
*/
2929
public class Injector {
3030
protected static Map<Class, Object> classes = new HashMap<>();
31-
private static Map<Class, ClassBuilder> classBuilders = new HashMap<>();
31+
protected static Map<Class, ClassBuilder> classBuilders = new HashMap<>();
3232
private static Context context;
3333
private static Activity activity;
3434

app/src/main/java/de/hauke_stieler/geonotes/MainActivity.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@
4444
import de.hauke_stieler.geonotes.map.Map;
4545
import de.hauke_stieler.geonotes.map.MarkerWindow;
4646
import de.hauke_stieler.geonotes.map.TouchDownListener;
47+
import de.hauke_stieler.geonotes.note_list.NoteListActivity;
4748
import de.hauke_stieler.geonotes.photo.ThumbnailUtil;
4849
import de.hauke_stieler.geonotes.settings.SettingsActivity;
4950

5051
public class MainActivity extends AppCompatActivity {
5152

52-
private final int REQUEST_PERMISSIONS_REQUEST_CODE = 1;
53-
private final int REQUEST_CAMERA_PERMISSIONS_REQUEST_CODE = 2;
54-
static final int REQUEST_IMAGE_CAPTURE = 1;
53+
private static final int REQUEST_NOTE_LIST_REQUEST_CODE = 4;
54+
private static final int REQUEST_PERMISSIONS_REQUEST_CODE = 3;
55+
private static final int REQUEST_CAMERA_PERMISSIONS_REQUEST_CODE = 2;
56+
private static final int REQUEST_IMAGE_CAPTURE = 1;
5557

5658
private Map map;
5759
private SharedPreferences preferences;
@@ -154,6 +156,9 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
154156
case R.id.toolbar_btn_settings:
155157
startActivity(new Intent(this, SettingsActivity.class));
156158
return true;
159+
case R.id.toolbar_btn_note_list:
160+
startActivityForResult(new Intent(this, NoteListActivity.class), REQUEST_NOTE_LIST_REQUEST_CODE);
161+
return true;
157162
default:
158163
return super.onOptionsItemSelected(item);
159164
}
@@ -275,11 +280,21 @@ private boolean hasPermission(String permission) {
275280
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
276281
super.onActivityResult(requestCode, resultCode, data);
277282

278-
// If photo-Intent was successful
279-
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
280-
addPhotoToDatabase(lastPhotoNoteId, lastPhotoFile);
281-
addPhotoToGallery(lastPhotoFile);
282-
map.addImagesToMarkerWindow();
283+
// If Intent was successful
284+
if (resultCode == RESULT_OK) {
285+
switch (requestCode) {
286+
case REQUEST_IMAGE_CAPTURE:
287+
addPhotoToDatabase(lastPhotoNoteId, lastPhotoFile);
288+
addPhotoToGallery(lastPhotoFile);
289+
map.addImagesToMarkerWindow();
290+
break;
291+
case REQUEST_NOTE_LIST_REQUEST_CODE:
292+
long selectedNoteId = data.getLongExtra(NoteListActivity.EXTRA_CLICKED_NOTE, -1L);
293+
if (selectedNoteId != -1) {
294+
map.selectNote(selectedNoteId);
295+
}
296+
break;
297+
}
283298
}
284299
}
285300

app/src/main/java/de/hauke_stieler/geonotes/database/Database.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public List<String> getPhotos(String noteId) {
6868
return photoStore.getPhotos(getReadableDatabase(), noteId);
6969
}
7070

71+
public boolean hasPhotos(long noteId) {
72+
return hasPhotos("" + noteId);
73+
}
74+
7175
public boolean hasPhotos(String noteId) {
7276
return getPhotos(noteId).size() > 0;
7377
}

app/src/main/java/de/hauke_stieler/geonotes/map/Map.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@
2222
import org.osmdroid.views.MapView;
2323
import org.osmdroid.views.overlay.MapEventsOverlay;
2424
import org.osmdroid.views.overlay.Marker;
25+
import org.osmdroid.views.overlay.Overlay;
2526
import org.osmdroid.views.overlay.ScaleBarOverlay;
2627
import org.osmdroid.views.overlay.compass.CompassOverlay;
2728
import org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider;
2829
import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider;
2930
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;
3031

3132
import java.io.File;
33+
import java.util.ArrayList;
3234
import java.util.List;
35+
import java.util.stream.Collectors;
3336

3437
import de.hauke_stieler.geonotes.database.Database;
3538
import de.hauke_stieler.geonotes.R;
@@ -91,7 +94,7 @@ public Map(Context context,
9194
createMarkerWindow(map);
9295

9396
for (Note n : this.database.getAllNotes()) {
94-
Marker marker = createMarker("" + n.getId(), n.getDescription(), new GeoPoint(n.getLat(), n.getLon()), markerClickListener);
97+
createMarker("" + n.getId(), n.getDescription(), new GeoPoint(n.getLat(), n.getLon()), markerClickListener);
9598
}
9699
}
97100

@@ -123,13 +126,6 @@ private void createOverlays(Context context, MapView map, BitmapDrawable locatio
123126
return true;
124127
}
125128

126-
// If a marker is currently selected -> deselect it
127-
if (markerInfoWindow.getSelectedMarker() != null) {
128-
setNormalIcon(markerInfoWindow.getSelectedMarker());
129-
// We don't need to deselect the marker or close the window as we will directly assign a new marker below
130-
}
131-
132-
centerLocationWithOffset(marker.getPosition());
133129
selectMarker(marker);
134130

135131
return true;
@@ -164,8 +160,6 @@ public boolean singleTapConfirmedHelper(GeoPoint p) {
164160
}
165161
}
166162

167-
centerLocationWithOffset(p);
168-
169163
return false;
170164
}
171165

@@ -255,6 +249,15 @@ private GeoPoint snapToGpsLocation(GeoPoint location) {
255249
return location;
256250
}
257251

252+
public void selectNote(long noteId) {
253+
String noteIdString = "" + noteId;
254+
for (Overlay marker : map.getOverlays()) {
255+
if (marker instanceof Marker && ((Marker) marker).getId().equals(noteIdString)) {
256+
this.selectMarker((Marker) marker);
257+
}
258+
}
259+
}
260+
258261
private void selectMarker(Marker marker) {
259262
// Reset icon of previous selection
260263
Marker selectedMarker = markerInfoWindow.getSelectedMarker();
@@ -268,6 +271,12 @@ private void selectMarker(Marker marker) {
268271
markerInfoWindow.focusEditField();
269272

270273
addImagesToMarkerWindow();
274+
275+
zoomToLocation(marker.getPosition(), map.getZoomLevelDouble());
276+
}
277+
278+
private Marker getSelectedMarker() {
279+
return markerInfoWindow.getSelectedMarker();
271280
}
272281

273282
/**
@@ -317,11 +326,7 @@ public void setMapScaleFactor(float factor) {
317326
map.setTilesScaleFactor(factor);
318327
}
319328

320-
private void centerLocationWithOffset(GeoPoint p) {
321-
centerLocationWithOffset(p, map.getZoomLevelDouble());
322-
}
323-
324-
private void centerLocationWithOffset(GeoPoint p, double zoom) {
329+
private void zoomToLocation(GeoPoint p, double zoom) {
325330
Point locationInPixels = new Point();
326331
map.getProjection().toPixels(p, locationInPixels);
327332
IGeoPoint newPoint = map.getProjection().fromPixels(locationInPixels.x, locationInPixels.y);
@@ -353,6 +358,13 @@ public void onResume() {
353358
if (!wakeLock.isHeld()) {
354359
wakeLock.acquire();
355360
}
361+
362+
// Before resuming (e.g. when switching back from the list of notes to the main activity),
363+
// the map doesn't zoom to markers. Therefore we here zoom to the currently selected marker.
364+
Marker selectedMarker = getSelectedMarker();
365+
if (selectedMarker != null) {
366+
zoomToLocation(selectedMarker.getPosition(), map.getZoomLevelDouble());
367+
}
356368
}
357369

358370
public void onPause() {
@@ -365,22 +377,12 @@ public void onDestroy() {
365377
}
366378
}
367379

368-
public void setLatitude(float lat) {
369-
double lon = map.getMapCenter().getLongitude();
370-
centerLocationWithOffset(new GeoPoint(lat, lon));
371-
}
372-
373-
public void setLongitude(float lon) {
374-
double lat = map.getMapCenter().getLatitude();
375-
centerLocationWithOffset(new GeoPoint(lat, lon));
376-
}
377-
378380
public IGeoPoint getLocation() {
379381
return map.getMapCenter();
380382
}
381383

382384
public void setLocation(float lat, float lon, float zoom) {
383-
centerLocationWithOffset(new GeoPoint(lat, lon), zoom);
385+
zoomToLocation(new GeoPoint(lat, lon), zoom);
384386
}
385387

386388
public float getZoom() {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package de.hauke_stieler.geonotes.note_list;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
import androidx.appcompat.widget.Toolbar;
5+
6+
import android.app.Activity;
7+
import android.content.Intent;
8+
import android.content.SharedPreferences;
9+
import android.os.Bundle;
10+
import android.widget.ListView;
11+
12+
import java.util.ArrayList;
13+
import java.util.HashMap;
14+
import java.util.List;
15+
import java.util.Map;
16+
17+
import de.hauke_stieler.geonotes.Injector;
18+
import de.hauke_stieler.geonotes.R;
19+
import de.hauke_stieler.geonotes.database.Database;
20+
import de.hauke_stieler.geonotes.notes.Note;
21+
22+
public class NoteListActivity extends AppCompatActivity {
23+
public static final String EXTRA_CLICKED_NOTE = "clicked_note";
24+
25+
private SharedPreferences preferences;
26+
private Database database;
27+
28+
@Override
29+
protected void onCreate(Bundle savedInstanceState) {
30+
super.onCreate(savedInstanceState);
31+
setContentView(R.layout.activity_note_list);
32+
33+
Toolbar toolbar = findViewById(R.id.toolbar);
34+
setSupportActionBar(toolbar);
35+
36+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
37+
getSupportActionBar().setDisplayShowHomeEnabled(true);
38+
39+
preferences = Injector.get(SharedPreferences.class);
40+
database = Injector.get(Database.class);
41+
42+
load();
43+
}
44+
45+
private void load() {
46+
List<Note> notes = database.getAllNotes();
47+
48+
List<Note> notesWithPhoto = new ArrayList<>();
49+
for (Note note : notes) {
50+
if (database.hasPhotos(note.getId())) {
51+
notesWithPhoto.add(note);
52+
}
53+
}
54+
55+
NoteListAdapter adapter = new NoteListAdapter(this, notes, notesWithPhoto, id -> {
56+
// Close this activity and send back clicked note id
57+
Intent resultIntent = new Intent();
58+
resultIntent.putExtra(EXTRA_CLICKED_NOTE, id);
59+
setResult(Activity.RESULT_OK, resultIntent);
60+
finish();
61+
});
62+
63+
ListView listView = findViewById(R.id.note_list_view);
64+
listView.setAdapter(adapter);
65+
}
66+
67+
@Override
68+
public boolean onSupportNavigateUp() {
69+
finish();
70+
return true;
71+
}
72+
}

0 commit comments

Comments
 (0)