Fix switchable quick actions theme change

This commit is contained in:
Chumva 2019-11-04 16:41:39 +02:00
parent 3f015259f9
commit 0944be75a7
6 changed files with 40 additions and 24 deletions

View file

@ -53,7 +53,7 @@ public class AddQuickActionDialog extends DialogFragment {
.getQuickActionRegistry()
.getQuickActions();
View root = inflater.inflate(R.layout.quick_action_add_dialog, container, false);
View root = UiUtilities.getInflater(getActivity(), !isLightContent).inflate(R.layout.quick_action_add_dialog, container, false);
Adapter adapter = new Adapter(QuickActionFactory.produceTypeActionsListWithHeaders(active));
TextView tvTitle = root.findViewById(R.id.tvTitle);

View file

@ -12,10 +12,12 @@ import android.widget.Toast;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.SwitchableAction;
@ -172,11 +174,12 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
return new View.OnClickListener() {
@Override
public void onClick(View view) {
final OsmandSettings settings = activity.getMyApplication().getSettings();
Map<String, String> entriesMap = settings.getTileSourceEntries();
OsmandApplication app = activity.getMyApplication();
Map<String, String> entriesMap = app.getSettings().getTileSourceEntries();
entriesMap.put(KEY_NO_OVERLAY, activity.getString(R.string.no_overlay));
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
Context themedContext = UiUtilities.getThemedContext(activity, nightMode);
AlertDialog.Builder builder = new AlertDialog.Builder(themedContext);
final ArrayList<String> keys = new ArrayList<>(entriesMap.keySet());
final String[] items = new String[entriesMap.size()];
int i = 0;
@ -185,7 +188,7 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
items[i++] = it;
}
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity, R.layout.dialog_text_item);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(themedContext, R.layout.dialog_text_item);
arrayAdapter.addAll(items);
builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override

View file

@ -12,9 +12,11 @@ import android.widget.Toast;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.SwitchableAction;
@ -148,16 +150,18 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
return new View.OnClickListener() {
@Override
public void onClick(View view) {
OsmandApplication app = activity.getMyApplication();
final OsmandSettings settings = activity.getMyApplication().getSettings();
final LinkedHashMap<String, String> entriesMap = new LinkedHashMap<>();
entriesMap.put(LAYER_OSM_VECTOR, activity.getString(R.string.vector_data));
entriesMap.putAll(settings.getTileSourceEntries());
entriesMap.putAll(app.getSettings().getTileSourceEntries());
final List<Map.Entry<String, String>> entriesMapList = new ArrayList<>(entriesMap.entrySet());
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
Context themedContext = UiUtilities.getThemedContext(activity, nightMode);
AlertDialog.Builder builder = new AlertDialog.Builder(themedContext);
final String[] items = new String[entriesMapList.size()];
int i = 0;
@ -166,7 +170,7 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
items[i++] = entry.getValue();
}
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity, R.layout.dialog_text_item);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(themedContext, R.layout.dialog_text_item);
arrayAdapter.addAll(items);
builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {

View file

@ -12,6 +12,7 @@ import android.widget.Toast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
@ -20,12 +21,12 @@ import net.osmand.plus.quickaction.SwitchableAction;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.render.RenderingRulesStorage;
import net.osmand.util.Algorithms;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import net.osmand.util.Algorithms;
public class MapStyleAction extends SwitchableAction<String> {
@ -134,11 +135,13 @@ public class MapStyleAction extends SwitchableAction<String> {
return new View.OnClickListener() {
@Override
public void onClick(View view) {
final OsmandApplication app = activity.getMyApplication();
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
Context themedContext = UiUtilities.getThemedContext(activity, nightMode);
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
AlertDialog.Builder bld = new AlertDialog.Builder(themedContext);
bld.setTitle(R.string.renderers);
final OsmandApplication app = activity.getMyApplication();
final List<String> visibleNamesList = new ArrayList<>();
final ArrayList<String> items = new ArrayList<>(app.getRendererRegistry().getRendererNames());
final boolean nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
@ -155,7 +158,7 @@ public class MapStyleAction extends SwitchableAction<String> {
}
}
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity, R.layout.dialog_text_item);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(themedContext, R.layout.dialog_text_item);
arrayAdapter.addAll(visibleNamesList);
bld.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {

View file

@ -12,10 +12,12 @@ import android.widget.Toast;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.SwitchableAction;
@ -176,11 +178,15 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
return new View.OnClickListener() {
@Override
public void onClick(View view) {
OsmandApplication app = activity.getMyApplication();
final OsmandSettings settings = activity.getMyApplication().getSettings();
Map<String, String> entriesMap = settings.getTileSourceEntries();
Map<String, String> entriesMap = app.getSettings().getTileSourceEntries();
entriesMap.put(KEY_NO_UNDERLAY, activity.getString(R.string.no_underlay));
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
Context themedContext = UiUtilities.getThemedContext(activity, nightMode);
AlertDialog.Builder builder = new AlertDialog.Builder(themedContext);
final ArrayList<String> keys = new ArrayList<>(entriesMap.keySet());
final String[] items = new String[entriesMap.size()];
int i = 0;
@ -189,7 +195,7 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
items[i++] = it;
}
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity, R.layout.dialog_text_item);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(themedContext, R.layout.dialog_text_item);
arrayAdapter.addAll(items);
builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override

View file

@ -19,6 +19,7 @@ import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiUIFilter;
@ -135,9 +136,8 @@ public class ShowHidePoiAction extends QuickAction {
@Override
public void drawUI(ViewGroup parent, final MapActivity activity) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.quick_action_show_hide_poi, parent, false);
boolean nightMode = activity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
View view = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.quick_action_show_hide_poi, parent, false);
RecyclerView list = (RecyclerView) view.findViewById(R.id.list);
Button addFilter = (Button) view.findViewById(R.id.btnAddCategory);
@ -288,9 +288,9 @@ public class ShowHidePoiAction extends QuickAction {
addFilterToList(adapter, list, f);
}
final ArrayAdapter<ContextMenuItem> listAdapter =
adapter.createListAdapter(activity, app.getSettings().isLightContent());
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
boolean nightMode = activity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
final ArrayAdapter<ContextMenuItem> listAdapter = adapter.createListAdapter(activity, !nightMode);
AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(activity, nightMode));
builder.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {