Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
KnollFrank committed Dec 16, 2024
1 parent 4d791c2 commit 4c16962
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion OsmAnd/build-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ dependencies {
implementation "androidx.car.app:app-projected:1.4.0"

implementation 'com.google.android.gms:play-services-location:21.3.0'
implementation 'com.github.KnollFrank:SettingsSearch:b30144e8c4'
implementation 'com.github.KnollFrank:SettingsSearch:a2aa865f48'
// https://mvnrepository.com/artifact/com.google.guava/guava
implementation 'com.google.guava:guava:33.3.1-android'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Optional;
import java.util.stream.Collectors;

import de.KnollFrank.lib.settingssearch.common.Lists;
import de.KnollFrank.lib.settingssearch.common.Optionals;

public class CustomizableSingleSelectionBottomSheetSearchableInfoProvider {

Expand All @@ -24,15 +24,10 @@ private static String asString(final List<DisplayItem> displayItems) {
}

private static String asString(final DisplayItem displayItem) {
return String.join(
", ",
concat(
return Optionals
.streamOfPresentElements(
Optional.ofNullable(displayItem.getTitle()),
Optional.ofNullable(displayItem.getDescription())));
}

private static List<CharSequence> concat(final Optional<CharSequence> dialogTitle,
final Optional<CharSequence> description) {
return Lists.getPresentElements(List.of(dialogTitle, description));
Optional.ofNullable(displayItem.getDescription()))
.collect(Collectors.joining(", "));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import net.osmand.plus.settings.fragments.search.SearchableInfoProvider;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import de.KnollFrank.lib.settingssearch.common.Lists;
import de.KnollFrank.lib.settingssearch.common.Optionals;

public class EditTextPreferenceEx extends EditTextPreference implements SearchableInfoProvider {

Expand Down Expand Up @@ -46,11 +46,10 @@ public void setDescription(int descriptionResId) {

@Override
public String getSearchableInfo() {
return String.join(
", ",
Lists.getPresentElements(
List.of(
Optional.ofNullable(getText()),
Optional.ofNullable(getDescription()))));
return Optionals
.streamOfPresentElements(
Optional.ofNullable(getText()),
Optional.ofNullable(getDescription()))
.collect(Collectors.joining(", "));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
import androidx.preference.DialogPreference;
import androidx.preference.PreferenceDataStore;

import com.google.common.collect.ImmutableList;

import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmAndPreferencesDataStore;
import net.osmand.plus.settings.fragments.search.SearchableInfoProvider;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import de.KnollFrank.lib.settingssearch.common.Lists;
import de.KnollFrank.lib.settingssearch.common.Optionals;

public class ListPreferenceEx extends DialogPreference implements SearchableInfoProvider {

Expand Down Expand Up @@ -168,8 +171,12 @@ public String getSearchableInfo() {
static List<CharSequence> concat(final Optional<CharSequence> dialogTitle,
final Optional<CharSequence> description,
final Optional<CharSequence[]> entries) {
final List<CharSequence> result = Lists.getPresentElements(List.of(dialogTitle, description));
result.addAll(Lists.asList(entries));
return result;
return ImmutableList
.<CharSequence>builder()
.addAll(Optionals
.streamOfPresentElements(dialogTitle, description)
.collect(Collectors.toList()))
.addAll(Optionals.asList(entries))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.stream.Collectors;

import de.KnollFrank.lib.settingssearch.common.Lists;
import de.KnollFrank.lib.settingssearch.common.Optionals;

public class SizePreference extends DialogPreference implements SearchableInfoProvider {

Expand Down Expand Up @@ -89,11 +89,10 @@ public String getValue() {

@Override
public String getSearchableInfo() {
return String.join(
", ",
Lists.getPresentElements(
List.of(
Optional.ofNullable(getDialogTitle()),
Optional.ofNullable(getSummary()))));
return Optionals
.streamOfPresentElements(
Optional.ofNullable(getDialogTitle()),
Optional.ofNullable(getSummary()))
.collect(Collectors.joining(", "));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import net.osmand.plus.settings.fragments.search.SearchableInfoProvider;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import de.KnollFrank.lib.settingssearch.common.Lists;
import de.KnollFrank.lib.settingssearch.common.Optionals;

public class SwitchPreferenceEx extends SwitchPreferenceCompat implements SearchableInfoProvider {

Expand Down Expand Up @@ -53,12 +53,11 @@ protected void onClick() {

@Override
public String getSearchableInfo() {
return String.join(
", ",
Lists.getPresentElements(
List.of(
Optional.ofNullable(getSummaryOff()),
Optional.ofNullable(getSummaryOn()),
Optional.ofNullable(getDescription()))));
return Optionals
.streamOfPresentElements(
Optional.ofNullable(getSummaryOff()),
Optional.ofNullable(getSummaryOn()),
Optional.ofNullable(getDescription()))
.collect(Collectors.joining(", "));
}
}

0 comments on commit 4c16962

Please sign in to comment.