mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Pasted text should have fonts unified (for Caption/Description) (#4667)
* Changed hardcoded "More" to getStrings(R.string.more) for Unlogged user - MainActivity toolbar showed "More" when clicked on More options in other language than English * Changed hardcoded "More" to getStrings(R.string.more) for Logged user - MainActivity toolbar showed "More" when clicked on More options in other language than English * Added test for: MainActivity.setUpPager * Pasted text is now unformatted for caption and description * Removed other branch contribution * Added test * Rename .java to .kt * Test from Java to Kotlin; +small fix * PasteSensitiveTextInputEditTextTest - updated
This commit is contained in:
parent
ad0aa7d4ea
commit
e910b1d14f
5 changed files with 159 additions and 9 deletions
|
|
@ -0,0 +1,67 @@
|
|||
package fr.free.nrw.commons.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import fr.free.nrw.commons.R;
|
||||
|
||||
public class PasteSensitiveTextInputEditText extends TextInputEditText {
|
||||
|
||||
private boolean formattingAllowed = true;
|
||||
|
||||
public PasteSensitiveTextInputEditText(final Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public PasteSensitiveTextInputEditText(final Context context, final AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
formattingAllowed = extractFormattingAttribute(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTextContextMenuItem(int id) {
|
||||
|
||||
// if not paste command, or formatting is allowed, return default
|
||||
if(id != android.R.id.paste || formattingAllowed){
|
||||
return super.onTextContextMenuItem(id);
|
||||
}
|
||||
|
||||
// if its paste and formatting not allowed
|
||||
boolean proceeded;
|
||||
if(VERSION.SDK_INT >= 23) {
|
||||
proceeded = super.onTextContextMenuItem(android.R.id.pasteAsPlainText);
|
||||
}else {
|
||||
proceeded = super.onTextContextMenuItem(id);
|
||||
if (proceeded && getText() != null) {
|
||||
// rewrite with plain text so formatting is lost
|
||||
setText(getText().toString());
|
||||
setSelection(getText().length());
|
||||
}
|
||||
}
|
||||
return proceeded;
|
||||
}
|
||||
|
||||
private boolean extractFormattingAttribute(Context context, AttributeSet attrs){
|
||||
|
||||
boolean formatAllowed = true;
|
||||
|
||||
TypedArray a = context.getTheme().obtainStyledAttributes(
|
||||
attrs, R.styleable.PasteSensitiveTextInputEditText, 0, 0);
|
||||
|
||||
try {
|
||||
formatAllowed = a.getBoolean(
|
||||
R.styleable.PasteSensitiveTextInputEditText_allowFormatting, true);
|
||||
} finally {
|
||||
a.recycle();
|
||||
}
|
||||
return formatAllowed;
|
||||
}
|
||||
|
||||
public void setFormattingAllowed(boolean formattingAllowed){
|
||||
this.formattingAllowed = formattingAllowed;
|
||||
}
|
||||
}
|
||||
|
|
@ -10,14 +10,12 @@ import android.widget.ImageView;
|
|||
import android.widget.Spinner;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatEditText;
|
||||
import androidx.appcompat.widget.AppCompatSpinner;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.ui.PasteSensitiveTextInputEditText;
|
||||
import fr.free.nrw.commons.utils.AbstractTextWatcher;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -93,13 +91,13 @@ public class UploadMediaDetailAdapter extends RecyclerView.Adapter<UploadMediaDe
|
|||
Spinner spinnerDescriptionLanguages;
|
||||
|
||||
@BindView(R.id.description_item_edit_text)
|
||||
TextInputEditText descItemEditText;
|
||||
PasteSensitiveTextInputEditText descItemEditText;
|
||||
|
||||
@BindView(R.id.description_item_edit_text_input_layout)
|
||||
TextInputLayout descInputLayout;
|
||||
|
||||
@BindView(R.id.caption_item_edit_text)
|
||||
TextInputEditText captionItemEditText;
|
||||
PasteSensitiveTextInputEditText captionItemEditText;
|
||||
|
||||
@BindView(R.id.caption_item_edit_text_input_layout)
|
||||
TextInputLayout captionInputLayout;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue