Commit 90c3f1c0 authored by Thomas's avatar Thomas
Browse files

Fix issue #1261 - Add 3-Dots menu for remote conversations

parent d3d7a85c
Loading
Loading
Loading
Loading
+396 −378
Original line number Diff line number Diff line
@@ -2287,17 +2287,181 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>


        // Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> holder.binding.statusContent.invalidate(), 0, 100, TimeUnit.MILLISECONDS);

        holder.binding.actionButtonMore.setOnClickListener(v -> {
            if (remote) {
            holder.binding.actionButtonMore.setVisibility(View.GONE);
                Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
                searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
                        .observe((LifecycleOwner) context, results -> {
                            if (results != null && results.statuses != null && !results.statuses.isEmpty()) {
                                clickMoreAction(context, statusesVM, holder, adapter, statusList, results.statuses.get(0));
                            } else {
            holder.binding.actionButtonMore.setVisibility(View.VISIBLE);
                                Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
                            }
        holder.binding.actionButtonMore.setOnClickListener(v -> {
                        });
            } else {
                clickMoreAction(context, statusesVM, holder, adapter, statusList, statusToDeal);
            }
        });

        holder.binding.actionButtonReplyContainer.setOnLongClickListener(v -> {
            CrossActionHelper.doCrossAction(context, CrossActionHelper.TypeOfCrossAction.REPLY_ACTION, null, statusToDeal);
            return true;
        });
        holder.binding.actionButtonQuote.setOnClickListener(v -> {
            Intent intent = new Intent(context, ComposeActivity.class);
            Bundle args = new Bundle();
            args.putSerializable(Helper.ARG_QUOTED_MESSAGE, statusToDeal);
            new CachedBundle(context).insertBundle(args, Helper.getCurrentAccount(context), bundleId -> {
                Bundle bundle = new Bundle();
                bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
                intent.putExtras(bundle);
                context.startActivity(intent);
            });
        });
        holder.binding.actionButtonReplyContainer.setOnClickListener(v -> {
            if (remote) {
                Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
                searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
                        .observe((LifecycleOwner) context, results -> {
                            if (results != null && results.statuses != null && results.statuses.size() > 0) {
                                Status fetchedStatus = results.statuses.get(0);
                                Intent intent = new Intent(context, ComposeActivity.class);
                                Bundle args = new Bundle();
                                args.putSerializable(Helper.ARG_STATUS_REPLY, fetchedStatus);
                                new CachedBundle(context).insertBundle(args, Helper.getCurrentAccount(context), bundleId -> {
                                    Bundle bundle = new Bundle();
                                    bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
                                    intent.putExtras(bundle);
                                    context.startActivity(intent);
                                });
                            } else {
                                Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
                            }
                        });
            } else {
                Intent intent = new Intent(context, ComposeActivity.class);
                Bundle args = new Bundle();
                args.putSerializable(Helper.ARG_STATUS_REPLY, statusToDeal);
                if (status.reblog != null) {
                    args.putSerializable(Helper.ARG_MENTION_BOOSTER, status.account);
                }
                new CachedBundle(context).insertBundle(args, Helper.getCurrentAccount(context), bundleId -> {
                    Bundle bundle = new Bundle();
                    bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
                    intent.putExtras(bundle);
                    context.startActivity(intent);
                });
            }
        });
        //For reports
        if (holder.bindingReport != null) {
            holder.bindingReport.checkbox.setChecked(status.isChecked);
            holder.bindingReport.checkbox.setOnClickListener(v -> status.isChecked = !status.isChecked);
        }

        if (status.isFetchMore && fetchMoreCallBack != null) {
            if (!autofetch) {
                DrawerFetchMoreBinding drawerFetchMoreBinding = DrawerFetchMoreBinding.inflate(LayoutInflater.from(context));
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                drawerFetchMoreBinding.fetchMoreContainer.setLayoutParams(lp);
                if (status.positionFetchMore == Status.PositionFetchMore.BOTTOM) {
                    holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
                    holder.binding.fetchMoreContainerTop.setVisibility(View.VISIBLE);
                    holder.binding.fetchMoreContainerTop.removeAllViews();
                    holder.binding.fetchMoreContainerTop.addView(drawerFetchMoreBinding.getRoot());
                } else {
                    holder.binding.fetchMoreContainerBottom.setVisibility(View.VISIBLE);
                    holder.binding.fetchMoreContainerTop.setVisibility(View.GONE);
                    holder.binding.fetchMoreContainerBottom.removeAllViews();
                    holder.binding.fetchMoreContainerBottom.addView(drawerFetchMoreBinding.getRoot());
                }
                drawerFetchMoreBinding.fetchMoreMin.setOnClickListener(v -> {
                    status.isFetchMore = false;
                    status.isFetching = true;
                    int position = holder.getBindingAdapterPosition();
                    adapter.notifyItemChanged(position);
                    if (position < statusList.size() - 1) {
                        String fromId;
                        if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
                            fromId = statusList.get(position + 1).id;
                        } else {
                            fromId = status.id;
                        }
                        fetchMoreCallBack.onClickMinId(fromId, status);
                    }
                });
                drawerFetchMoreBinding.fetchMoreMax.setOnClickListener(v -> {
                    //We hide the button
                    status.isFetchMore = false;
                    status.isFetching = true;
                    String fromId;
                    if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
                        fromId = statusList.get(holder.getBindingAdapterPosition()).id;
                    } else {
                        fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
                    }
                    fetchMoreCallBack.onClickMaxId(fromId, status);
                    adapter.notifyItemChanged(holder.getBindingAdapterPosition());
                });
            } else {
                holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
                holder.binding.fetchMoreContainerTop.setVisibility(View.GONE);
                status.isFetchMore = false;
                status.isFetching = true;
                int position = holder.getBindingAdapterPosition();
                String statusIdMin = null, statusIdMax;
                if (position < statusList.size() - 1) {
                    if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
                        statusIdMin = statusList.get(position + 1).id;
                    } else {
                        statusIdMin = status.id;
                    }
                }
                if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
                    statusIdMax = statusList.get(holder.getBindingAdapterPosition()).id;
                } else {
                    statusIdMax = statusList.get(holder.getBindingAdapterPosition() - 1).id;
                }
                fetchMoreCallBack.autoFetch(statusIdMin, statusIdMax, status);
                recyclerView.post(() -> adapter.notifyItemChanged(holder.getBindingAdapterPosition()));
            }
        } else if (status.isFetching) {
            DrawerMessageFetchingBinding drawerMessageFetchingBinding = DrawerMessageFetchingBinding.inflate(LayoutInflater.from(context));
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            drawerMessageFetchingBinding.fetchingContainer.setLayoutParams(lp);
            drawerMessageFetchingBinding.fetchingProgress.getIndeterminateDrawable().setColorFilter(ThemeHelper.getAttColor(context, R.attr.colorPrimary), PorterDuff.Mode.SRC_IN);
            if (status.positionFetchMore == Status.PositionFetchMore.BOTTOM) {
                holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
                holder.binding.fetchMoreContainerTop.setVisibility(View.VISIBLE);
                holder.binding.fetchMoreContainerTop.removeAllViews();
                holder.binding.fetchMoreContainerTop.addView(drawerMessageFetchingBinding.getRoot());
            } else {
                holder.binding.fetchMoreContainerBottom.setVisibility(View.VISIBLE);
                holder.binding.fetchMoreContainerTop.setVisibility(View.GONE);
                holder.binding.fetchMoreContainerBottom.removeAllViews();
                holder.binding.fetchMoreContainerBottom.addView(drawerMessageFetchingBinding.getRoot());
            }
        } else {
            holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
            holder.binding.fetchMoreContainerTop.setVisibility(View.GONE);
        }

    }

    private static void clickMoreAction(Context context,
                                        StatusesVM statusesVM,
                                        StatusViewHolder holder,
                                        RecyclerView.Adapter<RecyclerView.ViewHolder> adapter,
                                        List<Status> statusList,
                                        Status statusToDeal) {
        SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
        boolean share_details = sharedpreferences.getBoolean(context.getString(R.string.SET_SHARE_DETAILS), true);
        boolean isOwner = statusToDeal.account.id.compareTo(BaseMainActivity.currentUserID) == 0;
        PopupMenu popup = new PopupMenu(context, holder.binding.actionButtonMore);
        popup.getMenuInflater()
                .inflate(R.menu.option_toot, popup.getMenu());
            if (statusToDeal.visibility.equals("private") || status.visibility.equals("direct")) {
        if (statusToDeal.visibility.equals("private") || statusToDeal.visibility.equals("direct")) {
            popup.getMenu().findItem(R.id.action_mention).setVisible(false);
        }
        if (statusToDeal.bookmarked)
@@ -2667,153 +2831,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
            return true;
        });
        popup.show();
        });

        holder.binding.actionButtonReplyContainer.setOnLongClickListener(v -> {
            CrossActionHelper.doCrossAction(context, CrossActionHelper.TypeOfCrossAction.REPLY_ACTION, null, statusToDeal);
            return true;
        });
        holder.binding.actionButtonQuote.setOnClickListener(v -> {
            Intent intent = new Intent(context, ComposeActivity.class);
            Bundle args = new Bundle();
            args.putSerializable(Helper.ARG_QUOTED_MESSAGE, statusToDeal);
            new CachedBundle(context).insertBundle(args, Helper.getCurrentAccount(context), bundleId -> {
                Bundle bundle = new Bundle();
                bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
                intent.putExtras(bundle);
                context.startActivity(intent);
            });
        });
        holder.binding.actionButtonReplyContainer.setOnClickListener(v -> {
            if (remote) {
                Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
                searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
                        .observe((LifecycleOwner) context, results -> {
                            if (results != null && results.statuses != null && results.statuses.size() > 0) {
                                Status fetchedStatus = results.statuses.get(0);
                                Intent intent = new Intent(context, ComposeActivity.class);
                                Bundle args = new Bundle();
                                args.putSerializable(Helper.ARG_STATUS_REPLY, fetchedStatus);
                                new CachedBundle(context).insertBundle(args, Helper.getCurrentAccount(context), bundleId -> {
                                    Bundle bundle = new Bundle();
                                    bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
                                    intent.putExtras(bundle);
                                    context.startActivity(intent);
                                });
                            } else {
                                Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
                            }
                        });
            } else {
                Intent intent = new Intent(context, ComposeActivity.class);
                Bundle args = new Bundle();
                args.putSerializable(Helper.ARG_STATUS_REPLY, statusToDeal);
                if (status.reblog != null) {
                    args.putSerializable(Helper.ARG_MENTION_BOOSTER, status.account);
                }
                new CachedBundle(context).insertBundle(args, Helper.getCurrentAccount(context), bundleId -> {
                    Bundle bundle = new Bundle();
                    bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
                    intent.putExtras(bundle);
                    context.startActivity(intent);
                });
    }
        });
        //For reports
        if (holder.bindingReport != null) {
            holder.bindingReport.checkbox.setChecked(status.isChecked);
            holder.bindingReport.checkbox.setOnClickListener(v -> status.isChecked = !status.isChecked);
        }

        if (status.isFetchMore && fetchMoreCallBack != null) {
            if (!autofetch) {
                DrawerFetchMoreBinding drawerFetchMoreBinding = DrawerFetchMoreBinding.inflate(LayoutInflater.from(context));
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                drawerFetchMoreBinding.fetchMoreContainer.setLayoutParams(lp);
                if (status.positionFetchMore == Status.PositionFetchMore.BOTTOM) {
                    holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
                    holder.binding.fetchMoreContainerTop.setVisibility(View.VISIBLE);
                    holder.binding.fetchMoreContainerTop.removeAllViews();
                    holder.binding.fetchMoreContainerTop.addView(drawerFetchMoreBinding.getRoot());
                } else {
                    holder.binding.fetchMoreContainerBottom.setVisibility(View.VISIBLE);
                    holder.binding.fetchMoreContainerTop.setVisibility(View.GONE);
                    holder.binding.fetchMoreContainerBottom.removeAllViews();
                    holder.binding.fetchMoreContainerBottom.addView(drawerFetchMoreBinding.getRoot());
                }
                drawerFetchMoreBinding.fetchMoreMin.setOnClickListener(v -> {
                    status.isFetchMore = false;
                    status.isFetching = true;
                    int position = holder.getBindingAdapterPosition();
                    adapter.notifyItemChanged(position);
                    if (position < statusList.size() - 1) {
                        String fromId;
                        if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
                            fromId = statusList.get(position + 1).id;
                        } else {
                            fromId = status.id;
                        }
                        fetchMoreCallBack.onClickMinId(fromId, status);
                    }
                });
                drawerFetchMoreBinding.fetchMoreMax.setOnClickListener(v -> {
                    //We hide the button
                    status.isFetchMore = false;
                    status.isFetching = true;
                    String fromId;
                    if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
                        fromId = statusList.get(holder.getBindingAdapterPosition()).id;
                    } else {
                        fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
                    }
                    fetchMoreCallBack.onClickMaxId(fromId, status);
                    adapter.notifyItemChanged(holder.getBindingAdapterPosition());
                });
            } else {
                holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
                holder.binding.fetchMoreContainerTop.setVisibility(View.GONE);
                status.isFetchMore = false;
                status.isFetching = true;
                int position = holder.getBindingAdapterPosition();
                String statusIdMin = null, statusIdMax;
                if (position < statusList.size() - 1) {
                    if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
                        statusIdMin = statusList.get(position + 1).id;
                    } else {
                        statusIdMin = status.id;
                    }
                }
                if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
                    statusIdMax = statusList.get(holder.getBindingAdapterPosition()).id;
                } else {
                    statusIdMax = statusList.get(holder.getBindingAdapterPosition() - 1).id;
                }
                fetchMoreCallBack.autoFetch(statusIdMin, statusIdMax, status);
                recyclerView.post(() -> adapter.notifyItemChanged(holder.getBindingAdapterPosition()));
            }
        } else if (status.isFetching) {
            DrawerMessageFetchingBinding drawerMessageFetchingBinding = DrawerMessageFetchingBinding.inflate(LayoutInflater.from(context));
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            drawerMessageFetchingBinding.fetchingContainer.setLayoutParams(lp);
            drawerMessageFetchingBinding.fetchingProgress.getIndeterminateDrawable().setColorFilter(ThemeHelper.getAttColor(context, R.attr.colorPrimary), PorterDuff.Mode.SRC_IN);
            if (status.positionFetchMore == Status.PositionFetchMore.BOTTOM) {
                holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
                holder.binding.fetchMoreContainerTop.setVisibility(View.VISIBLE);
                holder.binding.fetchMoreContainerTop.removeAllViews();
                holder.binding.fetchMoreContainerTop.addView(drawerMessageFetchingBinding.getRoot());
            } else {
                holder.binding.fetchMoreContainerBottom.setVisibility(View.VISIBLE);
                holder.binding.fetchMoreContainerTop.setVisibility(View.GONE);
                holder.binding.fetchMoreContainerBottom.removeAllViews();
                holder.binding.fetchMoreContainerBottom.addView(drawerMessageFetchingBinding.getRoot());
            }
        } else {
            holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
            holder.binding.fetchMoreContainerTop.setVisibility(View.GONE);
        }

    }


    private static void translate(Context context, Status statusToDeal,
                                  StatusViewHolder holder,