Fixes issue #467 - Adds profile metadata
This commit is contained in:
parent
c0e7b27825
commit
5b6fa48b25
|
@ -59,7 +59,10 @@ import com.bumptech.glide.request.target.SimpleTarget;
|
|||
import com.bumptech.glide.request.transition.Transition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
|
@ -423,7 +426,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
|
|||
if (urlHeader.startsWith("/")) {
|
||||
urlHeader = Helper.getLiveInstanceWithProtocol(ShowAccountActivity.this) + account.getHeader();
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && !urlHeader.contains("missing.png")) {
|
||||
if (!urlHeader.contains("missing.png")) {
|
||||
|
||||
Glide.with(getApplicationContext())
|
||||
.asBitmap()
|
||||
|
@ -577,6 +580,76 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
|
|||
}
|
||||
});
|
||||
|
||||
if ( account.getFields() != null && account.getFields().size() > 0){
|
||||
HashMap<String, String> fields = account.getFields();
|
||||
Iterator it = fields.entrySet().iterator();
|
||||
int i = 1;
|
||||
LinearLayout fields_container = findViewById(R.id.fields_container);
|
||||
if( fields_container != null)
|
||||
fields_container.setVisibility(View.VISIBLE);
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
String label = (String)pair.getKey();
|
||||
String value = (String)pair.getValue();
|
||||
LinearLayout field;
|
||||
TextView labelView;
|
||||
TextView valueView;
|
||||
switch(i){
|
||||
case 1:
|
||||
field = findViewById(R.id.field1);
|
||||
labelView = findViewById(R.id.label1);
|
||||
valueView = findViewById(R.id.value1);
|
||||
break;
|
||||
case 2:
|
||||
field = findViewById(R.id.field2);
|
||||
labelView = findViewById(R.id.label2);
|
||||
valueView = findViewById(R.id.value2);
|
||||
break;
|
||||
case 3:
|
||||
field = findViewById(R.id.field3);
|
||||
labelView = findViewById(R.id.label3);
|
||||
valueView = findViewById(R.id.value3);
|
||||
break;
|
||||
case 4:
|
||||
field = findViewById(R.id.field4);
|
||||
labelView = findViewById(R.id.label4);
|
||||
valueView = findViewById(R.id.value4);
|
||||
break;
|
||||
default:
|
||||
field = findViewById(R.id.field1);
|
||||
labelView = findViewById(R.id.label1);
|
||||
valueView = findViewById(R.id.value1);
|
||||
break;
|
||||
}
|
||||
if( field != null && labelView != null && valueView != null) {
|
||||
switch (theme){
|
||||
case Helper.THEME_LIGHT:
|
||||
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_light_2));
|
||||
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_light_4));
|
||||
break;
|
||||
case Helper.THEME_DARK:
|
||||
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_2));
|
||||
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_4));
|
||||
break;
|
||||
case Helper.THEME_BLACK:
|
||||
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_black_2));
|
||||
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_black_4));
|
||||
break;
|
||||
default:
|
||||
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_2));
|
||||
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_4));
|
||||
}
|
||||
field.setVisibility(View.VISIBLE);
|
||||
SpannableString spannableValueString = Helper.clickableElementsDescription(ShowAccountActivity.this, value);
|
||||
valueView.setText(spannableValueString, TextView.BufferType.SPANNABLE);
|
||||
valueView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
labelView.setText(label);
|
||||
}
|
||||
i++;
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
account_dn.setText(Helper.shortnameToUnicode(account.getDisplay_name(), true));
|
||||
account_un.setText(String.format("@%s", account.getAcct()));
|
||||
SpannableString spannableString = Helper.clickableElementsDescription(ShowAccountActivity.this, account.getNote());
|
||||
|
|
|
@ -1849,6 +1849,16 @@ public class API {
|
|||
account.setAvatar_static(resobj.get("avatar_static").toString());
|
||||
account.setHeader(resobj.get("header").toString());
|
||||
account.setHeader_static(resobj.get("header_static").toString());
|
||||
try {
|
||||
JSONArray fields = resobj.getJSONArray("fields");
|
||||
HashMap<String, String> fieldsMap = 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"));
|
||||
}
|
||||
}
|
||||
account.setFields(fieldsMap);
|
||||
}catch (Exception ignored){}
|
||||
} catch (JSONException ignored) {}
|
||||
return account;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ import android.view.View;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
|
||||
|
@ -62,6 +64,8 @@ public class Account implements Parcelable {
|
|||
private boolean isMakingAction = false;
|
||||
private Account moved_to_account;
|
||||
private boolean muting_notifications;
|
||||
private int metaDataSize;
|
||||
private HashMap<String, String> fields = new HashMap<>();
|
||||
|
||||
public followAction getFollowType() {
|
||||
return followType;
|
||||
|
@ -95,6 +99,14 @@ public class Account implements Parcelable {
|
|||
this.muting_notifications = muting_notifications;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
public void setFields(HashMap<String, String> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
public enum followAction{
|
||||
FOLLOW,
|
||||
NOT_FOLLOW,
|
||||
|
@ -122,6 +134,12 @@ public class Account implements Parcelable {
|
|||
header_static = in.readString();
|
||||
token = in.readString();
|
||||
instance = in.readString();
|
||||
metaDataSize = in.readInt();
|
||||
for(int i = 0; i < metaDataSize; i++){
|
||||
String key = in.readString();
|
||||
String value = in.readString();
|
||||
fields.put(key,value);
|
||||
}
|
||||
}
|
||||
|
||||
public Account(){}
|
||||
|
@ -297,6 +315,14 @@ public class Account implements Parcelable {
|
|||
dest.writeString(header_static);
|
||||
dest.writeString(token);
|
||||
dest.writeString(instance);
|
||||
|
||||
metaDataSize = fields.size();
|
||||
dest.writeInt(metaDataSize);
|
||||
for (Map.Entry<String, String> entry : fields.entrySet()) {
|
||||
dest.writeString(entry.getKey());
|
||||
dest.writeString(entry.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isFollowing() {
|
||||
|
@ -362,4 +388,5 @@ public class Account implements Parcelable {
|
|||
}
|
||||
return spannableString;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -215,6 +215,114 @@
|
|||
android:maxLines="4"
|
||||
android:autoLink="web"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<!-- Fields container -->
|
||||
<LinearLayout
|
||||
android:visibility="gone"
|
||||
|
||||
android:id="@+id/fields_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<!-- Fields 1 to 4 -->
|
||||
<LinearLayout
|
||||
android:id="@+id/field1"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/label1"
|
||||
android:padding="5dp"
|
||||
android:minHeight="20dp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:textSize="16sp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent" />
|
||||
<TextView
|
||||
android:id="@+id/value1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_weight="2"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/field2"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/label2"
|
||||
android:padding="5dp"
|
||||
android:minHeight="20dp"
|
||||
android:layout_width="0dp"
|
||||
android:textSize="16sp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent" />
|
||||
<TextView
|
||||
android:id="@+id/value2"
|
||||
android:layout_width="0dp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_weight="2"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/field3"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/label3"
|
||||
android:padding="5dp"
|
||||
android:minHeight="20dp"
|
||||
android:textSize="16sp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent" />
|
||||
<TextView
|
||||
android:id="@+id/value3"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="2"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/field4"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/label4"
|
||||
android:padding="5dp"
|
||||
android:minHeight="20dp"
|
||||
android:textSize="16sp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent" />
|
||||
<TextView
|
||||
android:id="@+id/value4"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="2"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<!-- End Fields container -->
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
|
|
|
@ -211,6 +211,114 @@
|
|||
android:layout_width="match_parent"
|
||||
android:autoLink="web"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<!-- Fields container -->
|
||||
<LinearLayout
|
||||
android:visibility="gone"
|
||||
|
||||
android:id="@+id/fields_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<!-- Fields 1 to 4 -->
|
||||
<LinearLayout
|
||||
android:id="@+id/field1"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/label1"
|
||||
android:padding="5dp"
|
||||
android:minHeight="20dp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:textSize="16sp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent" />
|
||||
<TextView
|
||||
android:id="@+id/value1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_weight="2"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/field2"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/label2"
|
||||
android:padding="5dp"
|
||||
android:minHeight="20dp"
|
||||
android:layout_width="0dp"
|
||||
android:textSize="16sp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent" />
|
||||
<TextView
|
||||
android:id="@+id/value2"
|
||||
android:layout_width="0dp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_weight="2"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/field3"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/label3"
|
||||
android:padding="5dp"
|
||||
android:minHeight="20dp"
|
||||
android:textSize="16sp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent" />
|
||||
<TextView
|
||||
android:id="@+id/value3"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="2"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/field4"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/label4"
|
||||
android:padding="5dp"
|
||||
android:minHeight="20dp"
|
||||
android:textSize="16sp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent" />
|
||||
<TextView
|
||||
android:id="@+id/value4"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="2"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<!-- End Fields container -->
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
|
|
Loading…
Reference in New Issue