don't show translate for empty decoding
This commit is contained in:
parent
95dd3ff068
commit
295cb74287
|
@ -4,6 +4,7 @@ import static org.joinmastodon.android.api.MastodonAPIController.gson;
|
||||||
import static org.joinmastodon.android.api.MastodonAPIController.gsonWithoutDeserializer;
|
import static org.joinmastodon.android.api.MastodonAPIController.gsonWithoutDeserializer;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Pair;
|
||||||
|
|
||||||
import org.joinmastodon.android.api.ObjectValidationException;
|
import org.joinmastodon.android.api.ObjectValidationException;
|
||||||
import org.joinmastodon.android.api.RequiredField;
|
import org.joinmastodon.android.api.RequiredField;
|
||||||
|
@ -223,10 +224,10 @@ public class Status extends BaseModel implements DisplayItemsParent, Searchable{
|
||||||
instanceInfo.v2.configuration.translation.enabled;
|
instanceInfo.v2.configuration.translation.enabled;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String bottomText = BOTTOM_TEXT_PATTERN.matcher(getStrippedText()).find()
|
Pair<String, List<String>> decoded=BOTTOM_TEXT_PATTERN.matcher(getStrippedText()).find()
|
||||||
? new StatusTextEncoder(Bottom::decode).decode(getStrippedText(), BOTTOM_TEXT_PATTERN)
|
? new StatusTextEncoder(Bottom::decode).decode(getStrippedText(), BOTTOM_TEXT_PATTERN)
|
||||||
: null;
|
: null;
|
||||||
if(bottomText==null || bottomText.length()==0 || bottomText.equals("\u0005")) bottomText=null;
|
String bottomText=decoded==null || decoded.second.stream().allMatch(s->s.trim().isEmpty()) ? null : decoded.first;
|
||||||
if(bottomText!=null){
|
if(bottomText!=null){
|
||||||
translation=new Translation();
|
translation=new Translation();
|
||||||
translation.content=bottomText;
|
translation.content=bottomText;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package org.joinmastodon.android.utils;
|
package org.joinmastodon.android.utils;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.util.Pair;
|
||||||
|
|
||||||
import org.joinmastodon.android.fragments.ComposeFragment;
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.regex.MatchResult;
|
import java.util.regex.MatchResult;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -40,9 +40,10 @@ public class StatusTextEncoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
// prettiest almost-exact replica of a pretty function
|
// prettiest almost-exact replica of a pretty function
|
||||||
public String decode(String content, Pattern regex) {
|
public Pair<String, List<String>> decode(String content, Pattern regex) {
|
||||||
Matcher m=regex.matcher(content);
|
Matcher m=regex.matcher(content);
|
||||||
StringBuilder decodedString=new StringBuilder();
|
StringBuilder decodedString=new StringBuilder();
|
||||||
|
List<String> decodedParts=new ArrayList<>();
|
||||||
int previousEnd=0;
|
int previousEnd=0;
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
MatchResult res=m.toMatchResult();
|
MatchResult res=m.toMatchResult();
|
||||||
|
@ -50,9 +51,11 @@ public class StatusTextEncoder {
|
||||||
decodedString.append(content.substring(previousEnd, res.start()));
|
decodedString.append(content.substring(previousEnd, res.start()));
|
||||||
previousEnd=res.end();
|
previousEnd=res.end();
|
||||||
// the match - do decode
|
// the match - do decode
|
||||||
decodedString.append(fn.apply(res.group()));
|
String decoded=fn.apply(res.group());
|
||||||
|
decodedParts.add(decoded);
|
||||||
|
decodedString.append(decoded);
|
||||||
}
|
}
|
||||||
decodedString.append(content.substring(previousEnd));
|
decodedString.append(content.substring(previousEnd));
|
||||||
return decodedString.toString();
|
return Pair.create(decodedString.toString(), decodedParts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue