FairEmail/app/src/main/java/eu/faircode/email/AdapterMessage.java

4737 lines
210 KiB
Java
Raw Normal View History

2018-08-02 13:33:06 +00:00
package eu.faircode.email;
/*
2018-08-14 05:53:24 +00:00
This file is part of FairEmail.
2018-08-02 13:33:06 +00:00
2018-08-14 05:53:24 +00:00
FairEmail is free software: you can redistribute it and/or modify
2018-08-02 13:33:06 +00:00
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.
2018-10-29 10:46:49 +00:00
FairEmail is distributed in the hope that it will be useful,
2018-08-02 13:33:06 +00:00
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
2018-10-29 10:46:49 +00:00
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2018-08-02 13:33:06 +00:00
2018-12-31 08:04:33 +00:00
Copyright 2018-2019 by Marcel Bokhorst (M66B)
2018-08-02 13:33:06 +00:00
*/
2018-09-08 14:57:03 +00:00
import android.Manifest;
2019-08-16 12:31:31 +00:00
import android.animation.Animator;
2019-01-27 11:17:45 +00:00
import android.annotation.SuppressLint;
2019-03-07 12:29:03 +00:00
import android.annotation.TargetApi;
2019-04-19 06:31:00 +00:00
import android.app.Dialog;
2019-03-07 12:29:03 +00:00
import android.app.Notification;
import android.app.NotificationChannel;
2018-11-19 17:10:55 +00:00
import android.app.NotificationManager;
2018-09-08 14:57:03 +00:00
import android.content.ContentResolver;
2018-08-02 13:33:06 +00:00
import android.content.Context;
2018-09-19 10:00:58 +00:00
import android.content.DialogInterface;
2018-08-02 13:33:06 +00:00
import android.content.Intent;
import android.content.SharedPreferences;
2018-09-08 14:57:03 +00:00
import android.content.pm.PackageManager;
2018-12-10 18:27:04 +00:00
import android.content.res.ColorStateList;
2018-10-15 10:05:42 +00:00
import android.database.Cursor;
2018-09-12 16:54:48 +00:00
import android.graphics.Color;
2019-10-02 11:36:07 +00:00
import android.graphics.Paint;
2019-01-12 14:08:00 +00:00
import android.graphics.Rect;
2018-08-02 13:33:06 +00:00
import android.graphics.Typeface;
2019-09-07 18:13:58 +00:00
import android.graphics.drawable.AnimatedImageDrawable;
2018-09-08 14:57:03 +00:00
import android.graphics.drawable.Drawable;
import android.net.Uri;
2019-03-07 12:29:03 +00:00
import android.os.Build;
2018-09-01 06:27:13 +00:00
import android.os.Bundle;
2019-06-26 10:58:36 +00:00
import android.os.Handler;
2019-09-24 09:21:31 +00:00
import android.os.Looper;
2019-09-30 11:40:14 +00:00
import android.provider.CalendarContract;
2018-09-08 14:57:03 +00:00
import android.provider.ContactsContract;
2019-03-07 12:29:03 +00:00
import android.provider.Settings;
2019-06-28 15:06:13 +00:00
import android.text.Editable;
2018-10-15 10:05:42 +00:00
import android.text.Html;
import android.text.Layout;
import android.text.Spannable;
2018-12-20 20:12:28 +00:00
import android.text.SpannableStringBuilder;
2018-10-15 10:05:42 +00:00
import android.text.Spanned;
import android.text.TextUtils;
2019-06-28 15:06:13 +00:00
import android.text.TextWatcher;
2019-08-09 16:42:36 +00:00
import android.text.format.DateUtils;
2019-02-09 10:41:28 +00:00
import android.text.method.ArrowKeyMovementMethod;
2019-07-07 09:11:31 +00:00
import android.text.method.LinkMovementMethod;
2019-05-02 11:29:05 +00:00
import android.text.style.DynamicDrawableSpan;
2018-10-15 10:05:42 +00:00
import android.text.style.ImageSpan;
2018-12-20 20:12:28 +00:00
import android.text.style.QuoteSpan;
2018-10-15 10:05:42 +00:00
import android.text.style.URLSpan;
2019-10-04 16:59:37 +00:00
import android.util.Pair;
2018-12-30 16:17:22 +00:00
import android.util.TypedValue;
2019-08-10 08:42:28 +00:00
import android.view.KeyEvent;
2018-08-02 13:33:06 +00:00
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
2018-10-15 10:05:42 +00:00
import android.view.MotionEvent;
2019-09-01 13:42:53 +00:00
import android.view.ScaleGestureDetector;
2019-01-12 14:08:00 +00:00
import android.view.TouchDelegate;
2018-08-02 13:33:06 +00:00
import android.view.View;
2019-08-16 12:31:31 +00:00
import android.view.ViewAnimationUtils;
2019-06-26 10:58:36 +00:00
import android.view.ViewConfiguration;
2018-08-02 13:33:06 +00:00
import android.view.ViewGroup;
2019-05-30 17:46:58 +00:00
import android.view.ViewStub;
2019-12-24 10:39:45 +00:00
import android.view.accessibility.AccessibilityNodeInfo;
2019-08-16 12:31:31 +00:00
import android.view.animation.AccelerateDecelerateInterpolator;
2019-02-03 09:38:48 +00:00
import android.webkit.WebView;
2018-10-15 10:05:42 +00:00
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
2018-10-15 10:05:42 +00:00
import android.widget.EditText;
2018-12-21 14:19:07 +00:00
import android.widget.ImageButton;
import android.widget.ImageView;
2018-08-02 13:33:06 +00:00
import android.widget.TextView;
2019-08-13 08:27:17 +00:00
import android.widget.Toast;
2018-08-02 13:33:06 +00:00
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
2019-06-30 18:56:31 +00:00
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Group;
2019-09-09 12:06:43 +00:00
import androidx.core.content.FileProvider;
import androidx.core.graphics.ColorUtils;
2019-06-30 14:55:15 +00:00
import androidx.fragment.app.Fragment;
2019-04-19 06:31:00 +00:00
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.Observer;
2019-04-19 06:31:00 +00:00
import androidx.lifecycle.OnLifecycleEvent;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.paging.AsyncPagedListDiffer;
import androidx.paging.PagedList;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.selection.ItemDetailsLookup;
import androidx.recyclerview.selection.SelectionTracker;
import androidx.recyclerview.widget.AdapterListUpdateCallback;
import androidx.recyclerview.widget.AsyncDifferConfig;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
2019-07-06 10:52:00 +00:00
import com.github.chrisbanes.photoview.PhotoView;
2019-08-16 06:12:04 +00:00
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.bottomnavigation.LabelVisibilityMode;
2018-10-24 10:34:02 +00:00
import com.google.android.material.snackbar.Snackbar;
2018-10-15 10:05:42 +00:00
2019-02-03 09:38:48 +00:00
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
2018-10-15 10:05:42 +00:00
import java.io.File;
2018-10-15 10:05:42 +00:00
import java.io.IOException;
import java.io.UnsupportedEncodingException;
2019-09-24 09:21:31 +00:00
import java.lang.reflect.Field;
2019-10-30 12:38:25 +00:00
import java.nio.charset.StandardCharsets;
2019-08-13 08:27:17 +00:00
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
2019-03-10 08:02:17 +00:00
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
2018-10-15 10:05:42 +00:00
import java.util.ArrayList;
2018-11-26 11:42:06 +00:00
import java.util.Arrays;
2018-10-15 10:05:42 +00:00
import java.util.Collections;
import java.util.Date;
2019-08-11 14:08:53 +00:00
import java.util.HashMap;
import java.util.List;
2019-09-23 20:07:22 +00:00
import java.util.Locale;
2019-08-11 14:08:53 +00:00
import java.util.Map;
2019-06-25 07:46:31 +00:00
import java.util.Objects;
2019-09-24 09:21:31 +00:00
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
2018-10-15 10:05:42 +00:00
import javax.mail.Address;
import javax.mail.internet.InternetAddress;
2019-05-18 09:19:39 +00:00
import biweekly.Biweekly;
import biweekly.ICalendar;
import biweekly.component.VEvent;
2019-05-18 17:44:21 +00:00
import biweekly.parameter.ParticipationStatus;
2019-05-18 09:19:39 +00:00
import biweekly.property.Attendee;
2019-05-18 17:44:21 +00:00
import biweekly.property.Method;
import biweekly.property.Organizer;
2019-05-18 09:19:39 +00:00
import biweekly.util.ICalDate;
2019-06-30 19:43:48 +00:00
import static android.app.Activity.RESULT_OK;
2018-12-03 07:21:02 +00:00
public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHolder> {
2019-06-30 14:55:15 +00:00
private Fragment parentFragment;
2019-07-19 06:27:44 +00:00
private String type;
2018-08-06 13:36:55 +00:00
private ViewType viewType;
2019-01-15 17:39:12 +00:00
private boolean compact;
2018-12-30 16:33:52 +00:00
private int zoom;
2019-01-21 18:12:22 +00:00
private String sort;
2019-09-03 08:33:52 +00:00
private boolean ascending;
2019-04-28 13:16:26 +00:00
private boolean filter_duplicates;
private IProperties properties;
private Context context;
private LifecycleOwner owner;
private LayoutInflater inflater;
private boolean suitable;
private boolean unmetered;
private int dp36;
private int colorPrimary;
private int colorAccent;
private int textColorPrimary;
private int textColorSecondary;
private int colorUnread;
2019-10-07 11:07:26 +00:00
private int colorRead;
2019-10-02 12:07:55 +00:00
private int colorSeparator;
private boolean hasWebView;
private boolean contacts;
private float textSize;
private boolean date;
private boolean threading;
2019-10-09 11:24:16 +00:00
private boolean avatars;
private boolean name_email;
2019-10-03 08:19:27 +00:00
private boolean distinguish_contacts;
private Float font_size_sender;
private Float font_size_subject;
private boolean subject_top;
private boolean subject_italic;
private String subject_ellipsize;
2019-03-02 15:54:38 +00:00
private boolean flags;
private boolean flags_background;
2018-11-04 12:42:41 +00:00
private boolean preview;
private boolean preview_italic;
private int preview_lines;
private boolean attachments_alt;
private boolean contrast;
private boolean monospaced;
2019-10-04 13:25:04 +00:00
private boolean inline;
private boolean collapse_quotes;
private boolean authentication;
2019-06-25 07:46:31 +00:00
private static boolean debug;
2018-09-08 17:04:10 +00:00
private int answers = -1;
2019-05-15 11:37:35 +00:00
private boolean gotoTop = false;
2019-09-29 16:34:12 +00:00
private boolean firstClick = false;
2019-05-04 08:24:42 +00:00
private AsyncPagedListDiffer<TupleMessageEx> differ;
2019-08-11 14:08:53 +00:00
private Map<Long, Integer> keyPosition = new HashMap<>();
2018-10-24 09:09:07 +00:00
private SelectionTracker<Long> selectionTracker = null;
2018-08-02 13:33:06 +00:00
2018-08-26 12:17:09 +00:00
enum ViewType {UNIFIED, FOLDER, THREAD, SEARCH}
2018-08-02 13:33:06 +00:00
private NumberFormat NF = NumberFormat.getNumberInstance();
private DateFormat TF;
2019-07-15 19:28:25 +00:00
private DateFormat DTF;
2018-12-03 07:21:02 +00:00
private static final ExecutorService executor =
2019-10-10 11:26:44 +00:00
Helper.getBackgroundExecutor(2, "differ");
2019-07-29 20:27:55 +00:00
// https://github.com/newhouse/url-tracking-stripper
2019-04-17 11:37:14 +00:00
private static final List<String> PARANOID_QUERY = Collections.unmodifiableList(Arrays.asList(
"utm_source",
"utm_medium",
"utm_campaign",
"utm_term",
2019-07-29 20:27:55 +00:00
"utm_content",
"utm_name",
"utm_cid",
"utm_reader",
"utm_viz_id",
"utm_pubreferrer",
"utm_swu",
"gclid",
"fbclid"
2019-04-17 11:37:14 +00:00
));
2018-10-15 10:05:42 +00:00
public class ViewHolder extends RecyclerView.ViewHolder implements
2019-09-01 13:42:53 +00:00
View.OnKeyListener,
View.OnClickListener,
View.OnLongClickListener,
View.OnTouchListener,
2019-10-04 13:25:04 +00:00
View.OnLayoutChangeListener,
2019-09-01 13:42:53 +00:00
BottomNavigationView.OnNavigationItemSelectedListener {
private ViewCardOptional card;
2019-03-15 11:53:22 +00:00
private View view;
2019-08-14 11:18:42 +00:00
2019-08-14 15:21:37 +00:00
private View vwColor;
2019-09-01 17:19:50 +00:00
private ImageButton ibExpander;
2019-09-01 17:07:21 +00:00
private ImageView ibFlagged;
2019-10-22 17:41:15 +00:00
private ImageButton ibAvatar;
2019-12-23 16:34:46 +00:00
private View vwSeen;
2019-10-22 17:41:15 +00:00
private ImageButton ibAuth;
2019-10-21 09:54:39 +00:00
private ImageView ivPriorityHigh;
private ImageView ivPriorityLow;
2019-11-27 09:40:43 +00:00
private ImageView ivSigned;
2019-11-17 11:16:06 +00:00
private ImageView ivEncrypted;
2018-10-15 10:05:42 +00:00
private TextView tvFrom;
private TextView tvSize;
2018-10-15 10:05:42 +00:00
private TextView tvTime;
private ImageView ivType;
2019-10-22 17:41:15 +00:00
private ImageButton ibSnoozed;
2018-11-24 18:14:28 +00:00
private ImageView ivAnswered;
2018-10-15 10:05:42 +00:00
private ImageView ivAttachments;
private TextView tvSubject;
private TextView tvFolder;
private TextView tvCount;
private ImageView ivThread;
2019-10-18 17:35:40 +00:00
private TextView tvExpand;
2018-11-04 16:16:45 +00:00
private TextView tvPreview;
2018-10-15 10:05:42 +00:00
private TextView tvError;
2019-09-13 07:34:00 +00:00
private ImageButton ibHelp;
2018-10-15 10:05:42 +00:00
2019-05-30 17:46:58 +00:00
private View vsBody;
2019-09-01 16:59:51 +00:00
private ImageButton ibExpanderAddress;
2019-03-09 10:02:17 +00:00
2019-10-18 17:35:40 +00:00
private ImageView ivPlain;
private ImageView ivReceipt;
private ImageView ivBrowsed;
2019-05-08 14:44:01 +00:00
private ImageButton ibSearchContact;
private ImageButton ibNotifyContact;
private ImageButton ibAddContact;
2019-03-09 10:02:17 +00:00
private TextView tvFromExTitle;
private TextView tvToTitle;
private TextView tvReplyToTitle;
private TextView tvCcTitle;
private TextView tvBccTitle;
private TextView tvIdentityTitle;
2019-12-08 11:27:38 +00:00
private TextView tvSentTitle;
private TextView tvReceivedTitle;
2019-03-09 10:02:17 +00:00
private TextView tvSizeExTitle;
private TextView tvFromEx;
2018-10-15 10:05:42 +00:00
private TextView tvTo;
private TextView tvReplyTo;
private TextView tvCc;
private TextView tvBcc;
private TextView tvIdentity;
2019-12-08 11:27:38 +00:00
private TextView tvSent;
private TextView tvReceived;
private TextView tvSizeEx;
2019-03-09 10:02:17 +00:00
2018-10-15 10:05:42 +00:00
private TextView tvSubjectEx;
2019-01-29 20:15:24 +00:00
private TextView tvFlags;
2018-11-25 17:29:11 +00:00
private TextView tvKeywords;
2018-10-15 10:05:42 +00:00
private TextView tvHeaders;
2018-12-27 12:31:02 +00:00
private ContentLoadingProgressBar pbHeaders;
private TextView tvNoInternetHeaders;
2018-10-15 10:05:42 +00:00
private RecyclerView rvAttachment;
private CheckBox cbInline;
2019-01-05 14:56:19 +00:00
private Button btnSaveAttachments;
2019-08-15 13:01:26 +00:00
private Button btnDownloadAttachments;
private TextView tvNoInternetAttachments;
2019-08-16 06:12:04 +00:00
private BottomNavigationView bnvActions;
2019-10-08 16:05:23 +00:00
private Group grpActions;
2018-10-18 07:56:31 +00:00
private ImageButton ibFull;
2019-08-14 18:08:24 +00:00
private ImageButton ibImages;
2019-09-08 10:57:21 +00:00
private ImageButton ibUnsubscribe;
2019-11-27 09:40:43 +00:00
private ImageButton ibVerify;
2019-08-14 18:08:24 +00:00
private ImageButton ibDecrypt;
2018-10-15 10:05:42 +00:00
private TextView tvBody;
2019-10-04 13:25:04 +00:00
private View wvBody;
private ContentLoadingProgressBar pbBody;
private TextView tvNoInternetBody;
2019-10-05 10:54:41 +00:00
private ImageButton ibDownloading;
private Group grpDownloading;
2018-10-15 10:05:42 +00:00
2019-05-18 09:19:39 +00:00
private TextView tvCalendarSummary;
private TextView tvCalendarStart;
private TextView tvCalendarEnd;
private TextView tvAttendees;
2019-05-18 17:44:21 +00:00
private Button btnCalendarAccept;
private Button btnCalendarDecline;
private Button btnCalendarMaybe;
2019-09-30 11:40:14 +00:00
private ImageButton ibCalendar;
2019-05-18 09:19:39 +00:00
private ContentLoadingProgressBar pbCalendarWait;
2019-01-06 09:23:57 +00:00
private RecyclerView rvImage;
2019-05-17 16:54:44 +00:00
private Group grpAddresses;
2018-10-15 10:05:42 +00:00
private Group grpHeaders;
2019-05-18 09:19:39 +00:00
private Group grpCalendar;
2019-05-18 17:44:21 +00:00
private Group grpCalendarResponse;
2018-10-15 10:05:42 +00:00
private Group grpAttachments;
2019-05-13 18:44:08 +00:00
private Group grpImages;
2019-01-06 09:23:57 +00:00
private AdapterAttachment adapterAttachment;
private AdapterImage adapterImage;
2019-05-03 16:59:27 +00:00
private TwoStateOwner cowner = new TwoStateOwner(owner, "MessageAttachments");
private TwoStateOwner powner = new TwoStateOwner(owner, "MessagePopup");
2018-12-05 10:50:07 +00:00
2019-08-14 18:08:24 +00:00
private boolean hasJunk;
private boolean delete;
2019-09-01 13:42:53 +00:00
private ScaleGestureDetector gestureDetector;
2019-01-12 14:08:00 +00:00
ViewHolder(final View itemView) {
2018-08-02 13:33:06 +00:00
super(itemView);
2019-08-16 12:31:31 +00:00
card = itemView.findViewById(R.id.card);
2019-03-15 11:53:22 +00:00
view = itemView.findViewById(R.id.clItem);
2018-09-12 16:54:48 +00:00
vwColor = itemView.findViewById(R.id.vwColor);
2019-09-01 17:19:50 +00:00
ibExpander = itemView.findViewById(R.id.ibExpander);
2019-09-01 17:07:21 +00:00
ibFlagged = itemView.findViewById(R.id.ibFlagged);
2019-10-22 17:41:15 +00:00
ibAvatar = itemView.findViewById(R.id.ibAvatar);
2019-12-23 16:34:46 +00:00
vwSeen = itemView.findViewById(R.id.vwSeen);
2019-10-18 17:35:40 +00:00
ibAuth = itemView.findViewById(R.id.ibAuth);
2019-10-21 09:54:39 +00:00
ivPriorityHigh = itemView.findViewById(R.id.ivPriorityHigh);
ivPriorityLow = itemView.findViewById(R.id.ivPriorityLow);
2019-11-27 09:40:43 +00:00
ivSigned = itemView.findViewById(R.id.ivSigned);
2019-11-17 11:16:06 +00:00
ivEncrypted = itemView.findViewById(R.id.ivEncrypted);
tvFrom = itemView.findViewById(subject_top ? R.id.tvSubject : R.id.tvFrom);
tvSize = itemView.findViewById(R.id.tvSize);
2018-08-02 13:33:06 +00:00
tvTime = itemView.findViewById(R.id.tvTime);
ivType = itemView.findViewById(R.id.ivType);
2019-09-01 17:07:21 +00:00
ibSnoozed = itemView.findViewById(R.id.ibSnoozed);
2018-11-24 18:14:28 +00:00
ivAnswered = itemView.findViewById(R.id.ivAnswered);
ivAttachments = itemView.findViewById(R.id.ivAttachments);
tvSubject = itemView.findViewById(subject_top ? R.id.tvFrom : R.id.tvSubject);
2019-10-18 17:35:40 +00:00
tvExpand = itemView.findViewById(R.id.tvExpand);
2018-11-04 12:42:41 +00:00
tvPreview = itemView.findViewById(R.id.tvPreview);
2018-08-22 16:37:10 +00:00
tvFolder = itemView.findViewById(R.id.tvFolder);
2018-08-02 13:33:06 +00:00
tvCount = itemView.findViewById(R.id.tvCount);
2018-09-04 07:56:30 +00:00
ivThread = itemView.findViewById(R.id.ivThread);
tvError = itemView.findViewById(R.id.tvError);
2019-09-13 07:34:00 +00:00
ibHelp = itemView.findViewById(R.id.ibHelp);
2019-10-10 20:05:29 +00:00
if (tvSubject != null) {
tvSubject.setTextColor(colorRead);
if (compact)
if ("start".equals(subject_ellipsize))
tvSubject.setEllipsize(TextUtils.TruncateAt.START);
else if ("end".equals(subject_ellipsize))
tvSubject.setEllipsize(TextUtils.TruncateAt.END);
else
tvSubject.setEllipsize(TextUtils.TruncateAt.MIDDLE);
}
2019-12-24 10:39:45 +00:00
2019-12-24 11:10:07 +00:00
if (view != null)
view.setAccessibilityDelegate(new View.AccessibilityDelegate() {
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(host, info);
TupleMessageEx message = getMessage();
if (message == null)
return;
2019-12-24 17:00:08 +00:00
if (ibExpander != null && ibExpander.getVisibility() == View.VISIBLE) {
2019-12-24 11:10:07 +00:00
boolean expanded = properties.getValue("expanded", message.id);
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.ibExpander,
context.getString(expanded ? R.string.title_accessibility_collapse : R.string.title_accessibility_expand)));
}
2019-12-24 17:00:08 +00:00
if (ibAvatar != null && ibAvatar.getVisibility() == View.VISIBLE && ibAvatar.isEnabled())
2019-12-24 11:10:07 +00:00
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.ibAvatar,
context.getString(R.string.title_accessibility_view_contact)));
2019-12-24 17:00:08 +00:00
if (ibFlagged != null && ibFlagged.getVisibility() == View.VISIBLE && ibFlagged.isEnabled()) {
2019-12-24 11:10:07 +00:00
int flagged = (message.count - message.unflagged);
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.ibFlagged,
context.getString(flagged > 0 ? R.string.title_unflag : R.string.title_flag)));
}
2019-12-24 10:39:45 +00:00
}
2019-12-24 11:10:07 +00:00
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
TupleMessageEx message = getMessage();
if (message == null)
return false;
switch (action) {
case R.id.ibExpander:
onToggleMessage(message);
return true;
case R.id.ibAvatar:
onViewContact(message);
return true;
case R.id.ibFlagged:
onToggleFlag(message);
return true;
default:
return super.performAccessibilityAction(host, action, args);
}
2019-12-24 10:39:45 +00:00
}
2019-12-24 11:10:07 +00:00
});
2019-05-30 17:46:58 +00:00
}
2018-10-15 10:05:42 +00:00
2019-05-30 17:46:58 +00:00
private void ensureExpanded() {
if (vsBody != null)
return;
vsBody = ((ViewStub) itemView.findViewById(R.id.vsBody)).inflate();
ConstraintLayout inAttachments = vsBody.findViewById(R.id.inAttachments);
ConstraintLayout inAttachmentsAlt = vsBody.findViewById(R.id.inAttachmentsAlt);
inAttachments.setVisibility(attachments_alt ? View.GONE : View.VISIBLE);
inAttachmentsAlt.setVisibility(attachments_alt ? View.VISIBLE : View.GONE);
ConstraintLayout attachments = (attachments_alt ? inAttachmentsAlt : inAttachments);
2019-09-01 16:59:51 +00:00
ibExpanderAddress = vsBody.findViewById(R.id.ibExpanderAddress);
2019-05-30 17:46:58 +00:00
2019-10-18 17:35:40 +00:00
ivPlain = vsBody.findViewById(R.id.ivPlain);
ivReceipt = vsBody.findViewById(R.id.ivReceipt);
ivBrowsed = vsBody.findViewById(R.id.ivBrowsed);
2019-05-30 17:46:58 +00:00
ibSearchContact = vsBody.findViewById(R.id.ibSearchContact);
ibNotifyContact = vsBody.findViewById(R.id.ibNotifyContact);
ibAddContact = vsBody.findViewById(R.id.ibAddContact);
tvFromExTitle = vsBody.findViewById(R.id.tvFromExTitle);
tvToTitle = vsBody.findViewById(R.id.tvToTitle);
tvReplyToTitle = vsBody.findViewById(R.id.tvReplyToTitle);
tvCcTitle = vsBody.findViewById(R.id.tvCcTitle);
tvBccTitle = vsBody.findViewById(R.id.tvBccTitle);
tvIdentityTitle = vsBody.findViewById(R.id.tvIdentityTitle);
2019-12-08 11:27:38 +00:00
tvSentTitle = vsBody.findViewById(R.id.tvSentTitle);
tvReceivedTitle = vsBody.findViewById(R.id.tvReceivedTitle);
2019-05-30 17:46:58 +00:00
tvSizeExTitle = vsBody.findViewById(R.id.tvSizeExTitle);
tvFromEx = vsBody.findViewById(R.id.tvFromEx);
tvTo = vsBody.findViewById(R.id.tvTo);
tvReplyTo = vsBody.findViewById(R.id.tvReplyTo);
tvCc = vsBody.findViewById(R.id.tvCc);
tvBcc = vsBody.findViewById(R.id.tvBcc);
tvIdentity = vsBody.findViewById(R.id.tvIdentity);
2019-12-08 11:27:38 +00:00
tvSent = vsBody.findViewById(R.id.tvSent);
tvReceived = vsBody.findViewById(R.id.tvReceived);
2019-05-30 17:46:58 +00:00
tvSizeEx = vsBody.findViewById(R.id.tvSizeEx);
tvSubjectEx = vsBody.findViewById(R.id.tvSubjectEx);
tvFlags = vsBody.findViewById(R.id.tvFlags);
tvKeywords = vsBody.findViewById(R.id.tvKeywords);
tvHeaders = vsBody.findViewById(R.id.tvHeaders);
pbHeaders = vsBody.findViewById(R.id.pbHeaders);
tvNoInternetHeaders = vsBody.findViewById(R.id.tvNoInternetHeaders);
tvCalendarSummary = vsBody.findViewById(R.id.tvCalendarSummary);
tvCalendarStart = vsBody.findViewById(R.id.tvCalendarStart);
tvCalendarEnd = vsBody.findViewById(R.id.tvCalendarEnd);
tvAttendees = vsBody.findViewById(R.id.tvAttendees);
btnCalendarAccept = vsBody.findViewById(R.id.btnCalendarAccept);
btnCalendarDecline = vsBody.findViewById(R.id.btnCalendarDecline);
btnCalendarMaybe = vsBody.findViewById(R.id.btnCalendarMaybe);
2019-09-30 11:40:14 +00:00
ibCalendar = vsBody.findViewById(R.id.ibCalendar);
2019-05-30 17:46:58 +00:00
pbCalendarWait = vsBody.findViewById(R.id.pbCalendarWait);
rvAttachment = attachments.findViewById(R.id.rvAttachment);
rvAttachment.setHasFixedSize(false);
LinearLayoutManager llm = new LinearLayoutManager(context);
rvAttachment.setLayoutManager(llm);
rvAttachment.setItemAnimator(null);
adapterAttachment = new AdapterAttachment(parentFragment, true);
2019-05-30 17:46:58 +00:00
rvAttachment.setAdapter(adapterAttachment);
cbInline = attachments.findViewById(R.id.cbInline);
btnSaveAttachments = attachments.findViewById(R.id.btnSaveAttachments);
2019-08-15 13:01:26 +00:00
btnDownloadAttachments = attachments.findViewById(R.id.btnDownloadAttachments);
2019-05-30 17:46:58 +00:00
tvNoInternetAttachments = attachments.findViewById(R.id.tvNoInternetAttachments);
2019-08-16 06:12:04 +00:00
bnvActions = vsBody.findViewById(R.id.bnvActions);
if (compact) {
bnvActions.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED);
ViewGroup.LayoutParams lparam = bnvActions.getLayoutParams();
lparam.height = dp36;
bnvActions.setLayoutParams(lparam);
}
2019-10-08 16:05:23 +00:00
grpActions = vsBody.findViewById(R.id.grpActions);
2019-05-30 17:46:58 +00:00
ibFull = vsBody.findViewById(R.id.ibFull);
2019-08-14 18:08:24 +00:00
ibImages = vsBody.findViewById(R.id.ibImages);
2019-09-08 10:57:21 +00:00
ibUnsubscribe = vsBody.findViewById(R.id.ibUnsubscribe);
2019-11-27 09:40:43 +00:00
ibVerify = vsBody.findViewById(R.id.ibVerify);
2019-08-14 18:08:24 +00:00
ibDecrypt = vsBody.findViewById(R.id.ibDecrypt);
2019-05-30 17:46:58 +00:00
tvBody = vsBody.findViewById(R.id.tvBody);
2019-10-04 13:25:04 +00:00
wvBody = vsBody.findViewById(R.id.wvBody);
pbBody = vsBody.findViewById(R.id.pbBody);
2019-05-30 17:46:58 +00:00
tvNoInternetBody = vsBody.findViewById(R.id.tvNoInternetBody);
2019-10-05 10:54:41 +00:00
ibDownloading = vsBody.findViewById(R.id.ibDownloading);
grpDownloading = vsBody.findViewById(R.id.grpDownloading);
2019-05-30 17:46:58 +00:00
rvImage = vsBody.findViewById(R.id.rvImage);
rvImage.setHasFixedSize(false);
StaggeredGridLayoutManager sglm =
new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
rvImage.setLayoutManager(sglm);
adapterImage = new AdapterImage(parentFragment);
2019-05-30 17:46:58 +00:00
rvImage.setAdapter(adapterImage);
grpAddresses = vsBody.findViewById(R.id.grpAddresses);
grpHeaders = vsBody.findViewById(R.id.grpHeaders);
grpCalendar = vsBody.findViewById(R.id.grpCalendar);
grpCalendarResponse = vsBody.findViewById(R.id.grpCalendarResponse);
grpAttachments = attachments.findViewById(R.id.grpAttachments);
grpImages = vsBody.findViewById(R.id.grpImages);
2019-05-30 18:32:29 +00:00
unwire();
wire();
2018-08-02 13:33:06 +00:00
}
2019-01-20 15:22:21 +00:00
Rect getItemRect() {
return new Rect(
super.itemView.getLeft(),
2019-08-14 10:32:29 +00:00
super.itemView.getTop(),
2019-01-20 15:22:21 +00:00
super.itemView.getRight(),
super.itemView.getBottom());
}
2018-08-02 13:33:06 +00:00
private void wire() {
2019-09-01 17:19:50 +00:00
final View touch = (viewType == ViewType.THREAD ? ibExpander : vwColor);
2019-01-20 11:21:09 +00:00
touch.setOnClickListener(this);
2019-03-15 11:53:22 +00:00
view.post(new Runnable() {
2019-01-20 11:21:09 +00:00
@Override
public void run() {
Rect rect = new Rect(
2019-03-15 11:53:22 +00:00
view.getLeft(),
2019-01-24 07:10:51 +00:00
vwColor.getTop(),
2019-03-15 11:53:22 +00:00
view.getRight(),
2019-01-24 07:10:51 +00:00
vwColor.getBottom());
2019-03-15 11:53:22 +00:00
view.setTouchDelegate(new TouchDelegate(rect, touch));
2019-01-20 11:21:09 +00:00
}
});
2019-08-10 08:42:28 +00:00
view.setOnKeyListener(this);
2019-01-15 16:50:32 +00:00
2019-10-22 17:41:15 +00:00
ibAvatar.setOnClickListener(this);
2019-09-01 17:07:21 +00:00
ibAuth.setOnClickListener(this);
ibSnoozed.setOnClickListener(this);
ibFlagged.setOnClickListener(this);
2019-06-28 16:43:36 +00:00
if (viewType == ViewType.THREAD)
2019-09-01 17:07:21 +00:00
ibFlagged.setOnLongClickListener(this);
2019-09-13 07:34:00 +00:00
ibHelp.setOnClickListener(this);
2019-01-15 16:50:32 +00:00
2019-05-30 17:46:58 +00:00
if (vsBody != null) {
2019-09-01 16:59:51 +00:00
ibExpanderAddress.setOnClickListener(this);
2019-05-30 13:46:00 +00:00
ibSearchContact.setOnClickListener(this);
ibNotifyContact.setOnClickListener(this);
ibAddContact.setOnClickListener(this);
2019-01-15 16:50:32 +00:00
2019-05-30 13:46:00 +00:00
btnSaveAttachments.setOnClickListener(this);
2019-08-15 13:01:26 +00:00
btnDownloadAttachments.setOnClickListener(this);
2019-01-15 16:50:32 +00:00
2019-08-16 06:12:04 +00:00
bnvActions.setOnNavigationItemSelectedListener(this);
2019-05-30 13:46:00 +00:00
ibFull.setOnClickListener(this);
2019-08-14 18:08:24 +00:00
ibImages.setOnClickListener(this);
2019-09-08 10:57:21 +00:00
ibUnsubscribe.setOnClickListener(this);
2019-11-27 09:40:43 +00:00
ibVerify.setOnClickListener(this);
2019-08-14 18:08:24 +00:00
ibDecrypt.setOnClickListener(this);
2019-10-05 10:54:41 +00:00
ibDownloading.setOnClickListener(this);
2019-09-01 13:42:53 +00:00
tvBody.setOnTouchListener(this);
2019-10-04 13:25:04 +00:00
tvBody.addOnLayoutChangeListener(this);
2019-09-01 13:42:53 +00:00
2019-05-30 13:46:00 +00:00
btnCalendarAccept.setOnClickListener(this);
btnCalendarDecline.setOnClickListener(this);
btnCalendarMaybe.setOnClickListener(this);
2019-09-30 11:40:14 +00:00
ibCalendar.setOnClickListener(this);
2019-09-01 13:42:53 +00:00
gestureDetector = new ScaleGestureDetector(context, new ScaleGestureDetector.SimpleOnScaleGestureListener() {
@Override
public boolean onScale(ScaleGestureDetector detector) {
TupleMessageEx message = getMessage();
if (message != null) {
float factor = detector.getScaleFactor();
float size = tvBody.getTextSize() * factor;
2019-09-01 15:28:09 +00:00
//Log.i("Gesture factor=" + factor + " size=" + size);
2019-09-01 13:42:53 +00:00
properties.setSize(message.id, size);
tvBody.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}
return true;
}
});
2019-05-30 13:46:00 +00:00
}
2018-08-02 13:33:06 +00:00
}
private void unwire() {
2019-09-01 17:19:50 +00:00
final View touch = (viewType == ViewType.THREAD ? ibExpander : vwColor);
2019-08-10 08:42:28 +00:00
touch.setOnClickListener(null);
view.setOnKeyListener(null);
2019-05-18 17:44:21 +00:00
2019-10-22 17:41:15 +00:00
ibAvatar.setOnClickListener(null);
2019-09-01 17:07:21 +00:00
ibAuth.setOnClickListener(null);
ibSnoozed.setOnClickListener(null);
ibFlagged.setOnClickListener(null);
2019-06-28 16:43:36 +00:00
if (viewType == ViewType.THREAD)
2019-09-01 17:07:21 +00:00
ibFlagged.setOnLongClickListener(null);
2019-09-13 07:34:00 +00:00
ibHelp.setOnClickListener(null);
2019-05-18 17:44:21 +00:00
2019-05-30 17:46:58 +00:00
if (vsBody != null) {
2019-09-01 16:59:51 +00:00
ibExpanderAddress.setOnClickListener(null);
2019-05-30 13:46:00 +00:00
ibSearchContact.setOnClickListener(null);
ibNotifyContact.setOnClickListener(null);
ibAddContact.setOnClickListener(null);
2019-05-18 17:44:21 +00:00
2019-05-30 13:46:00 +00:00
btnSaveAttachments.setOnClickListener(null);
2019-08-15 13:01:26 +00:00
btnDownloadAttachments.setOnClickListener(null);
2019-05-18 17:44:21 +00:00
2019-08-16 06:12:04 +00:00
bnvActions.setOnNavigationItemSelectedListener(null);
2019-05-30 13:46:00 +00:00
ibFull.setOnClickListener(null);
2019-08-14 18:08:24 +00:00
ibImages.setOnClickListener(null);
2019-09-08 10:57:21 +00:00
ibUnsubscribe.setOnClickListener(null);
2019-11-27 09:40:43 +00:00
ibVerify.setOnClickListener(null);
2019-08-14 18:08:24 +00:00
ibDecrypt.setOnClickListener(null);
2019-10-05 10:54:41 +00:00
ibDownloading.setOnClickListener(null);
2019-09-01 13:42:53 +00:00
tvBody.setOnTouchListener(null);
2019-10-04 13:25:04 +00:00
tvBody.removeOnLayoutChangeListener(this);
2019-09-01 13:42:53 +00:00
2019-05-30 13:46:00 +00:00
btnCalendarAccept.setOnClickListener(null);
btnCalendarDecline.setOnClickListener(null);
btnCalendarMaybe.setOnClickListener(null);
2019-09-30 11:40:14 +00:00
ibCalendar.setOnClickListener(null);
2019-05-30 13:46:00 +00:00
}
2018-08-02 13:33:06 +00:00
}
private void clear() {
2018-10-15 10:05:42 +00:00
vwColor.setVisibility(View.GONE);
2019-09-01 17:19:50 +00:00
ibExpander.setVisibility(View.GONE);
2019-09-01 17:07:21 +00:00
ibFlagged.setVisibility(View.GONE);
2019-10-22 17:41:15 +00:00
ibAvatar.setVisibility(View.GONE);
2019-10-18 17:35:40 +00:00
ibAuth.setVisibility(View.GONE);
2019-10-21 09:54:39 +00:00
ivPriorityHigh.setVisibility(View.GONE);
ivPriorityLow.setVisibility(View.GONE);
2019-11-27 09:40:43 +00:00
ivSigned.setVisibility(View.GONE);
2019-11-17 11:16:06 +00:00
ivEncrypted.setVisibility(View.GONE);
2018-08-07 06:38:00 +00:00
tvFrom.setText(null);
tvSize.setText(null);
2018-08-07 06:38:00 +00:00
tvTime.setText(null);
ivType.setVisibility(View.GONE);
2019-09-01 17:07:21 +00:00
ibSnoozed.setVisibility(View.GONE);
2018-11-24 18:14:28 +00:00
ivAnswered.setVisibility(View.GONE);
2018-08-07 06:38:00 +00:00
ivAttachments.setVisibility(View.GONE);
2018-09-07 15:12:43 +00:00
tvSubject.setText(null);
2018-08-23 06:57:24 +00:00
tvFolder.setText(null);
2018-08-07 06:38:00 +00:00
tvCount.setText(null);
2018-09-04 07:56:30 +00:00
ivThread.setVisibility(View.GONE);
2019-10-18 17:35:40 +00:00
tvExpand.setVisibility(View.GONE);
2018-11-04 16:16:45 +00:00
tvPreview.setVisibility(View.GONE);
2018-09-08 17:39:35 +00:00
tvError.setVisibility(View.GONE);
2019-09-13 07:34:00 +00:00
ibHelp.setVisibility(View.GONE);
2018-11-04 16:16:45 +00:00
2019-06-05 05:59:34 +00:00
clearExpanded(null);
2018-08-07 06:38:00 +00:00
}
2019-01-27 11:17:45 +00:00
@SuppressLint("WrongConstant")
2019-03-04 10:18:42 +00:00
private void bindTo(final TupleMessageEx message) {
2019-08-11 18:11:48 +00:00
boolean inbox = EntityFolder.INBOX.equals(message.folderType);
boolean outbox = EntityFolder.OUTBOX.equals(message.folderType);
2019-10-09 11:24:16 +00:00
boolean outgoing = isOutgoing(message);
Address[] addresses = (outgoing && (viewType != ViewType.THREAD || !threading) ? message.to : message.senders);
2019-10-18 17:35:40 +00:00
boolean authenticated =
!(Boolean.FALSE.equals(message.dkim) ||
Boolean.FALSE.equals(message.spf) ||
Boolean.FALSE.equals(message.dmarc) ||
Boolean.FALSE.equals(message.mx));
2019-10-10 17:23:14 +00:00
boolean expanded = (viewType == ViewType.THREAD && properties.getValue("expanded", message.id));
// Text size
2019-01-20 11:21:09 +00:00
if (textSize != 0) {
float fz_sender = (font_size_sender == null ? textSize : font_size_sender) * (message.unseen > 0 ? 1.1f : 1f);
float fz_subject = (font_size_subject == null ? textSize : font_size_subject) * 0.9f;
tvFrom.setTextSize(TypedValue.COMPLEX_UNIT_PX, fz_sender);
tvSubject.setTextSize(TypedValue.COMPLEX_UNIT_PX, fz_subject);
2019-10-21 11:45:00 +00:00
tvFolder.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize * 0.9f);
2019-04-17 07:38:24 +00:00
tvPreview.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize * 0.9f);
2019-03-08 09:15:40 +00:00
int px = Math.round(fz_sender + fz_subject + (compact ? 0 : textSize * 0.9f));
2019-10-22 17:41:15 +00:00
ViewGroup.LayoutParams lparams = ibAvatar.getLayoutParams();
2019-03-08 09:15:40 +00:00
if (lparams.height != px) {
lparams.width = px;
lparams.height = px;
2019-10-22 17:41:15 +00:00
ibAvatar.requestLayout();
2019-03-08 09:15:40 +00:00
}
2019-01-20 11:21:09 +00:00
}
// Selected / disabled
2019-03-15 11:53:22 +00:00
view.setActivated(selectionTracker != null && selectionTracker.isSelected(message.id));
view.setAlpha(
(EntityFolder.OUTBOX.equals(message.folderType)
? message.identitySynchronize == null || !message.identitySynchronize
2019-11-23 12:48:59 +00:00
: message.uid == null && message.accountProtocol == EntityAccount.TYPE_IMAP)
? Helper.LOW_LIGHT : 1.0f);
2019-01-04 18:37:56 +00:00
// Duplicate
2018-11-27 06:27:32 +00:00
if (viewType == ViewType.THREAD) {
2019-03-07 13:26:36 +00:00
boolean dim = (message.duplicate || EntityFolder.TRASH.equals(message.folderType));
2019-09-01 17:07:21 +00:00
ibFlagged.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
2019-10-22 17:41:15 +00:00
ibAvatar.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
2019-10-18 17:35:40 +00:00
ibAuth.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
2019-10-21 09:54:39 +00:00
ivPriorityHigh.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
ivPriorityLow.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
2019-11-27 09:40:43 +00:00
ivSigned.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
2019-11-17 11:16:06 +00:00
ivEncrypted.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
2019-03-07 13:26:36 +00:00
tvFrom.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
tvSize.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
tvTime.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
ivType.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
2019-09-01 17:07:21 +00:00
ibSnoozed.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
2019-03-07 13:26:36 +00:00
ivAnswered.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
ivAttachments.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
tvSubject.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
tvFolder.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
tvCount.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
ivThread.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
tvPreview.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
tvError.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
2018-11-27 06:27:32 +00:00
}
// Unseen
Typeface typeface = (message.unseen > 0 ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
tvFrom.setTypeface(typeface);
tvSize.setTypeface(typeface);
tvTime.setTypeface(typeface);
if (subject_italic)
if (message.unseen > 0)
tvSubject.setTypeface(null, Typeface.BOLD_ITALIC);
else
tvSubject.setTypeface(null, Typeface.ITALIC);
else
tvSubject.setTypeface(typeface);
tvCount.setTypeface(typeface);
2018-12-24 18:16:01 +00:00
2019-10-07 11:07:26 +00:00
int colorUnseen = (message.unseen > 0 ? colorUnread : colorRead);
2019-10-10 20:05:29 +00:00
if (tvFrom.getTag() == null || (int) tvFrom.getTag() != colorUnseen) {
tvFrom.setTag(colorUnseen);
tvFrom.setTextColor(colorUnseen);
tvSize.setTextColor(colorUnseen);
tvTime.setTextColor(colorUnseen);
}
2018-09-08 14:57:03 +00:00
// Account color
2019-10-10 20:05:29 +00:00
int colorBackground =
(message.accountColor == null || !ActivityBilling.isPro(context)
? colorSeparator : message.accountColor);
if (vwColor.getTag() == null || (int) vwColor.getTag() != colorBackground) {
vwColor.setTag(colorBackground);
vwColor.setBackgroundColor(colorBackground);
}
2018-09-12 16:54:48 +00:00
// Expander
2019-10-10 20:05:29 +00:00
if (ibExpander.getTag() == null || (boolean) ibExpander.getTag() != expanded) {
ibExpander.setTag(expanded);
ibExpander.setImageLevel(expanded ? 0 /* less */ : 1 /* more */);
2019-12-19 13:26:17 +00:00
ibExpander.setContentDescription(context.getString(
expanded ? R.string.title_accessibility_expanded : R.string.title_accessibility_collapsed));
2019-10-10 20:05:29 +00:00
}
if (viewType == ViewType.THREAD)
2019-09-01 17:19:50 +00:00
ibExpander.setVisibility(EntityFolder.DRAFTS.equals(message.folderType) ? View.INVISIBLE : View.VISIBLE);
2018-11-13 09:22:41 +00:00
else
2019-09-01 17:19:50 +00:00
ibExpander.setVisibility(View.GONE);
2018-10-15 10:05:42 +00:00
2019-10-12 06:52:03 +00:00
// Photo
2019-10-22 17:41:15 +00:00
ibAvatar.setVisibility(avatars ? View.INVISIBLE : View.GONE);
2019-10-12 06:52:03 +00:00
2019-12-23 16:34:46 +00:00
vwSeen.setContentDescription(context.getString(
message.unseen > 0 ? R.string.title_accessibility_unseen : R.string.title_accessibility_seen));
// Line 1
2019-10-18 17:35:40 +00:00
ibAuth.setVisibility(authentication && !authenticated ? View.VISIBLE : View.GONE);
2019-10-21 09:54:39 +00:00
ivPriorityHigh.setVisibility(EntityMessage.PRIORITIY_HIGH.equals(message.priority) ? View.VISIBLE : View.GONE);
ivPriorityLow.setVisibility(EntityMessage.PRIORITIY_LOW.equals(message.priority) ? View.VISIBLE : View.GONE);
2019-11-27 09:40:43 +00:00
ivSigned.setVisibility(message.signed > 0 ? View.VISIBLE : View.GONE);
2019-11-17 11:16:06 +00:00
ivEncrypted.setVisibility(message.encrypted > 0 ? View.VISIBLE : View.GONE);
tvFrom.setText(MessageHelper.formatAddresses(addresses, name_email, false));
2019-10-02 11:36:07 +00:00
tvFrom.setPaintFlags(tvFrom.getPaintFlags() & ~Paint.UNDERLINE_TEXT_FLAG);
2019-10-18 17:35:40 +00:00
tvSize.setText(message.totalSize == null ? null : Helper.humanReadableByteCount(message.totalSize, true));
tvSize.setVisibility(message.totalSize != null && "size".equals(sort) ? View.VISIBLE : View.GONE);
tvTime.setText(date && "time".equals(sort)
? TF.format(message.received)
: Helper.getRelativeTimeSpanString(context, message.received));
2018-08-07 06:38:00 +00:00
// Line 2
tvSubject.setText(message.subject);
// Line 3
2019-10-11 08:06:26 +00:00
int icon = (message.drafts > 0
? R.drawable.baseline_edit_24
: EntityFolder.getIcon(outgoing ? EntityFolder.SENT : message.folderType));
ivType.setVisibility(message.drafts > 0 ||
(viewType == ViewType.UNIFIED && type == null && (!inbox || outgoing)) ||
(viewType == ViewType.FOLDER && outgoing && !EntityFolder.SENT.equals(message.folderType)) ||
(viewType == ViewType.THREAD && (outgoing || EntityFolder.SENT.equals(message.folderType))) ||
viewType == ViewType.SEARCH
2019-10-11 08:06:26 +00:00
? View.VISIBLE : View.GONE);
2019-10-10 20:05:29 +00:00
if (ivType.getTag() == null || (int) ivType.getTag() != icon) {
ivType.setTag(icon);
ivType.setImageResource(icon);
}
2019-09-30 14:55:58 +00:00
2019-10-12 09:09:54 +00:00
ibSnoozed.setImageResource(
message.ui_snoozed != null && message.ui_snoozed == Long.MAX_VALUE
? R.drawable.baseline_visibility_off_24 : R.drawable.baseline_timelapse_24);
2019-09-01 17:07:21 +00:00
ibSnoozed.setVisibility(message.ui_snoozed == null ? View.GONE : View.VISIBLE);
2018-11-24 18:14:28 +00:00
ivAnswered.setVisibility(message.ui_answered ? View.VISIBLE : View.GONE);
2018-08-23 06:57:24 +00:00
ivAttachments.setVisibility(message.attachments > 0 ? View.VISIBLE : View.GONE);
2018-08-07 06:38:00 +00:00
2019-01-20 10:18:42 +00:00
if (viewType == ViewType.FOLDER)
2019-08-11 18:11:48 +00:00
tvFolder.setText(outbox ? message.identityEmail : message.accountName);
2019-10-19 20:18:04 +00:00
else if (viewType == ViewType.THREAD || viewType == ViewType.SEARCH)
tvFolder.setText(message.getFolderName(context));
2019-10-01 11:56:48 +00:00
else
tvFolder.setText(message.accountName + "/" + message.getFolderName(context));
tvFolder.setVisibility(compact && viewType != ViewType.THREAD ? View.GONE : View.VISIBLE);
2018-08-23 06:57:24 +00:00
if (viewType == ViewType.THREAD || !threading) {
2018-08-23 06:57:24 +00:00
tvCount.setVisibility(View.GONE);
2018-09-04 07:56:30 +00:00
ivThread.setVisibility(View.GONE);
} else {
tvCount.setText(NF.format(message.visible));
2018-09-04 07:56:30 +00:00
ivThread.setVisibility(View.VISIBLE);
2018-08-09 05:37:52 +00:00
}
2018-08-07 06:38:00 +00:00
// Starred
bindFlagged(message, expanded);
2019-10-18 17:35:40 +00:00
// Expand warning
bindExpandWarning(message, expanded);
// Message text preview
2019-10-10 20:05:29 +00:00
int textColor = (contrast ? textColorPrimary : textColorSecondary);
if (tvPreview.getTag() == null || (int) tvPreview.getTag() != textColor) {
tvPreview.setTag(textColor);
tvPreview.setTextColor(textColor);
tvPreview.setMaxLines(preview_lines);
2019-10-10 20:05:29 +00:00
}
tvPreview.setTypeface(
monospaced ? Typeface.MONOSPACE : Typeface.DEFAULT,
preview_italic ? Typeface.ITALIC : Typeface.NORMAL);
tvPreview.setText(message.preview);
2019-06-05 06:42:46 +00:00
tvPreview.setVisibility(preview && !TextUtils.isEmpty(message.preview) ? View.VISIBLE : View.GONE);
// Error / warning
2019-01-17 10:49:18 +00:00
String error = message.error;
if (message.warning != null)
if (error == null)
error = message.warning;
else
error += " " + message.warning;
if (debug) {
2019-01-17 10:49:18 +00:00
String text = "error=" + error +
"\nuid=" + message.uid + " id=" + message.id + " " + DTF.format(new Date(message.received)) +
2019-09-27 16:25:55 +00:00
"\n" + (message.ui_hide ? "HIDDEN " : "") +
2019-01-05 14:08:07 +00:00
"seen=" + message.seen + "/" + message.ui_seen +
" unseen=" + message.unseen +
2019-01-10 18:55:40 +00:00
" ignored=" + message.ui_ignored +
2018-12-05 10:50:07 +00:00
" found=" + message.ui_found +
2019-01-05 14:08:07 +00:00
"\nmsgid=" + message.msgid +
"\nthread=" + message.thread +
"\nsender=" + message.sender;
2018-12-05 10:50:07 +00:00
tvError.setText(text);
tvError.setVisibility(View.VISIBLE);
2018-10-15 10:05:42 +00:00
} else {
2019-01-17 10:49:18 +00:00
tvError.setText(error);
tvError.setVisibility(error == null ? View.GONE : View.VISIBLE);
2019-09-13 07:34:00 +00:00
ibHelp.setVisibility(error == null ? View.GONE : View.VISIBLE);
}
2018-08-11 09:18:49 +00:00
// Contact info
2019-10-02 11:36:07 +00:00
ContactInfo info = ContactInfo.get(context, message.account, addresses, true);
if (info == null) {
Bundle aargs = new Bundle();
aargs.putLong("id", message.id);
2019-10-02 11:36:07 +00:00
aargs.putLong("account", message.account);
aargs.putSerializable("addresses", addresses);
2019-01-10 17:39:52 +00:00
new SimpleTask<ContactInfo>() {
@Override
protected ContactInfo onExecute(Context context, Bundle args) {
2019-10-02 11:36:07 +00:00
long account = args.getLong("account");
Address[] addresses = (Address[]) args.getSerializable("addresses");
2019-10-02 11:36:07 +00:00
return ContactInfo.get(context, account, addresses, false);
2018-12-05 10:50:07 +00:00
}
@Override
protected void onExecuted(Bundle args, ContactInfo info) {
2019-02-01 09:29:26 +00:00
long id = args.getLong("id");
TupleMessageEx amessage = getMessage();
if (amessage == null || !amessage.id.equals(id))
return;
2019-12-19 20:37:09 +00:00
bindContactInfo(info, addresses, name_email);
}
2018-12-05 10:50:07 +00:00
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2018-12-05 10:50:07 +00:00
}
2019-08-22 06:44:22 +00:00
}.setLog(false).execute(context, owner, aargs, "message:avatar");
2018-12-22 07:48:23 +00:00
} else
2019-12-19 20:37:09 +00:00
bindContactInfo(info, addresses, name_email);
2018-08-07 06:38:00 +00:00
2019-10-04 13:25:04 +00:00
if (viewType == ViewType.THREAD)
2019-06-24 09:05:30 +00:00
if (expanded)
2019-08-29 16:12:34 +00:00
bindExpanded(message, false);
2019-10-04 13:25:04 +00:00
else
2019-06-05 05:59:34 +00:00
clearExpanded(message);
2019-01-30 07:50:20 +00:00
}
2019-06-05 05:59:34 +00:00
private void clearExpanded(TupleMessageEx message) {
if (compact) {
tvFrom.setSingleLine(true);
tvSubject.setSingleLine(true);
}
2019-06-05 06:42:46 +00:00
tvPreview.setVisibility(
preview && message != null && !TextUtils.isEmpty(message.preview)
? View.VISIBLE : View.GONE);
if (vsBody == null)
return;
cowner.stop();
2019-05-17 16:54:44 +00:00
grpAddresses.setVisibility(View.GONE);
grpHeaders.setVisibility(View.GONE);
2019-05-18 09:19:39 +00:00
grpCalendar.setVisibility(View.GONE);
2019-05-18 17:44:21 +00:00
grpCalendarResponse.setVisibility(View.GONE);
grpAttachments.setVisibility(View.GONE);
2019-05-14 17:21:11 +00:00
grpImages.setVisibility(View.GONE);
2019-10-18 17:35:40 +00:00
ivPlain.setVisibility(View.GONE);
ivReceipt.setVisibility(View.GONE);
ivBrowsed.setVisibility(View.GONE);
2019-05-08 14:44:01 +00:00
ibSearchContact.setVisibility(View.GONE);
ibNotifyContact.setVisibility(View.GONE);
ibAddContact.setVisibility(View.GONE);
2019-03-09 10:02:17 +00:00
tvFromExTitle.setVisibility(View.GONE);
tvToTitle.setVisibility(View.GONE);
tvReplyToTitle.setVisibility(View.GONE);
tvCcTitle.setVisibility(View.GONE);
tvBccTitle.setVisibility(View.GONE);
tvIdentityTitle.setVisibility(View.GONE);
2019-12-08 11:27:38 +00:00
tvSentTitle.setVisibility(View.GONE);
tvReceivedTitle.setVisibility(View.GONE);
2019-03-09 10:02:17 +00:00
tvSizeExTitle.setVisibility(View.GONE);
tvFromEx.setVisibility(View.GONE);
tvTo.setVisibility(View.GONE);
tvReplyTo.setVisibility(View.GONE);
tvCc.setVisibility(View.GONE);
tvBcc.setVisibility(View.GONE);
tvIdentity.setVisibility(View.GONE);
2019-12-08 11:27:38 +00:00
tvSent.setVisibility(View.GONE);
tvReceived.setVisibility(View.GONE);
2019-03-09 10:02:17 +00:00
tvSizeEx.setVisibility(View.GONE);
tvSubjectEx.setVisibility(View.GONE);
tvFlags.setVisibility(View.GONE);
tvKeywords.setVisibility(View.GONE);
2019-03-09 10:02:17 +00:00
pbHeaders.setVisibility(View.GONE);
tvNoInternetHeaders.setVisibility(View.GONE);
2019-05-18 09:19:39 +00:00
tvCalendarSummary.setVisibility(View.GONE);
tvCalendarStart.setVisibility(View.GONE);
tvCalendarEnd.setVisibility(View.GONE);
tvAttendees.setVisibility(View.GONE);
pbCalendarWait.setVisibility(View.GONE);
cbInline.setVisibility(View.GONE);
btnSaveAttachments.setVisibility(View.GONE);
2019-08-15 13:01:26 +00:00
btnDownloadAttachments.setVisibility(View.GONE);
tvNoInternetAttachments.setVisibility(View.GONE);
2019-08-16 06:12:04 +00:00
bnvActions.setVisibility(View.GONE);
2019-10-08 16:05:23 +00:00
grpActions.setVisibility(View.GONE);
2019-05-17 16:54:44 +00:00
ibFull.setVisibility(View.GONE);
2019-08-14 18:08:24 +00:00
ibImages.setVisibility(View.GONE);
2019-09-08 10:57:21 +00:00
ibUnsubscribe.setVisibility(View.GONE);
2019-11-27 09:40:43 +00:00
ibVerify.setVisibility(View.GONE);
2019-08-14 18:08:24 +00:00
ibDecrypt.setVisibility(View.GONE);
tvBody.setVisibility(View.GONE);
2019-10-04 13:25:04 +00:00
wvBody.setVisibility(View.GONE);
pbBody.setVisibility(View.GONE);
tvNoInternetBody.setVisibility(View.GONE);
2019-10-05 10:54:41 +00:00
grpDownloading.setVisibility(View.GONE);
}
private void bindFlagged(TupleMessageEx message, boolean expanded) {
boolean pro = ActivityBilling.isPro(context);
2019-02-04 11:45:38 +00:00
int flagged = (message.count - message.unflagged);
int color = (message.color == null || !pro ? colorAccent : message.color);
ibFlagged.setImageResource(flagged > 0 ? R.drawable.baseline_star_24 : R.drawable.baseline_star_border_24);
ibFlagged.setImportantForAccessibility(
flagged == 0 ? View.IMPORTANT_FOR_ACCESSIBILITY_NO : View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
2019-12-19 13:26:17 +00:00
ibFlagged.setContentDescription(context.getString(
flagged > 0 ? R.string.title_accessibility_flagged : R.string.title_accessibility_unflagged));
ibFlagged.setImageTintList(ColorStateList.valueOf(flagged > 0 ? color : textColorSecondary));
2019-11-23 12:48:59 +00:00
ibFlagged.setEnabled(message.uid != null || message.accountProtocol != EntityAccount.TYPE_IMAP);
2019-09-25 19:25:37 +00:00
card.setCardBackgroundColor(
flags_background && flagged > 0 && !expanded
? ColorUtils.setAlphaComponent(color, 127) : Color.TRANSPARENT);
2019-09-25 19:25:37 +00:00
if (flags)
2019-09-28 08:05:45 +00:00
ibFlagged.setVisibility(message.folderReadOnly ? View.INVISIBLE : View.VISIBLE);
2019-09-25 19:25:37 +00:00
else
ibFlagged.setVisibility(View.GONE);
2019-02-04 11:45:38 +00:00
}
2019-12-19 20:37:09 +00:00
private void bindContactInfo(ContactInfo info, Address[] addresses, boolean name_email) {
2019-10-12 06:52:03 +00:00
if (info.hasPhoto()) {
2019-10-22 17:41:15 +00:00
ibAvatar.setImageBitmap(info.getPhotoBitmap());
ibAvatar.setVisibility(View.VISIBLE);
2019-10-12 06:52:03 +00:00
} else
2019-10-22 17:41:15 +00:00
ibAvatar.setVisibility(View.GONE);
Uri lookupUri = info.getLookupUri();
ibAvatar.setTag(lookupUri);
ibAvatar.setEnabled(lookupUri != null);
2019-10-02 11:36:07 +00:00
2019-12-24 08:26:10 +00:00
String displayName = info.getDisplayName();
if (!TextUtils.isEmpty(displayName) &&
addresses != null && addresses.length == 1) {
String email = ((InternetAddress) addresses[0]).getAddress();
String personal = ((InternetAddress) addresses[0]).getPersonal();
if (TextUtils.isEmpty(personal))
try {
InternetAddress a = new InternetAddress(email, displayName, StandardCharsets.UTF_8.name());
tvFrom.setText(MessageHelper.formatAddresses(new Address[]{a}, name_email, false));
} catch (UnsupportedEncodingException ex) {
Log.w(ex);
}
2019-12-19 20:37:09 +00:00
}
2019-10-02 11:36:07 +00:00
if (distinguish_contacts && info.isKnown())
tvFrom.setPaintFlags(tvFrom.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
2019-10-18 17:35:40 +00:00
private void bindExpandWarning(TupleMessageEx message, boolean expanded) {
if (viewType != ViewType.THREAD || expanded || message.content || message.uid == null || unmetered)
tvExpand.setVisibility(View.GONE);
else {
tvExpand.setText(context.getString(R.string.title_expand_warning,
message.size == null ? "?" : Helper.humanReadableByteCount(message.size, true)));
tvExpand.setVisibility(View.VISIBLE);
}
2019-10-18 17:35:40 +00:00
}
2019-09-22 18:34:41 +00:00
private void bindExpanded(final TupleMessageEx message, final boolean scroll) {
DB db = DB.getInstance(context);
2019-05-04 10:49:25 +00:00
boolean show_addresses = !properties.getValue("addresses", message.id);
boolean show_headers = properties.getValue("headers", message.id);
if (compact) {
tvFrom.setSingleLine(false);
tvSubject.setSingleLine(false);
}
2019-06-05 06:42:46 +00:00
tvPreview.setVisibility(View.GONE);
2019-05-30 17:46:58 +00:00
ensureExpanded();
2019-05-17 16:54:44 +00:00
grpAddresses.setVisibility(View.VISIBLE);
2019-03-09 10:02:17 +00:00
boolean hasFrom = (message.from != null && message.from.length > 0);
2019-05-13 12:08:51 +00:00
boolean hasTo = (message.to != null && message.to.length > 0);
2019-03-09 10:02:17 +00:00
boolean hasChannel = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O);
2019-10-18 17:35:40 +00:00
ivPlain.setVisibility(show_addresses && message.plain_only != null && message.plain_only ? View.VISIBLE : View.GONE);
ivReceipt.setVisibility(show_addresses && message.receipt_request != null && message.receipt_request ? View.VISIBLE : View.GONE);
ivBrowsed.setVisibility(show_addresses && message.ui_browsed ? View.VISIBLE : View.GONE);
2019-05-13 12:08:51 +00:00
ibSearchContact.setVisibility(show_addresses && (hasFrom || hasTo) ? View.VISIBLE : View.GONE);
2019-05-08 14:44:01 +00:00
ibNotifyContact.setVisibility(show_addresses && hasChannel && hasFrom ? View.VISIBLE : View.GONE);
ibAddContact.setVisibility(show_addresses && contacts && hasFrom ? View.VISIBLE : View.GONE);
grpHeaders.setVisibility(show_headers ? View.VISIBLE : View.GONE);
if (show_headers && message.headers == null) {
2019-03-16 13:12:31 +00:00
pbHeaders.setVisibility(suitable ? View.VISIBLE : View.GONE);
tvNoInternetHeaders.setVisibility(suitable ? View.GONE : View.VISIBLE);
2019-02-04 12:17:42 +00:00
} else {
pbHeaders.setVisibility(View.GONE);
tvNoInternetHeaders.setVisibility(View.GONE);
}
2019-10-08 16:05:23 +00:00
grpActions.setVisibility(View.VISIBLE);
2019-08-16 06:12:04 +00:00
for (int i = 0; i < bnvActions.getMenu().size(); i++)
bnvActions.getMenu().getItem(i).setVisible(false);
2019-08-15 09:35:10 +00:00
2019-10-04 13:25:04 +00:00
ibFull.setEnabled(false);
ibFull.setVisibility(View.VISIBLE);
2019-08-14 18:25:46 +00:00
ibImages.setVisibility(View.GONE);
2019-09-08 10:57:21 +00:00
ibUnsubscribe.setVisibility(message.unsubscribe == null ? View.GONE : View.VISIBLE);
2019-12-13 07:16:52 +00:00
ibDecrypt.setVisibility(View.GONE);
ibVerify.setVisibility(View.GONE);
2019-08-14 18:08:24 +00:00
// Addresses
2019-09-01 16:59:51 +00:00
ibExpanderAddress.setImageLevel(show_addresses ? 0 /* less */ : 1 /* more */);
2019-08-04 11:43:37 +00:00
String from = MessageHelper.formatAddresses(message.senders);
2019-03-09 10:02:17 +00:00
String to = MessageHelper.formatAddresses(message.to);
String replyto = MessageHelper.formatAddresses(message.reply);
String cc = MessageHelper.formatAddresses(message.cc);
String bcc = MessageHelper.formatAddresses(message.bcc);
tvFromExTitle.setVisibility(show_addresses && !TextUtils.isEmpty(from) ? View.VISIBLE : View.GONE);
tvFromEx.setVisibility(show_addresses && !TextUtils.isEmpty(from) ? View.VISIBLE : View.GONE);
tvFromEx.setText(from);
tvToTitle.setVisibility(show_addresses && !TextUtils.isEmpty(to) ? View.VISIBLE : View.GONE);
tvTo.setVisibility(show_addresses && !TextUtils.isEmpty(to) ? View.VISIBLE : View.GONE);
tvTo.setText(to);
tvReplyToTitle.setVisibility(show_addresses && !TextUtils.isEmpty(replyto) ? View.VISIBLE : View.GONE);
tvReplyTo.setVisibility(show_addresses && !TextUtils.isEmpty(replyto) ? View.VISIBLE : View.GONE);
tvReplyTo.setText(replyto);
tvCcTitle.setVisibility(show_addresses && !TextUtils.isEmpty(cc) ? View.VISIBLE : View.GONE);
tvCc.setVisibility(show_addresses && !TextUtils.isEmpty(cc) ? View.VISIBLE : View.GONE);
tvCc.setText(cc);
tvBccTitle.setVisibility(show_addresses && !TextUtils.isEmpty(bcc) ? View.VISIBLE : View.GONE);
tvBcc.setVisibility(show_addresses && !TextUtils.isEmpty(bcc) ? View.VISIBLE : View.GONE);
tvBcc.setText(bcc);
InternetAddress via = null;
if (message.identityEmail != null)
try {
via = new InternetAddress(message.identityEmail, message.identityName);
} catch (UnsupportedEncodingException ignored) {
}
2019-03-31 06:35:31 +00:00
tvIdentityTitle.setVisibility(show_addresses && via != null ? View.VISIBLE : View.GONE);
tvIdentity.setVisibility(show_addresses && via != null ? View.VISIBLE : View.GONE);
2019-03-10 08:53:59 +00:00
tvIdentity.setText(via == null ? null : MessageHelper.formatAddresses(new Address[]{via}));
2019-03-09 10:02:17 +00:00
2019-12-08 11:27:38 +00:00
tvSentTitle.setVisibility(show_addresses ? View.VISIBLE : View.GONE);
tvSent.setVisibility(show_addresses ? View.VISIBLE : View.GONE);
tvSent.setText(message.sent == null ? null : DTF.format(message.sent));
tvReceivedTitle.setVisibility(show_addresses ? View.VISIBLE : View.GONE);
tvReceived.setVisibility(show_addresses ? View.VISIBLE : View.GONE);
tvReceived.setText(DTF.format(message.received));
if (!message.duplicate)
tvSizeEx.setAlpha(message.content ? 1.0f : Helper.LOW_LIGHT);
2019-03-09 10:02:17 +00:00
tvSizeExTitle.setVisibility(!show_addresses || message.size == null ? View.GONE : View.VISIBLE);
2019-09-30 19:00:28 +00:00
tvSizeEx.setVisibility(!show_addresses || (message.size == null && message.total == null) ? View.GONE : View.VISIBLE);
StringBuilder size = new StringBuilder();
size
.append(message.size == null ? "-" : Helper.humanReadableByteCount(message.size, true))
.append("/")
.append(message.total == null ? "-" : Helper.humanReadableByteCount(message.total, true));
tvSizeEx.setText(size.toString());
2019-03-09 10:02:17 +00:00
tvSubjectEx.setVisibility(show_addresses ? View.VISIBLE : View.GONE);
tvSubjectEx.setText(message.subject);
if (subject_italic)
tvSubjectEx.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
else
tvSubjectEx.setTypeface(Typeface.DEFAULT);
// Flags
2019-03-09 10:02:17 +00:00
tvFlags.setVisibility(show_addresses && debug ? View.VISIBLE : View.GONE);
tvFlags.setText(message.flags);
// Keywords
2019-03-09 10:02:17 +00:00
tvKeywords.setVisibility(show_addresses && message.keywords.length > 0 ? View.VISIBLE : View.GONE);
tvKeywords.setText(TextUtils.join(" ", message.keywords));
// Headers
2019-08-29 19:57:04 +00:00
if (show_headers && message.headers != null)
tvHeaders.setText(HtmlHelper.highlightHeaders(context, message.headers));
else
tvHeaders.setText(null);
// Attachments
2019-04-04 12:47:56 +00:00
bindAttachments(message, properties.getAttachments(message.id));
// Setup actions
Bundle sargs = new Bundle();
sargs.putLong("id", message.id);
sargs.putLong("account", message.account);
new SimpleTask<List<EntityFolder>>() {
@Override
protected List<EntityFolder> onExecute(Context context, Bundle args) {
long account = args.getLong("account");
return DB.getInstance(context).folder().getSystemFolders(account);
}
@Override
protected void onExecuted(Bundle args, List<EntityFolder> folders) {
long id = args.getLong("id");
TupleMessageEx amessage = getMessage();
if (amessage == null || !amessage.id.equals(id))
return;
boolean hasArchive = false;
boolean hasTrash = false;
2019-08-14 18:08:24 +00:00
hasJunk = false;
if (folders != null)
for (EntityFolder folder : folders) {
if (EntityFolder.ARCHIVE.equals(folder.type))
hasArchive = true;
else if (EntityFolder.TRASH.equals(folder.type))
hasTrash = true;
else if (EntityFolder.JUNK.equals(folder.type))
hasJunk = true;
}
boolean inOutbox = EntityFolder.OUTBOX.equals(message.folderType);
boolean inArchive = EntityFolder.ARCHIVE.equals(message.folderType);
boolean inTrash = EntityFolder.TRASH.equals(message.folderType);
2019-05-25 15:37:01 +00:00
boolean inJunk = EntityFolder.JUNK.equals(message.folderType);
2019-08-14 18:08:24 +00:00
delete = (inTrash || !hasTrash || inOutbox);
2019-08-16 06:12:04 +00:00
bnvActions.getMenu().findItem(R.id.action_more).setVisible(!inOutbox);
2019-07-07 07:25:52 +00:00
if (!message.folderReadOnly) {
2019-09-14 14:48:49 +00:00
bnvActions.getMenu().findItem(R.id.action_delete).setVisible(
2019-09-27 13:37:03 +00:00
(delete ? message.uid != null || !TextUtils.isEmpty(message.msgid) : message.uid != null));
2019-08-16 06:12:04 +00:00
bnvActions.getMenu().findItem(R.id.action_delete).setTitle(
delete ? R.string.title_delete : R.string.title_trash);
bnvActions.getMenu().findItem(R.id.action_move).setVisible(
message.uid != null || inOutbox);
bnvActions.getMenu().findItem(R.id.action_move).setTitle(
inOutbox ? R.string.title_folder_drafts : R.string.title_move);
bnvActions.getMenu().findItem(R.id.action_move).setIcon(
2019-07-07 07:25:52 +00:00
inOutbox ? R.drawable.baseline_drafts_24 : R.drawable.baseline_folder_24);
2019-08-16 06:12:04 +00:00
bnvActions.getMenu().findItem(R.id.action_archive).setVisible(
message.uid != null && (inJunk || (!inArchive && hasArchive)));
bnvActions.getMenu().findItem(R.id.action_archive).setTitle(
inJunk ? R.string.title_folder_inbox : R.string.title_archive);
bnvActions.getMenu().findItem(R.id.action_archive).setIcon(
inJunk ? R.drawable.baseline_inbox_24 : R.drawable.baseline_archive_24);
2019-07-07 07:25:52 +00:00
}
2019-05-25 15:37:01 +00:00
2019-08-16 06:12:04 +00:00
bnvActions.getMenu().findItem(R.id.action_reply).setEnabled(message.content);
bnvActions.getMenu().findItem(R.id.action_reply).setVisible(!inOutbox);
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
2019-08-22 06:44:22 +00:00
}.setLog(false).execute(context, owner, sargs, "message:actions");
// Message text
pbBody.setVisibility(suitable || message.content ? View.VISIBLE : View.GONE);
2019-03-16 13:12:31 +00:00
tvNoInternetBody.setVisibility(suitable || message.content ? View.GONE : View.VISIBLE);
2019-09-22 18:34:41 +00:00
cowner.recreate();
2019-10-04 13:25:04 +00:00
bindBody(message);
2019-09-22 18:34:41 +00:00
db.attachment().liveAttachments(message.id).observe(cowner, new Observer<List<EntityAttachment>>() {
private int lastInlineImages = 0;
@Override
public void onChanged(@Nullable List<EntityAttachment> attachments) {
bindAttachments(message, attachments);
int inlineImages = 0;
if (attachments != null)
for (EntityAttachment attachment : attachments)
if (attachment.available && attachment.isInline() && attachment.isImage())
2019-09-22 18:34:41 +00:00
inlineImages++;
if (inlineImages != lastInlineImages) {
lastInlineImages = inlineImages;
2019-10-04 13:25:04 +00:00
bindBody(message);
2019-09-22 18:34:41 +00:00
}
if (scroll)
properties.scrollTo(getAdapterPosition());
}
});
}
2019-10-04 13:25:04 +00:00
private void bindBody(TupleMessageEx message) {
tvBody.setText(null);
2019-10-05 10:54:41 +00:00
grpDownloading.setVisibility(message.content ? View.GONE : View.VISIBLE);
2019-10-04 13:25:04 +00:00
if (!message.content)
return;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (message.from != null)
2019-11-12 13:15:52 +00:00
for (Address sender : message.from) {
String from = ((InternetAddress) sender).getAddress();
2019-10-04 13:25:04 +00:00
if (prefs.getBoolean(from + ".show_full", false)) {
properties.setValue("full", message.id, true);
properties.setValue("full_asked", message.id, true);
}
if (prefs.getBoolean(from + ".show_images", false)) {
2019-10-04 13:25:04 +00:00
properties.setValue("images", message.id, true);
properties.setValue("images_asked", message.id, true);
}
2019-10-04 13:25:04 +00:00
}
boolean show_full = properties.getValue("full", message.id);
boolean show_images = properties.getValue("images", message.id);
boolean show_quotes = (properties.getValue("quotes", message.id) || !collapse_quotes);
2019-12-19 19:12:42 +00:00
boolean always_images = prefs.getBoolean("html_always_images", false);
if (always_images && show_full) {
show_images = true;
properties.setValue("images", message.id, true);
}
2019-10-04 13:25:04 +00:00
float size = properties.getSize(message.id, show_full ? 0 : textSize);
2019-10-11 20:00:40 +00:00
int height = properties.getHeight(message.id, 0);
2019-10-04 16:59:37 +00:00
Pair<Integer, Integer> position = properties.getPosition(message.id);
2019-10-04 13:25:04 +00:00
Log.i("Bind size=" + size + " height=" + height);
ibFull.setEnabled(hasWebView);
ibFull.setImageResource(show_full ? R.drawable.baseline_fullscreen_exit_24 : R.drawable.baseline_fullscreen_24);
ibImages.setImageResource(show_images ? R.drawable.baseline_format_align_justify_24 : R.drawable.baseline_image_24);
2019-10-04 13:25:04 +00:00
if (show_full) {
// Create web view
2019-10-11 20:00:40 +00:00
WebViewEx webView;
2019-10-04 13:25:04 +00:00
if (wvBody instanceof WebView)
2019-10-11 20:00:40 +00:00
webView = (WebViewEx) wvBody;
2019-10-04 13:25:04 +00:00
else {
2019-12-08 16:31:30 +00:00
try {
webView = new WebViewEx(context);
} catch (Throwable ex) {
/*
android.util.AndroidRuntimeException: java.lang.reflect.InvocationTargetException
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:270)
at android.webkit.WebView.getFactory(WebView.java:2681)
at android.webkit.WebView.ensureProviderCreated(WebView.java:2676)
at android.webkit.WebView.setOverScrollMode(WebView.java:2741)
at android.view.View.<init>(View.java:4815)
at android.view.View.<init>(View.java:4956)
at android.view.ViewGroup.<init>(ViewGroup.java:659)
at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
at android.webkit.WebView.<init>(WebView.java:659)
at android.webkit.WebView.<init>(WebView.java:604)
at android.webkit.WebView.<init>(WebView.java:587)
at android.webkit.WebView.<init>(WebView.java:574)
at android.webkit.WebView.<init>(WebView.java:564)
*/
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
return;
}
2019-10-04 13:25:04 +00:00
webView.setId(wvBody.getId());
ConstraintLayout cl = (ConstraintLayout) vsBody;
cl.removeView(wvBody);
cl.addView(webView, wvBody.getLayoutParams());
cl.setPadding(
wvBody.getPaddingLeft(), wvBody.getPaddingTop(),
wvBody.getPaddingRight(), wvBody.getPaddingBottom());
2019-10-11 20:00:40 +00:00
wvBody = webView;
}
2019-10-04 13:25:04 +00:00
2019-10-11 20:00:40 +00:00
int dp60 = Helper.dp2pixels(context, 60);
webView.setMinimumHeight(height == 0 ? dp60 : height);
2019-10-04 13:25:04 +00:00
2019-10-11 20:00:40 +00:00
webView.init(
height, size, position,
textSize, monospaced,
show_images, inline,
new WebViewEx.IWebView() {
@Override
public void onSizeChanged(int w, int h, int ow, int oh) {
properties.setHeight(message.id, h);
}
2019-10-04 13:25:04 +00:00
2019-10-11 20:00:40 +00:00
@Override
public void onScaleChanged(float newScale) {
properties.setSize(message.id, newScale);
}
2019-10-04 13:25:04 +00:00
2019-10-04 16:59:37 +00:00
@Override
2019-10-11 20:00:40 +00:00
public void onScrollChange(int scrollX, int scrollY) {
2019-10-04 16:59:37 +00:00
properties.setPosition(message.id, new Pair<Integer, Integer>(scrollX, scrollY));
}
2019-10-04 13:25:04 +00:00
2019-10-11 20:00:40 +00:00
@Override
public boolean onOpenLink(String url) {
Uri uri = Uri.parse(url);
2019-10-04 13:25:04 +00:00
if ("cid".equals(uri.getScheme()) || "data".equals(uri.getScheme()))
return false;
2019-12-01 11:47:21 +00:00
if (parentFragment == null)
return false;
2019-10-11 20:00:40 +00:00
Bundle args = new Bundle();
args.putParcelable("uri", uri);
args.putString("title", null);
FragmentDialogLink fragment = new FragmentDialogLink();
fragment.setArguments(args);
2019-10-12 15:16:53 +00:00
fragment.show(parentFragment.getParentFragmentManager(), "open:link");
2019-10-04 13:25:04 +00:00
return true;
}
2019-10-11 20:00:40 +00:00
});
webView.setOnTouchListener(ViewHolder.this);
2019-10-04 13:25:04 +00:00
tvBody.setVisibility(View.GONE);
wvBody.setVisibility(View.VISIBLE);
} else {
2019-10-11 20:00:40 +00:00
tvBody.setMinHeight(height);
2019-10-04 13:25:04 +00:00
if (size != 0)
tvBody.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
2019-10-07 13:56:27 +00:00
tvBody.setTextColor(contrast ? textColorPrimary : colorRead);
2019-10-04 13:25:04 +00:00
tvBody.setTypeface(monospaced ? Typeface.MONOSPACE : Typeface.DEFAULT);
tvBody.setVisibility(View.VISIBLE);
wvBody.setVisibility(View.GONE);
}
2019-10-06 07:04:07 +00:00
final Bundle args = new Bundle();
2019-10-04 13:25:04 +00:00
args.putSerializable("message", message);
args.putBoolean("show_full", show_full);
args.putBoolean("show_images", show_images);
2019-10-04 13:25:04 +00:00
args.putBoolean("show_quotes", show_quotes);
args.putInt("zoom", zoom);
2019-10-08 16:49:17 +00:00
new SimpleTask<Object>() {
2019-10-04 13:25:04 +00:00
@Override
2019-10-08 16:49:17 +00:00
protected Object onExecute(final Context context, final Bundle args) throws IOException {
TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");
2019-11-15 15:08:03 +00:00
final boolean show_full = args.getBoolean("show_full");
final boolean show_images = args.getBoolean("show_images");
final boolean show_quotes = args.getBoolean("show_quotes");
final int zoom = args.getInt("zoom");
2019-10-08 16:49:17 +00:00
if (message == null || !message.content)
return null;
File file = message.getFile(context);
if (!file.exists())
return null;
String body = Helper.readText(file);
Document document = JsoupEx.parse(body);
// Check for inline encryption
int begin = body.indexOf(Helper.PGP_BEGIN_MESSAGE);
int end = body.indexOf(Helper.PGP_END_MESSAGE);
2019-10-29 18:31:48 +00:00
args.putBoolean("inline_encrypted", begin >= 0 && begin < end);
2019-10-08 16:49:17 +00:00
// Check for images
boolean has_images = false;
for (Element img : document.select("img")) {
if (inline) {
String src = img.attr("src");
if (!src.startsWith("cid:")) {
has_images = true;
break;
2019-10-04 13:25:04 +00:00
}
2019-10-08 16:49:17 +00:00
} else {
has_images = true;
break;
}
}
args.putBoolean("has_images", has_images);
// Download inline images
if (show_images) {
DB db = DB.getInstance(context);
try {
db.beginTransaction();
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
for (EntityAttachment attachment : attachments)
if (attachment.isInline() && attachment.isImage() &&
attachment.progress == null && !attachment.available)
EntityOperation.queue(context, message, EntityOperation.ATTACHMENT, attachment.id);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
// Format message
2019-10-08 16:49:17 +00:00
if (show_full) {
2019-10-08 17:54:52 +00:00
HtmlHelper.setViewport(document);
2019-10-08 16:49:17 +00:00
if (inline || show_images)
HtmlHelper.embedInlineImages(context, message.id, document);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean disable_tracking = prefs.getBoolean("disable_tracking", true);
if (disable_tracking)
HtmlHelper.removeTrackingPixels(context, document);
if (debug) {
Document format = JsoupEx.parse(document.html());
format.outputSettings().prettyPrint(true).outline(true).indentAmount(1);
Element pre = document.createElement("pre");
pre.text(format.html());
document.body().appendChild(pre);
}
2019-10-04 21:04:03 +00:00
2019-10-08 16:49:17 +00:00
return document.html();
} else {
2019-11-14 15:06:30 +00:00
// Cleanup message
2019-11-19 20:53:12 +00:00
document = HtmlHelper.sanitize(context, body, show_images, true);
2019-11-14 15:06:30 +00:00
2019-10-08 16:49:17 +00:00
// Collapse quotes
if (!show_quotes) {
2019-11-19 20:53:12 +00:00
for (Element quote : document.select("blockquote"))
2019-10-08 16:49:17 +00:00
quote.html("&#8230;");
}
2019-10-04 13:25:04 +00:00
2019-11-14 15:06:30 +00:00
// Add debug info
2019-10-08 16:49:17 +00:00
if (debug) {
2019-11-19 20:53:12 +00:00
document.outputSettings().prettyPrint(true).outline(true).indentAmount(1);
String[] lines = document.html().split("\\r?\\n");
2019-10-08 16:49:17 +00:00
for (int i = 0; i < lines.length; i++)
lines[i] = Html.escapeHtml(lines[i]);
2019-11-19 20:53:12 +00:00
Element pre = document.createElement("pre");
pre.html(TextUtils.join("<br>", lines));
document.appendChild(pre);
2019-10-08 16:49:17 +00:00
}
2019-10-04 13:25:04 +00:00
2019-11-14 15:06:30 +00:00
// Draw images
2019-11-19 20:53:12 +00:00
Spanned spanned = HtmlHelper.fromHtml(document.html(), new Html.ImageGetter() {
2019-10-08 16:49:17 +00:00
@Override
public Drawable getDrawable(String source) {
2019-11-15 15:08:03 +00:00
Drawable drawable = ImageHelper.decodeImage(context, message.id, source, show_images, zoom, tvBody);
2019-10-04 13:25:04 +00:00
2019-10-08 16:49:17 +00:00
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (drawable instanceof AnimatedImageDrawable)
((AnimatedImageDrawable) drawable).start();
2019-10-04 13:25:04 +00:00
}
2019-10-08 16:49:17 +00:00
return drawable;
2019-10-04 13:25:04 +00:00
}
2019-10-08 16:49:17 +00:00
}, null);
// Replace quote spans
2019-11-14 15:06:30 +00:00
final int px = Helper.dp2pixels(context, 24 + (zoom) * 8);
2019-10-08 16:49:17 +00:00
SpannableStringBuilder builder = new SpannableStringBuilder(spanned);
QuoteSpan[] quoteSpans = builder.getSpans(0, builder.length(), QuoteSpan.class);
for (QuoteSpan quoteSpan : quoteSpans) {
2019-11-14 15:06:30 +00:00
int s = builder.getSpanStart(quoteSpan);
int e = builder.getSpanEnd(quoteSpan);
2019-10-08 16:49:17 +00:00
builder.removeSpan(quoteSpan);
2019-10-04 13:25:04 +00:00
2019-11-14 15:06:30 +00:00
StyledQuoteSpan squote = new StyledQuoteSpan(context, colorPrimary);
builder.setSpan(squote, s, e, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
if (!show_quotes)
builder.setSpan(
new DynamicDrawableSpan() {
@Override
public Drawable getDrawable() {
Drawable d = context.getDrawable(R.drawable.baseline_format_quote_24);
d.setTint(colorAccent);
d.setBounds(0, 0, px, px);
return d;
}
},
s, e, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
2019-10-08 16:49:17 +00:00
}
2019-10-04 13:25:04 +00:00
2019-10-08 16:49:17 +00:00
return builder;
}
}
2019-10-04 13:25:04 +00:00
2019-10-08 16:49:17 +00:00
@Override
protected void onExecuted(Bundle args, Object result) {
TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");
2019-10-04 13:25:04 +00:00
2019-10-08 16:49:17 +00:00
TupleMessageEx amessage = getMessage();
if (amessage == null || !amessage.id.equals(message.id))
return;
2019-10-04 13:25:04 +00:00
2019-10-08 16:49:17 +00:00
boolean show_expanded = properties.getValue("expanded", message.id);
if (!show_expanded)
return;
2019-10-04 13:25:04 +00:00
2019-10-08 16:49:17 +00:00
boolean has_images = args.getBoolean("has_images");
2019-10-04 13:25:04 +00:00
2019-10-08 16:49:17 +00:00
if (result instanceof Spanned) {
tvBody.setText((Spanned) result);
tvBody.setTextIsSelectable(false);
tvBody.setTextIsSelectable(true);
tvBody.setMovementMethod(new TouchHandler(message));
} else if (result instanceof String)
2019-10-30 12:38:25 +00:00
((WebView) wvBody).loadDataWithBaseURL(null, (String) result, "text/html", StandardCharsets.UTF_8.name(), null);
2019-10-10 13:29:39 +00:00
else if (result == null) {
boolean show_full = args.getBoolean("show_full");
if (show_full)
2019-10-30 12:38:25 +00:00
((WebView) wvBody).loadDataWithBaseURL(null, "", "text/html", StandardCharsets.UTF_8.name(), null);
2019-10-10 13:29:39 +00:00
else
tvBody.setText(null);
} else
2019-10-08 16:49:17 +00:00
throw new IllegalStateException("Result=" + result);
2019-10-04 13:25:04 +00:00
2019-10-08 16:49:17 +00:00
pbBody.setVisibility(View.GONE);
2019-12-02 07:44:50 +00:00
// Show attachments
2019-10-08 16:49:17 +00:00
cowner.start();
2019-12-02 07:44:50 +00:00
// Show encrypt actions
2019-12-02 11:17:18 +00:00
ibVerify.setVisibility(false ||
EntityMessage.PGP_SIGNONLY.equals(message.encrypt) ||
EntityMessage.SMIME_SIGNONLY.equals(message.encrypt)
2019-12-02 07:44:50 +00:00
? View.VISIBLE : View.GONE);
ibDecrypt.setVisibility(args.getBoolean("inline_encrypted") ||
2019-12-02 09:03:46 +00:00
EntityMessage.PGP_SIGNENCRYPT.equals(message.encrypt) ||
EntityMessage.SMIME_SIGNENCRYPT.equals(message.encrypt)
2019-12-02 07:44:50 +00:00
? View.VISIBLE : View.GONE);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean auto_decrypt = prefs.getBoolean("auto_decrypt", false);
2019-12-06 12:38:52 +00:00
if (auto_decrypt &&
(EntityMessage.PGP_SIGNENCRYPT.equals(message.encrypt) ||
EntityMessage.SMIME_SIGNENCRYPT.equals(message.encrypt)))
2019-12-02 07:44:50 +00:00
onActionDecrypt(message, true);
boolean show_full = properties.getValue("full", message.id);
boolean always_images = prefs.getBoolean("html_always_images", false);
2019-12-02 07:44:50 +00:00
// Show images
2019-12-19 19:12:42 +00:00
ibImages.setVisibility(has_images && !(show_full && always_images) ? View.VISIBLE : View.GONE);
2019-10-04 13:25:04 +00:00
}
2019-10-08 16:49:17 +00:00
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-10-08 16:49:17 +00:00
}
}.execute(context, owner, args, "message:body");
2019-10-04 13:25:04 +00:00
}
2019-02-04 12:17:42 +00:00
private void bindAttachments(final TupleMessageEx message, @Nullable List<EntityAttachment> attachments) {
if (attachments == null)
attachments = new ArrayList<>();
2019-09-02 09:32:05 +00:00
properties.setAttachments(message.id, attachments);
2019-02-04 12:17:42 +00:00
2019-10-05 11:05:03 +00:00
grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE);
2019-02-04 12:17:42 +00:00
boolean show_inline = properties.getValue("inline", message.id);
2019-12-02 07:44:50 +00:00
Log.i("Show inline=" + show_inline);
2019-02-04 12:17:42 +00:00
2019-02-17 12:05:58 +00:00
boolean has_inline = false;
2019-02-04 12:17:42 +00:00
boolean download = false;
boolean save = (attachments.size() > 1);
boolean downloading = false;
2019-05-18 09:19:39 +00:00
boolean calendar = false;
2019-10-05 11:05:03 +00:00
2019-02-04 12:17:42 +00:00
List<EntityAttachment> a = new ArrayList<>();
for (EntityAttachment attachment : attachments) {
boolean inline = ((attachment.isInline() && attachment.isImage()) || attachment.encryption != null);
2019-02-17 12:05:58 +00:00
if (inline)
has_inline = true;
2019-02-04 12:17:42 +00:00
if (attachment.progress == null && !attachment.available)
download = true;
if (!attachment.available)
save = false;
if (attachment.progress != null)
downloading = true;
if (show_inline || !inline || !attachment.available)
2019-02-04 12:17:42 +00:00
a.add(attachment);
2019-05-18 09:19:39 +00:00
2019-05-18 17:44:21 +00:00
if (attachment.available && "text/calendar".equals(attachment.type)) {
2019-05-18 09:19:39 +00:00
calendar = true;
2019-07-22 07:30:58 +00:00
bindCalendar(message, attachment);
2019-05-18 09:19:39 +00:00
}
2019-02-04 12:17:42 +00:00
}
adapterAttachment.set(a);
2019-05-18 09:19:39 +00:00
if (!calendar) {
tvCalendarSummary.setVisibility(View.GONE);
tvCalendarStart.setVisibility(View.GONE);
tvCalendarEnd.setVisibility(View.GONE);
tvAttendees.setVisibility(View.GONE);
pbCalendarWait.setVisibility(View.GONE);
grpCalendar.setVisibility(View.GONE);
2019-05-18 17:44:21 +00:00
grpCalendarResponse.setVisibility(View.GONE);
2019-05-18 09:19:39 +00:00
}
2019-02-04 12:17:42 +00:00
cbInline.setOnCheckedChangeListener(null);
cbInline.setChecked(show_inline);
2019-02-17 12:05:58 +00:00
cbInline.setVisibility(has_inline ? View.VISIBLE : View.GONE);
2019-08-14 18:25:46 +00:00
2019-02-04 12:17:42 +00:00
btnSaveAttachments.setVisibility(save ? View.VISIBLE : View.GONE);
2019-08-15 13:01:26 +00:00
btnDownloadAttachments.setVisibility(download && suitable ? View.VISIBLE : View.GONE);
2019-03-16 13:12:31 +00:00
tvNoInternetAttachments.setVisibility(downloading && !suitable ? View.VISIBLE : View.GONE);
2019-02-04 12:17:42 +00:00
cbInline.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
properties.setValue("inline", message.id, isChecked);
2019-03-17 20:31:24 +00:00
cowner.restart();
DB.getInstance(context).attachment().liveAttachments(message.id).observe(cowner, new Observer<List<EntityAttachment>>() {
@Override
public void onChanged(@Nullable List<EntityAttachment> attachments) {
bindAttachments(message, attachments);
}
});
2019-02-04 12:17:42 +00:00
}
});
List<EntityAttachment> images = new ArrayList<>();
for (EntityAttachment attachment : attachments)
if (!attachment.isInline() && attachment.isImage())
2019-02-04 12:17:42 +00:00
images.add(attachment);
adapterImage.set(images);
2019-05-14 17:21:11 +00:00
grpImages.setVisibility(images.size() > 0 ? View.VISIBLE : View.GONE);
2019-02-04 12:17:42 +00:00
}
2019-07-22 07:30:58 +00:00
private void bindCalendar(final TupleMessageEx message, EntityAttachment attachment) {
// https://tools.ietf.org/html/rfc5546
Bundle args = new Bundle();
args.putLong("id", message.id);
args.putSerializable("file", attachment.getFile(context));
new SimpleTask<ICalendar>() {
@Override
protected void onPreExecute(Bundle args) {
grpCalendar.setVisibility(View.VISIBLE);
pbCalendarWait.setVisibility(View.VISIBLE);
}
@Override
protected void onPostExecute(Bundle args) {
pbCalendarWait.setVisibility(View.GONE);
}
@Override
protected ICalendar onExecute(Context context, Bundle args) throws IOException {
File file = (File) args.getSerializable("file");
return Biweekly.parse(file).first();
}
@Override
protected void onExecuted(Bundle args, ICalendar icalendar) {
long id = args.getLong("id");
TupleMessageEx amessage = getMessage();
if (amessage == null || !amessage.id.equals(id))
return;
if (icalendar == null ||
icalendar.getMethod() == null ||
icalendar.getEvents().size() == 0) {
tvCalendarSummary.setVisibility(View.GONE);
tvCalendarStart.setVisibility(View.GONE);
tvCalendarEnd.setVisibility(View.GONE);
tvAttendees.setVisibility(View.GONE);
pbCalendarWait.setVisibility(View.GONE);
grpCalendar.setVisibility(View.GONE);
grpCalendarResponse.setVisibility(View.GONE);
return;
}
DateFormat DTF = Helper.getDateTimeInstance(context);
VEvent event = icalendar.getEvents().get(0);
2019-09-30 11:40:14 +00:00
String summary = event.getSummary() == null ? null : event.getSummary().getValue();
2019-07-22 07:30:58 +00:00
ICalDate start = event.getDateStart() == null ? null : event.getDateStart().getValue();
ICalDate end = event.getDateEnd() == null ? null : event.getDateEnd().getValue();
List<String> attendee = new ArrayList<>();
for (Attendee a : event.getAttendees()) {
String email = a.getEmail();
String name = a.getCommonName();
if (TextUtils.isEmpty(name)) {
if (!TextUtils.isEmpty(email))
attendee.add(email);
} else {
if (TextUtils.isEmpty(email) || name.equals(email))
attendee.add(name);
else
attendee.add(name + " (" + email + ")");
}
}
Organizer organizer = event.getOrganizer();
2019-09-30 11:40:14 +00:00
tvCalendarSummary.setText(summary);
2019-07-22 07:30:58 +00:00
tvCalendarSummary.setVisibility(summary == null ? View.GONE : View.VISIBLE);
tvCalendarStart.setText(start == null ? null : DTF.format(start.getTime()));
tvCalendarStart.setVisibility(start == null ? View.GONE : View.VISIBLE);
tvCalendarEnd.setText(end == null ? null : DTF.format(end.getTime()));
tvCalendarEnd.setVisibility(end == null ? View.GONE : View.VISIBLE);
tvAttendees.setText(TextUtils.join(", ", attendee));
tvAttendees.setVisibility(attendee.size() == 0 ? View.GONE : View.VISIBLE);
boolean canRespond =
(icalendar.getMethod().isRequest() &&
organizer != null && organizer.getEmail() != null &&
message.to != null && message.to.length > 0);
grpCalendarResponse.setVisibility(canRespond ? View.VISIBLE : View.GONE);
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-07-22 07:30:58 +00:00
}
2019-08-22 06:44:22 +00:00
}.setLog(false).execute(context, owner, args, "message:calendar");
2019-07-22 07:30:58 +00:00
}
2019-05-18 17:44:21 +00:00
private void onActionCalendar(TupleMessageEx message, int action) {
2019-08-13 08:27:17 +00:00
if (!ActivityBilling.isPro(context)) {
context.startActivity(new Intent(context, ActivityBilling.class));
2019-05-25 14:12:53 +00:00
return;
}
2019-05-18 17:44:21 +00:00
Bundle args = new Bundle();
args.putLong("id", message.id);
args.putInt("action", action);
2019-09-30 11:40:14 +00:00
new SimpleTask<Object>() {
2019-05-18 17:44:21 +00:00
@Override
2019-09-30 11:40:14 +00:00
protected Object onExecute(Context context, Bundle args) throws Throwable {
2019-05-18 17:44:21 +00:00
long id = args.getLong("id");
int action = args.getInt("action");
DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
List<EntityAttachment> attachments = db.attachment().getAttachments(id);
for (EntityAttachment attachment : attachments)
if (attachment.available && "text/calendar".equals(attachment.type)) {
File file = attachment.getFile(context);
ICalendar icalendar = Biweekly.parse(file).first();
VEvent event = icalendar.getEvents().get(0);
2019-09-30 11:40:14 +00:00
if (action == R.id.ibCalendar) {
String summary = event.getSummary() == null ? null : event.getSummary().getValue();
ICalDate start = event.getDateStart() == null ? null : event.getDateStart().getValue();
ICalDate end = event.getDateEnd() == null ? null : event.getDateEnd().getValue();
String location = event.getLocation() == null ? null : event.getLocation().getValue();
List<String> attendee = new ArrayList<>();
for (Attendee a : event.getAttendees()) {
String email = a.getEmail();
if (!TextUtils.isEmpty(email))
attendee.add(email);
}
// https://developer.android.com/guide/topics/providers/calendar-provider.html#intent-insert
Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(CalendarContract.Events.CONTENT_URI)
.putExtra(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_BUSY);
if (summary != null)
intent.putExtra(CalendarContract.Events.TITLE, summary);
if (start != null)
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start.getTime());
if (end != null)
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end.getTime());
if (location != null)
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, location);
if (attendee.size() > 0)
intent.putExtra(Intent.EXTRA_EMAIL, TextUtils.join(",", attendee));
return intent;
}
2019-05-18 17:44:21 +00:00
// https://tools.ietf.org/html/rfc5546#section-4.2.2
VEvent ev = new VEvent();
ev.setOrganizer(event.getOrganizer());
ev.setUid(event.getUid());
if (event.getSequence() != null)
ev.setSequence(event.getSequence());
if (event.getDateStart() != null)
ev.setDateStart(event.getDateStart());
if (event.getDateEnd() != null)
ev.setDateEnd(event.getDateEnd());
2019-05-18 17:44:21 +00:00
InternetAddress to = (InternetAddress) message.to[0];
Attendee attendee = new Attendee(to.getPersonal(), to.getAddress());
switch (action) {
case R.id.btnCalendarAccept:
attendee.setParticipationStatus(ParticipationStatus.ACCEPTED);
break;
case R.id.btnCalendarDecline:
attendee.setParticipationStatus(ParticipationStatus.DECLINED);
break;
case R.id.btnCalendarMaybe:
attendee.setParticipationStatus(ParticipationStatus.TENTATIVE);
break;
}
ev.addAttendee(attendee);
// https://icalendar.org/validator.html
2019-05-18 17:44:21 +00:00
ICalendar response = new ICalendar();
response.setMethod(Method.REPLY);
response.addEvent(ev);
2019-08-03 11:31:18 +00:00
File ics = File.createTempFile("calendar", ".ics", context.getCacheDir());
2019-05-18 17:44:21 +00:00
response.write(ics);
return ics;
}
return null;
}
@Override
2019-09-30 11:40:14 +00:00
protected void onExecuted(Bundle args, Object result) {
if (result instanceof File) {
String status = null;
switch (action) {
case R.id.btnCalendarAccept:
status = context.getString(R.string.title_icalendar_accept);
break;
case R.id.btnCalendarDecline:
status = context.getString(R.string.title_icalendar_decline);
break;
case R.id.btnCalendarMaybe:
status = context.getString(R.string.title_icalendar_maybe);
break;
}
2019-08-16 06:29:11 +00:00
2019-09-30 11:40:14 +00:00
Intent reply = new Intent(context, ActivityCompose.class)
.putExtra("action", "participation")
.putExtra("reference", args.getLong("id"))
.putExtra("ics", (File) result)
.putExtra("status", status);
context.startActivity(reply);
} else if (result instanceof Intent) {
context.startActivity((Intent) result);
}
2019-05-18 17:44:21 +00:00
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-05-18 17:44:21 +00:00
}
}.execute(context, owner, args, "message:participation");
}
2019-10-09 11:24:16 +00:00
private boolean isOutgoing(TupleMessageEx message) {
if (EntityFolder.isOutgoing(message.folderType))
return true;
else
return (message.identityEmail != null &&
message.from != null && message.from.length == 1 &&
message.identityEmail.equals(((InternetAddress) message.from[0]).getAddress()));
2019-10-09 11:24:16 +00:00
}
2019-02-01 09:29:26 +00:00
private TupleMessageEx getMessage() {
int pos = getAdapterPosition();
if (pos == RecyclerView.NO_POSITION)
2019-02-01 09:29:26 +00:00
return null;
return differ.getItem(pos);
}
2018-10-15 10:05:42 +00:00
2019-09-01 13:42:53 +00:00
@Override
public boolean onTouch(View view, MotionEvent ev) {
2019-10-04 13:25:04 +00:00
if (ev.getPointerCount() > 1) {
2019-09-01 15:28:09 +00:00
view.getParent().requestDisallowInterceptTouchEvent(true);
2019-10-04 13:25:04 +00:00
if (view.getId() == R.id.tvBody) {
gestureDetector.onTouchEvent(ev);
return true;
} else
return false;
2019-09-01 15:28:09 +00:00
} else {
view.getParent().requestDisallowInterceptTouchEvent(false);
return false;
2019-09-01 13:42:53 +00:00
}
}
2019-10-04 13:25:04 +00:00
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
TupleMessageEx message = getMessage();
if (message != null)
properties.setHeight(message.id, bottom - top);
}
2019-02-01 09:29:26 +00:00
@Override
public void onClick(View view) {
2019-06-26 10:58:36 +00:00
final TupleMessageEx message = getMessage();
2019-01-26 10:09:40 +00:00
if (message == null)
return;
2018-08-02 13:33:06 +00:00
2019-10-22 17:41:15 +00:00
if (view.getId() == R.id.ibAvatar)
onViewContact(message);
else if (view.getId() == R.id.ibAuth)
onShowAuth(message);
2019-09-01 17:07:21 +00:00
else if (view.getId() == R.id.ibSnoozed)
2019-01-07 15:05:24 +00:00
onShowSnoozed(message);
2019-09-01 17:07:21 +00:00
else if (view.getId() == R.id.ibFlagged)
2018-12-04 16:08:36 +00:00
onToggleFlag(message);
2019-09-13 07:34:00 +00:00
else if (view.getId() == R.id.ibHelp)
2019-09-06 12:02:16 +00:00
onHelp(message);
2019-05-08 14:44:01 +00:00
else if (view.getId() == R.id.ibSearchContact)
2019-01-27 13:50:21 +00:00
onSearchContact(message);
2019-05-08 14:44:01 +00:00
else if (view.getId() == R.id.ibNotifyContact)
2019-03-07 12:29:03 +00:00
onNotifyContact(message);
2019-05-08 14:44:01 +00:00
else if (view.getId() == R.id.ibAddContact)
2018-10-15 10:05:42 +00:00
onAddContact(message);
else if (viewType == ViewType.THREAD) {
2019-05-18 17:44:21 +00:00
switch (view.getId()) {
2019-09-01 16:59:51 +00:00
case R.id.ibExpanderAddress:
2019-05-18 17:44:21 +00:00
onToggleAddresses(message);
break;
2019-08-15 13:01:26 +00:00
2019-05-18 17:44:21 +00:00
case R.id.btnSaveAttachments:
onSaveAttachments(message);
break;
2019-08-15 13:01:26 +00:00
case R.id.btnDownloadAttachments:
onDownloadAttachments(message);
break;
2019-08-14 18:08:24 +00:00
case R.id.ibFull:
2019-10-04 13:25:04 +00:00
onShow(message, true);
2019-07-10 17:00:25 +00:00
break;
2019-05-18 17:44:21 +00:00
case R.id.ibImages:
2019-10-04 13:25:04 +00:00
onShow(message, false);
2019-05-18 17:44:21 +00:00
break;
2019-09-08 10:57:21 +00:00
case R.id.ibUnsubscribe:
onActionUnsubscribe(message);
break;
2019-11-27 09:40:43 +00:00
case R.id.ibVerify:
2019-08-14 18:08:24 +00:00
case R.id.ibDecrypt:
onActionDecrypt(message, false);
2019-08-14 18:08:24 +00:00
break;
2019-10-05 10:54:41 +00:00
case R.id.ibDownloading:
Helper.viewFAQ(context, 15);
break;
2019-05-18 17:44:21 +00:00
case R.id.btnCalendarAccept:
case R.id.btnCalendarDecline:
case R.id.btnCalendarMaybe:
2019-09-30 11:40:14 +00:00
case R.id.ibCalendar:
2019-05-18 17:44:21 +00:00
onActionCalendar(message, view.getId());
break;
default:
onToggleMessage(message);
}
2018-10-15 10:05:42 +00:00
} else {
2019-08-16 12:31:31 +00:00
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
// Unreveal
int cx = card.getWidth() / 2;
int cy = card.getHeight() / 2;
int r = Math.max(card.getWidth(), card.getHeight());
Animator anim = ViewAnimationUtils.createCircularReveal(card, cx, cy, r, 0);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.setDuration(context.getResources().getInteger(android.R.integer.config_mediumAnimTime));
anim.start();
} else {
// selectableItemBackground
card.setClickable(true);
card.setPressed(true);
2019-08-18 06:34:12 +00:00
card.setPressed(false);
card.setClickable(false);
2019-08-16 12:31:31 +00:00
}
2019-03-08 10:27:33 +00:00
2019-02-05 10:28:38 +00:00
if (EntityFolder.DRAFTS.equals(message.folderType) && message.visible == 1)
context.startActivity(
2018-10-15 10:05:42 +00:00
new Intent(context, ActivityCompose.class)
.putExtra("action", "edit")
.putExtra("id", message.id));
else {
2019-06-26 11:55:35 +00:00
final LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
final Intent viewThread = new Intent(ActivityView.ACTION_VIEW_THREAD)
.putExtra("account", message.account)
.putExtra("thread", message.thread)
.putExtra("id", message.id)
.putExtra("found", viewType == ViewType.SEARCH);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
2019-10-01 13:20:24 +00:00
boolean doubletap = prefs.getBoolean("doubletap", false);
2019-06-26 11:55:35 +00:00
2019-07-07 07:25:52 +00:00
if (!doubletap || message.folderReadOnly || EntityFolder.OUTBOX.equals(message.folderType)) {
2019-06-26 11:55:35 +00:00
lbm.sendBroadcast(viewThread);
return;
}
2019-06-26 10:58:36 +00:00
firstClick = !firstClick;
if (firstClick) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (firstClick) {
firstClick = false;
2019-06-26 11:55:35 +00:00
lbm.sendBroadcast(viewThread);
2019-06-26 10:58:36 +00:00
}
}
}, ViewConfiguration.getDoubleTapTimeout());
} else {
2019-09-29 16:50:30 +00:00
message.ui_seen = !message.ui_seen;
message.unseen = (message.ui_seen ? 0 : message.count);
bindTo(message);
2019-06-26 10:58:36 +00:00
Bundle args = new Bundle();
args.putLong("id", message.id);
2019-11-23 12:48:59 +00:00
args.putInt("protocol", message.accountProtocol);
2019-06-26 10:58:36 +00:00
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
2019-11-23 12:48:59 +00:00
int protocol = args.getInt("protocol");
2019-06-26 10:58:36 +00:00
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
2019-09-25 19:23:44 +00:00
if (message == null)
return null;
2019-11-23 12:48:59 +00:00
if (protocol != EntityAccount.TYPE_IMAP)
2019-09-26 09:57:00 +00:00
EntityOperation.queue(context, message, EntityOperation.SEEN, !message.ui_seen);
else {
2019-07-25 13:38:14 +00:00
List<EntityMessage> messages = db.message().getMessagesByThread(
2019-08-30 06:06:25 +00:00
message.account, message.thread, threading ? null : id, message.ui_seen ? message.folder : null);
for (EntityMessage threaded : messages)
if (threaded.ui_seen == message.ui_seen)
EntityOperation.queue(context, threaded, EntityOperation.SEEN, !message.ui_seen);
}
2019-06-26 10:58:36 +00:00
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
2019-12-09 18:44:27 +00:00
ServiceSynchronize.eval(context, "doubletap");
2019-12-07 19:32:58 +00:00
2019-06-26 10:58:36 +00:00
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-06-26 10:58:36 +00:00
}
}.execute(context, owner, args, "message:seen");
}
2018-10-15 10:05:42 +00:00
}
}
}
2019-08-16 06:12:04 +00:00
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
final TupleMessageEx message = getMessage();
if (message == null)
return false;
switch (item.getItemId()) {
case R.id.action_more:
onActionMore(message);
return true;
case R.id.action_delete:
onActionDelete(message);
return true;
case R.id.action_move:
if (EntityFolder.OUTBOX.equals(message.folderType))
onActionMoveOutbox(message);
else
onActionMove(message, false);
return true;
case R.id.action_archive:
if (EntityFolder.JUNK.equals(message.folderType))
onActionMoveJunk(message);
else
onActionArchive(message);
return true;
case R.id.action_reply:
onActionReplyMenu(message);
return true;
default:
return false;
}
}
2019-06-28 16:43:36 +00:00
@Override
public boolean onLongClick(View view) {
final TupleMessageEx message = getMessage();
2019-07-07 07:25:52 +00:00
if (message == null || message.folderReadOnly)
2019-06-28 16:43:36 +00:00
return false;
2019-09-01 17:07:21 +00:00
if (view.getId() == R.id.ibFlagged) {
2019-06-28 16:43:36 +00:00
onMenuColoredStar(message);
return true;
}
return false;
}
2019-08-10 08:42:28 +00:00
@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
if (keyEvent.getAction() == KeyEvent.ACTION_DOWN &&
(keyCode == KeyEvent.KEYCODE_ENTER ||
keyCode == KeyEvent.KEYCODE_DPAD_CENTER ||
keyCode == KeyEvent.KEYCODE_BUTTON_A)) {
onClick(view);
return true;
} else
return false;
}
2019-10-22 17:41:15 +00:00
private void onViewContact(TupleMessageEx message) {
Uri lookupUri = (Uri) ibAvatar.getTag();
if (lookupUri != null) {
Intent intent = new Intent(Intent.ACTION_VIEW, lookupUri);
if (intent.resolveActivity(context.getPackageManager()) != null)
context.startActivity(intent);
}
}
private void onShowAuth(TupleMessageEx message) {
List<String> result = new ArrayList<>();
if (Boolean.FALSE.equals(message.dkim))
result.add("DKIM");
if (Boolean.FALSE.equals(message.spf))
result.add("SPF");
if (Boolean.FALSE.equals(message.dmarc))
result.add("DMARC");
if (Boolean.FALSE.equals(message.mx))
result.add("MX");
ToastEx.makeText(context,
context.getString(R.string.title_authentication_failed, TextUtils.join(", ", result)),
Toast.LENGTH_LONG)
.show();
}
2019-01-07 17:50:23 +00:00
private void onShowSnoozed(TupleMessageEx message) {
2019-10-12 09:09:54 +00:00
if (message.ui_snoozed != null && message.ui_snoozed != Long.MAX_VALUE) {
2019-07-15 19:28:25 +00:00
DateFormat DTF = Helper.getDateTimeInstance(context, SimpleDateFormat.MEDIUM, SimpleDateFormat.SHORT);
DateFormat D = new SimpleDateFormat("E");
2019-09-01 17:08:47 +00:00
ToastEx.makeText(
context,
2019-08-09 16:42:36 +00:00
D.format(message.ui_snoozed) + " " + DTF.format(message.ui_snoozed) + " - " +
DateUtils.getRelativeTimeSpanString(
message.ui_snoozed,
System.currentTimeMillis(),
DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE),
2019-09-01 17:08:47 +00:00
Toast.LENGTH_LONG).show();
}
2019-01-07 17:50:23 +00:00
}
private void onToggleFlag(TupleMessageEx message) {
2019-03-30 08:05:51 +00:00
int flagged = (message.count - message.unflagged);
Log.i("Set message id=" + message.id + " flagged=" + flagged);
2019-01-30 07:50:20 +00:00
2019-01-07 17:50:23 +00:00
Bundle args = new Bundle();
args.putLong("id", message.id);
2019-03-30 08:05:51 +00:00
args.putBoolean("flagged", flagged == 0);
2019-01-07 17:50:23 +00:00
args.putBoolean("thread", viewType != ViewType.THREAD);
2019-01-30 07:50:20 +00:00
message.unflagged = message.ui_flagged ? message.count : 0;
message.ui_flagged = !message.ui_flagged;
boolean expanded = properties.getValue("expanded", message.id);
bindFlagged(message, expanded);
2019-01-07 17:50:23 +00:00
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
boolean flagged = args.getBoolean("flagged");
boolean thread = args.getBoolean("thread");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
2019-09-28 08:05:45 +00:00
EntityAccount account = db.account().getAccount(message.account);
if (account == null)
return null;
2019-11-23 12:48:59 +00:00
if (account.protocol != EntityAccount.TYPE_IMAP)
2019-09-28 08:05:45 +00:00
EntityOperation.queue(context, message, EntityOperation.FLAG, flagged);
else {
List<EntityMessage> messages = db.message().getMessagesByThread(
message.account, message.thread, threading && thread ? null : id, null);
for (EntityMessage threaded : messages)
EntityOperation.queue(context, threaded, EntityOperation.FLAG, flagged);
}
2019-01-07 17:50:23 +00:00
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
2019-12-09 18:44:27 +00:00
ServiceSynchronize.eval(context, "flag");
2019-12-07 19:32:58 +00:00
2019-01-07 17:50:23 +00:00
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-01-07 17:50:23 +00:00
}
}.execute(context, owner, args, "message:flag");
}
2019-09-06 12:02:16 +00:00
private void onHelp(TupleMessageEx message) {
Helper.viewFAQ(context, 130);
2019-09-06 12:02:16 +00:00
}
2019-01-27 13:50:21 +00:00
private void onSearchContact(TupleMessageEx message) {
2019-01-27 14:38:53 +00:00
Bundle args = new Bundle();
args.putLong("id", message.id);
new SimpleTask<Address[]>() {
@Override
protected Address[] onExecute(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
EntityFolder folder = db.folder().getFolder(message.folder);
2019-09-22 18:03:31 +00:00
if (folder == null)
return null;
boolean outgoing = EntityFolder.isOutgoing(folder.type);
2019-01-27 14:38:53 +00:00
2019-09-22 18:03:31 +00:00
if (message.identity != null) {
2019-09-26 10:51:39 +00:00
if (message.from != null && message.from.length > 0) {
2019-09-22 18:03:31 +00:00
EntityIdentity identity = db.identity().getIdentity(message.identity);
if (identity == null)
return null;
2019-09-26 10:51:39 +00:00
for (Address sender : message.from)
2019-09-23 08:47:05 +00:00
if (identity.similarAddress(sender)) {
2019-09-22 18:03:31 +00:00
outgoing = true;
break;
}
}
2019-01-27 14:38:53 +00:00
}
2019-09-27 07:39:41 +00:00
if (outgoing && message.reply != null &&
MessageHelper.equal(message.from, message.to))
return message.reply;
2019-05-13 11:38:27 +00:00
return (outgoing ? message.to : message.from);
2019-01-27 14:38:53 +00:00
}
@Override
protected void onExecuted(Bundle args, Address[] addresses) {
2019-09-22 18:03:31 +00:00
if (addresses == null || addresses.length == 0)
return;
2019-05-13 12:08:51 +00:00
String query = ((InternetAddress) addresses[0]).getAddress();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_SEARCH)
2019-11-16 11:53:36 +00:00
.putExtra("account", -1L)
2019-05-13 12:08:51 +00:00
.putExtra("folder", -1L)
.putExtra("query", query));
2019-01-27 14:38:53 +00:00
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-01-27 14:38:53 +00:00
}
}.execute(context, owner, args, "message:search");
2019-01-27 13:50:21 +00:00
}
2019-03-07 12:29:03 +00:00
@TargetApi(Build.VERSION_CODES.O)
private void onNotifyContact(final TupleMessageEx message) {
final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
2019-11-12 09:57:26 +00:00
final String channelId = message.getNotificationChannelId();
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, ibAddContact);
NotificationChannel channel = nm.getNotificationChannel(channelId);
if (channel == null)
popupMenu.getMenu().add(Menu.NONE, R.string.title_create_channel, 1, R.string.title_create_channel);
else {
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, 2, R.string.title_edit_channel);
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_channel, 3, R.string.title_delete_channel);
}
2019-03-07 12:29:03 +00:00
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.string.title_create_channel:
onActionCreateChannel();
return true;
case R.string.title_edit_channel:
onActionEditChannel();
return true;
case R.string.title_delete_channel:
onActionDeleteChannel();
return true;
default:
return false;
}
}
@TargetApi(Build.VERSION_CODES.O)
private void onActionCreateChannel() {
2019-08-13 08:27:17 +00:00
if (!ActivityBilling.isPro(context)) {
context.startActivity(new Intent(context, ActivityBilling.class));
2019-05-16 09:10:01 +00:00
return;
}
2019-11-12 09:57:26 +00:00
InternetAddress from = (InternetAddress) message.from[0];
NotificationChannel channel = new NotificationChannel(
channelId, from.getAddress(),
NotificationManager.IMPORTANCE_HIGH);
channel.setGroup("contacts");
channel.setDescription(from.getPersonal());
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
channel.enableLights(true);
nm.createNotificationChannel(channel);
onActionEditChannel();
}
private void onActionEditChannel() {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName())
.putExtra(Settings.EXTRA_CHANNEL_ID, channelId);
context.startActivity(intent);
}
private void onActionDeleteChannel() {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.deleteNotificationChannel(channelId);
}
});
popupMenu.show();
}
2018-11-13 09:22:41 +00:00
private void onAddContact(TupleMessageEx message) {
2018-10-15 10:05:42 +00:00
for (Address address : message.from) {
InternetAddress ia = (InternetAddress) address;
String name = ia.getPersonal();
String email = ia.getAddress();
// https://developer.android.com/training/contacts-provider/modify-data
Intent edit = new Intent();
if (!TextUtils.isEmpty(name))
edit.putExtra(ContactsContract.Intents.Insert.NAME, name);
if (!TextUtils.isEmpty(email))
edit.putExtra(ContactsContract.Intents.Insert.EMAIL, email);
2019-02-22 15:59:23 +00:00
ContentResolver resolver = context.getContentResolver();
try (Cursor cursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
new String[]{
ContactsContract.CommonDataKinds.Photo.CONTACT_ID,
ContactsContract.Contacts.LOOKUP_KEY
},
ContactsContract.CommonDataKinds.Email.ADDRESS + " = ?",
new String[]{email}, null)) {
2018-12-24 10:51:32 +00:00
if (cursor != null && cursor.moveToNext()) {
2018-10-15 10:05:42 +00:00
int colContactId = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Photo.CONTACT_ID);
int colLookupKey = cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY);
long contactId = cursor.getLong(colContactId);
String lookupKey = cursor.getString(colLookupKey);
Uri lookupUri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
edit.setAction(Intent.ACTION_EDIT);
2019-11-16 13:17:59 +00:00
edit.setDataAndTypeAndNormalize(lookupUri, ContactsContract.Contacts.CONTENT_ITEM_TYPE);
2018-10-15 10:05:42 +00:00
} else {
edit.setAction(Intent.ACTION_INSERT);
edit.setType(ContactsContract.Contacts.CONTENT_TYPE);
}
}
2019-01-23 19:32:37 +00:00
PackageManager pm = context.getPackageManager();
if (edit.resolveActivity(pm) == null)
2019-06-30 14:55:15 +00:00
Snackbar.make(parentFragment.getView(),
R.string.title_no_contacts, Snackbar.LENGTH_LONG).show();
2019-01-23 19:32:37 +00:00
else
context.startActivity(edit);
2018-10-15 10:05:42 +00:00
}
}
2019-02-01 09:29:26 +00:00
private void onToggleMessage(TupleMessageEx message) {
2018-11-13 09:22:41 +00:00
if (EntityFolder.DRAFTS.equals(message.folderType))
context.startActivity(
2018-11-13 09:22:41 +00:00
new Intent(context, ActivityCompose.class)
.putExtra("action", "edit")
.putExtra("id", message.id));
else {
2018-12-21 07:32:26 +00:00
boolean expanded = !properties.getValue("expanded", message.id);
properties.setValue("expanded", message.id, expanded);
2018-12-22 08:06:33 +00:00
2019-10-20 07:53:12 +00:00
ibExpander.setTag(expanded);
2019-09-01 17:19:50 +00:00
ibExpander.setImageLevel(expanded ? 0 /* less*/ : 1 /* more */);
2019-12-19 13:26:17 +00:00
ibExpander.setContentDescription(context.getString(
expanded ? R.string.title_accessibility_expanded : R.string.title_accessibility_collapsed));
2019-04-17 07:38:24 +00:00
2019-08-29 16:12:34 +00:00
if (expanded)
bindExpanded(message, true);
else
2019-06-05 05:59:34 +00:00
clearExpanded(message);
bindFlagged(message, expanded);
2019-10-18 17:35:40 +00:00
bindExpandWarning(message, expanded);
2019-10-20 07:48:49 +00:00
// Needed for expand one
properties.scrollTo(getAdapterPosition());
2018-11-13 09:22:41 +00:00
}
2018-11-04 16:16:45 +00:00
}
2019-02-01 09:29:26 +00:00
private void onToggleAddresses(TupleMessageEx message) {
2018-12-21 07:32:26 +00:00
boolean addresses = !properties.getValue("addresses", message.id);
properties.setValue("addresses", message.id, addresses);
2019-08-29 16:12:34 +00:00
bindExpanded(message, false);
2018-11-04 16:16:45 +00:00
}
2019-08-15 13:05:41 +00:00
private void onDownloadAttachments(final TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("id", message.id);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
2019-10-05 10:42:04 +00:00
long mid = args.getLong("id");
2019-08-15 13:05:41 +00:00
DB db = DB.getInstance(context);
try {
db.beginTransaction();
2019-10-05 10:42:04 +00:00
EntityMessage message = db.message().getMessage(mid);
if (message == null || message.uid == null)
return null;
for (EntityAttachment attachment : db.attachment().getAttachments(message.id))
if (attachment.progress == null && !attachment.available)
EntityOperation.queue(context, message, EntityOperation.ATTACHMENT, attachment.id);
2019-08-15 13:05:41 +00:00
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
2019-12-09 18:44:27 +00:00
ServiceSynchronize.eval(context, "attachment");
2019-12-07 19:32:58 +00:00
2019-08-15 13:05:41 +00:00
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-08-15 13:05:41 +00:00
}
}.execute(context, owner, args, "message:attachment:download");
}
private void onSaveAttachments(TupleMessageEx message) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(FragmentMessages.ACTION_STORE_ATTACHMENTS)
.putExtra("id", message.id));
}
2019-10-04 13:25:04 +00:00
private void onShow(final TupleMessageEx message, boolean full) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean current = properties.getValue(full ? "full" : "images", message.id);
boolean asked = properties.getValue(full ? "full_asked" : "images_asked", message.id);
if (current || asked) {
if (current) {
SharedPreferences.Editor editor = prefs.edit();
2019-11-12 13:15:52 +00:00
for (Address sender : message.from) {
String from = ((InternetAddress) sender).getAddress();
editor.remove(from + (full ? ".show_full" : ".show_images"));
2019-10-04 13:25:04 +00:00
}
editor.apply();
2019-10-04 13:25:04 +00:00
}
properties.setValue(full ? "full" : "images", message.id, !current);
2019-11-04 08:57:38 +00:00
if (full)
onShowFullConfirmed(message);
else
onShowImagesConfirmed(message);
return;
}
2019-10-04 13:25:04 +00:00
View dview = LayoutInflater.from(context).inflate(
full ? R.layout.dialog_show_full : R.layout.dialog_show_images, null);
2019-09-19 07:00:50 +00:00
CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain);
CheckBox cbAlwaysImages = dview.findViewById(R.id.cbAlwaysImages);
2019-11-04 08:57:38 +00:00
if (full) {
cbAlwaysImages.setChecked(prefs.getBoolean("html_always_images", false));
2019-11-04 08:57:38 +00:00
cbAlwaysImages.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
prefs.edit().putBoolean("html_always_images", isChecked).apply();
}
});
}
2019-01-30 08:47:54 +00:00
2019-09-01 20:33:32 +00:00
if (message.from == null || message.from.length == 0)
cbNotAgain.setVisibility(View.GONE);
else {
List<String> froms = new ArrayList<>();
for (Address address : message.from)
froms.add(((InternetAddress) address).getAddress());
cbNotAgain.setText(context.getString(R.string.title_no_ask_for_again,
TextUtils.join(", ", froms)));
}
2019-01-30 08:47:54 +00:00
2019-09-19 07:00:50 +00:00
cbNotAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences.Editor editor = prefs.edit();
2019-11-12 13:15:52 +00:00
for (Address sender : message.from) {
String from = ((InternetAddress) sender).getAddress();
2019-10-04 13:25:04 +00:00
editor.putBoolean(from + (full ? ".show_full" : ".show_images"), isChecked);
2019-09-19 07:00:50 +00:00
}
editor.apply();
}
});
2019-10-05 08:26:56 +00:00
if (full) {
TextView tvDark = dview.findViewById(R.id.tvDark);
tvDark.setVisibility(Helper.isDarkTheme(context) ? View.VISIBLE : View.GONE);
} else {
2019-10-04 21:04:03 +00:00
boolean disable_tracking = prefs.getBoolean("disable_tracking", true);
ImageView ivInfo = dview.findViewById(R.id.ivInfo);
Group grpTracking = dview.findViewById(R.id.grpTracking);
grpTracking.setVisibility(disable_tracking ? View.VISIBLE : View.GONE);
ivInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Helper.viewFAQ(context, 82);
}
});
}
2019-07-01 17:54:37 +00:00
// TODO: dialog fragment
final Dialog dialog = new AlertDialog.Builder(context)
2019-01-30 08:47:54 +00:00
.setView(dview)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
properties.setValue(full ? "full" : "images", message.id, true);
properties.setValue(full ? "full_asked" : "images_asked", message.id, true);
2019-11-04 08:57:38 +00:00
if (full)
2019-10-04 13:25:04 +00:00
onShowFullConfirmed(message);
2019-11-04 08:57:38 +00:00
else
onShowImagesConfirmed(message);
2019-01-30 08:47:54 +00:00
}
})
.setNegativeButton(android.R.string.cancel, null)
.create();
owner.getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
public void onCreate() {
dialog.show();
}
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroyed() {
dialog.dismiss();
}
});
}
2018-10-15 10:05:42 +00:00
2019-10-04 13:25:04 +00:00
private void onShowFullConfirmed(final TupleMessageEx message) {
2019-11-04 09:31:53 +00:00
properties.setSize(message.id, null);
properties.setHeight(message.id, null);
properties.setPosition(message.id, null);
2019-10-04 13:25:04 +00:00
bindBody(message);
}
private void onShowImagesConfirmed(TupleMessageEx message) {
2019-10-04 13:25:04 +00:00
bindBody(message);
2018-10-15 10:05:42 +00:00
}
2019-09-08 10:57:21 +00:00
private void onActionUnsubscribe(TupleMessageEx message) {
Uri uri = Uri.parse(message.unsubscribe);
onOpenLink(uri, context.getString(R.string.title_legend_show_unsubscribe));
}
private void onActionDecrypt(TupleMessageEx message, boolean auto) {
2019-12-04 13:15:58 +00:00
int encrypt = (message.encrypt == null ? EntityMessage.PGP_SIGNENCRYPT /* Inline */ : message.encrypt);
2019-12-05 14:18:53 +00:00
2019-08-14 18:08:24 +00:00
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(FragmentMessages.ACTION_DECRYPT)
.putExtra("id", message.id)
2019-12-02 07:44:50 +00:00
.putExtra("auto", auto)
.putExtra("type", encrypt));
2019-05-04 09:16:33 +00:00
}
2019-08-14 18:08:24 +00:00
private void onActionReplyMenu(TupleMessageEx message) {
Bundle args = new Bundle();
args.putSerializable("message", message);
2019-02-06 18:40:12 +00:00
2019-09-23 11:04:34 +00:00
new SimpleTask<List<TupleIdentityEx>>() {
2019-08-14 18:08:24 +00:00
@Override
2019-09-23 11:04:34 +00:00
protected List<TupleIdentityEx> onExecute(Context context, Bundle args) {
2019-10-02 11:10:39 +00:00
TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");
if (message == null)
return null;
2019-08-14 18:08:24 +00:00
DB db = DB.getInstance(context);
2019-10-02 11:10:39 +00:00
return db.identity().getComposableIdentities(message.account);
2019-08-14 18:08:24 +00:00
}
2019-05-13 20:14:21 +00:00
2019-08-14 18:08:24 +00:00
@Override
2019-09-23 11:04:34 +00:00
protected void onExecuted(Bundle args, List<TupleIdentityEx> identities) {
2019-08-14 18:08:24 +00:00
TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");
2018-12-20 20:12:28 +00:00
2019-08-14 18:08:24 +00:00
TupleMessageEx amessage = getMessage();
if (amessage == null || !amessage.id.equals(message.id))
return;
2019-10-03 12:34:48 +00:00
final Address[] to =
message.replySelf(identities, message.account)
? message.to
: (message.reply == null || message.reply.length == 0 ? message.from : message.reply);
2019-10-02 11:10:39 +00:00
Address[] recipients = message.getAllRecipients(identities, message.account);
2018-12-20 20:12:28 +00:00
2019-08-16 06:12:04 +00:00
View anchor = bnvActions.findViewById(R.id.action_reply);
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, anchor);
2019-09-23 14:25:48 +00:00
popupMenu.inflate(R.menu.popup_reply);
2019-08-14 18:08:24 +00:00
popupMenu.getMenu().findItem(R.id.menu_reply_to_all).setVisible(recipients.length > 0);
popupMenu.getMenu().findItem(R.id.menu_reply_list).setVisible(message.list_post != null);
popupMenu.getMenu().findItem(R.id.menu_reply_receipt).setVisible(message.receipt_to != null);
popupMenu.getMenu().findItem(R.id.menu_reply_answer).setVisible(answers != 0 || !ActivityBilling.isPro(context));
2019-10-03 12:34:48 +00:00
popupMenu.getMenu().findItem(R.id.menu_new_message).setVisible(to != null && to.length > 0);
2018-12-20 20:12:28 +00:00
2019-08-14 18:08:24 +00:00
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem target) {
switch (target.getItemId()) {
case R.id.menu_reply_to_sender:
onMenuReply(message, "reply");
return true;
case R.id.menu_reply_to_all:
onMenuReply(message, "reply_all");
return true;
case R.id.menu_reply_list:
onMenuReply(message, "list");
return true;
case R.id.menu_reply_receipt:
onMenuReply(message, "receipt");
return true;
case R.id.menu_reply_answer:
onMenuAnswer(message);
return true;
2019-08-21 14:51:18 +00:00
case R.id.menu_forward:
onMenuReply(message, "forward");
2019-10-03 12:34:48 +00:00
return true;
case R.id.menu_new_message:
onMenuNew(message, to);
return true;
2019-08-14 18:08:24 +00:00
default:
return false;
}
}
});
popupMenu.show();
}
2019-05-03 07:41:50 +00:00
2019-08-14 18:08:24 +00:00
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-05-02 11:29:05 +00:00
}
2019-08-14 18:08:24 +00:00
}.execute(context, owner, args, "message:reply");
}
2019-05-02 11:29:05 +00:00
2019-08-14 18:08:24 +00:00
private void onMenuReply(TupleMessageEx message, String action) {
Intent reply = new Intent(context, ActivityCompose.class)
.putExtra("action", action)
.putExtra("reference", message.id);
context.startActivity(reply);
2019-08-14 18:08:24 +00:00
}
2019-10-03 12:34:48 +00:00
private void onMenuNew(TupleMessageEx message, Address[] to) {
Intent reply = new Intent(context, ActivityCompose.class)
.putExtra("action", "new")
.putExtra("to", MessageHelper.formatAddresses(to, true, true));
context.startActivity(reply);
}
2019-08-14 18:08:24 +00:00
private void onMenuAnswer(TupleMessageEx message) {
new SimpleTask<List<EntityAnswer>>() {
@Override
protected List<EntityAnswer> onExecute(Context context, Bundle args) {
return DB.getInstance(context).answer().getAnswers(false);
}
2019-08-14 18:08:24 +00:00
@Override
protected void onExecuted(Bundle args, List<EntityAnswer> answers) {
if (answers == null || answers.size() == 0) {
Snackbar snackbar = Snackbar.make(
parentFragment.getView(),
context.getString(R.string.title_no_answers),
Snackbar.LENGTH_LONG);
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
public void onClick(View v) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(new Intent(ActivityView.ACTION_EDIT_ANSWERS));
}
});
snackbar.show();
} else {
2019-08-16 06:12:04 +00:00
View anchor = bnvActions.findViewById(R.id.action_reply);
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, anchor);
2019-02-01 09:02:30 +00:00
2019-08-14 18:08:24 +00:00
int order = 0;
for (EntityAnswer answer : answers)
popupMenu.getMenu().add(Menu.NONE, answer.id.intValue(), order++, answer.name);
2018-12-20 20:12:28 +00:00
2019-08-14 18:08:24 +00:00
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem target) {
if (!ActivityBilling.isPro(context)) {
context.startActivity(new Intent(context, ActivityBilling.class));
2019-08-14 18:08:24 +00:00
return true;
}
2019-02-01 09:02:30 +00:00
context.startActivity(new Intent(context, ActivityCompose.class)
.putExtra("action", "reply")
.putExtra("reference", message.id)
.putExtra("answer", (long) target.getItemId()));
2019-08-14 18:08:24 +00:00
return true;
}
});
2019-08-14 18:08:24 +00:00
popupMenu.show();
}
}
2019-08-14 18:08:24 +00:00
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-08-14 18:08:24 +00:00
}
}.execute(context, owner, new Bundle(), "message:answer");
}
2018-10-15 10:05:42 +00:00
2019-08-14 18:08:24 +00:00
private void onActionArchive(TupleMessageEx message) {
properties.move(message.id, EntityFolder.ARCHIVE);
2019-02-03 18:38:56 +00:00
}
2019-08-14 18:08:24 +00:00
private void onActionMove(TupleMessageEx message, final boolean copy) {
2019-07-06 10:52:00 +00:00
Bundle args = new Bundle();
2019-08-14 18:08:24 +00:00
args.putString("title", context.getString(copy ? R.string.title_copy_to : R.string.title_move_to_folder));
args.putLong("account", message.account);
args.putLongArray("disabled", new long[]{message.folder});
args.putLong("message", message.id);
args.putBoolean("copy", copy);
args.putBoolean("similar", false);
2019-04-19 06:31:00 +00:00
2019-08-14 18:08:24 +00:00
FragmentDialogFolder fragment = new FragmentDialogFolder();
2019-07-06 10:52:00 +00:00
fragment.setArguments(args);
2019-08-14 18:08:24 +00:00
fragment.setTargetFragment(parentFragment, FragmentMessages.REQUEST_MESSAGE_MOVE);
2019-10-12 15:16:53 +00:00
fragment.show(parentFragment.getParentFragmentManager(), "message:move");
2019-07-21 09:54:36 +00:00
}
2019-08-14 18:08:24 +00:00
private void onActionMoveOutbox(TupleMessageEx message) {
2018-10-15 10:05:42 +00:00
Bundle args = new Bundle();
2019-06-28 16:49:50 +00:00
args.putLong("id", message.id);
2018-10-15 10:05:42 +00:00
new SimpleTask<Void>() {
@Override
2018-12-31 07:03:48 +00:00
protected Void onExecute(Context context, Bundle args) {
2018-10-15 10:05:42 +00:00
long id = args.getLong("id");
2019-08-14 18:08:24 +00:00
EntityMessage message;
2018-10-15 10:05:42 +00:00
DB db = DB.getInstance(context);
try {
db.beginTransaction();
2019-08-14 18:08:24 +00:00
message = db.message().getMessage(id);
2019-01-02 18:38:32 +00:00
if (message == null)
return null;
2019-08-14 18:08:24 +00:00
db.folder().setFolderError(message.folder, null);
File source = message.getFile(context);
// Insert into drafts
EntityFolder drafts = db.folder().getFolderByType(message.account, EntityFolder.DRAFTS);
message.id = null;
message.folder = drafts.id;
message.ui_snoozed = null;
message.error = null;
message.id = db.message().insertMessage(message);
File target = message.getFile(context);
source.renameTo(target);
List<EntityAttachment> attachments = db.attachment().getAttachments(id);
for (EntityAttachment attachment : attachments)
db.attachment().setMessage(attachment.id, message.id);
EntityOperation.queue(context, message, EntityOperation.ADD);
// Delete from outbox
db.message().deleteMessage(id); // will delete operation too
2018-10-15 10:05:42 +00:00
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
2019-12-09 18:44:27 +00:00
ServiceSynchronize.eval(context, "outbox/drafts");
2019-12-07 19:32:58 +00:00
2019-08-14 18:08:24 +00:00
if (message.identity != null) {
// Identity can be deleted
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("send:" + message.identity, 1);
}
2018-10-15 10:05:42 +00:00
2019-08-14 18:08:24 +00:00
return null;
2018-10-15 10:05:42 +00:00
}
2018-12-01 09:47:08 +00:00
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2018-12-01 09:47:08 +00:00
}
2019-08-14 18:08:24 +00:00
}.execute(context, owner, args, "message:move:draft");
2018-10-15 10:05:42 +00:00
}
2019-08-14 18:08:24 +00:00
private void onActionMoveJunk(TupleMessageEx message) {
properties.move(message.id, EntityFolder.INBOX);
}
2019-05-15 09:10:47 +00:00
2019-08-14 18:08:24 +00:00
private void onActionDelete(TupleMessageEx message) {
if (delete) {
Bundle aargs = new Bundle();
aargs.putString("question", context.getString(R.string.title_ask_delete));
aargs.putLong("id", message.id);
2019-06-30 14:55:15 +00:00
2019-08-14 18:08:24 +00:00
FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(aargs);
ask.setTargetFragment(parentFragment, FragmentMessages.REQUEST_MESSAGE_DELETE);
2019-10-12 15:16:53 +00:00
ask.show(parentFragment.getParentFragmentManager(), "message:delete");
2019-08-14 18:08:24 +00:00
} else
properties.move(message.id, EntityFolder.TRASH);
2019-05-15 09:10:47 +00:00
}
2019-08-14 18:08:24 +00:00
private void onActionMore(TupleMessageEx message) {
boolean show_headers = properties.getValue("headers", message.id);
2019-01-25 09:01:09 +00:00
2019-08-16 06:12:04 +00:00
View anchor = bnvActions.findViewById(R.id.action_more);
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, anchor);
2019-09-23 14:25:48 +00:00
popupMenu.inflate(R.menu.popup_message_more);
2019-01-25 09:01:09 +00:00
2019-08-14 18:08:24 +00:00
popupMenu.getMenu().findItem(R.id.menu_editasnew).setEnabled(message.content);
2019-01-25 09:01:09 +00:00
popupMenu.getMenu().findItem(R.id.menu_unseen).setTitle(message.ui_seen ? R.string.title_unseen : R.string.title_seen);
2019-09-29 10:03:29 +00:00
popupMenu.getMenu().findItem(R.id.menu_unseen).setEnabled(
2019-11-23 12:48:59 +00:00
(message.uid != null && !message.folderReadOnly) || message.accountProtocol != EntityAccount.TYPE_IMAP);
2019-09-28 07:52:58 +00:00
2019-10-12 09:09:54 +00:00
popupMenu.getMenu().findItem(R.id.menu_hide).setTitle(message.ui_snoozed == null ? R.string.title_hide : R.string.title_unhide);
2019-09-28 08:05:45 +00:00
popupMenu.getMenu().findItem(R.id.menu_flag_color).setEnabled(
2019-11-23 12:48:59 +00:00
(message.uid != null && !message.folderReadOnly) || message.accountProtocol != EntityAccount.TYPE_IMAP);
2019-01-25 09:01:09 +00:00
2019-08-14 18:08:24 +00:00
popupMenu.getMenu().findItem(R.id.menu_copy).setEnabled(message.uid != null && !message.folderReadOnly);
2019-11-23 12:48:59 +00:00
popupMenu.getMenu().findItem(R.id.menu_copy).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP);
2019-09-28 07:52:58 +00:00
2019-12-05 18:53:02 +00:00
popupMenu.getMenu().findItem(R.id.menu_delete).setEnabled(message.uid == null || !message.folderReadOnly);
2019-11-23 12:48:59 +00:00
popupMenu.getMenu().findItem(R.id.menu_delete).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP);
2019-09-28 07:52:58 +00:00
popupMenu.getMenu().findItem(R.id.menu_resync).setEnabled(message.uid != null);
2019-11-23 12:48:59 +00:00
popupMenu.getMenu().findItem(R.id.menu_resync).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP);
2019-09-28 07:52:58 +00:00
2019-11-23 12:48:59 +00:00
popupMenu.getMenu().findItem(R.id.menu_create_rule).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP);
2019-09-28 07:52:58 +00:00
popupMenu.getMenu().findItem(R.id.menu_manage_keywords).setEnabled(message.uid != null && !message.folderReadOnly);
2019-11-23 12:48:59 +00:00
popupMenu.getMenu().findItem(R.id.menu_manage_keywords).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP);
2019-08-14 18:08:24 +00:00
popupMenu.getMenu().findItem(R.id.menu_junk).setEnabled(message.uid != null && !message.folderReadOnly);
popupMenu.getMenu().findItem(R.id.menu_junk).setVisible(hasJunk && !EntityFolder.JUNK.equals(message.folderType));
2019-08-14 18:08:24 +00:00
popupMenu.getMenu().findItem(R.id.menu_share).setEnabled(message.content);
popupMenu.getMenu().findItem(R.id.menu_print).setEnabled(hasWebView && message.content);
popupMenu.getMenu().findItem(R.id.menu_print).setVisible(Helper.canPrint(context));
2019-08-14 18:08:24 +00:00
popupMenu.getMenu().findItem(R.id.menu_show_headers).setChecked(show_headers);
popupMenu.getMenu().findItem(R.id.menu_show_headers).setEnabled(message.uid != null);
2019-11-23 12:48:59 +00:00
popupMenu.getMenu().findItem(R.id.menu_show_headers).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP);
2019-03-11 16:02:40 +00:00
2019-09-09 12:06:43 +00:00
popupMenu.getMenu().findItem(R.id.menu_raw_download).setEnabled(
message.uid != null && (message.raw == null || !message.raw));
popupMenu.getMenu().findItem(R.id.menu_raw_save).setEnabled(
message.uid != null && (message.raw != null && message.raw));
popupMenu.getMenu().findItem(R.id.menu_raw_send).setEnabled(
message.uid != null && (message.raw != null && message.raw));
2019-04-04 15:54:05 +00:00
2019-11-23 12:48:59 +00:00
popupMenu.getMenu().findItem(R.id.menu_raw_download).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP);
popupMenu.getMenu().findItem(R.id.menu_raw_save).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP);
popupMenu.getMenu().findItem(R.id.menu_raw_send).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP);
2019-09-19 15:41:26 +00:00
2019-08-14 18:08:24 +00:00
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
2019-04-04 15:54:05 +00:00
@Override
2019-08-14 18:08:24 +00:00
public boolean onMenuItemClick(MenuItem target) {
switch (target.getItemId()) {
case R.id.menu_editasnew:
onMenuEditAsNew(message);
return true;
case R.id.menu_unseen:
onMenuUnseen(message);
return true;
2019-11-06 09:23:41 +00:00
case R.id.menu_snooze:
onMenuSnooze(message);
return true;
2019-10-12 09:09:54 +00:00
case R.id.menu_hide:
onMenuHide(message);
return true;
2019-08-14 18:08:24 +00:00
case R.id.menu_flag_color:
onMenuColoredStar(message);
return true;
case R.id.menu_copy:
onActionMove(message, true);
return true;
case R.id.menu_delete:
onMenuDelete(message);
return true;
case R.id.menu_junk:
onMenuJunk(message);
return true;
case R.id.menu_resync:
onMenuResync(message);
return true;
case R.id.menu_create_rule:
onMenuCreateRule(message);
return true;
case R.id.menu_manage_keywords:
onMenuManageKeywords(message);
return true;
case R.id.menu_share:
onMenuShare(message);
return true;
case R.id.menu_print:
onMenuPrint(message);
return true;
case R.id.menu_show_headers:
onMenuShowHeaders(message);
return true;
2019-09-09 12:06:43 +00:00
case R.id.menu_raw_download:
onMenuRawDownload(message);
return true;
case R.id.menu_raw_save:
onMenuRawSave(message);
return true;
case R.id.menu_raw_send:
onMenuRawSend(message);
2019-08-14 18:08:24 +00:00
return true;
default:
return false;
}
2019-04-04 15:54:05 +00:00
}
2019-08-14 18:08:24 +00:00
});
popupMenu.show();
2019-04-04 15:54:05 +00:00
}
2019-08-14 18:08:24 +00:00
private class TouchHandler extends ArrowKeyMovementMethod {
private TupleMessageEx message;
2018-10-16 10:56:05 +00:00
2019-08-14 18:08:24 +00:00
TouchHandler(TupleMessageEx message) {
this.message = message;
}
2018-10-16 10:56:05 +00:00
2019-08-14 18:08:24 +00:00
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
int x = (int) event.getX();
int y = (int) event.getY();
2019-01-02 18:38:32 +00:00
2019-08-14 18:08:24 +00:00
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
2019-01-02 18:38:32 +00:00
2019-08-14 18:08:24 +00:00
x += widget.getScrollX();
y += widget.getScrollY();
2019-01-02 18:38:32 +00:00
2019-08-14 18:08:24 +00:00
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
2019-01-02 18:38:32 +00:00
2019-08-14 18:08:24 +00:00
boolean show_images = properties.getValue("images", message.id);
if (!show_images) {
ImageSpan[] image = buffer.getSpans(off, off, ImageSpan.class);
if (image.length > 0 && image[0].getSource() != null) {
2019-10-04 19:25:52 +00:00
ImageHelper.AnnotatedSource a = new ImageHelper.AnnotatedSource(image[0].getSource());
2019-08-14 18:08:24 +00:00
Uri uri = Uri.parse(a.getSource());
if ("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())) {
onOpenLink(uri, null);
return true;
}
2019-01-02 18:38:32 +00:00
}
2018-10-17 18:29:24 +00:00
}
2019-08-14 18:08:24 +00:00
URLSpan[] link = buffer.getSpans(off, off, URLSpan.class);
if (link.length > 0) {
String url = link[0].getURL();
Uri uri = Uri.parse(url);
if (uri.getScheme() == null)
uri = Uri.parse("https://" + url);
2019-08-14 18:08:24 +00:00
int start = buffer.getSpanStart(link[0]);
int end = buffer.getSpanEnd(link[0]);
String title = (start < 0 || end < 0 || end <= start
? null : buffer.subSequence(start, end).toString());
if (url.equals(title))
title = null;
2019-08-14 18:08:24 +00:00
onOpenLink(uri, title);
return true;
}
2019-08-14 18:08:24 +00:00
ImageSpan[] image = buffer.getSpans(off, off, ImageSpan.class);
if (image.length > 0) {
String source = image[0].getSource();
if (source != null) {
onOpenImage(message.id, source);
return true;
}
}
2019-08-14 18:08:24 +00:00
DynamicDrawableSpan[] ddss = buffer.getSpans(off, off, DynamicDrawableSpan.class);
if (ddss.length > 0) {
properties.setValue("quotes", message.id, true);
2019-10-04 13:25:04 +00:00
bindBody(message);
}
2019-08-14 18:08:24 +00:00
}
return super.onTouchEvent(widget, buffer, event);
}
}
private void onOpenLink(final Uri uri, String title) {
Log.i("Opening uri=" + uri);
if (BuildConfig.APPLICATION_ID.equals(uri.getHost()) && "/activate/".equals(uri.getPath())) {
try {
if (ActivityBilling.activatePro(context, uri))
ToastEx.makeText(context, R.string.title_pro_valid, Toast.LENGTH_LONG).show();
else
ToastEx.makeText(context, R.string.title_pro_invalid, Toast.LENGTH_LONG).show();
} catch (NoSuchAlgorithmException ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-08-14 18:08:24 +00:00
}
} else {
2019-08-14 18:08:24 +00:00
if ("cid".equals(uri.getScheme()))
return;
Bundle args = new Bundle();
args.putParcelable("uri", uri);
args.putString("title", title);
FragmentDialogLink fragment = new FragmentDialogLink();
fragment.setArguments(args);
2019-10-12 15:16:53 +00:00
fragment.show(parentFragment.getParentFragmentManager(), "open:link");
}
}
2019-08-14 18:08:24 +00:00
private void onOpenImage(long id, String source) {
Log.i("Viewing image source=" + source);
2018-10-16 10:56:05 +00:00
2019-08-14 18:08:24 +00:00
Bundle args = new Bundle();
args.putLong("id", id);
args.putString("source", source);
2019-11-15 15:08:03 +00:00
args.putInt("zoom", zoom);
2018-10-21 14:53:39 +00:00
2019-08-14 18:08:24 +00:00
FragmentDialogImage fragment = new FragmentDialogImage();
fragment.setArguments(args);
2019-10-12 15:16:53 +00:00
fragment.show(parentFragment.getParentFragmentManager(), "view:image");
2019-08-14 18:08:24 +00:00
}
2018-11-13 19:05:09 +00:00
2019-08-14 18:08:24 +00:00
private void onMenuEditAsNew(final TupleMessageEx message) {
Intent asnew = new Intent(context, ActivityCompose.class)
.putExtra("action", "editasnew")
.putExtra("reference", message.id);
context.startActivity(asnew);
2019-08-14 18:08:24 +00:00
}
2019-08-14 18:08:24 +00:00
private void onMenuUnseen(final TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("id", message.id);
args.putBoolean("seen", !message.ui_seen);
2019-01-25 09:01:09 +00:00
2019-08-14 18:08:24 +00:00
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
boolean seen = args.getBoolean("seen");
2019-01-03 19:31:45 +00:00
2019-08-14 18:08:24 +00:00
DB db = DB.getInstance(context);
try {
db.beginTransaction();
2018-10-21 14:53:39 +00:00
2019-08-14 18:08:24 +00:00
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
EntityOperation.queue(context, message, EntityOperation.SEEN, seen);
2018-11-26 11:42:06 +00:00
2019-08-14 18:08:24 +00:00
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
2018-10-16 10:56:05 +00:00
2019-12-09 18:44:27 +00:00
ServiceSynchronize.eval(context, "seen");
2019-12-07 19:32:58 +00:00
2019-08-14 18:08:24 +00:00
return null;
}
2019-04-04 15:54:05 +00:00
2018-10-17 18:29:24 +00:00
@Override
2019-08-14 18:08:24 +00:00
protected void onExecuted(Bundle args, Void ignored) {
boolean seen = args.getBoolean("seen");
if (!seen)
properties.setValue("expanded", message.id, false);
2019-08-14 18:08:24 +00:00
notifyDataSetChanged();
2018-10-17 18:29:24 +00:00
}
2019-08-14 18:08:24 +00:00
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-08-14 18:08:24 +00:00
}
}.execute(context, owner, args, "message:unseen");
2018-10-16 10:56:05 +00:00
}
2019-11-06 09:23:41 +00:00
private void onMenuSnooze(final TupleMessageEx message) {
Bundle args = new Bundle();
args.putString("title", context.getString(R.string.title_snooze));
args.putLong("account", message.account);
args.putString("thread", message.thread);
args.putLong("id", message.id);
args.putBoolean("finish", true);
FragmentDialogDuration fragment = new FragmentDialogDuration();
fragment.setArguments(args);
fragment.setTargetFragment(parentFragment, FragmentMessages.REQUEST_MESSAGE_SNOOZE);
fragment.show(parentFragment.getParentFragmentManager(), "message:snooze");
}
2019-10-12 09:09:54 +00:00
private void onMenuHide(final TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("id", message.id);
args.putBoolean("hide", message.ui_snoozed == null);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
boolean hide = args.getBoolean("hide");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
db.message().setMessageSnoozed(message.id, hide ? Long.MAX_VALUE : null);
2019-11-04 08:00:14 +00:00
db.message().setMessageUiIgnored(message.id, true);
2019-10-12 09:09:54 +00:00
EntityMessage.snooze(context, message.id, hide ? Long.MAX_VALUE : null);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-10-12 09:09:54 +00:00
}
}.execute(context, owner, args, "message:hide");
}
2019-08-14 18:08:24 +00:00
private void onMenuColoredStar(final TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("id", message.id);
2019-09-29 14:31:13 +00:00
args.putInt("color", message.color == null ? Color.TRANSPARENT : message.color);
args.putString("title", context.getString(R.string.title_flag_color));
2019-08-14 18:08:24 +00:00
FragmentDialogColor fragment = new FragmentDialogColor();
2019-09-29 14:31:13 +00:00
fragment.setArguments(args);
2019-08-14 18:08:24 +00:00
fragment.setTargetFragment(parentFragment, FragmentMessages.REQUEST_MESSAGE_COLOR);
2019-10-12 15:16:53 +00:00
fragment.show(parentFragment.getParentFragmentManager(), "message:color");
2018-10-15 10:05:42 +00:00
}
2019-08-14 18:08:24 +00:00
private void onMenuDelete(final TupleMessageEx message) {
2019-09-22 19:07:51 +00:00
Bundle aargs = new Bundle();
aargs.putString("question", context.getString(R.string.title_ask_delete));
aargs.putLong("id", message.id);
2019-08-14 18:08:24 +00:00
2019-09-22 19:07:51 +00:00
FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(aargs);
ask.setTargetFragment(parentFragment, FragmentMessages.REQUEST_MESSAGE_DELETE);
2019-10-12 15:16:53 +00:00
ask.show(parentFragment.getParentFragmentManager(), "message:delete");
2019-08-14 18:08:24 +00:00
}
private void onMenuJunk(final TupleMessageEx message) {
String who = MessageHelper.formatAddresses(message.from);
Bundle aargs = new Bundle();
aargs.putString("question", context.getString(R.string.title_ask_spam_who, who));
aargs.putLong("id", message.id);
FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(aargs);
ask.setTargetFragment(parentFragment, FragmentMessages.REQUEST_MESSAGE_JUNK);
2019-10-12 15:16:53 +00:00
ask.show(parentFragment.getParentFragmentManager(), "message:junk");
2018-10-15 10:05:42 +00:00
}
2019-08-14 18:08:24 +00:00
private void onMenuResync(TupleMessageEx message) {
2019-05-25 15:37:01 +00:00
Bundle args = new Bundle();
2019-08-14 18:08:24 +00:00
args.putLong("id", message.id);
2019-05-25 15:37:01 +00:00
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
2019-08-14 18:08:24 +00:00
EntityMessage message = db.message().getMessage(id);
if (message == null || message.uid == null)
2019-05-25 15:37:01 +00:00
return null;
2019-11-02 16:03:36 +00:00
EntityFolder folder = db.folder().getFolder(message.folder);
if (folder == null)
return null;
2019-08-14 18:08:24 +00:00
db.message().deleteMessage(id);
2019-05-25 15:37:01 +00:00
2019-11-02 16:03:36 +00:00
EntityOperation.queue(context, folder, EntityOperation.FETCH, message.uid);
2019-05-25 15:37:01 +00:00
2019-08-14 18:08:24 +00:00
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
2019-05-25 15:37:01 +00:00
2019-12-09 18:44:27 +00:00
ServiceSynchronize.eval(context, "resync");
2019-12-07 19:32:58 +00:00
2019-08-14 18:08:24 +00:00
return null;
}
2019-05-25 15:37:01 +00:00
2019-08-14 18:08:24 +00:00
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-08-14 18:08:24 +00:00
}
}.execute(context, owner, args, "message:share");
}
2019-05-25 15:37:01 +00:00
2019-08-14 18:08:24 +00:00
private void onMenuCreateRule(TupleMessageEx message) {
Intent rule = new Intent(ActivityView.ACTION_EDIT_RULE);
rule.putExtra("account", message.account);
rule.putExtra("folder", message.folder);
if (message.from != null && message.from.length > 0)
rule.putExtra("sender", ((InternetAddress) message.from[0]).getAddress());
if (message.to != null && message.to.length > 0)
rule.putExtra("recipient", ((InternetAddress) message.to[0]).getAddress());
if (!TextUtils.isEmpty(message.subject))
rule.putExtra("subject", message.subject);
2019-05-25 15:37:01 +00:00
2019-08-14 18:08:24 +00:00
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(rule);
}
private void onMenuManageKeywords(TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("id", message.id);
args.putStringArray("keywords", message.keywords);
new SimpleTask<EntityFolder>() {
@Override
protected EntityFolder onExecute(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
2019-05-25 15:37:01 +00:00
2019-08-14 18:08:24 +00:00
return db.folder().getFolder(message.folder);
}
2019-05-25 15:37:01 +00:00
2019-08-14 18:08:24 +00:00
@Override
protected void onExecuted(final Bundle args, EntityFolder folder) {
if (folder == null)
return;
2019-05-25 15:37:01 +00:00
2019-08-14 18:08:24 +00:00
args.putStringArray("fkeywords", folder.keywords);
2019-05-25 15:37:01 +00:00
2019-08-14 18:08:24 +00:00
FragmentKeywordManage fragment = new FragmentKeywordManage();
fragment.setArguments(args);
2019-10-12 15:16:53 +00:00
fragment.show(parentFragment.getParentFragmentManager(), "keyword:manage");
2019-05-25 15:37:01 +00:00
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-05-25 15:37:01 +00:00
}
2019-08-14 18:08:24 +00:00
}.execute(context, owner, args, "message:keywords");
2019-05-25 15:37:01 +00:00
}
2019-08-14 18:08:24 +00:00
private void onMenuShare(TupleMessageEx message) {
2019-05-29 12:09:54 +00:00
Bundle args = new Bundle();
2019-08-14 18:08:24 +00:00
args.putLong("id", message.id);
2019-05-29 07:14:56 +00:00
2019-08-14 18:08:24 +00:00
new SimpleTask<String[]>() {
2019-05-29 12:09:54 +00:00
@Override
2019-08-14 18:08:24 +00:00
protected String[] onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
2019-05-22 14:21:04 +00:00
2019-05-29 12:09:54 +00:00
DB db = DB.getInstance(context);
2019-08-14 18:08:24 +00:00
EntityMessage message = db.message().getMessage(id);
if (message == null || !message.content)
return null;
2019-03-02 08:48:02 +00:00
2019-08-14 18:08:24 +00:00
File file = message.getFile(context);
if (!file.exists())
return null;
2019-05-29 12:09:54 +00:00
2019-08-14 18:08:24 +00:00
String from = null;
if (message.from != null && message.from.length > 0)
from = ((InternetAddress) message.from[0]).getAddress();
2019-05-29 12:09:54 +00:00
2019-12-03 14:39:45 +00:00
String text = HtmlHelper.getText(Helper.readText(file));
2019-05-29 12:09:54 +00:00
2019-12-03 14:39:45 +00:00
return new String[]{from, message.subject, text};
2019-08-14 18:08:24 +00:00
}
@Override
protected void onExecuted(Bundle args, String[] text) {
if (text == null)
2019-05-29 12:09:54 +00:00
return;
2019-08-14 18:08:24 +00:00
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setType("text/plain");
if (!TextUtils.isEmpty(text[0]))
share.putExtra(Intent.EXTRA_EMAIL, new String[]{text[0]});
if (!TextUtils.isEmpty(text[1]))
share.putExtra(Intent.EXTRA_SUBJECT, text[1]);
if (!TextUtils.isEmpty(text[2]))
share.putExtra(Intent.EXTRA_TEXT, text[2]);
2019-05-29 12:09:54 +00:00
2019-08-14 18:08:24 +00:00
PackageManager pm = context.getPackageManager();
if (share.resolveActivity(pm) == null)
Snackbar.make(parentFragment.getView(),
2019-12-03 14:39:45 +00:00
context.getString(R.string.title_no_viewer, share.getAction()),
Snackbar.LENGTH_LONG).
show();
2019-08-14 18:08:24 +00:00
else
2019-12-03 14:39:45 +00:00
context.startActivity(Helper.getChooser(context, share));
2019-03-02 08:48:02 +00:00
}
2019-05-29 12:09:54 +00:00
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-05-29 12:09:54 +00:00
}
2019-08-14 18:08:24 +00:00
}.execute(context, owner, args, "message:share");
2019-03-02 08:48:02 +00:00
}
2019-08-14 18:08:24 +00:00
private void onMenuPrint(TupleMessageEx message) {
2019-12-02 18:41:27 +00:00
Bundle args = new Bundle();
args.putLong("id", message.id);
args.putBoolean("headers", properties.getValue("headers", message.id));
2019-08-14 18:08:24 +00:00
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (prefs.getBoolean("print_html_confirmed", false)) {
Intent data = new Intent();
data.putExtra("args", args);
parentFragment.onActivityResult(FragmentMessages.REQUEST_PRINT, RESULT_OK, data);
return;
}
2019-12-02 18:41:27 +00:00
args.putString("question", context.getString(R.string.title_ask_show_html));
args.putString("notagain", "print_html_confirmed");
2019-08-14 18:08:24 +00:00
FragmentDialogAsk ask = new FragmentDialogAsk();
2019-12-02 18:41:27 +00:00
ask.setArguments(args);
2019-08-14 18:08:24 +00:00
ask.setTargetFragment(parentFragment, FragmentMessages.REQUEST_PRINT);
2019-10-12 15:16:53 +00:00
ask.show(parentFragment.getParentFragmentManager(), "message:print");
}
2018-10-24 09:09:07 +00:00
2019-08-14 18:08:24 +00:00
private void onMenuShowHeaders(TupleMessageEx message) {
boolean show_headers = !properties.getValue("headers", message.id);
properties.setValue("headers", message.id, show_headers);
if (show_headers && message.headers == null) {
grpHeaders.setVisibility(View.VISIBLE);
if (suitable)
pbHeaders.setVisibility(View.VISIBLE);
else
tvNoInternetHeaders.setVisibility(View.VISIBLE);
2019-03-02 08:48:02 +00:00
2019-08-14 18:08:24 +00:00
Bundle args = new Bundle();
args.putLong("id", message.id);
2019-03-02 08:48:02 +00:00
2019-08-14 18:08:24 +00:00
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
Long id = args.getLong("id");
2019-03-02 08:48:02 +00:00
2019-08-14 18:08:24 +00:00
DB db = DB.getInstance(context);
try {
db.beginTransaction();
2019-08-14 18:08:24 +00:00
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
2019-03-02 08:48:02 +00:00
2019-08-14 18:08:24 +00:00
EntityOperation.queue(context, message, EntityOperation.HEADERS);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
2019-12-07 19:32:58 +00:00
2019-12-09 18:44:27 +00:00
ServiceSynchronize.eval(context, "headers");
2019-12-07 19:32:58 +00:00
2019-08-14 18:08:24 +00:00
return null;
2019-03-02 08:48:02 +00:00
}
2019-08-14 18:08:24 +00:00
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-08-14 18:08:24 +00:00
}
}.execute(context, owner, args, "message:headers");
} else
notifyDataSetChanged();
}
2019-09-09 12:06:43 +00:00
private void onMenuRawDownload(TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("id", message.id);
2019-08-14 18:08:24 +00:00
2019-09-09 12:06:43 +00:00
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
Long id = args.getLong("id");
2019-08-14 18:08:24 +00:00
2019-09-09 12:06:43 +00:00
DB db = DB.getInstance(context);
try {
db.beginTransaction();
2019-08-14 18:08:24 +00:00
2019-09-09 12:06:43 +00:00
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
2019-08-14 18:08:24 +00:00
2019-09-09 12:06:43 +00:00
EntityOperation.queue(context, message, EntityOperation.RAW);
2019-08-14 18:08:24 +00:00
2019-09-09 12:06:43 +00:00
db.message().setMessageRaw(message.id, false);
2019-08-14 18:08:24 +00:00
2019-09-09 12:06:43 +00:00
db.setTransactionSuccessful();
} finally {
db.endTransaction();
2019-08-14 18:08:24 +00:00
}
2019-12-07 19:32:58 +00:00
2019-12-09 18:44:27 +00:00
ServiceSynchronize.eval(context, "raw");
2019-12-07 19:32:58 +00:00
2019-09-09 12:06:43 +00:00
return null;
}
2019-08-14 18:08:24 +00:00
2019-09-09 12:06:43 +00:00
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
2019-09-09 12:06:43 +00:00
}
}.execute(context, owner, args, "message:raw");
}
private void onMenuRawSave(TupleMessageEx message) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(FragmentMessages.ACTION_STORE_RAW)
.putExtra("id", message.id));
}
private void onMenuRawSend(TupleMessageEx message) {
File file = message.getRawFile(context);
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
Intent send = new Intent(Intent.ACTION_SEND);
send.putExtra(Intent.EXTRA_STREAM, uri);
send.setType("message/rfc822");
2019-12-13 08:32:18 +00:00
send.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(send);
2019-03-02 08:48:02 +00:00
}
2018-10-24 09:09:07 +00:00
ItemDetailsLookup.ItemDetails<Long> getItemDetails(@NonNull MotionEvent motionEvent) {
2018-12-03 12:18:23 +00:00
return new ItemDetailsMessage(this);
}
Long getKey() {
return getKeyAtPosition(getAdapterPosition());
2018-10-24 09:09:07 +00:00
}
2018-08-02 13:33:06 +00:00
}
AdapterMessage(Fragment parentFragment,
2019-07-19 06:27:44 +00:00
String type, ViewType viewType,
2019-09-03 08:33:52 +00:00
boolean compact, int zoom, String sort, boolean ascending, boolean filter_duplicates,
final IProperties properties) {
2019-06-30 14:55:15 +00:00
this.parentFragment = parentFragment;
2019-07-19 06:27:44 +00:00
this.type = type;
2018-08-02 13:33:06 +00:00
this.viewType = viewType;
2019-01-15 17:39:12 +00:00
this.compact = compact;
2018-12-30 16:33:52 +00:00
this.zoom = zoom;
2019-01-21 18:12:22 +00:00
this.sort = sort;
2019-09-03 08:33:52 +00:00
this.ascending = ascending;
2019-04-28 13:16:26 +00:00
this.filter_duplicates = filter_duplicates;
this.properties = properties;
this.context = parentFragment.getContext();
this.owner = parentFragment.getViewLifecycleOwner();
this.inflater = LayoutInflater.from(context);
this.TF = Helper.getTimeInstance(context, SimpleDateFormat.SHORT);
2019-07-15 19:28:25 +00:00
this.DTF = Helper.getDateTimeInstance(context, SimpleDateFormat.LONG, SimpleDateFormat.LONG);
ConnectionHelper.NetworkState state = ConnectionHelper.getNetworkState(context);
this.suitable = state.isSuitable();
this.unmetered = state.isUnmetered();
this.dp36 = Helper.dp2pixels(context, 36);
this.colorPrimary = Helper.resolveColor(context, R.attr.colorPrimary);
this.colorAccent = Helper.resolveColor(context, R.attr.colorAccent);
this.textColorPrimary = Helper.resolveColor(context, android.R.attr.textColorPrimary);
this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean highlight_unread = prefs.getBoolean("highlight_unread", false);
2019-10-07 11:07:26 +00:00
this.colorUnread = Helper.resolveColor(context, highlight_unread ? R.attr.colorUnreadHighlight : R.attr.colorUnread);
this.colorRead = Helper.resolveColor(context, R.attr.colorRead);
2019-10-02 12:07:55 +00:00
this.colorSeparator = Helper.resolveColor(context, R.attr.colorSeparator);
this.hasWebView = Helper.hasWebView(context);
2019-02-07 09:02:40 +00:00
this.contacts = Helper.hasPermission(context, Manifest.permission.READ_CONTACTS);
this.textSize = Helper.getTextSize(context, zoom);
2019-10-09 11:24:16 +00:00
boolean contacts = Helper.hasPermission(context, Manifest.permission.READ_CONTACTS);
boolean avatars = prefs.getBoolean("avatars", true);
boolean generated = prefs.getBoolean("generated_icons", true);
this.date = prefs.getBoolean("date", true);
this.threading = prefs.getBoolean("threading", true);
2019-10-09 11:24:16 +00:00
this.avatars = (contacts && avatars) || generated;
2019-08-25 09:14:16 +00:00
this.name_email = prefs.getBoolean("name_email", false);
2019-10-03 08:19:27 +00:00
this.distinguish_contacts = prefs.getBoolean("distinguish_contacts", false);
2019-11-18 09:39:32 +00:00
this.subject_top = prefs.getBoolean("subject_top", false);
int fz_sender = prefs.getInt("font_size_sender", -1);
if (fz_sender >= 0)
font_size_sender = Helper.getTextSize(context, fz_sender);
int fz_subject = prefs.getInt("font_size_subject", -1);
if (fz_subject >= 0)
font_size_subject = Helper.getTextSize(context, fz_subject);
this.subject_italic = prefs.getBoolean("subject_italic", true);
this.subject_ellipsize = prefs.getString("subject_ellipsize", "middle");
2019-03-02 15:54:38 +00:00
this.flags = prefs.getBoolean("flags", true);
this.flags_background = prefs.getBoolean("flags_background", false);
2018-11-04 12:42:41 +00:00
this.preview = prefs.getBoolean("preview", false);
this.preview_italic = prefs.getBoolean("preview_italic", true);
this.preview_lines = prefs.getInt("preview_lines", 2);
this.attachments_alt = prefs.getBoolean("attachments_alt", false);
this.contrast = prefs.getBoolean("contrast", false);
this.monospaced = prefs.getBoolean("monospaced", false);
2019-10-04 13:25:04 +00:00
this.inline = prefs.getBoolean("inline_images", false);
this.collapse_quotes = prefs.getBoolean("collapse_quotes", false);
this.authentication = prefs.getBoolean("authentication", true);
2019-07-11 18:16:58 +00:00
debug = prefs.getBoolean("debug", false);
2019-05-04 08:24:42 +00:00
AsyncDifferConfig<TupleMessageEx> config = new AsyncDifferConfig.Builder<>(DIFF_CALLBACK)
.setBackgroundThreadExecutor(executor)
.build();
this.differ = new AsyncPagedListDiffer<>(new AdapterListUpdateCallback(this), config);
2019-05-04 08:24:42 +00:00
this.differ.addPagedListListener(new AsyncPagedListDiffer.PagedListListener<TupleMessageEx>() {
@Override
public void onCurrentListChanged(@Nullable PagedList<TupleMessageEx> previousList, @Nullable PagedList<TupleMessageEx> currentList) {
2019-11-17 13:47:13 +00:00
if (gotoTop) {
2019-05-15 11:37:35 +00:00
gotoTop = false;
2019-05-04 08:24:42 +00:00
properties.scrollTo(0);
}
}
});
2019-09-24 09:21:31 +00:00
try {
// https://issuetracker.google.com/issues/135628748
Handler handler = new Handler(Looper.getMainLooper());
Field mMainThreadExecutor = this.differ.getClass().getDeclaredField("mMainThreadExecutor");
mMainThreadExecutor.setAccessible(true);
mMainThreadExecutor.set(this.differ, new Executor() {
@Override
2019-10-07 06:53:12 +00:00
public void execute(final Runnable command) {
handler.post(new Runnable() {
@Override
public void run() {
try {
command.run();
} catch (Throwable ex) {
Log.e(ex);
}
}
});
2019-09-24 09:21:31 +00:00
}
});
} catch (Throwable ex) {
Log.e(ex);
}
owner.getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroyed() {
2019-12-07 16:02:42 +00:00
Log.d(AdapterMessage.this + " parent destroyed");
AdapterMessage.this.parentFragment = null;
}
});
2018-08-02 13:33:06 +00:00
}
2019-05-15 11:37:35 +00:00
void gotoTop() {
properties.scrollTo(0);
this.gotoTop = true;
}
void submitList(PagedList<TupleMessageEx> list) {
2019-08-11 14:08:53 +00:00
keyPosition.clear();
2019-01-29 11:38:38 +00:00
differ.submitList(list);
2019-01-20 13:27:35 +00:00
}
2018-12-03 07:21:02 +00:00
PagedList<TupleMessageEx> getCurrentList() {
return differ.getCurrentList();
}
2019-01-15 17:39:12 +00:00
void setCompact(boolean compact) {
if (this.compact != compact) {
this.compact = compact;
notifyDataSetChanged();
}
}
2018-12-13 18:26:27 +00:00
void setZoom(int zoom) {
2018-12-30 16:33:52 +00:00
if (this.zoom != zoom) {
this.zoom = zoom;
textSize = Helper.getTextSize(context, zoom);
notifyDataSetChanged();
}
2018-12-13 18:26:27 +00:00
}
2019-01-21 18:12:22 +00:00
2019-04-04 08:11:24 +00:00
int getZoom() {
return this.zoom;
}
2019-01-21 18:12:22 +00:00
void setSort(String sort) {
if (!sort.equals(this.sort)) {
this.sort = sort;
2019-04-11 10:50:09 +00:00
notifyDataSetChanged();
// Needed to redraw item decorators / add/remove size
2019-01-21 18:12:22 +00:00
}
}
2018-12-13 18:26:27 +00:00
2019-04-04 08:11:24 +00:00
String getSort() {
return this.sort;
}
2019-09-03 08:33:52 +00:00
void setAscending(boolean ascending) {
this.ascending = ascending;
}
2019-04-28 13:16:26 +00:00
void setFilterDuplicates(boolean filter_duplicates) {
if (this.filter_duplicates != filter_duplicates) {
this.filter_duplicates = filter_duplicates;
notifyDataSetChanged();
}
}
void checkInternet() {
ConnectionHelper.NetworkState state = ConnectionHelper.getNetworkState(context);
if (this.suitable != state.isSuitable() || this.unmetered != state.isUnmetered()) {
this.suitable = state.isSuitable();
this.unmetered = state.isUnmetered();
notifyDataSetChanged();
}
}
2019-05-21 13:43:17 +00:00
void setAnswerCount(int answers) {
this.answers = answers;
Log.i("Answer count=" + answers);
}
2018-12-03 07:21:02 +00:00
@Override
public int getItemCount() {
return differ.getItemCount();
}
2018-08-12 16:14:20 +00:00
private static final DiffUtil.ItemCallback<TupleMessageEx> DIFF_CALLBACK =
2018-08-07 06:38:00 +00:00
new DiffUtil.ItemCallback<TupleMessageEx>() {
@Override
public boolean areItemsTheSame(
@NonNull TupleMessageEx prev, @NonNull TupleMessageEx next) {
return prev.id.equals(next.id);
}
2018-08-02 13:33:06 +00:00
2018-08-07 06:38:00 +00:00
@Override
public boolean areContentsTheSame(
@NonNull TupleMessageEx prev, @NonNull TupleMessageEx next) {
2019-06-25 07:46:31 +00:00
boolean same = true;
// id
// account
// folder
if (!Objects.equals(prev.identity, next.identity)) {
// via
same = false;
Log.i("Entity changed id=" + next.id);
}
// extra
if (!Objects.equals(prev.uid, next.uid)) {
same = false;
Log.i("uid changed id=" + next.id);
}
if (!Objects.equals(prev.msgid, next.msgid)) {
// debug info
same = false;
Log.i("msgid changed id=" + next.id);
}
// references
// deliveredto
// inreplyto
if (!Objects.equals(prev.thread, next.thread)) {
same = false;
Log.i("thread changed id=" + next.id);
}
2019-10-05 10:42:04 +00:00
if (!Objects.equals(prev.priority, next.priority)) {
same = false;
Log.i("priority changed id=" + next.id);
}
if (!Objects.equals(prev.receipt_request, next.receipt_request)) {
same = false;
Log.i("receipt_request changed id=" + next.id);
}
2019-06-25 07:46:31 +00:00
if (!MessageHelper.equal(prev.receipt_to, next.receipt_to)) {
same = false;
Log.i("receipt_to changed id=" + next.id);
}
if (!Objects.equals(prev.dkim, next.dkim)) {
same = false;
Log.i("dkim changed id=" + next.id);
}
if (!Objects.equals(prev.spf, next.spf)) {
same = false;
Log.i("spf changed id=" + next.id);
}
if (!Objects.equals(prev.dmarc, next.dmarc)) {
same = false;
Log.i("dmarc changed id=" + next.id);
}
if (!Objects.equals(prev.mx, next.mx)) {
same = false;
Log.i("mx changed id=" + next.id);
}
2019-06-25 07:46:31 +00:00
if (!Objects.equals(prev.avatar, next.avatar)) {
same = false;
Log.i("avatar changed id=" + next.id);
}
if (!Objects.equals(prev.sender, next.sender)) {
same = false;
Log.i("sender changed id=" + next.id);
}
if (!MessageHelper.equal(prev.from, next.from)) {
same = false;
Log.i("from changed id=" + next.id);
}
if (!MessageHelper.equal(prev.to, next.to)) {
same = false;
Log.i("to changed id=" + next.id);
}
if (!MessageHelper.equal(prev.cc, next.cc)) {
same = false;
Log.i("cc changed id=" + next.id);
}
if (!MessageHelper.equal(prev.bcc, next.bcc)) {
same = false;
Log.i("bcc changed id=" + next.id);
}
if (!MessageHelper.equal(prev.reply, next.reply)) {
same = false;
Log.i("reply changed id=" + next.id);
}
if (!MessageHelper.equal(prev.list_post, next.list_post)) {
same = false;
Log.i("list_post changed id=" + next.id);
}
if (!Objects.equals(prev.headers, next.headers)) {
same = false;
Log.i("headers changed id=" + next.id);
}
if (!Objects.equals(prev.raw, next.raw)) {
same = false;
Log.i("raw changed id=" + next.id);
}
if (!Objects.equals(prev.subject, next.subject)) {
same = false;
Log.i("subject changed id=" + next.id);
}
if (!Objects.equals(prev.size, next.size)) {
same = false;
Log.i("size changed id=" + next.id);
}
2019-09-30 19:00:28 +00:00
if (!Objects.equals(prev.total, next.total)) {
same = false;
Log.i("total changed id=" + next.id);
}
if (!Objects.equals(prev.attachments, next.attachments)) {
same = false;
Log.i("attachments changed id=" + next.id);
}
2019-06-25 07:46:31 +00:00
if (!prev.content.equals(next.content)) {
same = false;
Log.i("content changed id=" + next.id);
}
2019-10-05 10:42:04 +00:00
if (!Objects.equals(prev.plain_only, next.plain_only)) {
same = false;
Log.i("plain_only changed id=" + next.id);
}
2019-06-25 07:46:31 +00:00
if (!Objects.equals(prev.preview, next.preview)) {
same = false;
Log.i("preview changed id=" + next.id);
}
2019-06-25 12:25:56 +00:00
if (!Objects.equals(prev.sent, next.sent)) {
2019-06-25 07:46:31 +00:00
same = false;
Log.i("sent changed id=" + next.id);
}
if (!prev.received.equals(next.received)) {
same = false;
Log.i("received changed id=" + next.id);
}
if (!prev.stored.equals(next.stored)) {
// updated after decryption
same = false;
Log.i("stored changed id=" + next.id);
}
// seen
// answered
// flagged
if (debug && !Objects.equals(prev.flags, next.flags)) {
same = false;
Log.i("flags changed id=" + next.id);
}
if (!Helper.equal(prev.keywords, next.keywords)) {
same = false;
Log.i("keywords changed id=" + next.id);
}
2019-10-05 10:42:04 +00:00
// notifying
2019-06-25 07:46:31 +00:00
if (!prev.ui_seen.equals(next.ui_seen)) {
same = false;
Log.i("ui_seen changed id=" + next.id);
}
if (!prev.ui_answered.equals(next.ui_answered)) {
same = false;
Log.i("ui_answer changed id=" + next.id);
}
if (!prev.ui_flagged.equals(next.ui_flagged)) {
same = false;
Log.i("ui_flagged changed id=" + next.id);
}
if (!prev.ui_hide.equals(next.ui_hide)) {
same = false;
Log.i("ui_hide changed id=" + next.id);
}
if (!prev.ui_found.equals(next.ui_found)) {
same = false;
Log.i("ui_found changed id=" + next.id);
}
// ui_ignored
if (!prev.ui_browsed.equals(next.ui_browsed)) {
same = false;
Log.i("ui_browsed changed id=" + next.id);
}
if (!Objects.equals(prev.ui_snoozed, next.ui_snoozed)) {
same = false;
Log.i("ui_snoozed changed id=" + next.id);
}
if (!Objects.equals(prev.color, next.color)) {
same = false;
Log.i("color changed id=" + next.id);
}
// revision
// revisions
if (!Objects.equals(prev.warning, next.warning)) {
same = false;
Log.i("warning changed id=" + next.id);
}
if (!Objects.equals(prev.error, next.error)) {
same = false;
Log.i("error changed id=" + next.id);
}
// last_attempt
2019-10-05 10:42:04 +00:00
// accountPop
2019-06-25 07:46:31 +00:00
if (!Objects.equals(prev.accountName, next.accountName)) {
same = false;
Log.i("accountName changed id=" + next.id);
}
if (!Objects.equals(prev.accountColor, next.accountColor)) {
same = false;
Log.i("accountColor changed id=" + next.id);
}
// accountNotify
2019-10-05 10:42:04 +00:00
// accountAutoSeen
2019-06-25 07:46:31 +00:00
if (!prev.folderName.equals(next.folderName)) {
same = false;
Log.i("folderName changed id=" + next.id);
}
if (!Objects.equals(prev.folderDisplay, next.folderDisplay)) {
same = false;
Log.i("folderDisplay changed id=" + next.id);
}
if (!prev.folderType.equals(next.folderType)) {
same = false;
Log.i("folderType changed id=" + next.id);
}
2019-12-05 19:05:07 +00:00
if (prev.folderReadOnly != next.folderReadOnly) {
same = false;
Log.i("folderReadOnly changed id=" + next.id);
}
2019-06-25 07:46:31 +00:00
if (!Objects.equals(prev.identityName, next.identityName)) {
same = false;
Log.i("identityName changed id=" + next.id);
}
if (!Objects.equals(prev.identityEmail, next.identityEmail)) {
same = false;
Log.i("identityEmail changed id=" + next.id);
}
if (!Objects.equals(prev.identitySynchronize, next.identitySynchronize)) {
same = false;
Log.i("identitySynchronize changed id=" + next.id);
}
2019-10-05 10:42:04 +00:00
// senders
2019-06-25 07:46:31 +00:00
if (prev.count != next.count) {
same = false;
Log.i("count changed id=" + next.id);
}
if (prev.unseen != next.unseen) {
same = false;
Log.i("unseen changed id=" + next.id);
}
if (prev.unflagged != next.unflagged) {
same = false;
Log.i("unflagged changed id=" + next.id);
}
if (prev.drafts != next.drafts) {
same = false;
Log.i("drafts changed id=" + next.id);
}
2019-11-27 09:40:43 +00:00
if (prev.signed != next.signed) {
same = false;
Log.i("signed changed id=" + next.id);
}
2019-11-17 11:16:06 +00:00
if (prev.encrypted != next.encrypted) {
same = false;
Log.i("encrypted changed id=" + next.id);
}
2019-06-25 07:46:31 +00:00
if (prev.visible != next.visible) {
same = false;
Log.i("visible changed id=" + next.id);
}
if (!Objects.equals(prev.totalSize, next.totalSize)) {
same = false;
Log.i("totalSize changed id=" + next.id);
}
if (prev.duplicate != next.duplicate) {
same = false;
Log.i("duplicate changed id=" + next.id);
}
return same;
2018-08-07 06:38:00 +00:00
}
};
2018-08-02 13:33:06 +00:00
2019-10-11 09:22:30 +00:00
@Override
public int getItemViewType(int position) {
TupleMessageEx message = differ.getItem(position);
if (message == null || context == null)
return R.layout.item_message_placeholder;
if (filter_duplicates && message.duplicate)
return R.layout.item_message_duplicate;
return (compact ? R.layout.item_message_compact : R.layout.item_message_normal);
}
2018-08-02 13:33:06 +00:00
@Override
@NonNull
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
2019-01-15 17:39:12 +00:00
return new ViewHolder(inflater.inflate(viewType, parent, false));
2018-08-02 13:33:06 +00:00
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
2019-10-01 11:56:48 +00:00
TupleMessageEx message = differ.getItem(position);
2019-10-11 09:22:30 +00:00
2019-10-11 07:02:41 +00:00
if (message == null || context == null)
return;
2019-10-12 13:40:13 +00:00
if (viewType == ViewType.THREAD) {
boolean outgoing = holder.isOutgoing(message);
holder.card.setOutgoing(outgoing);
}
2019-10-11 07:02:41 +00:00
if (filter_duplicates && message.duplicate) {
2019-10-01 11:56:48 +00:00
holder.tvFolder.setText(context.getString(R.string.title_duplicate_in, message.getFolderName(context)));
2019-10-04 14:16:44 +00:00
holder.tvFolder.setTypeface(message.unseen > 0 ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
2019-10-07 11:07:26 +00:00
holder.tvFolder.setTextColor(message.unseen > 0 ? colorUnread : colorRead);
2019-10-01 11:56:48 +00:00
holder.tvFolder.setAlpha(Helper.LOW_LIGHT);
return;
}
2018-08-02 13:33:06 +00:00
holder.unwire();
2019-10-11 07:02:41 +00:00
holder.bindTo(message);
holder.wire();
2018-08-02 13:33:06 +00:00
}
2019-04-11 14:54:00 +00:00
@Override
2019-09-21 18:28:03 +00:00
public void onViewDetachedFromWindow(@NonNull ViewHolder holder) {
2019-04-13 06:02:01 +00:00
holder.cowner.stop();
2019-05-03 16:59:27 +00:00
holder.powner.recreate();
2019-04-11 14:54:00 +00:00
}
2018-10-24 09:09:07 +00:00
void setSelectionTracker(SelectionTracker<Long> selectionTracker) {
this.selectionTracker = selectionTracker;
}
2018-12-03 12:18:23 +00:00
int getPositionForKey(long key) {
2019-08-11 14:08:53 +00:00
if (keyPosition.isEmpty()) {
PagedList<TupleMessageEx> messages = getCurrentList();
if (messages != null) {
for (int i = 0; i < messages.size(); i++) {
TupleMessageEx message = messages.get(i);
if (message != null)
keyPosition.put(message.id, i);
}
Log.i("Mapped keys=" + keyPosition.size());
2018-12-03 12:18:23 +00:00
}
2019-08-11 14:08:53 +00:00
}
if (keyPosition.containsKey(key)) {
int pos = keyPosition.get(key);
Log.d("Position=" + pos + " @Key=" + key);
return pos;
}
2018-12-24 12:27:45 +00:00
Log.i("Position=" + RecyclerView.NO_POSITION + " @Key=" + key);
2018-12-03 12:18:23 +00:00
return RecyclerView.NO_POSITION;
}
TupleMessageEx getItemAtPosition(int pos) {
2019-08-11 14:08:53 +00:00
PagedList<TupleMessageEx> messages = getCurrentList();
if (messages != null && pos >= 0 && pos < messages.size()) {
TupleMessageEx message = messages.get(pos);
2018-12-03 12:18:23 +00:00
Long key = (message == null ? null : message.id);
2019-08-11 13:49:14 +00:00
Log.d("Item=" + key + " @Position=" + pos);
2018-12-03 12:18:23 +00:00
return message;
} else {
2019-08-11 13:49:14 +00:00
Log.d("Item=" + null + " @Position=" + pos);
2018-12-03 12:18:23 +00:00
return null;
}
}
TupleMessageEx getItemForKey(long key) {
2019-08-11 14:08:53 +00:00
int pos = getPositionForKey(key);
if (pos == RecyclerView.NO_POSITION) {
Log.d("Item=" + null + " @Key=" + key);
return null;
} else
return getItemAtPosition(pos);
2018-12-03 12:18:23 +00:00
}
Long getKeyAtPosition(int pos) {
TupleMessageEx message = getItemAtPosition(pos);
Long key = (message == null ? null : message.id);
2019-08-11 13:49:14 +00:00
Log.d("Key=" + key + " @Position=" + pos);
2018-12-03 12:18:23 +00:00
return key;
}
interface IProperties {
2018-12-21 07:32:26 +00:00
void setValue(String name, long id, boolean enabled);
2018-12-21 07:32:26 +00:00
boolean getValue(String name, long id);
2018-11-20 08:44:13 +00:00
2019-11-04 09:31:53 +00:00
void setSize(long id, Float size);
2019-09-01 13:42:53 +00:00
float getSize(long id, float defaultSize);
2019-11-04 09:31:53 +00:00
void setHeight(long id, Integer height);
2018-12-22 07:48:23 +00:00
2019-10-04 13:25:04 +00:00
int getHeight(long id, int defaultHeight);
2018-12-22 07:48:23 +00:00
2019-10-04 16:59:37 +00:00
void setPosition(long id, Pair<Integer, Integer> position);
Pair<Integer, Integer> getPosition(long id);
2019-09-02 09:32:05 +00:00
void setAttachments(long id, List<EntityAttachment> attachments);
2019-04-04 12:47:56 +00:00
List<EntityAttachment> getAttachments(long id);
2019-04-27 08:40:06 +00:00
void scrollTo(int pos);
void move(long id, String type);
void finish();
}
2019-06-30 18:56:31 +00:00
2019-09-11 19:43:27 +00:00
public static class FragmentDialogLink extends FragmentDialogBase {
2019-06-30 18:56:31 +00:00
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final Uri uri = getArguments().getParcelable("uri");
String title = getArguments().getString("title");
final Uri sanitized;
if (uri.isOpaque())
sanitized = uri;
else {
// https://en.wikipedia.org/wiki/UTM_parameters
Uri.Builder builder = uri.buildUpon();
boolean changed = false;
2019-06-30 18:56:31 +00:00
builder.clearQuery();
for (String key : uri.getQueryParameterNames())
2019-09-23 20:07:22 +00:00
if (PARANOID_QUERY.contains(key.toLowerCase(Locale.ROOT)))
changed = true;
else if (!TextUtils.isEmpty(key))
for (String value : uri.getQueryParameters(key)) {
Log.i("Query " + key + "=" + value);
builder.appendQueryParameter(key, value);
}
2019-06-30 18:56:31 +00:00
sanitized = (changed ? builder.build() : uri);
2019-06-30 18:56:31 +00:00
}
2019-12-05 15:43:04 +00:00
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_open_link, null);
TextView tvTitle = dview.findViewById(R.id.tvTitle);
final EditText etLink = dview.findViewById(R.id.etLink);
TextView tvDifferent = dview.findViewById(R.id.tvDifferent);
final CheckBox cbSecure = dview.findViewById(R.id.cbSecure);
CheckBox cbSanitize = dview.findViewById(R.id.cbSanitize);
final Button btnOwner = dview.findViewById(R.id.btnOwner);
TextView tvOwnerRemark = dview.findViewById(R.id.tvOwnerRemark);
final ContentLoadingProgressBar pbWait = dview.findViewById(R.id.pbWait);
final TextView tvHost = dview.findViewById(R.id.tvHost);
final TextView tvOwner = dview.findViewById(R.id.tvOwner);
final Group grpOwner = dview.findViewById(R.id.grpOwner);
2019-06-30 18:56:31 +00:00
etLink.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence text, int i, int i1, int i2) {
}
@Override
2019-09-24 07:56:58 +00:00
public void afterTextChanged(Editable editable) {
Uri uri = Uri.parse(editable.toString());
boolean secure = (!uri.isOpaque() &&
"https".equals(uri.getScheme()));
boolean hyperlink = (!uri.isOpaque() &&
("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())));
cbSecure.setTag(secure);
cbSecure.setChecked(secure);
cbSecure.setText(
2019-11-11 18:00:11 +00:00
secure ? R.string.title_link_https : R.string.title_link_http);
2019-09-24 07:56:58 +00:00
cbSecure.setTextColor(Helper.resolveColor(getContext(),
secure ? android.R.attr.textColorSecondary : R.attr.colorWarning));
cbSecure.setTypeface(
secure ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD);
cbSecure.setVisibility(hyperlink ? View.VISIBLE : View.GONE);
2019-06-30 18:56:31 +00:00
}
});
2019-07-07 09:11:31 +00:00
2019-06-30 18:56:31 +00:00
cbSecure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
2019-09-24 07:56:58 +00:00
boolean tag = (Boolean) compoundButton.getTag();
if (tag == checked)
return;
2019-06-30 18:56:31 +00:00
Uri uri = Uri.parse(etLink.getText().toString());
Uri.Builder builder = uri.buildUpon();
builder.scheme(checked ? "https" : "http");
String authority = uri.getEncodedAuthority();
if (authority != null) {
authority = authority.replace(checked ? ":80" : ":443", checked ? ":443" : ":80");
builder.encodedAuthority(authority);
}
etLink.setText(builder.build().toString());
}
});
cbSanitize.setVisibility(uri.equals(sanitized) ? View.GONE : View.VISIBLE);
2019-07-07 09:11:31 +00:00
2019-06-30 18:56:31 +00:00
cbSanitize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
if (checked)
etLink.setText(sanitized.toString());
else
etLink.setText(uri.toString());
}
});
2019-07-07 09:11:31 +00:00
tvOwnerRemark.setMovementMethod(LinkMovementMethod.getInstance());
2019-07-07 08:49:16 +00:00
pbWait.setVisibility(View.GONE);
2019-06-30 18:56:31 +00:00
grpOwner.setVisibility(View.GONE);
2019-07-07 09:11:31 +00:00
2019-07-07 08:49:16 +00:00
btnOwner.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle args = new Bundle();
args.putParcelable("uri", uri);
2019-06-30 18:56:31 +00:00
2019-07-07 08:49:16 +00:00
new SimpleTask<String[]>() {
@Override
protected void onPreExecute(Bundle args) {
btnOwner.setEnabled(false);
pbWait.setVisibility(View.VISIBLE);
grpOwner.setVisibility(View.GONE);
}
2019-06-30 18:56:31 +00:00
2019-07-07 08:49:16 +00:00
@Override
protected void onPostExecute(Bundle args) {
btnOwner.setEnabled(true);
pbWait.setVisibility(View.GONE);
grpOwner.setVisibility(View.VISIBLE);
}
2019-06-30 18:56:31 +00:00
2019-07-07 08:49:16 +00:00
@Override
protected String[] onExecute(Context context, Bundle args) throws Throwable {
Uri uri = args.getParcelable("uri");
2019-09-08 11:22:44 +00:00
return IPInfo.getOrganization(uri, context);
2019-07-07 08:49:16 +00:00
}
2019-06-30 18:56:31 +00:00
2019-07-07 08:49:16 +00:00
@Override
protected void onExecuted(Bundle args, String[] data) {
String host = data[0];
String organization = data[1];
tvHost.setText(host);
tvOwner.setText(organization == null ? "?" : organization);
2019-12-05 15:43:04 +00:00
new Handler().post(new Runnable() {
@Override
public void run() {
dview.scrollTo(0, tvOwner.getBottom());
}
});
2019-07-07 08:49:16 +00:00
}
2019-06-30 18:56:31 +00:00
2019-07-07 08:49:16 +00:00
@Override
protected void onException(Bundle args, Throwable ex) {
2019-06-30 18:56:31 +00:00
tvOwner.setText(ex.getMessage());
2019-07-07 08:49:16 +00:00
}
2019-09-11 12:03:59 +00:00
}.execute(FragmentDialogLink.this, args, "link:owner");
2019-07-07 08:49:16 +00:00
}
});
2019-06-30 18:56:31 +00:00
2019-09-24 07:56:58 +00:00
tvTitle.setText(title);
tvTitle.setVisibility(TextUtils.isEmpty(title) ? View.GONE : View.VISIBLE);
etLink.setText(uri.toString());
2019-10-12 12:05:31 +00:00
Uri uriTitle = Uri.parse(title == null ? "" : title);
tvDifferent.setVisibility(uriTitle.getHost() == null || uri.getHost() == null ||
uriTitle.getHost().equalsIgnoreCase(uri.getHost())
? View.GONE : View.VISIBLE);
2019-06-30 18:56:31 +00:00
return new AlertDialog.Builder(getContext())
2019-12-05 15:43:04 +00:00
.setView(dview)
2019-11-06 15:56:36 +00:00
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
2019-06-30 18:56:31 +00:00
@Override
public void onClick(DialogInterface dialog, int which) {
Uri uri = Uri.parse(etLink.getText().toString());
2019-07-01 18:34:02 +00:00
Helper.view(getContext(), uri, false);
2019-06-30 18:56:31 +00:00
}
})
.setNeutralButton(R.string.title_browse, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Uri uri = Uri.parse(etLink.getText().toString());
2019-07-01 18:34:02 +00:00
Helper.view(getContext(), uri, true);
2019-06-30 18:56:31 +00:00
}
})
2019-11-06 15:56:36 +00:00
.setNegativeButton(android.R.string.cancel, null)
2019-07-01 17:54:37 +00:00
.create();
2019-06-30 18:56:31 +00:00
}
}
2019-09-11 19:43:27 +00:00
public static class FragmentDialogImage extends FragmentDialogBase {
2019-07-06 10:52:00 +00:00
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final PhotoView pv = new PhotoView(getContext());
new SimpleTask<Drawable>() {
@Override
protected Drawable onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
String source = args.getString("source");
2019-11-15 15:08:03 +00:00
int zoom = args.getInt("zoom");
return ImageHelper.decodeImage(context, id, source, true, zoom, null);
2019-07-06 10:52:00 +00:00
}
@Override
protected void onExecuted(Bundle args, Drawable drawable) {
pv.setImageDrawable(drawable);
2019-09-07 18:13:58 +00:00
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (drawable instanceof AnimatedImageDrawable)
((AnimatedImageDrawable) drawable).start();
}
2019-07-06 10:52:00 +00:00
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(getParentFragmentManager(), ex);
2019-07-06 10:52:00 +00:00
}
2019-09-11 12:03:59 +00:00
}.execute(this, getArguments(), "view:image");
2019-07-06 10:52:00 +00:00
final Dialog dialog = new Dialog(getContext(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);
dialog.setContentView(pv);
return dialog;
}
}
2019-09-11 19:43:27 +00:00
public static class FragmentKeywordManage extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final long id = getArguments().getLong("id");
List<String> keywords = Arrays.asList(getArguments().getStringArray("keywords"));
List<String> fkeywords = Arrays.asList(getArguments().getStringArray("fkeywords"));
final List<String> items = new ArrayList<>(keywords);
for (String keyword : fkeywords)
if (!items.contains(keyword))
items.add(keyword);
Collections.sort(items);
final boolean[] selected = new boolean[items.size()];
final boolean[] dirty = new boolean[items.size()];
for (int i = 0; i < selected.length; i++) {
selected[i] = keywords.contains(items.get(i));
dirty[i] = false;
}
return new AlertDialog.Builder(getContext())
.setTitle(R.string.title_manage_keywords)
.setMultiChoiceItems(items.toArray(new String[0]), selected, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
dirty[which] = true;
}
})
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
2019-08-13 08:27:17 +00:00
if (!ActivityBilling.isPro(getContext())) {
2019-10-05 13:22:48 +00:00
startActivity(new Intent(getContext(), ActivityBilling.class));
return;
}
Bundle args = new Bundle();
args.putLong("id", id);
args.putStringArray("keywords", items.toArray(new String[0]));
args.putBooleanArray("selected", selected);
args.putBooleanArray("dirty", dirty);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
String[] keywords = args.getStringArray("keywords");
boolean[] selected = args.getBooleanArray("selected");
boolean[] dirty = args.getBooleanArray("dirty");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
for (int i = 0; i < selected.length; i++)
if (dirty[i])
EntityOperation.queue(context, message, EntityOperation.KEYWORD, keywords[i], selected[i]);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
2019-12-09 18:44:27 +00:00
ServiceSynchronize.eval(context, "keywords");
2019-12-07 19:32:58 +00:00
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(getParentFragmentManager(), ex);
}
2019-09-12 11:36:23 +00:00
}.execute(getContext(), getActivity(), args, "message:keywords:manage");
}
})
.setNeutralButton(R.string.title_add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Bundle args = new Bundle();
args.putLong("id", id);
FragmentKeywordAdd fragment = new FragmentKeywordAdd();
fragment.setArguments(args);
2019-10-12 15:16:53 +00:00
fragment.show(getParentFragmentManager(), "keyword:add");
}
})
2019-09-12 11:23:32 +00:00
.setNegativeButton(android.R.string.cancel, null)
.create();
}
}
2019-09-11 19:43:27 +00:00
public static class FragmentKeywordAdd extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final long id = getArguments().getLong("id");
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_keyword, null);
final EditText etKeyword = view.findViewById(R.id.etKeyword);
etKeyword.setText(null);
return new AlertDialog.Builder(getContext())
.setView(view)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
2019-08-13 08:27:17 +00:00
if (!ActivityBilling.isPro(getContext())) {
2019-10-05 13:22:48 +00:00
startActivity(new Intent(getContext(), ActivityBilling.class));
return;
}
2019-09-26 10:11:46 +00:00
String keyword = MessageHelper.sanitizeKeyword(etKeyword.getText().toString());
if (!TextUtils.isEmpty(keyword)) {
Bundle args = new Bundle();
args.putLong("id", id);
args.putString("keyword", keyword);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
String keyword = args.getString("keyword");
DB db = DB.getInstance(context);
2019-12-07 19:32:58 +00:00
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
EntityOperation.queue(context, message, EntityOperation.KEYWORD, keyword, true);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
2019-12-09 18:44:27 +00:00
ServiceSynchronize.eval(context, "keyword=" + keyword);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(getParentFragmentManager(), ex);
}
2019-09-12 11:36:23 +00:00
}.execute(getContext(), getActivity(), args, "message:keyword:add");
}
}
2019-09-12 11:23:32 +00:00
})
.setNegativeButton(android.R.string.cancel, null)
.create();
}
}
2018-08-02 13:33:06 +00:00
}