Refactoring

This commit is contained in:
M66B 2021-11-13 08:29:05 +01:00
parent cdaf7cbf54
commit 0b22af992a
2 changed files with 36 additions and 29 deletions

View File

@ -5648,6 +5648,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
continue;
if (i >= message.label_colors.length)
continue;
if (message.label_colors[i] == null)
continue;
int len = ssb.length();
ssb.setSpan(new ForegroundColorSpan(message.label_colors[i]),
@ -5662,27 +5664,31 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return null;
SpannableStringBuilder ssb = new SpannableStringBuilderEx();
if (message.keyword_titles == null || message.keyword_colors == null) {
ssb.append("Keywords missing!");
return ssb;
}
for (int i = 0; i < message.keywords.length; i++) {
if (MessageHelper.showKeyword(message.keywords[i])) {
String keyword = message.keywords[i];
if (MessageHelper.showKeyword(keyword)) {
if (ssb.length() > 0)
ssb.append(' ');
String keyword = message.keyword_titles[i];
if (message.keyword_titles != null &&
i < message.keyword_titles.length &&
message.keyword_titles[i] != null)
keyword = message.keyword_titles[i];
ssb.append(keyword);
if (message.keyword_colors[i] != null) {
int len = ssb.length();
ssb.setSpan(
new ForegroundColorSpan(message.keyword_colors[i]),
len - keyword.length(), len,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (message.keyword_colors == null)
continue;
if (i >= message.keyword_colors.length)
continue;
if (message.keyword_colors[i] == null)
continue;
int len = ssb.length();
ssb.setSpan(
new ForegroundColorSpan(message.keyword_colors[i]),
len - keyword.length(), len,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return ssb;

View File

@ -103,22 +103,23 @@ public class TupleMessageEx extends EntityMessage {
List<String> titles = new ArrayList<>();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
for (int i = 0; i < this.keywords.length; i++) {
String keyword = this.keywords[i];
if (this.keywords != null)
for (int i = 0; i < this.keywords.length; i++) {
String keyword = this.keywords[i];
String keyColor1 = "kwcolor." + keyword;
String keyColor2 = "keyword." + keyword; // legacy
if (prefs.contains(keyColor1))
color.add(prefs.getInt(keyColor1, Color.GRAY));
else if (prefs.contains(keyColor2))
color.add(prefs.getInt(keyColor2, Color.GRAY));
else
color.add(null);
String keyColor1 = "kwcolor." + keyword;
String keyColor2 = "keyword." + keyword; // legacy
if (prefs.contains(keyColor1))
color.add(prefs.getInt(keyColor1, Color.GRAY));
else if (prefs.contains(keyColor2))
color.add(prefs.getInt(keyColor2, Color.GRAY));
else
color.add(null);
String keyTitle = "kwtitle." + keyword;
String def = TupleKeyword.getDefaultKeywordAlias(context, keyword);
titles.add(prefs.getString(keyTitle, def));
}
String keyTitle = "kwtitle." + keyword;
String def = TupleKeyword.getDefaultKeywordAlias(context, keyword);
titles.add(prefs.getString(keyTitle, def));
}
this.keyword_colors = color.toArray(new Integer[0]);
this.keyword_titles = titles.toArray(new String[0]);