Skip to content

Commit

Permalink
Revert "Don't use a special intent extra for new task handling."
Browse files Browse the repository at this point in the history
In activities started via BrowseFilter, we still want the back
navigation.

This reverts commit 59d649e.
  • Loading branch information
maniac103 committed May 4, 2020
1 parent 3e6160f commit d84c514
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 21 deletions.
15 changes: 6 additions & 9 deletions app/src/main/java/com/gh4a/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public interface RefreshableChild {
@TargetApi(21)
@Override
public void run() {
String label = wasStartedAsNewTask() ? getActionBarTitle() : null;
String label = IntentUtils.isNewTaskIntent(getIntent()) ? getActionBarTitle() : null;
setTaskDescription(new ActivityManager.TaskDescription(label, null,
mProgressColors[0]));
}
Expand All @@ -152,7 +152,7 @@ protected void onCreate(Bundle savedInstanceState) {
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(getActionBarTitle());
actionBar.setSubtitle(getActionBarSubtitle());
actionBar.setDisplayHomeAsUpEnabled(!wasStartedAsNewTask());
actionBar.setDisplayHomeAsUpEnabled(!IntentUtils.isNewTaskIntent(getIntent()));

scheduleTaskDescriptionUpdate();
}
Expand Down Expand Up @@ -467,19 +467,15 @@ public MenuInflater getMenuInflater() {
@CallSuper
public boolean onCreateOptionsMenu(Menu menu) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
&& !wasStartedAsNewTask()
&& !IntentUtils.isNewTaskIntent(getIntent())
&& displayDetachAction()) {
menu.add(Menu.NONE, R.id.detach, Menu.NONE, R.string.detach);
}

return super.onCreateOptionsMenu(menu);
}

protected boolean wasStartedAsNewTask() {
return (getIntent().getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0;
}

protected boolean displayDetachAction() {
public boolean displayDetachAction() {
return false;
}

Expand Down Expand Up @@ -585,7 +581,8 @@ public void onBackPressed() {
if (closeDrawers()) {
return;
}
if (wasStartedAsNewTask() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
boolean wasStartedAsNewTask = (getIntent().getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0;
if (wasStartedAsNewTask && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
finishAndRemoveTask();
} else {
super.onBackPressed();
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/gh4a/activities/CommitActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ protected boolean fragmentNeedsRefresh(Fragment object) {
}

@Override
protected boolean displayDetachAction() {
public boolean displayDetachAction() {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,6 @@ protected void onNewIntent(Intent intent) {
}
}

@Override
protected boolean wasStartedAsNewTask() {
// As this is the entry point activity, it's normal to be started as new task,
// so pretend it wasn't started as new task to avoid BaseActivity's special handling.
return false;
}

private boolean handleIntent(Intent intent) {
Uri data = intent.getData();
if (data != null
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/gh4a/activities/IssueActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
}

@Override
protected boolean displayDetachAction() {
public boolean displayDetachAction() {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
}

@Override
protected boolean displayDetachAction() {
public boolean displayDetachAction() {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/gh4a/activities/UserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected void onFragmentDestroyed(Fragment f) {
}

@Override
protected boolean displayDetachAction() {
public boolean displayDetachAction() {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void onCreate(Bundle savedInstanceState) {
}

@Override
protected boolean displayDetachAction() {
public boolean displayDetachAction() {
return true;
}

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/gh4a/utils/IntentUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.zip.GZIPOutputStream;

public class IntentUtils {
private static final String EXTRA_NEW_TASK = "IntentUtils.new_task";
private static final String RAW_URL_FORMAT = "https://raw.githubusercontent.com/%s/%s/%s/%s";

private IntentUtils() {
Expand Down Expand Up @@ -181,9 +182,14 @@ public static void startNewTask(@NonNull Context context, @NonNull Intent intent
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
}
intent.putExtra(EXTRA_NEW_TASK, true);
context.startActivity(intent);
}

public static boolean isNewTaskIntent(@Nullable Intent intent) {
return intent != null && intent.getBooleanExtra(EXTRA_NEW_TASK, false);
}

public static void putParcelableToBundleCompressed(Bundle bundle,
String key, Parcelable parcelable, int thresholdBytes) {
Parcel parcel = Parcel.obtain();
Expand Down

0 comments on commit d84c514

Please # to comment.