warning dialog on zooms change for used source

This commit is contained in:
veliymolfar 2020-06-09 16:51:56 +03:00
parent 690ddb52e7
commit 765aafb4e7
3 changed files with 43 additions and 6 deletions

View file

@ -11,6 +11,7 @@
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_night_map">Night map</string>

View file

@ -408,7 +408,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
InputZoomLevelsBottomSheet.showInstance(
fm, EditMapSourceDialogFragment.this,
R.string.map_source_zoom_levels, R.string.map_source_zoom_levels_descr,
minZoom, maxZoom
minZoom, maxZoom, editedLayerName != null
);
break;
case EXPIRE_TIME:

View file

@ -1,5 +1,7 @@
package net.osmand.plus.mapsource;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
@ -10,6 +12,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
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 SLIDER_DESCR_RES_KEY = "slider_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_TO = 22;
@StringRes
@ -46,19 +50,22 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment {
private int dialogDescrRes;
private int minZoom;
private int maxZoom;
private boolean showWarning;
public static void showInstance(@NonNull FragmentManager fm,
@Nullable Fragment targetFragment,
int sliderDescr,
int dialogDescr,
int minZoom,
int maxZoom) {
int maxZoom,
boolean showWarning) {
InputZoomLevelsBottomSheet bottomSheet = new InputZoomLevelsBottomSheet();
bottomSheet.setTargetFragment(targetFragment, 0);
bottomSheet.setSliderDescrRes(sliderDescr);
bottomSheet.setDialogDescrRes(dialogDescr);
bottomSheet.setMinZoom(Math.max(minZoom, SLIDER_FROM));
bottomSheet.setMaxZoom(Math.min(maxZoom, SLIDER_TO));
bottomSheet.setShowWarning(showWarning);
bottomSheet.show(fm, TAG);
}
@ -70,6 +77,7 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment {
maxZoom = savedInstanceState.getInt(MAX_ZOOM_KEY);
dialogDescrRes = savedInstanceState.getInt(DIALOG_DESCR_RES_KEY);
sliderDescrRes = savedInstanceState.getInt(SLIDER_DESCR_RES_KEY);
showWarning = savedInstanceState.getBoolean(SHOW_WARNING_KEY);
}
LayoutInflater inflater = UiUtilities.getMaterialInflater(app, nightMode);
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(SLIDER_DESCR_RES_KEY, sliderDescrRes);
outState.putInt(DIALOG_DESCR_RES_KEY, dialogDescrRes);
outState.putBoolean(SHOW_WARNING_KEY, showWarning);
super.onSaveInstanceState(outState);
}
@Override
protected void onRightBottomButtonClick() {
Fragment fragment = getTargetFragment();
if (fragment instanceof OnZoomSetListener) {
((OnZoomSetListener) fragment).onZoomSet(minZoom, maxZoom);
if (showWarning) {
showWarningDialog();
} else {
applySelectedZooms();
}
dismiss();
}
@Override
@ -155,6 +164,29 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment {
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) {
SpannableString spannable = new SpannableString(text);
for (String t : textToStyle) {
@ -188,6 +220,10 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment {
this.maxZoom = maxZoom;
}
public void setShowWarning(boolean showWarning) {
this.showWarning = showWarning;
}
public interface OnZoomSetListener {
void onZoomSet(int min, int max);
}