fix bottomsheet screens
This commit is contained in:
parent
a560dff59d
commit
7bce4d7ffa
5 changed files with 200 additions and 40 deletions
|
@ -76,7 +76,7 @@
|
|||
android:maxLines="1"
|
||||
android:textSize="18sp"
|
||||
android:textColor="?attr/main_font_color_basic"
|
||||
tools:text="Item additional desription"/>
|
||||
tools:text="Item additional description"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -339,7 +339,6 @@
|
|||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:textStyle="bold"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Configure map"
|
||||
|
@ -388,7 +387,6 @@
|
|||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:textStyle="bold"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Configure screen"
|
||||
|
@ -439,7 +437,6 @@
|
|||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:textStyle="bold"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Navigation settings"
|
||||
|
|
|
@ -50,6 +50,7 @@ import net.osmand.plus.activities.SettingsNavigationActivity;
|
|||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
import net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.ProfileTypeDialogListener;
|
||||
import net.osmand.plus.profiles.SelectIconBottomSheetDialogFragment.IconIdListener;
|
||||
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener;
|
||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
|
||||
import net.osmand.router.GeneralRouter;
|
||||
|
@ -79,9 +80,9 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
private boolean isUserProfile = false;
|
||||
private boolean isDataChanged = false;
|
||||
|
||||
private ProfileTypeDialogListener navTypeListener = null;
|
||||
private SelectProfileListener navTypeListener = null;
|
||||
private IconIdListener iconIdListener = null;
|
||||
private ProfileTypeDialogListener baseTypeListener = null;
|
||||
private SelectProfileListener baseTypeListener = null;
|
||||
|
||||
private ImageView profileIcon;
|
||||
private LinearLayout profileIconBtn;
|
||||
|
@ -170,11 +171,11 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
|
||||
String title = "New Profile";
|
||||
|
||||
int startIconId = R.drawable.map_world_globe_dark;
|
||||
|
||||
if (isNew) {
|
||||
isDataChanged = true;
|
||||
title = String
|
||||
.format("Custom %s", getResources().getString(profile.parent.getStringResource()));
|
||||
startIconId = profile.parent.getSmallIconDark();
|
||||
profile.iconId = startIconId;
|
||||
} else if (isUserProfile) {
|
||||
|
@ -188,8 +189,8 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
startIconId = profile.iconId;
|
||||
clickBlockLayout.setClickable(true);
|
||||
}
|
||||
|
||||
profile.userProfileTitle = title;
|
||||
|
||||
if (profile.parent != null) {
|
||||
setupBaseProfileView(profile.parent.getStringKey());
|
||||
} else if (profile.key != -1) {
|
||||
|
@ -201,7 +202,8 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if (isUserProfile || isNew) {
|
||||
final ProfileBottomSheetDialogFragment dialog = new ProfileBottomSheetDialogFragment();
|
||||
//final ProfileBottomSheetDialogFragment dialog = new ProfileBottomSheetDialogFragment();
|
||||
final SelectProfileBottomSheetDialogFragment dialog = new SelectProfileBottomSheetDialogFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
if (profile.parent != null) {
|
||||
bundle.putString(SELECTED_KEY, profile.parent.getStringKey());
|
||||
|
@ -280,7 +282,8 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if (isNew || isUserProfile) {
|
||||
ProfileBottomSheetDialogFragment fragment = new ProfileBottomSheetDialogFragment();
|
||||
//ProfileBottomSheetDialogFragment fragment = new ProfileBottomSheetDialogFragment();
|
||||
final SelectProfileBottomSheetDialogFragment fragment = new SelectProfileBottomSheetDialogFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
if (profile.routingProfileDataObject != null) {
|
||||
bundle.putString(SELECTED_KEY,
|
||||
|
@ -430,7 +433,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
|
||||
@Override
|
||||
public void onResume() {
|
||||
baseTypeListener = new ProfileTypeDialogListener() {
|
||||
baseTypeListener = new SelectProfileListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos) {
|
||||
String key = SettingsProfileFragment.getBaseProfiles(getMyApplication()).get(pos)
|
||||
|
@ -440,7 +443,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
};
|
||||
|
||||
navTypeListener = new ProfileTypeDialogListener() {
|
||||
navTypeListener = new SelectProfileListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos) {
|
||||
updateRoutingProfile(pos);
|
||||
|
@ -477,9 +480,9 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
return iconIdListener;
|
||||
}
|
||||
|
||||
ProfileTypeDialogListener getBaseProfileListener() {
|
||||
SelectProfileListener getBaseProfileListener() {
|
||||
if (baseTypeListener == null) {
|
||||
baseTypeListener = new ProfileTypeDialogListener() {
|
||||
baseTypeListener = new SelectProfileListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos) {
|
||||
String key = SettingsProfileFragment.getBaseProfiles(getMyApplication())
|
||||
|
@ -492,9 +495,9 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
return baseTypeListener;
|
||||
}
|
||||
|
||||
ProfileTypeDialogListener getNavProfileListener() {
|
||||
SelectProfileListener getNavProfileListener() {
|
||||
if (navTypeListener == null) {
|
||||
navTypeListener = new ProfileTypeDialogListener() {
|
||||
navTypeListener = new SelectProfileListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos) {
|
||||
updateRoutingProfile(pos);
|
||||
|
|
|
@ -199,15 +199,15 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
if (getActivity() != null && getActivity() instanceof EditProfileActivity) {
|
||||
EditProfileFragment f = (EditProfileFragment) getActivity().getSupportFragmentManager()
|
||||
.findFragmentByTag(EditProfileActivity.EDIT_PROFILE_FRAGMENT_TAG);
|
||||
if (type.equals(TYPE_APP_PROFILE)) {
|
||||
listener = f.getBaseProfileListener();
|
||||
} else if (type.equals(TYPE_NAV_PROFILE)) {
|
||||
listener = f.getNavProfileListener();
|
||||
}
|
||||
// if (type.equals(TYPE_APP_PROFILE)) {
|
||||
// listener = f.getBaseProfileListener();
|
||||
// } else if (type.equals(TYPE_NAV_PROFILE)) {
|
||||
// listener = f.getNavProfileListener();
|
||||
// }
|
||||
} else if (getActivity() != null && getActivity() instanceof SettingsProfileActivity) {
|
||||
SettingsProfileFragment f = (SettingsProfileFragment) getActivity().getSupportFragmentManager()
|
||||
.findFragmentByTag(SettingsProfileActivity.SETTINGS_PROFILE_FRAGMENT_TAG);
|
||||
listener = f.getBaseProfileListener();
|
||||
// listener = f.getBaseProfileListener();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,159 @@
|
|||
package net.osmand.plus.profiles;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
|
||||
|
||||
private static final Log LOG = PlatformUtil
|
||||
.getLog(SelectProfileBottomSheetDialogFragment.class);
|
||||
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_NAV_PROFILE = "routing_profiles";
|
||||
public final static String SELECTED_KEY = "selected_base";
|
||||
|
||||
String type;
|
||||
|
||||
private SelectProfileListener listener;
|
||||
|
||||
private List<ProfileDataObject> profiles = new ArrayList<>();
|
||||
private String selectedItemKey;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
OsmandApplication app = getMyApplication();
|
||||
Bundle args = getArguments();
|
||||
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)) {
|
||||
profiles.addAll(SettingsProfileFragment.getBaseProfiles(app));
|
||||
} else {
|
||||
|
||||
LOG.error("Check intent data!");
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
if (type.equals(TYPE_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++) {
|
||||
final int pos = i;
|
||||
final ProfileDataObject profile = profiles.get(i);
|
||||
final boolean isSelected = profile.getStringKey().equals(selectedItemKey);
|
||||
final Drawable drawableIcon;
|
||||
if (isSelected) {
|
||||
drawableIcon = getMyApplication().getUIUtilities()
|
||||
.getIcon(profile.getIconRes(), nightMode
|
||||
? R.color.active_buttons_and_links_dark
|
||||
: R.color.active_buttons_and_links_light);
|
||||
} else {
|
||||
drawableIcon = getMyApplication().getUIUtilities()
|
||||
.getIcon(profile.getIconRes(), R.color.icon_color);
|
||||
}
|
||||
|
||||
items.add(new BottomSheetItemWithCompoundButton.Builder()
|
||||
.setChecked(isSelected)
|
||||
.setDescription(profile.getDescription())
|
||||
.setTitle(profile.getName())
|
||||
.setIcon(drawableIcon)
|
||||
.setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp)
|
||||
.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (listener == null) {
|
||||
getProfileListener();
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onSelectedType(pos);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create());
|
||||
}
|
||||
|
||||
} else if (type.equals(TYPE_NAV_PROFILE)){
|
||||
items.add(new TitleItem(getString(R.string.select_nav_profile_dialog_title)));
|
||||
for (int i = 0; i < profiles.size(); i++) {
|
||||
final int pos = i;
|
||||
final ProfileDataObject profile = profiles.get(i);
|
||||
final boolean isSelected = profile.getStringKey().equals(selectedItemKey);
|
||||
final Drawable drawableIcon;
|
||||
if (isSelected) {
|
||||
drawableIcon = getMyApplication().getUIUtilities()
|
||||
.getIcon(profile.getIconRes(), nightMode
|
||||
? R.color.active_buttons_and_links_dark
|
||||
: R.color.active_buttons_and_links_light);
|
||||
} else {
|
||||
drawableIcon = getMyApplication().getUIUtilities()
|
||||
.getIcon(profile.getIconRes(), R.color.icon_color);
|
||||
}
|
||||
|
||||
items.add(new BottomSheetItemWithCompoundButton.Builder()
|
||||
.setChecked(isSelected)
|
||||
.setDescription(profile.getDescription())
|
||||
.setTitle(profile.getName())
|
||||
.setIcon(drawableIcon)
|
||||
.setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp)
|
||||
.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (listener == null) {
|
||||
getProfileListener();
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onSelectedType(pos);
|
||||
}
|
||||
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getProfileListener() {
|
||||
if (getActivity() != null && getActivity() instanceof EditProfileActivity) {
|
||||
EditProfileFragment f = (EditProfileFragment) getActivity().getSupportFragmentManager()
|
||||
.findFragmentByTag(EditProfileActivity.EDIT_PROFILE_FRAGMENT_TAG);
|
||||
if (type.equals(TYPE_APP_PROFILE)) {
|
||||
listener = f.getBaseProfileListener();
|
||||
} else if (type.equals(TYPE_NAV_PROFILE)) {
|
||||
listener = f.getNavProfileListener();
|
||||
}
|
||||
} else if (getActivity() != null && getActivity() instanceof SettingsProfileActivity) {
|
||||
SettingsProfileFragment f = (SettingsProfileFragment) getActivity().getSupportFragmentManager()
|
||||
.findFragmentByTag(SettingsProfileActivity.SETTINGS_PROFILE_FRAGMENT_TAG);
|
||||
listener = f.getBaseProfileListener();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
interface SelectProfileListener {
|
||||
void onSelectedType(int pos);
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
import net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.ProfileTypeDialogListener;
|
||||
import net.osmand.plus.profiles.ProfileMenuAdapter.ProfileListener;
|
||||
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener;
|
||||
import net.osmand.util.Algorithms;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
|
@ -42,7 +43,7 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
private LinearLayout addNewProfileBtn;
|
||||
|
||||
ProfileListener listener = null;
|
||||
ProfileTypeDialogListener typeListener = null;
|
||||
SelectProfileListener typeListener = null;
|
||||
|
||||
private List<ApplicationMode> allAppModes;
|
||||
private Set<ApplicationMode> availableAppModes;
|
||||
|
@ -85,7 +86,7 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
};
|
||||
|
||||
typeListener = new ProfileTypeDialogListener() {
|
||||
typeListener = new SelectProfileListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos) {
|
||||
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||
|
@ -105,7 +106,7 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final ProfileBottomSheetDialogFragment dialog = new ProfileBottomSheetDialogFragment();
|
||||
final SelectProfileBottomSheetDialogFragment dialog = new SelectProfileBottomSheetDialogFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(DIALOG_TYPE, TYPE_APP_PROFILE);
|
||||
dialog.setArguments(bundle);
|
||||
|
@ -126,7 +127,7 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
typeListener = new ProfileTypeDialogListener() {
|
||||
typeListener = new SelectProfileListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos) {
|
||||
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||
|
@ -142,19 +143,19 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
adapter.updateItemsList(allAppModes, new LinkedHashSet<>(ApplicationMode.values(getMyApplication())));
|
||||
}
|
||||
|
||||
ProfileTypeDialogListener getBaseProfileListener() {
|
||||
if (typeListener == null) {
|
||||
typeListener = new ProfileTypeDialogListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos) {
|
||||
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||
intent.putExtra(IS_NEW_PROFILE, true);
|
||||
intent.putExtra(IS_USER_PROFILE, true);
|
||||
intent.putExtra(PROFILE_STRING_KEY, baseProfiles.get(pos).getStringKey());
|
||||
startActivity(intent);
|
||||
}
|
||||
};
|
||||
}
|
||||
SelectProfileListener getBaseProfileListener() {
|
||||
// if (typeListener == null) {
|
||||
// typeListener = new SelectProfileListener() {
|
||||
// @Override
|
||||
// public void onSelectedType(int pos) {
|
||||
// Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||
// intent.putExtra(IS_NEW_PROFILE, true);
|
||||
// intent.putExtra(IS_USER_PROFILE, true);
|
||||
// intent.putExtra(PROFILE_STRING_KEY, baseProfiles.get(pos).getStringKey());
|
||||
// startActivity(intent);
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
return typeListener;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue