Fix profiles UI

This commit is contained in:
crimean 2019-06-06 22:20:03 +03:00
parent 7d3a08629e
commit 423036a926
5 changed files with 208 additions and 210 deletions

View file

@ -1,104 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/profile_settings"
android:layout_width="match_parent"
android:layout_height="@dimen/setting_profile_item_height"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:orientation="horizontal">
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/profile_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:descendantFocusability="blocksDescendants"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_marginLeft="16dp"
android:layout_marginRight="@dimen/setting_profile_image_margin"
tools:src="@drawable/ic_action_bicycle_dark"/>
<ImageView
android:id="@+id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/favorites_icon_right_margin"
tools:src="@drawable/ic_action_bicycle_dark" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/setting_profile_item_height"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="63dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/main_font_dark"
android:textSize="@dimen/default_list_text_size"
tools:text="Bicycle" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:ellipsize="end"
android:textColor="@color/main_font_dark"
android:textSize="@dimen/default_list_text_size"
tools:text="Bicycle"/>
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textSize="@dimen/default_desc_text_size"
tools:text="Type: Bicycle" />
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/default_desc_text_size"
tools:text="Type: Bicycle"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
android:orientation="horizontal">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/menu_image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:paddingStart="@dimen/setting_profile_item_switch_margin"
android:paddingLeft="@dimen/setting_profile_item_switch_margin"
android:paddingEnd="10dp"
android:paddingRight="10dp"
android:src="@drawable/ic_action_additional_option"
android:tint="?attr/primary_icon_color" />
<ImageView
android:id="@+id/menu_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingTop="@dimen/setting_profile_item_switch_margin"
android:paddingBottom="@dimen/setting_profile_item_switch_margin"
android:paddingStart="@dimen/setting_profile_item_switch_margin"
android:paddingEnd="10dp"
android:paddingLeft="@dimen/setting_profile_item_switch_margin"
android:paddingRight="10dp"
android:src="@drawable/ic_action_additional_option"
android:tint="?attr/primary_icon_color"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/compound_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|end"
android:background="@null"
android:focusableInTouchMode="true"
android:padding="@dimen/content_padding" />
<android.support.v7.widget.SwitchCompat
android:id="@+id/compound_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:paddingTop="@dimen/setting_profile_item_switch_margin"
android:paddingBottom="@dimen/setting_profile_item_switch_margin"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<View
android:id="@+id/divider_bottom"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/settings_divider" />
<View
android:id="@+id/divider_bottom"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/settings_divider"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -343,9 +343,7 @@
<dimen name="pages_item_padding">3dp</dimen>
<dimen name="pages_item_margin">4dp</dimen>
<dimen name="setting_profile_item_height">64dp</dimen>
<dimen name="setting_profile_image_margin">24dp</dimen>
<dimen name="setting_profile_item_switch_margin">18dp</dimen>
</resources>

View file

@ -23,11 +23,12 @@ import java.util.List;
import java.util.Set;
import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
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.plus.profiles.ProfileMenuAdapter.ProfileMenuAdapterListener;
import net.osmand.util.Algorithms;
public class AppModesBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
@ -40,7 +41,7 @@ public class AppModesBottomSheetDialogFragment extends MenuBottomSheetDialogFrag
private ProfileMenuAdapter adapter;
private RecyclerView recyclerView;
private ProfileListener listener;
private ProfileMenuAdapterListener listener;
private UpdateMapRouteMenuListener updateMapRouteMenuListener;
@Override
@ -55,7 +56,7 @@ public class AppModesBottomSheetDialogFragment extends MenuBottomSheetDialogFrag
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup parent,
Bundle savedInstanceState) {
themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
adapter = new ProfileMenuAdapter(allModes, selectedModes, getMyApplication(), true);
adapter = new ProfileMenuAdapter(allModes, selectedModes, getMyApplication(), getString(R.string.shared_string_manage));
recyclerView = new RecyclerView(getContext());
recyclerView = (RecyclerView) View
.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.recyclerview, null);
@ -75,27 +76,37 @@ public class AppModesBottomSheetDialogFragment extends MenuBottomSheetDialogFrag
@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);
if (listener == null) {
listener = new ProfileMenuAdapterListener() {
@Override
public void onProfileSelected(ApplicationMode item, boolean selected) {
if (selected) {
selectedModes.add(item);
} else {
selectedModes.remove(item);
}
ApplicationMode.changeProfileStatus(item, selected, getMyApplication());
}
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);
@Override
public void onProfilePressed(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);
}
startActivity(intent);
}
};
@Override
public void onButtonPressed() {
OsmandApplication app = requiredMyApplication();
Intent intent = new Intent(app, SettingsProfileActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
app.startActivity(intent);
}
};
}
adapter.setListener(listener);
allModes = ApplicationMode.allPossibleValues();
allModes.remove(ApplicationMode.DEFAULT);

View file

@ -1,14 +1,17 @@
package net.osmand.plus.profiles;
import android.content.Intent;
import android.support.annotation.ColorRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -26,22 +29,25 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
private List<Object> items = new ArrayList<>();
private Set<ApplicationMode> selectedItems;
private ProfileListener listener;
@Nullable
private ProfileMenuAdapterListener listener;
private final OsmandApplication app;
@ColorRes
private int selectedIconColorRes;
private boolean isBottomSheet = false;
private static final String MANAGE_BTN = "manage_button";
private boolean bottomButton;
private String bottomButtonText;
private static final String BUTTON_ITEM = "button_item";
public ProfileMenuAdapter(List<ApplicationMode> items, Set<ApplicationMode> selectedItems,
OsmandApplication app, boolean isBottomSheet) {
OsmandApplication app, String bottomButtonText) {
this.items.addAll(items);
if (isBottomSheet) {
this.items.add(MANAGE_BTN);
if (bottomButton) {
this.items.add(BUTTON_ITEM);
}
this.app = app;
this.selectedItems = selectedItems;
this.isBottomSheet = isBottomSheet;
this.bottomButton = !Algorithms.isEmpty(bottomButtonText);
this.bottomButtonText = bottomButtonText;
selectedIconColorRes = isNightMode(app)
? R.color.active_buttons_and_links_dark
: R.color.active_buttons_and_links_light;
@ -51,12 +57,7 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
return items;
}
public void addItem(ApplicationMode profileItem) {
items.add(profileItem);
notifyDataSetChanged();
}
public void setListener(ProfileListener listener) {
public void setListener(@Nullable ProfileMenuAdapterListener listener) {
this.listener = listener;
}
@ -64,8 +65,8 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
this.items.clear();
this.selectedItems.clear();
this.items.addAll(newList);
if (isBottomSheet) {
items.add(MANAGE_BTN);
if (bottomButton) {
items.add(BUTTON_ITEM);
}
this.selectedItems.addAll(selectedItems);
notifyDataSetChanged();
@ -79,55 +80,22 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
@NonNull
@Override
public ProfileViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.profile_list_item, parent, false);
final ProfileViewHolder holder = new ProfileViewHolder(itemView);
holder.itemView.findViewById(R.id.compound_button).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
int pos = holder.getAdapterPosition();
if ( pos != RecyclerView.NO_POSITION) {
Object o = items.get(pos);
if (o instanceof ApplicationMode) {
final ApplicationMode item = (ApplicationMode) o;
int iconRes = item.getParent() == null
? item.getSmallIconDark()
: item.getIconRes(app);
if (iconRes == 0 || iconRes == -1) {
iconRes = R.drawable.ic_action_world_globe;
}
if (!selectedItems.contains(item)) {
selectedItems.add(item);
holder.icon.setImageDrawable(
app.getUIUtilities().getIcon(iconRes, selectedIconColorRes));
} else {
selectedItems.remove(item);
holder.icon.setImageDrawable(
app.getUIUtilities().getIcon(iconRes, R.color.icon_color));
}
listener.changeProfileStatus(item, holder.aSwitch.isChecked());
}
}
}
});
return holder;
View itemView =
LayoutInflater.from(parent.getContext()).inflate(R.layout.profile_list_item, parent, false);
return new ProfileViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull final ProfileViewHolder holder, int position) {
Object obj = items.get(position);
if (obj instanceof ApplicationMode) {
holder.divider.setVisibility(View.VISIBLE);
holder.icon.setVisibility(View.VISIBLE);
holder.descr.setVisibility(View.VISIBLE);
holder.aSwitch.setVisibility(View.VISIBLE);
holder.switcher.setVisibility(View.VISIBLE);
holder.menuIcon.setVisibility(View.VISIBLE);
final ApplicationMode item = (ApplicationMode) obj;
if (isBottomSheet) {
if (bottomButton) {
holder.divider.setBackgroundColor(isNightMode(app)
? app.getResources().getColor(R.color.divider_dark)
: app.getResources().getColor(R.color.divider_light));
@ -147,45 +115,21 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
? R.color.main_font_dark
: R.color.main_font_light));
int iconRes = item.getParent() == null
? item.getSmallIconDark()
: item.getIconRes(app);
if (iconRes == 0 || iconRes == -1) {
iconRes = R.drawable.ic_action_world_globe;
}
if (selectedItems.contains(item)) {
holder.aSwitch.setChecked(true);
holder.icon
.setImageDrawable(app.getUIUtilities().getIcon(iconRes, selectedIconColorRes));
} else {
holder.aSwitch.setChecked(false);
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes, R.color.icon_color));
}
holder.profileOptions.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
listener.editProfile(item);
}
});
holder.initSwitcher = true;
holder.switcher.setChecked(selectedItems.contains(item));
holder.initSwitcher = false;
updateViewHolder(holder, item);
} else {
final String title = (String) obj;
if (title.equals("manage_button"))
holder.divider.setVisibility(View.INVISIBLE);
if (title.equals(BUTTON_ITEM)) {
holder.divider.setVisibility(View.INVISIBLE);
}
holder.icon.setVisibility(View.INVISIBLE);
holder.descr.setVisibility(View.GONE);
holder.aSwitch.setVisibility(View.GONE);
holder.switcher.setVisibility(View.GONE);
holder.menuIcon.setVisibility(View.GONE);
holder.title.setTextColor(app.getResources().getColor(selectedIconColorRes));
holder.title.setText(R.string.shared_string_manage);
holder.profileOptions.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
app.startActivity(new Intent(app, SettingsProfileActivity.class));
}
});
holder.title.setText(bottomButtonText);
}
}
@ -194,6 +138,18 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
return items.size();
}
private void updateViewHolder(ProfileViewHolder holder, ApplicationMode mode) {
int iconRes = mode.getParent() == null ? mode.getSmallIconDark() : mode.getIconRes(app);
if (iconRes == 0 || iconRes == -1) {
iconRes = R.drawable.ic_action_world_globe;
}
if (selectedItems.contains(mode)) {
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes, selectedIconColorRes));
} else {
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes, R.color.icon_color));
}
}
private static boolean isNightMode(OsmandApplication ctx) {
return !ctx.getSettings().isLightContent();
}
@ -201,28 +157,65 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
class ProfileViewHolder extends RecyclerView.ViewHolder {
TextView title, descr;
SwitchCompat aSwitch;
SwitchCompat switcher;
ImageView icon, menuIcon;
LinearLayout profileOptions;
View divider;
boolean initSwitcher;
ProfileViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.title);
descr = itemView.findViewById(R.id.description);
aSwitch = itemView.findViewById(R.id.compound_button);
switcher = 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);
menuIcon = itemView.findViewById(R.id.menu_image);
profileOptions.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int pos = getAdapterPosition();
if (pos != RecyclerView.NO_POSITION && listener != null) {
Object o = items.get(pos);
if (o instanceof ApplicationMode) {
listener.onProfilePressed((ApplicationMode) o);
} else {
listener.onButtonPressed();
}
}
}
});
switcher.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int pos = getAdapterPosition();
if (pos != RecyclerView.NO_POSITION && listener != null && !initSwitcher) {
Object o = items.get(pos);
if (o instanceof ApplicationMode) {
final ApplicationMode item = (ApplicationMode) o;
if (isChecked) {
selectedItems.add(item);
} else {
selectedItems.remove(item);
}
updateViewHolder(ProfileViewHolder.this, item);
listener.onProfileSelected(item, isChecked);
}
}
}
});
}
}
public interface ProfileListener {
public interface ProfileMenuAdapterListener {
void changeProfileStatus(ApplicationMode item, boolean isSelected);
void onProfileSelected(ApplicationMode item, boolean selected);
void editProfile(ApplicationMode item);
void onProfilePressed(ApplicationMode item);
void onButtonPressed();
}
}

View file

@ -25,7 +25,7 @@ import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.profiles.ProfileMenuAdapter.ProfileListener;
import net.osmand.plus.profiles.ProfileMenuAdapter.ProfileMenuAdapterListener;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -43,7 +43,7 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
private RecyclerView recyclerView;
private LinearLayout addNewProfileBtn;
ProfileListener listener = null;
ProfileMenuAdapterListener listener = null;
SelectProfileListener typeListener = null;
private List<ApplicationMode> allAppModes;
@ -85,7 +85,7 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
}
});
adapter = new ProfileMenuAdapter(allAppModes, availableAppModes, getMyApplication(), false);
adapter = new ProfileMenuAdapter(allAppModes, availableAppModes, getMyApplication(), null);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
return view;
@ -95,19 +95,19 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
public void onResume() {
super.onResume();
if (listener == null) {
listener = new ProfileListener() {
listener = new ProfileMenuAdapterListener() {
@Override
public void changeProfileStatus(ApplicationMode am, boolean isSelected) {
if(isSelected) {
public void onProfileSelected(ApplicationMode am, boolean selected) {
if(selected) {
availableAppModes.add(am);
} else {
availableAppModes.remove(am);
}
ApplicationMode.changeProfileStatus(am, isSelected, getMyApplication());
ApplicationMode.changeProfileStatus(am, selected, getMyApplication());
}
@Override
public void editProfile(ApplicationMode item) {
public void onProfilePressed(ApplicationMode item) {
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
intent.putExtra(PROFILE_STRING_KEY, item.getStringKey());
if (!Algorithms.isEmpty(item.getUserProfileName())) {
@ -115,6 +115,10 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
}
startActivity(intent);
}
@Override
public void onButtonPressed() {
}
};
}
adapter.setListener(listener);