|
|
@ -71,7 +71,6 @@ import androidx.fragment.app.FragmentManager;
|
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
|
|
|
import androidx.lifecycle.Lifecycle;
|
|
|
|
import androidx.lifecycle.Lifecycle;
|
|
|
|
import androidx.lifecycle.LifecycleOwner;
|
|
|
|
import androidx.lifecycle.LifecycleOwner;
|
|
|
|
import androidx.lifecycle.LiveData;
|
|
|
|
|
|
|
|
import androidx.lifecycle.Observer;
|
|
|
|
import androidx.lifecycle.Observer;
|
|
|
|
import androidx.lifecycle.ViewModelProviders;
|
|
|
|
import androidx.lifecycle.ViewModelProviders;
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
@ -2620,78 +2619,82 @@ public class FragmentMessages extends FragmentBase {
|
|
|
|
|
|
|
|
|
|
|
|
ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class);
|
|
|
|
ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class);
|
|
|
|
|
|
|
|
|
|
|
|
LiveData<PagedList<TupleMessageEx>> liveMessages = model.getPagedList(
|
|
|
|
ViewModelMessages.Model vmodel = model.getModel(
|
|
|
|
getContext(), getViewLifecycleOwner(),
|
|
|
|
getContext(), getViewLifecycleOwner(),
|
|
|
|
viewType, account, folder, thread, id, query, server,
|
|
|
|
viewType, account, folder, thread, id, query, server);
|
|
|
|
new BoundaryCallbackMessages.IBoundaryCallbackMessages() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onLoading() {
|
|
|
|
|
|
|
|
loading = true;
|
|
|
|
|
|
|
|
pbWait.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onLoaded(int fetched) {
|
|
|
|
|
|
|
|
loading = false;
|
|
|
|
|
|
|
|
pbWait.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integer submitted = (Integer) rvMessage.getTag();
|
|
|
|
|
|
|
|
if (submitted == null)
|
|
|
|
|
|
|
|
submitted = 0;
|
|
|
|
|
|
|
|
if (submitted + fetched == 0)
|
|
|
|
|
|
|
|
tvNoEmail.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
vmodel.setCallback(callback);
|
|
|
|
public void onError(Throwable ex) {
|
|
|
|
vmodel.setObserver(getViewLifecycleOwner(), observer);
|
|
|
|
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
|
|
|
|
}
|
|
|
|
if (ex instanceof IllegalArgumentException)
|
|
|
|
|
|
|
|
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
|
|
|
|
|
|
|
|
.setMessage(Helper.formatThrowable(ex))
|
|
|
|
|
|
|
|
.setPositiveButton(android.R.string.cancel, null)
|
|
|
|
|
|
|
|
.create()
|
|
|
|
|
|
|
|
.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
liveMessages.observe(getViewLifecycleOwner(), new Observer<PagedList<TupleMessageEx>>() {
|
|
|
|
private BoundaryCallbackMessages.IBoundaryCallbackMessages callback = new BoundaryCallbackMessages.IBoundaryCallbackMessages() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onChanged(@Nullable PagedList<TupleMessageEx> messages) {
|
|
|
|
public void onLoading() {
|
|
|
|
if (messages == null)
|
|
|
|
loading = true;
|
|
|
|
return;
|
|
|
|
pbWait.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (viewType == AdapterMessage.ViewType.THREAD)
|
|
|
|
@Override
|
|
|
|
if (handleThreadActions(messages))
|
|
|
|
public void onLoaded(int fetched) {
|
|
|
|
return;
|
|
|
|
loading = false;
|
|
|
|
|
|
|
|
pbWait.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integer submitted = (Integer) rvMessage.getTag();
|
|
|
|
|
|
|
|
if (submitted == null)
|
|
|
|
|
|
|
|
submitted = 0;
|
|
|
|
|
|
|
|
if (submitted + fetched == 0)
|
|
|
|
|
|
|
|
tvNoEmail.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Submit messages=" + messages.size());
|
|
|
|
@Override
|
|
|
|
adapter.submitList(messages);
|
|
|
|
public void onError(Throwable ex) {
|
|
|
|
|
|
|
|
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
|
|
|
|
|
|
|
|
if (ex instanceof IllegalArgumentException)
|
|
|
|
|
|
|
|
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
|
|
|
|
|
|
|
|
.setMessage(Helper.formatThrowable(ex))
|
|
|
|
|
|
|
|
.setPositiveButton(android.R.string.cancel, null)
|
|
|
|
|
|
|
|
.create()
|
|
|
|
|
|
|
|
.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// This is to workaround not drawing when the search is expanded
|
|
|
|
private Observer<PagedList<TupleMessageEx>> observer = new Observer<PagedList<TupleMessageEx>>() {
|
|
|
|
new Handler().post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onChanged(@Nullable PagedList<TupleMessageEx> messages) {
|
|
|
|
public void run() {
|
|
|
|
if (messages == null)
|
|
|
|
rvMessage.requestLayout();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rvMessage.setTag(messages.size());
|
|
|
|
if (viewType == AdapterMessage.ViewType.THREAD)
|
|
|
|
|
|
|
|
if (handleThreadActions(messages))
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
boolean hasBoundary = (viewType == AdapterMessage.ViewType.FOLDER || viewType == AdapterMessage.ViewType.SEARCH);
|
|
|
|
Log.i("Submit messages=" + messages.size());
|
|
|
|
|
|
|
|
adapter.submitList(messages);
|
|
|
|
|
|
|
|
|
|
|
|
if (!hasBoundary || !loading)
|
|
|
|
// This is to workaround not drawing when the search is expanded
|
|
|
|
pbWait.setVisibility(View.GONE);
|
|
|
|
new Handler().post(new Runnable() {
|
|
|
|
if (!hasBoundary && messages.size() == 0)
|
|
|
|
@Override
|
|
|
|
tvNoEmail.setVisibility(View.VISIBLE);
|
|
|
|
public void run() {
|
|
|
|
if (messages.size() > 0) {
|
|
|
|
rvMessage.requestLayout();
|
|
|
|
tvNoEmail.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
grpReady.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rvMessage.setTag(messages.size());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean hasBoundary = (viewType == AdapterMessage.ViewType.FOLDER || viewType == AdapterMessage.ViewType.SEARCH);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!hasBoundary || !loading)
|
|
|
|
|
|
|
|
pbWait.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
if (!hasBoundary && messages.size() == 0)
|
|
|
|
|
|
|
|
tvNoEmail.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
if (messages.size() > 0) {
|
|
|
|
|
|
|
|
tvNoEmail.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
grpReady.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
private boolean handleThreadActions(@NonNull PagedList<TupleMessageEx> messages) {
|
|
|
|
private boolean handleThreadActions(@NonNull PagedList<TupleMessageEx> messages) {
|
|
|
|
// Auto close / next
|
|
|
|
// Auto close / next
|
|
|
|