Skip to content

Commit

Permalink
Close search activity if its data is saved
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
  • Loading branch information
jruesga committed Oct 20, 2016
1 parent 7379fb0 commit 3dfae49
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mBinding = DataBindingUtil.setContentView(this, R.layout.content);
setResult(RESULT_CANCELED);

// Check we have valid arguments
if (getIntent() == null) {
Expand Down Expand Up @@ -195,6 +196,8 @@ private void performSaveCustomFilter(View v) {
getSupportActionBar().setTitle(newValue);
}
invalidateOptionsMenu();

setResult(RESULT_OK);
});
fragment.show(getSupportFragmentManager(), EditDialogFragment.TAG);
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/ruesga/rview/SearchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import android.animation.Animator;
import android.annotation.TargetApi;
import android.content.Intent;
import android.content.res.TypedArray;
import android.databinding.DataBindingUtil;
import android.os.Build;
Expand Down Expand Up @@ -108,6 +109,14 @@ public void onSearchAction(String currentQuery) {
enterReveal();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == ActivityHelper.LIST_RESULT_CODE && resultCode == RESULT_OK) {
// Directly finish this activity. The search data was used
finish();
}
}

@Override
public void onBackPressed() {
exitReveal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ private void performApplyFilter(View v) {
filter = new ChangeQuery().topic(((TextView) v).getText().toString());
break;
}
ActivityHelper.openChangeListByFilterActivity(getContext(), title, filter, false);
ActivityHelper.openChangeListByFilterActivity(getActivity(), title, filter, false);
}

private void performAction(View v) {
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/ruesga/rview/misc/ActivityHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@

public class ActivityHelper {

public static final int LIST_RESULT_CODE = 100;

public static void openUriInCustomTabs(Activity activity, String uri) {
openUriInCustomTabs(activity, Uri.parse(uri));
}
Expand Down Expand Up @@ -149,12 +151,12 @@ public static void openChangeDetails(Context context, ChangeInfo change, boolean
}

public static void openChangeListByFilterActivity(
Context context, String title, ChangeQuery filter, boolean dirty) {
Intent intent = new Intent(context, ChangeListByFilterActivity.class);
Activity activity, String title, ChangeQuery filter, boolean dirty) {
Intent intent = new Intent(activity, ChangeListByFilterActivity.class);
intent.putExtra(Constants.EXTRA_TITLE, title);
intent.putExtra(Constants.EXTRA_FILTER, filter.toString());
intent.putExtra(Constants.EXTRA_DIRTY, dirty);
context.startActivity(intent);
activity.startActivityForResult(intent, LIST_RESULT_CODE);
}

public static void openRelatedChangesActivity(
Expand Down

0 comments on commit 3dfae49

Please sign in to comment.