Skip to content

Commit

Permalink
making LocationInterpolationBottomSheet searchable
Browse files Browse the repository at this point in the history
  • Loading branch information
KnollFrank committed Dec 16, 2024
1 parent 90ce901 commit 373d9df
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ private void setupLoadAvgInfoPref() {
// in microamperes (µA) as specified in the API documentation.
if (Math.abs(m1.energyConsumption) > AUTO_DETECT_MICROAMPERES) m1.energyConsumption /= 1000;
if (Math.abs(m5.energyConsumption) > AUTO_DETECT_MICROAMPERES) m5.energyConsumption /= 1000;
if (Math.abs(m15.energyConsumption) > AUTO_DETECT_MICROAMPERES) m15.energyConsumption /= 1000;
if (Math.abs(m15.energyConsumption) > AUTO_DETECT_MICROAMPERES)
m15.energyConsumption /= 1000;

String fps = String.format("%.0f / %.0f / %.0f", m1.fps1k, m5.fps1k, m15.fps1k);
String gpu = String.format("%.2f / %.2f / %.2f", m1.gpu1k, m5.gpu1k, m15.gpu1k);
Expand Down Expand Up @@ -352,11 +353,6 @@ public boolean onPreferenceClick(Preference preference) {
preference.setSummary(getAgpsDataDownloadedSummary());
}
return true;
} else if (settings.LOCATION_INTERPOLATION_PERCENT.getId().equals(prefId)) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
LocationInterpolationBottomSheet.showInstance(fragmentManager, preference.getKey(), this, getSelectedAppMode());
}
} else if (RESET_TO_DEFAULT.equals(prefId)) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
Expand Down Expand Up @@ -392,15 +388,32 @@ public void show() {
target,
getSelectedAppMode())) {

// FK-TODO: refactor
@Override
public void show() {
final FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
searchablePreferenceDialog.show(fragmentManager, app);
}
}
});
}
if (settings.LOCATION_INTERPOLATION_PERCENT.getId().equals(preference.getKey())) {
return Optional.of(
new ShowableSearchablePreferenceDialog(
LocationInterpolationBottomSheet.createInstance(
preference,
target,
getSelectedAppMode())) {

@Override
public void show() {
final FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
searchablePreferenceDialog.show(fragmentManager, app);
}
}
}
);
});
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.preference.Preference;

import com.google.android.material.slider.Slider;

Expand All @@ -23,15 +23,17 @@
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.preferences.CommonPreference;
import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet;
import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheetInitializer;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialog;
import net.osmand.plus.utils.AndroidUtils;
import net.osmand.plus.utils.ColorUtilities;
import net.osmand.plus.utils.UiUtilities;

import java.util.ArrayList;
import java.util.List;

public class LocationInterpolationBottomSheet extends BasePreferenceBottomSheet {
public class LocationInterpolationBottomSheet extends BasePreferenceBottomSheet implements SearchablePreferenceDialog {

public static final String TAG = LocationInterpolationBottomSheet.class.getSimpleName();

Expand Down Expand Up @@ -73,11 +75,8 @@ private void initData() {
public void createMenuItems(Bundle savedInstanceState) {
LayoutInflater inflater = UiUtilities.getInflater(getContext(), nightMode);

String title = getString(R.string.location_interpolation_percent);
items.add(new TitleItem(title));

String description = getString(R.string.location_interpolation_percent_desc);
items.add(new LongDescriptionItem(description));
items.add(new TitleItem(getTitle()));
items.add(new LongDescriptionItem(getDescription()));

View view = inflater.inflate(R.layout.bottom_sheet_allocated_routing_memory, null);
items.add(new BaseBottomSheetItem.Builder().setCustomView(view).create());
Expand All @@ -89,6 +88,16 @@ public void createMenuItems(Bundle savedInstanceState) {
setupResetButton(buttonView);
}

@NonNull
private String getTitle() {
return getString(R.string.location_interpolation_percent);
}

@NonNull
private String getDescription() {
return getString(R.string.location_interpolation_percent_desc);
}

@SuppressLint("SetTextI18n")
private void setupSliderView(View container) {
TextView title = container.findViewById(R.id.title);
Expand Down Expand Up @@ -161,7 +170,7 @@ protected int getRightBottomButtonTextId() {

private List<Integer> getAvailableRange() {
List<Integer> powRange = new ArrayList<>();
for (int i = 0; i <= 100; i+=10) {
for (int i = 0; i <= 100; i += 10) {
powRange.add(i);
}
return powRange;
Expand All @@ -180,19 +189,23 @@ private boolean isChanged() {
return initialValue != currentValue;
}

public static void showInstance(@NonNull FragmentManager fragmentManager,
@NonNull String key,
@NonNull Fragment target,
@Nullable ApplicationMode appMode) {
public static LocationInterpolationBottomSheet createInstance(final Preference preference,
final Fragment target,
final ApplicationMode appMode) {
return BasePreferenceBottomSheetInitializer
.initialize(new LocationInterpolationBottomSheet())
.with(preference, appMode, false, target);
}

@Override
public void show(final FragmentManager fragmentManager, final OsmandApplication app) {
if (AndroidUtils.isFragmentCanBeAdded(fragmentManager, TAG)) {
Bundle args = new Bundle();
args.putString(PREFERENCE_ID, key);
LocationInterpolationBottomSheet fragment = new LocationInterpolationBottomSheet();
fragment.setArguments(args);
fragment.setUsedOnMap(false);
fragment.setAppMode(appMode);
fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, TAG);
show(fragmentManager, TAG);
}
}

@Override
public String getSearchableInfo() {
return String.join(", ", getTitle(), getDescription());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import net.osmand.plus.settings.backend.ApplicationMode;

class BasePreferenceBottomSheetInitializer<T extends BasePreferenceBottomSheet> {
public class BasePreferenceBottomSheetInitializer<T extends BasePreferenceBottomSheet> {

private final T basePreferenceBottomSheet;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.annotation.SuppressLint;
import android.text.Editable;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -33,6 +34,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class FuelTankCapacityBottomSheet extends BaseTextFieldBottomSheet implements SearchablePreferenceDialog {
private static final Log LOG = PlatformUtil.getLog(VehicleParametersBottomSheet.class);
Expand Down Expand Up @@ -156,9 +159,9 @@ public void show(final FragmentManager fragmentManager, final OsmandApplication

@Override
public String getSearchableInfo() {
return String.join(
", ",
title.getText(),
tvDescription.getText());
return Stream
.of(title, tvDescription)
.map(TextView::getText)
.collect(Collectors.joining(", "));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import java.text.DecimalFormatSymbols;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class VehicleParametersBottomSheet extends BaseTextFieldBottomSheet implements SearchablePreferenceDialog {
private static final Log LOG = PlatformUtil.getLog(VehicleParametersBottomSheet.class);
Expand Down Expand Up @@ -159,7 +161,10 @@ public void show(final FragmentManager fragmentManager, final OsmandApplication

@Override
public String getSearchableInfo() {
return String.join(", ", _getText(R.id.title), _getText(R.id.description));
return Stream
.of(R.id.title, R.id.description)
.map(this::_getText)
.collect(Collectors.joining(", "));
}

private CharSequence _getText(final @IdRes int id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,27 @@ public static Iterable<Object[]> data() {
return Arrays.asList(
new Object[][]{
{"RecalculateRoute", R.string.recalculate_route},
{"AnnouncementTimeBottomSheet_title", R.string.announcement_time_title},
{"AnnouncementTimeBottomSheet_description", R.string.announcement_time_descr},
{"FuelTankCapacityBottomSheet_description", R.string.fuel_tank_capacity_description},
{"RecalculateRouteInDeviationBottomSheet_title", R.string.recalculate_route_in_deviation},
{"RecalculateRouteInDeviationBottomSheet_description", R.string.select_distance_route_will_recalc},
{"RecalculateRouteInDeviationBottomSheet_longDescription", R.string.recalculate_route_distance_promo},
{"ScreenTimeoutBottomSheet_description", R.string.system_screen_timeout_descr},
{"GoodsRestrictionsBottomSheet_title", R.string.routing_attr_goods_restrictions_name},

{"AnnouncementTimeBottomSheet: title", R.string.announcement_time_title},
{"AnnouncementTimeBottomSheet: description", R.string.announcement_time_descr},

{"FuelTankCapacityBottomSheet: description", R.string.fuel_tank_capacity_description},

{"RecalculateRouteInDeviationBottomSheet: title", R.string.recalculate_route_in_deviation},
{"RecalculateRouteInDeviationBottomSheet: description", R.string.select_distance_route_will_recalc},
{"RecalculateRouteInDeviationBottomSheet: longDescription", R.string.recalculate_route_distance_promo},

{"ScreenTimeoutBottomSheet: description", R.string.system_screen_timeout_descr},

{"GoodsRestrictionsBottomSheet: title", R.string.routing_attr_goods_restrictions_name},
{"GoodsRestrictionsBottomSheet: goods_delivery_desc", R.string.goods_delivery_desc},
{"GoodsRestrictionsBottomSheet: goods_delivery_desc_2", R.string.goods_delivery_desc_2},
{"GoodsRestrictionsBottomSheet: goods_delivery_desc_3", R.string.goods_delivery_desc_3},
{"GoodsRestrictionsBottomSheet: goods_delivery_desc_4", R.string.goods_delivery_desc_4},

// FK-TODO: enable development plugin for these two test cases
// {"LocationInterpolationBottomSheet: title", R.string.location_interpolation_percent},
// {"LocationInterpolationBottomSheet: description", R.string.location_interpolation_percent_desc}
});
}

Expand Down

0 comments on commit 373d9df

Please sign in to comment.