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>
<android.support.v7.widget.AppCompatImageView
android:id="@+id/ic_open_list"
android:id="@+id/ic_expand_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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.measurementtool.MeasurementToolFragment;
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.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.routepreparationmenu.WaypointsFragment;
@ -116,6 +114,11 @@ public class MapActivityActions implements DialogProvider {
public static final String KEY_ZOOM = "zoom";
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
public static final int DIRECTIONS_FROM_ITEM_ORDER = 1000;
@ -131,6 +134,9 @@ public class MapActivityActions implements DialogProvider {
private static final int DIALOG_RELOAD_TITLE = 103;
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
private static Bundle dialogBundle = new Bundle();
@ -142,6 +148,8 @@ public class MapActivityActions implements DialogProvider {
@NonNull
private ImageView drawerLogoHeader;
private View drawerOsmAndFooter;
private int drawerMode = DRAWER_MODE_NORMAL;
public MapActivityActions(MapActivity mapActivity) {
this.mapActivity = mapActivity;
@ -630,50 +638,77 @@ public class MapActivityActions implements DialogProvider {
}
}
public ContextMenuAdapter createMainOptionsMenu() {
final OsmandMapTileView mapView = mapActivity.getMapView();
final OsmandApplication app = mapActivity.getMyApplication();
ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter();
boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
//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);
if (drawerMode == DRAWER_MODE_SWITCH_PROFILE) {
return createSwitchProfileOptionsMenu(app, optionsMenuHelper, nightMode);
}
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.main_menu_drawer_btn_switch_profile)
.setIcon(currentMode.getIconRes())
.setColor(currentMode.getIconColorInfo().getColor(nightMode))
.setTitle(currentMode.toHumanString(app))
.setDescription(modeDescription)
return createNormalOptionsMenu(app, optionsMenuHelper, nightMode);
}
private ContextMenuAdapter createSwitchProfileOptionsMenu(final OsmandApplication app, ContextMenuAdapter optionsMenuHelper, boolean nightMode) {
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() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
final AppModesBottomSheetDialogFragment fragment = new SelectAppModesBottomSheetDialogFragment();
fragment.setUsedOnMap(true);
mapActivity.getSupportFragmentManager().beginTransaction()
.add(fragment, SelectAppModesBottomSheetDialogFragment.TAG).commitAllowingStateLoss();
Intent intent = new Intent(app, SettingsProfileActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
app.startActivity(intent);
return true;
}
})
.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());
return optionsMenuHelper;
}
private ContextMenuAdapter createNormalOptionsMenu(final OsmandApplication app, ContextMenuAdapter optionsMenuHelper, boolean nightMode) {
createProfilesController(app, optionsMenuHelper, nightMode, false);
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.home, mapActivity)
.setId(DRAWER_DASHBOARD_ID)
@ -729,7 +764,7 @@ public class MapActivityActions implements DialogProvider {
}
}).createItem());
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.get_directions, mapActivity)
.setId(DRAWER_DIRECTIONS_ID)
.setIcon(R.drawable.ic_action_gdirections_dark)
@ -944,6 +979,46 @@ public class MapActivityActions implements DialogProvider {
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() {
mapActivity.hideContextAndRouteInfoMenues();
WaypointsFragment.showInstance(mapActivity.getSupportFragmentManager());