From 15158d89f7ef464eb96b721334eed12cf8bead2f Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 11 Mar 2020 12:35:14 +0100 Subject: [PATCH] Pleroma reactions --- .../java/app/fedilab/android/client/API.java | 24 +++++++- .../android/drawers/StatusListAdapter.java | 26 ++++++--- app/src/main/res/layout/drawer_status.xml | 58 ++++++++++++++++++- .../main/res/layout/drawer_status_compact.xml | 2 + .../main/res/layout/drawer_status_console.xml | 54 ++++++++++++++++- .../main/res/layout/drawer_status_focused.xml | 52 +++++++++++++++++ app/src/main/res/layout/include_reactions.xml | 55 ++++++++++++++++-- 7 files changed, 253 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java index 876c44fc1..67138fc6d 100644 --- a/app/src/main/java/app/fedilab/android/client/API.java +++ b/app/src/main/java/app/fedilab/android/client/API.java @@ -746,6 +746,16 @@ public class API { } catch (Exception e) { status.setLanguage("ja"); } + + List reactions = new ArrayList<>(); + if (resobj.has("pleroma") && resobj.getJSONObject("pleroma").has("emoji_reactions") ) { + try { + reactions = parseReaction(resobj.getJSONObject("pleroma").getJSONArray("emoji_reactions")); + }catch (Exception ignored){} + } + status.setReactions(reactions); + + status.setUrl(resobj.get("url").toString()); ArrayList attachments = new ArrayList<>(); //Retrieves attachments @@ -4269,6 +4279,10 @@ public class API { case ADD_REACTION: action = String.format("/announcements/%s/reactions/%s", targetedId, comment); break; + case REMOVE_PLEROMA_REACTION: + case ADD_PLEROMA_REACTION: + action = String.format("/pleroma/statuses/%s/reactions/%s", targetedId, comment); + break; case DISMISS_ANNOUNCEMENT: action = String.format("/announcements/%s/dismiss", targetedId); break; @@ -4322,7 +4336,9 @@ public class API { default: return -1; } - if (statusAction != StatusAction.UNSTATUS && statusAction != StatusAction.ADD_REACTION && statusAction != StatusAction.REMOVE_REACTION) { + if (statusAction != StatusAction.UNSTATUS + && statusAction != StatusAction.ADD_REACTION && statusAction != StatusAction.REMOVE_REACTION + && statusAction != StatusAction.ADD_PLEROMA_REACTION && statusAction != StatusAction.REMOVE_PLEROMA_REACTION) { try { HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); String resp = httpsConnection.post(getAbsoluteUrl(action), 10, params, prefKeyOauthTokenT); @@ -4351,7 +4367,7 @@ public class API { } catch (NoSuchAlgorithmException | IOException | KeyManagementException e) { e.printStackTrace(); } - } else if(statusAction == StatusAction.ADD_REACTION){ + } else if(statusAction == StatusAction.ADD_REACTION || statusAction == StatusAction.ADD_PLEROMA_REACTION){ try { HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); httpsConnection.put(getAbsoluteUrl(action), 10, null, prefKeyOauthTokenT); @@ -4366,7 +4382,7 @@ public class API { HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); httpsConnection.delete(getAbsoluteUrl(action), 10, null, prefKeyOauthTokenT); actionCode = httpsConnection.getActionCode(); - if( statusAction != StatusAction.REMOVE_REACTION) { + if( statusAction != StatusAction.REMOVE_REACTION && statusAction != StatusAction.REMOVE_PLEROMA_REACTION) { SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); new TimelineCacheDAO(context, db).remove(targetedId); } @@ -6209,6 +6225,8 @@ public class API { REFRESHPOLL, ADD_REACTION, REMOVE_REACTION, + ADD_PLEROMA_REACTION, + REMOVE_PLEROMA_REACTION, DISMISS_ANNOUNCEMENT } diff --git a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java index 7146ecae5..4fb9b7675 100644 --- a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java +++ b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java @@ -1015,11 +1015,13 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct iconColor = ThemeHelper.getAttColor(context, R.attr.iconColor); } - if( type == RetrieveFeedsAsyncTask.Type.ANNOUNCEMENTS){ - holder.status_account_profile.setVisibility(View.GONE); - holder.status_account_displayname_owner.setVisibility(View.GONE); - holder.status_account_username.setVisibility(View.GONE); - holder.status_action_container.setVisibility(View.GONE); + if( type == RetrieveFeedsAsyncTask.Type.ANNOUNCEMENTS || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON){ + if( type == RetrieveFeedsAsyncTask.Type.ANNOUNCEMENTS ) { + holder.status_account_profile.setVisibility(View.GONE); + holder.status_account_displayname_owner.setVisibility(View.GONE); + holder.status_account_username.setVisibility(View.GONE); + holder.status_action_container.setVisibility(View.GONE); + } holder.status_reactions.setVisibility(View.VISIBLE); ReactionAdapter reactionAdapter = new ReactionAdapter(status.getReactions()); holder.reactions_view.setAdapter(reactionAdapter); @@ -1056,7 +1058,12 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct status.getReactions().add(0, reaction); notifyStatusChanged(status); } - API.StatusAction statusAction = alreadyAdded?API.StatusAction.REMOVE_REACTION:API.StatusAction.ADD_REACTION; + API.StatusAction statusAction; + if( type == RetrieveFeedsAsyncTask.Type.ANNOUNCEMENTS ) { + statusAction = alreadyAdded ? API.StatusAction.REMOVE_REACTION : API.StatusAction.ADD_REACTION; + }else{ + statusAction = alreadyAdded ? API.StatusAction.REMOVE_PLEROMA_REACTION : API.StatusAction.ADD_PLEROMA_REACTION; + } new PostActionAsyncTask(context, statusAction, status.getId(), null,emojiStr, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }) .build(holder.fake_edittext); @@ -1106,7 +1113,12 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct status.getReactions().add(0, reaction); notifyStatusChanged(status); } - API.StatusAction statusAction = alreadyAdded?API.StatusAction.REMOVE_REACTION:API.StatusAction.ADD_REACTION; + API.StatusAction statusAction; + if( type == RetrieveFeedsAsyncTask.Type.ANNOUNCEMENTS ) { + statusAction = alreadyAdded ? API.StatusAction.REMOVE_REACTION : API.StatusAction.ADD_REACTION; + }else{ + statusAction = alreadyAdded ? API.StatusAction.REMOVE_PLEROMA_REACTION : API.StatusAction.ADD_PLEROMA_REACTION; + } new PostActionAsyncTask(context, statusAction, status.getId(), null, emojis.get(position).getShortcode(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); alertDialogEmoji.dismiss(); }); diff --git a/app/src/main/res/layout/drawer_status.xml b/app/src/main/res/layout/drawer_status.xml index 1c8b8f935..2faa8f6d8 100644 --- a/app/src/main/res/layout/drawer_status.xml +++ b/app/src/main/res/layout/drawer_status.xml @@ -919,6 +919,62 @@ + + + + + + + + + + + + @@ -146,7 +145,6 @@ android:layout_width="30dp" android:layout_height="30dp" android:layout_alignParentEnd="true" - android:layout_alignParentRight="true" android:layout_marginTop="25dp" android:contentDescription="@string/profile_picture" android:visibility="gone" /> @@ -759,7 +757,6 @@ android:layout_height="wrap_content" android:layout_gravity="end" android:layout_marginEnd="20dp" - android:layout_marginRight="20dp" android:layout_marginBottom="5dp" android:gravity="end" android:maxLines="1" @@ -768,6 +765,57 @@ android:textStyle="italic" android:visibility="gone" /> + + + + + + + + + + + + + + + + + + + + + - + + + + - \ No newline at end of file + + + + + \ No newline at end of file