add select app profile bottom sheet - work in progress
This commit is contained in:
parent
b7889bf6dd
commit
1125a074c2
6 changed files with 100 additions and 24 deletions
|
@ -9,7 +9,7 @@
|
|||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/profile_icon"
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/standard_icon_size"
|
||||
android:layout_marginLeft="@dimen/setting_profile_image_margin"
|
||||
|
@ -39,7 +39,7 @@
|
|||
android:layout_weight="5">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/profile_title"
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/main_font_dark"
|
||||
|
@ -47,7 +47,7 @@
|
|||
tools:text="Bicycle"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/profile_descr"
|
||||
android:id="@+id/description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
|
@ -75,7 +75,7 @@
|
|||
android:paddingEnd="10dp"/>
|
||||
|
||||
<android.support.v7.widget.SwitchCompat
|
||||
android:id="@+id/profile_switch"
|
||||
android:id="@+id/compound_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
|
|
|
@ -3,7 +3,7 @@ package net.osmand.plus.profiles;
|
|||
import static net.osmand.plus.activities.SettingsNavigationActivity.INTENT_SKIP_DIALOG;
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY;
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_APP_PROFILE;
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE;
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_ICON;
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_NAV_PROFILE;
|
||||
import static net.osmand.plus.profiles.SettingsProfileFragment.IS_NEW_PROFILE;
|
||||
|
@ -207,7 +207,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
if (profile.parent != null) {
|
||||
bundle.putString(SELECTED_KEY, profile.parent.getStringKey());
|
||||
}
|
||||
bundle.putString(DIALOG_TYPE, TYPE_APP_PROFILE);
|
||||
bundle.putString(DIALOG_TYPE, TYPE_BASE_APP_PROFILE);
|
||||
dialog.setArguments(bundle);
|
||||
if (getActivity() != null) {
|
||||
getActivity().getSupportFragmentManager().beginTransaction()
|
||||
|
|
|
@ -122,10 +122,10 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
|
|||
|
||||
ProfileViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
title = itemView.findViewById(R.id.profile_title);
|
||||
descr = itemView.findViewById(R.id.profile_descr);
|
||||
aSwitch = itemView.findViewById(R.id.profile_switch);
|
||||
icon = itemView.findViewById(R.id.profile_icon);
|
||||
title = itemView.findViewById(R.id.title);
|
||||
descr = itemView.findViewById(R.id.description);
|
||||
aSwitch = itemView.findViewById(R.id.compound_button);
|
||||
icon = itemView.findViewById(R.id.icon);
|
||||
profileOptions = itemView.findViewById(R.id.profile_settings);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,17 +7,16 @@ import android.graphics.drawable.Drawable;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
|
@ -33,16 +32,21 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
public static final String TAG = "SelectProfileBottomSheetDialogFragment";
|
||||
|
||||
public final static String DIALOG_TYPE = "dialog_type";
|
||||
public final static String TYPE_APP_PROFILE = "base_profiles";
|
||||
public final static String TYPE_BASE_APP_PROFILE = "base_profiles";
|
||||
public final static String TYPE_NAV_PROFILE = "routing_profiles";
|
||||
public final static String TYPE_ICON = "icon_type";
|
||||
public final static String TYPE_APP_PROFILES = "app_profiles";
|
||||
public final static String SELECTED_KEY = "selected_base";
|
||||
|
||||
String type;
|
||||
int bottomButtonText = R.string.shared_string_cancel;
|
||||
|
||||
private SelectProfileListener listener;
|
||||
|
||||
private List<ProfileDataObject> profiles = new ArrayList<>();
|
||||
private final List<ProfileDataObject> profiles = new ArrayList<>();
|
||||
private final List<ApplicationMode> appModes = new ArrayList<>();
|
||||
private final Set<ApplicationMode> activeAppModes = new HashSet<>();
|
||||
|
||||
private List<IconResWithDescr> icons;
|
||||
private String selectedItemKey;
|
||||
private int selectedIconRes;
|
||||
|
@ -55,14 +59,19 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
if (args != null && args.get(DIALOG_TYPE) != null) {
|
||||
type = args.getString(DIALOG_TYPE);
|
||||
selectedItemKey = args.getString(SELECTED_KEY, null);
|
||||
|
||||
if (type.equals(TYPE_NAV_PROFILE)) {
|
||||
profiles.addAll(EditProfileFragment.getRoutingProfiles(app));
|
||||
} else if (type.equals(TYPE_APP_PROFILE)) {
|
||||
} else if (type.equals(TYPE_BASE_APP_PROFILE)) {
|
||||
profiles.addAll(SettingsProfileFragment.getBaseProfiles(app));
|
||||
} else if (type.equals(TYPE_ICON)) {
|
||||
selectedIconRes = args.getInt(SELECTED_ICON, -1);
|
||||
icons = getProfileIcons();
|
||||
} else if (type.equals(TYPE_APP_PROFILES)){
|
||||
appModes.addAll(ApplicationMode.allPossibleValues());
|
||||
appModes.remove(0);
|
||||
activeAppModes.addAll(ApplicationMode.values(app));
|
||||
activeAppModes.remove(0);
|
||||
bottomButtonText = R.string.shared_string_close;
|
||||
} else {
|
||||
LOG.error("Check intent data!");
|
||||
dismiss();
|
||||
|
@ -88,7 +97,7 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
|
||||
if (type.equals(TYPE_APP_PROFILE)) {
|
||||
if (type.equals(TYPE_BASE_APP_PROFILE)) {
|
||||
items.add(new TitleItem(getString(R.string.select_base_profile_dialog_title)));
|
||||
items.add(new LongDescriptionItem(getString(R.string.select_base_profile_dialog_message)));
|
||||
for (int i = 0; i < profiles.size(); i++) {
|
||||
|
@ -170,6 +179,53 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
})
|
||||
.create());
|
||||
}
|
||||
} else if (type.equals(TYPE_APP_PROFILES)) {
|
||||
items.add(new TitleItem(getString(R.string.application_profiles)));
|
||||
for (int i = 0; i < appModes.size(); i++) {
|
||||
final int pos = i;
|
||||
final ApplicationMode mode = appModes.get(i);
|
||||
final boolean[] isSelected = {activeAppModes.contains(mode)};
|
||||
final Drawable icon;
|
||||
if (isSelected[0]) {
|
||||
icon = getMyApplication().getUIUtilities().getIcon(mode.getSmallIconDark(), nightMode
|
||||
? R.color.active_buttons_and_links_dark
|
||||
: R.color.active_buttons_and_links_light);
|
||||
} else {
|
||||
icon = getMyApplication().getUIUtilities().getIcon(
|
||||
mode.getSmallIconDark(), R.color.icon_color);
|
||||
}
|
||||
items.add(new BottomSheetItemWithCompoundButton.Builder()
|
||||
.setChecked(isSelected[0])
|
||||
.setDescription(mode.getParent() == null
|
||||
? getString(R.string.profile_type_base_string)
|
||||
: String.format(getString(R.string.profile_type_descr_string),
|
||||
getString(mode.getParent().getStringResource())))
|
||||
.setTitle(mode.getParent() == null
|
||||
? getString(mode.getStringResource())
|
||||
: mode.getUserProfileName())
|
||||
.setIcon(icon)
|
||||
.setLayoutId(R.layout.profile_list_item)
|
||||
.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (getView() != null) {
|
||||
((SwitchCompat) getView().findViewById(R.id.compound_button)).toggle();
|
||||
}
|
||||
if (!isSelected[0]) {
|
||||
activeAppModes.add(mode);
|
||||
} else {
|
||||
activeAppModes.remove(mode);
|
||||
}
|
||||
ApplicationMode
|
||||
.changeProfileStatus(mode, isSelected[0], getMyApplication());
|
||||
boolean status = !isSelected[0];
|
||||
isSelected[0] = status;
|
||||
}
|
||||
})
|
||||
.create()
|
||||
|
||||
);
|
||||
}
|
||||
} else if (type.equals(TYPE_ICON)) {
|
||||
items.add(new TitleItem(getString(R.string.select_icon_profile_dialog_title)));
|
||||
for (final IconResWithDescr icon : icons) {
|
||||
|
@ -211,11 +267,13 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void getListener() {
|
||||
if (getActivity() != null && getActivity() instanceof EditProfileActivity) {
|
||||
EditProfileFragment f = (EditProfileFragment) getActivity().getSupportFragmentManager()
|
||||
.findFragmentByTag(EditProfileActivity.EDIT_PROFILE_FRAGMENT_TAG);
|
||||
if (type.equals(TYPE_APP_PROFILE)) {
|
||||
if (type.equals(TYPE_BASE_APP_PROFILE)) {
|
||||
listener = f.getBaseProfileListener();
|
||||
} else if (type.equals(TYPE_NAV_PROFILE)) {
|
||||
listener = f.getNavProfileListener();
|
||||
|
|
|
@ -3,7 +3,7 @@ package net.osmand.plus.profiles;
|
|||
|
||||
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_APP_PROFILE;
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -98,7 +98,7 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
public void onClick(View v) {
|
||||
final SelectProfileBottomSheetDialogFragment dialog = new SelectProfileBottomSheetDialogFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(DIALOG_TYPE, TYPE_APP_PROFILE);
|
||||
bundle.putString(DIALOG_TYPE, TYPE_BASE_APP_PROFILE);
|
||||
dialog.setArguments(bundle);
|
||||
if (getActivity() != null) {
|
||||
getActivity().getSupportFragmentManager().beginTransaction()
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package net.osmand.plus.routepreparationmenu;
|
||||
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_APP_PROFILES;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.NonNull;
|
||||
|
@ -60,6 +65,7 @@ import net.osmand.plus.helpers.GpxUiHelper;
|
|||
import net.osmand.plus.helpers.WaypointHelper;
|
||||
import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
|
||||
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter;
|
||||
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter;
|
||||
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter;
|
||||
|
@ -728,7 +734,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
mainView.findViewById(R.id.app_modes_options).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
availableProfileDialog();
|
||||
showProfileBottomSheetDialog(mapActivity);
|
||||
//availableProfileDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -743,6 +750,17 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
updateApplicationModesOptions();
|
||||
}
|
||||
|
||||
private void showProfileBottomSheetDialog(Activity activity) {
|
||||
final SelectProfileBottomSheetDialogFragment fragment = new SelectProfileBottomSheetDialogFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(DIALOG_TYPE, TYPE_APP_PROFILES);
|
||||
fragment.setArguments(bundle);
|
||||
getMapActivity().getSupportFragmentManager().beginTransaction()
|
||||
.add(fragment, "app_profile_settings").commitAllowingStateLoss();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void availableProfileDialog() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
|
|
Loading…
Reference in a new issue