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
|
|
|
*/
|
|
|
|
|
|
|
|
import android.content.Context;
|
2018-12-29 10:33:22 +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;
|
2018-09-08 06:23:53 +00:00
|
|
|
import android.os.Bundle;
|
2018-11-26 13:48:59 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2018-11-26 08:12:44 +00:00
|
|
|
import android.text.TextUtils;
|
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;
|
2018-08-02 13:33:06 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2019-02-20 09:49:17 +00:00
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2018-08-08 06:55:47 +00:00
|
|
|
import androidx.annotation.NonNull;
|
2018-09-08 06:23:53 +00:00
|
|
|
import androidx.appcompat.widget.PopupMenu;
|
|
|
|
import androidx.lifecycle.LifecycleOwner;
|
2018-08-08 06:55:47 +00:00
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
|
import androidx.recyclerview.widget.DiffUtil;
|
|
|
|
import androidx.recyclerview.widget.ListUpdateCallback;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder> {
|
|
|
|
private Context context;
|
2018-12-24 13:41:49 +00:00
|
|
|
private LayoutInflater inflater;
|
2018-09-08 06:23:53 +00:00
|
|
|
private LifecycleOwner owner;
|
2018-12-24 13:41:49 +00:00
|
|
|
|
2018-12-02 09:09:21 +00:00
|
|
|
private long account;
|
2018-11-26 13:48:59 +00:00
|
|
|
private boolean debug;
|
2018-12-03 09:39:44 +00:00
|
|
|
private int dp12;
|
2019-01-22 15:43:58 +00:00
|
|
|
private float textSize;
|
2019-01-05 14:24:04 +00:00
|
|
|
private int colorUnread;
|
|
|
|
private int textColorSecondary;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
|
|
|
private List<TupleFolderEx> all = new ArrayList<>();
|
|
|
|
private List<TupleFolderEx> filtered = new ArrayList<>();
|
|
|
|
|
2018-08-26 08:33:22 +00:00
|
|
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
2018-11-26 08:12:44 +00:00
|
|
|
private View itemView;
|
2018-12-02 09:09:21 +00:00
|
|
|
private View vwColor;
|
2018-12-03 09:39:44 +00:00
|
|
|
private View vwLevel;
|
2018-11-26 08:12:44 +00:00
|
|
|
private ImageView ivState;
|
2018-12-09 08:38:23 +00:00
|
|
|
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;
|
2018-11-26 08:12:44 +00:00
|
|
|
private ImageView ivUnified;
|
|
|
|
private TextView tvType;
|
|
|
|
private TextView tvAfter;
|
|
|
|
private ImageView ivSync;
|
|
|
|
private TextView tvKeywords;
|
|
|
|
private TextView tvError;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-09-14 07:24:34 +00:00
|
|
|
private final static int action_synchronize_now = 1;
|
|
|
|
private final static int action_delete_local = 2;
|
2018-12-29 10:33:22 +00:00
|
|
|
private final static int action_empty_trash = 3;
|
|
|
|
private final static int action_edit_properties = 4;
|
2019-01-18 08:23:53 +00:00
|
|
|
private final static int action_edit_rules = 5;
|
2018-09-08 06:23:53 +00:00
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
ViewHolder(View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
|
2018-09-21 15:19:37 +00:00
|
|
|
this.itemView = itemView.findViewById(R.id.clItem);
|
2018-12-02 09:09:21 +00:00
|
|
|
vwColor = itemView.findViewById(R.id.vwColor);
|
2018-12-03 09:39:44 +00:00
|
|
|
vwLevel = itemView.findViewById(R.id.vwLevel);
|
2018-09-08 16:32:13 +00:00
|
|
|
ivState = itemView.findViewById(R.id.ivState);
|
2018-12-09 08:38:23 +00:00
|
|
|
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);
|
2018-09-05 09:41:16 +00:00
|
|
|
ivUnified = itemView.findViewById(R.id.ivUnified);
|
2018-09-08 16:32:13 +00:00
|
|
|
tvType = itemView.findViewById(R.id.tvType);
|
2018-08-02 13:33:06 +00:00
|
|
|
tvAfter = itemView.findViewById(R.id.tvAfter);
|
|
|
|
ivSync = itemView.findViewById(R.id.ivSync);
|
2018-11-26 08:12:44 +00:00
|
|
|
tvKeywords = itemView.findViewById(R.id.tvKeywords);
|
2018-08-11 08:28:54 +00:00
|
|
|
tvError = itemView.findViewById(R.id.tvError);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
2018-09-08 16:32:13 +00:00
|
|
|
private void wire() {
|
2018-08-02 13:33:06 +00:00
|
|
|
itemView.setOnClickListener(this);
|
2018-08-26 08:33:22 +00:00
|
|
|
itemView.setOnLongClickListener(this);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void unwire() {
|
|
|
|
itemView.setOnClickListener(null);
|
2018-08-26 08:33:22 +00:00
|
|
|
itemView.setOnLongClickListener(null);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 06:51:49 +00:00
|
|
|
private void bindTo(TupleFolderEx folder) {
|
2019-02-04 10:19:17 +00:00
|
|
|
itemView.setActivated(folder.tbc != null || folder.tbd != null);
|
2018-09-21 15:19:37 +00:00
|
|
|
itemView.setAlpha(folder.hide ? 0.5f : 1.0f);
|
|
|
|
|
2019-01-22 15:43:58 +00:00
|
|
|
if (textSize != 0)
|
|
|
|
tvName.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
|
|
|
|
2018-12-02 09:09:21 +00:00
|
|
|
vwColor.setBackgroundColor(folder.accountColor == null ? Color.TRANSPARENT : folder.accountColor);
|
2018-12-18 15:42:28 +00:00
|
|
|
vwColor.setVisibility(account < 0 ? View.VISIBLE : View.GONE);
|
2018-12-02 09:09:21 +00:00
|
|
|
|
2018-12-03 09:39:44 +00:00
|
|
|
if (account > 0) {
|
|
|
|
ViewGroup.LayoutParams lp = vwLevel.getLayoutParams();
|
2018-12-13 17:20:24 +00:00
|
|
|
lp.width = (EntityFolder.USER.equals(folder.type) ? folder.level : 0) * dp12;
|
2018-12-03 09:39:44 +00:00
|
|
|
vwLevel.setLayoutParams(lp);
|
|
|
|
}
|
|
|
|
|
2019-02-28 12:35:19 +00:00
|
|
|
if (folder.sync_state == null ||
|
|
|
|
"requested".equals(folder.sync_state) || "manual".equals(folder.sync_state)) {
|
2019-02-02 08:13:48 +00:00
|
|
|
if ("waiting".equals(folder.state))
|
|
|
|
ivState.setImageResource(R.drawable.baseline_hourglass_empty_24);
|
|
|
|
else if ("connected".equals(folder.state))
|
2018-12-03 12:41:36 +00:00
|
|
|
ivState.setImageResource(R.drawable.baseline_cloud_24);
|
|
|
|
else if ("connecting".equals(folder.state))
|
|
|
|
ivState.setImageResource(R.drawable.baseline_cloud_queue_24);
|
|
|
|
else if ("closing".equals(folder.state))
|
|
|
|
ivState.setImageResource(R.drawable.baseline_close_24);
|
|
|
|
else if (folder.state == null)
|
2019-02-28 12:35:19 +00:00
|
|
|
ivState.setImageResource(R.drawable.baseline_cloud_off_24);
|
2018-12-03 12:41:36 +00:00
|
|
|
else
|
|
|
|
ivState.setImageResource(android.R.drawable.stat_sys_warning);
|
|
|
|
} else {
|
2019-02-28 12:35:19 +00:00
|
|
|
if ("syncing".equals(folder.sync_state))
|
2018-12-03 12:41:36 +00:00
|
|
|
ivState.setImageResource(R.drawable.baseline_compare_arrows_24);
|
|
|
|
else if ("downloading".equals(folder.sync_state))
|
|
|
|
ivState.setImageResource(R.drawable.baseline_cloud_download_24);
|
|
|
|
else
|
|
|
|
ivState.setImageResource(android.R.drawable.stat_sys_warning);
|
|
|
|
}
|
|
|
|
ivState.setVisibility(
|
|
|
|
folder.synchronize || folder.state != null || folder.sync_state != null
|
|
|
|
? View.VISIBLE : View.INVISIBLE);
|
2018-08-14 09:09:44 +00:00
|
|
|
|
2018-12-09 08:38:23 +00:00
|
|
|
ivNotify.setVisibility(folder.notify ? View.VISIBLE : View.GONE);
|
|
|
|
|
2018-12-01 09:17:49 +00:00
|
|
|
String name = folder.getDisplayName(context);
|
2018-08-07 17:44:25 +00:00
|
|
|
if (folder.unseen > 0)
|
2018-12-16 16:39:15 +00:00
|
|
|
tvName.setText(context.getString(R.string.title_unseen_count, name, folder.unseen));
|
2018-08-07 17:44:25 +00:00
|
|
|
else
|
|
|
|
tvName.setText(name);
|
2018-08-07 06:51:49 +00:00
|
|
|
tvName.setTypeface(null, folder.unseen > 0 ? Typeface.BOLD : Typeface.NORMAL);
|
2019-01-05 14:24:04 +00:00
|
|
|
tvName.setTextColor(folder.unseen > 0 ? colorUnread : textColorSecondary);
|
2018-08-07 06:51:49 +00:00
|
|
|
|
2018-09-16 18:07:26 +00:00
|
|
|
tvMessages.setText(String.format("%d/%d", folder.content, folder.messages));
|
2019-01-05 17:09:12 +00:00
|
|
|
ivMessages.setImageResource(folder.download || EntityFolder.OUTBOX.equals(folder.type)
|
2019-01-05 14:24:04 +00:00
|
|
|
? R.drawable.baseline_mail_24 : R.drawable.baseline_mail_outline_24);
|
2018-08-07 06:51:49 +00:00
|
|
|
|
2018-12-02 09:09:21 +00:00
|
|
|
ivUnified.setVisibility(account > 0 && folder.unified ? View.VISIBLE : View.INVISIBLE);
|
2018-09-08 16:32:13 +00:00
|
|
|
|
2018-12-02 09:09:21 +00:00
|
|
|
if (account < 0)
|
|
|
|
tvType.setText(folder.accountName);
|
|
|
|
else {
|
|
|
|
int resid = context.getResources().getIdentifier(
|
|
|
|
"title_folder_" + folder.type.toLowerCase(),
|
|
|
|
"string",
|
|
|
|
context.getPackageName());
|
|
|
|
tvType.setText(resid > 0 ? context.getString(resid) : folder.type);
|
|
|
|
}
|
2018-08-07 17:44:25 +00:00
|
|
|
|
2018-09-08 16:32:13 +00:00
|
|
|
if (folder.account == null) {
|
|
|
|
tvAfter.setText(null);
|
2018-09-14 13:13:26 +00:00
|
|
|
ivSync.setImageResource(R.drawable.baseline_sync_24);
|
2018-09-08 16:32:13 +00:00
|
|
|
} else {
|
2018-12-10 10:23:20 +00:00
|
|
|
if (folder.keep_days == Integer.MAX_VALUE)
|
|
|
|
tvAfter.setText(String.format("%d/∞", folder.sync_days));
|
|
|
|
else
|
|
|
|
tvAfter.setText(String.format("%d/%d", folder.sync_days, folder.keep_days));
|
2018-09-08 16:32:13 +00:00
|
|
|
ivSync.setImageResource(folder.synchronize ? R.drawable.baseline_sync_24 : R.drawable.baseline_sync_disabled_24);
|
|
|
|
}
|
2018-12-11 11:18:26 +00:00
|
|
|
ivSync.setImageTintList(ColorStateList.valueOf(
|
2019-01-05 14:24:04 +00:00
|
|
|
folder.synchronize && folder.initialize && !EntityFolder.OUTBOX.equals(folder.type)
|
|
|
|
? colorUnread : textColorSecondary));
|
2018-08-13 14:44:47 +00:00
|
|
|
|
2018-11-26 08:12:44 +00:00
|
|
|
tvKeywords.setText(TextUtils.join(" ", folder.keywords));
|
2018-11-26 13:48:59 +00:00
|
|
|
tvKeywords.setVisibility(debug && folder.keywords.length > 0 ? View.VISIBLE : View.GONE);
|
2018-11-26 08:12:44 +00:00
|
|
|
|
2018-08-11 08:28:54 +00:00
|
|
|
tvError.setText(folder.error);
|
2019-02-10 19:21:07 +00:00
|
|
|
tvError.setVisibility(folder.error != null ? View.VISIBLE : View.GONE);
|
2018-08-07 06:51:49 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2018-08-05 18:36:39 +00:00
|
|
|
int pos = getAdapterPosition();
|
|
|
|
if (pos == RecyclerView.NO_POSITION)
|
|
|
|
return;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-08-05 18:36:39 +00:00
|
|
|
TupleFolderEx folder = filtered.get(pos);
|
2019-01-12 11:02:26 +00:00
|
|
|
if (folder.tbd != null)
|
|
|
|
return;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-09-08 16:32:13 +00:00
|
|
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
|
|
|
lbm.sendBroadcast(
|
|
|
|
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
|
2018-10-17 09:15:44 +00:00
|
|
|
.putExtra("account", folder.account)
|
2019-01-19 09:48:45 +00:00
|
|
|
.putExtra("folder", folder.id));
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
2018-08-26 08:33:22 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
int pos = getAdapterPosition();
|
|
|
|
if (pos == RecyclerView.NO_POSITION)
|
|
|
|
return false;
|
|
|
|
|
2018-09-08 06:23:53 +00:00
|
|
|
final TupleFolderEx folder = filtered.get(pos);
|
2019-01-12 11:02:26 +00:00
|
|
|
if (folder.tbd != null)
|
|
|
|
return false;
|
2018-09-08 06:23:53 +00:00
|
|
|
|
|
|
|
PopupMenu popupMenu = new PopupMenu(context, itemView);
|
2018-09-08 16:32:13 +00:00
|
|
|
|
2019-02-27 19:55:33 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, action_synchronize_now, 1, R.string.title_synchronize_now);
|
2018-09-08 16:32:13 +00:00
|
|
|
|
2019-02-11 21:46:12 +00:00
|
|
|
if (folder.account != null)
|
2019-01-21 19:11:14 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, action_delete_local, 2, R.string.title_delete_local);
|
|
|
|
|
2019-02-11 21:46:12 +00:00
|
|
|
if (EntityFolder.TRASH.equals(folder.type))
|
2018-12-29 10:33:22 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, action_empty_trash, 3, R.string.title_empty_trash);
|
2018-09-09 05:59:48 +00:00
|
|
|
|
2019-01-18 08:23:53 +00:00
|
|
|
if (folder.account != null) {
|
2019-02-21 07:38:30 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, action_edit_rules, 4, R.string.title_edit_rules);
|
|
|
|
popupMenu.getMenu().add(Menu.NONE, action_edit_properties, 5, R.string.title_edit_properties);
|
2019-01-18 08:23:53 +00:00
|
|
|
}
|
2018-09-08 16:32:13 +00:00
|
|
|
|
2018-09-08 06:23:53 +00:00
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemClick(MenuItem target) {
|
|
|
|
switch (target.getItemId()) {
|
2018-09-14 07:24:34 +00:00
|
|
|
case action_synchronize_now:
|
2018-11-22 07:57:34 +00:00
|
|
|
onActionSynchronizeNow();
|
2018-11-22 17:46:58 +00:00
|
|
|
return true;
|
2018-09-08 06:23:53 +00:00
|
|
|
|
2018-09-14 07:24:34 +00:00
|
|
|
case action_delete_local:
|
2018-11-22 07:57:34 +00:00
|
|
|
OnActionDeleteLocal();
|
2018-11-22 17:46:58 +00:00
|
|
|
return true;
|
2018-09-08 06:23:53 +00:00
|
|
|
|
2018-12-29 10:33:22 +00:00
|
|
|
case action_empty_trash:
|
|
|
|
onActionEmptyTrash();
|
|
|
|
return true;
|
|
|
|
|
2019-01-18 08:23:53 +00:00
|
|
|
case action_edit_rules:
|
|
|
|
onActionEditRules();
|
|
|
|
return true;
|
|
|
|
|
2019-02-21 07:38:30 +00:00
|
|
|
case action_edit_properties:
|
|
|
|
onActionEditProperties();
|
|
|
|
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
|
|
|
|
2018-11-22 07:57:34 +00:00
|
|
|
private void onActionSynchronizeNow() {
|
2018-12-02 13:19:54 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("folder", folder.id);
|
|
|
|
|
2019-02-28 19:17:09 +00:00
|
|
|
new SimpleTask<Void>() {
|
2018-12-02 13:19:54 +00:00
|
|
|
@Override
|
2019-02-28 19:17:09 +00:00
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
2018-12-06 08:09:30 +00:00
|
|
|
long fid = args.getLong("folder");
|
2018-12-02 13:19:54 +00:00
|
|
|
|
2019-02-28 19:17:09 +00:00
|
|
|
if (!Helper.isConnected(context))
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
|
2019-02-28 12:35:19 +00:00
|
|
|
|
2018-12-02 13:19:54 +00:00
|
|
|
DB db = DB.getInstance(context);
|
2019-02-17 18:04:22 +00:00
|
|
|
try {
|
|
|
|
db.beginTransaction();
|
|
|
|
|
2019-02-28 19:17:09 +00:00
|
|
|
EntityOperation.sync(context, fid);
|
2019-02-17 18:04:22 +00:00
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
2019-02-21 08:13:44 +00:00
|
|
|
|
2019-02-17 18:04:22 +00:00
|
|
|
} finally {
|
|
|
|
db.endTransaction();
|
|
|
|
}
|
|
|
|
|
2019-02-28 19:17:09 +00:00
|
|
|
return null;
|
2018-12-02 13:19:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
2019-02-21 19:54:47 +00:00
|
|
|
if (ex instanceof IllegalArgumentException)
|
|
|
|
Snackbar.make(itemView, ex.getMessage(), Snackbar.LENGTH_LONG).show();
|
2019-02-27 15:05:15 +00:00
|
|
|
else
|
2019-02-20 09:49:17 +00:00
|
|
|
Helper.unexpectedError(context, owner, ex);
|
2018-12-02 13:19:54 +00:00
|
|
|
}
|
2019-01-12 13:15:15 +00:00
|
|
|
}.execute(context, owner, args, "folder:sync");
|
2018-11-22 07:57:34 +00:00
|
|
|
}
|
2018-09-19 14:09:00 +00:00
|
|
|
|
2018-11-22 07:57:34 +00:00
|
|
|
private void OnActionDeleteLocal() {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", folder.id);
|
|
|
|
args.putBoolean("outbox", folder.account == null);
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
2018-12-31 07:03:48 +00:00
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
2018-11-22 07:57:34 +00:00
|
|
|
long id = args.getLong("id");
|
|
|
|
boolean outbox = args.getBoolean("outbox");
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("Delete local messages outbox=" + outbox);
|
2018-11-22 07:57:34 +00:00
|
|
|
if (outbox)
|
|
|
|
DB.getInstance(context).message().deleteSeenMessages(id);
|
|
|
|
else
|
|
|
|
DB.getInstance(context).message().deleteLocalMessages(id);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onException(Bundle args, Throwable ex) {
|
2018-12-01 12:04:41 +00:00
|
|
|
Helper.unexpectedError(context, owner, ex);
|
2018-11-22 07:57:34 +00:00
|
|
|
}
|
2019-01-12 13:15:15 +00:00
|
|
|
}.execute(context, owner, args, "folder:delete:local");
|
2018-11-22 07:57:34 +00:00
|
|
|
}
|
2018-09-19 14:09:00 +00:00
|
|
|
|
2018-12-29 10:33:22 +00:00
|
|
|
private void onActionEmptyTrash() {
|
|
|
|
new DialogBuilderLifecycle(context, owner)
|
|
|
|
.setMessage(R.string.title_empty_trash_ask)
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", folder.id);
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
2018-12-31 07:03:48 +00:00
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
2018-12-29 10:33:22 +00:00
|
|
|
long id = args.getLong("id");
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
try {
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
for (Long mid : db.message().getMessageByFolder(id)) {
|
|
|
|
EntityMessage message = db.message().getMessage(mid);
|
2019-01-04 18:37:56 +00:00
|
|
|
EntityOperation.queue(context, db, message, EntityOperation.DELETE);
|
2018-12-29 10:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
} finally {
|
|
|
|
db.endTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
Helper.unexpectedError(context, owner, ex);
|
|
|
|
}
|
2019-01-12 13:15:15 +00:00
|
|
|
}.execute(context, owner, args, "folder:delete");
|
2018-12-29 10:33:22 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
.putExtra("folder", folder.id));
|
|
|
|
}
|
2019-02-21 07:38:30 +00:00
|
|
|
|
|
|
|
private void onActionEditProperties() {
|
|
|
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
|
|
|
lbm.sendBroadcast(
|
|
|
|
new Intent(ActivityView.ACTION_EDIT_FOLDER)
|
|
|
|
.putExtra("id", folder.id));
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2018-09-08 06:23:53 +00:00
|
|
|
AdapterFolder(Context context, LifecycleOwner owner) {
|
2018-08-02 13:33:06 +00:00
|
|
|
this.context = context;
|
2018-12-24 13:41:49 +00:00
|
|
|
this.inflater = LayoutInflater.from(context);
|
2018-09-08 06:23:53 +00:00
|
|
|
this.owner = owner;
|
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);
|
|
|
|
int zoom = prefs.getInt("zoom", compact ? 0 : 1);
|
|
|
|
if (zoom == 0)
|
|
|
|
zoom = 1;
|
|
|
|
|
2018-11-26 13:48:59 +00:00
|
|
|
this.debug = prefs.getBoolean("debug", false);
|
|
|
|
|
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-01-05 14:24:04 +00:00
|
|
|
this.colorUnread = Helper.resolveColor(context, R.attr.colorUnread);
|
|
|
|
this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
|
2018-12-03 09:39:44 +00:00
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
setHasStableIds(true);
|
|
|
|
}
|
|
|
|
|
2018-11-26 08:12:44 +00:00
|
|
|
void showHidden(boolean show) {
|
2019-02-21 07:34:23 +00:00
|
|
|
set(account, show, all);
|
2018-09-21 15:19:37 +00:00
|
|
|
}
|
|
|
|
|
2019-02-21 07:34:23 +00:00
|
|
|
public void set(long account, boolean showAll, @NonNull List<TupleFolderEx> _folders) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("Set account=" + account + " folders=" + _folders.size());
|
2018-12-02 09:09:21 +00:00
|
|
|
|
|
|
|
this.account = account;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-12-22 10:44:44 +00:00
|
|
|
List<EntityFolder> folders = new ArrayList<>();
|
|
|
|
folders.addAll(_folders);
|
2018-12-22 15:13:52 +00:00
|
|
|
EntityFolder.sort(context, folders);
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-12-22 10:44:44 +00:00
|
|
|
all.clear();
|
|
|
|
for (EntityFolder folder : folders)
|
|
|
|
all.add((TupleFolderEx) folder);
|
2018-09-21 15:19:37 +00:00
|
|
|
|
|
|
|
List<TupleFolderEx> shown = new ArrayList<>();
|
2018-12-22 10:44:44 +00:00
|
|
|
for (EntityFolder folder : folders)
|
2018-09-21 15:19:37 +00:00
|
|
|
if (!folder.hide || showAll)
|
2018-12-22 10:44:44 +00:00
|
|
|
shown.add((TupleFolderEx) folder);
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2019-02-10 18:02:55 +00:00
|
|
|
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(filtered, shown));
|
2018-08-02 13:33:06 +00:00
|
|
|
|
|
|
|
filtered.clear();
|
2018-09-21 15:19:37 +00:00
|
|
|
filtered.addAll(shown);
|
2018-08-02 13:33:06 +00:00
|
|
|
|
|
|
|
diff.dispatchUpdatesTo(new ListUpdateCallback() {
|
|
|
|
@Override
|
|
|
|
public void onInserted(int position, int count) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("Inserted @" + position + " #" + count);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRemoved(int position, int count) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("Removed @" + position + " #" + count);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMoved(int fromPosition, int toPosition) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("Moved " + fromPosition + ">" + toPosition);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChanged(int position, int count, Object payload) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("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
|
|
|
}
|
|
|
|
|
2019-02-10 18:02:55 +00:00
|
|
|
private class DiffCallback extends DiffUtil.Callback {
|
2018-08-02 13:33:06 +00:00
|
|
|
private List<TupleFolderEx> prev;
|
|
|
|
private List<TupleFolderEx> next;
|
|
|
|
|
2019-02-10 18:02:55 +00:00
|
|
|
DiffCallback(List<TupleFolderEx> prev, List<TupleFolderEx> next) {
|
2018-08-02 13:33:06 +00:00
|
|
|
this.prev = prev;
|
|
|
|
this.next = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
|
|
|
return f1.equals(f2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
|
|
|
return filtered.get(position).id;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return filtered.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@NonNull
|
|
|
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
2018-12-24 13:41:49 +00:00
|
|
|
return new ViewHolder(inflater.inflate(R.layout.item_folder, parent, false));
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
|
|
|
holder.unwire();
|
|
|
|
|
|
|
|
TupleFolderEx folder = filtered.get(position);
|
2018-08-07 06:51:49 +00:00
|
|
|
holder.bindTo(folder);
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-09-08 16:32:13 +00:00
|
|
|
holder.wire();
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
}
|