From 5b6fa48b259d481701a63a4504c0b9fb419ee778 Mon Sep 17 00:00:00 2001 From: stom79 Date: Sun, 20 May 2018 10:34:32 +0200 Subject: [PATCH] Fixes issue #467 - Adds profile metadata --- .../activities/ShowAccountActivity.java | 75 +++++++++++- .../fr/gouv/etalab/mastodon/client/API.java | 10 ++ .../mastodon/client/Entities/Account.java | 27 +++++ .../layout-sw600dp/activity_show_account.xml | 108 ++++++++++++++++++ .../main/res/layout/activity_show_account.xml | 108 ++++++++++++++++++ 5 files changed, 327 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java index 5ba3263b2..d1b83d115 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java @@ -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 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()); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index 9c2ceea5a..9cbda2113 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -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 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; } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Account.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Account.java index bc0db3093..2468d977e 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Account.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Account.java @@ -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 fields = new HashMap<>(); public followAction getFollowType() { return followType; @@ -95,6 +99,14 @@ public class Account implements Parcelable { this.muting_notifications = muting_notifications; } + public HashMap getFields() { + return fields; + } + + public void setFields(HashMap 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 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; } + } diff --git a/app/src/main/res/layout-sw600dp/activity_show_account.xml b/app/src/main/res/layout-sw600dp/activity_show_account.xml index 4d09a285b..8fbd2c357 100644 --- a/app/src/main/res/layout-sw600dp/activity_show_account.xml +++ b/app/src/main/res/layout-sw600dp/activity_show_account.xml @@ -215,6 +215,114 @@ android:maxLines="4" android:autoLink="web" android:layout_height="wrap_content" /> + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_show_account.xml b/app/src/main/res/layout/activity_show_account.xml index 27933858b..9a978d987 100644 --- a/app/src/main/res/layout/activity_show_account.xml +++ b/app/src/main/res/layout/activity_show_account.xml @@ -211,6 +211,114 @@ android:layout_width="match_parent" android:autoLink="web" android:layout_height="wrap_content" /> + + + + + + + + + + + + + + + + + + + + + +