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
|
|
|
|
2021-01-01 07:56:36 +00:00
|
|
|
Copyright 2018-2021 by Marcel Bokhorst (M66B)
|
2018-08-02 13:33:06 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-23 07:33:19 +00:00
|
|
|
import android.app.Dialog;
|
2019-05-16 08:04:20 +00:00
|
|
|
import android.app.NotificationChannel;
|
|
|
|
import android.app.NotificationManager;
|
2020-06-25 14:02:25 +00:00
|
|
|
import android.content.ActivityNotFoundException;
|
2018-08-02 13:33:06 +00:00
|
|
|
import android.content.Context;
|
2020-03-23 07:33:19 +00:00
|
|
|
import android.content.DialogInterface;
|
2018-08-02 13:33:06 +00:00
|
|
|
import android.content.Intent;
|
2018-11-26 13:48:59 +00:00
|
|
|
import android.content.SharedPreferences;
|
2018-12-11 11:18:26 +00:00
|
|
|
import android.content.res.ColorStateList;
|
2018-12-02 09:09:21 +00:00
|
|
|
import android.graphics.Color;
|
2018-08-02 13:33:06 +00:00
|
|
|
import android.graphics.Typeface;
|
2019-05-16 08:04:20 +00:00
|
|
|
import android.os.Build;
|
2018-09-08 06:23:53 +00:00
|
|
|
import android.os.Bundle;
|
2019-05-16 08:04:20 +00:00
|
|
|
import android.provider.Settings;
|
2020-01-21 09:52:34 +00:00
|
|
|
import android.text.SpannableString;
|
2018-11-26 08:12:44 +00:00
|
|
|
import android.text.TextUtils;
|
2020-01-21 10:41:07 +00:00
|
|
|
import android.text.style.RelativeSizeSpan;
|
2020-01-21 09:52:34 +00:00
|
|
|
import android.text.style.StyleSpan;
|
2019-01-22 15:43:58 +00:00
|
|
|
import android.util.TypedValue;
|
2018-08-02 13:33:06 +00:00
|
|
|
import android.view.LayoutInflater;
|
2018-09-08 06:23:53 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2020-11-18 21:32:41 +00:00
|
|
|
import android.view.SubMenu;
|
2018-08-02 13:33:06 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2019-09-01 16:20:03 +00:00
|
|
|
import android.widget.Button;
|
2020-03-23 07:33:19 +00:00
|
|
|
import android.widget.EditText;
|
2019-08-16 14:35:33 +00:00
|
|
|
import android.widget.ImageButton;
|
2018-08-02 13:33:06 +00:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
2020-06-25 14:02:25 +00:00
|
|
|
import android.widget.Toast;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-08-08 06:55:47 +00:00
|
|
|
import androidx.annotation.NonNull;
|
2020-03-23 07:33:19 +00:00
|
|
|
import androidx.annotation.Nullable;
|
2019-06-08 07:34:29 +00:00
|
|
|
import androidx.annotation.RequiresApi;
|
2020-03-23 07:33:19 +00:00
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2018-09-08 06:23:53 +00:00
|
|
|
import androidx.appcompat.widget.PopupMenu;
|
2019-10-03 13:57:21 +00:00
|
|
|
import androidx.constraintlayout.widget.Group;
|
2019-06-30 18:47:30 +00:00
|
|
|
import androidx.fragment.app.Fragment;
|
2019-07-01 07:30:07 +00:00
|
|
|
import androidx.lifecycle.Lifecycle;
|
|
|
|
import androidx.lifecycle.LifecycleObserver;
|
2018-09-08 06:23:53 +00:00
|
|
|
import androidx.lifecycle.LifecycleOwner;
|
2019-07-01 07:30:07 +00:00
|
|
|
import androidx.lifecycle.OnLifecycleEvent;
|
2018-08-08 06:55:47 +00:00
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
2019-03-15 13:54:25 +00:00
|
|
|
import androidx.preference.PreferenceManager;
|
2018-08-08 06:55:47 +00:00
|
|
|
import androidx.recyclerview.widget.DiffUtil;
|
|
|
|
import androidx.recyclerview.widget.ListUpdateCallback;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2019-04-17 18:21:44 +00:00
|
|
|
import java.text.NumberFormat;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
2019-05-25 20:09:15 +00:00
|
|
|
import java.util.HashMap;
|
2019-04-17 18:21:44 +00:00
|
|
|
import java.util.List;
|
2019-05-25 20:09:15 +00:00
|
|
|
import java.util.Map;
|
2019-04-17 18:21:44 +00:00
|
|
|
|
2019-06-30 18:47:30 +00:00
|
|
|
import static android.app.Activity.RESULT_OK;
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder> {
|
2019-06-30 18:47:30 +00:00
|
|
|
private Fragment parentFragment;
|
2018-12-02 09:09:21 +00:00
|
|
|
private long account;
|
2020-04-15 18:53:46 +00:00
|
|
|
private boolean primary;
|
2019-10-03 13:57:21 +00:00
|
|
|
private boolean show_compact;
|
2019-07-01 07:30:07 +00:00
|
|
|
private boolean show_hidden;
|
2020-05-19 06:46:49 +00:00
|
|
|
private boolean show_flagged;
|
2020-03-31 11:43:58 +00:00
|
|
|
private boolean subscribed_only;
|
2019-05-25 20:51:44 +00:00
|
|
|
private IFolderSelectedListener listener;
|
2019-05-25 20:09:15 +00:00
|
|
|
|
2019-07-01 07:30:07 +00:00
|
|
|
private Context context;
|
|
|
|
private LifecycleOwner owner;
|
|
|
|
private LayoutInflater inflater;
|
|
|
|
|
2019-04-25 17:02:37 +00:00
|
|
|
private boolean subscriptions;
|
2019-08-14 11:49:40 +00:00
|
|
|
|
2018-12-03 09:39:44 +00:00
|
|
|
private int dp12;
|
2019-01-22 15:43:58 +00:00
|
|
|
private float textSize;
|
2019-08-16 14:24:03 +00:00
|
|
|
private int textColorPrimary;
|
2019-01-05 14:24:04 +00:00
|
|
|
private int textColorSecondary;
|
2019-09-08 15:27:50 +00:00
|
|
|
private int colorUnread;
|
2020-12-08 07:12:20 +00:00
|
|
|
private int colorControlNormal;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2019-05-26 11:15:56 +00:00
|
|
|
private List<Long> disabledIds = new ArrayList<>();
|
2019-06-06 08:14:49 +00:00
|
|
|
private List<TupleFolderEx> all = new ArrayList<>();
|
2019-03-18 08:33:40 +00:00
|
|
|
private List<TupleFolderEx> items = new ArrayList<>();
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2019-07-22 07:52:08 +00:00
|
|
|
private NumberFormat NF = NumberFormat.getNumberInstance();
|
2019-03-09 13:22:49 +00:00
|
|
|
|
2018-08-26 08:33:22 +00:00
|
|
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
2019-03-15 11:53:22 +00:00
|
|
|
private View view;
|
2019-08-14 11:49:40 +00:00
|
|
|
|
2019-08-14 15:21:37 +00:00
|
|
|
private View vwColor;
|
2018-11-26 08:12:44 +00:00
|
|
|
private ImageView ivState;
|
2019-04-30 07:06:32 +00:00
|
|
|
private ImageView ivReadOnly;
|
2019-06-14 19:14:51 +00:00
|
|
|
|
2019-03-18 08:33:40 +00:00
|
|
|
private View vwLevel;
|
2019-09-01 16:59:51 +00:00
|
|
|
private ImageButton ibExpander;
|
2019-06-14 19:14:51 +00:00
|
|
|
|
|
|
|
private ImageView ivUnified;
|
2019-04-25 16:11:18 +00:00
|
|
|
private ImageView ivSubscribed;
|
2019-06-21 06:39:36 +00:00
|
|
|
private ImageView ivRule;
|
|
|
|
private ImageView ivNotify;
|
2018-11-26 08:12:44 +00:00
|
|
|
private TextView tvName;
|
|
|
|
private TextView tvMessages;
|
2019-01-05 14:24:04 +00:00
|
|
|
private ImageView ivMessages;
|
2019-06-14 19:14:51 +00:00
|
|
|
|
2019-05-22 14:29:18 +00:00
|
|
|
private ImageView ivType;
|
2018-11-26 08:12:44 +00:00
|
|
|
private TextView tvType;
|
2019-05-26 07:57:47 +00:00
|
|
|
private TextView tvTotal;
|
2018-11-26 08:12:44 +00:00
|
|
|
private TextView tvAfter;
|
|
|
|
private ImageView ivSync;
|
2019-06-14 19:14:51 +00:00
|
|
|
|
2018-11-26 08:12:44 +00:00
|
|
|
private TextView tvKeywords;
|
2020-05-19 06:46:49 +00:00
|
|
|
private TextView tvFlagged;
|
|
|
|
private ImageView ibFlagged;
|
|
|
|
|
2018-11-26 08:12:44 +00:00
|
|
|
private TextView tvError;
|
2019-09-01 16:20:03 +00:00
|
|
|
private Button btnHelp;
|
2019-05-03 16:59:27 +00:00
|
|
|
|
2020-05-19 06:46:49 +00:00
|
|
|
private Group grpFlagged;
|
2019-10-03 13:57:21 +00:00
|
|
|
private Group grpExtended;
|
|
|
|
|
2019-05-03 16:59:27 +00:00
|
|
|
private TwoStateOwner powner = new TwoStateOwner(owner, "FolderPopup");
|
2018-08-02 13:33:06 +00:00
|
|
|
|
|
|
|
ViewHolder(View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
|
2019-03-15 11:53:22 +00:00
|
|
|
view = itemView.findViewById(R.id.clItem);
|
2019-08-14 11:49:40 +00:00
|
|
|
|
2019-08-14 15:21:37 +00:00
|
|
|
vwColor = itemView.findViewById(R.id.vwColor);
|
2018-09-08 16:32:13 +00:00
|
|
|
ivState = itemView.findViewById(R.id.ivState);
|
2019-04-30 07:06:32 +00:00
|
|
|
ivReadOnly = itemView.findViewById(R.id.ivReadOnly);
|
2019-06-14 19:14:51 +00:00
|
|
|
|
2019-03-18 08:33:40 +00:00
|
|
|
vwLevel = itemView.findViewById(R.id.vwLevel);
|
2019-09-01 16:59:51 +00:00
|
|
|
ibExpander = itemView.findViewById(R.id.ibExpander);
|
2019-06-14 19:14:51 +00:00
|
|
|
|
|
|
|
ivUnified = itemView.findViewById(R.id.ivUnified);
|
2019-04-25 16:11:18 +00:00
|
|
|
ivSubscribed = itemView.findViewById(R.id.ivSubscribed);
|
2019-06-21 06:39:36 +00:00
|
|
|
ivRule = itemView.findViewById(R.id.ivRule);
|
|
|
|
ivNotify = itemView.findViewById(R.id.ivNotify);
|
2018-08-02 13:33:06 +00:00
|
|
|
tvName = itemView.findViewById(R.id.tvName);
|
2018-08-07 17:44:25 +00:00
|
|
|
tvMessages = itemView.findViewById(R.id.tvMessages);
|
2019-01-05 14:24:04 +00:00
|
|
|
ivMessages = itemView.findViewById(R.id.ivMessages);
|
2019-06-14 19:14:51 +00:00
|
|
|
|
2019-05-22 14:29:18 +00:00
|
|
|
ivType = itemView.findViewById(R.id.ivType);
|
2018-09-08 16:32:13 +00:00
|
|
|
tvType = itemView.findViewById(R.id.tvType);
|
2019-05-26 07:57:47 +00:00
|
|
|
tvTotal = itemView.findViewById(R.id.tvTotal);
|
2018-08-02 13:33:06 +00:00
|
|
|
tvAfter = itemView.findViewById(R.id.tvAfter);
|
|
|
|
ivSync = itemView.findViewById(R.id.ivSync);
|
2019-06-14 19:14:51 +00:00
|
|
|
|
2018-11-26 08:12:44 +00:00
|
|
|
tvKeywords = itemView.findViewById(R.id.tvKeywords);
|
2020-05-19 06:46:49 +00:00
|
|
|
tvFlagged = itemView.findViewById(R.id.tvFlagged);
|
|
|
|
ibFlagged = itemView.findViewById(R.id.ibFlagged);
|
|
|
|
|
2018-08-11 08:28:54 +00:00
|
|
|
tvError = itemView.findViewById(R.id.tvError);
|
2019-09-01 16:20:03 +00:00
|
|
|
btnHelp = itemView.findViewById(R.id.btnHelp);
|
2019-10-03 13:57:21 +00:00
|
|
|
|
2020-05-19 06:46:49 +00:00
|
|
|
grpFlagged = itemView.findViewById(R.id.grpFlagged);
|
2019-10-03 13:57:21 +00:00
|
|
|
grpExtended = itemView.findViewById(R.id.grpExtended);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
2018-09-08 16:32:13 +00:00
|
|
|
private void wire() {
|
2019-03-15 11:53:22 +00:00
|
|
|
view.setOnClickListener(this);
|
2019-09-01 16:59:51 +00:00
|
|
|
ibExpander.setOnClickListener(this);
|
2020-05-19 06:46:49 +00:00
|
|
|
if (tvFlagged != null)
|
|
|
|
tvFlagged.setOnClickListener(this);
|
|
|
|
if (ibFlagged != null)
|
|
|
|
ibFlagged.setOnClickListener(this);
|
2019-07-30 05:50:57 +00:00
|
|
|
if (listener == null)
|
|
|
|
view.setOnLongClickListener(this);
|
2019-09-01 16:20:03 +00:00
|
|
|
if (btnHelp != null)
|
|
|
|
btnHelp.setOnClickListener(this);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void unwire() {
|
2019-03-15 11:53:22 +00:00
|
|
|
view.setOnClickListener(null);
|
2019-09-01 16:59:51 +00:00
|
|
|
ibExpander.setOnClickListener(null);
|
2020-05-19 06:46:49 +00:00
|
|
|
if (tvFlagged != null)
|
|
|
|
tvFlagged.setOnClickListener(null);
|
|
|
|
if (ibFlagged != null)
|
|
|
|
ibFlagged.setOnClickListener(null);
|
2019-07-30 05:50:57 +00:00
|
|
|
if (listener == null)
|
|
|
|
view.setOnLongClickListener(null);
|
2019-09-01 16:20:03 +00:00
|
|
|
if (btnHelp != null)
|
|
|
|
btnHelp.setOnClickListener(null);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 08:33:40 +00:00
|
|
|
private void bindTo(final TupleFolderEx folder) {
|
2019-07-29 19:53:32 +00:00
|
|
|
view.setActivated(folder.tbc != null || folder.rename != null || folder.tbd != null);
|
2020-01-09 19:20:59 +00:00
|
|
|
view.setAlpha(
|
|
|
|
folder.hide ||
|
|
|
|
!folder.selectable ||
|
|
|
|
(folder.read_only && listener != null) ||
|
|
|
|
disabledIds.contains(folder.id)
|
|
|
|
? Helper.LOW_LIGHT : 1.0f);
|
2018-09-21 15:19:37 +00:00
|
|
|
|
2019-01-22 15:43:58 +00:00
|
|
|
if (textSize != 0)
|
|
|
|
tvName.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
|
|
|
|
2019-05-25 20:51:44 +00:00
|
|
|
if (listener == null) {
|
2019-10-07 16:15:02 +00:00
|
|
|
vwColor.setBackgroundColor(folder.color == null ? Color.TRANSPARENT : folder.color);
|
|
|
|
vwColor.setVisibility(ActivityBilling.isPro(context) ? View.VISIBLE : View.GONE);
|
2019-05-25 20:51:44 +00:00
|
|
|
|
|
|
|
if (folder.sync_state == null || "requested".equals(folder.sync_state)) {
|
2019-12-28 20:48:44 +00:00
|
|
|
if (folder.executing > 0) {
|
2020-09-28 07:18:56 +00:00
|
|
|
ivState.setImageResource(R.drawable.twotone_dns_24);
|
2019-12-28 20:48:44 +00:00
|
|
|
ivState.setContentDescription(context.getString(R.string.title_legend_executing));
|
|
|
|
} else if ("connected".equals(folder.state)) {
|
2020-09-28 16:37:00 +00:00
|
|
|
ivState.setImageResource(R.drawable.twotone_cloud_done_24);
|
2019-12-28 20:48:44 +00:00
|
|
|
ivState.setContentDescription(context.getString(R.string.title_legend_connected));
|
|
|
|
} else if ("connecting".equals(folder.state)) {
|
2020-09-28 07:18:56 +00:00
|
|
|
ivState.setImageResource(R.drawable.twotone_cloud_queue_24);
|
2019-12-28 20:48:44 +00:00
|
|
|
ivState.setContentDescription(context.getString(R.string.title_legend_connecting));
|
2019-12-29 12:02:08 +00:00
|
|
|
} else if ("closing".equals(folder.state)) {
|
2020-10-01 10:07:28 +00:00
|
|
|
ivState.setImageResource(R.drawable.twotone_cancel_24);
|
2019-12-28 20:48:44 +00:00
|
|
|
ivState.setContentDescription(context.getString(R.string.title_legend_closing));
|
|
|
|
} else if (folder.state == null) {
|
2020-09-28 07:18:56 +00:00
|
|
|
ivState.setImageResource(R.drawable.twotone_cloud_off_24);
|
2019-12-28 20:48:44 +00:00
|
|
|
ivState.setContentDescription(context.getString(R.string.title_legend_disconnected));
|
|
|
|
} else
|
2020-09-28 07:18:56 +00:00
|
|
|
ivState.setImageResource(R.drawable.twotone_warning_24);
|
2019-05-25 20:51:44 +00:00
|
|
|
} else {
|
2019-12-28 20:48:44 +00:00
|
|
|
if ("syncing".equals(folder.sync_state)) {
|
2020-09-28 07:18:56 +00:00
|
|
|
ivState.setImageResource(R.drawable.twotone_compare_arrows_24);
|
2019-12-28 20:48:44 +00:00
|
|
|
ivState.setContentDescription(context.getString(R.string.title_legend_synchronizing));
|
|
|
|
} else if ("downloading".equals(folder.sync_state)) {
|
2020-09-28 07:18:56 +00:00
|
|
|
ivState.setImageResource(R.drawable.twotone_cloud_download_24);
|
2019-12-28 20:48:44 +00:00
|
|
|
ivState.setContentDescription(context.getString(R.string.title_legend_downloading));
|
|
|
|
} else
|
2020-09-28 07:18:56 +00:00
|
|
|
ivState.setImageResource(R.drawable.twotone_warning_24);
|
2019-05-25 20:51:44 +00:00
|
|
|
}
|
|
|
|
ivState.setVisibility(
|
2021-01-04 07:43:24 +00:00
|
|
|
(folder.selectable && folder.synchronize) || folder.state != null || folder.sync_state != null
|
2019-05-25 20:51:44 +00:00
|
|
|
? View.VISIBLE : View.INVISIBLE);
|
2018-08-14 09:09:44 +00:00
|
|
|
|
2019-07-08 13:22:52 +00:00
|
|
|
if (folder.selectable)
|
2019-10-03 13:57:21 +00:00
|
|
|
ivReadOnly.setVisibility(!show_compact && folder.read_only ? View.VISIBLE : View.GONE);
|
2019-05-25 20:51:44 +00:00
|
|
|
}
|
2019-04-30 07:06:32 +00:00
|
|
|
|
2019-03-18 08:33:40 +00:00
|
|
|
ViewGroup.LayoutParams lp = vwLevel.getLayoutParams();
|
2020-04-15 18:53:46 +00:00
|
|
|
lp.width = (account < 0 && !primary ? 1 : folder.indentation) * dp12;
|
2019-03-18 08:33:40 +00:00
|
|
|
vwLevel.setLayoutParams(lp);
|
|
|
|
|
2019-09-01 16:59:51 +00:00
|
|
|
ibExpander.setImageLevel(folder.collapsed ? 1 /* more */ : 0 /* less */);
|
2019-12-28 20:48:44 +00:00
|
|
|
ibExpander.setContentDescription(context.getString(folder.collapsed ? R.string.title_accessibility_expand : R.string.title_accessibility_collapse));
|
2020-04-15 18:53:46 +00:00
|
|
|
ibExpander.setVisibility((account < 0 && !primary) || !folder.expander
|
2019-05-25 20:09:15 +00:00
|
|
|
? View.GONE
|
2019-06-05 05:46:06 +00:00
|
|
|
: folder.child_refs != null && folder.child_refs.size() > 0
|
|
|
|
? View.VISIBLE : View.INVISIBLE);
|
2019-03-18 08:33:40 +00:00
|
|
|
|
2019-07-08 13:22:52 +00:00
|
|
|
if (listener == null && folder.selectable) {
|
2020-04-15 18:53:46 +00:00
|
|
|
ivUnified.setVisibility((account > 0 || primary) && folder.unified ? View.VISIBLE : View.GONE);
|
2019-05-25 20:51:44 +00:00
|
|
|
ivSubscribed.setVisibility(subscriptions && folder.subscribed != null && folder.subscribed ? View.VISIBLE : View.GONE);
|
2019-06-21 06:39:36 +00:00
|
|
|
ivRule.setVisibility(folder.rules > 0 ? View.VISIBLE : View.GONE);
|
|
|
|
ivNotify.setVisibility(folder.notify ? View.VISIBLE : View.GONE);
|
2019-05-25 20:51:44 +00:00
|
|
|
}
|
2018-12-09 08:38:23 +00:00
|
|
|
|
2018-08-07 17:44:25 +00:00
|
|
|
if (folder.unseen > 0)
|
2019-03-12 15:26:21 +00:00
|
|
|
tvName.setText(context.getString(R.string.title_name_count,
|
2019-06-05 05:46:06 +00:00
|
|
|
folder.getDisplayName(context, folder.parent_ref == null ? null : folder.parent_ref),
|
2019-07-22 07:52:08 +00:00
|
|
|
NF.format(folder.unseen)));
|
2019-03-12 15:26:21 +00:00
|
|
|
else
|
2019-10-04 14:16:23 +00:00
|
|
|
tvName.setText(folder.getDisplayName(context, folder.parent_ref));
|
2019-03-12 15:26:21 +00:00
|
|
|
|
2019-05-30 08:05:54 +00:00
|
|
|
tvName.setTypeface(folder.unseen > 0 ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
|
2019-09-08 15:27:50 +00:00
|
|
|
tvName.setTextColor(folder.unseen > 0 ? colorUnread : textColorSecondary);
|
2018-08-07 06:51:49 +00:00
|
|
|
|
2019-07-08 13:22:52 +00:00
|
|
|
if (listener == null && folder.selectable) {
|
2019-05-25 20:51:44 +00:00
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
if (folder.account == null)
|
2019-07-22 07:52:08 +00:00
|
|
|
sb.append(NF.format(folder.messages));
|
2019-05-25 20:51:44 +00:00
|
|
|
else {
|
2019-10-08 08:28:44 +00:00
|
|
|
if (!show_compact) {
|
|
|
|
sb.append(NF.format(folder.content));
|
|
|
|
sb.append('/');
|
|
|
|
}
|
2019-07-22 07:52:08 +00:00
|
|
|
sb.append(NF.format(folder.messages));
|
2019-05-25 20:51:44 +00:00
|
|
|
}
|
|
|
|
tvMessages.setText(sb.toString());
|
2019-03-09 08:20:46 +00:00
|
|
|
|
2019-05-25 20:51:44 +00:00
|
|
|
ivMessages.setImageResource(folder.download || EntityFolder.OUTBOX.equals(folder.type)
|
2020-09-28 07:18:56 +00:00
|
|
|
? R.drawable.twotone_mail_24 : R.drawable.twotone_mail_outline_24);
|
2019-05-25 20:51:44 +00:00
|
|
|
}
|
2018-08-07 06:51:49 +00:00
|
|
|
|
2019-10-03 13:57:21 +00:00
|
|
|
if (folder.selectable)
|
2019-07-08 13:22:52 +00:00
|
|
|
ivType.setImageResource(EntityFolder.getIcon(folder.type));
|
2019-10-03 13:57:21 +00:00
|
|
|
|
2020-12-08 07:12:20 +00:00
|
|
|
if (listener != null) {
|
2019-10-03 13:57:21 +00:00
|
|
|
ivType.setVisibility(folder.selectable ? View.VISIBLE : View.GONE);
|
2020-12-08 07:12:20 +00:00
|
|
|
ivType.setImageTintList(ColorStateList.valueOf(folder.color == null ? colorControlNormal : folder.color));
|
|
|
|
}
|
2018-09-08 16:32:13 +00:00
|
|
|
|
2019-07-08 13:22:52 +00:00
|
|
|
if (listener == null && folder.selectable) {
|
2020-04-15 18:53:46 +00:00
|
|
|
if (account < 0 && !primary)
|
2019-05-25 20:51:44 +00:00
|
|
|
tvType.setText(folder.accountName);
|
2019-07-19 06:27:44 +00:00
|
|
|
else
|
2020-06-06 08:02:11 +00:00
|
|
|
tvType.setText(EntityFolder.localizeType(context, folder.type));
|
2018-08-07 17:44:25 +00:00
|
|
|
|
2020-10-26 15:25:31 +00:00
|
|
|
tvTotal.setText(folder.total == null ? null : NF.format(folder.total));
|
2019-05-26 07:57:47 +00:00
|
|
|
|
2019-05-25 20:51:44 +00:00
|
|
|
if (folder.account == null) {
|
|
|
|
tvAfter.setText(null);
|
2020-09-28 07:18:56 +00:00
|
|
|
ivSync.setImageResource(R.drawable.twotone_sync_24);
|
2019-12-28 20:48:44 +00:00
|
|
|
ivSync.setContentDescription(context.getString(R.string.title_legend_synchronize_on));
|
2019-05-25 20:51:44 +00:00
|
|
|
} else {
|
|
|
|
StringBuilder a = new StringBuilder();
|
2019-09-19 15:41:26 +00:00
|
|
|
|
|
|
|
if (folder.sync_days == Integer.MAX_VALUE)
|
|
|
|
a.append('∞');
|
|
|
|
else
|
|
|
|
a.append(NF.format(folder.sync_days));
|
|
|
|
|
2019-05-25 20:51:44 +00:00
|
|
|
a.append('/');
|
2019-09-19 15:41:26 +00:00
|
|
|
|
2019-05-25 20:51:44 +00:00
|
|
|
if (folder.keep_days == Integer.MAX_VALUE)
|
|
|
|
a.append('∞');
|
|
|
|
else
|
2019-07-22 07:52:08 +00:00
|
|
|
a.append(NF.format(folder.keep_days));
|
2019-09-19 15:41:26 +00:00
|
|
|
|
2019-05-25 20:51:44 +00:00
|
|
|
tvAfter.setText(a.toString());
|
2020-10-26 12:21:43 +00:00
|
|
|
if (folder.synchronize) {
|
|
|
|
ivSync.setImageResource(folder.poll
|
|
|
|
? R.drawable.twotone_hourglass_top_24
|
|
|
|
: R.drawable.twotone_sync_24);
|
|
|
|
ivSync.setContentDescription(context.getString(folder.poll
|
|
|
|
? R.string.title_legend_synchronize_poll
|
|
|
|
: R.string.title_legend_synchronize_on));
|
|
|
|
} else {
|
|
|
|
ivSync.setImageResource(R.drawable.twotone_sync_disabled_24);
|
|
|
|
ivSync.setContentDescription(context.getString(R.string.title_legend_synchronize_off));
|
|
|
|
}
|
2019-05-25 20:51:44 +00:00
|
|
|
}
|
|
|
|
ivSync.setImageTintList(ColorStateList.valueOf(
|
2020-11-16 10:05:32 +00:00
|
|
|
folder.synchronize && folder.initialize != 0 &&
|
|
|
|
!EntityFolder.OUTBOX.equals(folder.type) &&
|
|
|
|
folder.accountProtocol == EntityAccount.TYPE_IMAP
|
2019-08-16 14:24:03 +00:00
|
|
|
? textColorPrimary : textColorSecondary));
|
2018-08-13 14:44:47 +00:00
|
|
|
|
2020-05-19 07:47:28 +00:00
|
|
|
tvKeywords.setText(BuildConfig.DEBUG ? TextUtils.join(" ", folder.keywords) : null);
|
|
|
|
tvKeywords.setVisibility(show_flagged ? View.VISIBLE : View.GONE);
|
2020-05-19 06:46:49 +00:00
|
|
|
|
|
|
|
tvFlagged.setText(NF.format(folder.flagged));
|
2020-05-19 07:50:37 +00:00
|
|
|
ibFlagged.setImageResource(folder.flagged == 0
|
2020-09-29 18:12:01 +00:00
|
|
|
? R.drawable.twotone_star_border_24 : R.drawable.twotone_star_24);
|
2020-05-19 13:47:13 +00:00
|
|
|
tvFlagged.setEnabled(folder.flagged > 0);
|
|
|
|
ibFlagged.setEnabled(folder.flagged > 0);
|
2018-11-26 08:12:44 +00:00
|
|
|
|
2019-05-25 20:51:44 +00:00
|
|
|
tvError.setText(folder.error);
|
|
|
|
tvError.setVisibility(folder.error != null ? View.VISIBLE : View.GONE);
|
2019-09-01 16:20:03 +00:00
|
|
|
if (btnHelp != null)
|
|
|
|
btnHelp.setVisibility(folder.error == null ? View.GONE : View.VISIBLE);
|
2019-10-03 13:57:21 +00:00
|
|
|
|
2020-05-19 13:42:41 +00:00
|
|
|
grpFlagged.setVisibility(show_flagged ? View.VISIBLE : View.GONE);
|
2019-10-03 13:57:21 +00:00
|
|
|
grpExtended.setVisibility(show_compact ? View.GONE : View.VISIBLE);
|
2019-05-25 20:51:44 +00:00
|
|
|
}
|
2018-08-07 06:51:49 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2019-09-01 16:20:03 +00:00
|
|
|
if (view.getId() == R.id.btnHelp)
|
2021-01-29 16:19:10 +00:00
|
|
|
Helper.viewFAQ(view.getContext(), 22);
|
2019-09-01 16:20:03 +00:00
|
|
|
else {
|
|
|
|
int pos = getAdapterPosition();
|
|
|
|
if (pos == RecyclerView.NO_POSITION)
|
|
|
|
return;
|
|
|
|
|
|
|
|
TupleFolderEx folder = items.get(pos);
|
2020-09-22 06:40:42 +00:00
|
|
|
if (folder.tbd != null)
|
2019-09-01 16:20:03 +00:00
|
|
|
return;
|
|
|
|
|
2020-05-19 06:46:49 +00:00
|
|
|
switch (view.getId()) {
|
|
|
|
case R.id.ibExpander:
|
|
|
|
onCollapse(folder);
|
|
|
|
break;
|
|
|
|
case R.id.tvFlagged:
|
|
|
|
case R.id.ibFlagged:
|
|
|
|
onFlagged(folder);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (listener == null) {
|
2020-09-22 06:40:42 +00:00
|
|
|
if (!folder.selectable)
|
|
|
|
return;
|
|
|
|
|
2020-05-19 06:46:49 +00:00
|
|
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
|
|
|
lbm.sendBroadcast(
|
|
|
|
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
|
|
|
|
.putExtra("account", folder.account)
|
|
|
|
.putExtra("folder", folder.id)
|
|
|
|
.putExtra("type", folder.type));
|
|
|
|
} else {
|
|
|
|
if (folder.read_only)
|
|
|
|
return;
|
|
|
|
if (disabledIds.contains(folder.id))
|
|
|
|
return;
|
|
|
|
listener.onFolderSelected(folder);
|
|
|
|
}
|
2019-05-26 11:15:56 +00:00
|
|
|
}
|
2019-03-17 21:23:55 +00:00
|
|
|
}
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
2018-08-26 08:33:22 +00:00
|
|
|
|
2019-03-18 08:33:40 +00:00
|
|
|
private void onCollapse(TupleFolderEx folder) {
|
2019-05-25 20:51:44 +00:00
|
|
|
if (listener != null) {
|
|
|
|
folder.collapsed = !folder.collapsed;
|
2019-06-06 08:14:49 +00:00
|
|
|
set(all);
|
2019-05-25 20:51:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-18 08:33:40 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", folder.id);
|
|
|
|
args.putBoolean("collapsed", !folder.collapsed);
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
|
|
|
long id = args.getLong("id");
|
|
|
|
boolean collapsed = args.getBoolean("collapsed");
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
db.folder().setFolderCollapsed(id, collapsed);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
2019-12-06 07:50:46 +00:00
|
|
|
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
2019-03-18 08:33:40 +00:00
|
|
|
}
|
|
|
|
}.execute(context, owner, args, "folder:collapse");
|
|
|
|
}
|
|
|
|
|
2020-05-19 06:46:49 +00:00
|
|
|
private void onFlagged(TupleFolderEx folder) {
|
|
|
|
BoundaryCallbackMessages.SearchCriteria criteria = new BoundaryCallbackMessages.SearchCriteria();
|
|
|
|
criteria.in_senders = false;
|
|
|
|
criteria.in_recipients = false;
|
|
|
|
criteria.in_subject = false;
|
|
|
|
criteria.in_keywords = false;
|
|
|
|
criteria.in_message = false;
|
|
|
|
criteria.with_flagged = true;
|
|
|
|
FragmentMessages.search(
|
|
|
|
context, owner, parentFragment.getParentFragmentManager(),
|
|
|
|
folder.account, folder.id, false, criteria);
|
|
|
|
}
|
|
|
|
|
2018-08-26 08:33:22 +00:00
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
int pos = getAdapterPosition();
|
|
|
|
if (pos == RecyclerView.NO_POSITION)
|
|
|
|
return false;
|
|
|
|
|
2019-03-18 08:33:40 +00:00
|
|
|
final TupleFolderEx folder = items.get(pos);
|
2020-12-17 14:05:44 +00:00
|
|
|
if (folder.tbd != null || folder.local)
|
2019-01-12 11:02:26 +00:00
|
|
|
return false;
|
2018-09-08 06:23:53 +00:00
|
|
|
|
2019-09-19 15:41:26 +00:00
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
2020-04-16 14:25:10 +00:00
|
|
|
boolean debug = prefs.getBoolean("debug", false);
|
2019-09-19 15:41:26 +00:00
|
|
|
|
2020-10-14 08:10:18 +00:00
|
|
|
int order = 1;
|
2019-05-25 20:09:15 +00:00
|
|
|
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, view);
|
2018-09-08 16:32:13 +00:00
|
|
|
|
2019-11-11 18:29:19 +00:00
|
|
|
if (folder.selectable) {
|
2020-10-26 15:25:31 +00:00
|
|
|
String title;
|
|
|
|
if (folder.last_sync == null)
|
|
|
|
title = folder.getDisplayName(context);
|
|
|
|
else
|
|
|
|
title = context.getString(R.string.title_name_count,
|
|
|
|
folder.getDisplayName(context),
|
|
|
|
Helper.getRelativeTimeSpanString(context, folder.last_sync));
|
|
|
|
|
|
|
|
SpannableString ss = new SpannableString(title);
|
2020-01-21 09:52:34 +00:00
|
|
|
ss.setSpan(new StyleSpan(Typeface.ITALIC), 0, ss.length(), 0);
|
2020-01-21 10:41:07 +00:00
|
|
|
ss.setSpan(new RelativeSizeSpan(0.9f), 0, ss.length(), 0);
|
2020-01-21 09:52:34 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, 0, 0, ss).setEnabled(false);
|
|
|
|
|
2020-10-14 08:10:18 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_synchronize_now, order++, R.string.title_synchronize_now);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (folder.selectable) {
|
2019-11-23 12:48:59 +00:00
|
|
|
if (folder.account != null && folder.accountProtocol == EntityAccount.TYPE_IMAP) {
|
2020-10-14 08:10:18 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_synchronize_more, order++, R.string.title_synchronize_more);
|
2019-06-26 06:23:27 +00:00
|
|
|
|
2020-10-14 08:10:18 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_local, order++, R.string.title_delete_local);
|
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_browsed, order++, R.string.title_delete_browsed);
|
2019-11-11 18:29:19 +00:00
|
|
|
}
|
2019-07-01 19:32:41 +00:00
|
|
|
|
2020-07-26 17:58:13 +00:00
|
|
|
if (EntityFolder.TRASH.equals(folder.type))
|
2020-10-14 08:10:18 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_empty_trash, order++, R.string.title_empty_trash);
|
2020-07-26 17:58:13 +00:00
|
|
|
else if (EntityFolder.JUNK.equals(folder.type))
|
2020-10-14 08:10:18 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_empty_spam, order++, R.string.title_empty_spam);
|
2020-07-26 17:58:13 +00:00
|
|
|
|
2019-11-11 18:29:19 +00:00
|
|
|
if (folder.account != null) {
|
2020-10-14 08:10:18 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_unified_folder, order++, R.string.title_unified_folder)
|
2020-04-15 09:42:15 +00:00
|
|
|
.setCheckable(true).setChecked(folder.unified);
|
2019-05-25 15:14:51 +00:00
|
|
|
|
2020-10-14 08:10:18 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_navigation_folder, order++, R.string.title_navigation_folder)
|
2019-11-11 18:29:19 +00:00
|
|
|
.setCheckable(true).setChecked(folder.navigation);
|
2019-05-25 15:14:51 +00:00
|
|
|
|
2020-10-14 08:10:18 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_notify_folder, order++, R.string.title_notify_folder)
|
2019-11-11 18:29:19 +00:00
|
|
|
.setCheckable(true).setChecked(folder.notify);
|
|
|
|
}
|
2019-05-25 15:14:51 +00:00
|
|
|
|
2019-11-23 12:48:59 +00:00
|
|
|
if (folder.account != null && folder.accountProtocol == EntityAccount.TYPE_IMAP) {
|
2019-11-11 18:29:19 +00:00
|
|
|
boolean subscriptions = prefs.getBoolean("subscriptions", false);
|
2020-04-01 11:21:40 +00:00
|
|
|
if (subscriptions && !folder.read_only)
|
2020-10-14 08:10:18 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_subscribe, order++, R.string.title_subscribe)
|
2020-03-31 11:43:58 +00:00
|
|
|
.setCheckable(true).setChecked(folder.subscribed != null && folder.subscribed);
|
2019-11-11 18:29:19 +00:00
|
|
|
|
2020-10-14 08:10:18 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_synchronize_enabled, order++, R.string.title_synchronize_enabled)
|
2019-11-11 18:29:19 +00:00
|
|
|
.setCheckable(true).setChecked(folder.synchronize);
|
|
|
|
|
|
|
|
if (!folder.read_only)
|
2020-10-14 08:10:18 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_rules, order++, R.string.title_edit_rules);
|
2020-11-15 14:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_properties, order++, R.string.title_edit_properties);
|
2019-11-11 18:29:19 +00:00
|
|
|
|
2020-11-15 14:09:06 +00:00
|
|
|
if (folder.account != null && folder.accountProtocol == EntityAccount.TYPE_IMAP) {
|
2019-11-11 18:29:19 +00:00
|
|
|
if (folder.notify && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
String channelId = EntityFolder.getNotificationChannelId(folder.id);
|
|
|
|
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
NotificationChannel channel = nm.getNotificationChannel(channelId);
|
|
|
|
if (channel == null)
|
2020-10-14 08:10:18 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_create_channel, order++, R.string.title_create_channel);
|
2019-11-11 18:29:19 +00:00
|
|
|
else {
|
2020-10-14 08:10:18 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, order++, R.string.title_edit_channel);
|
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_channel, order++, R.string.title_delete_channel);
|
2019-11-11 18:29:19 +00:00
|
|
|
}
|
2019-05-16 08:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-18 08:23:53 +00:00
|
|
|
}
|
2018-09-08 16:32:13 +00:00
|
|
|
|
2020-07-01 06:57:17 +00:00
|
|
|
if (EntityFolder.INBOX.equals(folder.type) && folder.accountProtocol == EntityAccount.TYPE_POP)
|
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_rules, 11, R.string.title_edit_rules);
|
|
|
|
|
2020-11-19 12:51:00 +00:00
|
|
|
int childs = 0;
|
|
|
|
if (folder.child_refs != null)
|
|
|
|
for (TupleFolderEx child : folder.child_refs)
|
|
|
|
if (child.selectable)
|
|
|
|
childs++;
|
|
|
|
if (childs > 0) {
|
|
|
|
SubMenu submenu = popupMenu.getMenu()
|
|
|
|
.addSubMenu(Menu.NONE, Menu.NONE, order++, R.string.title_synchronize_subfolders);
|
|
|
|
|
|
|
|
submenu.add(Menu.FIRST, R.string.title_synchronize_now, 1, R.string.title_synchronize_now);
|
|
|
|
submenu.add(Menu.FIRST, R.string.title_synchronize_batch_enable, 2, R.string.title_synchronize_batch_enable);
|
|
|
|
submenu.add(Menu.FIRST, R.string.title_synchronize_batch_disable, 3, R.string.title_synchronize_batch_disable);
|
|
|
|
}
|
|
|
|
|
2019-11-23 12:48:59 +00:00
|
|
|
if (folder.account != null && folder.accountProtocol == EntityAccount.TYPE_IMAP)
|
2020-02-24 08:32:03 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_create_sub_folder, 16, R.string.title_create_sub_folder)
|
|
|
|
.setEnabled(folder.inferiors);
|
2019-11-11 18:29:19 +00:00
|
|
|
|
2020-04-16 14:25:10 +00:00
|
|
|
if (!folder.selectable && debug)
|
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete, 17, R.string.title_delete)
|
|
|
|
.setEnabled(folder.inferiors);
|
|
|
|
|
2018-09-08 06:23:53 +00:00
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
@Override
|
2019-05-03 13:18:32 +00:00
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
2020-11-18 21:32:41 +00:00
|
|
|
if (item.getGroupId() == Menu.FIRST) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.string.title_synchronize_now:
|
|
|
|
onActionSync(true);
|
|
|
|
return true;
|
2020-11-19 09:18:01 +00:00
|
|
|
case R.string.title_synchronize_batch_enable:
|
2020-11-18 21:32:41 +00:00
|
|
|
onActionEnable(true);
|
|
|
|
return true;
|
2020-11-19 09:18:01 +00:00
|
|
|
case R.string.title_synchronize_batch_disable:
|
2020-11-18 21:32:41 +00:00
|
|
|
onActionEnable(false);
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-03 13:18:32 +00:00
|
|
|
switch (item.getItemId()) {
|
2019-05-16 08:40:21 +00:00
|
|
|
case R.string.title_synchronize_now:
|
2020-10-14 08:10:18 +00:00
|
|
|
onActionSync(false);
|
|
|
|
return true;
|
2019-06-24 10:45:52 +00:00
|
|
|
|
2020-03-23 07:33:19 +00:00
|
|
|
case R.string.title_synchronize_more:
|
|
|
|
onActionSyncMore();
|
2018-11-22 17:46:58 +00:00
|
|
|
return true;
|
2018-09-08 06:23:53 +00:00
|
|
|
|
2019-05-25 15:14:51 +00:00
|
|
|
case R.string.title_unified_folder:
|
|
|
|
case R.string.title_navigation_folder:
|
|
|
|
case R.string.title_notify_folder:
|
2019-05-16 08:40:21 +00:00
|
|
|
case R.string.title_synchronize_enabled:
|
2019-05-25 15:14:51 +00:00
|
|
|
onActionProperty(item.getItemId(), !item.isChecked());
|
2019-05-03 13:18:32 +00:00
|
|
|
return true;
|
|
|
|
|
2019-07-14 20:44:03 +00:00
|
|
|
case R.string.title_subscribe:
|
|
|
|
onActionSubscribe();
|
|
|
|
return true;
|
|
|
|
|
2019-05-16 08:40:21 +00:00
|
|
|
case R.string.title_delete_local:
|
2019-03-09 14:09:30 +00:00
|
|
|
OnActionDeleteLocal(false);
|
|
|
|
return true;
|
|
|
|
|
2019-05-16 08:40:21 +00:00
|
|
|
case R.string.title_delete_browsed:
|
2019-03-09 14:09:30 +00:00
|
|
|
OnActionDeleteLocal(true);
|
2018-11-22 17:46:58 +00:00
|
|
|
return true;
|
2018-09-08 06:23:53 +00:00
|
|
|
|
2019-05-16 08:40:21 +00:00
|
|
|
case R.string.title_empty_trash:
|
2019-09-30 07:15:47 +00:00
|
|
|
onActionEmpty(EntityFolder.TRASH);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case R.string.title_empty_spam:
|
|
|
|
onActionEmpty(EntityFolder.JUNK);
|
2018-12-29 10:33:22 +00:00
|
|
|
return true;
|
|
|
|
|
2019-05-16 08:40:21 +00:00
|
|
|
case R.string.title_edit_rules:
|
2019-01-18 08:23:53 +00:00
|
|
|
onActionEditRules();
|
|
|
|
return true;
|
|
|
|
|
2019-05-16 08:40:21 +00:00
|
|
|
case R.string.title_edit_properties:
|
2019-02-21 07:38:30 +00:00
|
|
|
onActionEditProperties();
|
|
|
|
return true;
|
|
|
|
|
2019-05-16 08:40:21 +00:00
|
|
|
case R.string.title_create_channel:
|
2019-06-08 07:34:29 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
|
|
|
onActionCreateChannel();
|
2019-05-16 08:04:20 +00:00
|
|
|
return true;
|
|
|
|
|
2019-05-16 08:40:21 +00:00
|
|
|
case R.string.title_edit_channel:
|
2019-06-08 07:34:29 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
|
|
|
onActionEditChannel();
|
2019-05-16 08:04:20 +00:00
|
|
|
return true;
|
|
|
|
|
2019-05-16 08:40:21 +00:00
|
|
|
case R.string.title_delete_channel:
|
2019-06-08 07:34:29 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
|
|
|
onActionDeleteChannel();
|
2019-05-16 08:04:20 +00:00
|
|
|
return true;
|
|
|
|
|
2019-06-26 06:55:27 +00:00
|
|
|
case R.string.title_create_sub_folder:
|
|
|
|
onActionCreateFolder();
|
|
|
|
return true;
|
|
|
|
|
2020-04-16 14:25:10 +00:00
|
|
|
case R.string.title_delete:
|
|
|
|
onActionDeleteFolder();
|
|
|
|
return true;
|
|
|
|
|
2018-11-22 17:46:58 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2018-11-22 07:57:34 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-19 14:09:00 +00:00
|
|
|
|
2020-10-14 08:10:18 +00:00
|
|
|
private void onActionSync(boolean childs) {
|
2019-07-19 05:08:30 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("folder", folder.id);
|
2020-03-23 07:33:19 +00:00
|
|
|
args.putInt("months", -1);
|
2020-10-14 08:10:18 +00:00
|
|
|
args.putBoolean("childs", childs);
|
|
|
|
|
2019-07-19 05:08:30 +00:00
|
|
|
Intent data = new Intent();
|
|
|
|
data.putExtra("args", args);
|
|
|
|
parentFragment.onActivityResult(FragmentFolders.REQUEST_SYNC, RESULT_OK, data);
|
|
|
|
}
|
|
|
|
|
2020-11-18 21:32:41 +00:00
|
|
|
private void onActionEnable(boolean enabled) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", folder.id);
|
|
|
|
args.putLong("account", folder.account);
|
|
|
|
args.putBoolean("enabled", enabled);
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
long id = args.getLong("id");
|
|
|
|
long aid = args.getLong("account");
|
|
|
|
boolean enabled = args.getBoolean("enabled");
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
try {
|
|
|
|
db.beginTransaction();
|
|
|
|
List<EntityFolder> childs = db.folder().getChildFolders(id);
|
|
|
|
if (childs == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
for (EntityFolder child : childs)
|
|
|
|
db.folder().setFolderSynchronize(child.id, enabled);
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
} finally {
|
|
|
|
db.endTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
ServiceSynchronize.reload(context, aid, false, "child sync=" + enabled);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
|
|
|
}
|
|
|
|
}.execute(context, owner, args, "enable");
|
|
|
|
}
|
|
|
|
|
2020-03-23 07:33:19 +00:00
|
|
|
private void onActionSyncMore() {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("folder", folder.id);
|
|
|
|
args.putString("name", folder.getDisplayName(context));
|
2019-06-30 18:47:30 +00:00
|
|
|
|
2020-03-23 07:33:19 +00:00
|
|
|
FragmentDialogSync sync = new FragmentDialogSync();
|
|
|
|
sync.setArguments(args);
|
|
|
|
sync.setTargetFragment(parentFragment, FragmentFolders.REQUEST_SYNC);
|
|
|
|
sync.show(parentFragment.getParentFragmentManager(), "folder:sync");
|
2019-06-24 10:45:52 +00:00
|
|
|
}
|
|
|
|
|
2019-05-25 15:14:51 +00:00
|
|
|
private void onActionProperty(int property, boolean enabled) {
|
2019-05-03 13:18:32 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", folder.id);
|
2019-12-09 18:44:27 +00:00
|
|
|
args.putLong("account", folder.account);
|
2019-05-25 15:14:51 +00:00
|
|
|
args.putInt("property", property);
|
|
|
|
args.putBoolean("enabled", enabled);
|
2019-05-03 13:18:32 +00:00
|
|
|
|
2019-12-07 14:14:35 +00:00
|
|
|
new SimpleTask<Void>() {
|
2019-05-03 13:18:32 +00:00
|
|
|
@Override
|
2019-12-07 14:14:35 +00:00
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
2019-05-03 13:18:32 +00:00
|
|
|
long id = args.getLong("id");
|
2019-12-09 18:44:27 +00:00
|
|
|
long aid = args.getLong("account");
|
2019-05-25 15:14:51 +00:00
|
|
|
int property = args.getInt("property");
|
|
|
|
boolean enabled = args.getBoolean("enabled");
|
2019-05-03 13:18:32 +00:00
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
2019-05-25 15:14:51 +00:00
|
|
|
switch (property) {
|
|
|
|
case R.string.title_unified_folder:
|
|
|
|
db.folder().setFolderUnified(id, enabled);
|
2019-12-07 14:14:35 +00:00
|
|
|
break;
|
2019-05-25 15:14:51 +00:00
|
|
|
case R.string.title_navigation_folder:
|
|
|
|
db.folder().setFolderNavigation(id, enabled);
|
2019-12-07 14:14:35 +00:00
|
|
|
break;
|
2019-05-25 15:14:51 +00:00
|
|
|
case R.string.title_notify_folder:
|
|
|
|
db.folder().setFolderNotify(id, enabled);
|
2019-12-07 14:14:35 +00:00
|
|
|
break;
|
2019-05-25 15:14:51 +00:00
|
|
|
case R.string.title_synchronize_enabled:
|
|
|
|
db.folder().setFolderSynchronize(id, enabled);
|
2020-03-30 11:07:37 +00:00
|
|
|
ServiceSynchronize.reload(context, aid, false, "folder sync=" + enabled);
|
2019-12-07 14:14:35 +00:00
|
|
|
break;
|
2019-05-25 15:14:51 +00:00
|
|
|
default:
|
2019-12-07 14:14:35 +00:00
|
|
|
throw new IllegalArgumentException("Unknown folder property=" + property);
|
2019-05-25 15:14:51 +00:00
|
|
|
}
|
2019-05-03 13:18:32 +00:00
|
|
|
|
2019-12-07 14:14:35 +00:00
|
|
|
return null;
|
2019-05-03 13:18:32 +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-03 13:18:32 +00:00
|
|
|
}
|
|
|
|
}.execute(context, owner, args, "folder:enable");
|
|
|
|
}
|
|
|
|
|
2019-07-14 20:44:03 +00:00
|
|
|
private void onActionSubscribe() {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", folder.id);
|
2020-03-31 11:43:58 +00:00
|
|
|
args.putBoolean("subscribed", !(folder.subscribed != null && folder.subscribed));
|
2019-07-14 20:44:03 +00:00
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
|
|
|
long id = args.getLong("id");
|
|
|
|
boolean subscribed = args.getBoolean("subscribed");
|
|
|
|
|
|
|
|
EntityOperation.subscribe(context, id, subscribed);
|
2019-12-09 18:44:27 +00:00
|
|
|
ServiceSynchronize.eval(context, "subscribed=" + subscribed);
|
2019-07-14 20:44:03 +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-07-14 20:44:03 +00:00
|
|
|
}
|
|
|
|
}.execute(context, owner, args, "folder:subscribe");
|
|
|
|
}
|
|
|
|
|
2019-03-13 06:40:15 +00:00
|
|
|
private void OnActionDeleteLocal(final boolean browsed) {
|
2019-06-30 18:47:30 +00:00
|
|
|
Bundle aargs = new Bundle();
|
|
|
|
aargs.putString("question", context.getString(R.string.title_ask_delete_local));
|
|
|
|
aargs.putLong("folder", folder.id);
|
|
|
|
aargs.putBoolean("browsed", browsed);
|
|
|
|
|
|
|
|
FragmentDialogAsk ask = new FragmentDialogAsk();
|
|
|
|
ask.setArguments(aargs);
|
|
|
|
ask.setTargetFragment(parentFragment, FragmentFolders.REQUEST_DELETE_LOCAL);
|
2019-10-12 15:16:53 +00:00
|
|
|
ask.show(parentFragment.getParentFragmentManager(), "folder:delete_local");
|
2018-11-22 07:57:34 +00:00
|
|
|
}
|
2018-09-19 14:09:00 +00:00
|
|
|
|
2019-09-30 07:15:47 +00:00
|
|
|
private void onActionEmpty(String type) {
|
2019-06-30 18:47:30 +00:00
|
|
|
Bundle aargs = new Bundle();
|
2019-09-30 07:15:47 +00:00
|
|
|
if (EntityFolder.TRASH.equals(type))
|
|
|
|
aargs.putString("question", context.getString(R.string.title_empty_trash_ask));
|
|
|
|
else if (EntityFolder.JUNK.equals(type))
|
|
|
|
aargs.putString("question", context.getString(R.string.title_empty_spam_ask));
|
|
|
|
else
|
|
|
|
throw new IllegalArgumentException("Invalid folder type=" + type);
|
2020-10-25 13:55:58 +00:00
|
|
|
aargs.putBoolean("warning", true);
|
2020-07-26 10:16:48 +00:00
|
|
|
aargs.putString("remark", context.getString(R.string.title_empty_all));
|
2019-06-30 18:47:30 +00:00
|
|
|
aargs.putLong("folder", folder.id);
|
2019-09-30 07:15:47 +00:00
|
|
|
aargs.putString("type", type);
|
2019-06-30 18:47:30 +00:00
|
|
|
|
|
|
|
FragmentDialogAsk ask = new FragmentDialogAsk();
|
|
|
|
ask.setArguments(aargs);
|
2019-09-30 07:15:47 +00:00
|
|
|
ask.setTargetFragment(parentFragment, FragmentFolders.REQUEST_EMPTY_FOLDER);
|
2019-10-12 15:16:53 +00:00
|
|
|
ask.show(parentFragment.getParentFragmentManager(), "folder:empty");
|
2018-12-29 10:33:22 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 08:23:53 +00:00
|
|
|
private void onActionEditRules() {
|
|
|
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
|
|
|
lbm.sendBroadcast(
|
|
|
|
new Intent(ActivityView.ACTION_EDIT_RULES)
|
|
|
|
.putExtra("account", folder.account)
|
2020-09-05 20:55:34 +00:00
|
|
|
.putExtra("protocol", folder.accountProtocol)
|
2020-07-01 06:57:17 +00:00
|
|
|
.putExtra("folder", folder.id)
|
2020-09-05 20:55:34 +00:00
|
|
|
.putExtra("type", folder.type));
|
2019-01-18 08:23:53 +00:00
|
|
|
}
|
2019-02-21 07:38:30 +00:00
|
|
|
|
|
|
|
private void onActionEditProperties() {
|
|
|
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
|
|
|
lbm.sendBroadcast(
|
|
|
|
new Intent(ActivityView.ACTION_EDIT_FOLDER)
|
2020-11-15 14:09:06 +00:00
|
|
|
.putExtra("id", folder.id)
|
|
|
|
.putExtra("imap", folder.accountProtocol == EntityAccount.TYPE_IMAP));
|
2019-02-21 07:38:30 +00:00
|
|
|
}
|
2019-05-16 08:04:20 +00:00
|
|
|
|
2019-06-08 07:34:29 +00:00
|
|
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
2019-05-16 08:04:20 +00:00
|
|
|
private void onActionCreateChannel() {
|
2019-08-13 08:27:17 +00:00
|
|
|
if (!ActivityBilling.isPro(context)) {
|
2019-09-09 12:58:31 +00:00
|
|
|
context.startActivity(new Intent(context, ActivityBilling.class));
|
2019-05-16 09:10:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-16 08:04:20 +00:00
|
|
|
folder.createNotificationChannel(context);
|
|
|
|
onActionEditChannel();
|
|
|
|
}
|
|
|
|
|
2019-06-08 07:34:29 +00:00
|
|
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
2019-05-16 08:04:20 +00:00
|
|
|
private void onActionEditChannel() {
|
|
|
|
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
|
|
|
.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName())
|
|
|
|
.putExtra(Settings.EXTRA_CHANNEL_ID, EntityFolder.getNotificationChannelId(folder.id));
|
2020-06-25 14:02:25 +00:00
|
|
|
try {
|
|
|
|
context.startActivity(intent);
|
|
|
|
} catch (ActivityNotFoundException ex) {
|
|
|
|
Log.w(ex);
|
|
|
|
ToastEx.makeText(context, context.getString(R.string.title_no_viewer, intent), Toast.LENGTH_LONG).show();
|
|
|
|
}
|
2019-05-16 08:04:20 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 07:34:29 +00:00
|
|
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
2019-05-16 08:04:20 +00:00
|
|
|
private void onActionDeleteChannel() {
|
|
|
|
folder.deleteNotificationChannel(context);
|
|
|
|
}
|
2019-06-26 06:55:27 +00:00
|
|
|
|
|
|
|
private void onActionCreateFolder() {
|
|
|
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
|
|
|
lbm.sendBroadcast(
|
|
|
|
new Intent(ActivityView.ACTION_EDIT_FOLDER)
|
|
|
|
.putExtra("account", folder.account)
|
|
|
|
.putExtra("parent", folder.name));
|
|
|
|
}
|
2020-04-16 14:25:10 +00:00
|
|
|
|
|
|
|
private void onActionDeleteFolder() {
|
|
|
|
Bundle aargs = new Bundle();
|
|
|
|
aargs.putLong("id", folder.id);
|
|
|
|
aargs.putString("question", context.getString(R.string.title_folder_delete));
|
2020-10-25 13:55:58 +00:00
|
|
|
aargs.putBoolean("warning", true);
|
2020-04-16 14:25:10 +00:00
|
|
|
|
|
|
|
FragmentDialogAsk ask = new FragmentDialogAsk();
|
|
|
|
ask.setArguments(aargs);
|
|
|
|
ask.setTargetFragment(parentFragment, FragmentFolders.REQUEST_DELETE_FOLDER);
|
|
|
|
ask.show(parentFragment.getParentFragmentManager(), "folder:delete");
|
|
|
|
}
|
2018-09-08 06:23:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
popupMenu.show();
|
2018-08-26 08:33:22 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 06:46:49 +00:00
|
|
|
AdapterFolder(Fragment parentFragment, long account, boolean primary, boolean show_compact, boolean show_hidden, boolean show_flagged, IFolderSelectedListener listener) {
|
|
|
|
this(parentFragment.getContext(), parentFragment.getViewLifecycleOwner(), account, primary, show_compact, show_hidden, show_flagged, listener);
|
2019-06-30 18:47:30 +00:00
|
|
|
this.parentFragment = parentFragment;
|
2019-07-01 08:59:38 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 06:46:49 +00:00
|
|
|
AdapterFolder(Context context, LifecycleOwner owner, long account, boolean primary, boolean show_compact, boolean show_hidden, boolean show_flagged, IFolderSelectedListener listener) {
|
2019-05-25 20:09:15 +00:00
|
|
|
this.account = account;
|
2020-04-15 18:53:46 +00:00
|
|
|
this.primary = primary;
|
2019-10-03 13:57:21 +00:00
|
|
|
this.show_compact = show_compact;
|
2019-07-01 07:30:07 +00:00
|
|
|
this.show_hidden = show_hidden;
|
2020-05-19 06:46:49 +00:00
|
|
|
this.show_flagged = show_flagged;
|
2019-05-25 20:51:44 +00:00
|
|
|
this.listener = listener;
|
2018-11-26 13:48:59 +00:00
|
|
|
|
2019-07-01 08:59:38 +00:00
|
|
|
this.context = context;
|
|
|
|
this.owner = owner;
|
2019-07-01 07:30:07 +00:00
|
|
|
this.inflater = LayoutInflater.from(context);
|
|
|
|
|
2018-11-26 13:48:59 +00:00
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
2019-01-22 15:43:58 +00:00
|
|
|
boolean compact = prefs.getBoolean("compact", false);
|
2019-11-15 15:08:03 +00:00
|
|
|
int zoom = prefs.getInt("view_zoom", compact ? 0 : 1);
|
2019-01-22 15:43:58 +00:00
|
|
|
if (zoom == 0)
|
|
|
|
zoom = 1;
|
|
|
|
|
2019-04-25 17:02:37 +00:00
|
|
|
this.subscriptions = prefs.getBoolean("subscriptions", false);
|
2020-03-31 11:43:58 +00:00
|
|
|
this.subscribed_only = prefs.getBoolean("subscribed_only", false) && subscriptions;
|
2018-11-26 13:48:59 +00:00
|
|
|
|
2018-12-30 14:35:19 +00:00
|
|
|
this.dp12 = Helper.dp2pixels(context, 12);
|
2019-01-22 15:43:58 +00:00
|
|
|
this.textSize = Helper.getTextSize(context, zoom);
|
2019-08-16 14:24:03 +00:00
|
|
|
this.textColorPrimary = Helper.resolveColor(context, android.R.attr.textColorPrimary);
|
2019-01-05 14:24:04 +00:00
|
|
|
this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
|
2018-12-03 09:39:44 +00:00
|
|
|
|
2020-03-08 20:25:20 +00:00
|
|
|
boolean highlight_unread = prefs.getBoolean("highlight_unread", true);
|
2020-10-07 06:23:51 +00:00
|
|
|
int colorHighlight = prefs.getInt("highlight_color", Helper.resolveColor(context, R.attr.colorUnreadHighlight));
|
|
|
|
this.colorUnread = (highlight_unread ? colorHighlight : Helper.resolveColor(context, R.attr.colorUnread));
|
2020-12-08 07:12:20 +00:00
|
|
|
this.colorControlNormal = Helper.resolveColor(context, R.attr.colorControlNormal);
|
2019-09-08 15:27:50 +00:00
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
setHasStableIds(true);
|
2019-07-01 07:30:07 +00:00
|
|
|
|
|
|
|
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
|
|
|
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
|
|
|
public void onDestroyed() {
|
2019-12-07 16:02:42 +00:00
|
|
|
Log.d(AdapterFolder.this + " parent destroyed");
|
2019-07-01 07:30:07 +00:00
|
|
|
AdapterFolder.this.parentFragment = null;
|
|
|
|
}
|
|
|
|
});
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
2019-10-03 13:57:21 +00:00
|
|
|
void setCompact(boolean compact) {
|
2020-11-19 10:46:20 +00:00
|
|
|
if (this.show_compact != compact)
|
2019-10-03 13:57:21 +00:00
|
|
|
this.show_compact = compact;
|
|
|
|
}
|
|
|
|
|
2019-06-15 09:58:56 +00:00
|
|
|
void setShowHidden(boolean show_hidden) {
|
|
|
|
if (this.show_hidden != show_hidden) {
|
|
|
|
this.show_hidden = show_hidden;
|
|
|
|
set(all);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 06:46:49 +00:00
|
|
|
void setShowFlagged(boolean show_flagged) {
|
2020-11-19 10:46:20 +00:00
|
|
|
if (this.show_flagged != show_flagged)
|
2020-05-19 06:46:49 +00:00
|
|
|
this.show_flagged = show_flagged;
|
|
|
|
}
|
|
|
|
|
2020-03-31 11:43:58 +00:00
|
|
|
void setSubscribedOnly(boolean subscribed_only) {
|
|
|
|
if (this.subscribed_only != subscribed_only) {
|
|
|
|
this.subscribed_only = subscribed_only;
|
|
|
|
set(all);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 11:15:56 +00:00
|
|
|
void setDisabled(List<Long> ids) {
|
|
|
|
disabledIds = ids;
|
|
|
|
}
|
|
|
|
|
2019-05-25 20:09:15 +00:00
|
|
|
public void set(@NonNull List<TupleFolderEx> folders) {
|
|
|
|
Log.i("Set folders=" + folders.size());
|
2019-06-06 08:14:49 +00:00
|
|
|
all = folders;
|
2019-03-18 13:08:31 +00:00
|
|
|
|
2019-06-07 15:08:57 +00:00
|
|
|
List<TupleFolderEx> hierarchical;
|
2020-04-15 18:53:46 +00:00
|
|
|
if (account < 0 && !primary) {
|
2019-07-29 21:21:49 +00:00
|
|
|
if (folders.size() > 0)
|
|
|
|
Collections.sort(folders, folders.get(0).getComparator(context));
|
2019-06-07 15:08:57 +00:00
|
|
|
hierarchical = folders;
|
2019-07-29 21:21:49 +00:00
|
|
|
} else {
|
2019-06-07 15:08:57 +00:00
|
|
|
List<TupleFolderEx> parents = new ArrayList<>();
|
|
|
|
Map<Long, TupleFolderEx> idFolder = new HashMap<>();
|
|
|
|
Map<Long, List<TupleFolderEx>> parentChilds = new HashMap<>();
|
|
|
|
|
|
|
|
for (TupleFolderEx folder : folders) {
|
|
|
|
idFolder.put(folder.id, folder);
|
|
|
|
if (folder.parent == null)
|
|
|
|
parents.add(folder);
|
|
|
|
else {
|
|
|
|
if (!parentChilds.containsKey(folder.parent))
|
|
|
|
parentChilds.put(folder.parent, new ArrayList<TupleFolderEx>());
|
|
|
|
parentChilds.get(folder.parent).add(folder);
|
|
|
|
}
|
2019-05-25 20:09:15 +00:00
|
|
|
}
|
2018-09-21 15:19:37 +00:00
|
|
|
|
2019-06-07 15:08:57 +00:00
|
|
|
TupleFolderEx root = new TupleFolderEx();
|
|
|
|
root.name = "[root]";
|
|
|
|
root.child_refs = parents;
|
|
|
|
for (TupleFolderEx parent : parents)
|
|
|
|
parent.parent_ref = root;
|
|
|
|
|
|
|
|
for (long pid : parentChilds.keySet()) {
|
|
|
|
TupleFolderEx parent = idFolder.get(pid);
|
|
|
|
if (parent != null) {
|
|
|
|
parent.child_refs = parentChilds.get(pid);
|
|
|
|
for (TupleFolderEx child : parent.child_refs)
|
|
|
|
child.parent_ref = parent;
|
|
|
|
}
|
2019-05-25 20:51:44 +00:00
|
|
|
}
|
2019-05-25 20:09:15 +00:00
|
|
|
|
2019-06-07 16:25:32 +00:00
|
|
|
boolean anyChild = false;
|
|
|
|
for (TupleFolderEx parent : parents)
|
|
|
|
if (parent.child_refs != null && parent.child_refs.size() > 0) {
|
|
|
|
anyChild = true;
|
|
|
|
break;
|
|
|
|
}
|
2019-07-29 21:21:49 +00:00
|
|
|
for (TupleFolderEx parent : parents) {
|
2019-06-07 16:25:32 +00:00
|
|
|
parent.expander = anyChild;
|
|
|
|
|
2019-07-29 21:21:49 +00:00
|
|
|
if (!parent.selectable && parent.child_refs != null && EntityFolder.USER.equals(parent.type))
|
|
|
|
for (TupleFolderEx child : parent.child_refs)
|
|
|
|
if (!EntityFolder.USER.equals(child.type)) {
|
|
|
|
parent.type = EntityFolder.SYSTEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-07 16:25:32 +00:00
|
|
|
hierarchical = getHierarchical(parents, anyChild ? 0 : 1);
|
2019-06-07 15:08:57 +00:00
|
|
|
}
|
2019-05-25 20:09:15 +00:00
|
|
|
|
|
|
|
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, hierarchical), false);
|
|
|
|
|
|
|
|
items = hierarchical;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
|
|
|
diff.dispatchUpdatesTo(new ListUpdateCallback() {
|
|
|
|
@Override
|
|
|
|
public void onInserted(int position, int count) {
|
2019-12-07 16:02:42 +00:00
|
|
|
Log.d("Inserted @" + position + " #" + count);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRemoved(int position, int count) {
|
2019-12-07 16:02:42 +00:00
|
|
|
Log.d("Removed @" + position + " #" + count);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMoved(int fromPosition, int toPosition) {
|
2019-12-07 16:02:42 +00:00
|
|
|
Log.d("Moved " + fromPosition + ">" + toPosition);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChanged(int position, int count, Object payload) {
|
2019-12-07 16:02:42 +00:00
|
|
|
Log.d("Changed @" + position + " #" + count);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
});
|
2018-08-27 07:06:03 +00:00
|
|
|
diff.dispatchUpdatesTo(this);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 12:37:36 +00:00
|
|
|
public void search(String query, final int result, final ISearchResult intf) {
|
|
|
|
if (TextUtils.isEmpty(query)) {
|
|
|
|
intf.onNotFound();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expand all
|
|
|
|
for (TupleFolderEx folder : all)
|
|
|
|
folder.collapsed = false;
|
|
|
|
set(all);
|
|
|
|
|
|
|
|
// Delay search until after expanding
|
2020-08-23 15:34:14 +00:00
|
|
|
ApplicationEx.getMainHandler().post(new Runnable() {
|
2020-02-05 12:37:36 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
int pos = -1;
|
|
|
|
int next = -1;
|
|
|
|
int count = result + 1;
|
|
|
|
for (int i = 0; i < items.size(); i++)
|
|
|
|
if (items.get(i).getDisplayName(context).toLowerCase().contains(query.toLowerCase())) {
|
|
|
|
count--;
|
|
|
|
if (count == 0)
|
|
|
|
pos = i;
|
|
|
|
else if (count < 0) {
|
|
|
|
next = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pos < 0)
|
|
|
|
intf.onNotFound();
|
|
|
|
else
|
|
|
|
intf.onFound(pos, next >= 0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ISearchResult {
|
|
|
|
void onFound(int pos, boolean hasNext);
|
2019-12-08 16:22:55 +00:00
|
|
|
|
2020-02-05 12:37:36 +00:00
|
|
|
void onNotFound();
|
2019-12-08 16:22:55 +00:00
|
|
|
}
|
|
|
|
|
2019-07-29 21:21:49 +00:00
|
|
|
private List<TupleFolderEx> getHierarchical(List<TupleFolderEx> parents, int indentation) {
|
2019-05-25 20:09:15 +00:00
|
|
|
List<TupleFolderEx> result = new ArrayList<>();
|
|
|
|
|
2019-07-29 21:21:49 +00:00
|
|
|
if (parents.size() > 0)
|
|
|
|
Collections.sort(parents, parents.get(0).getComparator(context));
|
|
|
|
|
2020-06-11 12:15:59 +00:00
|
|
|
for (TupleFolderEx parent : parents) {
|
|
|
|
if (parent.hide && !show_hidden)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
List<TupleFolderEx> childs = null;
|
|
|
|
if (parent.child_refs != null)
|
|
|
|
childs = getHierarchical(parent.child_refs, indentation + 1);
|
|
|
|
|
|
|
|
if (!subscribed_only ||
|
|
|
|
parent.accountProtocol != EntityAccount.TYPE_IMAP ||
|
|
|
|
(parent.subscribed != null && parent.subscribed) ||
|
|
|
|
(childs != null && childs.size() > 0)) {
|
2019-06-15 09:58:56 +00:00
|
|
|
parent.indentation = indentation;
|
|
|
|
result.add(parent);
|
2020-06-11 12:15:59 +00:00
|
|
|
if (!parent.collapsed && childs != null)
|
|
|
|
result.addAll(childs);
|
2019-06-15 09:58:56 +00:00
|
|
|
}
|
2020-06-11 12:15:59 +00:00
|
|
|
}
|
2019-05-25 20:09:15 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-12-30 18:29:20 +00:00
|
|
|
private static class DiffCallback extends DiffUtil.Callback {
|
2019-03-15 11:53:22 +00:00
|
|
|
private List<TupleFolderEx> prev = new ArrayList<>();
|
|
|
|
private List<TupleFolderEx> next = new ArrayList<>();
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2019-02-10 18:02:55 +00:00
|
|
|
DiffCallback(List<TupleFolderEx> prev, List<TupleFolderEx> next) {
|
2019-03-15 11:53:22 +00:00
|
|
|
this.prev.addAll(prev);
|
|
|
|
this.next.addAll(next);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getOldListSize() {
|
|
|
|
return prev.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getNewListSize() {
|
|
|
|
return next.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
|
|
|
|
TupleFolderEx f1 = prev.get(oldItemPosition);
|
|
|
|
TupleFolderEx f2 = next.get(newItemPosition);
|
|
|
|
return f1.id.equals(f2.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
|
|
|
|
TupleFolderEx f1 = prev.get(oldItemPosition);
|
|
|
|
TupleFolderEx f2 = next.get(newItemPosition);
|
2019-05-31 06:32:20 +00:00
|
|
|
if (!f1.equals(f2))
|
|
|
|
return false;
|
|
|
|
|
2019-11-18 14:27:31 +00:00
|
|
|
if (f1.indentation != f2.indentation ||
|
|
|
|
f1.expander != f2.expander)
|
|
|
|
return false;
|
|
|
|
|
2019-05-31 06:32:20 +00:00
|
|
|
TupleFolderEx p1 = f1.parent_ref;
|
|
|
|
TupleFolderEx p2 = f2.parent_ref;
|
|
|
|
while (p1 != null && p2 != null) {
|
2019-06-15 09:58:56 +00:00
|
|
|
if (p1.hide != p2.hide)
|
|
|
|
return false;
|
|
|
|
|
2019-05-31 06:32:20 +00:00
|
|
|
if (p1.collapsed != p2.collapsed)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
p1 = p1.parent_ref;
|
|
|
|
p2 = p2.parent_ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
2019-03-18 08:33:40 +00:00
|
|
|
return items.get(position).id;
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
2019-03-18 08:33:40 +00:00
|
|
|
return items.size();
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
2019-07-08 13:22:52 +00:00
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
2019-10-03 13:57:21 +00:00
|
|
|
if (listener == null)
|
2019-07-08 13:22:52 +00:00
|
|
|
return (items.get(position).selectable ? R.layout.item_folder : R.layout.item_folder_unselectable);
|
2019-10-03 13:57:21 +00:00
|
|
|
else
|
2019-07-08 13:22:52 +00:00
|
|
|
return R.layout.item_folder_select;
|
|
|
|
}
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
@Override
|
|
|
|
@NonNull
|
|
|
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
2019-07-08 13:22:52 +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-03-18 08:33:40 +00:00
|
|
|
TupleFolderEx folder = items.get(position);
|
2020-11-12 07:07:30 +00:00
|
|
|
holder.powner.recreate(folder == null ? null : folder.id);
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2020-11-12 07:07:30 +00:00
|
|
|
holder.unwire();
|
|
|
|
holder.bindTo(folder);
|
2018-09-08 16:32:13 +00:00
|
|
|
holder.wire();
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
2019-05-25 20:51:44 +00:00
|
|
|
|
|
|
|
interface IFolderSelectedListener {
|
|
|
|
void onFolderSelected(TupleFolderEx folder);
|
|
|
|
}
|
2020-03-23 07:33:19 +00:00
|
|
|
|
|
|
|
public static class FragmentDialogSync extends FragmentDialogBase {
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
|
|
|
String name = getArguments().getString("name");
|
|
|
|
|
2020-10-30 09:36:16 +00:00
|
|
|
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_sync, null);
|
2020-03-23 07:33:19 +00:00
|
|
|
final TextView tvFolder = view.findViewById(R.id.tvFolder);
|
|
|
|
final EditText etMonths = view.findViewById(R.id.etMonths);
|
|
|
|
|
|
|
|
tvFolder.setText(name);
|
|
|
|
etMonths.setText(null);
|
|
|
|
|
2020-10-30 09:36:16 +00:00
|
|
|
return new AlertDialog.Builder(getContext())
|
2020-03-23 07:33:19 +00:00
|
|
|
.setView(view)
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
String months = etMonths.getText().toString();
|
|
|
|
if (TextUtils.isEmpty(months))
|
|
|
|
getArguments().putInt("months", 0);
|
|
|
|
else
|
|
|
|
try {
|
|
|
|
getArguments().putInt("months", Integer.parseInt(months));
|
|
|
|
} catch (NumberFormatException ex) {
|
|
|
|
Log.e(ex);
|
|
|
|
}
|
|
|
|
sendResult(RESULT_OK);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.create();
|
|
|
|
}
|
|
|
|
}
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|