Skip to content

Commit 4069619

Browse files
committed
make sure, only one error alert is shown
DcBackupProvider.unref() will soon also emit errors, see chatmail/core#4242 , but also before, this was only correct by coincidence
1 parent fbf7f17 commit 4069619

3 files changed

Lines changed: 26 additions & 26 deletions

File tree

src/org/thoughtcrime/securesms/qr/BackupProviderFragment.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
7474
}
7575
progressBar.setVisibility(View.GONE);
7676
if (!dcBackupProvider.isOk()) {
77-
activity.setTransferState(BackupTransferActivity.TransferState.TRANSFER_ERROR);
78-
activity.showLastErrorAlert("Cannot create backup provider");
77+
activity.setTransferError("Cannot create backup provider");
7978
return;
8079
}
8180
statusLine.setVisibility(View.GONE);
@@ -144,8 +143,7 @@ public void handleEvent(@NonNull DcEvent event) {
144143

145144
Log.i(TAG,"DC_EVENT_IMEX_PROGRESS, " + permille);
146145
if (permille == 0) {
147-
getTransferActivity().setTransferState(BackupTransferActivity.TransferState.TRANSFER_ERROR);
148-
getTransferActivity().showLastErrorAlert("Sending Error");
146+
getTransferActivity().setTransferError("Sending Error");
149147
hideQrCode = true;
150148
} else if(permille <= 350) {
151149
statusLineText = getString(R.string.preparing_account);

src/org/thoughtcrime/securesms/qr/BackupReceiverFragment.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ public void handleEvent(@NonNull DcEvent event) {
8080

8181
Log.i(TAG,"DC_EVENT_IMEX_PROGRESS, " + permille);
8282
if (permille == 0) {
83-
getTransferActivity().setTransferState(BackupTransferActivity.TransferState.TRANSFER_ERROR);
84-
getTransferActivity().showLastErrorAlert("Receiving Error");
83+
getTransferActivity().setTransferError("Receiving Error");
8584
} else if (permille <= 100) {
8685
statusLineText = getString(R.string.preparing_account);
8786
hideSameNetworkHint = true;

src/org/thoughtcrime/securesms/qr/BackupTransferActivity.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import androidx.appcompat.app.ActionBar;
1616
import androidx.appcompat.app.AlertDialog;
1717

18-
import org.thoughtcrime.securesms.ApplicationContext;
1918
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
2019
import org.thoughtcrime.securesms.BaseActionBarActivity;
2120
import org.thoughtcrime.securesms.ConversationListActivity;
@@ -148,6 +147,29 @@ public void setTransferState(TransferState transferState) {
148147
this.transferState = transferState;
149148
}
150149

150+
public void setTransferError(@NonNull String errorContext) {
151+
if (this.transferState != TransferState.TRANSFER_ERROR) {
152+
this.transferState = TransferState.TRANSFER_ERROR;
153+
154+
String lastError = DcHelper.getContext(this).getLastError();
155+
if (lastError.isEmpty()) {
156+
lastError = "<last error not set>";
157+
}
158+
159+
String error = errorContext;
160+
if (!error.isEmpty()) {
161+
error += ": ";
162+
}
163+
error += lastError;
164+
165+
new AlertDialog.Builder(this)
166+
.setMessage(error)
167+
.setPositiveButton(android.R.string.ok, null)
168+
.setCancelable(false)
169+
.show();
170+
}
171+
}
172+
151173
private void finishOrAskToFinish() {
152174
switch (transferState) {
153175
case TRANSFER_ERROR:
@@ -193,25 +215,6 @@ public void doFinish() {
193215
finish();
194216
}
195217

196-
public void showLastErrorAlert(@NonNull String errorContext) {
197-
String lastError = DcHelper.getContext(this).getLastError();
198-
if (lastError.isEmpty()) {
199-
lastError = "<last error not set>";
200-
}
201-
202-
String error = errorContext;
203-
if (!error.isEmpty()) {
204-
error += ": ";
205-
}
206-
error += lastError;
207-
208-
new AlertDialog.Builder(this)
209-
.setMessage(error)
210-
.setPositiveButton(android.R.string.ok, null)
211-
.setCancelable(false)
212-
.show();
213-
}
214-
215218
public static void appendSSID(Activity activity, final TextView textView) {
216219
if (textView != null && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
217220
new Thread(() -> {

0 commit comments

Comments
 (0)