Move colors selection from code to layout

Delete unnecessary colors choosing code
This commit is contained in:
Nazar 2019-08-28 11:36:02 +03:00
parent cdc8331ca5
commit d1c500d29d
4 changed files with 14 additions and 42 deletions

View file

@ -51,7 +51,7 @@
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:textSize="@dimen/default_desc_text_size" android:textSize="@dimen/default_desc_text_size"
android:textColor="@color/description_font_and_bottom_sheet_icons" android:textColor="?android:textColorSecondary"
tools:text="Type: Bicycle" /> tools:text="Type: Bicycle" />
</LinearLayout> </LinearLayout>

View file

@ -104,7 +104,7 @@ public class AppModesBottomSheetDialogFragment extends MenuBottomSheetDialogFrag
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
adapter = new ProfileMenuAdapter(allModes, selectedModes, getMyApplication(), getString(R.string.shared_string_manage), true); adapter = new ProfileMenuAdapter(allModes, selectedModes, getMyApplication(), getString(R.string.shared_string_manage), nightMode);
recyclerView = new RecyclerView(getContext()); recyclerView = new RecyclerView(getContext());
recyclerView = (RecyclerView) View recyclerView = (RecyclerView) View
.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.recyclerview, null); .inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.recyclerview, null);

View file

@ -3,9 +3,9 @@ package net.osmand.plus.profiles;
import android.support.annotation.ColorRes; import android.support.annotation.ColorRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.view.ContextThemeWrapper;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -41,25 +41,20 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
private String bottomButtonText; private String bottomButtonText;
private static final String BUTTON_ITEM = "button_item"; private static final String BUTTON_ITEM = "button_item";
private boolean usedOnMap; private boolean nightMode;
public ProfileMenuAdapter(List<ApplicationMode> items, Set<ApplicationMode> selectedItems, public ProfileMenuAdapter(List<ApplicationMode> items, Set<ApplicationMode> selectedItems,
OsmandApplication app, String bottomButtonText) { OsmandApplication app, String bottomButtonText, boolean nightMode) {
this(items, selectedItems, app, bottomButtonText, false);
}
public ProfileMenuAdapter(List<ApplicationMode> items, Set<ApplicationMode> selectedItems,
OsmandApplication app, String bottomButtonText, boolean usedOnMap) {
this.items.addAll(items); this.items.addAll(items);
if (bottomButton) { if (bottomButton) {
this.items.add(BUTTON_ITEM); this.items.add(BUTTON_ITEM);
} }
this.usedOnMap = usedOnMap;
this.app = app; this.app = app;
this.selectedItems = selectedItems; this.selectedItems = selectedItems;
this.bottomButton = !Algorithms.isEmpty(bottomButtonText); this.bottomButton = !Algorithms.isEmpty(bottomButtonText);
this.bottomButtonText = bottomButtonText; this.bottomButtonText = bottomButtonText;
selectedIconColorRes = isNightMode(app, usedOnMap) this.nightMode = nightMode;
selectedIconColorRes = nightMode
? R.color.active_color_primary_dark ? R.color.active_color_primary_dark
: R.color.active_color_primary_light; : R.color.active_color_primary_light;
} }
@ -88,19 +83,12 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
return super.getItemViewType(position); return super.getItemViewType(position);
} }
public boolean isUsedOnMap() {
return usedOnMap;
}
public void setUsedOnMap(boolean usedOnMap) {
this.usedOnMap = usedOnMap;
}
@NonNull @NonNull
@Override @Override
public ProfileViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { public ProfileViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = int themeResId = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
LayoutInflater.from(parent.getContext()).inflate(R.layout.profile_list_item, parent, false); View itemView =
View.inflate(new ContextThemeWrapper(parent.getContext(), themeResId), R.layout.profile_list_item, null);
return new ProfileViewHolder(itemView); return new ProfileViewHolder(itemView);
} }
@ -114,11 +102,6 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
holder.switcher.setVisibility(View.VISIBLE); holder.switcher.setVisibility(View.VISIBLE);
holder.menuIcon.setVisibility(View.VISIBLE); holder.menuIcon.setVisibility(View.VISIBLE);
final ApplicationMode item = (ApplicationMode) obj; final ApplicationMode item = (ApplicationMode) obj;
if (bottomButton) {
holder.divider.setBackgroundColor(isNightMode(app, usedOnMap)
? app.getResources().getColor(R.color.divider_color_dark)
: app.getResources().getColor(R.color.divider_color_light));
}
holder.title.setText(item.toHumanString(app)); holder.title.setText(item.toHumanString(app));
if (item.isCustomProfile()) { if (item.isCustomProfile()) {
holder.descr.setText(String.format(app.getString(R.string.profile_type_descr_string), holder.descr.setText(String.format(app.getString(R.string.profile_type_descr_string),
@ -127,10 +110,6 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
holder.descr.setText(R.string.profile_type_base_string); holder.descr.setText(R.string.profile_type_base_string);
} }
holder.title.setTextColor(app.getResources().getColor(isNightMode(app, usedOnMap)
? R.color.text_color_primary_dark
: R.color.text_color_primary_light));
holder.initSwitcher = true; holder.initSwitcher = true;
holder.switcher.setChecked(selectedItems.contains(item)); holder.switcher.setChecked(selectedItems.contains(item));
holder.initSwitcher = false; holder.initSwitcher = false;
@ -145,7 +124,7 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
holder.switcher.setVisibility(View.GONE); holder.switcher.setVisibility(View.GONE);
holder.menuIcon.setVisibility(View.GONE); holder.menuIcon.setVisibility(View.GONE);
holder.title.setTextColor(app.getResources().getColor( holder.title.setTextColor(app.getResources().getColor(
isNightMode(app, usedOnMap) nightMode
? R.color.active_color_primary_dark ? R.color.active_color_primary_dark
: R.color.active_color_primary_light)); : R.color.active_color_primary_light));
holder.title.setText(bottomButtonText); holder.title.setText(bottomButtonText);
@ -162,21 +141,14 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
if (iconRes == 0 || iconRes == -1) { if (iconRes == 0 || iconRes == -1) {
iconRes = R.drawable.ic_action_world_globe; iconRes = R.drawable.ic_action_world_globe;
} }
selectedIconColorRes = mode.getIconColorInfo().getColor(isNightMode(app, usedOnMap)); selectedIconColorRes = mode.getIconColorInfo().getColor(nightMode);
if (selectedItems.contains(mode)) { if (selectedItems.contains(mode)) {
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes, mode.getIconColorInfo().getColor(isNightMode(app, usedOnMap)))); holder.icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes, selectedIconColorRes));
} else { } else {
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes, R.color.profile_icon_color_inactive)); holder.icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes, R.color.profile_icon_color_inactive));
} }
} }
private static boolean isNightMode(OsmandApplication ctx, boolean useMapTheme) {
if (useMapTheme) {
return ctx.getDaynightHelper().isNightModeForMapControls();
}
return !ctx.getSettings().isLightContent();
}
class ProfileViewHolder extends RecyclerView.ViewHolder { class ProfileViewHolder extends RecyclerView.ViewHolder {
TextView title, descr; TextView title, descr;

View file

@ -85,7 +85,7 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
} }
}); });
adapter = new ProfileMenuAdapter(allAppModes, availableAppModes, getMyApplication(), null); adapter = new ProfileMenuAdapter(allAppModes, availableAppModes, getMyApplication(), null, !getMyApplication().getSettings().isLightContent());
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
return view; return view;