Merge pull request #1172 from diddypod/rtl-upload

Fix issue #1163: Crash on upload picture with right to left languages
This commit is contained in:
neslihanturan 2018-02-28 12:43:40 +02:00 committed by GitHub
commit b1a4f7f990
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 23 deletions

View file

@ -1,5 +1,6 @@
package fr.free.nrw.commons.category;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;

View file

@ -9,6 +9,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.TextWatcher;
@ -228,36 +229,41 @@ public class SingleUploadFragment extends CommonsDaggerSupportFragment {
*/
@OnTouch(R.id.titleEdit)
boolean titleInfo(View view, MotionEvent motionEvent) {
//Should replace right with end to support different right-to-left languages as well
final int value = titleEdit.getRight() - titleEdit.getCompoundDrawables()[2].getBounds().width();
final int value;
if (ViewCompat.getLayoutDirection(getView()) == ViewCompat.LAYOUT_DIRECTION_LTR) {
value = titleEdit.getRight() - titleEdit.getCompoundDrawables()[2].getBounds().width();
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) {
new AlertDialog.Builder(getContext())
.setTitle(R.string.media_detail_title)
.setMessage(R.string.title_info)
.setCancelable(true)
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
.create()
.show();
showInfoAlert(R.string.media_detail_title, R.string.title_info);
return true;
}
}
else {
value = titleEdit.getLeft() + titleEdit.getCompoundDrawables()[0].getBounds().width();
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() <= value) {
showInfoAlert(R.string.media_detail_title, R.string.title_info);
return true;
}
}
return false;
}
@OnTouch(R.id.descEdit)
boolean descriptionInfo(View view, MotionEvent motionEvent) {
final int value = descEdit.getRight() - descEdit.getCompoundDrawables()[2].getBounds().width();
final int value;
if (ViewCompat.getLayoutDirection(getView()) == ViewCompat.LAYOUT_DIRECTION_LTR) {
value = descEdit.getRight() - descEdit.getCompoundDrawables()[2].getBounds().width();
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) {
new AlertDialog.Builder(getContext())
.setTitle(R.string.media_detail_description)
.setMessage(R.string.description_info)
.setCancelable(true)
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
.create()
.show();
showInfoAlert(R.string.media_detail_description,R.string.description_info);
return true;
}
}
else{
value = descEdit.getLeft() + descEdit.getCompoundDrawables()[0].getBounds().width();
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() <= value) {
showInfoAlert(R.string.media_detail_description,R.string.description_info);
return true;
}
}
return false;
}
@ -321,4 +327,14 @@ public class SingleUploadFragment extends CommonsDaggerSupportFragment {
}
}
}
private void showInfoAlert (int titleStringID, int messageStringID){
new AlertDialog.Builder(getContext())
.setTitle(titleStringID)
.setMessage(messageStringID)
.setCancelable(true)
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
.create()
.show();
}
}