Layout updates + fixes

This commit is contained in:
stom79 2019-01-09 18:26:25 +01:00
parent 3f76b8b836
commit 56054f03a2
3 changed files with 5 additions and 583 deletions

View File

@ -41,14 +41,12 @@ import java.util.Map;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
import fr.gouv.etalab.mastodon.client.Entities.Card;
import fr.gouv.etalab.mastodon.client.Entities.Conversation;
import fr.gouv.etalab.mastodon.client.Entities.Emojis;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.Filters;
import fr.gouv.etalab.mastodon.client.Entities.HowToVideo;
import fr.gouv.etalab.mastodon.client.Entities.Instance;
import fr.gouv.etalab.mastodon.client.Entities.InstanceSocial;
import fr.gouv.etalab.mastodon.client.Entities.Peertube;
import fr.gouv.etalab.mastodon.client.Entities.PeertubeInformation;
import fr.gouv.etalab.mastodon.client.Entities.Relationship;
@ -649,82 +647,6 @@ public class PeertubeAPI {
}
/**
* Retrieves accounts that reblogged the status *synchronously*
*
* @param statusId String Id of the status
* @param max_id String id max
* @return APIResponse
*/
@SuppressWarnings("SameParameterValue")
public APIResponse getRebloggedBy(String statusId, String max_id) {
HashMap<String, String> params = new HashMap<>();
if (max_id != null)
params.put("max_id", max_id);
params.put("limit", "80");
accounts = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s/reblogged_by", statusId)), 60, params, prefKeyOauthTokenT);
accounts = parseAccountResponse(new JSONArray(response));
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setAccounts(accounts);
return apiResponse;
}
/**
* Retrieves accounts that favourited the status *synchronously*
*
* @param statusId String Id of the status
* @param max_id String id max
* @return APIResponse
*/
@SuppressWarnings("SameParameterValue")
public APIResponse getFavouritedBy(String statusId, String max_id) {
HashMap<String, String> params = new HashMap<>();
if (max_id != null)
params.put("max_id", max_id);
params.put("limit", "80");
accounts = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s/favourited_by", statusId)), 60, params, prefKeyOauthTokenT);
accounts = parseAccountResponse(new JSONArray(response));
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setAccounts(accounts);
return apiResponse;
}
/**
@ -1047,72 +969,6 @@ public class PeertubeAPI {
/**
* Retrieves following for the account specified by targetedId *synchronously*
* @param targetedId String targetedId
* @param max_id String id max
* @return APIResponse
*/
public APIResponse getFollowing(String targetedId, String max_id){
return getAccounts(String.format("/accounts/%s/following",targetedId),max_id, null, accountPerPage);
}
/**
* Retrieves followers for the account specified by targetedId *synchronously*
* @param targetedId String targetedId
* @param max_id String id max
* @return APIResponse
*/
public APIResponse getFollowers(String targetedId, String max_id){
return getAccounts(String.format("/accounts/%s/followers",targetedId),max_id, null, accountPerPage);
}
/**
* Retrieves blocked users by the authenticated account *synchronously*
* @param max_id String id max
* @param since_id String since the id
* @param limit int limit - max value 40
* @return APIResponse
*/
@SuppressWarnings("SameParameterValue")
private APIResponse getAccounts(String action, String max_id, String since_id, int limit){
HashMap<String, String> params = new HashMap<>();
if( max_id != null )
params.put("max_id", max_id);
if( since_id != null )
params.put("since_id", since_id);
if( 0 > limit || limit > 40)
limit = 40;
params.put("limit",String.valueOf(limit));
accounts = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
accounts = parseAccountResponse(new JSONArray(response));
if( accounts != null && accounts.size() == 1 ){
if(accounts.get(0).getAcct() == null){
Throwable error = new Throwable(context.getString(R.string.toast_error));
setError(500, error);
}
}
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setAccounts(accounts);
return apiResponse;
}
/**
@ -1270,88 +1126,6 @@ public class PeertubeAPI {
}
/**
* Retrieves Accounts when searching (ie: via @...) *synchronously*
* Not limited to following
* @param query String search
* @return APIResponse
*/
@SuppressWarnings("SameParameterValue")
public APIResponse searchAccounts(String query, int count) {
return searchAccounts(query, count, false);
}
/**
* Retrieves Accounts when searching (ie: via @...) *synchronously*
* @param query String search
* @param count int limit
* @param following boolean following only
* @return APIResponse
*/
public APIResponse searchAccounts(String query, int count, boolean following) {
HashMap<String, String> params = new HashMap<>();
params.put("q", query);
if( count < 5)
count = 5;
if( count > 40 )
count = 40;
if( following)
params.put("following", Boolean.toString(true));
params.put("limit", String.valueOf(count));
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl("/accounts/search"), 60, params, prefKeyOauthTokenT);
accounts = parseAccountResponse(new JSONArray(response));
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setAccounts(accounts);
return apiResponse;
}
/**
* Retrieves Accounts when searching (ie: via @...) *synchronously*
*
* @return APIResponse
*/
public APIResponse getCustomEmoji() {
List<Emojis> emojis = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl("/custom_emojis"), 60, null, prefKeyOauthTokenT);
emojis = parseEmojis(new JSONArray(response));
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setEmojis(emojis);
return apiResponse;
}
/**
@ -1560,218 +1334,6 @@ public class PeertubeAPI {
return apiResponse;
}
/**
* Get accounts in a list for a user
* @param listId String, id of the list
* @param limit int, limit of results
* @return APIResponse
*/
@SuppressWarnings("SameParameterValue")
public APIResponse getAccountsInList(String listId, int limit){
HashMap<String, String> params = new HashMap<>();
if( limit < 0)
limit = 0;
if( limit > 50 )
limit = 50;
params.put("limit",String.valueOf(limit));
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/lists/%s/accounts", listId)), 60, params, prefKeyOauthTokenT);
accounts = parseAccountResponse(new JSONArray(response));
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setAccounts(accounts);
return apiResponse;
}
/**
* Get a list
* @param id String, id of the list
* @return APIResponse
*/
@SuppressWarnings("unused")
public APIResponse getList(String id){
List<fr.gouv.etalab.mastodon.client.Entities.List> lists = new ArrayList<>();
fr.gouv.etalab.mastodon.client.Entities.List list;
try {
String response = new HttpsConnection(context).get(getAbsoluteUrl(String.format("/lists/%s",id)), 60, null, prefKeyOauthTokenT);
list = parseList(new JSONObject(response));
lists.add(list);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setLists(lists);
return apiResponse;
}
/**
* Parse json response an unique Car
* @param resobj JSONObject
* @return Card
*/
private static Card parseCardResponse(JSONObject resobj){
Card card = new Card();
try {
card.setUrl(resobj.get("url").toString());
card.setTitle(resobj.get("title").toString());
card.setDescription(resobj.get("description").toString());
card.setImage(resobj.get("image").toString());
card.setHtml(resobj.get("html").toString());
card.setType(resobj.get("type").toString());
try {
card.setAuthor_name(resobj.get("author_name").toString());
}catch (Exception e){
e.printStackTrace();
card.setAuthor_name(null);
}
try {
card.setAuthor_url(resobj.get("author_url").toString());
}catch (Exception e){
e.printStackTrace();
card.setAuthor_url(null);
}
try {
card.setEmbed_url(resobj.get("embed_url").toString());
}catch (Exception e){
e.printStackTrace();
card.setEmbed_url(null);
}
try {
card.setProvider_name(resobj.get("provider_name").toString());
}catch (Exception e){
e.printStackTrace();
card.setProvider_name(null);
}
try {
card.setProvider_url(resobj.get("provider_url").toString());
}catch (Exception e){
e.printStackTrace();
card.setProvider_url(null);
}
try {
card.setHeight(Integer.parseInt(resobj.get("height").toString()));
}catch (Exception e){
e.printStackTrace();
card.setHeight(0);
}
try {
card.setWidth(Integer.parseInt(resobj.get("width").toString()));
}catch (Exception e){
e.printStackTrace();
card.setWidth(0);
}
} catch (JSONException e) {
e.printStackTrace();
card = null;
}
return card;
}
/**
* Parse json response an unique instance social result
* @param resobj JSONObject
* @return InstanceSocial
*/
public static InstanceSocial parseInstanceSocialResponse(Context context, JSONObject resobj){
InstanceSocial instanceSocial = new InstanceSocial();
try {
instanceSocial.setUptime(Float.parseFloat(resobj.get("uptime").toString()));
instanceSocial.setUp(Boolean.parseBoolean(resobj.get("up").toString()));
instanceSocial.setConnections(Long.parseLong(resobj.get("connections").toString()));
instanceSocial.setDead(Boolean.parseBoolean(resobj.get("dead").toString()));
instanceSocial.setId(resobj.get("id").toString());
instanceSocial.setInfo(resobj.get("info").toString());
instanceSocial.setVersion(resobj.get("version").toString());
instanceSocial.setName(resobj.get("name").toString());
instanceSocial.setObs_rank(resobj.get("obs_rank").toString());
instanceSocial.setThumbnail(resobj.get("thumbnail").toString());
instanceSocial.setIpv6(Boolean.parseBoolean(resobj.get("ipv6").toString()));
instanceSocial.setObs_score(Integer.parseInt(resobj.get("obs_score").toString()));
instanceSocial.setOpen_registrations(Boolean.parseBoolean(resobj.get("open_registrations").toString()));
instanceSocial.setUsers(Long.parseLong(resobj.get("users").toString()));
instanceSocial.setStatuses(Long.parseLong(resobj.get("statuses").toString()));
instanceSocial.setHttps_rank(resobj.get("https_rank").toString());
instanceSocial.setHttps_score(Integer.parseInt(resobj.get("https_score").toString()));
instanceSocial.setAdded_at(Helper.mstStringToDate(context, resobj.get("added_at").toString()));
instanceSocial.setChecked_at(Helper.mstStringToDate(context, resobj.get("checked_at").toString()));
instanceSocial.setUpdated_at(Helper.mstStringToDate(context, resobj.get("updated_at").toString()));
} catch (Exception e) {
e.printStackTrace();
}
return instanceSocial;
}
/**
* Parse Domains
* @param jsonArray JSONArray
* @return List<String> of domains
*/
private List<String> parseDomains(JSONArray jsonArray){
List<String> list_tmp = new ArrayList<>();
for(int i = 0; i < jsonArray.length(); i++){
try {
list_tmp.add(jsonArray.getString(i));
} catch (JSONException ignored) {}
}
return list_tmp;
}
/**
* Parse Tags
* @param jsonArray JSONArray
* @return List<String> of tags
*/
private List<String> parseTags(JSONArray jsonArray){
List<String> list_tmp = new ArrayList<>();
for(int i = 0; i < jsonArray.length(); i++){
try {
list_tmp.add(jsonArray.getString(i));
} catch (JSONException ignored) {}
}
return list_tmp;
}
/**
* Parse json response for several howto
* @param jsonArray JSONArray
@ -2271,149 +1833,8 @@ public class PeertubeAPI {
return account;
}
/**
* Parse json response an unique account
* @param resobj JSONObject
* @return Account
*/
@SuppressWarnings("InfiniteRecursion")
private static Account parseAccountResponse(Context context, JSONObject resobj){
Account account = new Account();
try {
account.setId(resobj.get("id").toString());
account.setUsername(resobj.get("username").toString());
account.setAcct(resobj.get("acct").toString());
account.setDisplay_name(resobj.get("display_name").toString());
account.setLocked(Boolean.parseBoolean(resobj.get("locked").toString()));
account.setCreated_at(Helper.mstStringToDate(context, resobj.get("created_at").toString()));
account.setFollowers_count(Integer.valueOf(resobj.get("followers_count").toString()));
account.setFollowing_count(Integer.valueOf(resobj.get("following_count").toString()));
account.setStatuses_count(Integer.valueOf(resobj.get("statuses_count").toString()));
account.setNote(resobj.get("note").toString());
try {
account.setBot(Boolean.parseBoolean(resobj.get("bot").toString()));
}catch (Exception e){
account.setBot(false);
}
try{
account.setMoved_to_account(parseAccountResponse(context, resobj.getJSONObject("moved")));
}catch (Exception ignored){account.setMoved_to_account(null);}
account.setUrl(resobj.get("url").toString());
account.setAvatar(resobj.get("avatar").toString());
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");
LinkedHashMap<String, String> fieldsMap = new LinkedHashMap<>();
LinkedHashMap<String, Boolean> fieldsMapVerified = new LinkedHashMap<>();
if( fields != null){
for(int j = 0 ; j < fields.length() ; j++){
fieldsMap.put(fields.getJSONObject(j).getString("name"),fields.getJSONObject(j).getString("value"));
try {
fieldsMapVerified.put(fields.getJSONObject(j).getString("name"),(fields.getJSONObject(j).getString("verified_at")!= null && !fields.getJSONObject(j).getString("verified_at").equals("null")));
}catch (Exception e){
fieldsMapVerified.put(fields.getJSONObject(j).getString("name"),false);
}
}
}
account.setFields(fieldsMap);
account.setFieldsVerified(fieldsMapVerified);
}catch (Exception ignored){}
//Retrieves emjis
List<Emojis> emojiList = new ArrayList<>();
try {
JSONArray emojisTag = resobj.getJSONArray("emojis");
if( emojisTag != null){
for(int j = 0 ; j < emojisTag.length() ; j++){
JSONObject emojisObj = emojisTag.getJSONObject(j);
Emojis emojis = parseEmojis(emojisObj);
emojiList.add(emojis);
}
}
account.setEmojis(emojiList);
}catch (Exception e){
account.setEmojis(new ArrayList<>());
}
} catch (JSONException ignored) {} catch (ParseException e) {
e.printStackTrace();
}
return account;
}
/**
* Parse json response an unique account
* @param resobj JSONObject
* @return Account
*/
@SuppressWarnings("InfiniteRecursion")
private static Account parseMisskeyAccountResponse(Context context, String instance, JSONObject resobj){
Account account = new Account();
try {
account.setId(resobj.get("id").toString());
account.setUsername(resobj.get("username").toString());
String host = resobj.get("host").toString();
String acct;
if( host == null || host.equals("null"))
acct = resobj.get("username").toString();
else
acct = resobj.get("username").toString() + "@" + host;
account.setAcct(acct);
account.setDisplay_name(resobj.get("name").toString());
account.setCreated_at(new Date());
account.setUrl("https://" + instance + "/@"+account.getUsername());
account.setAvatar(resobj.get("avatarUrl").toString());
account.setAvatar_static(resobj.get("avatarUrl").toString());
try {
account.setBot(Boolean.parseBoolean(resobj.get("isBot").toString()));
}catch (Exception e){
account.setBot(false);
}
//Retrieves emjis
List<Emojis> emojiList = new ArrayList<>();
try {
JSONArray emojisTag = resobj.getJSONArray("emojis");
if( emojisTag != null){
for(int j = 0 ; j < emojisTag.length() ; j++){
JSONObject emojisObj = emojisTag.getJSONObject(j);
Emojis emojis = parseEmojis(emojisObj);
emojiList.add(emojis);
}
}
account.setEmojis(emojiList);
}catch (Exception e){
account.setEmojis(new ArrayList<>());
}
} catch (JSONException ignored) {}
return account;
}
/**
* Parse json response for list of accounts
* @param jsonArray JSONArray
* @return List<Account>
*/
private List<Account> parseAccountResponse(JSONArray jsonArray){
List<Account> accounts = new ArrayList<>();
try {
int i = 0;
while (i < jsonArray.length() ) {
JSONObject resobj = jsonArray.getJSONObject(i);
Account account = parseAccountResponse(context, resobj);
accounts.add(account);
i++;
}
} catch (JSONException e) {
setDefaultError(e);
}
return accounts;
}
/**

View File

@ -116,7 +116,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter implements OnListActio
Glide.with(holder.peertube_video_image.getContext())
.load("https://" + peertube.getInstance() + peertube.getThumbnailPath())
.into(holder.peertube_video_image);
if (account.getAvatar() != null && !account.getAvatar().startsWith("http"))
if (account.getAvatar() != null && !account.getAvatar().equals("null") && !account.getAvatar().startsWith("http"))
account.setAvatar("https://" + peertube.getInstance() + account.getAvatar());
Helper.loadGiF(context, account.getAvatar(), holder.peertube_profile);

View File

@ -21,13 +21,11 @@
android:id="@+id/main_container"
android:divider="?android:dividerHorizontal"
android:showDividers="end"
android:paddingBottom="10dp"
android:orientation="vertical">
<ImageView
android:layout_marginTop="5dp"
android:id="@+id/peertube_video_image"
android:layout_width="match_parent"
android:scaleType="fitCenter"
android:scaleType="centerCrop"
android:layout_height="200dp"
android:gravity="center"
/>
@ -37,6 +35,7 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/peertube_profile"
android:layout_marginTop="10dp"
android:layout_width="40dp"
android:scaleType="fitCenter"
android:layout_height="40dp"
@ -45,6 +44,8 @@
<LinearLayout
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">