Skip to content

Commit f7164d0

Browse files
authored
Fix #5246: map icon in Upload Wizard indicating if location is included in the EXIF data (#5343)
* Add XML map icons with a tick/question mark for the Upload Wizard The existing map icon may not be intuitive enough to indicate whether the location EXIF data will be included The two new XML map icons are intended to indicate the status of location sharing with the location data in the Upload Wizard * Label the map icon in the Upload Wizard if location is included If an image is capture with the in-app camera, the location in the image metadata by default If so, the map icon in the Upload Wizard should be labelled with a green tick during initialisation of its UploadMediaDetailFragment instance * Update the map icon in Upload Wizard if location is pin-pointed If the user selects images from the device storage to upload, the location EXIF data might originally not be included The map icon is labelled with a red question mark After pin-pointing the location manully, the map icon should be labelled with a green tick instead * Fix Upload Wizard map icon XML rendering failure SVG path is invalid, resulting in failure to render the icons Also imports are required for UploadMediaDetailFragment to use Drawable objects and R objects * Add hasLocation() to UploadableFile to indicate existence of EXIF When an image is chosen from the album to the Upload Wizard, its EXIF might contain location data. hasLocation() and fix of init() in UploadMediaDetailFragment ensures that the map icon is shown correctly * Fix init() NullPointerException in UploadMediaDetailFragment * Fix comment typo in UploadMediaDetailFragment Fix the comment about red and green labels for the map icon * Use SLF4J logging for try-catch clauses in UploadableFile class Instead of using printStackTrace(), error directed to logcat * Use Timber for logging in UploadableFile Clean up the catch clause in hasLocation() and getDataTimeFromExif()
1 parent 64652b9 commit f7164d0

File tree

6 files changed

+90
-13
lines changed

6 files changed

+90
-13
lines changed

app/src/main/java/fr/free/nrw/commons/filepicker/UploadableFile.java

+23-12
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
import androidx.annotation.Nullable;
1111
import androidx.exifinterface.media.ExifInterface;
1212

13+
import fr.free.nrw.commons.upload.FileUtils;
1314
import java.io.File;
1415
import java.io.IOException;
15-
import java.text.ParseException;
16-
import java.text.SimpleDateFormat;
1716
import java.util.Date;
18-
19-
import fr.free.nrw.commons.upload.FileUtils;
17+
import timber.log.Timber;
2018

2119
public class UploadableFile implements Parcelable {
2220
public static final Creator<UploadableFile> CREATOR = new Creator<UploadableFile>() {
@@ -74,7 +72,6 @@ public int describeContents() {
7472
return 0;
7573
}
7674

77-
7875
/**
7976
* First try to get the file creation date from EXIF else fall back to CP
8077
* @param context
@@ -118,6 +115,24 @@ private DateTimeWithSource getFileCreatedDateFromCP(Context context) {
118115
}
119116
}
120117

118+
/**
119+
* Indicate whether the EXIF contains the location (both latitude and longitude).
120+
*
121+
* @return whether the location exists for the file's EXIF
122+
*/
123+
public boolean hasLocation() {
124+
try {
125+
ExifInterface exif = new ExifInterface(file.getAbsolutePath());
126+
final String latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
127+
final String longitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
128+
return latitude != null && longitude != null;
129+
} catch (IOException | NumberFormatException | IndexOutOfBoundsException e) {
130+
Timber.tag("UploadableFile");
131+
Timber.d(e);
132+
}
133+
return false;
134+
}
135+
121136
/**
122137
* Get filePath creation date from uri from EXIF
123138
*
@@ -143,13 +158,9 @@ private DateTimeWithSource getDateTimeFromExif() {
143158
}
144159
}
145160
}
146-
147-
} catch (IOException e) {
148-
e.printStackTrace();
149-
} catch (NumberFormatException e) {
150-
e.printStackTrace();
151-
} catch (IndexOutOfBoundsException e) {
152-
e.printStackTrace();
161+
} catch (IOException | NumberFormatException | IndexOutOfBoundsException e) {
162+
Timber.tag("UploadableFile");
163+
Timber.d(e);
153164
}
154165
return null;
155166
}

app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.widget.LinearLayout;
1818
import android.widget.TextView;
1919
import android.widget.Toast;
20+
import android.graphics.drawable.Drawable;
2021
import androidx.annotation.NonNull;
2122
import androidx.annotation.Nullable;
2223
import androidx.appcompat.widget.AppCompatButton;
@@ -47,6 +48,7 @@
4748
import fr.free.nrw.commons.utils.DialogUtil;
4849
import fr.free.nrw.commons.utils.ImageUtils;
4950
import fr.free.nrw.commons.utils.ViewUtil;
51+
import fr.free.nrw.commons.R.drawable.*;
5052
import java.util.List;
5153
import java.util.Locale;
5254
import java.util.Objects;
@@ -180,6 +182,18 @@ private void init() {
180182
btnPrevious.setAlpha(1.0f);
181183
}
182184

185+
// If the image EXIF data contains the location, show the map icon with a green tick
186+
if (inAppPictureLocation != null ||
187+
(uploadableFile != null && uploadableFile.hasLocation())) {
188+
Drawable mapTick = getResources().getDrawable(R.drawable.ic_map_tick_white_24dp);
189+
ibMap.setImageDrawable(mapTick);
190+
} else {
191+
// Otherwise, show the map icon with a red question mark
192+
Drawable mapQuestionMark =
193+
getResources().getDrawable(R.drawable.ic_map_question_white_24dp);
194+
ibMap.setImageDrawable(mapQuestionMark);
195+
}
196+
183197
//If this is the last media, we have nothing to copy, lets not show the button
184198
if (callback.getIndexInViewFlipper(this) == callback.getTotalNumberOfSteps()-4) {
185199
btnCopyToSubsequentMedia.setVisibility(View.GONE);
@@ -188,7 +202,6 @@ private void init() {
188202
}
189203

190204
attachImageViewScaleChangeListener();
191-
192205
}
193206

194207
/**
@@ -540,6 +553,11 @@ public void editLocation(final String latitude, final String longitude, final do
540553
editableUploadItem.getGpsCoords().setDecimalCoords(latitude+"|"+longitude);
541554
editableUploadItem.getGpsCoords().setImageCoordsExists(true);
542555
editableUploadItem.getGpsCoords().setZoomLevel(zoom);
556+
557+
// Replace the map icon using the one with a green tick
558+
Drawable mapTick = getResources().getDrawable(R.drawable.ic_map_tick_white_24dp);
559+
ibMap.setImageDrawable(mapTick);
560+
543561
Toast.makeText(getContext(), "Location Updated", Toast.LENGTH_LONG).show();
544562

545563
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="@dimen/half_standard_height"
3+
android:height="@dimen/half_standard_height"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="@color/button_background_dark"
8+
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"/>
9+
<path
10+
android:fillColor="#FF0000"
11+
android:pathData="m16.544673,17.112357 q 0,-0.811828 0.149547,-1.388654 0.170911,-0.598188 0.555461,-1.132286 0.405915,-0.534097 1.08956,-1.110923 0.833191,-0.705008 1.281834,-1.175014 0.470006,-0.470006 0.66228,-0.918647 0.192275,-0.448643 0.192275,-1.08956 0,-1.0254662 -0.662281,-1.580927 -0.66228,-0.5554621 -1.922751,-0.5554621 -1.04683,0 -1.858659,0.2777304 -0.811828,0.256367 -1.559564,0.6195535 L 13.810094,7.562695 q 0.854556,-0.4486413 1.880023,-0.7477364 1.046831,-0.2990947 2.328665,-0.2990947 2.02957,0 3.140493,1.0041031 1.110922,1.0041034 1.110922,2.734578 0,0.961377 -0.320458,1.64502 -0.299094,0.662282 -0.87592,1.239107 -0.555461,0.555461 -1.324562,1.196378 -0.705008,0.598189 -1.089558,1.046832 -0.363186,0.448641 -0.49137,0.897283 -0.128183,0.427278 -0.128183,1.046831 v 0.363186 h -1.495473 z m -0.491369,3.717318 q 0,-0.790464 0.363186,-1.110923 0.38455,-0.320458 0.961375,-0.320458 0.534098,0 0.918648,0.320458 0.38455,0.320459 0.38455,1.110923 0,0.7691 -0.38455,1.110923 -0.38455,0.341822 -0.918648,0.341822 -0.576825,0 -0.961375,-0.341822 -0.363186,-0.341823 -0.363186,-1.110923z" />
12+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="@dimen/half_standard_height"
3+
android:height="@dimen/half_standard_height"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="#FFFFFFFF"
8+
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"/>
9+
<path
10+
android:fillColor="#FF0000"
11+
android:pathData="m 16.544673,17.112357 q 0,-0.811828 0.149547,-1.388654 0.170911,-0.598188 0.555461,-1.132286 0.405915,-0.534097 1.08956,-1.110923 0.833191,-0.705008 1.281834,-1.175014 0.470006,-0.470006 0.66228,-0.918647 0.192275,-0.448643 0.192275,-1.08956 0,-1.0254662 -0.662281,-1.580927 -0.66228,-0.5554621 -1.922751,-0.5554621 -1.04683,0 -1.858659,0.2777304 -0.811828,0.256367 -1.559564,0.6195535 L 13.810094,7.562695 q 0.854556,-0.4486413 1.880023,-0.7477364 1.046831,-0.2990947 2.328665,-0.2990947 2.02957,0 3.140493,1.0041031 1.110922,1.0041034 1.110922,2.734578 0,0.961377 -0.320458,1.64502 -0.299094,0.662282 -0.87592,1.239107 -0.555461,0.555461 -1.324562,1.196378 -0.705008,0.598189 -1.089558,1.046832 -0.363186,0.448641 -0.49137,0.897283 -0.128183,0.427278 -0.128183,1.046831 v 0.363186 h -1.495473 z m -0.491369,3.717318 q 0,-0.790464 0.363186,-1.110923 0.38455,-0.320458 0.961375,-0.320458 0.534098,0 0.918648,0.320458 0.38455,0.320459 0.38455,1.110923 0,0.7691 -0.38455,1.110923 -0.38455,0.341822 -0.918648,0.341822 -0.576825,0 -0.961375,-0.341822 -0.363186,-0.341823 -0.363186,-1.110923 z" />
12+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="@dimen/half_standard_height"
3+
android:height="@dimen/half_standard_height"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="@color/button_background_dark"
8+
android:pathData="M20.5,3m-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"/>
9+
<path
10+
android:fillColor="#00FF00"
11+
android:pathData="m 11.168943,16.76403 q 0.481743,0 0.728791,0.790553 0.494095,1.482287 0.704086,1.482287 0.160581,0 0.333515,-0.247048 3.471022,-5.558576 6.423244,-8.9925417 Q 20.124427,8.907908 21.792,8.907908 q 0.395277,0 0.531153,0.074114 0.135877,0.074114 0.135877,0.1852859 0,0.1729335 -0.407629,0.6793817 -4.768024,5.7315104 -8.844314,12.1053454 -0.284105,0.444686 -1.161125,0.444686 -0.889372,0 -1.049953,-0.07411 -0.419981,-0.185286 -0.988191,-1.889916 -0.6423249,-1.889916 -0.6423249,-2.37166 0,-0.5188 0.8646679,-1.000544 0.531153,-0.296457 0.938782,-0.296457 z"/>
12+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="@dimen/half_standard_height"
3+
android:height="@dimen/half_standard_height"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="#FFFFFFFF"
8+
android:pathData="M20.5,3m-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"/>
9+
<path
10+
android:fillColor="#00FF00"
11+
android:pathData="m 11.168943,16.76403 q 0.481743,0 0.728791,0.790553 0.494095,1.482287 0.704086,1.482287 0.160581,0 0.333515,-0.247048 3.471022,-5.558576 6.423244,-8.9925417 Q 20.124427,8.907908 21.792,8.907908 q 0.395277,0 0.531153,0.074114 0.135877,0.074114 0.135877,0.1852859 0,0.1729335 -0.407629,0.6793817 -4.768024,5.7315104 -8.844314,12.1053454 -0.284105,0.444686 -1.161125,0.444686 -0.889372,0 -1.049953,-0.07411 -0.419981,-0.185286 -0.988191,-1.889916 -0.6423249,-1.889916 -0.6423249,-2.37166 0,-0.5188 0.8646679,-1.000544 0.531153,-0.296457 0.938782,-0.296457 z"/>
12+
</vector>

0 commit comments

Comments
 (0)