Added retry on boundary error

pull/177/head
M66B 6 years ago
parent edfbf320ed
commit 9fee5fef07

@ -118,6 +118,11 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
queue_load(false); queue_load(false);
} }
void retry() {
state.reset();
queue_load(true);
}
private void queue_load(final boolean zero) { private void queue_load(final boolean zero) {
final State state = this.state; final State state = this.state;

@ -116,7 +116,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.google.android.material.bottomnavigation.BottomNavigationView; import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.sun.mail.util.FolderClosedIOException;
import org.bouncycastle.asn1.cms.Attribute; import org.bouncycastle.asn1.cms.Attribute;
import org.bouncycastle.asn1.cms.AttributeTable; import org.bouncycastle.asn1.cms.AttributeTable;
@ -192,7 +191,6 @@ import java.util.Objects;
import java.util.Properties; import java.util.Properties;
import javax.mail.Address; import javax.mail.Address;
import javax.mail.FolderClosedException;
import javax.mail.Session; import javax.mail.Session;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
@ -318,6 +316,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private static final int REQUEST_SEARCH = 18; private static final int REQUEST_SEARCH = 18;
private static final int REQUEST_ACCOUNT = 19; private static final int REQUEST_ACCOUNT = 19;
private static final int REQUEST_EMPTY_FOLDER = 20; private static final int REQUEST_EMPTY_FOLDER = 20;
private static final int REQUEST_BOUNDARY_RETRY = 21;
static final String ACTION_STORE_RAW = BuildConfig.APPLICATION_ID + ".STORE_RAW"; static final String ACTION_STORE_RAW = BuildConfig.APPLICATION_ID + ".STORE_RAW";
static final String ACTION_DECRYPT = BuildConfig.APPLICATION_ID + ".DECRYPT"; static final String ACTION_DECRYPT = BuildConfig.APPLICATION_ID + ".DECRYPT";
@ -3797,6 +3796,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
public void onException(@NonNull Throwable ex) { public void onException(@NonNull Throwable ex) {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
if (ex instanceof IllegalStateException) { if (ex instanceof IllegalStateException) {
// No internet connection
Snackbar snackbar = Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG); Snackbar snackbar = Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG);
snackbar.setAction(R.string.title_fix, new View.OnClickListener() { snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override @Override
@ -3807,15 +3807,13 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
}); });
snackbar.show(); snackbar.show();
} else if (ex instanceof IllegalArgumentException || } else {
ex instanceof FolderClosedException || ex instanceof FolderClosedIOException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("error", Log.formatThrowable(ex, false)); args.putString("error", Log.formatThrowable(ex, false));
FragmentDialogError fragment = new FragmentDialogError(); FragmentDialogBoundaryError fragment = new FragmentDialogBoundaryError();
fragment.setArguments(args); fragment.setArguments(args);
fragment.setTargetFragment(FragmentMessages.this, REQUEST_BOUNDARY_RETRY);
fragment.show(getParentFragmentManager(), "boundary:error"); fragment.show(getParentFragmentManager(), "boundary:error");
} }
} }
@ -4863,6 +4861,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (resultCode == RESULT_OK) if (resultCode == RESULT_OK)
onEmptyFolder(data.getBundleExtra("args")); onEmptyFolder(data.getBundleExtra("args"));
break; break;
case REQUEST_BOUNDARY_RETRY:
if (resultCode == RESULT_OK)
onBoundaryRetry();
break;
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
@ -6356,6 +6358,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}.execute(this, args, "folder:delete"); }.execute(this, args, "folder:delete");
} }
private void onBoundaryRetry() {
ViewModelMessages model = new ViewModelProvider(getActivity()).get(ViewModelMessages.class);
model.retry(viewType);
}
static void search( static void search(
final Context context, final LifecycleOwner owner, final FragmentManager manager, final Context context, final LifecycleOwner owner, final FragmentManager manager,
long account, long folder, boolean server, String query) { long account, long folder, boolean server, String query) {
@ -6654,15 +6661,31 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
} }
public static class FragmentDialogError extends FragmentDialogBase { public static class FragmentDialogBoundaryError extends FragmentDialogBase {
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
String error = getArguments().getString("error"); String error = getArguments().getString("error");
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_boundary_error, null);
TextView tvError = dview.findViewById(R.id.tvError);
tvError.setText(error);
return new AlertDialog.Builder(getContext()) return new AlertDialog.Builder(getContext())
.setMessage(error) .setView(dview)
.setPositiveButton(android.R.string.cancel, null) .setPositiveButton(R.string.title_boundary_retry, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sendResult(Activity.RESULT_OK);
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
sendResult(Activity.RESULT_CANCELED);
}
})
.create(); .create();
} }
} }

@ -207,6 +207,12 @@ public class ViewModelMessages extends ViewModel {
return model; return model;
} }
void retry(AdapterMessage.ViewType viewType) {
Model model = models.get(viewType);
if (model != null && model.boundary != null)
model.boundary.retry();
}
@Override @Override
protected void onCleared() { protected void onCleared() {
for (AdapterMessage.ViewType viewType : new ArrayList<>(models.keySet())) for (AdapterMessage.ViewType viewType : new ArrayList<>(models.keySet()))

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="24dp"
android:scrollbarStyle="outsideOverlay">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<eu.faircode.email.FixedTextView
android:id="@+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_boundary_error"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvError"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="Error"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvMessage" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

@ -1177,6 +1177,9 @@
<string name="title_pro_invalid">Invalid response</string> <string name="title_pro_invalid">Invalid response</string>
<string name="title_pro_support">FairEmail needs your help. Tap to purchase pro features to keep the project going.</string> <string name="title_pro_support">FairEmail needs your help. Tap to purchase pro features to keep the project going.</string>
<string name="title_boundary_error">Error on downloading messages from the email server</string>
<string name="title_boundary_retry">Try again</string>
<string name="title_unexpected_error">Unexpected error</string> <string name="title_unexpected_error">Unexpected error</string>
<string name="title_log">Log</string> <string name="title_log">Log</string>
<string name="title_auto_scroll">Auto scroll</string> <string name="title_auto_scroll">Auto scroll</string>

Loading…
Cancel
Save