Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
fix(YouTube - Settings): Actually prevent autofocus on the search bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco146 committed Sep 9, 2024
1 parent 40fad5e commit b46fd8a
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
import android.widget.SearchView.OnQueryTextListener;
import android.widget.TextView;
import android.widget.Toolbar;

import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.util.Objects;

import app.revanced.integrations.shared.utils.Logger;
import app.revanced.integrations.shared.utils.ResourceUtils;
import app.revanced.integrations.shared.utils.Utils;
import app.revanced.integrations.youtube.settings.preference.ReVancedPreferenceFragment;
import app.revanced.integrations.youtube.utils.ThemeUtils;

import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.util.Objects;

@SuppressWarnings("deprecation")
public class VideoQualitySettingsActivity extends Activity {

Expand Down Expand Up @@ -185,10 +184,19 @@ private void setSearchView() {
// Set the listener for query text changes
searchView.setOnQueryTextListener(onQueryTextListener);

// Clear focus on SearchView to prevent autofocus when returning to the activity
searchView.clearFocus();

// Keep a weak reference to the SearchView
searchViewRef = new WeakReference<>(searchView);
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus || searchViewRef.get() == null) return;

SearchView searchView = searchViewRef.get();

if (searchView.getQuery().length() != 0) return;

searchView.clearFocus();
}
}

0 comments on commit b46fd8a

Please sign in to comment.