mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 05:13:53 +01:00
* add methods to check and remove trailing whitespace * fix filter to check and remove trailing whitespace * fix filter to check and remove trailing space first * add test and fix filter() and removeTrailingWhitespace() * caption trailing whitespace: change solution to remove trailing whitespaces when set to uploadMediaDetails * update code documentation * add more tests include instance tab, carriage return and Japanese whitespace * Caption field: Stop blocking Japanese Space, convert to English Space when set to uploadMediaDetails * Change method name from convertJapSpaceToEngSpace to convertIdeographicSpaceToLatinSpace * Change pattern name from JapSpacePattern to ideographicSpacePattern
This commit is contained in:
parent
09564c3eca
commit
3488644938
4 changed files with 87 additions and 4 deletions
|
|
@ -34,6 +34,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.inject.Inject;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
|
@ -197,7 +198,7 @@ public class UploadMediaDetailAdapter extends RecyclerView.Adapter<UploadMediaDe
|
|||
|
||||
removeButton.setOnClickListener(v -> removeDescription(uploadMediaDetail, position));
|
||||
captionListener = new AbstractTextWatcher(
|
||||
captionText -> uploadMediaDetails.get(position).setCaptionText(captionText));
|
||||
captionText -> uploadMediaDetails.get(position).setCaptionText(convertIdeographicSpaceToLatinSpace(removeTrailingWhitespace(captionText))));
|
||||
descriptionListener = new AbstractTextWatcher(
|
||||
descriptionText -> uploadMediaDetails.get(position).setDescriptionText(descriptionText));
|
||||
captionItemEditText.addTextChangedListener(captionListener);
|
||||
|
|
@ -418,10 +419,45 @@ public class UploadMediaDetailAdapter extends RecyclerView.Adapter<UploadMediaDe
|
|||
languageHistoryListView.setAdapter(recentLanguagesAdapter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the source string contains trailing whitespace
|
||||
* @param source input string
|
||||
* @return true if contains trailing whitespace and false otherwise
|
||||
*/
|
||||
public Boolean checkTrailingWhitespace(String source) {
|
||||
int len = source.length();
|
||||
if (len == 0) {
|
||||
return false;
|
||||
}
|
||||
return Character.isWhitespace(source.charAt(len - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any trailing whitespace from the source text.
|
||||
* @param source input string
|
||||
* @return a string without trailing whitespace
|
||||
*/
|
||||
public String removeTrailingWhitespace(String source) {
|
||||
while (checkTrailingWhitespace(source)) {
|
||||
source = source.substring(0, source.length() - 1);
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Ideographic space to Latin space
|
||||
* @param source the source text
|
||||
* @return a string with Latin spaces instead of Ideographic spaces
|
||||
*/
|
||||
public String convertIdeographicSpaceToLatinSpace(String source) {
|
||||
Pattern ideographicSpacePattern = Pattern.compile("\\x{3000}");
|
||||
return ideographicSpacePattern.matcher(source).replaceAll(" ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface Callback {
|
||||
|
||||
void showAlert(int mediaDetailDescription, int descriptionInfo);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class UploadMediaDetailInputFilter implements InputFilter {
|
|||
*/
|
||||
public UploadMediaDetailInputFilter() {
|
||||
patterns = new Pattern[]{
|
||||
Pattern.compile("[\\x{00A0}\\x{1680}\\x{180E}\\x{2000}-\\x{200B}\\x{2028}\\x{2029}\\x{202F}\\x{205F}\\x{3000}]"),
|
||||
Pattern.compile("[\\x{00A0}\\x{1680}\\x{180E}\\x{2000}-\\x{200B}\\x{2028}\\x{2029}\\x{202F}\\x{205F}]"),
|
||||
Pattern.compile("[\\x{202A}-\\x{202E}]"),
|
||||
Pattern.compile("\\p{Cc}"),
|
||||
Pattern.compile("\\x{FEFF}"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue