bottom sheet fragment ui fixes
This commit is contained in:
parent
d86c0c00cc
commit
88dc065a98
6 changed files with 114 additions and 72 deletions
|
@ -91,6 +91,7 @@
|
|||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider_bottom"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_weight="2"
|
||||
|
|
|
@ -43,6 +43,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
|
|||
protected int themeRes;
|
||||
|
||||
private LinearLayout itemsContainer;
|
||||
protected int dismissButtonStringRes = R.string.shared_string_cancel;
|
||||
|
||||
public void setUsedOnMap(boolean usedOnMap) {
|
||||
this.usedOnMap = usedOnMap;
|
||||
|
@ -245,7 +246,11 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
|
|||
|
||||
@StringRes
|
||||
protected int getDismissButtonTextId() {
|
||||
return R.string.shared_string_cancel;
|
||||
return dismissButtonStringRes;
|
||||
}
|
||||
|
||||
protected void setDismissButtonTextId(int stringRes) {
|
||||
dismissButtonStringRes = stringRes;
|
||||
}
|
||||
|
||||
protected void onDismissButtonClickAction() {
|
||||
|
|
|
@ -18,6 +18,7 @@ import android.view.ViewGroup;
|
|||
import android.widget.TextView;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
|
@ -44,10 +45,8 @@ public class AppModesBottomSheetDialogFragment extends MenuBottomSheetDialogFrag
|
|||
@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);
|
||||
setDismissButtonTextId(R.string.shared_string_close);
|
||||
getData();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -56,6 +55,7 @@ public class AppModesBottomSheetDialogFragment extends MenuBottomSheetDialogFrag
|
|||
Bundle savedInstanceState) {
|
||||
themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
adapter = new ProfileMenuAdapter(allModes, selectedModes, getMyApplication(), listener);
|
||||
adapter.setBottomSheetMode(true);
|
||||
recyclerView = new RecyclerView(getContext());
|
||||
recyclerView = (RecyclerView) View
|
||||
.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.recyclerview, null);
|
||||
|
@ -96,8 +96,19 @@ public class AppModesBottomSheetDialogFragment extends MenuBottomSheetDialogFrag
|
|||
startActivity(intent);
|
||||
}
|
||||
};
|
||||
|
||||
adapter.setListener(listener);
|
||||
allModes = ApplicationMode.allPossibleValues();
|
||||
allModes.remove(ApplicationMode.DEFAULT);
|
||||
adapter.updateItemsList(allModes, new LinkedHashSet<>(ApplicationMode.values(getMyApplication())));
|
||||
setupHeightAndBackground(getView());
|
||||
|
||||
}
|
||||
|
||||
private void getData() {
|
||||
allModes.addAll(ApplicationMode.allPossibleValues());
|
||||
allModes.remove(ApplicationMode.DEFAULT);
|
||||
selectedModes.addAll(ApplicationMode.values(getMyApplication()));
|
||||
selectedModes.remove(ApplicationMode.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -385,6 +385,10 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
});
|
||||
|
||||
if (!isNew && !isUserProfile) {
|
||||
saveButtonSV.setEnabled(false);
|
||||
saveButton.setEnabled(false);
|
||||
} else {
|
||||
saveButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -404,6 +408,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
|
||||
@Override
|
||||
|
|
|
@ -26,9 +26,12 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
|
|||
private Set<ApplicationMode> selectedItems;
|
||||
private ProfileListener listener;
|
||||
private final OsmandApplication app;
|
||||
@ColorRes private int selectedIconColorRes;
|
||||
@ColorRes
|
||||
private int selectedIconColorRes;
|
||||
private boolean isBottomSheet = false;
|
||||
|
||||
public ProfileMenuAdapter(List<ApplicationMode> items, Set<ApplicationMode> selectedItems, 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;
|
||||
|
@ -47,6 +50,10 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setBottomSheetMode(boolean isBottomSheet) {
|
||||
this.isBottomSheet = isBottomSheet;
|
||||
}
|
||||
|
||||
public void setListener(ProfileListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
@ -70,10 +77,18 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
|
|||
@Override
|
||||
public void onBindViewHolder(@NonNull final ProfileViewHolder holder, int position) {
|
||||
final ApplicationMode item = items.get(position);
|
||||
|
||||
if (isBottomSheet) {
|
||||
holder.divider.setBackgroundColor(isNightMode(app)
|
||||
? app.getResources().getColor(R.color.divider_dark)
|
||||
: app.getResources().getColor(R.color.divider_light));
|
||||
}
|
||||
|
||||
if (item.getParent() != null) {
|
||||
holder.title.setText(item.getUserProfileName());
|
||||
holder.descr.setText(String.format(app.getString(R.string.profile_type_descr_string),
|
||||
Algorithms.capitalizeFirstLetterAndLowercase(item.getParent().getStringKey().replace("_", " "))));
|
||||
Algorithms.capitalizeFirstLetterAndLowercase(
|
||||
item.getParent().getStringKey().replace("_", " "))));
|
||||
} else {
|
||||
holder.title.setText(app.getResources().getString(item.getStringResource()));
|
||||
holder.descr.setText(R.string.profile_type_base_string);
|
||||
|
@ -97,7 +112,8 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
|
|||
|
||||
if (selectedItems.contains(item)) {
|
||||
holder.aSwitch.setChecked(true);
|
||||
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes, selectedIconColorRes));
|
||||
holder.icon
|
||||
.setImageDrawable(app.getUIUtilities().getIcon(iconRes, selectedIconColorRes));
|
||||
} else {
|
||||
holder.aSwitch.setChecked(false);
|
||||
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes, R.color.icon_color));
|
||||
|
@ -108,9 +124,11 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
|
|||
public void onClick(View v) {
|
||||
listener.changeProfileStatus(item, holder.aSwitch.isChecked());
|
||||
if (selectedItems.contains(item)) {
|
||||
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(item.getSmallIconDark(), selectedIconColorRes));
|
||||
holder.icon.setImageDrawable(app.getUIUtilities()
|
||||
.getIcon(item.getSmallIconDark(), selectedIconColorRes));
|
||||
} else {
|
||||
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(item.getSmallIconDark(), R.color.icon_color));
|
||||
holder.icon.setImageDrawable(
|
||||
app.getUIUtilities().getIcon(item.getSmallIconDark(), R.color.icon_color));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -132,10 +150,12 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
|
|||
}
|
||||
|
||||
class ProfileViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
TextView title, descr;
|
||||
SwitchCompat aSwitch;
|
||||
ImageView icon;
|
||||
LinearLayout profileOptions;
|
||||
View divider;
|
||||
|
||||
ProfileViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
@ -144,11 +164,14 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
|
|||
aSwitch = itemView.findViewById(R.id.compound_button);
|
||||
icon = itemView.findViewById(R.id.icon);
|
||||
profileOptions = itemView.findViewById(R.id.profile_settings);
|
||||
divider = itemView.findViewById(R.id.divider_bottom);
|
||||
}
|
||||
}
|
||||
|
||||
public interface ProfileListener {
|
||||
|
||||
void changeProfileStatus(ApplicationMode item, boolean isSelected);
|
||||
|
||||
void editProfile(ApplicationMode item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -733,7 +733,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
showProfileBottomSheetDialog(mapActivity);
|
||||
showProfileBottomSheetDialog();
|
||||
//todo clear (+ method's body) before final commit
|
||||
//availableProfileDialog();
|
||||
}
|
||||
|
@ -750,7 +750,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
updateApplicationModesOptions();
|
||||
}
|
||||
|
||||
private void showProfileBottomSheetDialog(Activity activity) {
|
||||
private void showProfileBottomSheetDialog() {
|
||||
final AppModesBottomSheetDialogFragment fragment = new AppModesBottomSheetDialogFragment();
|
||||
fragment.setUpdateMapRouteMenuListener(new UpdateMapRouteMenuListener() {
|
||||
@Override
|
||||
|
@ -760,45 +760,42 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
});
|
||||
getMapActivity().getSupportFragmentManager().beginTransaction()
|
||||
.add(fragment, "app_profile_settings").commitAllowingStateLoss();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void availableProfileDialog() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
AlertDialog.Builder b = new AlertDialog.Builder(mapActivity);
|
||||
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
|
||||
final List<ApplicationMode> modes = ApplicationMode.allPossibleValues();
|
||||
modes.remove(ApplicationMode.DEFAULT);
|
||||
final Set<ApplicationMode> selected = new LinkedHashSet<>(ApplicationMode.values(mapActivity.getMyApplication()));
|
||||
selected.remove(ApplicationMode.DEFAULT);
|
||||
View v = AppModeDialog.prepareAppModeView(mapActivity, modes, selected, null, false, true, false,
|
||||
new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
StringBuilder vls = new StringBuilder(ApplicationMode.DEFAULT.getStringKey() + ",");
|
||||
for (ApplicationMode mode : modes) {
|
||||
if (selected.contains(mode)) {
|
||||
vls.append(mode.getStringKey()).append(",");
|
||||
}
|
||||
}
|
||||
settings.AVAILABLE_APP_MODES.set(vls.toString());
|
||||
}
|
||||
});
|
||||
b.setTitle(R.string.profile_settings);
|
||||
b.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
updateApplicationModes();
|
||||
}
|
||||
});
|
||||
b.setView(v);
|
||||
b.show();
|
||||
}
|
||||
}
|
||||
// private void availableProfileDialog() {
|
||||
// MapActivity mapActivity = getMapActivity();
|
||||
// if (mapActivity != null) {
|
||||
// AlertDialog.Builder b = new AlertDialog.Builder(mapActivity);
|
||||
// final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
|
||||
// final List<ApplicationMode> modes = ApplicationMode.allPossibleValues();
|
||||
// modes.remove(ApplicationMode.DEFAULT);
|
||||
// final Set<ApplicationMode> selected = new LinkedHashSet<>(ApplicationMode.values(mapActivity.getMyApplication()));
|
||||
// selected.remove(ApplicationMode.DEFAULT);
|
||||
// View v = AppModeDialog.prepareAppModeView(mapActivity, modes, selected, null, false, true, false,
|
||||
// new OnClickListener() {
|
||||
//
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// StringBuilder vls = new StringBuilder(ApplicationMode.DEFAULT.getStringKey() + ",");
|
||||
// for (ApplicationMode mode : modes) {
|
||||
// if (selected.contains(mode)) {
|
||||
// vls.append(mode.getStringKey()).append(",");
|
||||
// }
|
||||
// }
|
||||
// settings.AVAILABLE_APP_MODES.set(vls.toString());
|
||||
// }
|
||||
// });
|
||||
// b.setTitle(R.string.profile_settings);
|
||||
// b.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// updateApplicationModes();
|
||||
// }
|
||||
// });
|
||||
// b.setView(v);
|
||||
// b.show();
|
||||
// }
|
||||
// }
|
||||
|
||||
private void updateApplicationMode(ApplicationMode mode, ApplicationMode next) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
|
|
Loading…
Reference in a new issue