Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5246: map icon in Upload Wizard indicating if location is included in the EXIF data #5343

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
import androidx.annotation.Nullable;
import androidx.exifinterface.media.ExifInterface;

import com.mapbox.mapboxsdk.style.expressions.Expression.NumberFormatOption;
import fr.free.nrw.commons.location.LatLng;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import fr.free.nrw.commons.upload.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UploadableFile implements Parcelable {
public static final Creator<UploadableFile> CREATOR = new Creator<UploadableFile>() {
Expand Down Expand Up @@ -74,6 +78,7 @@ public int describeContents() {
return 0;
}

private static final Logger logger = LoggerFactory.getLogger(UploadableFile.class);

/**
* First try to get the file creation date from EXIF else fall back to CP
Expand Down Expand Up @@ -118,6 +123,27 @@ private DateTimeWithSource getFileCreatedDateFromCP(Context context) {
}
}

/**
* Indicate whether the EXIF contains the location (both latitude and longitude).
*
* @return whether the location exists for the file's EXIF
*/
public boolean hasLocation() {
try {
ExifInterface exif = new ExifInterface(file.getAbsolutePath());
final String latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
final String longitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
return latitude != null && longitude != null;
} catch (IOException e) {
logger.error("hasLocation IOException: ", e);
} catch (NumberFormatException e) {
logger.error("hasLocation NumberFormatException: ", e);
} catch (IndexOutOfBoundsException e) {
logger.error("hasLocation IndexOutOfBoundsException: ", e);
}
return false;
}

/**
* Get filePath creation date from uri from EXIF
*
Expand All @@ -143,13 +169,12 @@ private DateTimeWithSource getDateTimeFromExif() {
}
}
}

} catch (IOException e) {
e.printStackTrace();
logger.error("hasLocation IOException: ", e);
} catch (NumberFormatException e) {
e.printStackTrace();
logger.error("hasLocation NumberFormatException: ", e);
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();
logger.error("hasLocation IndexOutOfBoundsException: ", e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatButton;
Expand Down Expand Up @@ -47,6 +48,7 @@
import fr.free.nrw.commons.utils.DialogUtil;
import fr.free.nrw.commons.utils.ImageUtils;
import fr.free.nrw.commons.utils.ViewUtil;
import fr.free.nrw.commons.R.drawable.*;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
Expand Down Expand Up @@ -180,6 +182,18 @@ private void init() {
btnPrevious.setAlpha(1.0f);
}

// If the image EXIF data contains the location, show the map icon with a green tick
if (inAppPictureLocation != null ||
(uploadableFile != null && uploadableFile.hasLocation())) {
Drawable mapTick = getResources().getDrawable(R.drawable.ic_map_tick_white_24dp);
ibMap.setImageDrawable(mapTick);
} else {
// Otherwise, show the map icon with a red question mark
Drawable mapQuestionMark =
getResources().getDrawable(R.drawable.ic_map_question_white_24dp);
ibMap.setImageDrawable(mapQuestionMark);
}

//If this is the last media, we have nothing to copy, lets not show the button
if (callback.getIndexInViewFlipper(this) == callback.getTotalNumberOfSteps()-4) {
btnCopyToSubsequentMedia.setVisibility(View.GONE);
Expand All @@ -188,7 +202,6 @@ private void init() {
}

attachImageViewScaleChangeListener();

}

/**
Expand Down Expand Up @@ -540,6 +553,11 @@ public void editLocation(final String latitude, final String longitude, final do
editableUploadItem.getGpsCoords().setDecimalCoords(latitude+"|"+longitude);
editableUploadItem.getGpsCoords().setImageCoordsExists(true);
editableUploadItem.getGpsCoords().setZoomLevel(zoom);

// Replace the map icon using the one with a green tick
Drawable mapTick = getResources().getDrawable(R.drawable.ic_map_tick_white_24dp);
ibMap.setImageDrawable(mapTick);

Toast.makeText(getContext(), "Location Updated", Toast.LENGTH_LONG).show();

}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_map_question_dark_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="@dimen/half_standard_height"
android:height="@dimen/half_standard_height"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/button_background_dark"
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"/>
<path
android:fillColor="#FF0000"
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" />
</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_map_question_white_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="@dimen/half_standard_height"
android:height="@dimen/half_standard_height"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
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"/>
<path
android:fillColor="#FF0000"
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" />
</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_map_tick_dark_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="@dimen/half_standard_height"
android:height="@dimen/half_standard_height"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/button_background_dark"
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"/>
<path
android:fillColor="#00FF00"
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"/>
</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_map_tick_white_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="@dimen/half_standard_height"
android:height="@dimen/half_standard_height"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
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"/>
<path
android:fillColor="#00FF00"
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"/>
</vector>