Display social network on profile + creation date
This commit is contained in:
parent
63f588c3a6
commit
5bdaf80a24
|
@ -64,6 +64,8 @@ import com.bumptech.glide.request.RequestOptions;
|
||||||
import com.bumptech.glide.request.target.SimpleTarget;
|
import com.bumptech.glide.request.target.SimpleTarget;
|
||||||
import com.bumptech.glide.request.transition.Transition;
|
import com.bumptech.glide.request.transition.Transition;
|
||||||
|
|
||||||
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -79,6 +81,7 @@ import app.fedilab.android.client.APIResponse;
|
||||||
import app.fedilab.android.client.Entities.Account;
|
import app.fedilab.android.client.Entities.Account;
|
||||||
import app.fedilab.android.client.Entities.Attachment;
|
import app.fedilab.android.client.Entities.Attachment;
|
||||||
import app.fedilab.android.client.Entities.Error;
|
import app.fedilab.android.client.Entities.Error;
|
||||||
|
import app.fedilab.android.client.Entities.InstanceNodeInfo;
|
||||||
import app.fedilab.android.client.Entities.Relationship;
|
import app.fedilab.android.client.Entities.Relationship;
|
||||||
import app.fedilab.android.client.Entities.RemoteInstance;
|
import app.fedilab.android.client.Entities.RemoteInstance;
|
||||||
import app.fedilab.android.client.Entities.Status;
|
import app.fedilab.android.client.Entities.Status;
|
||||||
|
@ -112,6 +115,7 @@ import static app.fedilab.android.helper.Helper.THEME_BLACK;
|
||||||
import static app.fedilab.android.helper.Helper.THEME_DARK;
|
import static app.fedilab.android.helper.Helper.THEME_DARK;
|
||||||
import static app.fedilab.android.helper.Helper.THEME_LIGHT;
|
import static app.fedilab.android.helper.Helper.THEME_LIGHT;
|
||||||
import static app.fedilab.android.helper.Helper.changeDrawableColor;
|
import static app.fedilab.android.helper.Helper.changeDrawableColor;
|
||||||
|
import static app.fedilab.android.helper.Helper.getLiveInstance;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -781,6 +785,32 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
TextView account_date = findViewById(R.id.account_date);
|
||||||
|
account_date.setText(Helper.shortDateToString(account.getCreated_at()));
|
||||||
|
new Thread(new Runnable(){
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
String instance = getLiveInstance(getApplicationContext());
|
||||||
|
if( account.getAcct().split("@").length > 1 ){
|
||||||
|
instance = account.getAcct().split("@")[1];
|
||||||
|
}
|
||||||
|
InstanceNodeInfo instanceNodeInfo = new API(ShowAccountActivity.this).displayNodeInfo(instance);
|
||||||
|
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
if(instanceNodeInfo != null && instanceNodeInfo.getName() != null){
|
||||||
|
TextView instance_info = findViewById(R.id.instance_info);
|
||||||
|
instance_info.setText(instanceNodeInfo.getName());
|
||||||
|
instance_info.setVisibility(View.VISIBLE);
|
||||||
|
TextView seperator = findViewById(R.id.seperator);
|
||||||
|
seperator.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -692,6 +692,76 @@ public class API {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public InstanceNodeInfo displayNodeInfo(String domain){
|
||||||
|
|
||||||
|
String response;
|
||||||
|
InstanceNodeInfo instanceNodeInfo = new InstanceNodeInfo();
|
||||||
|
try {
|
||||||
|
response = new HttpsConnection(context, domain).get("https://" + domain + "/.well-known/nodeinfo", 30, null, null);
|
||||||
|
JSONArray jsonArray = new JSONObject(response).getJSONArray("links");
|
||||||
|
ArrayList<NodeInfo> nodeInfos = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
int i = 0;
|
||||||
|
while (i < jsonArray.length() ){
|
||||||
|
|
||||||
|
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||||
|
NodeInfo nodeInfo = new NodeInfo();
|
||||||
|
nodeInfo.setHref(resobj.getString("href"));
|
||||||
|
nodeInfo.setRel(resobj.getString("rel"));
|
||||||
|
i++;
|
||||||
|
nodeInfos.add(nodeInfo);
|
||||||
|
}
|
||||||
|
if( nodeInfos.size() > 0){
|
||||||
|
NodeInfo nodeInfo = nodeInfos.get(nodeInfos.size()-1);
|
||||||
|
response = new HttpsConnection(context, this.instance).get(nodeInfo.getHref(), 30, null, null);
|
||||||
|
JSONObject resobj = new JSONObject(response);
|
||||||
|
JSONObject jsonObject = resobj.getJSONObject("software");
|
||||||
|
String name= null;
|
||||||
|
name = jsonObject.getString("name").toUpperCase();
|
||||||
|
instanceNodeInfo.setName(name);
|
||||||
|
instanceNodeInfo.setVersion(jsonObject.getString("version"));
|
||||||
|
instanceNodeInfo.setOpenRegistrations(resobj.getBoolean("openRegistrations"));
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
setDefaultError(e);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (KeyManagementException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
try {
|
||||||
|
response = new HttpsConnection(context, this.instance).get("https://" + domain + "/api/v1/instance", 30, null, null);
|
||||||
|
JSONObject jsonObject = new JSONObject(response);
|
||||||
|
instanceNodeInfo.setName("MASTODON");
|
||||||
|
instanceNodeInfo.setVersion(jsonObject.getString("version"));
|
||||||
|
instanceNodeInfo.setOpenRegistrations(true);
|
||||||
|
} catch (IOException e1) {
|
||||||
|
instanceNodeInfo.setConnectionError(true);
|
||||||
|
e1.printStackTrace();
|
||||||
|
} catch (NoSuchAlgorithmException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
} catch (KeyManagementException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
} catch (HttpsConnection.HttpsConnectionException e1) {
|
||||||
|
instanceNodeInfo.setName("GNU");
|
||||||
|
instanceNodeInfo.setVersion("unknown");
|
||||||
|
instanceNodeInfo.setOpenRegistrations(true);
|
||||||
|
e1.printStackTrace();
|
||||||
|
} catch (JSONException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return instanceNodeInfo;
|
||||||
|
}
|
||||||
|
|
||||||
public API(Context context, String instance, String token) {
|
public API(Context context, String instance, String token) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
if( context == null) {
|
if( context == null) {
|
||||||
|
|
|
@ -246,6 +246,39 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
<TextView
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textColor="@color/mastodonC4"
|
||||||
|
android:background="@drawable/blue_border"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:id="@+id/instance_info"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/seperator"
|
||||||
|
android:text="-"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
<TextView
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:id="@+id/account_date"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
||||||
<!-- Fields container -->
|
<!-- Fields container -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
|
|
|
@ -237,6 +237,7 @@
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -249,6 +250,39 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
<TextView
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textColor="@color/mastodonC4"
|
||||||
|
android:background="@drawable/blue_border"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:id="@+id/instance_info"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/seperator"
|
||||||
|
android:text="-"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
<TextView
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:id="@+id/account_date"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
||||||
<!-- Fields container -->
|
<!-- Fields container -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
|
|
Loading…
Reference in New Issue