Skip to content

Commit 7a36f86

Browse files
committed
Directly link to review comments from news feed
In order to implement this improvement I had to add an additional parameter to UrlLoadTask and ProgressDialogFragment. It is telling them whether the calling activity should be closed once the dialog is dismissed or operation finishes. Without that change the activity with news feed would be automatically closed after review is loaded, which is not what we want. We want the user to be able to return here by pressing back key.
1 parent db5f488 commit 7a36f86

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

app/src/main/java/com/gh4a/BrowseFilter.java

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ public void onCreate(Bundle savedInstanceState) {
239239
IntentUtils.InitialCommentMarker reviewCommentMarker =
240240
generateInitialCommentMarker(uri.getFragment(), "discussion_r");
241241
if (reviewCommentMarker != null) {
242-
new PullRequestReviewCommentLoadTask(user, repo, pullRequestNumber,
243-
reviewCommentMarker).execute();
242+
new PullRequestReviewCommentLoadTask(BrowseFilter.this, user, repo,
243+
pullRequestNumber, reviewCommentMarker, true).execute();
244244
return; // avoid finish() for now
245245
}
246246

@@ -350,6 +350,14 @@ private DiffHighlightId extractDiffId(String fragment, String prefix, boolean is
350350
}
351351

352352
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+
353361
@NonNull
354362
@Override
355363
public Dialog onCreateDialog(Bundle savedInstanceState) {
@@ -359,9 +367,12 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
359367
@Override
360368
public void onDismiss(DialogInterface dialog) {
361369
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+
}
365376
}
366377
}
367378
}
@@ -383,16 +394,24 @@ public DiffHighlightId(String fileHash, int startLine, int endLine, boolean righ
383394

384395
private static abstract class UrlLoadTask extends BackgroundTask<Intent> {
385396
protected FragmentActivity mActivity;
397+
private final boolean mFinishCurrentActivity;
398+
private ProgressDialogFragment mProgressDialog;
386399

387400
public UrlLoadTask(FragmentActivity activity) {
401+
this(activity, true);
402+
}
403+
404+
public UrlLoadTask(FragmentActivity activity, boolean finishCurrentActivity) {
388405
super(activity);
389406
mActivity = activity;
407+
mFinishCurrentActivity = finishCurrentActivity;
390408
}
391409

392410
@Override
393411
protected void onPreExecute() {
394412
super.onPreExecute();
395-
new ProgressDialogFragment().show(mActivity.getSupportFragmentManager(), "progress");
413+
mProgressDialog = ProgressDialogFragment.newInstance(mFinishCurrentActivity);
414+
mProgressDialog.show(mActivity.getSupportFragmentManager(), "progress");
396415
}
397416

398417
@Override
@@ -406,13 +425,23 @@ protected void onSuccess(Intent result) {
406425
} else {
407426
IntentUtils.launchBrowser(mActivity, mActivity.getIntent().getData());
408427
}
409-
mActivity.finish();
428+
429+
dismiss();
410430
}
411431

412432
@Override
413433
protected void onError(Exception e) {
414434
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+
}
416445
}
417446
}
418447

@@ -502,15 +531,16 @@ protected Intent run() throws Exception {
502531
}
503532
}
504533

505-
private class PullRequestReviewCommentLoadTask extends UrlLoadTask {
534+
public static class PullRequestReviewCommentLoadTask extends UrlLoadTask {
506535
private final String mRepoOwner;
507536
private final String mRepoName;
508537
private final int mPullRequestNumber;
509538
private final IntentUtils.InitialCommentMarker mMarker;
510539

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);
514544
mRepoOwner = repoOwner;
515545
mRepoName = repoName;
516546
mPullRequestNumber = pullRequestNumber;
@@ -547,14 +577,15 @@ protected Intent run() throws Exception {
547577

548578
Review review = pullRequestService.getReview(repoId, mPullRequestNumber,
549579
reviewId);
550-
return ReviewActivity.makeIntent(BrowseFilter.this, mRepoOwner, mRepoName,
580+
return ReviewActivity.makeIntent(mActivity, mRepoOwner, mRepoName,
551581
mPullRequestNumber, review, mMarker);
552582
}
553583
}
554584

555585
return null;
556586
}
557587
}
588+
558589
private class PullRequestReviewLoadTask extends UrlLoadTask {
559590
private final String mRepoOwner;
560591
private final String mRepoName;

app/src/main/java/com/gh4a/fragment/EventListFragment.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,13 @@ public void onItemClick(Event event) {
246246
? new IntentUtils.InitialCommentMarker(comment.getId()) : null;
247247

248248
if (pr != null) {
249-
intent = PullRequestActivity.makeIntent(getActivity(),
250-
repoOwner, repoName, pr.getNumber(),
251-
initialComment != null ? PullRequestActivity.PAGE_CONVERSATION : -1,
252-
initialComment);
249+
if (initialComment != null) {
250+
new BrowseFilter.PullRequestReviewCommentLoadTask(getActivity(), repoOwner,
251+
repoName, pr.getNumber(), initialComment, false).schedule();
252+
} else {
253+
intent = PullRequestActivity.makeIntent(getActivity(), repoOwner, repoName,
254+
pr.getNumber(), -1, null);
255+
}
253256
} else if (comment != null) {
254257
intent = CommitActivity.makeIntent(getActivity(), repoOwner, repoName,
255258
comment.getCommitId(), initialComment);

0 commit comments

Comments
 (0)