forked from osmandapp/OsmAnd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
300bb53
commit 0e8ab87
Showing
7 changed files
with
105 additions
and
95 deletions.
There are no files selected for viewing
91 changes: 3 additions & 88 deletions
91
OsmAnd/src/net/osmand/plus/settings/fragments/search/SearchableInfoProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,7 @@ | ||
package net.osmand.plus.settings.fragments.search; | ||
|
||
import androidx.preference.Preference; | ||
@FunctionalInterface | ||
public interface SearchableInfoProvider { | ||
|
||
import net.osmand.plus.settings.preferences.EditTextPreferenceEx; | ||
import net.osmand.plus.settings.preferences.ListPreferenceEx; | ||
import net.osmand.plus.settings.preferences.MultiSelectBooleanPreference; | ||
import net.osmand.plus.settings.preferences.SizePreference; | ||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import de.KnollFrank.lib.settingssearch.common.Lists; | ||
|
||
class SearchableInfoProvider implements de.KnollFrank.lib.settingssearch.search.provider.SearchableInfoProvider { | ||
|
||
@Override | ||
public Optional<String> getSearchableInfo(final Preference preference) { | ||
if (preference instanceof final ListPreferenceEx listPreferenceEx) { | ||
return Optional.of(getSearchableInfo(listPreferenceEx)); | ||
} | ||
if (preference instanceof final SwitchPreferenceEx switchPreferenceEx) { | ||
return Optional.of(getSearchableInfo(switchPreferenceEx)); | ||
} | ||
if (preference instanceof final MultiSelectBooleanPreference multiSelectBooleanPreference) { | ||
return Optional.of(getSearchableInfo(multiSelectBooleanPreference)); | ||
} | ||
if (preference instanceof final EditTextPreferenceEx editTextPreferenceEx) { | ||
return Optional.of(getSearchableInfo(editTextPreferenceEx)); | ||
} | ||
if (preference instanceof final SizePreference sizePreference) { | ||
return Optional.of(getSizePreferenceSearchableInfo(sizePreference)); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
private static String getSearchableInfo(final ListPreferenceEx preference) { | ||
return String.join( | ||
", ", | ||
concat( | ||
Optional.ofNullable(preference.getDialogTitle()), | ||
Optional.ofNullable(preference.getDescription()), | ||
Optional.ofNullable(preference.getEntries()))); | ||
} | ||
|
||
private static String getSearchableInfo(final SwitchPreferenceEx preference) { | ||
return String.join( | ||
", ", | ||
Lists.getPresentElements( | ||
Arrays.asList( | ||
Optional.ofNullable(preference.getSummaryOff()), | ||
Optional.ofNullable(preference.getSummaryOn()), | ||
Optional.ofNullable(preference.getDescription())))); | ||
} | ||
|
||
private static String getSearchableInfo(final MultiSelectBooleanPreference preference) { | ||
return String.join( | ||
", ", | ||
concat( | ||
Optional.ofNullable(preference.getDialogTitle()), | ||
Optional.ofNullable(preference.getDescription()), | ||
Optional.ofNullable(preference.getEntries()))); | ||
} | ||
|
||
private static String getSearchableInfo(final EditTextPreferenceEx preference) { | ||
return String.join( | ||
", ", | ||
Lists.getPresentElements( | ||
Arrays.asList( | ||
Optional.ofNullable(preference.getText()), | ||
Optional.ofNullable(preference.getDescription())))); | ||
} | ||
|
||
private static String getSizePreferenceSearchableInfo(final SizePreference preference) { | ||
return String.join( | ||
", ", | ||
Lists.getPresentElements( | ||
Arrays.asList( | ||
Optional.ofNullable(preference.getDialogTitle()), | ||
Optional.ofNullable(preference.getSummary())))); | ||
} | ||
|
||
private static List<CharSequence> concat(final Optional<CharSequence> dialogTitle, | ||
final Optional<CharSequence> description, | ||
final Optional<CharSequence[]> entries) { | ||
final List<CharSequence> result = Lists.getPresentElements(Arrays.asList(dialogTitle, description)); | ||
result.addAll(Lists.asList(entries)); | ||
return result; | ||
} | ||
String getSearchableInfo(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters