use dc_get_last_error() api (#2109)

* add getLastError() api

* use getLastError() for QR code processing

* use getLastError() for import/export

* remove now unused getCapturedError()
This commit is contained in:
bjoern
2021-11-25 12:15:39 +01:00
committed by GitHub
parent 1b68e13d9c
commit 447e879bac
6 changed files with 24 additions and 24 deletions
+9
View File
@@ -347,6 +347,15 @@ JNIEXPORT jstring Java_com_b44t_messenger_DcContext_getBlobdir(JNIEnv *env, jobj
}
JNIEXPORT jstring Java_com_b44t_messenger_DcContext_getLastError(JNIEnv *env, jobject obj)
{
char* temp = dc_get_last_error(get_dc_context(env, obj));
jstring ret = JSTRING_NEW(temp);
dc_str_unref(temp);
return ret;
}
JNIEXPORT void Java_com_b44t_messenger_DcContext_configure(JNIEnv *env, jobject obj)
{
dc_configure(get_dc_context(env, obj));
+1
View File
@@ -115,6 +115,7 @@ public class DcContext {
public native void setStockTranslation (int stockId, String translation);
public native String getBlobdir ();
public native String getLastError ();
public native void configure ();
public native void stopOngoingProcess ();
public native int isConfigured ();
@@ -56,6 +56,7 @@ public class WelcomeActivity extends BaseActionBarActivity implements DcEventCen
private boolean manualConfigure = true; // false: configure by QR account creation
private ProgressDialog progressDialog = null;
private boolean imexUserAborted;
DcContext dcContext;
private NotificationController notificationController;
@@ -164,11 +165,13 @@ public class WelcomeActivity extends BaseActionBarActivity implements DcEventCen
progressDialog = null;
}
imexUserAborted = false;
progressDialog = new ProgressDialog(this);
progressDialog.setMessage(getResources().getString(R.string.one_moment));
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setCancelable(false);
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.cancel), (dialog, which) -> {
imexUserAborted = true;
dcContext.stopOngoingProcess();
notificationController.close();
cleanupTempBackupFile();
@@ -222,9 +225,7 @@ public class WelcomeActivity extends BaseActionBarActivity implements DcEventCen
DcHelper.getEventCenter(this).captureNextError();
if (!dcContext.setConfigFromQr(qrCode)) {
Util.sleep(100); // hack to avoid a race condition, see https://github.com/deltachat/deltachat-core-rust/issues/2787 for more details and possible fix
String err = DcHelper.getEventCenter(this).getCapturedError();
progressError(TextUtils.isEmpty(err) ? "Cannot create account from QR code." : err);
progressError(dcContext.getLastError());
return;
}
@@ -281,7 +282,9 @@ public class WelcomeActivity extends BaseActionBarActivity implements DcEventCen
if (eventId== DcContext.DC_EVENT_IMEX_PROGRESS ) {
long progress = event.getData1Int();
if (progress==0/*error/aborted*/) {
progressError(DcHelper.getEventCenter(this).getCapturedError());
if (!imexUserAborted) {
progressError(dcContext.getLastError());
}
notificationController.close();
cleanupTempBackupFile();
}
@@ -95,25 +95,11 @@ public class DcEventCenter {
}
private final Object lastErrorLock = new Object();
private String lastErrorString = "";
private boolean showNextErrorAsToast = true;
public void captureNextError() {
synchronized (lastErrorLock) {
showNextErrorAsToast = false;
lastErrorString = "";
}
}
public boolean hasCapturedError() {
synchronized (lastErrorLock) {
return !lastErrorString.isEmpty();
}
}
public String getCapturedError() {
synchronized (lastErrorLock) {
return lastErrorString;
}
}
@@ -128,7 +114,6 @@ public class DcEventCenter {
boolean showAsToast;
Log.e("DeltaChat", string);
synchronized (lastErrorLock) {
lastErrorString = string;
showAsToast = showNextErrorAsToast;
showNextErrorAsToast = true;
}
@@ -101,8 +101,10 @@ public abstract class ListSummaryPreferenceFragment extends CorrectedPreferenceF
protected ProgressDialog progressDialog = null;
protected int progressWhat = 0;
protected String imexDir = "";
protected boolean imexUserAborted = false;
protected void startImex(int what)
{
imexUserAborted = false;
notificationController = GenericForegroundService.startForegroundTask(getContext(), getString(R.string.export_backup_desktop));
if( progressDialog!=null ) {
progressDialog.dismiss();
@@ -114,6 +116,7 @@ public abstract class ListSummaryPreferenceFragment extends CorrectedPreferenceF
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setCancelable(false);
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel), (dialog, which) -> {
imexUserAborted = true;
dcContext.stopOngoingProcess();
notificationController.close();
notificationController = null;
@@ -136,9 +139,9 @@ public abstract class ListSummaryPreferenceFragment extends CorrectedPreferenceF
DcHelper.getAccounts(context).startIo();
progressDialog.dismiss();
progressDialog = null;
if (DcHelper.getEventCenter(context).hasCapturedError()) {
if (!imexUserAborted) {
new AlertDialog.Builder(context)
.setMessage(DcHelper.getEventCenter(context).getCapturedError())
.setMessage(dcContext.getLastError())
.setPositiveButton(android.R.string.ok, null)
.show();
}
@@ -205,16 +205,15 @@ public class QrCodeHandler {
builder.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
DcHelper.getEventCenter(activity).captureNextError();
int newChatId = dcContext.joinSecurejoin(qrRawString);
String errorString = DcHelper.getEventCenter(activity).getCapturedError();
DcHelper.getEventCenter(activity).endCaptureNextError();
if (newChatId != 0) {
Intent intent = new Intent(activity, ConversationActivity.class);
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, newChatId);
activity.startActivity(intent);
} else if (!errorString.isEmpty()) {
} else {
AlertDialog.Builder builder1 = new AlertDialog.Builder(activity);
builder1.setMessage(errorString);
builder1.setMessage(dcContext.getLastError());
builder1.setPositiveButton(android.R.string.ok, null);
builder1.create().show();
}