Some improvements

This commit is contained in:
stom79 2018-12-31 16:11:44 +01:00
parent 7bad216013
commit c7e3fe9a95
2 changed files with 103 additions and 18 deletions

View File

@ -572,21 +572,10 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_4));
}
field.setVisibility(View.VISIBLE);
SpannableString spannableValueString;
if( verified ){
value = "" + value;
if( verified) {
verifiedView.setBackgroundResource(R.drawable.verified);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
valueView.setBackground(null);
}
spannableValueString = Helper.clickableElementsDescription(ShowAccountActivity.this, value);
spannableValueString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(ShowAccountActivity.this, R.color.verified_text)), 0, spannableValueString.toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}else {
spannableValueString = Helper.clickableElementsDescription(ShowAccountActivity.this, value);
}
valueView.setText(spannableValueString, TextView.BufferType.SPANNABLE);
valueView.setMovementMethod(LinkMovementMethod.getInstance());
labelView.setText(label);
}
i++;
}
@ -911,7 +900,8 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
@Override
public void onRetrieveEmojiAccount(Account account) {
account_note.setText(account.getNoteSpan(), TextView.BufferType.SPANNABLE);
account_dn.setText(account.getdisplayNameSpan(), TextView.BufferType.SPANNABLE);;
account_dn.setText(account.getdisplayNameSpan(), TextView.BufferType.SPANNABLE);
LinkedHashMap<String, Boolean> fieldsVerified = account.getFieldsVerified();
if ( account.getFieldsSpan() != null && account.getFieldsSpan().size() > 0){
HashMap<SpannableString, SpannableString> fieldsSpan = account.getFieldsSpan();
Iterator it = fieldsSpan.entrySet().iterator();
@ -959,6 +949,19 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
valueView.setMovementMethod(LinkMovementMethod.getInstance());
labelView.setText(label);
}
if( field != null && labelView != null && valueView != null) {
boolean verified = fieldsVerified.get((String)pair.getKey().toString());
if( verified) {
valueView.setBackgroundResource(R.drawable.verified);
value.setSpan(new ForegroundColorSpan(ContextCompat.getColor(ShowAccountActivity.this, R.color.verified_text)), 0, value.toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
field.setVisibility(View.VISIBLE);
valueView.setText(value, TextView.BufferType.SPANNABLE);
valueView.setMovementMethod(LinkMovementMethod.getInstance());
labelView.setText(label);
}
i++;
}
}

View File

@ -35,6 +35,7 @@ import android.text.TextUtils;
import android.text.style.ClickableSpan;
import android.text.style.ImageSpan;
import android.text.style.URLSpan;
import android.util.Patterns;
import android.view.View;
import android.widget.Toast;
@ -101,7 +102,6 @@ public class Account implements Parcelable {
private LinkedHashMap<String, Boolean> fieldsVerified;
private LinkedHashMap<SpannableString, SpannableString> fieldsSpan;
private List<Emojis> emojis;
private Account account;
private String host;
private boolean isBot;
@ -283,9 +283,7 @@ public class Account implements Parcelable {
public Account(){
this.account = this;
}
public Account(){ }
public static final Creator<Account> CREATOR = new Creator<Account>() {
@Override
@ -596,8 +594,92 @@ public class Account implements Parcelable {
}
}
matcher = android.util.Patterns.EMAIL_ADDRESS.matcher(fieldSpan);
while (matcher.find()){
URLSpan[] urls = fieldSpan.getSpans(0, fieldSpan.length(), URLSpan.class);
for(URLSpan span : urls)
fieldSpan.removeSpan(span);
int matchStart = matcher.start(0);
int matchEnd = matcher.end();
final String email = fieldSpan.toString().substring(matchStart, matchEnd);
if( matchEnd <= fieldSpan.toString().length() && matchEnd >= matchStart) {
fieldSpan.setSpan(new ClickableSpan() {
@Override
public void onClick(View textView) {
try {
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{email});
context.startActivity(Intent.createChooser(emailIntent, context.getString(R.string.send_email)));
}catch (Exception e){
Toasty.error(context, context.getString(R.string.toast_no_apps), Toast.LENGTH_LONG).show();
}
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot));
}
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
fieldsSpan.put(keySpan, fieldSpan);
}
}
}
it = fieldsSpan.entrySet().iterator();
fieldsVerified = account.getFieldsVerified();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
SpannableString fieldSpan = (SpannableString) pair.getValue();
SpannableString keySpan = (SpannableString) pair.getKey();
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
Matcher matcher;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT)
matcher = Patterns.WEB_URL.matcher(fieldSpan);
else
matcher = Helper.urlPattern.matcher(fieldSpan);
while (matcher.find()){
URLSpan[] urls = fieldSpan.getSpans(0, fieldSpan.length(), URLSpan.class);
for(URLSpan span : urls)
fieldSpan.removeSpan(span);
int matchStart = matcher.start(0);
int matchEnd = matcher.end();
final String url = fieldSpan.toString().substring(matchStart, matchEnd);
if( matchEnd <= fieldSpan.toString().length() && matchEnd >= matchStart) {
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
fieldSpan.setSpan(new ClickableSpan() {
@Override
public void onClick(View textView) {
Helper.openBrowser(context, url);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot));
}
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
fieldsSpan.put(keySpan, fieldSpan);
}
}
}
final List<Emojis> emojis = account.getEmojis();
if( emojis != null && emojis.size() > 0 ) {