fedilab-Android-App/app/src/main/java/app/fedilab/android/drawers/BaseNotificationsListAdapte...

1416 lines
75 KiB
Java
Raw Normal View History

2019-05-18 11:10:30 +02:00
package app.fedilab.android.drawers;
2017-05-05 16:36:04 +02:00
/* Copyright 2017 Thomas Schneider
*
2019-05-18 11:10:30 +02:00
* This file is a part of Fedilab
2017-05-05 16:36:04 +02:00
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
2019-05-18 11:10:30 +02:00
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
2017-05-05 16:36:04 +02:00
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
2019-05-18 11:10:30 +02:00
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
2017-05-05 16:36:04 +02:00
* see <http://www.gnu.org/licenses>. */
2020-04-09 18:57:12 +02:00
import android.annotation.SuppressLint;
2020-04-09 14:09:43 +02:00
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
2017-05-05 16:36:04 +02:00
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
2020-04-09 14:09:43 +02:00
import android.graphics.PorterDuff;
2020-04-09 15:07:32 +02:00
import android.graphics.Typeface;
2017-05-05 16:36:04 +02:00
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
2017-05-05 16:36:04 +02:00
import android.os.Build;
import android.os.Bundle;
2018-11-10 15:41:26 +01:00
import android.os.CountDownTimer;
import android.os.Handler;
2017-05-05 16:36:04 +02:00
import android.text.Html;
2020-07-06 11:59:47 +02:00
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
2020-07-06 11:59:47 +02:00
import android.text.style.ForegroundColorSpan;
import android.util.TypedValue;
2017-05-05 16:36:04 +02:00
import android.view.LayoutInflater;
2018-09-15 17:45:33 +02:00
import android.view.MotionEvent;
2017-05-05 16:36:04 +02:00
import android.view.View;
import android.view.ViewGroup;
2017-08-04 14:38:18 +02:00
import android.widget.Button;
2019-03-26 19:07:25 +01:00
import android.widget.CheckBox;
import android.widget.EditText;
2017-10-28 11:25:33 +02:00
import android.widget.FrameLayout;
2017-05-05 16:36:04 +02:00
import android.widget.ImageView;
import android.widget.LinearLayout;
2020-04-09 14:09:43 +02:00
import android.widget.ProgressBar;
2019-03-26 19:07:25 +01:00
import android.widget.RadioButton;
import android.widget.RadioGroup;
2017-08-04 14:38:18 +02:00
import android.widget.RelativeLayout;
2017-05-05 16:36:04 +02:00
import android.widget.TextView;
import android.widget.Toast;
2017-05-05 16:36:04 +02:00
2019-11-15 16:32:25 +01:00
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.constraintlayout.widget.ConstraintLayout;
2020-07-06 11:48:59 +02:00
import androidx.core.app.ActivityOptionsCompat;
2019-11-15 16:32:25 +01:00
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
2017-12-02 11:02:25 +01:00
import com.bumptech.glide.Glide;
2018-12-04 07:53:19 +01:00
import com.varunest.sparkbutton.SparkButton;
2017-05-05 16:36:04 +02:00
2019-08-02 18:35:49 +02:00
import org.jetbrains.annotations.NotNull;
2017-07-30 11:21:55 +02:00
import java.util.ArrayList;
2019-03-26 19:07:25 +01:00
import java.util.Iterator;
2017-05-05 16:36:04 +02:00
import java.util.List;
2020-03-07 14:16:28 +01:00
import java.util.Objects;
2019-07-26 11:36:08 +02:00
import java.util.Timer;
import java.util.TimerTask;
2020-07-06 11:59:47 +02:00
import java.util.regex.Matcher;
import java.util.regex.Pattern;
2019-07-27 12:47:10 +02:00
2019-11-15 16:32:25 +01:00
import app.fedilab.android.R;
import app.fedilab.android.activities.AccountReportActivity;
2019-12-17 09:45:45 +01:00
import app.fedilab.android.activities.BaseActivity;
2019-11-15 16:32:25 +01:00
import app.fedilab.android.activities.CustomSharingActivity;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.activities.ShowAccountActivity;
import app.fedilab.android.activities.ShowConversationActivity;
2019-10-09 18:49:33 +02:00
import app.fedilab.android.activities.SlideMediaActivity;
2019-11-15 16:32:25 +01:00
import app.fedilab.android.activities.TootActivity;
import app.fedilab.android.activities.TootInfoActivity;
import app.fedilab.android.asynctasks.ManagePollAsyncTask;
import app.fedilab.android.asynctasks.PostActionAsyncTask;
import app.fedilab.android.asynctasks.PostNotificationsAsyncTask;
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
2019-05-18 11:10:30 +02:00
import app.fedilab.android.client.API;
import app.fedilab.android.client.APIResponse;
import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.client.Entities.Attachment;
import app.fedilab.android.client.Entities.Emojis;
import app.fedilab.android.client.Entities.Error;
import app.fedilab.android.client.Entities.Notification;
import app.fedilab.android.client.Entities.Poll;
import app.fedilab.android.client.Entities.PollOptions;
import app.fedilab.android.client.Entities.Status;
import app.fedilab.android.helper.CrossActions;
import app.fedilab.android.helper.CustomTextView;
import app.fedilab.android.helper.Helper;
2019-11-08 18:39:55 +01:00
import app.fedilab.android.helper.ThemeHelper;
2019-05-18 11:10:30 +02:00
import app.fedilab.android.interfaces.OnPollInterface;
import app.fedilab.android.interfaces.OnPostActionInterface;
import app.fedilab.android.interfaces.OnPostNotificationsActionInterface;
import app.fedilab.android.interfaces.OnRetrieveEmojiAccountInterface;
import app.fedilab.android.interfaces.OnRetrieveEmojiInterface;
2019-11-15 16:32:25 +01:00
import app.fedilab.android.interfaces.OnRetrieveImageInterface;
import es.dmoral.toasty.Toasty;
2019-05-18 11:10:30 +02:00
2019-07-27 15:05:29 +02:00
import static android.content.Context.MODE_PRIVATE;
2019-05-18 11:10:30 +02:00
import static app.fedilab.android.activities.BaseMainActivity.social;
2020-06-19 17:17:17 +02:00
import static app.fedilab.android.helper.Helper.makeEmojis;
2017-05-05 16:36:04 +02:00
/**
* Created by Thomas on 24/04/2017.
* Adapter for Status
*/
2017-10-24 14:33:14 +02:00
2020-07-14 09:44:16 +02:00
public abstract class BaseNotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements OnPostActionInterface, OnPostNotificationsActionInterface, OnRetrieveEmojiInterface, OnRetrieveEmojiAccountInterface, OnPollInterface, OnRetrieveImageInterface {
2017-05-05 16:36:04 +02:00
2019-11-15 16:32:25 +01:00
private final Object lock = new Object();
2020-07-14 09:44:16 +02:00
protected Context context;
2017-05-05 16:36:04 +02:00
private List<Notification> notifications;
2020-07-14 09:44:16 +02:00
private BaseNotificationsListAdapter notificationsListAdapter;
2017-08-04 14:38:18 +02:00
private int behaviorWithAttachments;
private boolean isOnWifi;
2018-09-08 15:34:25 +02:00
private NotificationsListAdapter.ViewHolder holder;
2018-11-03 14:45:55 +01:00
private int style;
2019-07-28 12:24:24 +02:00
private RecyclerView mRecyclerView;
2019-07-27 15:05:29 +02:00
private Runnable updateAnimatedEmoji = new Runnable() {
@Override
public void run() {
2019-08-17 18:54:54 +02:00
synchronized (lock) {
2019-09-06 17:55:14 +02:00
if (mRecyclerView != null && (mRecyclerView.getLayoutManager()) != null) {
2019-07-28 12:24:24 +02:00
int firstPosition = ((LinearLayoutManager) mRecyclerView.getLayoutManager()).findFirstCompletelyVisibleItemPosition();
int lastPosition = ((LinearLayoutManager) mRecyclerView.getLayoutManager()).findLastCompletelyVisibleItemPosition();
2020-04-09 18:57:12 +02:00
for (int i = firstPosition; i <= lastPosition; i++) {
2020-04-11 19:18:08 +02:00
if (mRecyclerView.findViewHolderForAdapterPosition(i) != null && mRecyclerView.findViewHolderForAdapterPosition(i) instanceof ViewHolder) {
2020-04-09 18:57:12 +02:00
((ViewHolder) Objects.requireNonNull(mRecyclerView.findViewHolderForAdapterPosition(i))).updateAnimatedEmoji();
2019-07-28 12:24:24 +02:00
}
}
2019-07-27 15:05:29 +02:00
}
}
}
};
private Handler mHandler = new Handler();
2019-08-18 17:41:10 +02:00
2017-08-04 14:38:18 +02:00
2020-07-14 09:44:16 +02:00
public BaseNotificationsListAdapter(boolean isOnWifi, int behaviorWithAttachments, List<Notification> notifications) {
2017-05-05 16:36:04 +02:00
this.notifications = notifications;
notificationsListAdapter = this;
2017-08-04 14:38:18 +02:00
this.isOnWifi = isOnWifi;
this.behaviorWithAttachments = behaviorWithAttachments;
2017-05-05 16:36:04 +02:00
}
2019-07-28 12:24:24 +02:00
@Override
2019-08-02 18:35:49 +02:00
public void onAttachedToRecyclerView(@NotNull RecyclerView recyclerView) {
2019-07-28 12:24:24 +02:00
super.onAttachedToRecyclerView(recyclerView);
mRecyclerView = recyclerView;
}
2017-05-05 16:36:04 +02:00
2019-08-18 18:38:22 +02:00
@Override
2019-09-06 17:55:14 +02:00
public void onDetachedFromRecyclerView(@NotNull RecyclerView recyclerView) {
2019-08-18 18:38:22 +02:00
super.onDetachedFromRecyclerView(recyclerView);
mRecyclerView = null;
}
@NonNull
2017-05-05 16:36:04 +02:00
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
2019-08-18 17:41:10 +02:00
context = parent.getContext();
2020-03-07 14:16:28 +01:00
LayoutInflater layoutInflater = LayoutInflater.from(this.context);
2017-10-24 14:33:14 +02:00
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_notification, parent, false));
2017-05-05 16:36:04 +02:00
}
2020-04-09 18:57:12 +02:00
@SuppressLint("ClickableViewAccessibility")
2017-05-05 16:36:04 +02:00
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
2017-05-05 16:36:04 +02:00
2018-09-08 15:34:25 +02:00
holder = (NotificationsListAdapter.ViewHolder) viewHolder;
2019-08-18 17:41:10 +02:00
context = holder.status_document_container.getContext();
2019-07-27 15:05:29 +02:00
2019-08-18 19:04:16 +02:00
holder.startUpdateTimer();
2017-05-05 16:36:04 +02:00
final Notification notification = notifications.get(position);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130);
int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110);
2017-05-05 16:36:04 +02:00
final float scale = context.getResources().getDisplayMetrics().density;
String type = notification.getType();
String typeString = "";
2017-08-27 16:36:18 +02:00
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
2018-02-09 17:39:09 +01:00
boolean expand_cw = sharedpreferences.getBoolean(Helper.SET_EXPAND_CW, false);
2018-12-04 19:21:24 +01:00
boolean confirmFav = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION_FAV, false);
boolean confirmBoost = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, true);
2019-03-19 02:12:29 +01:00
boolean hide_notification_delete = sharedpreferences.getBoolean(Helper.SET_HIDE_DELETE_BUTTON_ON_TAB, false);
2017-11-02 15:55:14 +01:00
2019-11-06 15:52:39 +01:00
2019-11-08 18:04:23 +01:00
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int iconColor = prefs.getInt("theme_icons_color", -1);
2019-11-15 16:32:25 +01:00
if (iconColor == -1) {
2019-11-08 18:04:23 +01:00
iconColor = ThemeHelper.getAttColor(context, R.attr.iconColor);
}
Helper.changeDrawableColor(context, R.drawable.ic_audio_wave, iconColor);
2019-11-09 17:11:55 +01:00
Helper.changeDrawableColor(context, R.drawable.ic_photo, R.color.cyanea_accent_reference);
Helper.changeDrawableColor(context, R.drawable.ic_remove_red_eye, R.color.cyanea_accent_reference);
Helper.changeDrawableColor(context, R.drawable.ic_fetch_more, R.color.cyanea_accent_reference);
2019-11-08 18:04:23 +01:00
Helper.changeDrawableColor(context, R.drawable.ic_fetch_more, iconColor);
Helper.changeDrawableColor(context, holder.status_reply, iconColor);
Helper.changeDrawableColor(context, R.drawable.ic_conversation, iconColor);
Helper.changeDrawableColor(context, R.drawable.ic_more_horiz, iconColor);
Helper.changeDrawableColor(context, holder.status_more, iconColor);
Helper.changeDrawableColor(context, holder.status_privacy, iconColor);
Helper.changeDrawableColor(context, R.drawable.ic_repeat, iconColor);
Helper.changeDrawableColor(context, R.drawable.ic_plus_one, iconColor);
Helper.changeDrawableColor(context, R.drawable.ic_pin_drop, iconColor);
2020-01-19 11:01:56 +01:00
2019-11-08 18:04:23 +01:00
holder.status_reply_count.setTextColor(iconColor);
holder.status_favorite_count.setTextColor(iconColor);
holder.status_reblog_count.setTextColor(iconColor);
2019-11-06 15:52:39 +01:00
2018-11-03 14:45:55 +01:00
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
2019-09-06 17:55:14 +02:00
} else if (theme == Helper.THEME_BLACK) {
2018-11-03 14:45:55 +01:00
style = R.style.DialogBlack;
2019-09-06 17:55:14 +02:00
} else {
2018-11-03 14:45:55 +01:00
style = R.style.Dialog;
}
2019-03-19 02:12:29 +01:00
2019-11-22 18:12:32 +01:00
int theme_text_color = prefs.getInt("theme_text_color", -1);
if (holder.notification_status_content != null && theme_text_color != -1) {
holder.notification_status_content.setTextColor(theme_text_color);
holder.status_spoiler.setTextColor(theme_text_color);
}
2019-11-08 18:04:23 +01:00
2019-11-06 15:52:39 +01:00
int reblogColor = prefs.getInt("theme_statuses_color", -1);
2019-11-15 16:32:25 +01:00
if (holder.main_linear_container != null && reblogColor != -1) {
2019-11-06 15:52:39 +01:00
holder.main_linear_container.setBackgroundColor(reblogColor);
}
2019-09-06 17:55:14 +02:00
if (hide_notification_delete)
2019-03-19 02:12:29 +01:00
holder.notification_delete.setVisibility(View.GONE);
2017-08-27 17:10:04 +02:00
Drawable imgH = null;
2018-12-24 11:47:49 +01:00
holder.status_date.setVisibility(View.VISIBLE);
2019-11-08 18:39:55 +01:00
holder.main_container_trans.setAlpha(.3f);
2019-09-06 17:55:14 +02:00
switch (type) {
2017-05-05 16:36:04 +02:00
case "mention":
holder.status_action_container.setVisibility(View.VISIBLE);
2019-09-06 17:55:14 +02:00
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
2020-04-08 15:29:02 +02:00
typeString = String.format("%s %s", notification.getAccount().getDisplay_name(), context.getString(R.string.notif_mention));
2017-07-31 19:29:14 +02:00
else
2019-09-06 17:55:14 +02:00
typeString = String.format("@%s %s", notification.getAccount().getUsername(), context.getString(R.string.notif_mention));
2017-10-11 14:58:52 +02:00
imgH = ContextCompat.getDrawable(context, R.drawable.ic_chat_bubble_outline);
2020-06-19 18:00:48 +02:00
if (notification.getStatus() != null && notification.getStatus().getVisibility().equals("direct")) {
2019-11-08 18:39:55 +01:00
holder.main_container_trans.setVisibility(View.GONE);
2019-11-15 16:32:25 +01:00
} else {
2019-11-08 18:39:55 +01:00
holder.main_container_trans.setVisibility(View.VISIBLE);
holder.main_container_trans.setAlpha(.1f);
}
2017-11-02 14:06:59 +01:00
holder.status_more.setVisibility(View.VISIBLE);
2017-05-05 16:36:04 +02:00
break;
2019-03-26 19:07:25 +01:00
case "poll":
holder.status_action_container.setVisibility(View.GONE);
2019-09-06 17:55:14 +02:00
typeString = context.getString(R.string.notif_poll);
2019-03-26 19:07:25 +01:00
imgH = ContextCompat.getDrawable(context, R.drawable.ic_view_list_poll_notif);
holder.main_container_trans.setVisibility(View.VISIBLE);
holder.status_more.setVisibility(View.GONE);
break;
2017-05-05 16:36:04 +02:00
case "reblog":
holder.status_action_container.setVisibility(View.GONE);
2019-09-06 17:55:14 +02:00
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
2020-04-08 15:29:02 +02:00
typeString = String.format("%s %s", notification.getAccount().getDisplay_name(), context.getString(R.string.notif_reblog));
2017-07-31 19:29:14 +02:00
else
2019-09-06 17:55:14 +02:00
typeString = String.format("@%s %s", notification.getAccount().getUsername(), context.getString(R.string.notif_reblog));
2017-10-28 17:15:06 +02:00
imgH = ContextCompat.getDrawable(context, R.drawable.ic_repeat_head);
2017-10-28 11:25:33 +02:00
holder.main_container_trans.setVisibility(View.VISIBLE);
2017-11-02 14:06:59 +01:00
holder.status_more.setVisibility(View.GONE);
2017-05-05 16:36:04 +02:00
break;
case "favourite":
holder.status_action_container.setVisibility(View.GONE);
2019-09-06 17:55:14 +02:00
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
2020-04-08 15:29:02 +02:00
typeString = String.format("%s %s", notification.getAccount().getDisplay_name(), context.getString(R.string.notif_favourite));
2017-07-31 19:29:14 +02:00
else
2019-09-06 17:55:14 +02:00
typeString = String.format("@%s %s", notification.getAccount().getUsername(), context.getString(R.string.notif_favourite));
2017-10-28 17:15:06 +02:00
imgH = ContextCompat.getDrawable(context, R.drawable.ic_star_border_header);
2017-10-28 11:25:33 +02:00
holder.main_container_trans.setVisibility(View.VISIBLE);
2017-11-02 14:06:59 +01:00
holder.status_more.setVisibility(View.GONE);
2017-05-05 16:36:04 +02:00
break;
2019-12-17 10:24:25 +01:00
case "follow_request":
holder.status_action_container.setVisibility(View.GONE);
holder.status_date.setVisibility(View.GONE);
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
2020-04-08 15:29:02 +02:00
typeString = String.format("%s %s", notification.getAccount().getDisplay_name(), context.getString(R.string.notif_follow_request));
2019-12-17 10:24:25 +01:00
else
typeString = String.format("@%s %s", notification.getAccount().getUsername(), context.getString(R.string.notif_follow_request));
imgH = ContextCompat.getDrawable(context, R.drawable.ic_follow_notif_header);
holder.main_container_trans.setVisibility(View.GONE);
break;
2017-05-05 16:36:04 +02:00
case "follow":
holder.status_action_container.setVisibility(View.GONE);
2018-12-24 11:47:49 +01:00
holder.status_date.setVisibility(View.GONE);
2019-09-06 17:55:14 +02:00
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
2020-04-08 15:29:02 +02:00
typeString = String.format("%s %s", notification.getAccount().getDisplay_name(), context.getString(R.string.notif_follow));
2017-07-31 19:29:14 +02:00
else
2019-09-06 17:55:14 +02:00
typeString = String.format("@%s %s", notification.getAccount().getUsername(), context.getString(R.string.notif_follow));
2017-08-27 17:10:04 +02:00
imgH = ContextCompat.getDrawable(context, R.drawable.ic_follow_notif_header);
2017-10-28 11:25:33 +02:00
holder.main_container_trans.setVisibility(View.GONE);
2017-05-05 16:36:04 +02:00
break;
}
2018-09-09 15:59:34 +02:00
2020-04-09 11:04:38 +02:00
if (notification.getAccount().getDisplayNameSpan() == null) {
2018-09-08 15:34:25 +02:00
holder.notification_type.setText(typeString);
2018-12-24 11:47:49 +01:00
notification.getAccount().setStored_displayname(notification.getAccount().getDisplay_name());
2020-06-19 17:17:17 +02:00
} else {
holder.notification_type.setText(typeString, TextView.BufferType.SPANNABLE);
makeEmojis(context, holder.notification_type, notification.getAccount().getDisplayNameSpan(), notification.getAccount().getEmojis());
}
2019-08-02 18:35:49 +02:00
2019-09-06 17:55:14 +02:00
if (imgH != null) {
2019-11-08 18:39:55 +01:00
DrawableCompat.setTint(imgH, ContextCompat.getColor(context, R.color.cyanea_accent));
2019-09-06 17:55:14 +02:00
holder.notification_type.setCompoundDrawablePadding((int) Helper.convertDpToPixel(5, context));
2017-08-27 17:10:04 +02:00
imgH.setBounds(0, 0, (int) (20 * iconSizePercent / 100 * scale + 0.5f), (int) (20 * iconSizePercent / 100 * scale + 0.5f));
}
2019-09-06 17:55:14 +02:00
holder.notification_type.setCompoundDrawables(imgH, null, null, null);
2017-08-27 17:10:04 +02:00
2020-03-08 10:29:06 +01:00
holder.status_privacy.getLayoutParams().height = (int) Helper.convertDpToPixel(((float) (20 * iconSizePercent) / 100), context);
holder.status_privacy.getLayoutParams().width = (int) Helper.convertDpToPixel(((float) (20 * iconSizePercent) / 100), context);
holder.status_reply.getLayoutParams().height = (int) Helper.convertDpToPixel(((float) (20 * iconSizePercent) / 100), context);
holder.status_reply.getLayoutParams().width = (int) Helper.convertDpToPixel(((float) (20 * iconSizePercent) / 100), context);
holder.status_spoiler.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) (14 * textSizePercent) / 100);
2020-03-08 10:29:06 +01:00
holder.notification_status_content.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) (14 * textSizePercent) / 100);
holder.notification_type.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) (14 * textSizePercent) / 100);
holder.status_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) (12 * textSizePercent) / 100);
2019-11-15 19:06:43 +01:00
int theme_text_header_1_line = prefs.getInt("theme_text_header_1_line", -1);
if (theme_text_header_1_line == -1) {
theme_text_header_1_line = ThemeHelper.getAttColor(context, R.attr.textColor);
}
holder.notification_type.setTextColor(theme_text_header_1_line);
2017-05-05 16:36:04 +02:00
holder.spark_button_fav.pressOnTouch(false);
holder.spark_button_reblog.pressOnTouch(false);
2018-12-04 07:53:19 +01:00
holder.spark_button_fav.setActiveImageTint(R.color.marked_icon);
holder.spark_button_reblog.setActiveImageTint(R.color.boost_icon);
2018-12-04 19:21:24 +01:00
holder.spark_button_fav.setDisableCircle(true);
holder.spark_button_reblog.setDisableCircle(true);
2019-11-08 18:04:23 +01:00
holder.spark_button_fav.setInActiveImageTintColor(iconColor);
holder.spark_button_reblog.setInActiveImageTintColor(iconColor);
2018-12-04 07:53:19 +01:00
holder.spark_button_fav.setColors(R.color.marked_icon, R.color.marked_icon);
2019-09-06 17:55:14 +02:00
holder.spark_button_fav.setImageSize((int) (20 * iconSizePercent / 100 * scale + 0.5f));
2020-03-08 10:29:06 +01:00
holder.spark_button_fav.setMinimumWidth((int) Helper.convertDpToPixel(((float) (20 * iconSizePercent) / 100 * scale + 0.5f), context));
2018-12-04 07:53:19 +01:00
holder.spark_button_reblog.setColors(R.color.boost_icon, R.color.boost_icon);
2019-09-06 17:55:14 +02:00
holder.spark_button_reblog.setImageSize((int) (20 * iconSizePercent / 100 * scale + 0.5f));
2020-03-08 10:29:06 +01:00
holder.spark_button_reblog.setMinimumWidth((int) Helper.convertDpToPixel(((float) (20 * iconSizePercent) / 100 * scale + 0.5f), context));
2018-12-04 07:53:19 +01:00
2020-07-15 18:27:35 +02:00
final Status status = notification.getStatus();
2019-09-06 17:55:14 +02:00
if (status != null) {
if (status.getMedia_attachments() == null || status.getMedia_attachments().size() < 1)
2017-05-05 16:36:04 +02:00
holder.status_document_container.setVisibility(View.GONE);
else
holder.status_document_container.setVisibility(View.VISIBLE);
2019-07-27 14:42:28 +02:00
2020-01-19 11:01:56 +01:00
holder.status_privacy.setOnClickListener(view -> {
String v = status.getVisibility();
2020-03-08 10:29:06 +01:00
holder.status_privacy.setContentDescription(context.getString(R.string.toot_visibility_tilte) + ": " + v);
2020-01-19 11:01:56 +01:00
});
2017-12-03 15:10:11 +01:00
holder.notification_status_content.setText(status.getContentSpan(), TextView.BufferType.SPANNABLE);
2020-06-19 17:17:17 +02:00
makeEmojis(context, holder.notification_status_content, status.getContentSpan(), status.getEmojis());
holder.status_spoiler.setText(status.getContentSpanCW(), TextView.BufferType.SPANNABLE);
2018-01-25 13:47:34 +01:00
holder.status_spoiler.setMovementMethod(LinkMovementMethod.getInstance());
holder.notification_status_content.setMovementMethod(LinkMovementMethod.getInstance());
2019-06-16 17:38:15 +02:00
if (status.getReplies_count() > 0)
holder.status_reply_count.setText(String.valueOf(status.getReplies_count()));
else
holder.status_reply_count.setText("");
2019-06-14 13:05:11 +02:00
if (status.getFavourites_count() > 0)
holder.status_favorite_count.setText(String.valueOf(status.getFavourites_count()));
2019-06-14 16:14:47 +02:00
else
holder.status_favorite_count.setText("");
2019-06-14 13:05:11 +02:00
if (status.getReblogs_count() > 0)
holder.status_reblog_count.setText(String.valueOf(status.getReblogs_count()));
2019-06-14 16:14:47 +02:00
else
holder.status_reblog_count.setText("");
2017-05-05 16:36:04 +02:00
holder.status_date.setText(Helper.dateDiff(context, status.getCreated_at()));
Helper.absoluteDateTimeReveal(context, holder.status_date, status.getCreated_at());
2019-09-06 17:55:14 +02:00
holder.status_mention_spoiler.setText(Helper.makeMentionsClick(context, status.getMentions()), TextView.BufferType.SPANNABLE);
holder.status_mention_spoiler.setMovementMethod(LinkMovementMethod.getInstance());
2017-05-05 16:36:04 +02:00
//Adds attachment -> disabled, to enable them uncomment the line below
//loadAttachments(status, holder);
holder.notification_status_container.setVisibility(View.VISIBLE);
2020-03-07 14:16:28 +01:00
holder.card_status_container.setOnClickListener(v -> {
Intent intent = new Intent(context, ShowConversationActivity.class);
Bundle b = new Bundle();
b.putParcelable("status", status);
intent.putExtras(b);
context.startActivity(intent);
});
2020-03-07 14:16:28 +01:00
holder.notification_status_content.setOnClickListener(v -> {
Intent intent = new Intent(context, ShowConversationActivity.class);
Bundle b = new Bundle();
b.putParcelable("status", status);
intent.putExtras(b);
context.startActivity(intent);
});
2018-01-26 10:13:32 +01:00
holder.status_action_container.setVisibility(View.VISIBLE);
2019-09-06 17:55:14 +02:00
if (!status.isFavAnimated()) {
2018-12-04 07:53:19 +01:00
if (status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited())) {
holder.spark_button_fav.setChecked(true);
} else {
holder.spark_button_fav.setChecked(false);
}
2019-09-06 17:55:14 +02:00
} else {
2018-12-05 09:35:38 +01:00
status.setFavAnimated(false);
holder.spark_button_fav.setChecked(true);
holder.spark_button_fav.setAnimationSpeed(1.0f);
holder.spark_button_fav.playAnimation();
2018-01-26 10:13:32 +01:00
}
2019-09-06 17:55:14 +02:00
if (!status.isBoostAnimated()) {
if (status.isReblogged() || (status.getReblog() != null && status.getReblog().isReblogged())) {
2018-12-04 07:53:19 +01:00
holder.spark_button_reblog.setChecked(true);
2019-09-06 17:55:14 +02:00
} else {
2018-12-04 07:53:19 +01:00
holder.spark_button_reblog.setChecked(false);
}
2019-09-06 17:55:14 +02:00
} else {
2018-12-05 09:35:38 +01:00
status.setBoostAnimated(false);
holder.spark_button_reblog.setChecked(true);
holder.spark_button_reblog.setAnimationSpeed(1.0f);
holder.spark_button_reblog.playAnimation();
2018-01-26 10:13:32 +01:00
}
2018-12-05 09:35:38 +01:00
2019-09-06 17:55:14 +02:00
if (status.getReblog() == null) {
if (status.getSpoiler_text() != null && status.getSpoiler_text().trim().length() > 0) {
2018-01-26 10:13:32 +01:00
holder.status_spoiler_container.setVisibility(View.VISIBLE);
2019-09-06 17:55:14 +02:00
if (!status.isSpoilerShown() && !expand_cw) {
2018-01-26 10:13:32 +01:00
holder.notification_status_container.setVisibility(View.GONE);
holder.status_spoiler_mention_container.setVisibility(View.VISIBLE);
holder.status_spoiler_button.setText(context.getString(R.string.load_attachment_spoiler));
2019-09-06 17:55:14 +02:00
} else {
holder.notification_status_container.setVisibility(View.VISIBLE);
2018-01-26 10:13:32 +01:00
holder.status_spoiler_mention_container.setVisibility(View.GONE);
holder.status_spoiler_button.setText(context.getString(R.string.load_attachment_spoiler_less));
}
2018-01-26 10:13:32 +01:00
} else {
holder.status_spoiler_container.setVisibility(View.GONE);
holder.status_spoiler_mention_container.setVisibility(View.GONE);
holder.notification_status_container.setVisibility(View.VISIBLE);
}
2019-09-06 17:55:14 +02:00
} else {
2018-01-26 10:13:32 +01:00
if (status.getReblog().getSpoiler_text() != null && status.getReblog().getSpoiler_text().trim().length() > 0) {
holder.status_spoiler_container.setVisibility(View.VISIBLE);
2019-09-06 17:55:14 +02:00
if (!status.isSpoilerShown() && !expand_cw) {
2018-01-26 10:13:32 +01:00
holder.notification_status_container.setVisibility(View.GONE);
holder.status_spoiler_mention_container.setVisibility(View.VISIBLE);
holder.status_spoiler_button.setText(context.getString(R.string.load_attachment_spoiler));
2019-09-06 17:55:14 +02:00
} else {
holder.notification_status_container.setVisibility(View.VISIBLE);
2018-01-26 10:13:32 +01:00
holder.status_spoiler_mention_container.setVisibility(View.GONE);
holder.status_spoiler_button.setText(context.getString(R.string.load_attachment_spoiler_less));
}
2018-01-26 10:13:32 +01:00
} else {
holder.status_spoiler_container.setVisibility(View.GONE);
holder.status_spoiler_mention_container.setVisibility(View.GONE);
holder.notification_status_container.setVisibility(View.VISIBLE);
}
2018-01-26 10:13:32 +01:00
}
2019-06-16 17:38:15 +02:00
2019-09-06 17:55:14 +02:00
if (type.equals("favourite") || type.equals("reblog")) {
2018-01-26 10:13:32 +01:00
holder.status_document_container.setVisibility(View.GONE);
2018-11-02 15:44:17 +01:00
holder.status_show_more.setVisibility(View.GONE);
2019-09-06 17:55:14 +02:00
} else {
2018-01-26 10:13:32 +01:00
if (status.getReblog() == null) {
2019-03-24 19:49:17 +01:00
if (status.getMedia_attachments() == null || status.getMedia_attachments().size() < 1) {
2018-01-26 10:13:32 +01:00
holder.status_document_container.setVisibility(View.GONE);
holder.status_show_more.setVisibility(View.GONE);
} else {
//If medias are loaded without any conditions or if device is on wifi
if (!status.isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || (behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi))) {
2018-11-02 15:44:17 +01:00
loadAttachments(notification, holder);
holder.status_show_more.setVisibility(View.GONE);
2018-01-26 10:13:32 +01:00
status.setAttachmentShown(true);
} else {
2018-01-26 10:13:32 +01:00
//Text depending if toots is sensitive or not
String textShowMore = (status.isSensitive()) ? context.getString(R.string.load_sensitive_attachment) : context.getString(R.string.load_attachment);
holder.status_show_more.setText(textShowMore);
if (!status.isAttachmentShown()) {
holder.status_show_more.setVisibility(View.VISIBLE);
holder.status_document_container.setVisibility(View.GONE);
2017-10-30 10:50:53 +01:00
} else {
2018-11-02 15:44:17 +01:00
loadAttachments(notification, holder);
}
2017-08-04 14:38:18 +02:00
}
}
}
2018-01-26 10:13:32 +01:00
}
2019-03-26 19:07:25 +01:00
2020-03-08 10:29:06 +01:00
if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
2019-03-26 19:07:25 +01:00
holder.rated.setVisibility(View.GONE);
2019-03-29 17:58:54 +01:00
holder.poll_container.setVisibility(View.GONE);
2019-03-26 19:07:25 +01:00
holder.multiple_choice.setVisibility(View.GONE);
holder.single_choice.setVisibility(View.GONE);
holder.submit_vote.setVisibility(View.GONE);
2019-09-06 17:55:14 +02:00
if (status.getPoll() != null && status.getPoll().getOptionsList() != null) {
2019-03-26 19:07:25 +01:00
Poll poll = status.getPoll();
2019-09-06 17:55:14 +02:00
if (poll.isVoted() || poll.isExpired()) {
2019-03-26 19:07:25 +01:00
holder.rated.setVisibility(View.VISIBLE);
int greaterValue = 0;
2019-09-06 17:55:14 +02:00
for (PollOptions pollOption : status.getPoll().getOptionsList()) {
if (pollOption.getVotes_count() > greaterValue)
2019-03-26 19:07:25 +01:00
greaterValue = pollOption.getVotes_count();
}
2020-04-09 18:57:12 +02:00
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
2020-04-09 14:09:43 +02:00
holder.rated.removeAllViews();
List<Integer> ownvotes = poll.getOwn_votes();
int j = 0;
2020-04-16 14:34:45 +02:00
if (poll.getOptionsList() != null) {
2020-04-16 12:22:48 +02:00
for (PollOptions pollOption : poll.getOptionsList()) {
View item = inflater.inflate(R.layout.layout_poll_item, new LinearLayout(context), false);
double value = ((double) (pollOption.getVotes_count() * 100) / (double) poll.getVoters_count());
TextView poll_item_percent = item.findViewById(R.id.poll_item_percent);
TextView poll_item_text = item.findViewById(R.id.poll_item_text);
ProgressBar poll_item_value = item.findViewById(R.id.poll_item_value);
2020-06-16 18:23:13 +02:00
poll_item_percent.setText(String.format("%s %%", (int) value));
2020-04-16 12:22:48 +02:00
poll_item_text.setText(pollOption.getTitle(), TextView.BufferType.SPANNABLE);
2020-06-19 17:17:17 +02:00
makeEmojis(context, poll_item_text, pollOption.getTitleSpan(), poll.getEmojis());
2020-04-16 12:22:48 +02:00
poll_item_value.setProgress((int) value);
holder.rated.addView(item);
if (pollOption.getVotes_count() == greaterValue) {
poll_item_percent.setTypeface(null, Typeface.BOLD);
poll_item_text.setTypeface(null, Typeface.BOLD);
}
if (ownvotes != null && ownvotes.contains(j)) {
Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_check_poll);
assert img != null;
img.setColorFilter(ContextCompat.getColor(context, R.color.cyanea_accent_reference), PorterDuff.Mode.SRC_IN);
img.setBounds(0, 0, (int) (20 * scale + 0.5f), (int) (20 * scale + 0.5f));
poll_item_text.setCompoundDrawables(null, null, img, null);
}
j++;
2019-03-26 19:07:25 +01:00
}
}
2019-09-06 17:55:14 +02:00
} else {
if (poll.isMultiple()) {
if ((holder.multiple_choice).getChildCount() > 0)
2019-04-28 11:15:57 +02:00
(holder.multiple_choice).removeAllViews();
2019-09-06 17:55:14 +02:00
for (PollOptions pollOption : poll.getOptionsList()) {
2019-04-28 11:15:57 +02:00
CheckBox cb = new CheckBox(context);
cb.setText(pollOption.getTitle());
2020-06-19 17:17:17 +02:00
makeEmojis(context, cb, pollOption.getTitleSpan(), poll.getEmojis());
2019-04-28 11:15:57 +02:00
holder.multiple_choice.addView(cb);
2019-03-26 19:07:25 +01:00
}
2019-04-28 11:15:57 +02:00
holder.multiple_choice.setVisibility(View.VISIBLE);
2019-09-06 17:55:14 +02:00
} else {
if ((holder.radio_group).getChildCount() > 0)
2019-04-28 11:15:57 +02:00
(holder.radio_group).removeAllViews();
2019-09-06 17:55:14 +02:00
for (PollOptions pollOption : poll.getOptionsList()) {
2019-04-28 11:15:57 +02:00
RadioButton rb = new RadioButton(context);
rb.setText(pollOption.getTitle());
2020-06-19 17:17:17 +02:00
makeEmojis(context, rb, pollOption.getTitleSpan(), poll.getEmojis());
2019-04-28 11:15:57 +02:00
holder.radio_group.addView(rb);
2019-03-26 19:07:25 +01:00
}
2019-04-28 11:15:57 +02:00
holder.single_choice.setVisibility(View.VISIBLE);
2019-03-26 19:07:25 +01:00
}
holder.submit_vote.setVisibility(View.VISIBLE);
2020-03-07 14:16:28 +01:00
holder.submit_vote.setOnClickListener(v -> {
int[] choice;
if (poll.isMultiple()) {
ArrayList<Integer> choices = new ArrayList<>();
int choicesCount = holder.multiple_choice.getChildCount();
for (int i = 0; i < choicesCount; i++) {
if (holder.multiple_choice.getChildAt(i) != null && holder.multiple_choice.getChildAt(i) instanceof CheckBox) {
if (((CheckBox) holder.multiple_choice.getChildAt(i)).isChecked()) {
choices.add(i);
2019-04-28 11:15:57 +02:00
}
}
2020-03-07 14:16:28 +01:00
}
choice = new int[choices.size()];
Iterator<Integer> iterator = choices.iterator();
for (int i = 0; i < choice.length; i++) {
choice[i] = iterator.next();
}
if (choice.length == 0)
return;
} else {
choice = new int[1];
choice[0] = -1;
int choicesCount = holder.radio_group.getChildCount();
for (int i = 0; i < choicesCount; i++) {
if (holder.radio_group.getChildAt(i) != null && holder.radio_group.getChildAt(i) instanceof RadioButton) {
if (((RadioButton) holder.radio_group.getChildAt(i)).isChecked()) {
choice[0] = i;
2019-04-28 11:15:57 +02:00
}
}
2019-03-26 19:07:25 +01:00
}
2020-03-07 14:16:28 +01:00
if (choice[0] == -1)
return;
2019-03-26 19:07:25 +01:00
}
2020-07-14 09:44:16 +02:00
new ManagePollAsyncTask(context, ManagePollAsyncTask.type_s.SUBMIT, status, choice, BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
2019-03-26 19:07:25 +01:00
});
}
2020-07-14 09:44:16 +02:00
holder.refresh_poll.setOnClickListener(v -> new ManagePollAsyncTask(context, ManagePollAsyncTask.type_s.REFRESH, status, null, BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR));
2019-03-26 19:07:25 +01:00
holder.poll_container.setVisibility(View.VISIBLE);
2019-11-19 18:11:49 +01:00
holder.number_votes.setText(context.getResources().getQuantityString(R.plurals.number_of_voters, status.getPoll().getVoters_count(), status.getPoll().getVoters_count()));
2020-03-08 10:29:06 +01:00
if (poll.isExpired()) {
2019-11-22 17:48:29 +01:00
holder.remaining_time.setText(context.getString(R.string.poll_finish_at, Helper.dateToStringPoll(poll.getExpires_at())));
2020-03-08 10:29:06 +01:00
} else {
2019-11-22 17:48:29 +01:00
holder.remaining_time.setText(context.getString(R.string.poll_finish_in, Helper.dateDiffPoll(context, poll.getExpires_at())));
}
2019-09-06 17:55:14 +02:00
} else {
2019-03-26 19:07:25 +01:00
holder.poll_container.setVisibility(View.GONE);
}
}
2020-03-07 14:16:28 +01:00
holder.spark_button_fav.setOnClickListener(v -> {
2019-01-22 15:02:08 +01:00
2020-03-07 14:16:28 +01:00
if (!status.isFavourited() && confirmFav)
status.setFavAnimated(true);
if (!status.isFavourited() && !confirmFav) {
status.setFavAnimated(true);
notifyNotificationChanged(notification);
2018-12-04 07:53:19 +01:00
}
2020-07-14 09:44:16 +02:00
CrossActions.doCrossAction(context, null, status, null, status.isFavourited() ? API.StatusAction.UNFAVOURITE : API.StatusAction.FAVOURITE, notificationsListAdapter, BaseNotificationsListAdapter.this, true);
2018-12-04 07:53:19 +01:00
});
2020-03-07 14:16:28 +01:00
holder.spark_button_reblog.setOnClickListener(v -> {
if (!status.isReblogged() && confirmBoost)
status.setBoostAnimated(true);
if (!status.isReblogged() && !confirmBoost) {
status.setBoostAnimated(true);
notifyNotificationChanged(notification);
2018-12-04 07:53:19 +01:00
}
2020-07-14 09:44:16 +02:00
CrossActions.doCrossAction(context, null, status, null, status.isReblogged() ? API.StatusAction.UNREBLOG : API.StatusAction.REBLOG, notificationsListAdapter, BaseNotificationsListAdapter.this, true);
2018-12-04 07:53:19 +01:00
});
2018-01-26 10:13:32 +01:00
//Spoiler opens
2020-03-07 14:16:28 +01:00
holder.status_spoiler_button.setOnClickListener(v -> {
notification.getStatus().setSpoilerShown(!status.isSpoilerShown());
notifyNotificationChanged(notification);
2018-01-26 10:13:32 +01:00
});
2019-09-06 17:55:14 +02:00
switch (status.getVisibility()) {
2018-01-26 10:13:32 +01:00
case "public":
holder.status_privacy.setImageResource(R.drawable.ic_public);
break;
case "unlisted":
holder.status_privacy.setImageResource(R.drawable.ic_lock_open);
break;
case "private":
holder.status_privacy.setImageResource(R.drawable.ic_lock_outline);
break;
case "direct":
holder.status_privacy.setImageResource(R.drawable.ic_mail_outline);
break;
2017-08-04 14:38:18 +02:00
}
2019-09-06 17:55:14 +02:00
switch (status.getVisibility()) {
2018-01-26 10:13:32 +01:00
case "direct":
case "private":
holder.status_reblog_count.setVisibility(View.GONE);
2018-12-05 09:35:38 +01:00
holder.spark_button_reblog.setVisibility(View.GONE);
2018-01-26 10:13:32 +01:00
break;
case "public":
case "unlisted":
holder.status_reblog_count.setVisibility(View.VISIBLE);
2018-12-05 09:35:38 +01:00
holder.spark_button_reblog.setVisibility(View.VISIBLE);
2018-01-26 10:13:32 +01:00
break;
}
2020-03-07 14:16:28 +01:00
holder.status_show_more.setOnClickListener(v -> {
notification.getStatus().setAttachmentShown(true);
notifyNotificationChanged(notification);
2020-03-07 14:16:28 +01:00
final int timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5);
2020-03-07 14:16:28 +01:00
if (timeout > 0) {
2020-03-07 14:16:28 +01:00
new CountDownTimer((timeout * 1000), 1000) {
2020-03-07 14:16:28 +01:00
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
notification.getStatus().setAttachmentShown(false);
notifyNotificationChanged(notification);
}
}.start();
}
});
2017-08-04 14:38:18 +02:00
2017-10-04 10:23:12 +02:00
2020-03-07 14:16:28 +01:00
holder.status_reply.setOnClickListener(v -> CrossActions.doCrossReply(context, status, RetrieveFeedsAsyncTask.Type.LOCAL, true));
2019-09-06 17:55:14 +02:00
if (!status.getVisibility().equals("direct"))
2020-03-07 14:16:28 +01:00
holder.spark_button_fav.setOnLongClickListener(view -> {
2020-07-14 09:44:16 +02:00
CrossActions.doCrossAction(context, null, status, null, status.isFavourited() ? API.StatusAction.UNFAVOURITE : API.StatusAction.FAVOURITE, notificationsListAdapter, BaseNotificationsListAdapter.this, false);
2020-03-07 14:16:28 +01:00
return true;
2019-09-06 17:55:14 +02:00
});
if (!status.getVisibility().equals("direct"))
2020-03-07 14:16:28 +01:00
holder.status_reply.setOnLongClickListener(view -> {
CrossActions.doCrossReply(context, status, RetrieveFeedsAsyncTask.Type.LOCAL, false);
return true;
2019-09-06 17:55:14 +02:00
});
if (!status.getVisibility().equals("direct"))
2020-03-07 14:16:28 +01:00
holder.spark_button_reblog.setOnLongClickListener(view -> {
2020-07-14 09:44:16 +02:00
CrossActions.doCrossAction(context, null, status, null, status.isReblogged() ? API.StatusAction.UNREBLOG : API.StatusAction.REBLOG, notificationsListAdapter, BaseNotificationsListAdapter.this, false);
2020-03-07 14:16:28 +01:00
return true;
2019-09-06 17:55:14 +02:00
});
} else {
2017-12-26 08:06:05 +01:00
holder.notification_status_container.setVisibility(View.GONE);
holder.status_spoiler_container.setVisibility(View.GONE);
holder.status_spoiler_mention_container.setVisibility(View.GONE);
2017-12-26 08:06:05 +01:00
holder.card_status_container.setOnClickListener(null);
2019-04-28 16:09:10 +02:00
holder.poll_container.setVisibility(View.GONE);
2017-12-26 08:06:05 +01:00
}
2020-03-07 14:16:28 +01:00
holder.notification_account_profile.setOnClickListener(v -> {
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
notification.getAccount().setDisplay_name(notification.getAccount().getStored_displayname());
b.putParcelable("account", notification.getAccount());
intent.putExtras(b);
context.startActivity(intent);
2017-05-05 16:36:04 +02:00
});
2020-03-07 14:16:28 +01:00
holder.notification_delete.setOnClickListener(v -> displayConfirmationNotificationDialog(notification));
2020-07-06 11:59:47 +02:00
2020-07-08 09:48:45 +02:00
if (notification.getAccount() != null) {
2020-07-06 11:59:47 +02:00
SpannableString wordtoSpan = new SpannableString("@" + notification.getAccount().getAcct());
Pattern hashAcct = Pattern.compile("(@" + notification.getAccount().getAcct() + ")");
int theme_text_header_2_line = prefs.getInt("theme_text_header_2_line", -1);
if (theme_text_header_2_line == -1) {
theme_text_header_2_line = ThemeHelper.getAttColor(context, R.attr.textHeader);
}
Matcher matcherAcct = hashAcct.matcher(wordtoSpan);
while (matcherAcct.find()) {
int matchStart = matcherAcct.start(1);
int matchEnd = matcherAcct.end();
if (wordtoSpan.length() >= matchEnd && matchStart < matchEnd) {
wordtoSpan.setSpan(new ForegroundColorSpan(theme_text_header_2_line), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
holder.notification_account_username.setText(wordtoSpan);
}
2017-09-29 18:44:20 +02:00
final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
2017-09-29 18:59:14 +02:00
final View attached = holder.status_more;
2020-03-07 14:16:28 +01:00
holder.status_more.setOnClickListener(v -> {
PopupMenu popup = new PopupMenu(context, attached);
assert status != null;
final boolean isOwner = status.getReblog() != null ? status.getReblog().getAccount().getId().equals(userId) : status.getAccount().getId().equals(userId);
popup.getMenuInflater()
.inflate(R.menu.option_toot, popup.getMenu());
if (notification.getType().equals("mention"))
popup.getMenu().findItem(R.id.action_timed_mute).setVisible(true);
else
popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false);
if (status.getVisibility().equals("private") || status.getVisibility().equals("direct")) {
popup.getMenu().findItem(R.id.action_mention).setVisible(false);
}
if (popup.getMenu().findItem(R.id.action_redraft) != null)
popup.getMenu().findItem(R.id.action_redraft).setVisible(false);
if (popup.getMenu().findItem(R.id.action_translate) != null)
popup.getMenu().findItem(R.id.action_translate).setVisible(false);
final String[] stringArrayConf;
if (isOwner) {
popup.getMenu().findItem(R.id.action_block).setVisible(false);
popup.getMenu().findItem(R.id.action_mute).setVisible(false);
popup.getMenu().findItem(R.id.action_report).setVisible(false);
stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm);
if (social != UpdateAccountInfoAsyncTask.SOCIAL.MASTODON && social != UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
2019-08-27 18:22:34 +02:00
popup.getMenu().findItem(R.id.action_stats).setVisible(false);
2017-12-25 18:28:56 +01:00
}
2020-03-07 14:16:28 +01:00
} else {
popup.getMenu().findItem(R.id.action_stats).setVisible(false);
popup.getMenu().findItem(R.id.action_remove).setVisible(false);
stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm);
}
if (status.getAccount().getAcct().split("@").length < 2)
popup.getMenu().findItem(R.id.action_block_domain).setVisible(false);
2019-02-15 18:50:26 +01:00
2020-03-07 14:16:28 +01:00
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
popup.getMenu().findItem(R.id.action_info).setVisible(false);
popup.getMenu().findItem(R.id.action_report).setVisible(false);
popup.getMenu().findItem(R.id.action_block_domain).setVisible(false);
popup.getMenu().findItem(R.id.action_mute_conversation).setVisible(false);
2019-02-15 18:50:26 +01:00
2020-03-07 14:16:28 +01:00
}
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
popup.getMenu().findItem(R.id.action_admin).setVisible(false);
} else {
boolean display_admin_statuses = sharedpreferences.getBoolean(Helper.SET_DISPLAY_ADMIN_STATUSES + userId + Helper.getLiveInstance(context), false);
if (!display_admin_statuses) {
popup.getMenu().findItem(R.id.action_admin).setVisible(false);
}
2020-03-07 14:16:28 +01:00
}
if (status.isMuted())
popup.getMenu().findItem(R.id.action_mute_conversation).setTitle(R.string.unmute_conversation);
else
popup.getMenu().findItem(R.id.action_mute_conversation).setTitle(R.string.mute_conversation);
boolean custom_sharing = sharedpreferences.getBoolean(Helper.SET_CUSTOM_SHARING, false);
if (custom_sharing && status.getVisibility().equals("public"))
popup.getMenu().findItem(R.id.action_custom_sharing).setVisible(true);
popup.setOnMenuItemClickListener(item -> {
AlertDialog.Builder builderInner;
final API.StatusAction doAction;
switch (item.getItemId()) {
case R.id.action_remove:
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[0]);
doAction = API.StatusAction.UNSTATUS;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
builderInner.setMessage(Html.fromHtml(status.getContent()));
break;
case R.id.action_mute:
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[0]);
doAction = API.StatusAction.MUTE;
break;
case R.id.action_mute_conversation:
if (status.isMuted())
doAction = API.StatusAction.UNMUTE_CONVERSATION;
else
doAction = API.StatusAction.MUTE_CONVERSATION;
2020-07-14 09:44:16 +02:00
new PostActionAsyncTask(context, doAction, status.getId(), BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
2020-03-07 14:16:28 +01:00
return true;
case R.id.action_open_browser:
Helper.openBrowser(context, status.getUrl());
return true;
case R.id.action_admin:
String account_id = status.getReblog() != null ? status.getReblog().getAccount().getId() : status.getAccount().getId();
Intent intent = new Intent(context, AccountReportActivity.class);
Bundle b = new Bundle();
b.putString("account_id", account_id);
intent.putExtras(b);
context.startActivity(intent);
return true;
case R.id.action_stats:
2020-07-15 18:27:35 +02:00
notificationStatusChart(status);
2020-03-07 14:16:28 +01:00
return true;
case R.id.action_info:
intent = new Intent(context, TootInfoActivity.class);
b = new Bundle();
if (status.getReblog() != null) {
b.putString("toot_id", status.getReblog().getId());
b.putInt("toot_reblogs_count", status.getReblog().getReblogs_count());
b.putInt("toot_favorites_count", status.getReblog().getFavourites_count());
} else {
b.putString("toot_id", status.getId());
b.putInt("toot_reblogs_count", status.getReblogs_count());
b.putInt("toot_favorites_count", status.getFavourites_count());
}
intent.putExtras(b);
context.startActivity(intent);
return true;
case R.id.action_block_domain:
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[3]);
doAction = API.StatusAction.BLOCK_DOMAIN;
String domain = status.getAccount().getAcct().split("@")[1];
builderInner.setMessage(context.getString(R.string.block_domain_confirm_message, domain));
break;
case R.id.action_block:
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[1]);
doAction = API.StatusAction.BLOCK;
break;
case R.id.action_report:
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[2]);
doAction = API.StatusAction.REPORT;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
builderInner.setMessage(Html.fromHtml(status.getContent()));
break;
case R.id.action_copy:
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
String content;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
else
content = Html.fromHtml(status.getContent()).toString();
ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content);
assert clipboard != null;
clipboard.setPrimaryClip(clip);
Toasty.info(context, context.getString(R.string.clipboard), Toast.LENGTH_LONG).show();
return true;
case R.id.action_copy_link:
clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
2017-09-29 18:44:20 +02:00
2020-03-07 14:16:28 +01:00
clip = ClipData.newPlainText(Helper.CLIP_BOARD, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl());
if (clipboard != null) {
clipboard.setPrimaryClip(clip);
Toasty.info(context, context.getString(R.string.clipboard_url), Toast.LENGTH_LONG).show();
2017-09-29 18:44:20 +02:00
}
2020-03-07 14:16:28 +01:00
return true;
case R.id.action_share:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via));
sendIntent.putExtra(Intent.EXTRA_TEXT, status.getUrl());
sendIntent.setType("text/plain");
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with)));
return true;
case R.id.action_custom_sharing:
Intent intentCustomSharing = new Intent(context, CustomSharingActivity.class);
Bundle bCustomSharing = new Bundle();
if (status.getReblog() != null) {
bCustomSharing.putParcelable("status", status.getReblog());
} else {
bCustomSharing.putParcelable("status", status);
2017-09-29 18:44:20 +02:00
2017-12-25 18:28:56 +01:00
}
2020-03-07 14:16:28 +01:00
intentCustomSharing.putExtras(bCustomSharing);
context.startActivity(intentCustomSharing);
return true;
case R.id.action_mention:
Handler handler = new Handler();
handler.postDelayed(() -> {
Intent intent1 = new Intent(context, TootActivity.class);
Bundle b1 = new Bundle();
b1.putString("tootMention", (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct());
b1.putString("urlMention", (status.getReblog() != null) ? status.getReblog().getUrl() : status.getUrl());
intent1.putExtras(b1);
context.startActivity(intent1);
}, 500);
return true;
default:
2017-12-25 18:28:56 +01:00
return true;
2020-03-07 14:16:28 +01:00
}
//Text for report
EditText input = null;
if (doAction == API.StatusAction.REPORT) {
input = new EditText(context);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
input.setLayoutParams(lp);
builderInner.setView(input);
}
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
final EditText finalInput = input;
builderInner.setPositiveButton(R.string.yes, (dialog, which) -> {
if (doAction == API.StatusAction.UNSTATUS) {
String targetedId = status.getId();
2020-07-14 09:44:16 +02:00
new PostActionAsyncTask(context, doAction, targetedId, BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
2020-03-07 14:16:28 +01:00
} else if (doAction == API.StatusAction.REPORT) {
String comment = null;
if (finalInput.getText() != null)
comment = finalInput.getText().toString();
2020-07-14 09:44:16 +02:00
new PostActionAsyncTask(context, doAction, status.getId(), status, comment, BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
2020-03-07 14:16:28 +01:00
} else {
String targetedId = status.getAccount().getId();
2020-07-14 09:44:16 +02:00
new PostActionAsyncTask(context, doAction, targetedId, BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
2017-09-29 18:44:20 +02:00
}
2020-03-07 14:16:28 +01:00
dialog.dismiss();
2017-09-29 18:44:20 +02:00
});
2020-03-07 14:16:28 +01:00
builderInner.show();
return true;
});
popup.show();
});
2020-03-07 14:16:28 +01:00
holder.notification_status_content.setOnTouchListener((view, motionEvent) -> {
if (motionEvent.getAction() == MotionEvent.ACTION_UP && !view.hasFocus()) {
try {
view.requestFocus();
} catch (Exception ignored) {
2018-09-15 17:45:33 +02:00
}
}
2020-03-07 14:16:28 +01:00
return false;
2018-09-15 17:45:33 +02:00
});
2019-11-09 14:35:45 +01:00
2017-05-05 16:36:04 +02:00
//Profile picture
Helper.loadGiF(context, notification.getAccount(), holder.notification_account_profile);
2017-10-24 14:33:14 +02:00
}
2019-09-06 17:55:14 +02:00
private void notifyNotificationChanged(Notification notification) {
for (int i = 0; i < notificationsListAdapter.getItemCount(); i++) {
2019-08-08 09:43:12 +02:00
2020-03-07 14:16:28 +01:00
if (notificationsListAdapter.getItemAt(i) != null && Objects.requireNonNull(notificationsListAdapter.getItemAt(i)).getId().trim().compareTo(notification.getId().trim()) == 0) {
try {
2019-09-06 17:55:14 +02:00
if (mRecyclerView != null) {
2019-08-08 09:43:12 +02:00
int finalI = i;
2020-03-07 14:16:28 +01:00
mRecyclerView.post(() -> notificationsListAdapter.notifyItemChanged(finalI));
2019-08-08 09:43:12 +02:00
}
break;
2019-09-06 17:55:14 +02:00
} catch (Exception ignored) {
}
}
}
}
2019-01-11 14:55:53 +01:00
2019-09-06 17:55:14 +02:00
public void notifyNotificationWithActionChanged(Status status) {
2019-01-11 14:55:53 +01:00
for (int i = 0; i < notificationsListAdapter.getItemCount(); i++) {
2020-03-07 14:16:28 +01:00
if (notificationsListAdapter.getItemAt(i) != null && Objects.requireNonNull(notificationsListAdapter.getItemAt(i)).getStatus() != null && Objects.requireNonNull(notificationsListAdapter.getItemAt(i)).getStatus().getId().equals(status.getId())) {
2019-01-11 14:55:53 +01:00
try {
2019-09-06 17:55:14 +02:00
if (notifications.get(i).getStatus() != null) {
2019-03-30 18:48:38 +01:00
notifications.get(i).setStatus(status);
2019-08-08 09:43:12 +02:00
notifyItemChanged(i);
2019-09-06 17:55:14 +02:00
if (mRecyclerView != null) {
2019-08-08 09:43:12 +02:00
int finalI = i;
2020-03-07 14:16:28 +01:00
mRecyclerView.post(() -> notificationsListAdapter.notifyItemChanged(finalI));
2019-08-08 09:43:12 +02:00
}
2019-01-13 11:34:32 +01:00
break;
2019-01-11 14:55:53 +01:00
}
2019-09-06 17:55:14 +02:00
} catch (Exception ignored) {
}
2019-01-11 14:55:53 +01:00
}
}
}
2017-10-24 14:33:14 +02:00
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return notifications.size();
2017-05-05 16:36:04 +02:00
}
2020-07-14 09:44:16 +02:00
protected Notification getItemAt(int position) {
2019-09-06 17:55:14 +02:00
if (notifications.size() > position)
return notifications.get(position);
else
return null;
}
2017-07-30 11:21:55 +02:00
/**
* Display a validation message for notification deletion
2019-09-06 17:55:14 +02:00
*
2017-07-30 11:21:55 +02:00
* @param notification Notification
*/
2019-09-06 17:55:14 +02:00
private void displayConfirmationNotificationDialog(final Notification notification) {
2020-06-16 18:23:13 +02:00
final ArrayList<Integer> seletedItems = new ArrayList<>();
2017-08-27 16:36:18 +02:00
2018-11-03 14:45:55 +01:00
AlertDialog dialog = new AlertDialog.Builder(context, style)
2017-07-30 11:21:55 +02:00
.setTitle(R.string.delete_notification_ask)
2020-03-07 14:16:28 +01:00
.setMultiChoiceItems(new String[]{context.getString(R.string.delete_notification_ask_all)}, null, (dialog1, indexSelected, isChecked) -> {
if (isChecked) {
seletedItems.add(indexSelected);
} else {
if (seletedItems.contains(indexSelected))
seletedItems.remove(Integer.valueOf(indexSelected));
2017-07-30 11:21:55 +02:00
}
2020-03-07 14:16:28 +01:00
}).setPositiveButton(R.string.yes, (dialog13, id) -> {
if (seletedItems.size() > 0)
2020-07-14 09:44:16 +02:00
new PostNotificationsAsyncTask(context, null, BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
2020-03-07 14:16:28 +01:00
else
2020-07-14 09:44:16 +02:00
new PostNotificationsAsyncTask(context, notification.getId(), BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
2020-03-07 14:16:28 +01:00
dialog13.dismiss();
}).setNegativeButton(R.string.cancel, (dialog12, id) -> dialog12.dismiss()).create();
2017-07-30 11:21:55 +02:00
dialog.show();
}
@Override
public void onPostAction(int statusCode, API.StatusAction statusAction, String targetedId, Error error) {
2019-09-06 17:55:14 +02:00
if (error != null) {
Toasty.error(context, error.getError(), Toast.LENGTH_LONG).show();
return;
}
Helper.manageMessageStatusCode(context, statusCode, statusAction);
//When muting or blocking an account, its status are removed from the list
List<Notification> notificationsToRemove = new ArrayList<>();
2019-09-06 17:55:14 +02:00
if (statusAction == API.StatusAction.MUTE || statusAction == API.StatusAction.BLOCK) {
for (Notification notification : notifications) {
if (notification.getType().toLowerCase().equals("mention") && notification.getAccount().getId().equals(targetedId))
notificationsToRemove.add(notification);
}
notifications.removeAll(notificationsToRemove);
notificationsListAdapter.notifyDataSetChanged();
}
}
2017-07-30 11:21:55 +02:00
@Override
public void onPostNotificationsAction(APIResponse apiResponse, String targetedId) {
2019-09-06 17:55:14 +02:00
if (apiResponse.getError() != null) {
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
2017-07-30 11:21:55 +02:00
return;
}
2019-09-06 17:55:14 +02:00
if (targetedId != null) {
int position = 0;
for (Notification notif : notifications) {
if (notif.getId().equals(targetedId)) {
notifications.remove(notif);
notificationsListAdapter.notifyItemRemoved(position);
break;
}
position++;
}
2019-09-06 17:55:14 +02:00
Toasty.success(context, context.getString(R.string.delete_notification), Toast.LENGTH_LONG).show();
} else {
2017-12-28 14:03:08 +01:00
int size = notifications.size();
2017-07-30 11:21:55 +02:00
notifications.clear();
2017-12-28 14:03:08 +01:00
notificationsListAdapter.notifyItemRangeRemoved(0, size);
2019-09-06 17:55:14 +02:00
Toasty.success(context, context.getString(R.string.delete_notification_all), Toast.LENGTH_LONG).show();
2017-07-30 11:21:55 +02:00
}
}
2019-09-06 17:55:14 +02:00
private void loadAttachments(final Notification notification, ViewHolder holder) {
2018-11-02 15:44:17 +01:00
List<Attachment> attachments = notification.getStatus().getMedia_attachments();
2019-09-06 17:55:14 +02:00
if (attachments != null && attachments.size() > 0) {
2017-08-04 14:38:18 +02:00
int i = 0;
2017-11-04 08:05:50 +01:00
holder.status_document_container.setVisibility(View.VISIBLE);
2019-09-06 17:55:14 +02:00
if (attachments.size() == 1) {
2017-08-04 14:38:18 +02:00
holder.status_container2.setVisibility(View.GONE);
2019-09-06 17:55:14 +02:00
if (attachments.get(0).getUrl().trim().contains("missing.png"))
2017-08-04 14:38:18 +02:00
holder.status_document_container.setVisibility(View.GONE);
2019-09-06 17:55:14 +02:00
} else if (attachments.size() == 2) {
2017-08-04 14:38:18 +02:00
holder.status_container2.setVisibility(View.VISIBLE);
holder.status_container3.setVisibility(View.GONE);
2017-11-04 08:05:50 +01:00
holder.status_prev4_container.setVisibility(View.GONE);
2019-09-06 17:55:14 +02:00
if (attachments.get(1).getUrl().trim().contains("missing.png"))
2017-08-04 14:38:18 +02:00
holder.status_container2.setVisibility(View.GONE);
2019-09-06 17:55:14 +02:00
} else if (attachments.size() == 3) {
2017-08-04 14:38:18 +02:00
holder.status_container2.setVisibility(View.VISIBLE);
holder.status_container3.setVisibility(View.VISIBLE);
holder.status_prev4_container.setVisibility(View.GONE);
2019-09-06 17:55:14 +02:00
if (attachments.get(2).getUrl().trim().contains("missing.png"))
2017-08-04 14:38:18 +02:00
holder.status_container3.setVisibility(View.GONE);
2019-09-06 17:55:14 +02:00
} else {
2017-11-04 08:05:50 +01:00
holder.status_container2.setVisibility(View.VISIBLE);
holder.status_container3.setVisibility(View.VISIBLE);
2017-08-04 14:38:18 +02:00
holder.status_prev4_container.setVisibility(View.VISIBLE);
2019-09-06 17:55:14 +02:00
if (attachments.get(2).getUrl().trim().contains("missing.png"))
2017-08-04 14:38:18 +02:00
holder.status_prev4_container.setVisibility(View.GONE);
}
int position = 1;
2019-09-06 17:55:14 +02:00
for (final Attachment attachment : attachments) {
2017-08-04 14:38:18 +02:00
ImageView imageView;
2019-09-06 17:55:14 +02:00
if (i == 0) {
2017-08-04 14:38:18 +02:00
imageView = holder.status_prev1;
2019-09-06 17:55:14 +02:00
if (attachment.getType().toLowerCase().equals("image"))
2017-08-04 14:38:18 +02:00
holder.status_prev1_play.setVisibility(View.GONE);
else
holder.status_prev1_play.setVisibility(View.VISIBLE);
2019-09-06 17:55:14 +02:00
} else if (i == 1) {
2017-08-04 14:38:18 +02:00
imageView = holder.status_prev2;
2019-09-06 17:55:14 +02:00
if (attachment.getType().toLowerCase().equals("image"))
2017-08-04 14:38:18 +02:00
holder.status_prev2_play.setVisibility(View.GONE);
else
holder.status_prev2_play.setVisibility(View.VISIBLE);
2019-09-06 17:55:14 +02:00
} else if (i == 2) {
2017-08-04 14:38:18 +02:00
imageView = holder.status_prev3;
2019-09-06 17:55:14 +02:00
if (attachment.getType().toLowerCase().equals("image"))
2017-08-04 14:38:18 +02:00
holder.status_prev3_play.setVisibility(View.GONE);
else
holder.status_prev3_play.setVisibility(View.VISIBLE);
2019-09-06 17:55:14 +02:00
} else {
2017-08-04 14:38:18 +02:00
imageView = holder.status_prev4;
2019-09-06 17:55:14 +02:00
if (attachment.getType().toLowerCase().equals("image"))
2017-08-04 14:38:18 +02:00
holder.status_prev4_play.setVisibility(View.GONE);
else
holder.status_prev4_play.setVisibility(View.VISIBLE);
}
String url = attachment.getPreview_url();
2019-09-06 17:55:14 +02:00
if (url == null || url.trim().equals(""))
2017-08-04 14:38:18 +02:00
url = attachment.getUrl();
2019-09-06 17:55:14 +02:00
if (!url.trim().contains("missing.png"))
2017-12-02 15:05:54 +01:00
Glide.with(imageView.getContext())
2017-12-02 11:02:25 +01:00
.load(url)
2019-12-17 15:29:46 +01:00
.override(640, 480)
2017-12-02 11:02:25 +01:00
.into(imageView);
2017-08-04 14:38:18 +02:00
final int finalPosition = position;
2020-03-07 14:16:28 +01:00
imageView.setOnClickListener(v -> {
Intent intent = new Intent(context, SlideMediaActivity.class);
Bundle b = new Bundle();
intent.putParcelableArrayListExtra("mediaArray", notification.getStatus().getMedia_attachments());
b.putInt("position", finalPosition);
2020-05-16 17:06:13 +02:00
b.putInt("bgcolor", context.getResources().getColor(R.color.cyanea_primary_dark));
2020-03-07 14:16:28 +01:00
intent.putExtras(b);
2020-07-06 11:48:59 +02:00
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
ActivityOptionsCompat options = ActivityOptionsCompat
2020-07-08 09:48:45 +02:00
.makeSceneTransitionAnimation((Activity) context, imageView, notification.getStatus().getMedia_attachments().get(finalPosition - 1).getUrl());
2020-07-06 11:48:59 +02:00
// start the new activity
context.startActivity(intent, options.toBundle());
2020-07-08 09:48:45 +02:00
} else {
2020-07-06 11:48:59 +02:00
// start the new activity
context.startActivity(intent);
}
2017-08-04 14:38:18 +02:00
});
i++;
position++;
}
2019-09-06 17:55:14 +02:00
} else {
2017-08-04 14:38:18 +02:00
holder.status_document_container.setVisibility(View.GONE);
}
holder.status_show_more.setVisibility(View.GONE);
}
2017-10-20 19:58:46 +02:00
@Override
2017-12-03 14:17:57 +01:00
public void onRetrieveEmoji(Status status, boolean fromTranslation) {
2020-04-16 16:01:13 +02:00
if (status != null) {
notifyNotificationWithActionChanged(status);
}
2019-01-02 14:22:57 +01:00
}
@Override
public void onRetrieveEmoji(Notification notification) {
2019-09-06 17:55:14 +02:00
if (notification != null && notification.getStatus() != null) {
2019-01-02 14:22:57 +01:00
notifyNotificationChanged(notification);
2017-10-20 19:58:46 +02:00
}
}
2017-11-01 19:19:37 +01:00
@Override
public void onRetrieveSearchEmoji(List<Emojis> emojis) {
}
2018-01-25 13:47:34 +01:00
@Override
public void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder) {
2018-01-25 13:47:34 +01:00
super.onViewAttachedToWindow(holder);
final NotificationsListAdapter.ViewHolder viewHolder = (NotificationsListAdapter.ViewHolder) holder;
// Bug workaround for losing text selection ability, see:
// https://code.google.com/p/android/issues/detail?id=208169
viewHolder.notification_status_content.setEnabled(false);
viewHolder.notification_status_content.setEnabled(true);
viewHolder.status_spoiler.setEnabled(false);
viewHolder.status_spoiler.setEnabled(true);
}
2017-05-05 16:36:04 +02:00
2018-09-08 15:34:25 +02:00
@Override
public void onRetrieveEmojiAccount(Account account) {
2019-09-06 17:55:14 +02:00
for (Notification notification : notifications) {
if (notification.getAccount().equals(account)) {
2018-09-14 19:12:39 +02:00
notifyNotificationChanged(notification);
}
}
2018-09-08 15:34:25 +02:00
}
2019-03-26 19:07:25 +01:00
@Override
public void onPoll(Status status, Poll poll) {
2020-04-16 16:01:13 +02:00
if (status != null) {
status.setPoll(poll);
notifyNotificationWithActionChanged(status);
}
2019-03-26 19:07:25 +01:00
}
2019-07-23 11:22:38 +02:00
@Override
public void onRetrieveImage(Status status, boolean fromTranslation) {
2019-09-06 17:55:14 +02:00
if (status != null) {
2019-07-23 11:22:38 +02:00
status.setEmojiFound(true);
notifyNotificationWithActionChanged(status);
}
}
2020-07-15 18:27:35 +02:00
protected abstract void notificationStatusChart(Status status);
2020-07-14 19:50:54 +02:00
2017-10-24 14:33:14 +02:00
class ViewHolder extends RecyclerView.ViewHolder {
2017-10-30 10:50:53 +01:00
FrameLayout card_status_container;
2018-10-28 11:32:23 +01:00
CustomTextView notification_status_content;
2017-05-05 16:36:04 +02:00
TextView notification_type;
LinearLayout status_spoiler_container;
2018-10-28 11:32:23 +01:00
CustomTextView status_spoiler;
Button status_spoiler_button;
2017-05-05 16:36:04 +02:00
TextView notification_account_username;
ImageView notification_account_profile;
2017-07-30 11:21:55 +02:00
ImageView notification_delete;
2017-05-05 16:36:04 +02:00
TextView status_favorite_count;
TextView status_reblog_count;
TextView status_date;
2019-06-16 17:38:15 +02:00
TextView status_reply_count;
2017-05-05 16:36:04 +02:00
LinearLayout status_document_container;
2019-06-11 13:17:53 +02:00
ConstraintLayout status_action_container;
2017-08-04 14:38:18 +02:00
Button status_show_more;
ImageView status_prev1;
ImageView status_prev2;
ImageView status_prev3;
ImageView status_prev4;
ImageView status_prev1_play;
ImageView status_prev2_play;
ImageView status_prev3_play;
ImageView status_prev4_play;
ImageView status_more;
2017-08-04 14:38:18 +02:00
RelativeLayout status_prev4_container;
LinearLayout status_container2;
LinearLayout status_container3;
2017-05-05 16:36:04 +02:00
LinearLayout notification_status_container;
2017-10-30 10:50:53 +01:00
RelativeLayout main_container_trans;
2017-05-05 16:36:04 +02:00
ImageView status_privacy;
LinearLayout status_spoiler_mention_container;
TextView status_mention_spoiler;
2019-06-16 17:38:15 +02:00
ImageView status_reply;
2018-12-04 07:53:19 +01:00
SparkButton spark_button_fav, spark_button_reblog;
2019-03-26 19:07:25 +01:00
//Poll
LinearLayout poll_container, single_choice, multiple_choice, rated;
RadioGroup radio_group;
2019-03-31 18:29:02 +02:00
TextView number_votes, remaining_time;
Button submit_vote, refresh_poll;
2019-11-06 15:52:39 +01:00
LinearLayout main_linear_container;
2017-10-25 13:28:45 +02:00
2017-10-24 14:33:14 +02:00
public ViewHolder(View itemView) {
super(itemView);
card_status_container = itemView.findViewById(R.id.card_status_container);
2017-10-28 11:25:33 +02:00
main_container_trans = itemView.findViewById(R.id.container_trans);
2017-10-24 14:33:14 +02:00
notification_status_container = itemView.findViewById(R.id.notification_status_container);
status_document_container = itemView.findViewById(R.id.status_document_container);
notification_status_content = itemView.findViewById(R.id.notification_status_content);
notification_account_username = itemView.findViewById(R.id.notification_account_username);
notification_type = itemView.findViewById(R.id.notification_type);
notification_account_profile = itemView.findViewById(R.id.notification_account_profile);
status_favorite_count = itemView.findViewById(R.id.status_favorite_count);
status_reblog_count = itemView.findViewById(R.id.status_reblog_count);
status_date = itemView.findViewById(R.id.status_date);
2019-06-16 17:38:15 +02:00
status_reply_count = itemView.findViewById(R.id.status_reply_count);
2017-10-24 14:33:14 +02:00
status_privacy = itemView.findViewById(R.id.status_privacy);
notification_delete = itemView.findViewById(R.id.notification_delete);
status_show_more = itemView.findViewById(R.id.status_show_more);
status_prev1 = itemView.findViewById(R.id.status_prev1);
status_prev2 = itemView.findViewById(R.id.status_prev2);
status_prev3 = itemView.findViewById(R.id.status_prev3);
status_prev4 = itemView.findViewById(R.id.status_prev4);
status_prev1_play = itemView.findViewById(R.id.status_prev1_play);
status_prev2_play = itemView.findViewById(R.id.status_prev2_play);
status_prev3_play = itemView.findViewById(R.id.status_prev3_play);
status_prev4_play = itemView.findViewById(R.id.status_prev4_play);
status_container2 = itemView.findViewById(R.id.status_container2);
status_container3 = itemView.findViewById(R.id.status_container3);
status_prev4_container = itemView.findViewById(R.id.status_prev4_container);
status_action_container = itemView.findViewById(R.id.status_action_container);
status_more = itemView.findViewById(R.id.status_more);
status_spoiler_container = itemView.findViewById(R.id.status_spoiler_container);
status_spoiler = itemView.findViewById(R.id.status_spoiler);
status_spoiler_button = itemView.findViewById(R.id.status_spoiler_button);
status_spoiler_mention_container = itemView.findViewById(R.id.status_spoiler_mention_container);
status_mention_spoiler = itemView.findViewById(R.id.status_mention_spoiler);
2019-06-16 17:38:15 +02:00
status_reply = itemView.findViewById(R.id.status_reply);
2019-09-06 17:55:14 +02:00
spark_button_fav = itemView.findViewById(R.id.spark_button_fav);
spark_button_reblog = itemView.findViewById(R.id.spark_button_reblog);
2019-03-26 19:07:25 +01:00
poll_container = itemView.findViewById(R.id.poll_container);
single_choice = itemView.findViewById(R.id.single_choice);
multiple_choice = itemView.findViewById(R.id.multiple_choice);
rated = itemView.findViewById(R.id.rated);
radio_group = itemView.findViewById(R.id.radio_group);
number_votes = itemView.findViewById(R.id.number_votes);
remaining_time = itemView.findViewById(R.id.remaining_time);
submit_vote = itemView.findViewById(R.id.submit_vote);
refresh_poll = itemView.findViewById(R.id.refresh_poll);
2019-11-06 15:52:39 +01:00
main_linear_container = itemView.findViewById(R.id.main_linear_container);
2017-10-24 14:33:14 +02:00
}
2019-07-27 15:05:29 +02:00
2019-11-15 16:32:25 +01:00
public View getView() {
return itemView;
}
2019-07-27 15:05:29 +02:00
void updateAnimatedEmoji() {
2019-07-28 12:24:24 +02:00
notification_status_content.invalidate();
notification_account_username.invalidate();
2019-07-27 15:05:29 +02:00
}
2019-08-18 19:04:16 +02:00
void startUpdateTimer() {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
2019-09-06 17:55:14 +02:00
if (!disableAnimatedEmoji) {
2019-12-17 09:45:45 +01:00
if (BaseActivity.timer == null) {
BaseActivity.timer = new Timer();
2019-08-18 19:04:16 +02:00
}
2019-12-17 09:45:45 +01:00
BaseActivity.timer.schedule(new TimerTask() {
2019-08-18 19:04:16 +02:00
@Override
public void run() {
mHandler.post(updateAnimatedEmoji);
}
}, 0, 130);
}
}
2017-05-05 16:36:04 +02:00
}
}