Pleroma reactions

This commit is contained in:
tom79 2020-03-11 12:35:14 +01:00
parent ca1840c250
commit 15158d89f7
7 changed files with 253 additions and 18 deletions

View File

@ -746,6 +746,16 @@ public class API {
} catch (Exception e) {
status.setLanguage("ja");
}
List<Reaction> 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<Attachment> 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
}

View File

@ -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();
});

View File

@ -919,6 +919,62 @@
</LinearLayout>
</LinearLayout>
<LinearLayout
app:layout_constraintTop_toBottomOf="@id/status_content_section"
app:layout_constraintBottom_toTopOf="@+id/status_action_container"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:id="@+id/status_reactions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:layout_gravity="center"
>
<LinearLayout
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<app.fedilab.android.helper.MastalabAutoCompleteTextView
android:id="@+id/fake_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:inputType="text" />
</LinearLayout>
<ImageView
android:id="@+id/status_add_reaction"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_add"
android:layout_marginEnd="10dp"
app:tint="?attr/iconColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/add_reaction" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/reactions_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<ImageView
android:id="@+id/status_add_custom_emoji"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_insert_emoticon"
android:layout_marginStart="10dp"
app:tint="?attr/iconColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/add_reaction" />
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/status_action_container"
android:layout_width="0dp"
@ -927,7 +983,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/status_content_section"
app:layout_constraintTop_toBottomOf="@id/status_content_section"
app:layout_constraintTop_toBottomOf="@id/status_reactions"
app:layout_constraintVertical_bias="1">
<ImageView

View File

@ -869,6 +869,7 @@
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:layout_gravity="center"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent">
<LinearLayout
android:visibility="gone"
@ -911,6 +912,7 @@
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/add_reaction" />
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/status_action_container"
android:layout_width="match_parent"

View File

@ -136,7 +136,6 @@
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
android:contentDescription="@string/profile_picture"
android:visibility="gone" />
@ -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" />
<LinearLayout
android:id="@+id/status_reactions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:layout_gravity="center"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent">
<LinearLayout
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<app.fedilab.android.helper.MastalabAutoCompleteTextView
android:id="@+id/fake_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:inputType="text" />
</LinearLayout>
<ImageView
android:id="@+id/status_add_reaction"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_add"
android:layout_marginEnd="10dp"
app:tint="?attr/iconColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/add_reaction" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/reactions_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<ImageView
android:id="@+id/status_add_custom_emoji"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_insert_emoticon"
android:layout_marginStart="10dp"
app:tint="?attr/iconColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/add_reaction" />
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/status_action_container"
android:layout_width="match_parent"

View File

@ -778,6 +778,58 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:id="@+id/status_reactions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:layout_gravity="center"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent">
<LinearLayout
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<app.fedilab.android.helper.MastalabAutoCompleteTextView
android:id="@+id/fake_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:inputType="text" />
</LinearLayout>
<ImageView
android:id="@+id/status_add_reaction"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_add"
android:layout_marginEnd="10dp"
app:tint="?attr/iconColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/add_reaction" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/reactions_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<ImageView
android:id="@+id/status_add_custom_emoji"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_insert_emoticon"
android:layout_marginStart="10dp"
app:tint="?attr/iconColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/add_reaction" />
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/status_action_container"
android:layout_width="match_parent"

View File

@ -1,6 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/status_reactions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:layout_gravity="center"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent">
<LinearLayout
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<app.fedilab.android.helper.MastalabAutoCompleteTextView
android:id="@+id/fake_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:inputType="text" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<ImageView
android:id="@+id/status_add_reaction"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_add"
android:layout_marginEnd="10dp"
app:tint="?attr/iconColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/add_reaction" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/reactions_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<ImageView
android:id="@+id/status_add_custom_emoji"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_insert_emoticon"
android:layout_marginStart="10dp"
app:tint="?attr/iconColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/add_reaction" />
</LinearLayout>