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 show_compact;
private boolean show_hidden;
private boolean show_flagged;
private boolean subscribed_only;
private IFolderSelectedListener listener;
@ -128,9 +129,13 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private ImageView ivSync;
private TextView tvKeywords;
private TextView tvFlagged;
private ImageView ibFlagged;
private TextView tvError;
private Button btnHelp;
private Group grpFlagged;
private Group grpExtended;
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);
tvKeywords = itemView.findViewById(R.id.tvKeywords);
tvFlagged = itemView.findViewById(R.id.tvFlagged);
ibFlagged = itemView.findViewById(R.id.ibFlagged);
tvError = itemView.findViewById(R.id.tvError);
btnHelp = itemView.findViewById(R.id.btnHelp);
grpFlagged = itemView.findViewById(R.id.grpFlagged);
grpExtended = itemView.findViewById(R.id.grpExtended);
}
private void wire() {
view.setOnClickListener(this);
ibExpander.setOnClickListener(this);
if (tvFlagged != null)
tvFlagged.setOnClickListener(this);
if (ibFlagged != null)
ibFlagged.setOnClickListener(this);
if (listener == null)
view.setOnLongClickListener(this);
if (btnHelp != null)
@ -180,6 +193,10 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private void unwire() {
view.setOnClickListener(null);
ibExpander.setOnClickListener(null);
if (tvFlagged != null)
tvFlagged.setOnClickListener(null);
if (ibFlagged != null)
ibFlagged.setOnClickListener(null);
if (listener == null)
view.setOnLongClickListener(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)
? textColorPrimary : textColorSecondary));
tvKeywords.setText(TextUtils.join(" ", folder.keywords));
tvKeywords.setVisibility(debug && folder.keywords.length > 0 ? View.VISIBLE : View.GONE);
tvKeywords.setText(debug ? TextUtils.join(" ", folder.keywords) : null);
tvKeywords.setVisibility(
show_flagged || (debug && folder.keywords.length > 0)
? View.VISIBLE : View.GONE);
tvFlagged.setText(NF.format(folder.flagged));
tvError.setText(folder.error);
tvError.setVisibility(folder.error != null ? View.VISIBLE : View.GONE);
if (btnHelp != null)
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);
}
}
@ -352,23 +374,29 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
if (folder.tbd != null)
return;
if (view.getId() == R.id.ibExpander)
onCollapse(folder);
else if (folder.selectable) {
if (listener == null) {
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);
}
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) {
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);
}
}
}
}
@ -403,6 +431,19 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
}.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
public boolean onLongClick(View v) {
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) {
this(parentFragment.getContext(), parentFragment.getViewLifecycleOwner(), account, primary, show_compact, show_hidden, 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, show_flagged, listener);
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.primary = primary;
this.show_compact = show_compact;
this.show_hidden = show_hidden;
this.show_flagged = show_flagged;
this.listener = listener;
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) {
if (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 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 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" +
" FROM folder" +
" 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.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 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" +
" FROM folder" +
" JOIN account ON account.id = folder.account" +
@ -100,6 +102,7 @@ public interface DaoFolder {
", 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 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" +
" FROM folder" +
" JOIN account ON account.id = folder.account" +
@ -137,6 +140,7 @@ public interface DaoFolder {
", 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 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" +
" FROM folder" +
" LEFT JOIN account ON account.id = folder.account" +

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

@ -83,6 +83,7 @@ public class FragmentFolders extends FragmentBase {
private long account;
private boolean primary;
private boolean show_hidden = false;
private boolean show_flagged;
private AdapterFolder adapter;
private NumberFormat NF = NumberFormat.getNumberInstance();
@ -104,6 +105,7 @@ public class FragmentFolders extends FragmentBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
cards = prefs.getBoolean("cards", true);
compact = prefs.getBoolean("compact_folders", false);
show_flagged = prefs.getBoolean("flagged_folders", false);
setTitle(R.string.page_folders);
}
@ -176,7 +178,7 @@ public class FragmentFolders extends FragmentBase {
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);
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_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).setVisible(subscriptions);
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:
onMenuShowHidden();
return true;
case R.id.menu_show_flagged:
onMenuShowFlagged();
return true;
case R.id.menu_subscribed_only:
onMenuSubscribedOnly();
return true;
@ -487,6 +493,16 @@ public class FragmentFolders extends FragmentBase {
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() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean subscribed_only = !prefs.getBoolean("subscribed_only", false);

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

@ -217,12 +217,37 @@
android:layout_marginTop="3dp"
android:layout_marginEnd="6dp"
android:gravity="center_vertical"
android:minHeight="24dp"
android:text="Keywords"
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_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
android:id="@+id/tvError"
android:layout_width="0dp"
@ -249,6 +274,12 @@
app:layout_constraintEnd_toEndOf="parent"
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
android:id="@+id/grpExtended"
android:layout_width="0dp"

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

@ -657,6 +657,7 @@
<string name="title_folder_name">Folder name</string>
<string name="title_display_name">Display name</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_apply_to_all">Apply to all &#8230;</string>
<string name="title_hide_folder">Hide folder</string>

Loading…
Cancel
Save