add select app profile bottom sheet to rp menu

This commit is contained in:
madwasp79 2019-05-27 13:50:28 +03:00
parent 1125a074c2
commit 95e522b1ee
5 changed files with 116 additions and 88 deletions

View file

@ -7,33 +7,8 @@
android:background="?attr/bg_color"
android:orientation="vertical">
<TextView
android:id="@+id/dialog_title"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/list_content_padding"
android:layout_marginBottom="@dimen/list_content_padding"
android:layout_marginStart="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/list_content_padding"
tools:text="Select navigation type"
android:textColor="?attr/main_font_color_basic"
android:textSize="@dimen/default_list_text_size"/>
<TextView
android:id="@+id/dialog_description_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/list_content_padding"
android:paddingStart="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:textSize="@dimen/default_list_text_size"
android:visibility="gone"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/menu_list_view"
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">

View file

@ -0,0 +1,109 @@
package net.osmand.plus.profiles;
import static net.osmand.plus.profiles.SettingsProfileFragment.IS_USER_PROFILE;
import static net.osmand.plus.profiles.SettingsProfileFragment.PROFILE_STRING_KEY;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.profiles.ProfileMenuAdapter.ProfileListener;
import net.osmand.util.Algorithms;
public class AppModesBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
private List<ApplicationMode> allModes = new ArrayList<>();
private Set<ApplicationMode> selectedModes = new HashSet<>();
protected boolean nightMode;
private ProfileMenuAdapter adapter;
private RecyclerView recyclerView;
private ProfileListener listener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
allModes.addAll(ApplicationMode.allPossibleValues());
allModes.remove(ApplicationMode.DEFAULT);
selectedModes.addAll(ApplicationMode.values(getMyApplication()));
selectedModes.remove(ApplicationMode.DEFAULT);
}
@Override
public void onResume() {
super.onResume();
listener = new ProfileListener() {
@Override
public void changeProfileStatus(ApplicationMode item, boolean isSelected) {
if(isSelected) {
selectedModes.add(item);
} else {
selectedModes.remove(item);
}
ApplicationMode.changeProfileStatus(item, isSelected, getMyApplication());
}
@Override
public void editProfile(ApplicationMode item) {
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
intent.putExtra(PROFILE_STRING_KEY, item.getStringKey());
if (!Algorithms.isEmpty(item.getUserProfileName())) {
intent.putExtra(IS_USER_PROFILE, true);
}
startActivity(intent);
}
};
adapter.setListener(listener);
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
adapter = new ProfileMenuAdapter(allModes, selectedModes, getMyApplication(), listener);
recyclerView = new RecyclerView(getContext());
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
recyclerView = (RecyclerView) View
.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.recyclerview, null);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
final View textButtonView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.bottom_sheet_item_simple, null);
TextView textView = (TextView) textButtonView.findViewById(R.id.title);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16.0f);
textView.setTextColor(nightMode
? getResources().getColor(R.color.active_buttons_and_links_dark)
: getResources().getColor(R.color.active_buttons_and_links_light));
textView.setText(R.string.shared_string_manage);
items.add(new TitleItem(getString(R.string.application_profiles)));
items.add(new BaseBottomSheetItem.Builder().setCustomView(recyclerView).create());
items.add(new BaseBottomSheetItem.Builder().setCustomView(textButtonView)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getContext(), SettingsProfileActivity.class));
}
})
.create());
}
}

View file

@ -47,6 +47,10 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
notifyDataSetChanged();
}
public void setListener(ProfileListener listener) {
this.listener = listener;
}
public void updateItemsList(List<ApplicationMode> newList, Set<ApplicationMode> selectedItems) {
items.clear();
this.selectedItems.clear();

View file

@ -35,7 +35,6 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
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;
@ -66,12 +65,6 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
} 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();
@ -179,53 +172,6 @@ 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) {

View file

@ -1,7 +1,5 @@
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;
@ -10,7 +8,6 @@ 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;
@ -65,7 +62,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.profiles.AppModesBottomSheetDialogFragment;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter;
@ -751,10 +748,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
}
private void showProfileBottomSheetDialog(Activity activity) {
final SelectProfileBottomSheetDialogFragment fragment = new SelectProfileBottomSheetDialogFragment();
Bundle bundle = new Bundle();
bundle.putString(DIALOG_TYPE, TYPE_APP_PROFILES);
fragment.setArguments(bundle);
final AppModesBottomSheetDialogFragment fragment = new AppModesBottomSheetDialogFragment();
getMapActivity().getSupportFragmentManager().beginTransaction()
.add(fragment, "app_profile_settings").commitAllowingStateLoss();