@@ -239,8 +239,8 @@ public void onCreate(Bundle savedInstanceState) {
239
239
IntentUtils .InitialCommentMarker reviewCommentMarker =
240
240
generateInitialCommentMarker (uri .getFragment (), "discussion_r" );
241
241
if (reviewCommentMarker != null ) {
242
- new PullRequestReviewCommentLoadTask (user , repo , pullRequestNumber ,
243
- reviewCommentMarker ).execute ();
242
+ new PullRequestReviewCommentLoadTask (BrowseFilter . this , user , repo ,
243
+ pullRequestNumber , reviewCommentMarker , true ).execute ();
244
244
return ; // avoid finish() for now
245
245
}
246
246
@@ -350,6 +350,14 @@ private DiffHighlightId extractDiffId(String fragment, String prefix, boolean is
350
350
}
351
351
352
352
public static class ProgressDialogFragment extends DialogFragment {
353
+ public static ProgressDialogFragment newInstance (boolean finishCurrentActivity ) {
354
+ Bundle args = new Bundle ();
355
+ args .putBoolean ("finish_activity" , finishCurrentActivity );
356
+ ProgressDialogFragment dialogFragment = new ProgressDialogFragment ();
357
+ dialogFragment .setArguments (args );
358
+ return dialogFragment ;
359
+ }
360
+
353
361
@ NonNull
354
362
@ Override
355
363
public Dialog onCreateDialog (Bundle savedInstanceState ) {
@@ -359,9 +367,12 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
359
367
@ Override
360
368
public void onDismiss (DialogInterface dialog ) {
361
369
super .onDismiss (dialog );
362
- Activity activity = getActivity ();
363
- if (activity != null ) {
364
- activity .finish ();
370
+ Bundle args = getArguments ();
371
+ if (args != null && args .getBoolean ("finish_activity" )) {
372
+ Activity activity = getActivity ();
373
+ if (activity != null ) {
374
+ activity .finish ();
375
+ }
365
376
}
366
377
}
367
378
}
@@ -383,16 +394,24 @@ public DiffHighlightId(String fileHash, int startLine, int endLine, boolean righ
383
394
384
395
private static abstract class UrlLoadTask extends BackgroundTask <Intent > {
385
396
protected FragmentActivity mActivity ;
397
+ private final boolean mFinishCurrentActivity ;
398
+ private ProgressDialogFragment mProgressDialog ;
386
399
387
400
public UrlLoadTask (FragmentActivity activity ) {
401
+ this (activity , true );
402
+ }
403
+
404
+ public UrlLoadTask (FragmentActivity activity , boolean finishCurrentActivity ) {
388
405
super (activity );
389
406
mActivity = activity ;
407
+ mFinishCurrentActivity = finishCurrentActivity ;
390
408
}
391
409
392
410
@ Override
393
411
protected void onPreExecute () {
394
412
super .onPreExecute ();
395
- new ProgressDialogFragment ().show (mActivity .getSupportFragmentManager (), "progress" );
413
+ mProgressDialog = ProgressDialogFragment .newInstance (mFinishCurrentActivity );
414
+ mProgressDialog .show (mActivity .getSupportFragmentManager (), "progress" );
396
415
}
397
416
398
417
@ Override
@@ -406,13 +425,23 @@ protected void onSuccess(Intent result) {
406
425
} else {
407
426
IntentUtils .launchBrowser (mActivity , mActivity .getIntent ().getData ());
408
427
}
409
- mActivity .finish ();
428
+
429
+ dismiss ();
410
430
}
411
431
412
432
@ Override
413
433
protected void onError (Exception e ) {
414
434
IntentUtils .launchBrowser (mActivity , mActivity .getIntent ().getData ());
415
- mActivity .finish ();
435
+ dismiss ();
436
+ }
437
+
438
+ private void dismiss () {
439
+ if (mProgressDialog != null ) {
440
+ // Progress dialog will automatically finish current activity if necessary
441
+ mProgressDialog .dismiss ();
442
+ } else if (mFinishCurrentActivity ) {
443
+ mActivity .finish ();
444
+ }
416
445
}
417
446
}
418
447
@@ -502,15 +531,16 @@ protected Intent run() throws Exception {
502
531
}
503
532
}
504
533
505
- private class PullRequestReviewCommentLoadTask extends UrlLoadTask {
534
+ public static class PullRequestReviewCommentLoadTask extends UrlLoadTask {
506
535
private final String mRepoOwner ;
507
536
private final String mRepoName ;
508
537
private final int mPullRequestNumber ;
509
538
private final IntentUtils .InitialCommentMarker mMarker ;
510
539
511
- public PullRequestReviewCommentLoadTask (String repoOwner , String repoName ,
512
- int pullRequestNumber , IntentUtils .InitialCommentMarker marker ) {
513
- super (BrowseFilter .this );
540
+ public PullRequestReviewCommentLoadTask (FragmentActivity activity , String repoOwner ,
541
+ String repoName , int pullRequestNumber , IntentUtils .InitialCommentMarker marker ,
542
+ boolean finishCurrentActivity ) {
543
+ super (activity , finishCurrentActivity );
514
544
mRepoOwner = repoOwner ;
515
545
mRepoName = repoName ;
516
546
mPullRequestNumber = pullRequestNumber ;
@@ -547,14 +577,15 @@ protected Intent run() throws Exception {
547
577
548
578
Review review = pullRequestService .getReview (repoId , mPullRequestNumber ,
549
579
reviewId );
550
- return ReviewActivity .makeIntent (BrowseFilter . this , mRepoOwner , mRepoName ,
580
+ return ReviewActivity .makeIntent (mActivity , mRepoOwner , mRepoName ,
551
581
mPullRequestNumber , review , mMarker );
552
582
}
553
583
}
554
584
555
585
return null ;
556
586
}
557
587
}
588
+
558
589
private class PullRequestReviewLoadTask extends UrlLoadTask {
559
590
private final String mRepoOwner ;
560
591
private final String mRepoName ;
0 commit comments