Added folder option show flagged messages

pull/178/head
M66B 5 years ago
parent 121236a5d6
commit 96e739dfb4

@ -81,6 +81,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private boolean primary; private boolean primary;
private boolean show_compact; private boolean show_compact;
private boolean show_hidden; private boolean show_hidden;
private boolean show_flagged;
private boolean subscribed_only; private boolean subscribed_only;
private IFolderSelectedListener listener; private IFolderSelectedListener listener;
@ -128,9 +129,13 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private ImageView ivSync; private ImageView ivSync;
private TextView tvKeywords; private TextView tvKeywords;
private TextView tvFlagged;
private ImageView ibFlagged;
private TextView tvError; private TextView tvError;
private Button btnHelp; private Button btnHelp;
private Group grpFlagged;
private Group grpExtended; private Group grpExtended;
private TwoStateOwner powner = new TwoStateOwner(owner, "FolderPopup"); private TwoStateOwner powner = new TwoStateOwner(owner, "FolderPopup");
@ -162,15 +167,23 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
ivSync = itemView.findViewById(R.id.ivSync); ivSync = itemView.findViewById(R.id.ivSync);
tvKeywords = itemView.findViewById(R.id.tvKeywords); tvKeywords = itemView.findViewById(R.id.tvKeywords);
tvFlagged = itemView.findViewById(R.id.tvFlagged);
ibFlagged = itemView.findViewById(R.id.ibFlagged);
tvError = itemView.findViewById(R.id.tvError); tvError = itemView.findViewById(R.id.tvError);
btnHelp = itemView.findViewById(R.id.btnHelp); btnHelp = itemView.findViewById(R.id.btnHelp);
grpFlagged = itemView.findViewById(R.id.grpFlagged);
grpExtended = itemView.findViewById(R.id.grpExtended); grpExtended = itemView.findViewById(R.id.grpExtended);
} }
private void wire() { private void wire() {
view.setOnClickListener(this); view.setOnClickListener(this);
ibExpander.setOnClickListener(this); ibExpander.setOnClickListener(this);
if (tvFlagged != null)
tvFlagged.setOnClickListener(this);
if (ibFlagged != null)
ibFlagged.setOnClickListener(this);
if (listener == null) if (listener == null)
view.setOnLongClickListener(this); view.setOnLongClickListener(this);
if (btnHelp != null) if (btnHelp != null)
@ -180,6 +193,10 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private void unwire() { private void unwire() {
view.setOnClickListener(null); view.setOnClickListener(null);
ibExpander.setOnClickListener(null); ibExpander.setOnClickListener(null);
if (tvFlagged != null)
tvFlagged.setOnClickListener(null);
if (ibFlagged != null)
ibFlagged.setOnClickListener(null);
if (listener == null) if (listener == null)
view.setOnLongClickListener(null); view.setOnLongClickListener(null);
if (btnHelp != null) if (btnHelp != null)
@ -327,14 +344,19 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
folder.synchronize && folder.initialize != 0 && !EntityFolder.OUTBOX.equals(folder.type) folder.synchronize && folder.initialize != 0 && !EntityFolder.OUTBOX.equals(folder.type)
? textColorPrimary : textColorSecondary)); ? textColorPrimary : textColorSecondary));
tvKeywords.setText(TextUtils.join(" ", folder.keywords)); tvKeywords.setText(debug ? TextUtils.join(" ", folder.keywords) : null);
tvKeywords.setVisibility(debug && folder.keywords.length > 0 ? View.VISIBLE : View.GONE); tvKeywords.setVisibility(
show_flagged || (debug && folder.keywords.length > 0)
? View.VISIBLE : View.GONE);
tvFlagged.setText(NF.format(folder.flagged));
tvError.setText(folder.error); tvError.setText(folder.error);
tvError.setVisibility(folder.error != null ? View.VISIBLE : View.GONE); tvError.setVisibility(folder.error != null ? View.VISIBLE : View.GONE);
if (btnHelp != null) if (btnHelp != null)
btnHelp.setVisibility(folder.error == null ? View.GONE : View.VISIBLE); btnHelp.setVisibility(folder.error == null ? View.GONE : View.VISIBLE);
grpFlagged.setVisibility(show_compact || !show_flagged ? View.GONE : View.VISIBLE);
grpExtended.setVisibility(show_compact ? View.GONE : View.VISIBLE); grpExtended.setVisibility(show_compact ? View.GONE : View.VISIBLE);
} }
} }
@ -352,23 +374,29 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
if (folder.tbd != null) if (folder.tbd != null)
return; return;
if (view.getId() == R.id.ibExpander) switch (view.getId()) {
onCollapse(folder); case R.id.ibExpander:
else if (folder.selectable) { onCollapse(folder);
if (listener == null) { break;
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); case R.id.tvFlagged:
lbm.sendBroadcast( case R.id.ibFlagged:
new Intent(ActivityView.ACTION_VIEW_MESSAGES) onFlagged(folder);
.putExtra("account", folder.account) break;
.putExtra("folder", folder.id) default:
.putExtra("type", folder.type)); if (listener == null) {
} else { LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
if (folder.read_only) lbm.sendBroadcast(
return; new Intent(ActivityView.ACTION_VIEW_MESSAGES)
if (disabledIds.contains(folder.id)) .putExtra("account", folder.account)
return; .putExtra("folder", folder.id)
listener.onFolderSelected(folder); .putExtra("type", folder.type));
} } else {
if (folder.read_only)
return;
if (disabledIds.contains(folder.id))
return;
listener.onFolderSelected(folder);
}
} }
} }
} }
@ -403,6 +431,19 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
}.execute(context, owner, args, "folder:collapse"); }.execute(context, owner, args, "folder:collapse");
} }
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);
}
@Override @Override
public boolean onLongClick(View v) { public boolean onLongClick(View v) {
int pos = getAdapterPosition(); int pos = getAdapterPosition();
@ -741,16 +782,17 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
} }
} }
AdapterFolder(Fragment parentFragment, long account, boolean primary, boolean show_compact, boolean show_hidden, IFolderSelectedListener listener) { 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, listener); this(parentFragment.getContext(), parentFragment.getViewLifecycleOwner(), account, primary, show_compact, show_hidden, show_flagged, listener);
this.parentFragment = parentFragment; this.parentFragment = parentFragment;
} }
AdapterFolder(Context context, LifecycleOwner owner, long account, boolean primary, boolean show_compact, boolean show_hidden, IFolderSelectedListener listener) { AdapterFolder(Context context, LifecycleOwner owner, long account, boolean primary, boolean show_compact, boolean show_hidden, boolean show_flagged, IFolderSelectedListener listener) {
this.account = account; this.account = account;
this.primary = primary; this.primary = primary;
this.show_compact = show_compact; this.show_compact = show_compact;
this.show_hidden = show_hidden; this.show_hidden = show_hidden;
this.show_flagged = show_flagged;
this.listener = listener; this.listener = listener;
this.context = context; this.context = context;
@ -800,6 +842,13 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
} }
} }
void setShowFlagged(boolean show_flagged) {
if (this.show_flagged != show_flagged) {
this.show_flagged = show_flagged;
notifyDataSetChanged();
}
}
void setSubscribedOnly(boolean subscribed_only) { void setSubscribedOnly(boolean subscribed_only) {
if (this.subscribed_only != subscribed_only) { if (this.subscribed_only != subscribed_only) {
this.subscribed_only = subscribed_only; this.subscribed_only = subscribed_only;

@ -41,6 +41,7 @@ public interface DaoFolder {
", COUNT(DISTINCT message.id) AS messages" + ", COUNT(DISTINCT message.id) AS messages" +
", COUNT(DISTINCT CASE WHEN message.content = 1 THEN message.id ELSE NULL END) AS content" + ", COUNT(DISTINCT CASE WHEN message.content = 1 THEN message.id ELSE NULL END) AS content" +
", COUNT(DISTINCT CASE WHEN NOT message.ui_seen THEN message.id ELSE NULL END) AS unseen" + ", COUNT(DISTINCT CASE WHEN NOT message.ui_seen THEN message.id ELSE NULL END) AS unseen" +
", COUNT(DISTINCT CASE WHEN message.ui_flagged THEN message.id ELSE NULL END) AS flagged" +
", COUNT(DISTINCT CASE WHEN operation.state = 'executing' THEN operation.id ELSE NULL END) AS executing" + ", COUNT(DISTINCT CASE WHEN operation.state = 'executing' THEN operation.id ELSE NULL END) AS executing" +
" FROM folder" + " FROM folder" +
" LEFT JOIN account ON account.id = folder.account" + " LEFT JOIN account ON account.id = folder.account" +
@ -78,6 +79,7 @@ public interface DaoFolder {
", COUNT(DISTINCT CASE WHEN message.ui_hide THEN NULL ELSE message.id END) AS messages" + ", COUNT(DISTINCT CASE WHEN message.ui_hide THEN NULL ELSE message.id END) AS messages" +
", COUNT(DISTINCT CASE WHEN message.content = 1 AND NOT message.ui_hide THEN message.id ELSE NULL END) AS content" + ", COUNT(DISTINCT CASE WHEN message.content = 1 AND NOT message.ui_hide THEN message.id ELSE NULL END) AS content" +
", COUNT(DISTINCT CASE WHEN NOT message.ui_seen AND NOT message.ui_hide THEN message.id ELSE NULL END) AS unseen" + ", COUNT(DISTINCT CASE WHEN NOT message.ui_seen AND NOT message.ui_hide THEN message.id ELSE NULL END) AS unseen" +
", COUNT(DISTINCT CASE WHEN message.ui_flagged AND NOT message.ui_hide THEN message.id ELSE NULL END) AS flagged" +
", COUNT(DISTINCT CASE WHEN operation.state = 'executing' THEN operation.id ELSE NULL END) AS executing" + ", COUNT(DISTINCT CASE WHEN operation.state = 'executing' THEN operation.id ELSE NULL END) AS executing" +
" FROM folder" + " FROM folder" +
" JOIN account ON account.id = folder.account" + " JOIN account ON account.id = folder.account" +
@ -100,6 +102,7 @@ public interface DaoFolder {
", COUNT(DISTINCT message.id) AS messages" + ", COUNT(DISTINCT message.id) AS messages" +
", COUNT(DISTINCT CASE WHEN message.content = 1 THEN message.id ELSE NULL END) AS content" + ", COUNT(DISTINCT CASE WHEN message.content = 1 THEN message.id ELSE NULL END) AS content" +
", COUNT(DISTINCT CASE WHEN NOT message.ui_seen THEN message.id ELSE NULL END) AS unseen" + ", COUNT(DISTINCT CASE WHEN NOT message.ui_seen THEN message.id ELSE NULL END) AS unseen" +
", COUNT(DISTINCT CASE WHEN message.ui_flagged THEN message.id ELSE NULL END) AS flagged" +
", COUNT(DISTINCT CASE WHEN operation.state = 'executing' THEN operation.id ELSE NULL END) AS executing" + ", COUNT(DISTINCT CASE WHEN operation.state = 'executing' THEN operation.id ELSE NULL END) AS executing" +
" FROM folder" + " FROM folder" +
" JOIN account ON account.id = folder.account" + " JOIN account ON account.id = folder.account" +
@ -137,6 +140,7 @@ public interface DaoFolder {
", COUNT(DISTINCT message.id) AS messages" + ", COUNT(DISTINCT message.id) AS messages" +
", COUNT(DISTINCT CASE WHEN message.content = 1 THEN message.id ELSE NULL END) AS content" + ", COUNT(DISTINCT CASE WHEN message.content = 1 THEN message.id ELSE NULL END) AS content" +
", COUNT(DISTINCT CASE WHEN NOT message.ui_seen THEN message.id ELSE NULL END) AS unseen" + ", COUNT(DISTINCT CASE WHEN NOT message.ui_seen THEN message.id ELSE NULL END) AS unseen" +
", COUNT(DISTINCT CASE WHEN message.ui_flagged THEN message.id ELSE NULL END) AS flagged" +
", COUNT(DISTINCT CASE WHEN operation.state = 'executing' THEN operation.id ELSE NULL END) AS executing" + ", COUNT(DISTINCT CASE WHEN operation.state = 'executing' THEN operation.id ELSE NULL END) AS executing" +
" FROM folder" + " FROM folder" +
" LEFT JOIN account ON account.id = folder.account" + " LEFT JOIN account ON account.id = folder.account" +

@ -119,7 +119,7 @@ public class FragmentDialogFolder extends FragmentDialogBase {
rvFolder.setLayoutManager(llm); rvFolder.setLayoutManager(llm);
final AdapterFolder adapter = new AdapterFolder(context, getViewLifecycleOwner(), final AdapterFolder adapter = new AdapterFolder(context, getViewLifecycleOwner(),
account, false, false, false, new AdapterFolder.IFolderSelectedListener() { account, false, false, false, false, new AdapterFolder.IFolderSelectedListener() {
@Override @Override
public void onFolderSelected(TupleFolderEx folder) { public void onFolderSelected(TupleFolderEx folder) {
String name = folder.getDisplayName(context, folder.parent_ref); String name = folder.getDisplayName(context, folder.parent_ref);

@ -83,6 +83,7 @@ public class FragmentFolders extends FragmentBase {
private long account; private long account;
private boolean primary; private boolean primary;
private boolean show_hidden = false; private boolean show_hidden = false;
private boolean show_flagged;
private AdapterFolder adapter; private AdapterFolder adapter;
private NumberFormat NF = NumberFormat.getNumberInstance(); private NumberFormat NF = NumberFormat.getNumberInstance();
@ -104,6 +105,7 @@ public class FragmentFolders extends FragmentBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
cards = prefs.getBoolean("cards", true); cards = prefs.getBoolean("cards", true);
compact = prefs.getBoolean("compact_folders", false); compact = prefs.getBoolean("compact_folders", false);
show_flagged = prefs.getBoolean("flagged_folders", false);
setTitle(R.string.page_folders); setTitle(R.string.page_folders);
} }
@ -176,7 +178,7 @@ public class FragmentFolders extends FragmentBase {
rvFolder.addItemDecoration(itemDecorator); rvFolder.addItemDecoration(itemDecorator);
} }
adapter = new AdapterFolder(this, account, primary, compact, show_hidden, null); adapter = new AdapterFolder(this, account, primary, compact, show_hidden, show_flagged, null);
rvFolder.setAdapter(adapter); rvFolder.setAdapter(adapter);
fabAdd.setOnClickListener(new View.OnClickListener() { fabAdd.setOnClickListener(new View.OnClickListener() {
@ -429,6 +431,7 @@ public class FragmentFolders extends FragmentBase {
menu.findItem(R.id.menu_compact).setChecked(compact); menu.findItem(R.id.menu_compact).setChecked(compact);
menu.findItem(R.id.menu_show_hidden).setChecked(show_hidden); menu.findItem(R.id.menu_show_hidden).setChecked(show_hidden);
menu.findItem(R.id.menu_show_flagged).setChecked(show_flagged);
menu.findItem(R.id.menu_subscribed_only).setChecked(subscribed_only); menu.findItem(R.id.menu_subscribed_only).setChecked(subscribed_only);
menu.findItem(R.id.menu_subscribed_only).setVisible(subscriptions); menu.findItem(R.id.menu_subscribed_only).setVisible(subscriptions);
menu.findItem(R.id.menu_apply_all).setVisible(account >= 0); menu.findItem(R.id.menu_apply_all).setVisible(account >= 0);
@ -448,6 +451,9 @@ public class FragmentFolders extends FragmentBase {
case R.id.menu_show_hidden: case R.id.menu_show_hidden:
onMenuShowHidden(); onMenuShowHidden();
return true; return true;
case R.id.menu_show_flagged:
onMenuShowFlagged();
return true;
case R.id.menu_subscribed_only: case R.id.menu_subscribed_only:
onMenuSubscribedOnly(); onMenuSubscribedOnly();
return true; return true;
@ -487,6 +493,16 @@ public class FragmentFolders extends FragmentBase {
adapter.setShowHidden(show_hidden); adapter.setShowHidden(show_hidden);
} }
private void onMenuShowFlagged() {
show_flagged = !show_flagged;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("flagged_folders", show_flagged).apply();
getActivity().invalidateOptionsMenu();
adapter.setShowFlagged(show_flagged);
}
private void onMenuSubscribedOnly() { private void onMenuSubscribedOnly() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean subscribed_only = !prefs.getBoolean("subscribed_only", false); boolean subscribed_only = !prefs.getBoolean("subscribed_only", false);

@ -46,6 +46,7 @@ public class TupleFolderEx extends EntityFolder implements Serializable {
public int messages; public int messages;
public int content; public int content;
public int unseen; public int unseen;
public int flagged;
public int executing; public int executing;
@Ignore @Ignore
@ -74,6 +75,7 @@ public class TupleFolderEx extends EntityFolder implements Serializable {
this.messages == other.messages && this.messages == other.messages &&
this.content == other.content && this.content == other.content &&
this.unseen == other.unseen && this.unseen == other.unseen &&
this.flagged == other.flagged &&
this.executing == other.executing); this.executing == other.executing);
} else } else
return false; return false;

@ -217,12 +217,37 @@
android:layout_marginTop="3dp" android:layout_marginTop="3dp"
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:minHeight="24dp"
android:text="Keywords" android:text="Keywords"
android:textAppearance="@android:style/TextAppearance.Small" android:textAppearance="@android:style/TextAppearance.Small"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toStartOf="@id/tvFlagged"
app:layout_constraintStart_toEndOf="@id/ibExpander" app:layout_constraintStart_toEndOf="@id/ibExpander"
app:layout_constraintTop_toBottomOf="@id/tvType" /> app:layout_constraintTop_toBottomOf="@id/tvType" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvFlagged"
android:layout_width="wrap_content"
android:layout_height="24dp"
android:layout_marginEnd="6dp"
android:gravity="center_vertical"
android:text="3"
android:textAppearance="@android:style/TextAppearance.Small"
app:layout_constraintBottom_toBottomOf="@id/tvKeywords"
app:layout_constraintEnd_toStartOf="@+id/ibFlagged"
app:layout_constraintTop_toTopOf="@+id/tvKeywords" />
<ImageView
android:id="@+id/ibFlagged"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="6dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_flag"
app:layout_constraintBottom_toBottomOf="@id/tvKeywords"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/tvKeywords"
app:srcCompat="@drawable/baseline_star_24" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView
android:id="@+id/tvError" android:id="@+id/tvError"
android:layout_width="0dp" android:layout_width="0dp"
@ -249,6 +274,12 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvError" /> app:layout_constraintTop_toBottomOf="@id/tvError" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpFlagged"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvFlagged,ibFlagged" />
<androidx.constraintlayout.widget.Group <androidx.constraintlayout.widget.Group
android:id="@+id/grpExtended" android:id="@+id/grpExtended"
android:layout_width="0dp" android:layout_width="0dp"

@ -20,6 +20,12 @@
android:title="@string/title_show_folders" android:title="@string/title_show_folders"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_show_flagged"
android:checkable="true"
android:title="@string/title_show_flagged"
app:showAsAction="never" />
<item <item
android:id="@+id/menu_subscribed_only" android:id="@+id/menu_subscribed_only"
android:checkable="true" android:checkable="true"

@ -657,6 +657,7 @@
<string name="title_folder_name">Folder name</string> <string name="title_folder_name">Folder name</string>
<string name="title_display_name">Display name</string> <string name="title_display_name">Display name</string>
<string name="title_show_folders">Show hidden folders</string> <string name="title_show_folders">Show hidden folders</string>
<string name="title_show_flagged">Show starred messages</string>
<string name="title_subscribed_only">Subscribed only</string> <string name="title_subscribed_only">Subscribed only</string>
<string name="title_apply_to_all">Apply to all &#8230;</string> <string name="title_apply_to_all">Apply to all &#8230;</string>
<string name="title_hide_folder">Hide folder</string> <string name="title_hide_folder">Hide folder</string>

Loading…
Cancel
Save