Search in sources :

Example 1 with ProfileDataObject

use of net.osmand.plus.profiles.data.ProfileDataObject in project Osmand by osmandapp.

the class MapActivityActions method createSwitchProfileOptionsMenu.

private ContextMenuAdapter createSwitchProfileOptionsMenu(final OsmandApplication app, ContextMenuAdapter optionsMenuHelper, boolean nightMode) {
    drawerMode = DRAWER_MODE_NORMAL;
    createProfilesController(app, optionsMenuHelper, nightMode, true);
    List<ApplicationMode> activeModes = ApplicationMode.values(app);
    ApplicationMode currentMode = app.getSettings().APPLICATION_MODE.get();
    String modeDescription;
    Map<String, ProfileDataObject> profilesObjects = routingDataUtils.getRoutingProfiles();
    for (final ApplicationMode appMode : activeModes) {
        if (appMode.isCustomProfile()) {
            modeDescription = getProfileDescription(app, appMode, profilesObjects, getString(R.string.profile_type_user_string));
        } else {
            modeDescription = getProfileDescription(app, appMode, profilesObjects, getString(R.string.profile_type_osmand_string));
        }
        int tag = currentMode.equals(appMode) ? PROFILES_CHOSEN_PROFILE_TAG : PROFILES_NORMAL_PROFILE_TAG;
        optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.profile_list_item).setIcon(appMode.getIconRes()).setColor(appMode.getProfileColor(nightMode)).setTag(tag).setTitle(appMode.toHumanString()).setDescription(modeDescription).setListener(new ItemClickListener() {

            @Override
            public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
                app.getSettings().setApplicationMode(appMode);
                updateDrawerMenu();
                return false;
            }
        }).createItem());
    }
    optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.profile_list_item).setColor(ColorUtilities.getActiveColor(app, nightMode)).setTag(PROFILES_CONTROL_BUTTON_TAG).setTitle(getString(R.string.shared_string_manage)).setListener(new ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
            BaseSettingsFragment.showInstance(mapActivity, BaseSettingsFragment.SettingsScreenType.MAIN_SETTINGS);
            return true;
        }
    }).createItem());
    return optionsMenuHelper;
}
Also used : ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuItemClickListener(net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) FavouritePoint(net.osmand.data.FavouritePoint) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) ProfileDataObject(net.osmand.plus.profiles.data.ProfileDataObject)

Example 2 with ProfileDataObject

use of net.osmand.plus.profiles.data.ProfileDataObject in project Osmand by osmandapp.

the class SelectNavProfileBottomSheet method addNonePredefinedView.

private void addNonePredefinedView() {
    int padding = getDimen(R.dimen.content_padding_half);
    addGroupHeader(getString(R.string.shared_string_predefined));
    addMessageWithRoundedBackground(getString(R.string.failed_loading_predefined_engines), 0, padding);
    if (OnlineRoutingEngine.isPredefinedEngineKey(selectedItemKey)) {
        ProfileDataObject selectedProfile = getDataUtils().getOnlineEngineByKey(selectedItemKey);
        addProfileItem(selectedProfile);
    }
    addDivider();
}
Also used : ProfileDataObject(net.osmand.plus.profiles.data.ProfileDataObject)

Example 3 with ProfileDataObject

use of net.osmand.plus.profiles.data.ProfileDataObject in project Osmand by osmandapp.

the class SelectMultipleProfilesBottomSheet method refreshProfiles.

private void refreshProfiles(OsmandApplication app) {
    profiles.clear();
    List<ApplicationMode> appModes = ApplicationMode.allPossibleValues();
    profiles.addAll(ProfileDataUtils.getDataObjects(app, appModes));
    for (ProfileDataObject profile : profiles) {
        String key = profile.getStringKey();
        profile.setSelected(selectedProfiles.contains(key));
        profile.setEnabled(!disabledProfiles.contains(key));
    }
}
Also used : ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) ProfileDataObject(net.osmand.plus.profiles.data.ProfileDataObject)

Example 4 with ProfileDataObject

use of net.osmand.plus.profiles.data.ProfileDataObject in project Osmand by osmandapp.

the class EditProfilesFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    OsmandApplication app = requireMyApplication();
    if (savedInstanceState != null && savedInstanceState.containsKey(APP_MODES_ORDER_KEY) && savedInstanceState.containsKey(DELETED_APP_MODES_KEY)) {
        appModesOrders = (HashMap<String, Integer>) savedInstanceState.getSerializable(APP_MODES_ORDER_KEY);
        deletedModesKeys = savedInstanceState.getStringArrayList(DELETED_APP_MODES_KEY);
    } else {
        for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
            appModesOrders.put(mode.getStringKey(), mode.getOrder());
        }
    }
    nightMode = !app.getSettings().isLightContent();
    View mainView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.edit_arrangement_list_fragment, container, false);
    AppBarLayout appbar = mainView.findViewById(R.id.appbar);
    View toolbar = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.global_preference_toolbar, container, false);
    appbar.addView(toolbar);
    ImageButton closeButton = mainView.findViewById(R.id.close_button);
    closeButton.setImageResource(R.drawable.ic_action_remove_dark);
    closeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentActivity fragmentActivity = getActivity();
            if (fragmentActivity != null) {
                fragmentActivity.onBackPressed();
            }
        }
    });
    TextView toolbarTitle = mainView.findViewById(R.id.toolbar_title);
    toolbarTitle.setText(R.string.edit_profiles);
    RecyclerView recyclerView = mainView.findViewById(R.id.profiles_list);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    adapter = new EditProfilesAdapter(app);
    updateItems();
    final ItemTouchHelper touchHelper = new ItemTouchHelper(new ReorderItemTouchHelperCallback(adapter));
    touchHelper.attachToRecyclerView(recyclerView);
    adapter.setAdapterListener(new ProfilesAdapterListener() {

        private int fromPosition;

        private int toPosition;

        @Override
        public void onDragStarted(RecyclerView.ViewHolder holder) {
            fromPosition = holder.getAdapterPosition();
            touchHelper.startDrag(holder);
        }

        @Override
        public void onDragOrSwipeEnded(RecyclerView.ViewHolder holder) {
            toPosition = holder.getAdapterPosition();
            if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
                adapter.notifyDataSetChanged();
            }
        }

        @Override
        public void onButtonClicked(int pos) {
            Object item = adapter.getItem(pos);
            if (item instanceof EditProfileDataObject) {
                EditProfileDataObject profileDataObject = (EditProfileDataObject) item;
                profileDataObject.toggleDeleted();
                if (profileDataObject.deleted) {
                    deletedModesKeys.add(profileDataObject.getStringKey());
                } else {
                    deletedModesKeys.remove(profileDataObject.getStringKey());
                }
                updateItems();
            }
        }
    });
    recyclerView.setAdapter(adapter);
    View cancelButton = mainView.findViewById(R.id.dismiss_button);
    UiUtilities.setupDialogButton(nightMode, cancelButton, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentActivity fragmentActivity = getActivity();
            if (fragmentActivity != null) {
                fragmentActivity.onBackPressed();
            }
        }
    });
    mainView.findViewById(R.id.buttons_divider).setVisibility(View.VISIBLE);
    View applyButton = mainView.findViewById(R.id.right_bottom_button);
    UiUtilities.setupDialogButton(nightMode, applyButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_apply);
    applyButton.setVisibility(View.VISIBLE);
    applyButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MapActivity mapActivity = (MapActivity) getActivity();
            if (mapActivity != null) {
                OsmandApplication app = mapActivity.getMyApplication();
                if (!deletedModesKeys.isEmpty()) {
                    List<ApplicationMode> deletedModes = new ArrayList<>();
                    for (String modeKey : deletedModesKeys) {
                        ApplicationMode mode = ApplicationMode.valueOfStringKey(modeKey, null);
                        if (mode != null) {
                            deletedModes.add(mode);
                        }
                    }
                    ApplicationMode.deleteCustomModes(deletedModes, app);
                }
                for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
                    String modeKey = mode.getStringKey();
                    Integer order = appModesOrders.get(modeKey);
                    if (order == null) {
                        order = mode.getOrder();
                    }
                    mode.setOrder(order);
                }
                ApplicationMode.reorderAppModes();
                mapActivity.onBackPressed();
            }
        }
    });
    if (Build.VERSION.SDK_INT >= 21) {
        AndroidUtils.addStatusBarPadding21v(app, mainView);
    }
    return mainView;
}
Also used : ReorderItemTouchHelperCallback(net.osmand.plus.views.controls.ReorderItemTouchHelperCallback) OsmandApplication(net.osmand.plus.OsmandApplication) SpannableString(android.text.SpannableString) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) FragmentActivity(androidx.fragment.app.FragmentActivity) ImageButton(android.widget.ImageButton) TextView(android.widget.TextView) RecyclerView(androidx.recyclerview.widget.RecyclerView) ProfileDataObject(net.osmand.plus.profiles.data.ProfileDataObject) ArrayList(java.util.ArrayList) List(java.util.List) AppBarLayout(com.google.android.material.appbar.AppBarLayout) MapActivity(net.osmand.plus.activities.MapActivity) Nullable(androidx.annotation.Nullable)

Example 5 with ProfileDataObject

use of net.osmand.plus.profiles.data.ProfileDataObject in project Osmand by osmandapp.

the class SelectNavProfileBottomSheet method createProfilesList.

private void createProfilesList() {
    for (ProfilesGroup group : profileGroups) {
        List<ProfileDataObject> items = group.getProfiles();
        if (!Algorithms.isEmpty(items)) {
            addGroupHeader(group.getTitle(), group.getDescription(app, nightMode));
            for (ProfileDataObject item : items) {
                addProfileItem(item);
            }
            addDivider();
        }
    }
}
Also used : ProfileDataObject(net.osmand.plus.profiles.data.ProfileDataObject) ProfilesGroup(net.osmand.plus.profiles.data.ProfilesGroup) PredefinedProfilesGroup(net.osmand.plus.profiles.data.PredefinedProfilesGroup)

Aggregations

ProfileDataObject (net.osmand.plus.profiles.data.ProfileDataObject)9 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)5 FavouritePoint (net.osmand.data.FavouritePoint)2 ItemClickListener (net.osmand.plus.ContextMenuAdapter.ItemClickListener)2 ContextMenuItem (net.osmand.plus.ContextMenuItem)2 ItemBuilder (net.osmand.plus.ContextMenuItem.ItemBuilder)2 ContextMenuItemClickListener (net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener)2 SuppressLint (android.annotation.SuppressLint)1 SpannableString (android.text.SpannableString)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Nullable (androidx.annotation.Nullable)1 FragmentActivity (androidx.fragment.app.FragmentActivity)1 ItemTouchHelper (androidx.recyclerview.widget.ItemTouchHelper)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 AppBarLayout (com.google.android.material.appbar.AppBarLayout)1 ArrayList (java.util.ArrayList)1