1
1
package org .thoughtcrime .securesms .registration .fragments ;
2
2
3
- import static org .thoughtcrime .securesms .registration .fragments .RegistrationViewDelegate .setDebugLogSubmitMultiTapView ;
4
- import static org .thoughtcrime .securesms .util .CircularProgressButtonUtil .cancelSpinning ;
5
- import static org .thoughtcrime .securesms .util .CircularProgressButtonUtil .setSpinning ;
6
-
7
3
import android .annotation .SuppressLint ;
8
4
import android .app .Activity ;
9
5
import android .content .Context ;
31
27
import androidx .annotation .Nullable ;
32
28
import androidx .annotation .RequiresApi ;
33
29
import androidx .appcompat .app .AlertDialog ;
34
- import androidx .lifecycle .ViewModelProviders ;
30
+ import androidx .lifecycle .ViewModelProvider ;
35
31
import androidx .navigation .Navigation ;
36
32
37
33
import com .dd .CircularProgressButton ;
57
53
import org .thoughtcrime .securesms .service .LocalBackupListener ;
58
54
import org .thoughtcrime .securesms .util .BackupUtil ;
59
55
import org .thoughtcrime .securesms .util .DateUtils ;
60
- import org .thoughtcrime .securesms .util .TextSecurePreferences ;
61
56
import org .thoughtcrime .securesms .util .Util ;
62
57
import org .thoughtcrime .securesms .util .concurrent .SimpleTask ;
63
58
64
59
import java .io .IOException ;
65
60
import java .util .Locale ;
66
61
62
+ import static org .thoughtcrime .securesms .registration .fragments .RegistrationViewDelegate .setDebugLogSubmitMultiTapView ;
63
+ import static org .thoughtcrime .securesms .util .CircularProgressButtonUtil .cancelSpinning ;
64
+ import static org .thoughtcrime .securesms .util .CircularProgressButtonUtil .setSpinning ;
65
+
67
66
public final class RestoreBackupFragment extends LoggingFragment {
68
67
69
68
private static final String TAG = Log .tag (RestoreBackupFragment .class );
@@ -74,6 +73,7 @@ public final class RestoreBackupFragment extends LoggingFragment {
74
73
private TextView restoreBackupProgress ;
75
74
private CircularProgressButton restoreButton ;
76
75
private View skipRestoreButton ;
76
+ private RegistrationViewModel viewModel ;
77
77
78
78
@ Override
79
79
public View onCreateView (LayoutInflater inflater , ViewGroup container ,
@@ -101,14 +101,20 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
101
101
.navigate (RestoreBackupFragmentDirections .actionSkip ());
102
102
});
103
103
104
- RegistrationViewModel viewModel = ViewModelProviders .of (requireActivity ()).get (RegistrationViewModel .class );
104
+ viewModel = new ViewModelProvider (requireActivity ()).get (RegistrationViewModel .class );
105
+
105
106
if (viewModel .isReregister ()) {
106
107
Log .i (TAG , "Skipping backup restore during re-register." );
107
108
Navigation .findNavController (view )
108
109
.navigate (RestoreBackupFragmentDirections .actionSkipNoReturn ());
109
110
return ;
110
111
}
111
112
113
+ if (viewModel .hasBackupCompleted ()) {
114
+ onBackupComplete ();
115
+ return ;
116
+ }
117
+
112
118
if (SignalStore .settings ().isBackupEnabled ()) {
113
119
Log .i (TAG , "Backups enabled, so a backup must have been previously restored." );
114
120
Navigation .findNavController (view )
@@ -279,6 +285,7 @@ protected BackupImportResult doInBackground(Void... voids) {
279
285
280
286
@ Override
281
287
protected void onPostExecute (@ NonNull BackupImportResult result ) {
288
+ viewModel .markBackupCompleted ();
282
289
cancelSpinning (restoreButton );
283
290
skipRestoreButton .setVisibility (View .VISIBLE );
284
291
@@ -305,6 +312,14 @@ public void onStart() {
305
312
EventBus .getDefault ().register (this );
306
313
}
307
314
315
+ @ Override
316
+ public void onResume () {
317
+ super .onResume ();
318
+ if (viewModel != null && viewModel .hasBackupCompleted ()) {
319
+ onBackupComplete ();
320
+ }
321
+ }
322
+
308
323
@ Override
309
324
public void onStop () {
310
325
super .onStop ();
@@ -325,12 +340,16 @@ public void onEvent(@NonNull FullBackupBase.BackupEvent event) {
325
340
skipRestoreButton .setVisibility (View .INVISIBLE );
326
341
327
342
if (event .getType () == FullBackupBase .BackupEvent .Type .FINISHED ) {
328
- if (BackupUtil .isUserSelectionRequired (requireContext ()) && !BackupUtil .canUserAccessBackupDirectory (requireContext ())) {
329
- displayConfirmationDialog (requireContext ());
330
- } else {
331
- Navigation .findNavController (requireView ())
332
- .navigate (RestoreBackupFragmentDirections .actionBackupRestored ());
333
- }
343
+ onBackupComplete ();
344
+ }
345
+ }
346
+
347
+ private void onBackupComplete () {
348
+ if (BackupUtil .isUserSelectionRequired (requireContext ()) && !BackupUtil .canUserAccessBackupDirectory (requireContext ())) {
349
+ displayConfirmationDialog (requireContext ());
350
+ } else {
351
+ Navigation .findNavController (requireView ())
352
+ .navigate (RestoreBackupFragmentDirections .actionBackupRestored ());
334
353
}
335
354
}
336
355
0 commit comments