Add search function to preferences
This commit is contained in:
parent
d7d614f33f
commit
f8950ae9b8
|
@ -173,6 +173,7 @@ dependencies {
|
||||||
implementation "com.github.AntennaPod:AntennaPod-AudioPlayer:$audioPlayerVersion"
|
implementation "com.github.AntennaPod:AntennaPod-AudioPlayer:$audioPlayerVersion"
|
||||||
|
|
||||||
implementation 'com.github.mfietz:fyydlin:v0.3'
|
implementation 'com.github.mfietz:fyydlin:v0.3'
|
||||||
|
implementation 'com.github.ByteHamster:SearchPreference:v1.0.2'
|
||||||
|
|
||||||
androidTestImplementation "com.jayway.android.robotium:robotium-solo:$robotiumSoloVersion"
|
androidTestImplementation "com.jayway.android.robotium:robotium-solo:$robotiumSoloVersion"
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,9 @@ import android.widget.FrameLayout;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
|
import com.bytehamster.lib.preferencesearch.SearchPreference;
|
||||||
|
import com.bytehamster.lib.preferencesearch.SearchPreferenceResult;
|
||||||
|
import com.bytehamster.lib.preferencesearch.SearchPreferenceResultListener;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.preferences.PreferenceController;
|
import de.danoeh.antennapod.preferences.PreferenceController;
|
||||||
|
@ -22,7 +25,7 @@ import de.danoeh.antennapod.preferences.PreferenceController;
|
||||||
* PreferenceActivity for API 11+. In order to change the behavior of the preference UI, see
|
* PreferenceActivity for API 11+. In order to change the behavior of the preference UI, see
|
||||||
* PreferenceController.
|
* PreferenceController.
|
||||||
*/
|
*/
|
||||||
public class PreferenceActivity extends AppCompatActivity {
|
public class PreferenceActivity extends AppCompatActivity implements SearchPreferenceResultListener {
|
||||||
|
|
||||||
public static final String PARAM_RESOURCE = "resource";
|
public static final String PARAM_RESOURCE = "resource";
|
||||||
private static WeakReference<PreferenceActivity> instance;
|
private static WeakReference<PreferenceActivity> instance;
|
||||||
|
@ -35,6 +38,11 @@ public class PreferenceActivity extends AppCompatActivity {
|
||||||
this.fragment = fragment;
|
this.fragment = fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreferenceFragmentCompat getFragment() {
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Preference findPreference(CharSequence key) {
|
public Preference findPreference(CharSequence key) {
|
||||||
return fragment.findPreference(key);
|
return fragment.findPreference(key);
|
||||||
|
@ -76,12 +84,21 @@ public class PreferenceActivity extends AppCompatActivity {
|
||||||
// since the MainFragment depends on the preferenceController already being created
|
// since the MainFragment depends on the preferenceController already being created
|
||||||
preferenceController = new PreferenceController(preferenceUI);
|
preferenceController = new PreferenceController(preferenceUI);
|
||||||
|
|
||||||
|
showPreferenceScreen(R.xml.preferences, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showPreferenceScreen(int screen, boolean addHistory) {
|
||||||
PreferenceFragmentCompat prefFragment = new MainFragment();
|
PreferenceFragmentCompat prefFragment = new MainFragment();
|
||||||
preferenceUI.setFragment(prefFragment);
|
preferenceUI.setFragment(prefFragment);
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putInt(PARAM_RESOURCE, R.xml.preferences);
|
args.putInt(PARAM_RESOURCE, screen);
|
||||||
prefFragment.setArguments(args);
|
prefFragment.setArguments(args);
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.content, prefFragment).commit();
|
if (addHistory) {
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.content, prefFragment)
|
||||||
|
.addToBackStack(getString(PreferenceController.getTitleOfPage(screen))).commit();
|
||||||
|
} else {
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.content, prefFragment).commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -111,6 +128,12 @@ public class PreferenceActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSearchResultClicked(SearchPreferenceResult result) {
|
||||||
|
showPreferenceScreen(result.getResourceFile(), true);
|
||||||
|
result.highlight(preferenceUI.getFragment());
|
||||||
|
}
|
||||||
|
|
||||||
public static class MainFragment extends PreferenceFragmentCompat {
|
public static class MainFragment extends PreferenceFragmentCompat {
|
||||||
private int screen;
|
private int screen;
|
||||||
|
|
||||||
|
@ -136,7 +159,7 @@ public class PreferenceActivity extends AppCompatActivity {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
PreferenceActivity activity = instance.get();
|
PreferenceActivity activity = instance.get();
|
||||||
if(activity != null && activity.preferenceController != null) {
|
if(activity != null && activity.preferenceController != null) {
|
||||||
activity.setTitle(activity.preferenceController.getTitleOfPage(screen));
|
activity.setTitle(PreferenceController.getTitleOfPage(screen));
|
||||||
activity.preferenceUI.setFragment(this);
|
activity.preferenceUI.setFragment(this);
|
||||||
activity.preferenceController.onResume(screen);
|
activity.preferenceController.onResume(screen);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import com.afollestad.materialdialogs.MaterialDialog;
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||||||
|
|
||||||
|
import com.bytehamster.lib.preferencesearch.SearchPreference;
|
||||||
import de.danoeh.antennapod.activity.AboutActivity;
|
import de.danoeh.antennapod.activity.AboutActivity;
|
||||||
import de.danoeh.antennapod.activity.ImportExportActivity;
|
import de.danoeh.antennapod.activity.ImportExportActivity;
|
||||||
import de.danoeh.antennapod.activity.MediaplayerActivity;
|
import de.danoeh.antennapod.activity.MediaplayerActivity;
|
||||||
|
@ -489,6 +490,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
|
||||||
|
|
||||||
private void setupMainScreen() {
|
private void setupMainScreen() {
|
||||||
final AppCompatActivity activity = ui.getActivity();
|
final AppCompatActivity activity = ui.getActivity();
|
||||||
|
setupSearch();
|
||||||
ui.findPreference(PREF_SCREEN_USER_INTERFACE).setOnPreferenceClickListener(preference -> {
|
ui.findPreference(PREF_SCREEN_USER_INTERFACE).setOnPreferenceClickListener(preference -> {
|
||||||
openScreen(R.xml.preferences_user_interface, activity);
|
openScreen(R.xml.preferences_user_interface, activity);
|
||||||
return true;
|
return true;
|
||||||
|
@ -555,6 +557,25 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupSearch() {
|
||||||
|
final AppCompatActivity activity = ui.getActivity();
|
||||||
|
|
||||||
|
SearchPreference searchPreference = (SearchPreference) ui.findPreference("searchPreference");
|
||||||
|
searchPreference.setActivity(activity);
|
||||||
|
searchPreference.setFragmentContainerViewId(R.id.content);
|
||||||
|
searchPreference.setBreadcrumbsEnabled(true);
|
||||||
|
|
||||||
|
searchPreference.addResourceFileToIndex(R.xml.preferences_user_interface, getTitleOfPage(R.xml.preferences_user_interface));
|
||||||
|
searchPreference.addResourceFileToIndex(R.xml.preferences_playback, getTitleOfPage(R.xml.preferences_playback));
|
||||||
|
searchPreference.addResourceFileToIndex(R.xml.preferences_network, getTitleOfPage(R.xml.preferences_network));
|
||||||
|
searchPreference.addResourceFileToIndex(R.xml.preferences_storage, getTitleOfPage(R.xml.preferences_storage));
|
||||||
|
String integrations = activity.getString(getTitleOfPage(R.xml.preferences_integrations));
|
||||||
|
String flattr = activity.getString(getTitleOfPage(R.xml.preferences_flattr));
|
||||||
|
String gpodder = activity.getString(getTitleOfPage(R.xml.preferences_gpodder));
|
||||||
|
searchPreference.addResourceFileToIndex(R.xml.preferences_flattr, integrations + " > " + flattr);
|
||||||
|
searchPreference.addResourceFileToIndex(R.xml.preferences_gpodder, integrations + " > " + gpodder);
|
||||||
|
}
|
||||||
|
|
||||||
public PreferenceFragmentCompat openScreen(int preferences, AppCompatActivity activity) {
|
public PreferenceFragmentCompat openScreen(int preferences, AppCompatActivity activity) {
|
||||||
PreferenceFragmentCompat prefFragment = new PreferenceActivity.MainFragment();
|
PreferenceFragmentCompat prefFragment = new PreferenceActivity.MainFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
@ -566,7 +587,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
|
||||||
return prefFragment;
|
return prefFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTitleOfPage(int preferences) {
|
public static int getTitleOfPage(int preferences) {
|
||||||
switch (preferences) {
|
switch (preferences) {
|
||||||
case R.xml.preferences_network:
|
case R.xml.preferences_network:
|
||||||
return R.string.network_pref;
|
return R.string.network_pref;
|
||||||
|
@ -1152,6 +1173,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
|
||||||
public interface PreferenceUI {
|
public interface PreferenceUI {
|
||||||
|
|
||||||
void setFragment(PreferenceFragmentCompat fragment);
|
void setFragment(PreferenceFragmentCompat fragment);
|
||||||
|
PreferenceFragmentCompat getFragment();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds a preference based on its key.
|
* Finds a preference based on its key.
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<com.bytehamster.lib.preferencesearch.SearchPreference
|
||||||
|
android:key="searchPreference" />
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="prefScreenInterface"
|
android:key="prefScreenInterface"
|
||||||
android:title="@string/user_interface_label"
|
android:title="@string/user_interface_label"
|
||||||
android:icon="?attr/type_video" />
|
android:icon="?attr/type_video" />
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="prefScreenPlayback"
|
android:key="prefScreenPlayback"
|
||||||
|
|
|
@ -37,12 +37,12 @@ subprojects {
|
||||||
}
|
}
|
||||||
|
|
||||||
project.ext {
|
project.ext {
|
||||||
compileSdkVersion = 25
|
compileSdkVersion = 26
|
||||||
buildToolsVersion = "27.0.3"
|
buildToolsVersion = "27.0.3"
|
||||||
minSdkVersion = 14
|
minSdkVersion = 14
|
||||||
targetSdkVersion = 26
|
targetSdkVersion = 26
|
||||||
|
|
||||||
supportVersion = "25.3.1"
|
supportVersion = "26.1.0"
|
||||||
commonsioVersion = "2.5"
|
commonsioVersion = "2.5"
|
||||||
commonslangVersion = "3.6"
|
commonslangVersion = "3.6"
|
||||||
commonstextVersion = "1.3"
|
commonstextVersion = "1.3"
|
||||||
|
|
|
@ -12,7 +12,7 @@ dependencies:
|
||||||
- ~/.android
|
- ~/.android
|
||||||
- ~/android
|
- ~/android
|
||||||
pre:
|
pre:
|
||||||
- echo y | android update sdk --no-ui --all --filter "tool,extra-android-m2repository,extra-android-support,extra-google-google_play_services,extra-google-m2repository,android-25"
|
- echo y | android update sdk --no-ui --all --filter "tool,extra-android-m2repository,extra-android-support,extra-google-google_play_services,extra-google-m2repository,android-26"
|
||||||
- echo y | android update sdk --no-ui --all --filter "build-tools-27.0.3"
|
- echo y | android update sdk --no-ui --all --filter "build-tools-27.0.3"
|
||||||
override:
|
override:
|
||||||
- echo override dependencies
|
- echo override dependencies
|
||||||
|
|
Loading…
Reference in New Issue