mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
After implementing UI also
This commit is contained in:
parent
8f0584534d
commit
824501f6ce
3 changed files with 205 additions and 5 deletions
|
|
@ -17,6 +17,7 @@ import android.support.annotation.RequiresApi;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.graphics.drawable.VectorDrawableCompat;
|
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
@ -58,7 +59,7 @@ import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.NO_DUPLICATE;
|
||||||
public class ShareActivity
|
public class ShareActivity
|
||||||
extends AuthenticatedActivity
|
extends AuthenticatedActivity
|
||||||
implements SingleUploadFragment.OnUploadActionInitiated,
|
implements SingleUploadFragment.OnUploadActionInitiated,
|
||||||
OnCategoriesSaveHandler {
|
OnCategoriesSaveHandler,SimilarImageDialogFragment.onResponse {
|
||||||
|
|
||||||
private static final int REQUEST_PERM_ON_CREATE_STORAGE = 1;
|
private static final int REQUEST_PERM_ON_CREATE_STORAGE = 1;
|
||||||
private static final int REQUEST_PERM_ON_CREATE_LOCATION = 2;
|
private static final int REQUEST_PERM_ON_CREATE_LOCATION = 2;
|
||||||
|
|
@ -80,6 +81,7 @@ public class ShareActivity
|
||||||
private boolean cacheFound;
|
private boolean cacheFound;
|
||||||
|
|
||||||
private GPSExtractor imageObj;
|
private GPSExtractor imageObj;
|
||||||
|
private GPSExtractor tempImageObj;
|
||||||
private String decimalCoords;
|
private String decimalCoords;
|
||||||
|
|
||||||
private boolean useNewPermissions = false;
|
private boolean useNewPermissions = false;
|
||||||
|
|
@ -486,7 +488,10 @@ public class ShareActivity
|
||||||
Timber.d("EXIF:false");
|
Timber.d("EXIF:false");
|
||||||
findOtherImages(gpsEnabled);
|
findOtherImages(gpsEnabled);
|
||||||
}
|
}
|
||||||
useImageCoords();
|
else {
|
||||||
|
// As the selected image has GPS data in EXIF go ahead with the same.
|
||||||
|
useImageCoords();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Timber.w("File not found: " + mediaUri, e);
|
Timber.w("File not found: " + mediaUri, e);
|
||||||
|
|
@ -498,15 +503,14 @@ public class ShareActivity
|
||||||
String filePath = getPathOfMediaOrCopy();
|
String filePath = getPathOfMediaOrCopy();
|
||||||
long timeOfCreation = new File(filePath).lastModified();//Time when the original image was created
|
long timeOfCreation = new File(filePath).lastModified();//Time when the original image was created
|
||||||
File folder = new File(filePath.substring(0,filePath.lastIndexOf('/')));
|
File folder = new File(filePath.substring(0,filePath.lastIndexOf('/')));
|
||||||
// Timber.d("folderath"+folderPath);
|
|
||||||
File[] files = folder.listFiles();
|
File[] files = folder.listFiles();
|
||||||
Timber.d("folder:"+files.length);
|
Timber.d("folderTime Number:"+files.length);
|
||||||
|
|
||||||
for(File file : files){
|
for(File file : files){
|
||||||
if(file.lastModified()-timeOfCreation<=(120*1000) && file.lastModified()-timeOfCreation>=-(120*1000)){
|
if(file.lastModified()-timeOfCreation<=(120*1000) && file.lastModified()-timeOfCreation>=-(120*1000)){
|
||||||
//Make sure the photos were taken within 20seconds
|
//Make sure the photos were taken within 20seconds
|
||||||
Timber.d("fild date:"+file.lastModified()+ " time of creation"+timeOfCreation);
|
Timber.d("fild date:"+file.lastModified()+ " time of creation"+timeOfCreation);
|
||||||
GPSExtractor tempImageObj = null;//Temporary GPSExtractor to extract coords from these photos
|
tempImageObj = null;//Temporary GPSExtractor to extract coords from these photos
|
||||||
ParcelFileDescriptor descriptor
|
ParcelFileDescriptor descriptor
|
||||||
= null;
|
= null;
|
||||||
try {
|
try {
|
||||||
|
|
@ -529,12 +533,37 @@ public class ShareActivity
|
||||||
if(tempImageObj.getCoords(gpsEnabled)!=null && tempImageObj.imageCoordsExists){
|
if(tempImageObj.getCoords(gpsEnabled)!=null && tempImageObj.imageCoordsExists){
|
||||||
// Current image has gps coordinates and it's not current gps locaiton
|
// Current image has gps coordinates and it's not current gps locaiton
|
||||||
Timber.d("This fild has image coords:"+ file.getAbsolutePath());
|
Timber.d("This fild has image coords:"+ file.getAbsolutePath());
|
||||||
|
// Create a dialog fragment for the suggestion
|
||||||
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
|
SimilarImageDialogFragment newFragment = new SimilarImageDialogFragment();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putString("originalImagePath",filePath);
|
||||||
|
args.putString("possibleImagePath",file.getAbsolutePath());
|
||||||
|
newFragment.setArguments(args);
|
||||||
|
newFragment.show(fragmentManager, "dialog");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPostiveResponse() {
|
||||||
|
imageObj = tempImageObj;
|
||||||
|
decimalCoords = imageObj.getCoords(false);// Not necessary to use gps as image already ha EXIF data
|
||||||
|
Timber.d("EXIF from tempImageObj");
|
||||||
|
useImageCoords();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNegativeResponse() {
|
||||||
|
Timber.d("EXIF from imageObj");
|
||||||
|
useImageCoords();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -604,4 +633,6 @@ public class ShareActivity
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
package fr.free.nrw.commons.upload;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
|
||||||
|
import com.facebook.drawee.view.SimpleDraweeView;
|
||||||
|
import com.facebook.imagepipeline.listener.RequestListener;
|
||||||
|
import com.facebook.imagepipeline.listener.RequestLoggingListener;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by harisanker on 14/2/18.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SimilarImageDialogFragment extends DialogFragment {
|
||||||
|
SimpleDraweeView originalImage;
|
||||||
|
SimpleDraweeView possibleImage;
|
||||||
|
Button positiveButton;
|
||||||
|
Button negativeButton;
|
||||||
|
onResponse mOnResponse;//Implemented interface from shareActivity
|
||||||
|
Boolean gotResponse = false;
|
||||||
|
public SimilarImageDialogFragment() {
|
||||||
|
}
|
||||||
|
public interface onResponse{
|
||||||
|
public void onPostiveResponse();
|
||||||
|
public void onNegativeResponse();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.fragment_similar_image_dialog, container, false);
|
||||||
|
Set<RequestListener> requestListeners = new HashSet<>();
|
||||||
|
requestListeners.add(new RequestLoggingListener());
|
||||||
|
|
||||||
|
originalImage =(SimpleDraweeView) view.findViewById(R.id.orginalImage);
|
||||||
|
possibleImage =(SimpleDraweeView) view.findViewById(R.id.possibleImage);
|
||||||
|
positiveButton = (Button) view.findViewById(R.id.postive_button);
|
||||||
|
negativeButton = (Button) view.findViewById(R.id.negative_button);
|
||||||
|
|
||||||
|
originalImage.setHierarchy(GenericDraweeHierarchyBuilder
|
||||||
|
.newInstance(getResources())
|
||||||
|
.setPlaceholderImage(VectorDrawableCompat.create(getResources(),
|
||||||
|
R.drawable.ic_image_black_24dp,getContext().getTheme()))
|
||||||
|
.setFailureImage(VectorDrawableCompat.create(getResources(),
|
||||||
|
R.drawable.ic_error_outline_black_24dp, getContext().getTheme()))
|
||||||
|
.build());
|
||||||
|
possibleImage.setHierarchy(GenericDraweeHierarchyBuilder
|
||||||
|
.newInstance(getResources())
|
||||||
|
.setPlaceholderImage(VectorDrawableCompat.create(getResources(),
|
||||||
|
R.drawable.ic_image_black_24dp,getContext().getTheme()))
|
||||||
|
.setFailureImage(VectorDrawableCompat.create(getResources(),
|
||||||
|
R.drawable.ic_error_outline_black_24dp, getContext().getTheme()))
|
||||||
|
.build());
|
||||||
|
|
||||||
|
originalImage.setImageURI(Uri.fromFile(new File(getArguments().getString("originalImagePath"))));
|
||||||
|
possibleImage.setImageURI(Uri.fromFile(new File(getArguments().getString("possibleImagePath"))));
|
||||||
|
|
||||||
|
negativeButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
mOnResponse.onNegativeResponse();
|
||||||
|
gotResponse = true;
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
positiveButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
mOnResponse.onPostiveResponse();
|
||||||
|
gotResponse = true;
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
mOnResponse = (onResponse) getActivity();//Interface Implementation
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
Dialog dialog = super.onCreateDialog(savedInstanceState);
|
||||||
|
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDismiss(DialogInterface dialog) {
|
||||||
|
// I user dismisses dialog by pressing outside the dialog.
|
||||||
|
if(!gotResponse)
|
||||||
|
mOnResponse.onNegativeResponse();
|
||||||
|
super.onDismiss(dialog);
|
||||||
|
}
|
||||||
|
}
|
||||||
57
app/src/main/res/layout/fragment_similar_image_dialog.xml
Normal file
57
app/src/main/res/layout/fragment_similar_image_dialog.xml
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
<com.facebook.drawee.view.SimpleDraweeView
|
||||||
|
android:id="@+id/orginalImage"
|
||||||
|
android:layout_width="160dp"
|
||||||
|
android:layout_height="240dp"
|
||||||
|
android:layout_margin="3dp"
|
||||||
|
app:actualImageScaleType="centerCrop" />
|
||||||
|
<com.facebook.drawee.view.SimpleDraweeView
|
||||||
|
android:id="@+id/possibleImage"
|
||||||
|
android:layout_width="160dp"
|
||||||
|
android:layout_height="240dp"
|
||||||
|
android:layout_margin="3dp"
|
||||||
|
app:actualImageScaleType="centerCrop" />
|
||||||
|
</LinearLayout>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="6dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:text="Did you shoot these two pictures at the same place? Do you want to use the latitude/longitude of the picture on the right?"/>
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<View
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
<Button
|
||||||
|
style="@style/Widget.AppCompat.Button.Borderless"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_gravity="right"
|
||||||
|
android:id="@+id/negative_button"
|
||||||
|
android:layout_marginRight="3dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="No" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
style="@style/Widget.AppCompat.Button.Borderless"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/postive_button"
|
||||||
|
android:layout_gravity="right"
|
||||||
|
android:layout_marginLeft="3dp"
|
||||||
|
android:text="Yes" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue