Suppress expand notice on unmetered connections

This commit is contained in:
M66B 2019-10-21 09:01:24 +02:00
parent 1990384398
commit af318125d1
1 changed files with 17 additions and 11 deletions

View File

@ -172,7 +172,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private Context context;
private LifecycleOwner owner;
private LayoutInflater inflater;
private boolean suitable;
private boolean unmetered;
private int dp36;
private int colorPrimary;
@ -1018,13 +1020,13 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
private void bindExpandWarning(TupleMessageEx message, boolean expanded) {
tvExpand.setText(
message.size == null ? null : context.getString(R.string.title_expand_warning,
Helper.humanReadableByteCount(message.size, true)));
tvExpand.setVisibility(
viewType == ViewType.THREAD && !expanded &&
message.size != null && !message.content && message.uid != null
? View.VISIBLE : View.GONE);
if (viewType != ViewType.THREAD || expanded || message.content || message.uid == null || unmetered)
tvExpand.setVisibility(View.GONE);
else {
tvExpand.setText(context.getString(R.string.title_expand_warning,
message.size == null ? "?" : Helper.humanReadableByteCount(message.size, true)));
tvExpand.setVisibility(View.VISIBLE);
}
}
private void bindExpanded(final TupleMessageEx message, final boolean scroll) {
@ -3513,11 +3515,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.context = parentFragment.getContext();
this.owner = parentFragment.getViewLifecycleOwner();
this.suitable = ConnectionHelper.getNetworkState(context).isSuitable();
this.inflater = LayoutInflater.from(context);
this.TF = Helper.getTimeInstance(context, SimpleDateFormat.SHORT);
this.DTF = Helper.getDateTimeInstance(context, SimpleDateFormat.LONG, SimpleDateFormat.LONG);
ConnectionHelper.NetworkState state = ConnectionHelper.getNetworkState(context);
this.suitable = state.isSuitable();
this.unmetered = state.isUnmetered();
this.dp36 = Helper.dp2pixels(context, 36);
this.colorPrimary = Helper.resolveColor(context, R.attr.colorPrimary);
this.colorAccent = Helper.resolveColor(context, R.attr.colorAccent);
@ -3688,9 +3693,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
void checkInternet() {
boolean suitable = ConnectionHelper.getNetworkState(context).isSuitable();
if (this.suitable != suitable) {
this.suitable = suitable;
ConnectionHelper.NetworkState state = ConnectionHelper.getNetworkState(context);
if (this.suitable != state.isSuitable() || this.unmetered != state.isUnmetered()) {
this.suitable = state.isSuitable();
this.unmetered = state.isUnmetered();
notifyDataSetChanged();
}
}