Handle VPN exceptions back button if search open

This commit is contained in:
emanuele-f 2022-07-05 18:58:14 +02:00
parent a620d914b7
commit 2f2d3c87f1
4 changed files with 36 additions and 7 deletions

View File

@ -1287,4 +1287,14 @@ public class Utils {
// Delay otherwise the query won't be set when the activity is just started
searchView.post(() -> searchView.setQuery(query, true));
}
public static boolean backHandleSearchview(SearchView searchView) {
if((searchView != null) && !searchView.isIconified()) {
// Required to close the SearchView when the search submit button was not pressed
searchView.setIconified(true);
return true;
}
return false;
}
}

View File

@ -23,6 +23,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -61,6 +62,23 @@ public class VpnExceptionsActivity extends BaseActivity {
getSupportFragmentManager().putFragment(outState, "fragment", mFragment);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == android.R.id.home) {
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
if(mFragment.onBackPressed())
return;
super.onBackPressed();
}
public static class VpnExceptionsFragment extends AppsToggles {
private static final String TAG = "VpnExceptions";
private final Set<String> mExcludedApps = new HashSet<>();

View File

@ -122,6 +122,12 @@ public abstract class AppsToggles extends Fragment implements AppsLoadListener,
}
}
// NOTE: must be called from the activity
public boolean onBackPressed() {
Log.d(TAG, "onBackPressed");
return Utils.backHandleSearchview(mSearchView);
}
@Override
public boolean onQueryTextSubmit(String query) { return true; }

View File

@ -811,13 +811,8 @@ public class ConnectionsFragment extends Fragment implements ConnectionsListener
return true;
}
// NOTE: dispatched from activity, returns true if handled
public boolean onBackPressed() {
if((mSearchView != null) && !mSearchView.isIconified()) {
// Required to close the SearchView when the search submit button was not pressed
mSearchView.setIconified(true);
return true;
}
return false;
return Utils.backHandleSearchview(mSearchView);
}
}