optimizing profile menu

This commit is contained in:
madwasp79 2019-04-09 18:03:39 +03:00
parent f224cdf7d8
commit 73be369ac6
6 changed files with 81 additions and 75 deletions

View file

@ -19,7 +19,7 @@ public class ApplicationMode {
private static List<ApplicationMode> values = new ArrayList<>();
private static List<ApplicationMode> cachedFilteredValues = new ArrayList<>();
/*
* DEFAULT("Browse map"), CAR("Car"), BICYCLE("Bicycle"), PEDESTRIAN("Pedestrian"); NAUTICAL("boat")
* DEFAULT("Browse map"), CAR("Car"), BICYCLE("Bicycle"), PEDESTRIAN("Pedestrian"); NAUTICAL("boat"); PUBLIC_TRANSPORT("Public transport")
*/
public static final ApplicationMode DEFAULT = create(R.string.app_mode_default, "default").speed(1.5f, 5).arrivalDistance(90).defLocation().
icon(R.drawable.map_world_globe_dark, R.drawable.ic_world_globe_dark).reg();
@ -57,8 +57,8 @@ public class ApplicationMode {
carLocation().icon(R.drawable.map_action_train, R.drawable.ic_action_train).reg();
static {
ApplicationMode[] exceptDefault = new ApplicationMode[]{CAR, PEDESTRIAN, BICYCLE, BOAT, AIRCRAFT, PUBLIC_TRANSPORT, TRAIN};
ApplicationMode[] exceptPedestrianAndDefault = new ApplicationMode[]{CAR, BICYCLE, BOAT, AIRCRAFT, PUBLIC_TRANSPORT, TRAIN};
ApplicationMode[] exceptDefault = new ApplicationMode[]{CAR, PEDESTRIAN, BICYCLE, BOAT, PUBLIC_TRANSPORT};
ApplicationMode[] exceptPedestrianAndDefault = new ApplicationMode[]{CAR, BICYCLE, BOAT, PUBLIC_TRANSPORT};
ApplicationMode[] exceptAirBoatDefault = new ApplicationMode[]{CAR, BICYCLE, PEDESTRIAN};
ApplicationMode[] pedestrian = new ApplicationMode[]{PEDESTRIAN};
ApplicationMode[] pedestrianBicycle = new ApplicationMode[]{PEDESTRIAN, BICYCLE};
@ -101,6 +101,7 @@ public class ApplicationMode {
}
private static class ApplicationModeBuilder {
@ -191,6 +192,10 @@ public class ApplicationMode {
return builder;
}
public static ApplicationModeBuilder createCustomMode(int key, String stringKey) {
return create(key, stringKey);
}
private ApplicationMode(int key, String stringKey) {
this.key = key;
this.stringKey = stringKey;

View file

@ -2,13 +2,21 @@ package net.osmand.plus.profiles;
import android.os.Parcel;
import android.os.Parcelable;
import net.osmand.plus.ApplicationMode;
public class AppProfile implements Parcelable {
private int iconRes;
private String title;
private String navType;
private boolean isSelected;
private String prefKey;
private float defSpeed;
private int distForTurn;
private int arrivalDistance;
private int offRouteDistance;
public AppProfile(int iconRes, String title, String descr) {
this.iconRes = iconRes;
@ -17,7 +25,6 @@ public class AppProfile implements Parcelable {
}
public int getIconRes() {
return iconRes;
}

View file

@ -13,13 +13,11 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import java.util.EnumSet;
import java.util.List;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
import org.apache.commons.logging.Log;
public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment {

View file

@ -10,35 +10,40 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.profiles.ProfileMenuAdapter.ProfileViewHolder;
import net.sf.junidecode.App;
public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder> {
private List<AppProfile> items;
private List<ApplicationMode> items;
private Set<ApplicationMode> selectedItems;
private ProfileListener listener = null;
private final OsmandApplication app;
public ProfileMenuAdapter(List<AppProfile> items, OsmandApplication app, ProfileListener listener) {
public ProfileMenuAdapter(List<ApplicationMode> items, Set<ApplicationMode> selectedItems, OsmandApplication app, ProfileListener listener) {
this.items = items;
this.listener = listener;
this.app = app;
this.selectedItems = selectedItems;
}
public List<AppProfile> getItems() {
public List<ApplicationMode> getItems() {
return items;
}
public void addItem(AppProfile profileItem) {
public void addItem(ApplicationMode profileItem) {
items.add(profileItem);
notifyDataSetChanged();
}
public void updateItemsList(List<AppProfile> newList) {
public void updateItemsList(List<ApplicationMode> newList) {
items.clear();
items.addAll(newList);
notifyDataSetChanged();
@ -54,12 +59,17 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
@Override
public void onBindViewHolder(@NonNull final ProfileViewHolder holder, int position) {
final AppProfile item = items.get(position);
holder.title.setText(item.getTitle());
final ApplicationMode item = items.get(position);
if (item.getParent() != null) {
holder.descr.setText(String.format("Type: %s", item.getParent().getStringKey()));
} else {
holder.title.setText(app.getResources().getString(item.getStringResource()));
holder.descr.setText(String.format("Type: %s", item.getStringKey()));
}
holder.title.setTextColor(app.getResources().getColor(isNightMode(app) ? R.color.main_font_dark : R.color.main_font_light));
holder.descr.setText(String.format("Type: %s", item.getNavType()));
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(item.getIconRes(), isNightMode(app) ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light));
holder.aSwitch.setChecked(item.isSelected());
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(item.getSmallIconDark(), isNightMode(app) ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light));
holder.aSwitch.setChecked(selectedItems.contains(item));
holder.aSwitch.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@ -99,8 +109,8 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
}
public interface ProfileListener {
void changeProfileStatus(AppProfile item, boolean isSelected);
void editProfile(AppProfile item);
void changeProfileStatus(ApplicationMode item, boolean isSelected);
void editProfile(ApplicationMode item);
}
}

View file

@ -19,7 +19,7 @@ public class SelectedProfileActivity extends OsmandActionBarActivity {
Intent intent = getIntent();
if (intent.getExtras() != null) {
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(((AppProfile) intent.getParcelableExtra("profile")).getTitle());
// getSupportActionBar().setTitle(((AppProfile) intent.getParcelableExtra("profile")).getTitle());
getSupportActionBar().setElevation(5.0f);
}
}

View file

@ -1,7 +1,6 @@
package net.osmand.plus.profiles;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -12,7 +11,6 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@ -33,54 +31,42 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
ProfileListener listener = null;
private List<ApplicationMode> allDefaultModes;
private Set<ApplicationMode> selectedDefaultModes;
private List<AppProfile> profilesList;
private List<ApplicationMode> allAppModes;
private Set<ApplicationMode> availableAppModes;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context ctx = getMyApplication().getApplicationContext();
profilesList = new ArrayList<>();
allDefaultModes = ApplicationMode.allPossibleValues();
allDefaultModes.remove(ApplicationMode.DEFAULT);
allDefaultModes.remove(ApplicationMode.AIRCRAFT);
allDefaultModes.remove(ApplicationMode.HIKING);
allDefaultModes.remove(ApplicationMode.TRAIN);
selectedDefaultModes = new LinkedHashSet<>(ApplicationMode.values(getMyApplication()));
selectedDefaultModes.remove(ApplicationMode.DEFAULT);
for (ApplicationMode am : allDefaultModes) {
AppProfile profileItem = new AppProfile(
am.getSmallIconDark(),
am.toHumanStringCtx(getMyApplication().getApplicationContext()),
getNavType(am, ctx));
if (selectedDefaultModes.contains(am)) {
profileItem.setSelected(true);
}
profilesList.add(profileItem);
}
allAppModes = ApplicationMode.allPossibleValues();
allAppModes.remove(ApplicationMode.DEFAULT);
allAppModes.remove(ApplicationMode.AIRCRAFT);
allAppModes.remove(ApplicationMode.HIKING);
allAppModes.remove(ApplicationMode.TRAIN);
availableAppModes = new LinkedHashSet<>(ApplicationMode.values(getMyApplication()));
availableAppModes.remove(ApplicationMode.DEFAULT);
}
private String getNavType(ApplicationMode am, Context ctx) {
if (am.getParent() != null) {
return getNavType(am.getParent(), ctx);
} else {
switch(am.getStringKey()) {
case "car":
return ctx.getResources().getString(R.string.rendering_value_car_name);
case "bicycle":
return ctx.getResources().getString(R.string.rendering_value_bicycle_name);
case "pedestrian":
return ctx.getResources().getString(R.string.rendering_value_pedestrian_name);
case "public_transport":
return ctx.getResources().getString(R.string.app_mode_public_transport);
case "boat":
return ctx.getResources().getString(R.string.app_mode_boat);
}
}
return "";
}
// private String getNavType(ApplicationMode am, Context ctx) {
// if (am.getParent() != null) {
// return getNavType(am.getParent(), ctx);
// } else {
// switch(am.getStringKey()) {
// case "car":
// return ctx.getResources().getString(R.string.rendering_value_car_name);
// case "bicycle":
// return ctx.getResources().getString(R.string.rendering_value_bicycle_name);
// case "pedestrian":
// return ctx.getResources().getString(R.string.rendering_value_pedestrian_name);
// case "public_transport":
// return ctx.getResources().getString(R.string.app_mode_public_transport);
// case "boat":
// return ctx.getResources().getString(R.string.app_mode_boat);
// }
// }
// return "";
// }
@Nullable
@Override
@ -97,23 +83,23 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
});
listener = new ProfileListener() {
@Override
public void changeProfileStatus(AppProfile item, boolean isSelected) {
LOG.debug(item.getTitle() + " - " + isSelected);
public void changeProfileStatus(ApplicationMode item, boolean isSelected) {
LOG.debug(getString(item.getStringResource()) + " - " + isSelected);
StringBuilder vls = new StringBuilder(ApplicationMode.DEFAULT.getStringKey()+",");
ApplicationMode mode = null;
for (ApplicationMode sam : allDefaultModes) {
if (sam.toHumanString(getContext()).equals(item.getTitle())) {
for (ApplicationMode sam : allAppModes) {
if (sam.getStringKey().equals(item.getStringKey())) {
mode = sam;
}
}
if(isSelected && mode != null) {
selectedDefaultModes.add(mode);
availableAppModes.add(mode);
} else if (mode != null) {
selectedDefaultModes.remove(mode);
availableAppModes.remove(mode);
}
for (ApplicationMode sam : selectedDefaultModes) {
for (ApplicationMode sam : availableAppModes) {
vls.append(sam.getStringKey()).append(",");
}
getSettings().AVAILABLE_APP_MODES.set(vls.toString());
@ -121,13 +107,13 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
}
@Override
public void editProfile(AppProfile item) {
Intent intent = new Intent(getActivity(), SelectedProfileActivity.class);
intent.putExtra("profile", item);
startActivity(intent);
public void editProfile(ApplicationMode item) {
// Intent intent = new Intent(getActivity(), SelectedProfileActivity.class);
// intent.putExtra("profile", item);
// startActivity(intent);
}
};
adapter = new ProfileMenuAdapter(profilesList, getMyApplication(), listener);
adapter = new ProfileMenuAdapter(allAppModes, availableAppModes, getMyApplication(), listener);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);