Improved list state

pull/177/head
M66B 5 years ago
parent f0b61b836c
commit 26fba327fd

@ -3784,14 +3784,13 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override
public void onLoading() {
loading = true;
pbWait.setVisibility(View.VISIBLE);
updateListState("Loading");
}
@Override
public void onLoaded(int fetched) {
loading = false;
if (initialized && SimpleTask.getCount() == 0)
pbWait.setVisibility(View.GONE);
updateListState("Loaded");
}
@Override
@ -3846,18 +3845,42 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
});
initialized = true;
if (!loading && SimpleTask.getCount() == 0)
pbWait.setVisibility(View.GONE);
tvNoEmail.setVisibility(messages.size() == 0 ? View.VISIBLE : View.GONE);
tvNoEmailHint.setVisibility(
messages.size() == 0 && filterActive() && viewType != AdapterMessage.ViewType.SEARCH
? View.VISIBLE : View.GONE);
updateListState("Observed");
grpReady.setVisibility(View.VISIBLE);
}
};
private void updateListState(String reason) {
Context context = getContext();
if (context == null)
return;
if (!getViewLifecycleOwner().getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
return;
int tasks = SimpleTask.getCount();
int items = adapter.getItemCount();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean filter_seen = prefs.getBoolean("filter_seen", false);
boolean filter_unflagged = prefs.getBoolean("filter_unflagged", false);
boolean filter_unknown = prefs.getBoolean("filter_unknown", false);
boolean filter_active = (filter_seen || filter_unflagged || filter_unknown);
boolean none = (items == 0 && !loading && tasks == 0 && initialized);
boolean filtered = (filter_active && viewType != AdapterMessage.ViewType.SEARCH);
pbWait.setVisibility(loading || tasks > 0 ? View.VISIBLE : View.GONE);
tvNoEmail.setVisibility(none ? View.VISIBLE : View.GONE);
tvNoEmailHint.setVisibility(none && filtered ? View.VISIBLE : View.GONE);
Log.i("List state reason=" + reason +
" tasks=" + tasks + " loading=" + loading +
" items=" + items + " initialized=" + initialized +
" wait=" + (pbWait.getVisibility() == View.VISIBLE) +
" no=" + (tvNoEmail.getVisibility() == View.VISIBLE));
}
private boolean handleThreadActions(@NonNull PagedList<TupleMessageEx> messages) {
// Auto close / next
if (messages.size() == 0 && (autoclose || onclose != null)) {
@ -4423,14 +4446,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return TextUtils.join(", ", displays);
}
private boolean filterActive() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean filter_seen = prefs.getBoolean("filter_seen", false);
boolean filter_unflagged = prefs.getBoolean("filter_unflagged", false);
boolean filter_unknown = prefs.getBoolean("filter_unknown", false);
return (filter_seen || filter_unflagged || filter_unknown);
}
private ActivityBase.IKeyPressedListener onBackPressedListener = new ActivityBase.IKeyPressedListener() {
@Override
public boolean onKeyPressed(KeyEvent event) {
@ -4632,12 +4647,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
};
private void onTaskCount(Intent intent) {
int count = intent.getIntExtra("count", 0);
if (count == 0) {
if (initialized && !loading)
pbWait.setVisibility(View.GONE);
} else
pbWait.setVisibility(View.VISIBLE);
updateListState("Tasks");
}
private void onNewMessage(Intent intent) {

@ -0,0 +1,65 @@
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2020 by Marcel Bokhorst (M66B)
*/
import android.content.Context;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;
public class ViewTextDelayed extends AppCompatTextView {
private int visibility;
private static final int VISIBILITY_DELAY = 1000; // milliseconds
public ViewTextDelayed(@NonNull Context context) {
super(context);
}
public ViewTextDelayed(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public ViewTextDelayed(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void setVisibility(int visibility) {
this.visibility = visibility;
removeCallbacks(delayedShow);
if (visibility == VISIBLE) {
super.setVisibility(INVISIBLE);
postDelayed(delayedShow, VISIBILITY_DELAY);
} else
super.setVisibility(visibility);
}
private final Runnable delayedShow = new Runnable() {
@Override
public void run() {
if (visibility == VISIBLE)
ViewTextDelayed.super.setVisibility(VISIBLE);
}
};
}

@ -135,7 +135,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvHintSelect" />
<eu.faircode.email.FixedTextView
<eu.faircode.email.ViewTextDelayed
android:id="@+id/tvNoEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -146,7 +146,7 @@
app:layout_constraintStart_toStartOf="@+id/rvMessage"
app:layout_constraintTop_toTopOf="@+id/rvMessage" />
<eu.faircode.email.FixedTextView
<eu.faircode.email.ViewTextDelayed
android:id="@+id/tvNoEmailHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

Loading…
Cancel
Save