Skip to content

Commit b1a4f7f

Browse files
Merge pull request commons-app#1172 from diddypod/rtl-upload
Fix issue commons-app#1163: Crash on upload picture with right to left languages
2 parents e207edc + 67d1df2 commit b1a4f7f

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

app/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fr.free.nrw.commons.category;
22

3+
34
import android.app.Activity;
45
import android.content.SharedPreferences;
56
import android.os.Bundle;

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

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.os.Bundle;
1010
import android.preference.PreferenceManager;
1111
import android.support.annotation.NonNull;
12+
import android.support.v4.view.ViewCompat;
1213
import android.support.v7.app.AlertDialog;
1314
import android.text.Editable;
1415
import android.text.TextWatcher;
@@ -228,35 +229,40 @@ void setTitleDescButton() {
228229
*/
229230
@OnTouch(R.id.titleEdit)
230231
boolean titleInfo(View view, MotionEvent motionEvent) {
231-
//Should replace right with end to support different right-to-left languages as well
232-
final int value = titleEdit.getRight() - titleEdit.getCompoundDrawables()[2].getBounds().width();
233-
234-
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) {
235-
new AlertDialog.Builder(getContext())
236-
.setTitle(R.string.media_detail_title)
237-
.setMessage(R.string.title_info)
238-
.setCancelable(true)
239-
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
240-
.create()
241-
.show();
242-
return true;
232+
final int value;
233+
if (ViewCompat.getLayoutDirection(getView()) == ViewCompat.LAYOUT_DIRECTION_LTR) {
234+
value = titleEdit.getRight() - titleEdit.getCompoundDrawables()[2].getBounds().width();
235+
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) {
236+
showInfoAlert(R.string.media_detail_title, R.string.title_info);
237+
return true;
238+
}
239+
}
240+
else {
241+
value = titleEdit.getLeft() + titleEdit.getCompoundDrawables()[0].getBounds().width();
242+
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() <= value) {
243+
showInfoAlert(R.string.media_detail_title, R.string.title_info);
244+
return true;
245+
}
243246
}
244247
return false;
245248
}
246249

247250
@OnTouch(R.id.descEdit)
248251
boolean descriptionInfo(View view, MotionEvent motionEvent) {
249-
final int value = descEdit.getRight() - descEdit.getCompoundDrawables()[2].getBounds().width();
250-
251-
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) {
252-
new AlertDialog.Builder(getContext())
253-
.setTitle(R.string.media_detail_description)
254-
.setMessage(R.string.description_info)
255-
.setCancelable(true)
256-
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
257-
.create()
258-
.show();
259-
return true;
252+
final int value;
253+
if (ViewCompat.getLayoutDirection(getView()) == ViewCompat.LAYOUT_DIRECTION_LTR) {
254+
value = descEdit.getRight() - descEdit.getCompoundDrawables()[2].getBounds().width();
255+
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) {
256+
showInfoAlert(R.string.media_detail_description,R.string.description_info);
257+
return true;
258+
}
259+
}
260+
else{
261+
value = descEdit.getLeft() + descEdit.getCompoundDrawables()[0].getBounds().width();
262+
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() <= value) {
263+
showInfoAlert(R.string.media_detail_description,R.string.description_info);
264+
return true;
265+
}
260266
}
261267
return false;
262268
}
@@ -321,4 +327,14 @@ public void afterTextChanged(Editable editable) {
321327
}
322328
}
323329
}
330+
331+
private void showInfoAlert (int titleStringID, int messageStringID){
332+
new AlertDialog.Builder(getContext())
333+
.setTitle(titleStringID)
334+
.setMessage(messageStringID)
335+
.setCancelable(true)
336+
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
337+
.create()
338+
.show();
339+
}
324340
}

0 commit comments

Comments
 (0)