warning dialog on zooms change for used source
This commit is contained in:
parent
690ddb52e7
commit
765aafb4e7
3 changed files with 43 additions and 6 deletions
|
@ -11,6 +11,7 @@
|
||||||
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="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>
|
||||||
|
|
|
@ -408,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:
|
||||||
|
|
|
@ -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 SHOW_WARNING_KEY = "show_warning_key";
|
||||||
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 showWarning;
|
||||||
|
|
||||||
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 showWarning) {
|
||||||
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.setShowWarning(showWarning);
|
||||||
bottomSheet.show(fm, TAG);
|
bottomSheet.show(fm, TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +77,7 @@ 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);
|
||||||
|
showWarning = savedInstanceState.getBoolean(SHOW_WARNING_KEY);
|
||||||
}
|
}
|
||||||
LayoutInflater inflater = UiUtilities.getMaterialInflater(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));
|
||||||
|
@ -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(SHOW_WARNING_KEY, showWarning);
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onRightBottomButtonClick() {
|
protected void onRightBottomButtonClick() {
|
||||||
Fragment fragment = getTargetFragment();
|
if (showWarning) {
|
||||||
if (fragment instanceof OnZoomSetListener) {
|
showWarningDialog();
|
||||||
((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 showWarningDialog() {
|
||||||
|
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 setShowWarning(boolean showWarning) {
|
||||||
|
this.showWarning = showWarning;
|
||||||
|
}
|
||||||
|
|
||||||
public interface OnZoomSetListener {
|
public interface OnZoomSetListener {
|
||||||
void onZoomSet(int min, int max);
|
void onZoomSet(int min, int max);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue