Search in sources :

Example 1 with SwitchProfileAction

use of net.osmand.plus.quickaction.actions.SwitchProfileAction in project Osmand by osmandapp.

the class SelectMapViewQuickActionsBottomSheet method populateItemsList.

private void populateItemsList() {
    Context context = getContext();
    if (context == null) {
        return;
    }
    int counter = 0;
    if (action instanceof MapStyleAction) {
        MapStyleAction mapStyleAction = (MapStyleAction) action;
        List<String> stylesList = mapStyleAction.getFilteredStyles();
        for (String entry : stylesList) {
            boolean selected = entry.equals(selectedItem);
            createItemRow(selected, counter, getContentIcon(action.getIconRes()), mapStyleAction.getTranslatedItemName(context, entry), entry);
            counter++;
        }
    } else if (action instanceof SwitchProfileAction) {
        SwitchProfileAction switchProfileAction = (SwitchProfileAction) action;
        List<String> profilesKeys = (List<String>) switchProfileAction.loadListFromParams();
        for (String key : profilesKeys) {
            ApplicationMode appMode = ApplicationMode.valueOfStringKey(key, null);
            if (appMode != null) {
                boolean selected = key.equals(selectedItem);
                int iconId = appMode.getIconRes();
                int color = appMode.getProfileColor(nightMode);
                Drawable icon = getPaintedIcon(iconId, color);
                String translatedName = appMode.toHumanString();
                createItemRow(selected, counter, icon, translatedName, key);
                counter++;
            }
        }
    } else if (action instanceof SwitchableAction) {
        SwitchableAction switchableAction = (SwitchableAction) action;
        List<Pair<String, String>> sources = (List<Pair<String, String>>) switchableAction.loadListFromParams();
        for (Pair<String, String> entry : sources) {
            String tag = entry.first;
            boolean selected = tag.equals(selectedItem);
            createItemRow(selected, counter, getContentIcon(action.getIconRes()), entry.second, tag);
            counter++;
        }
    }
}
Also used : Context(android.content.Context) Drawable(android.graphics.drawable.Drawable) MapStyleAction(net.osmand.plus.quickaction.actions.MapStyleAction) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) SwitchableAction(net.osmand.plus.quickaction.SwitchableAction) SwitchProfileAction(net.osmand.plus.quickaction.actions.SwitchProfileAction) ColorStateList(android.content.res.ColorStateList) List(java.util.List) Pair(androidx.core.util.Pair)

Aggregations

Context (android.content.Context)1 ColorStateList (android.content.res.ColorStateList)1 Drawable (android.graphics.drawable.Drawable)1 Pair (androidx.core.util.Pair)1 List (java.util.List)1 SwitchableAction (net.osmand.plus.quickaction.SwitchableAction)1 MapStyleAction (net.osmand.plus.quickaction.actions.MapStyleAction)1 SwitchProfileAction (net.osmand.plus.quickaction.actions.SwitchProfileAction)1 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)1