fix for icons color glitch

minor refactoring
This commit is contained in:
madwasp79 2019-06-06 14:25:49 +03:00
parent a5f026b79d
commit 845eb55909
3 changed files with 61 additions and 56 deletions

View file

@ -55,7 +55,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(), listener, true);
adapter = new ProfileMenuAdapter(allModes, selectedModes, getMyApplication(), true);
recyclerView = new RecyclerView(getContext());
recyclerView = (RecyclerView) View
.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.recyclerview, null);

View file

@ -34,21 +34,11 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
private static final String MANAGE_BTN = "manage_button";
public ProfileMenuAdapter(List<ApplicationMode> items, Set<ApplicationMode> selectedItems,
OsmandApplication app, ProfileListener listener) {
this.items.addAll(items);
this.listener = listener;
this.app = app;
this.selectedItems = selectedItems;
selectedIconColorRes = isNightMode(app)
? R.color.active_buttons_and_links_dark
: R.color.active_buttons_and_links_light;
}
public ProfileMenuAdapter(List<ApplicationMode> items, Set<ApplicationMode> selectedItems,
OsmandApplication app, ProfileListener listener, boolean isBottomSheet) {
OsmandApplication app, boolean isBottomSheet) {
this.items.addAll(items);
if (isBottomSheet) {
this.items.add(MANAGE_BTN);
this.listener = listener;
}
this.app = app;
this.selectedItems = selectedItems;
this.isBottomSheet = isBottomSheet;
@ -71,9 +61,9 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
}
public void updateItemsList(List<ApplicationMode> newList, Set<ApplicationMode> selectedItems) {
items.clear();
this.items.clear();
this.selectedItems.clear();
items.addAll(newList);
this.items.addAll(newList);
if (isBottomSheet) {
items.add(MANAGE_BTN);
}
@ -91,7 +81,35 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
public ProfileViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.profile_list_item, parent, false);
return new ProfileViewHolder(itemView);
final ProfileViewHolder holder = new ProfileViewHolder(itemView);
holder.itemView.findViewById(R.id.compound_button).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
Object o = items.get(holder.getAdapterPosition());
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;
}
@Override
@ -133,8 +151,6 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
iconRes = R.drawable.ic_action_world_globe;
}
final int ficon = iconRes;
if (selectedItems.contains(item)) {
holder.aSwitch.setChecked(true);
holder.icon
@ -144,19 +160,6 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes, R.color.icon_color));
}
holder.aSwitch.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
listener.changeProfileStatus(item, holder.aSwitch.isChecked());
if (selectedItems.contains(item)) {
holder.icon.setImageDrawable(app.getUIUtilities()
.getIcon(ficon, selectedIconColorRes));
} else {
holder.icon.setImageDrawable(
app.getUIUtilities().getIcon(ficon, R.color.icon_color));
}
}
});
holder.profileOptions.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

View file

@ -65,6 +65,36 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.profiles_list_fragment, container, false);
recyclerView = view.findViewById(R.id.profiles_list);
addNewProfileBtn = view.findViewById(R.id.add_profile_btn);
addNewProfileBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final SelectProfileBottomSheetDialogFragment dialog = new SelectProfileBottomSheetDialogFragment();
Bundle bundle = new Bundle();
bundle.putString(DIALOG_TYPE, TYPE_BASE_APP_PROFILE);
dialog.setArguments(bundle);
if (getActivity() != null) {
getActivity().getSupportFragmentManager().beginTransaction()
.add(dialog, "select_base_type").commitAllowingStateLoss();
}
}
});
adapter = new ProfileMenuAdapter(allAppModes, availableAppModes, getMyApplication(), false);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
return view;
}
@Override
public void onResume() {
super.onResume();
if (listener == null) {
listener = new ProfileListener() {
@Override
public void changeProfileStatus(ApplicationMode am, boolean isSelected) {
@ -86,36 +116,8 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
startActivity(intent);
}
};
View view = inflater.inflate(R.layout.profiles_list_fragment, container, false);
recyclerView = view.findViewById(R.id.profiles_list);
addNewProfileBtn = view.findViewById(R.id.add_profile_btn);
addNewProfileBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final SelectProfileBottomSheetDialogFragment dialog = new SelectProfileBottomSheetDialogFragment();
Bundle bundle = new Bundle();
bundle.putString(DIALOG_TYPE, TYPE_BASE_APP_PROFILE);
dialog.setArguments(bundle);
if (getActivity() != null) {
getActivity().getSupportFragmentManager().beginTransaction()
.add(dialog, "select_base_type").commitAllowingStateLoss();
}
}
});
adapter = new ProfileMenuAdapter(allAppModes, availableAppModes, getMyApplication(), listener);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
return view;
}
@Override
public void onResume() {
super.onResume();
adapter.setListener(listener);
getBaseProfileListener();