Skip to content

Commit 14a2975

Browse files
committed
Merge branch 'RxFixes3' into RxFixes2
2 parents cfeed69 + c2a20ce commit 14a2975

30 files changed

+235
-500
lines changed

app/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ dependencies {
8888
implementation "androidx.browser:browser:1.0.0"
8989
implementation "androidx.cardview:cardview:1.0.0"
9090
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
91+
implementation "androidx.exifinterface:exifinterface:1.0.0"
9192

9293
//swipe_layout
9394
implementation 'com.daimajia.swipelayout:library:1.2.0@aar'

app/src/main/java/fr/free/nrw/commons/ui/widget/CustomEditText.java

-194
This file was deleted.

app/src/main/java/fr/free/nrw/commons/upload/DescriptionsAdapter.java

+38-32
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
package fr.free.nrw.commons.upload;
22

3+
import android.annotation.SuppressLint;
34
import android.content.Context;
45
import android.graphics.drawable.Drawable;
5-
import androidx.annotation.NonNull;
6-
import androidx.annotation.Nullable;
7-
import androidx.appcompat.widget.AppCompatSpinner;
8-
import androidx.recyclerview.widget.RecyclerView;
96
import android.text.TextUtils;
107
import android.view.LayoutInflater;
8+
import android.view.MotionEvent;
119
import android.view.View;
1210
import android.view.ViewGroup;
1311
import android.widget.AdapterView;
1412
import android.widget.AdapterView.OnItemSelectedListener;
13+
import android.widget.EditText;
1514

1615
import java.util.ArrayList;
1716
import java.util.List;
1817

18+
import androidx.annotation.NonNull;
19+
import androidx.annotation.Nullable;
20+
import androidx.appcompat.widget.AppCompatSpinner;
21+
import androidx.recyclerview.widget.RecyclerView;
1922
import butterknife.BindView;
2023
import butterknife.ButterKnife;
2124
import fr.free.nrw.commons.R;
22-
import fr.free.nrw.commons.ui.widget.CustomEditText;
2325
import fr.free.nrw.commons.utils.AbstractTextWatcher;
2426
import fr.free.nrw.commons.utils.BiMap;
2527
import fr.free.nrw.commons.utils.ViewUtil;
@@ -117,7 +119,7 @@ public class ViewHolder extends RecyclerView.ViewHolder {
117119
AppCompatSpinner spinnerDescriptionLanguages;
118120

119121
@BindView(R.id.description_item_edit_text)
120-
CustomEditText descItemEditText;
122+
EditText descItemEditText;
121123

122124
private View view;
123125

@@ -128,6 +130,7 @@ public ViewHolder(View itemView) {
128130
Timber.i("descItemEditText:" + descItemEditText);
129131
}
130132

133+
@SuppressLint("ClickableViewAccessibility")
131134
public void init(int position) {
132135
if (position == 0) {
133136
Timber.d("Title is " + title);
@@ -150,16 +153,19 @@ public void init(int position) {
150153
}
151154
});
152155

153-
descItemEditText.setDrawableClickListener(target -> {
154-
switch (target) {
155-
case RIGHT:
156-
if (getAdapterPosition() == 0) {
157-
callback.showAlert(R.string.media_detail_title, R.string.title_info);
158-
}
159-
break;
160-
default:
161-
break;
162-
}
156+
descItemEditText.setOnTouchListener((v, event) -> {
157+
// Check this is a touch up event
158+
if(event.getAction() != MotionEvent.ACTION_UP) return false;
159+
160+
// Check we are tapping within 15px of the info icon
161+
int extraTapArea = 15;
162+
Drawable info = descItemEditText.getCompoundDrawables()[2];
163+
int infoHitboxX = descItemEditText.getWidth() - info.getBounds().width();
164+
if (event.getX() + extraTapArea < infoHitboxX) return false;
165+
166+
// If the above are true, show the info dialog
167+
callback.showAlert(R.string.media_detail_title, R.string.title_info);
168+
return true;
163169
});
164170

165171
} else {
@@ -170,10 +176,24 @@ public void init(int position) {
170176
} else {
171177
descItemEditText.setText("");
172178
}
179+
180+
// Show the info icon for the first description
173181
if (position == 1) {
174182
descItemEditText.setCompoundDrawablesWithIntrinsicBounds(null, null, getInfoIcon(), null);
175-
} else {
176-
descItemEditText.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
183+
descItemEditText.setOnTouchListener((v, event) -> {
184+
// Check this is a touch up event
185+
if(event.getAction() != MotionEvent.ACTION_UP) return false;
186+
187+
// Check we are tapping within 15px of the info icon
188+
int extraTapArea = 15;
189+
Drawable info = descItemEditText.getCompoundDrawables()[2];
190+
int infoHitboxX = descItemEditText.getWidth() - info.getBounds().width();
191+
if (event.getX() + extraTapArea < infoHitboxX) return false;
192+
193+
// If the above are true, show the info dialog
194+
callback.showAlert(R.string.media_detail_description, R.string.description_info);
195+
return true;
196+
});
177197
}
178198

179199
descItemEditText.addTextChangedListener(new AbstractTextWatcher(descriptionText->{
@@ -188,20 +208,6 @@ public void init(int position) {
188208
}
189209
});
190210

191-
192-
descItemEditText.setDrawableClickListener(target -> {
193-
switch (target) {
194-
case RIGHT:
195-
if (getAdapterPosition() == 1) {
196-
callback.showAlert(R.string.media_detail_description,
197-
R.string.description_info);
198-
}
199-
break;
200-
default:
201-
break;
202-
}
203-
});
204-
205211
initLanguageSpinner(position, description);
206212
}
207213

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package fr.free.nrw.commons.upload;
2+
3+
import com.drew.imaging.ImageMetadataReader;
4+
import com.drew.imaging.ImageProcessingException;
5+
import com.drew.metadata.Directory;
6+
import com.drew.metadata.Metadata;
7+
8+
import java.io.File;
9+
import java.io.IOException;
10+
11+
import javax.inject.Inject;
12+
import javax.inject.Singleton;
13+
14+
import fr.free.nrw.commons.utils.ImageUtils;
15+
import io.reactivex.Single;
16+
import timber.log.Timber;
17+
18+
/**
19+
* We try to avoid copyright violations in commons app.
20+
* For doing that we read EXIF data using the library metadata-reader
21+
* If an image doesn't have any EXIF Directoris in it's metadata then the image is an
22+
* internet download image(and not the one taken using phone's camera) */
23+
24+
@Singleton
25+
public class EXIFReader {
26+
@Inject
27+
public EXIFReader() {
28+
//Empty
29+
}
30+
/**
31+
* The method takes in path of the image and reads metadata using the library metadata-extractor
32+
* And the checks for the presence of EXIF Directories in metadata object
33+
* */
34+
35+
public Single<Integer> processMetadata(String path) {
36+
Metadata readMetadata = null;
37+
try {
38+
readMetadata = ImageMetadataReader.readMetadata(new File(path));
39+
} catch (ImageProcessingException e) {
40+
Timber.d(e.toString());
41+
} catch (IOException e) {
42+
Timber.d(e.toString());
43+
}
44+
if (readMetadata != null) {
45+
for (Directory directory : readMetadata.getDirectories()) {
46+
// In case of internet downloaded image these three fields are not present
47+
if (directory.getName().equals("Exif IFD0") //Contains information about the device capturing the photo
48+
|| directory.getName().equals("Exif SubIFD") //contains information like date, time and pixels of the image
49+
|| directory.getName().equals("Exif Thumbnail")) //contains information about image thumbnail like compression and reolution
50+
{
51+
Timber.d(directory.getName() + " Contains metadata");
52+
return Single.just(ImageUtils.IMAGE_OK);
53+
}
54+
}
55+
}
56+
return Single.just(ImageUtils.FILE_NO_EXIF);
57+
}
58+
59+
}
60+

0 commit comments

Comments
 (0)