Prevent flicker on expanding messages

pull/175/head
M66B 5 years ago
parent c86578c12c
commit 5d4028fd63

@ -2824,7 +2824,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
.putExtra("id", message.id)); .putExtra("id", message.id));
else { else {
boolean expanded = !properties.getValue("expanded", message.id); boolean expanded = !properties.getValue("expanded", message.id);
properties.setValue("expanded", message.id, expanded); properties.setExpanded(message, expanded);
ibExpander.setTag(expanded); ibExpander.setTag(expanded);
ibExpander.setImageLevel(expanded ? 0 /* less*/ : 1 /* more */); ibExpander.setImageLevel(expanded ? 0 /* less*/ : 1 /* more */);
@ -3585,7 +3585,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (amessage == null || !amessage.id.equals(id)) if (amessage == null || !amessage.id.equals(id))
return; return;
properties.setValue("expanded", message.id, false); properties.setExpanded(message, false);
message.ui_seen = args.getBoolean("seen"); message.ui_seen = args.getBoolean("seen");
message.unseen = (message.ui_seen ? 0 : message.count); message.unseen = (message.ui_seen ? 0 : message.count);
bindTo(message, getAdapterPosition()); bindTo(message, getAdapterPosition());
@ -4942,6 +4942,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean getValue(String name, long id); boolean getValue(String name, long id);
void setExpanded(TupleMessageEx message, boolean expanded);
void setSize(long id, Float size); void setSize(long id, Float size);
float getSize(long id, float defaultSize); float getSize(long id, float defaultSize);

@ -1469,26 +1469,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
values.get(name).add(id); values.get(name).add(id);
} else } else
values.get(name).remove(id); values.get(name).remove(id);
if ("expanded".equals(name)) {
// Collapse other messages
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean expand_all = prefs.getBoolean("expand_all", false);
boolean expand_one = prefs.getBoolean("expand_one", true);
if (!expand_all && expand_one) {
for (Long other : new ArrayList<>(values.get(name)))
if (!other.equals(id)) {
values.get(name).remove(other);
int pos = adapter.getPositionForKey(other);
if (pos != RecyclerView.NO_POSITION)
adapter.notifyItemChanged(pos);
}
}
updateExpanded();
if (enabled)
handleExpand(id);
}
} }
@Override @Override
@ -1500,6 +1480,36 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return false; return false;
} }
public void setExpanded(TupleMessageEx message, boolean value) {
// Prevent flicker
if (value &&
message.accountProtocol != EntityAccount.TYPE_IMAP ||
(message.accountAutoSeen && !message.ui_seen && !message.folderReadOnly)) {
message.unseen = 0;
message.ui_seen = true;
}
setValue("expanded", message.id, value);
// Collapse other messages
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean expand_all = prefs.getBoolean("expand_all", false);
boolean expand_one = prefs.getBoolean("expand_one", true);
if (!expand_all && expand_one) {
for (Long other : new ArrayList<>(values.get("expanded")))
if (!other.equals(id)) {
values.get("expanded").remove(other);
int pos = adapter.getPositionForKey(other);
if (pos != RecyclerView.NO_POSITION)
adapter.notifyItemChanged(pos);
}
}
updateExpanded();
if (value)
handleExpand(id);
}
@Override @Override
public void setSize(long id, Float size) { public void setSize(long id, Float size) {
if (size == null) if (size == null)
@ -3769,16 +3779,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
expand = messages.get(0); expand = messages.get(0);
if (expand != null && if (expand != null &&
(expand.content || unmetered || (expand.size != null && expand.size < download))) { (expand.content || unmetered || (expand.size != null && expand.size < download)))
// Prevent flicker iProperties.setExpanded(expand, true);
if (expand.accountProtocol != EntityAccount.TYPE_IMAP ||
(expand.accountAutoSeen && !expand.ui_seen && !expand.folderReadOnly)) {
expand.unseen = 0;
expand.ui_seen = true;
}
iProperties.setValue("expanded", expand.id, true);
}
} }
// Auto expand all seen messages // Auto expand all seen messages
@ -3786,7 +3788,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (expand_all) if (expand_all)
for (TupleMessageEx message : messages) for (TupleMessageEx message : messages)
if (message != null && message.ui_seen) if (message != null && message.ui_seen)
iProperties.setValue("expanded", message.id, true); iProperties.setExpanded(message, true);
} else { } else {
if (autoCloseCount > 0 && (autoclose || onclose != null)) { if (autoCloseCount > 0 && (autoclose || onclose != null)) {
int count = 0; int count = 0;

Loading…
Cancel
Save