Drawer - App profile select

Replace BottomSheet on drawer inside list
This commit is contained in:
Nazar 2019-09-24 11:43:06 +03:00
parent d39348934f
commit 346578ef3e
2 changed files with 109 additions and 34 deletions

View file

@ -69,7 +69,7 @@
</LinearLayout> </LinearLayout>
<android.support.v7.widget.AppCompatImageView <android.support.v7.widget.AppCompatImageView
android:id="@+id/ic_open_list" android:id="@+id/ic_expand_list"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"

View file

@ -58,8 +58,6 @@ import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.MarkersPlanRouteContext; import net.osmand.plus.mapmarkers.MarkersPlanRouteContext;
import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment;
import net.osmand.plus.profiles.SelectAppModesBottomSheetDialogFragment;
import net.osmand.plus.profiles.SettingsProfileActivity; import net.osmand.plus.profiles.SettingsProfileActivity;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu; import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.routepreparationmenu.WaypointsFragment; import net.osmand.plus.routepreparationmenu.WaypointsFragment;
@ -117,6 +115,11 @@ public class MapActivityActions implements DialogProvider {
public static final int REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION = 203; public static final int REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION = 203;
// Constants to determine profiles list item type (drawer menu items in 'Switch profile' mode)
public static final int PROFILES_NORMAL_PROFILE_TAG = 0;
public static final int PROFILES_CHOSEN_PROFILE_TAG = 1;
public static final int PROFILES_CONTROL_BUTTON_TAG = 2;
// Constants for determining the order of items in the additional actions context menu // Constants for determining the order of items in the additional actions context menu
public static final int DIRECTIONS_FROM_ITEM_ORDER = 1000; public static final int DIRECTIONS_FROM_ITEM_ORDER = 1000;
public static final int SEARCH_NEAR_ITEM_ORDER = 2000; public static final int SEARCH_NEAR_ITEM_ORDER = 2000;
@ -132,6 +135,9 @@ public class MapActivityActions implements DialogProvider {
private static final int DIALOG_SAVE_DIRECTIONS = 106; private static final int DIALOG_SAVE_DIRECTIONS = 106;
private static final int DRAWER_MODE_NORMAL = 100_000;
private static final int DRAWER_MODE_SWITCH_PROFILE = 200_000;
// make static // make static
private static Bundle dialogBundle = new Bundle(); private static Bundle dialogBundle = new Bundle();
@ -143,6 +149,8 @@ public class MapActivityActions implements DialogProvider {
private ImageView drawerLogoHeader; private ImageView drawerLogoHeader;
private View drawerOsmAndFooter; private View drawerOsmAndFooter;
private int drawerMode = DRAWER_MODE_NORMAL;
public MapActivityActions(MapActivity mapActivity) { public MapActivityActions(MapActivity mapActivity) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
settings = mapActivity.getMyApplication().getSettings(); settings = mapActivity.getMyApplication().getSettings();
@ -630,50 +638,77 @@ public class MapActivityActions implements DialogProvider {
} }
} }
public ContextMenuAdapter createMainOptionsMenu() { public ContextMenuAdapter createMainOptionsMenu() {
final OsmandMapTileView mapView = mapActivity.getMapView(); final OsmandMapTileView mapView = mapActivity.getMapView();
final OsmandApplication app = mapActivity.getMyApplication(); final OsmandApplication app = mapActivity.getMyApplication();
ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(); ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter();
boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
//switch profile button if (drawerMode == DRAWER_MODE_SWITCH_PROFILE) {
ApplicationMode currentMode = app.getSettings().APPLICATION_MODE.get(); return createSwitchProfileOptionsMenu(app, optionsMenuHelper, nightMode);
String modeDescription;
if (currentMode.isCustomProfile()) {
modeDescription = String.format(app.getString(R.string.profile_type_descr_string),
Algorithms.capitalizeFirstLetterAndLowercase(currentMode.getParent().toHumanString(app)));
} else {
modeDescription = getString(R.string.profile_type_base_string);
} }
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.main_menu_drawer_btn_switch_profile) return createNormalOptionsMenu(app, optionsMenuHelper, nightMode);
.setIcon(currentMode.getIconRes()) }
.setColor(currentMode.getIconColorInfo().getColor(nightMode))
.setTitle(currentMode.toHumanString(app)) private ContextMenuAdapter createSwitchProfileOptionsMenu(final OsmandApplication app, ContextMenuAdapter optionsMenuHelper, boolean nightMode) {
.setDescription(modeDescription)
createProfilesController(app, optionsMenuHelper, nightMode, true);
List<ApplicationMode> activeModes = ApplicationMode.values(app);
ApplicationMode currentMode = app.getSettings().APPLICATION_MODE.get();
String modeDescription;
for (final ApplicationMode appMode : activeModes) {
if (appMode.isCustomProfile()) {
modeDescription = String.format(app.getString(R.string.profile_type_descr_string),
Algorithms.capitalizeFirstLetterAndLowercase(appMode.getParent().toHumanString(app)));
} else {
modeDescription = getString(R.string.profile_type_base_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.getIconColorInfo().getColor(nightMode))
.setTag(tag)
.setTitle(appMode.toHumanString(app))
.setDescription(modeDescription)
.setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
app.getSettings().APPLICATION_MODE.set(appMode);
drawerMode = DRAWER_MODE_NORMAL;
updateDrawerMenu();
return false;
}
})
.createItem());
}
int activeColorPrimaryResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.profile_list_item)
.setColor(activeColorPrimaryResId)
.setTag(PROFILES_CONTROL_BUTTON_TAG)
.setTitle(getString(R.string.shared_string_manage))
.setListener(new ItemClickListener() { .setListener(new ItemClickListener() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) { public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
final AppModesBottomSheetDialogFragment fragment = new SelectAppModesBottomSheetDialogFragment(); Intent intent = new Intent(app, SettingsProfileActivity.class);
fragment.setUsedOnMap(true); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mapActivity.getSupportFragmentManager().beginTransaction() app.startActivity(intent);
.add(fragment, SelectAppModesBottomSheetDialogFragment.TAG).commitAllowingStateLoss();
return true; return true;
} }
}) })
.createItem()); .createItem());
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.main_menu_drawer_btn_configure_profile) return optionsMenuHelper;
.setColor(currentMode.getIconColorInfo().getColor(nightMode)) }
.setTitle(getString(R.string.configure_profile))
.setListener(new ItemClickListener() { private ContextMenuAdapter createNormalOptionsMenu(final OsmandApplication app, ContextMenuAdapter optionsMenuHelper, boolean nightMode) {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) { createProfilesController(app, optionsMenuHelper, nightMode, false);
ConfigureProfileFragment.showInstance(mapActivity.getSupportFragmentManager());
return true;
}
})
.createItem());
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.home, mapActivity) optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.home, mapActivity)
.setId(DRAWER_DASHBOARD_ID) .setId(DRAWER_DASHBOARD_ID)
@ -944,6 +979,46 @@ public class MapActivityActions implements DialogProvider {
return optionsMenuHelper; return optionsMenuHelper;
} }
private void createProfilesController(final OsmandApplication app, ContextMenuAdapter optionsMenuHelper, boolean nightMode, boolean listExpanded) {
//switch profile button
ApplicationMode currentMode = app.getSettings().APPLICATION_MODE.get();
String modeDescription;
if (currentMode.isCustomProfile()) {
modeDescription = String.format(app.getString(R.string.profile_type_descr_string),
Algorithms.capitalizeFirstLetterAndLowercase(currentMode.getParent().toHumanString(app)));
} else {
modeDescription = getString(R.string.profile_type_base_string);
}
int icArrowResId = listExpanded ? R.drawable.ic_action_arrow_drop_up : R.drawable.ic_action_arrow_drop_down;
final int nextMode = listExpanded ? DRAWER_MODE_NORMAL : DRAWER_MODE_SWITCH_PROFILE;
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.main_menu_drawer_btn_switch_profile)
.setIcon(currentMode.getIconRes())
.setSecondaryIcon(icArrowResId)
.setColor(currentMode.getIconColorInfo().getColor(nightMode))
.setTitle(currentMode.toHumanString(app))
.setDescription(modeDescription)
.setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
drawerMode = nextMode;
updateDrawerMenu();
return false;
}
})
.createItem());
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.main_menu_drawer_btn_configure_profile)
.setColor(currentMode.getIconColorInfo().getColor(nightMode))
.setTitle(getString(R.string.configure_profile))
.setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
ConfigureProfileFragment.showInstance(mapActivity.getSupportFragmentManager());
return true;
}
})
.createItem());
}
public void openIntermediatePointsDialog() { public void openIntermediatePointsDialog() {
mapActivity.hideContextAndRouteInfoMenues(); mapActivity.hideContextAndRouteInfoMenues();
WaypointsFragment.showInstance(mapActivity.getSupportFragmentManager()); WaypointsFragment.showInstance(mapActivity.getSupportFragmentManager());