Merge pull request #9191 from osmandapp/fix_map_source_dialog

Fix map source dialog
This commit is contained in:
max-klaus 2020-06-11 12:14:17 +03:00 committed by GitHub
commit b974c1123f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 95 additions and 46 deletions

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -11,10 +10,9 @@
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height" android:layout_height="@dimen/toolbar_height"
android:background="?attr/actionModeBackground"
android:theme="?attr/toolbar_theme"
app:title="@string/edit_online_source" app:title="@string/edit_online_source"
osmand:titleTextColor="?android:textColorPrimary"> android:theme="?attr/toolbar_theme"
tools:background="?attr/actionModeBackground">
<ImageButton <ImageButton
android:id="@+id/toolbar_action" android:id="@+id/toolbar_action"
@ -73,10 +71,7 @@
android:layout_height="match_parent" /> android:layout_height="match_parent" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<View <include layout="@layout/divider" />
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/divider_color_basic" />
<LinearLayout <LinearLayout
android:id="@+id/content_container" android:id="@+id/content_container"
@ -88,27 +83,25 @@
</ScrollView> </ScrollView>
<View <include layout="@layout/divider" />
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/divider_color_basic" />
<FrameLayout <FrameLayout
android:id="@+id/save_button_bg"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/list_background_color"
android:minHeight="@dimen/dialog_button_ex_height" android:minHeight="@dimen/dialog_button_ex_height"
android:paddingStart="@dimen/content_padding" android:paddingStart="@dimen/content_padding"
android:paddingTop="@dimen/content_padding_small" android:paddingTop="@dimen/content_padding_small"
android:paddingEnd="@dimen/content_padding" android:paddingEnd="@dimen/content_padding"
android:paddingBottom="@dimen/content_padding_small"> android:paddingBottom="@dimen/content_padding_small"
tools:background="?attr/list_background_color">
<FrameLayout <FrameLayout
android:id="@+id/save_button" android:id="@+id/save_button"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_height" android:layout_height="@dimen/dialog_button_height"
android:layout_gravity="center" android:layout_gravity="center"
android:background="?attr/dlg_btn_primary"> tools:background="?attr/dlg_btn_primary">
<TextView <TextView
android:id="@+id/save_button_title" android:id="@+id/save_button_title"
@ -118,7 +111,7 @@
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:gravity="center" android:gravity="center"
android:text="@string/shared_string_save" android:text="@string/shared_string_save"
android:textColor="?attr/dlg_btn_primary_text" /> tools:textColor="?attr/dlg_btn_primary_text" />
</FrameLayout> </FrameLayout>

View file

@ -11,6 +11,8 @@
Thx - Hardy Thx - Hardy
--> -->
<string name="clear_tiles_warning">Applying these changes will clear the cached data for this tile source</string>
<string name="add_online_source">Add online source</string>
<!-- string name="shared_string_all_time">All time</string --> <!-- string name="shared_string_all_time">All time</string -->
<string name="shared_string_night_map">Night map</string> <string name="shared_string_night_map">Night map</string>
<string name="details_dialog_decr">Control visibility of additional details shown on the map</string> <string name="details_dialog_decr">Control visibility of additional details shown on the map</string>

View file

@ -1141,6 +1141,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
} }
}); });
} }
if (info.getType() != LocalIndexType.TILES_DATA) {
item = optionsMenu.getMenu().add(R.string.shared_string_rename) item = optionsMenu.getMenu().add(R.string.shared_string_rename)
.setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark)); .setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@ -1150,6 +1151,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
return true; return true;
} }
}); });
}
if (info.getType() == LocalIndexType.TILES_DATA if (info.getType() == LocalIndexType.TILES_DATA
&& ((info.getAttachedObject() instanceof TileSourceManager.TileSourceTemplate) && ((info.getAttachedObject() instanceof TileSourceManager.TileSourceTemplate)
|| ((info.getAttachedObject() instanceof SQLiteTileSource) || ((info.getAttachedObject() instanceof SQLiteTileSource)

View file

@ -120,8 +120,11 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
elliptic = savedInstanceState.getBoolean(ELLIPTIC_KEY); elliptic = savedInstanceState.getBoolean(ELLIPTIC_KEY);
sqliteDB = savedInstanceState.getBoolean(SQLITE_DB_KEY); sqliteDB = savedInstanceState.getBoolean(SQLITE_DB_KEY);
} }
View root = UiUtilities.getMaterialInflater(app, nightMode).inflate(R.layout.fragment_edit_map_source, container, false); View root = UiUtilities.getMaterialInflater(requireContext(), nightMode).inflate(R.layout.fragment_edit_map_source, container, false);
Toolbar toolbar = root.findViewById(R.id.toolbar); Toolbar toolbar = root.findViewById(R.id.toolbar);
toolbar.setBackgroundColor(ContextCompat.getColor(app, nightMode ? R.color.app_bar_color_dark : R.color.app_bar_color_light));
toolbar.setTitleTextColor(ContextCompat.getColor(app, nightMode ? R.color.active_buttons_and_links_text_dark : R.color.active_buttons_and_links_text_light));
toolbar.setTitle(editedLayerName == null ? R.string.add_online_source : R.string.edit_online_source);
ImageButton iconHelp = root.findViewById(R.id.toolbar_action); ImageButton iconHelp = root.findViewById(R.id.toolbar_action);
Drawable closeDrawable = app.getUIUtilities().getIcon(AndroidUtils.getNavigationIconResId(app), Drawable closeDrawable = app.getUIUtilities().getIcon(AndroidUtils.getNavigationIconResId(app),
nightMode ? R.color.active_buttons_and_links_text_dark : R.color.active_buttons_and_links_text_light); nightMode ? R.color.active_buttons_and_links_text_dark : R.color.active_buttons_and_links_text_light);
@ -145,6 +148,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
int boxStrokeColor = nightMode int boxStrokeColor = nightMode
? ContextCompat.getColor(app, R.color.app_bar_color_light) ? ContextCompat.getColor(app, R.color.app_bar_color_light)
: ContextCompat.getColor(app, R.color.active_buttons_and_links_bg_pressed_dark); : ContextCompat.getColor(app, R.color.active_buttons_and_links_bg_pressed_dark);
int btnBgColorRes = nightMode ? R.color.list_background_color_dark : R.color.list_background_color_light;
TextInputLayout nameInputLayout = root.findViewById(R.id.name_input_layout); TextInputLayout nameInputLayout = root.findViewById(R.id.name_input_layout);
nameInputLayout.setBoxStrokeColor(boxStrokeColor); nameInputLayout.setBoxStrokeColor(boxStrokeColor);
nameEditText = root.findViewById(R.id.name_edit_text); nameEditText = root.findViewById(R.id.name_edit_text);
@ -155,7 +159,12 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
urlEditText.addTextChangedListener(getTextWatcher()); urlEditText.addTextChangedListener(getTextWatcher());
contentContainer = root.findViewById(R.id.content_container); contentContainer = root.findViewById(R.id.content_container);
saveBtn = root.findViewById(R.id.save_button); saveBtn = root.findViewById(R.id.save_button);
saveBtn.setBackgroundResource(nightMode ? R.drawable.dlg_btn_primary_dark : R.drawable.dlg_btn_primary_light);
FrameLayout saveBtnBg = root.findViewById(R.id.save_button_bg);
saveBtnBg.setBackgroundColor(ContextCompat.getColor(app, btnBgColorRes));
saveBtnTitle = root.findViewById(R.id.save_button_title); saveBtnTitle = root.findViewById(R.id.save_button_title);
saveBtnTitle.setTextColor(ContextCompat.getColorStateList(app,
nightMode ? R.color.dlg_btn_primary_text_dark : R.color.dlg_btn_primary_text_light));
saveBtn.setOnClickListener(new View.OnClickListener() { saveBtn.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -270,8 +279,15 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
@Override @Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
String s = charSequence.toString();
if (Algorithms.isEmpty(s)) { }
@Override
public void afterTextChanged(Editable editable) {
if (nameEditText.getText() != null && urlEditText.getText() != null) {
String name = nameEditText.getText().toString().trim();
String url = urlEditText.getText().toString().trim();
if (Algorithms.isEmpty(name) || Algorithms.isEmpty(url)) {
saveBtn.setEnabled(false); saveBtn.setEnabled(false);
saveBtnTitle.setEnabled(false); saveBtnTitle.setEnabled(false);
} else { } else {
@ -279,10 +295,6 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
saveBtnTitle.setEnabled(true); saveBtnTitle.setEnabled(true);
} }
} }
@Override
public void afterTextChanged(Editable editable) {
} }
}; };
} }
@ -396,7 +408,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
InputZoomLevelsBottomSheet.showInstance( InputZoomLevelsBottomSheet.showInstance(
fm, EditMapSourceDialogFragment.this, fm, EditMapSourceDialogFragment.this,
R.string.map_source_zoom_levels, R.string.map_source_zoom_levels_descr, R.string.map_source_zoom_levels, R.string.map_source_zoom_levels_descr,
minZoom, maxZoom minZoom, maxZoom, editedLayerName == null
); );
break; break;
case EXPIRE_TIME: case EXPIRE_TIME:

View file

@ -1,5 +1,7 @@
package net.osmand.plus.mapsource; package net.osmand.plus.mapsource;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
@ -10,6 +12,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
@ -38,6 +41,7 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment {
private static final String MAX_ZOOM_KEY = "max_zoom_key"; private static final String MAX_ZOOM_KEY = "max_zoom_key";
private static final String SLIDER_DESCR_RES_KEY = "slider_descr_key"; private static final String SLIDER_DESCR_RES_KEY = "slider_descr_key";
private static final String DIALOG_DESCR_RES_KEY = "dialog_descr_key"; private static final String DIALOG_DESCR_RES_KEY = "dialog_descr_key";
private static final String NEW_MAP_SOURCE = "new_map_source";
private static final int SLIDER_FROM = 1; private static final int SLIDER_FROM = 1;
private static final int SLIDER_TO = 22; private static final int SLIDER_TO = 22;
@StringRes @StringRes
@ -46,19 +50,22 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment {
private int dialogDescrRes; private int dialogDescrRes;
private int minZoom; private int minZoom;
private int maxZoom; private int maxZoom;
private boolean newMapSource;
public static void showInstance(@NonNull FragmentManager fm, public static void showInstance(@NonNull FragmentManager fm,
@Nullable Fragment targetFragment, @Nullable Fragment targetFragment,
int sliderDescr, int sliderDescr,
int dialogDescr, int dialogDescr,
int minZoom, int minZoom,
int maxZoom) { int maxZoom,
boolean newMapSource) {
InputZoomLevelsBottomSheet bottomSheet = new InputZoomLevelsBottomSheet(); InputZoomLevelsBottomSheet bottomSheet = new InputZoomLevelsBottomSheet();
bottomSheet.setTargetFragment(targetFragment, 0); bottomSheet.setTargetFragment(targetFragment, 0);
bottomSheet.setSliderDescrRes(sliderDescr); bottomSheet.setSliderDescrRes(sliderDescr);
bottomSheet.setDialogDescrRes(dialogDescr); bottomSheet.setDialogDescrRes(dialogDescr);
bottomSheet.setMinZoom(Math.max(minZoom, SLIDER_FROM)); bottomSheet.setMinZoom(Math.max(minZoom, SLIDER_FROM));
bottomSheet.setMaxZoom(Math.min(maxZoom, SLIDER_TO)); bottomSheet.setMaxZoom(Math.min(maxZoom, SLIDER_TO));
bottomSheet.setNewMapSource(newMapSource);
bottomSheet.show(fm, TAG); bottomSheet.show(fm, TAG);
} }
@ -70,8 +77,9 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment {
maxZoom = savedInstanceState.getInt(MAX_ZOOM_KEY); maxZoom = savedInstanceState.getInt(MAX_ZOOM_KEY);
dialogDescrRes = savedInstanceState.getInt(DIALOG_DESCR_RES_KEY); dialogDescrRes = savedInstanceState.getInt(DIALOG_DESCR_RES_KEY);
sliderDescrRes = savedInstanceState.getInt(SLIDER_DESCR_RES_KEY); sliderDescrRes = savedInstanceState.getInt(SLIDER_DESCR_RES_KEY);
newMapSource = savedInstanceState.getBoolean(NEW_MAP_SOURCE);
} }
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode); LayoutInflater inflater = UiUtilities.getMaterialInflater(app, nightMode);
TitleItem titleItem = new TitleItem(getString(R.string.shared_string_zoom_levels)); TitleItem titleItem = new TitleItem(getString(R.string.shared_string_zoom_levels));
items.add(titleItem); items.add(titleItem);
final View sliderView = inflater.inflate(R.layout.zoom_levels_with_descr, null); final View sliderView = inflater.inflate(R.layout.zoom_levels_with_descr, null);
@ -133,16 +141,17 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment {
outState.putInt(MAX_ZOOM_KEY, maxZoom); outState.putInt(MAX_ZOOM_KEY, maxZoom);
outState.putInt(SLIDER_DESCR_RES_KEY, sliderDescrRes); outState.putInt(SLIDER_DESCR_RES_KEY, sliderDescrRes);
outState.putInt(DIALOG_DESCR_RES_KEY, dialogDescrRes); outState.putInt(DIALOG_DESCR_RES_KEY, dialogDescrRes);
outState.putBoolean(NEW_MAP_SOURCE, newMapSource);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
@Override @Override
protected void onRightBottomButtonClick() { protected void onRightBottomButtonClick() {
Fragment fragment = getTargetFragment(); if (!newMapSource) {
if (fragment instanceof OnZoomSetListener) { showClearTilesWarningDialog();
((OnZoomSetListener) fragment).onZoomSet(minZoom, maxZoom); } else {
applySelectedZooms();
} }
dismiss();
} }
@Override @Override
@ -155,6 +164,29 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment {
return R.string.shared_string_apply; return R.string.shared_string_apply;
} }
private void showClearTilesWarningDialog() {
Context themedContext = UiUtilities.getThemedContext(getActivity(), nightMode);
AlertDialog.Builder dismissDialog = new AlertDialog.Builder(themedContext);
dismissDialog.setTitle(getString(R.string.osmand_parking_warning));
dismissDialog.setMessage(getString(R.string.clear_tiles_warning));
dismissDialog.setNegativeButton(R.string.shared_string_cancel, null);
dismissDialog.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
applySelectedZooms();
}
});
dismissDialog.show();
}
private void applySelectedZooms() {
Fragment fragment = getTargetFragment();
if (fragment instanceof OnZoomSetListener) {
((OnZoomSetListener) fragment).onZoomSet(minZoom, maxZoom);
}
dismiss();
}
private SpannableString createSpannableString(@NonNull String text, @NonNull String... textToStyle) { private SpannableString createSpannableString(@NonNull String text, @NonNull String... textToStyle) {
SpannableString spannable = new SpannableString(text); SpannableString spannable = new SpannableString(text);
for (String t : textToStyle) { for (String t : textToStyle) {
@ -188,6 +220,10 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment {
this.maxZoom = maxZoom; this.maxZoom = maxZoom;
} }
public void setNewMapSource(boolean newMapSource) {
this.newMapSource = newMapSource;
}
public interface OnZoomSetListener { public interface OnZoomSetListener {
void onZoomSet(int min, int max); void onZoomSet(int min, int max);
} }

View file

@ -90,8 +90,10 @@ public class MercatorProjectionBottomSheet extends MenuBottomSheetDialogFragment
view.setOnClickListener(new View.OnClickListener() { view.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (mercatorProjection != m){
mercatorProjection = m; mercatorProjection = m;
populateValuesList(); dismiss();
}
} }
}); });
} }

View file

@ -90,8 +90,10 @@ public class TileStorageFormatBottomSheet extends MenuBottomSheetDialogFragment
view.setOnClickListener(new View.OnClickListener() { view.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (tileStorageFormat != m) {
tileStorageFormat = m; tileStorageFormat = m;
populateValuesList(); dismiss();
}
} }
}); });
} }