Support verified links on profiles

This commit is contained in:
stom79 2018-09-27 19:33:22 +02:00
parent 82432007e5
commit f61ad952fc
12 changed files with 137 additions and 29 deletions

View File

@ -22,6 +22,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
@ -39,8 +40,10 @@ import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.PopupMenu;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan;
import android.util.Log;
import android.view.Menu;
@ -50,6 +53,7 @@ import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
@ -659,6 +663,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
if ( account.getFields() != null && account.getFields().size() > 0){
HashMap<String, String> fields = account.getFields();
HashMap<String, Boolean> fieldsVerified = account.getFieldsVerified();
Iterator it = fields.entrySet().iterator();
int i = 1;
LinearLayout fields_container = findViewById(R.id.fields_container);
@ -668,34 +673,42 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
Map.Entry pair = (Map.Entry)it.next();
String label = (String)pair.getKey();
String value = (String)pair.getValue();
boolean verified = fieldsVerified.get(label);
LinearLayout field;
TextView labelView;
TextView valueView;
LinearLayout verifiedView;
switch(i){
case 1:
field = findViewById(R.id.field1);
labelView = findViewById(R.id.label1);
valueView = findViewById(R.id.value1);
verifiedView = findViewById(R.id.value1BG);
break;
case 2:
field = findViewById(R.id.field2);
labelView = findViewById(R.id.label2);
valueView = findViewById(R.id.value2);
verifiedView = findViewById(R.id.value2BG);
break;
case 3:
field = findViewById(R.id.field3);
labelView = findViewById(R.id.label3);
valueView = findViewById(R.id.value3);
verifiedView = findViewById(R.id.value3BG);
break;
case 4:
field = findViewById(R.id.field4);
labelView = findViewById(R.id.label4);
valueView = findViewById(R.id.value4);
verifiedView = findViewById(R.id.value4BG);
break;
default:
field = findViewById(R.id.field1);
labelView = findViewById(R.id.label1);
valueView = findViewById(R.id.value1);
verifiedView = findViewById(R.id.value1BG);
break;
}
if( field != null && labelView != null && valueView != null) {
@ -717,13 +730,24 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_4));
}
field.setVisibility(View.VISIBLE);
SpannableString spannableValueString = Helper.clickableElementsDescription(ShowAccountActivity.this, value, account.getEmojis());
SpannableString spannableValueString;
if( verified ){
value = "" + value;
verifiedView.setBackgroundResource(R.drawable.verified);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
valueView.setBackground(null);
}
spannableValueString = Helper.clickableElementsDescription(ShowAccountActivity.this, value, account.getEmojis());
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, account.getEmojis());
}
valueView.setText(spannableValueString, TextView.BufferType.SPANNABLE);
valueView.setMovementMethod(LinkMovementMethod.getInstance());
labelView.setText(label);
}
i++;
// it.remove();
}
}
@ -937,27 +961,27 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
return;
account_follow.setEnabled(true);
if( accountId != null && accountId.equals(userId)){
account_follow.setVisibility(View.GONE);
header_edit_profile.setVisibility(View.VISIBLE);
account_follow.hide();
header_edit_profile.show();
header_edit_profile.bringToFront();
}else if( relationship.isBlocking()){
account_follow.setImageResource(R.drawable.ic_lock_open);
doAction = action.UNBLOCK;
account_follow.setVisibility(View.VISIBLE);
account_follow.show();
}else if( relationship.isRequested()){
account_follow_request.setVisibility(View.VISIBLE);
account_follow.setVisibility(View.GONE);
account_follow.hide();
doAction = action.NOTHING;
}else if( relationship.isFollowing()){
account_follow.setImageResource(R.drawable.ic_user_times);
doAction = action.UNFOLLOW;
account_follow.setVisibility(View.VISIBLE);
account_follow.show();
}else if( !relationship.isFollowing()){
account_follow.setImageResource(R.drawable.ic_user_plus);
doAction = action.FOLLOW;
account_follow.setVisibility(View.VISIBLE);
account_follow.show();
}else{
account_follow.setVisibility(View.GONE);
account_follow.hide();
doAction = action.NOTHING;
}
}

View File

@ -16,6 +16,7 @@ package fr.gouv.etalab.mastodon.client;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
@ -2482,12 +2483,15 @@ public class API {
try {
JSONArray fields = resobj.getJSONArray("fields");
HashMap<String, String> fieldsMap = new HashMap<>();
HashMap<String, Boolean> fieldsMapVerified = new HashMap<>();
if( fields != null){
for(int j = 0 ; j < fields.length() ; j++){
fieldsMap.put(fields.getJSONObject(j).getString("name"),fields.getJSONObject(j).getString("value"));
fieldsMapVerified.put(fields.getJSONObject(j).getString("name"),(fields.getJSONObject(j).getString("verified_at")!= null && !fields.getJSONObject(j).getString("verified_at").equals("null")));
}
}
account.setFields(fieldsMap);
account.setFieldsVerified(fieldsMapVerified);
}catch (Exception ignored){}
//Retrieves emjis

View File

@ -85,7 +85,9 @@ public class Account implements Parcelable {
private Account moved_to_account;
private boolean muting_notifications;
private int metaDataSize;
private int metaDataSizeVerified;
private HashMap<String, String> fields = new HashMap<>();
private HashMap<String, Boolean> fieldsVerified = new HashMap<>();
private HashMap<String, SpannableString> fieldsSpan = new HashMap<>();
private List<Emojis> emojis;
private Account account;
@ -141,6 +143,13 @@ public class Account implements Parcelable {
return fieldsSpan;
}
public HashMap<String, Boolean> getFieldsVerified() {
return fieldsVerified;
}
public void setFieldsVerified(HashMap<String, Boolean> fieldsVerified) {
this.fieldsVerified = fieldsVerified;
}
public enum followAction{
@ -176,6 +185,12 @@ public class Account implements Parcelable {
String value = in.readString();
fields.put(key,value);
}
metaDataSizeVerified = in.readInt();
for(int i = 0; i < metaDataSizeVerified; i++){
String key = in.readString();
Boolean value = in.readByte() != 0;
fieldsVerified.put(key,value);
}
}
public Account(){
@ -379,12 +394,18 @@ public class Account implements Parcelable {
dest.writeString(instance);
metaDataSize = fields.size();
metaDataSizeVerified = fieldsVerified.size();
dest.writeInt(metaDataSize);
for (Map.Entry<String, String> entry : fields.entrySet()) {
dest.writeString(entry.getKey());
dest.writeString(entry.getValue());
}
dest.writeInt(metaDataSizeVerified);
for (Map.Entry<String, Boolean> entry : fieldsVerified.entrySet()) {
dest.writeString(entry.getKey());
dest.writeByte((byte) (entry.getValue() ? 1 : 0));
}
}
public boolean isFollowing() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 541 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 697 B

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/verified_background" />
<stroke
android:width="1px"
android:color="@color/verified_text" />
</shape>

View File

@ -233,17 +233,29 @@
android:minHeight="20dp"
android:layout_gravity="center"
android:gravity="center"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textSize="16sp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent" />
<TextView
android:id="@+id/value1"
<LinearLayout
android:layout_width="0dp"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="2"
android:layout_height="match_parent" />
android:id="@+id/value1BG"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/value1"
android:layout_gravity="center"
android:gravity="center"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/field2"
@ -257,17 +269,29 @@
android:minHeight="20dp"
android:layout_width="0dp"
android:textSize="16sp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="1"
android:layout_height="match_parent" />
<TextView
android:id="@+id/value2"
<LinearLayout
android:layout_width="0dp"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="2"
android:layout_height="match_parent" />
android:id="@+id/value2BG"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/value2"
android:layout_gravity="center"
android:gravity="center"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/field3"
@ -284,14 +308,24 @@
android:gravity="center"
android:layout_width="0dp"
android:layout_weight="1"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_height="match_parent" />
<TextView
android:id="@+id/value3"
android:layout_gravity="center"
android:gravity="center"
<LinearLayout
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:id="@+id/value3BG"
android:orientation="vertical">
<TextView
android:id="@+id/value3"
android:layout_gravity="center"
android:gravity="center"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/field4"
@ -307,15 +341,26 @@
android:layout_gravity="center"
android:gravity="center"
android:layout_width="0dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_weight="1"
android:layout_height="match_parent" />
<TextView
android:id="@+id/value4"
android:layout_gravity="center"
android:gravity="center"
<LinearLayout
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:id="@+id/value4BG"
android:orientation="vertical">
<TextView
android:id="@+id/value4"
android:layout_gravity="center"
android:gravity="center"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<!-- End Fields container -->

View File

@ -69,4 +69,7 @@
<color name="notif_light_3">#d9e1e8</color>
<color name="notif_light_4">#c9d1d8</color>
<color name="verified_text">#79bd9a</color>
<color name="verified_background">#5579bd9a</color>
</resources>