use of net.osmand.plus.widgets.chips.ChipItem in project Osmand by osmandapp.
the class IconsCard method setupCategoriesSelector.
@SuppressLint("NotifyDataSetChanged")
private void setupCategoriesSelector() {
List<ChipItem> items = new ArrayList<>();
for (String category : iconsCategories.keySet()) {
ChipItem item = new ChipItem(category);
if (!category.equals(KEY_LAST_USED_ICONS)) {
item.title = category;
}
items.add(item);
}
HorizontalChipsView categorySelector = view.findViewById(R.id.icons_categories_selector);
categorySelector.setItems(items);
ChipItem selected = categorySelector.getChipById(selectedIconCategory);
categorySelector.setSelected(selected);
categorySelector.setOnSelectChipListener(chip -> {
selectedIconCategory = chip.id;
fillIconsSelector();
reselectIcon(selectedIconId, false);
categorySelector.notifyDataSetChanged();
categorySelector.smoothScrollTo(chip);
return true;
});
ChipItem lastUsedCategory = categorySelector.getChipById(KEY_LAST_USED_ICONS);
if (lastUsedCategory != null) {
lastUsedCategory.icon = getIcon(R.drawable.ic_action_history);
lastUsedCategory.iconColor = ColorUtilities.getActiveColor(app, nightMode);
}
categorySelector.notifyDataSetChanged();
categorySelector.scrollTo(selected);
}
use of net.osmand.plus.widgets.chips.ChipItem in project Osmand by osmandapp.
the class OnlineRoutingEngineFragment method setupVehicleTypes.
private void setupVehicleTypes() {
List<ChipItem> vehicleItems = new ArrayList<>();
for (VehicleType vehicle : engine.getAllowedVehicles()) {
String title = vehicle.getTitle(app);
ChipItem item = new ChipItem(title);
item.title = title;
item.tag = vehicle;
vehicleItems.add(item);
}
vehicleCard.setSelectionMenu(vehicleItems, engine.getSelectedVehicleType().getTitle(app), result -> {
VehicleType vehicle = (VehicleType) result.tag;
if (!Algorithms.objectEquals(engine.getSelectedVehicleType(), vehicle)) {
String vehicleKey = vehicle.equals(CUSTOM_VEHICLE) ? customVehicleKey : vehicle.getKey();
engine.put(EngineParameter.VEHICLE_KEY, vehicleKey);
generateUniqueNameIfNeeded();
updateCardViews(nameCard, vehicleCard, exampleCard);
return true;
}
return false;
});
}
use of net.osmand.plus.widgets.chips.ChipItem in project Osmand by osmandapp.
the class OnlineRoutingEngineFragment method setupTypeCard.
private void setupTypeCard() {
typeCard = new OnlineRoutingCard(mapActivity, isNightMode(), appMode);
typeCard.build(mapActivity);
typeCard.setHeaderTitle(getString(R.string.shared_string_type));
List<net.osmand.plus.widgets.chips.ChipItem> typeItems = new ArrayList<>();
for (OnlineRoutingEngine type : EngineType.values()) {
String title = type.getTitle();
ChipItem item = new ChipItem(title);
item.title = title;
item.tag = type;
typeItems.add(item);
}
typeCard.setSelectionMenu(typeItems, engine.getType().getTitle(), result -> {
OnlineRoutingEngine type = (OnlineRoutingEngine) result.tag;
if (engine.getType() != type) {
changeEngineType(type);
return true;
}
return false;
});
typeCard.setOnTextChangedListener(new OnTextChangedListener() {
@Override
public void onTextChanged(boolean editedByUser, @NonNull String text) {
if (editedByUser) {
engine.put(EngineParameter.CUSTOM_URL, text);
updateCardViews(exampleCard);
}
}
});
typeCard.setFieldBoxLabelText(getString(R.string.shared_string_server_url));
typeCard.showDivider();
segmentsContainer.addView(typeCard.getView());
}
use of net.osmand.plus.widgets.chips.ChipItem in project Osmand by osmandapp.
the class SelectFileBottomSheet method getFolderChips.
private List<ChipItem> getFolderChips() {
List<ChipItem> items = new ArrayList<>();
for (String name : getFolderNames()) {
ChipItem item = new ChipItem(name);
item.title = name;
items.add(item);
}
return items;
}
use of net.osmand.plus.widgets.chips.ChipItem in project Osmand by osmandapp.
the class SelectFileBottomSheet method createMenuItems.
@Override
public void createMenuItems(final Bundle savedInstanceState) {
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
Context context = requireContext();
final OsmandApplication app = requiredMyApplication();
mainView = View.inflate(new ContextThemeWrapper(context, themeRes), R.layout.bottom_sheet_plan_route_select_file, null);
TextView titleView = mainView.findViewById(R.id.title);
titleView.setText(fragmentMode.title);
final TextView descriptionView = mainView.findViewById(R.id.description);
descriptionView.setText(fragmentMode.description);
final RecyclerView filesRecyclerView = mainView.findViewById(R.id.gpx_track_list);
filesRecyclerView.setLayoutManager(new LinearLayoutManager(context));
if (fragmentMode == Mode.OPEN_TRACK) {
titleView.setText(AndroidUtils.addColon(app, fragmentMode.title));
updateDescription(descriptionView);
}
final ImageButton sortButton = mainView.findViewById(R.id.sort_button);
int backgroundColorId = ColorUtilities.getInactiveButtonsAndLinksColorId(nightMode);
Drawable background = app.getUIUtilities().getIcon(R.drawable.bg_dash_line_dark, backgroundColorId);
AndroidUtils.setBackground(sortButton, background);
sortButton.setImageResource(sortByMode.getIconId());
sortButton.setVisibility(View.VISIBLE);
sortButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final List<PopUpMenuItem> items = new ArrayList<>();
for (final TracksSortByMode mode : TracksSortByMode.values()) {
items.add(new PopUpMenuItem.Builder(app).setTitleId(mode.getNameId()).setIcon(app.getUIUtilities().getThemedIcon(mode.getIconId())).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sortByMode = mode;
sortButton.setImageResource(mode.getIconId());
updateDescription(descriptionView);
sortFolderList();
folderSelector.setItems(getFolderChips());
folderSelector.notifyDataSetChanged();
sortFileList();
adapter.notifyDataSetChanged();
}
}).setSelected(sortByMode == mode).create());
}
new PopUpMenuHelper.Builder(v, items, nightMode).show();
}
});
final File gpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
allFilesFolder = context.getString(R.string.shared_string_all);
if (savedInstanceState == null) {
selectedFolder = allFilesFolder;
}
final List<GPXInfo> allGpxList = getSortedGPXFilesInfo(gpxDir, null, false);
currentlyRecording = new GPXInfo(getString(R.string.shared_string_currently_recording_track), 0, 0);
if (isShowCurrentGpx()) {
allGpxList.add(0, currentlyRecording);
}
gpxInfoMap = new HashMap<>();
gpxInfoMap.put(allFilesFolder, allGpxList);
for (GPXInfo gpxInfo : allGpxList) {
String folderName = getFolderName(gpxInfo);
List<GPXInfo> gpxList = gpxInfoMap.get(folderName);
if (gpxList == null) {
gpxList = new ArrayList<>();
gpxInfoMap.put(folderName, gpxList);
}
gpxList.add(gpxInfo);
}
adapter = new GpxTrackAdapter(requireContext(), allGpxList, isShowCurrentGpx(), showFoldersName());
adapter.setAdapterListener(new OnItemClickListener() {
@Override
public void onItemClick(int position) {
List<GPXInfo> gpxList = adapter.getGpxInfoList();
if (position != RecyclerView.NO_POSITION && position < gpxList.size()) {
String fileName;
if (isShowCurrentGpx() && position == 0) {
fileName = null;
} else {
fileName = gpxList.get(position).getFileName();
}
if (listener != null) {
listener.selectFileOnCLick(fileName);
}
}
dismiss();
}
});
filesRecyclerView.setAdapter(adapter);
folderSelector = mainView.findViewById(R.id.folder_list);
folders = new ArrayList<>();
collectDirs(gpxDir, folders);
sortFolderList();
folderSelector.setItems(getFolderChips());
ChipItem selected = folderSelector.getChipById(selectedFolder);
folderSelector.setSelected(selected);
folderSelector.setOnSelectChipListener(chip -> {
selectedFolder = chip.id;
folderSelector.smoothScrollTo(chip);
updateFileList();
return true;
});
items.add(new BaseBottomSheetItem.Builder().setCustomView(mainView).create());
updateFileList();
}
Aggregations