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));
else {
boolean expanded = !properties.getValue("expanded", message.id);
properties.setValue("expanded", message.id, expanded);
properties.setExpanded(message, expanded);
ibExpander.setTag(expanded);
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))
return;
properties.setValue("expanded", message.id, false);
properties.setExpanded(message, false);
message.ui_seen = args.getBoolean("seen");
message.unseen = (message.ui_seen ? 0 : message.count);
bindTo(message, getAdapterPosition());
@ -4942,6 +4942,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean getValue(String name, long id);
void setExpanded(TupleMessageEx message, boolean expanded);
void setSize(long id, Float size);
float getSize(long id, float defaultSize);

@ -1469,26 +1469,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
values.get(name).add(id);
} else
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
@ -1500,6 +1480,36 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
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
public void setSize(long id, Float size) {
if (size == null)
@ -3769,16 +3779,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
expand = messages.get(0);
if (expand != null &&
(expand.content || unmetered || (expand.size != null && expand.size < download))) {
// Prevent flicker
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);
}
(expand.content || unmetered || (expand.size != null && expand.size < download)))
iProperties.setExpanded(expand, true);
}
// Auto expand all seen messages
@ -3786,7 +3788,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (expand_all)
for (TupleMessageEx message : messages)
if (message != null && message.ui_seen)
iProperties.setValue("expanded", message.id, true);
iProperties.setExpanded(message, true);
} else {
if (autoCloseCount > 0 && (autoclose || onclose != null)) {
int count = 0;

Loading…
Cancel
Save