From f4907a4c7ba6bb5e9e35a878063acbb606477540 Mon Sep 17 00:00:00 2001 From: tom79 Date: Sun, 29 Sep 2019 15:23:48 +0200 Subject: [PATCH] Add live comments --- .../asynctasks/PostStatusAsyncTask.java | 4 ++- .../android/drawers/PixelfedListAdapter.java | 35 ++++++++++++------- .../android/drawers/StatusListAdapter.java | 18 ++++++++-- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/asynctasks/PostStatusAsyncTask.java b/app/src/main/java/app/fedilab/android/asynctasks/PostStatusAsyncTask.java index eca84ff98..e63bf31d6 100644 --- a/app/src/main/java/app/fedilab/android/asynctasks/PostStatusAsyncTask.java +++ b/app/src/main/java/app/fedilab/android/asynctasks/PostStatusAsyncTask.java @@ -88,7 +88,9 @@ public class PostStatusAsyncTask extends AsyncTask { apiResponse.setError(error); } } - + if( status.getIn_reply_to_id() != null){ + apiResponse.setTargetedId(status.getIn_reply_to_id()); + } return null; } diff --git a/app/src/main/java/app/fedilab/android/drawers/PixelfedListAdapter.java b/app/src/main/java/app/fedilab/android/drawers/PixelfedListAdapter.java index c877be140..a4f46d444 100644 --- a/app/src/main/java/app/fedilab/android/drawers/PixelfedListAdapter.java +++ b/app/src/main/java/app/fedilab/android/drawers/PixelfedListAdapter.java @@ -187,6 +187,20 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA Toasty.info(context, context.getString(R.string.toast_toot_saved_error), Toast.LENGTH_LONG).show(); } + if( apiResponse.getTargetedId() != null && apiResponse.getStatuses() != null && apiResponse.getStatuses().size() > 0){ + int position = 0; + for(Status tl: this.statuses){ + if( tl.getId().equals(apiResponse.getTargetedId())){ + List comments = this.statuses.get(position).getComments(); + comments.add(comments.size(), apiResponse.getStatuses().get(0)); + this.statuses.get(position).setComments(comments); + notifyStatusChanged(this.statuses.get(position)); + break; + } + position++; + } + } + } @@ -413,18 +427,11 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA - + holder.quick_reply_switch_to_full.setVisibility(View.GONE); if (status.isShortReply()) { holder.quick_reply_container.setVisibility(View.VISIBLE); holder.pixelfed_comments.setVisibility(View.VISIBLE); - holder.quick_reply_switch_to_full.setVisibility(View.GONE); in_reply_to_status = status.getReblog() != null ? status.getReblog().getId() : status.getId(); - for (Status s : statuses) { - if (s.isShortReply() && !s.getId().equals(status.getId())) { - s.setShortReply(false); - notifyStatusChanged(s); - } - } if( status.isCommentsFetched()){ StatusListAdapter statusListAdapter = new StatusListAdapter(0, status.getId(), true, status.getComments()); final LinearLayoutManager mLayoutManager; @@ -541,8 +548,6 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA } else { holder.quick_reply_container.setVisibility(View.GONE); holder.pixelfed_comments.setVisibility(View.GONE); - holder.quick_reply_container.setVisibility(View.GONE); - holder.pixelfed_comments.setVisibility(View.GONE); } @@ -588,7 +593,6 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA notifyStatusChanged(status); }); theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); - holder.quick_reply_container.setVisibility(View.VISIBLE); holder.pf_description.setText(status.getContentSpan(), TextView.BufferType.SPANNABLE); holder.pf_date.setText(Helper.longDateToString(status.getCreated_at())); holder.quick_reply_text.setHint(R.string.leave_a_comment); @@ -596,7 +600,14 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA holder.pf_comment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - status.setShortReply(!status.isShortReply()); + boolean currentValue = status.isShortReply(); + for (Status s : statuses) { + if (s.isShortReply() && !s.getId().equals(status.getId())) { + s.setShortReply(false); + notifyStatusChanged(s); + } + } + status.setShortReply(!currentValue); if( !status.isShortReply()){ InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); assert imm != null; 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 f00f32905..3d7bd2b92 100644 --- a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java +++ b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java @@ -862,7 +862,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct if (statuses.get(position).isFocused() && type == RetrieveFeedsAsyncTask.Type.CONTEXT && statuses.get(position).getViewType() != CONSOLE_STATUS) return FOCUSED_STATUS; else { - if( social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) { + if( social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED && type == RetrieveFeedsAsyncTask.Type.CONTEXT) { return COMPACT_STATUS; }else { return statuses.get(position).getViewType(); @@ -917,6 +917,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct status.setItemViewType(viewHolder.getItemViewType()); + + + boolean fullAttachement = sharedpreferences.getBoolean(Helper.SET_FULL_PREVIEW, false); boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false); boolean isConsoleMode = sharedpreferences.getBoolean(Helper.SET_CONSOLE_MODE, false); @@ -961,7 +964,18 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct } } - + if( social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED && type == RetrieveFeedsAsyncTask.Type.CONTEXT) { + if (theme == Helper.THEME_DARK) { + holder.main_container.setBackgroundColor(ContextCompat.getColor(context, R.color.notif_dark_1)); + holder.main_container.setAlpha(.5f); + } else if (theme == Helper.THEME_BLACK) { + holder.main_container.setBackgroundColor(ContextCompat.getColor(context, R.color.notif_black_1)); + holder.main_container.setAlpha(.5f); + } else { + holder.main_container.setBackgroundColor(ContextCompat.getColor(context, R.color.notif_light_1)); + holder.main_container.setAlpha(.5f); + } + } //Display a preview for accounts that have replied *if enabled and only for home timeline* if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { holder.rated.setVisibility(View.GONE);