Merge pull request #9191 from osmandapp/fix_map_source_dialog
Fix map source dialog
This commit is contained in:
commit
b974c1123f
7 changed files with 95 additions and 46 deletions
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -11,10 +10,9 @@
|
|||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/toolbar_height"
|
||||
android:background="?attr/actionModeBackground"
|
||||
android:theme="?attr/toolbar_theme"
|
||||
app:title="@string/edit_online_source"
|
||||
osmand:titleTextColor="?android:textColorPrimary">
|
||||
android:theme="?attr/toolbar_theme"
|
||||
tools:background="?attr/actionModeBackground">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/toolbar_action"
|
||||
|
@ -73,10 +71,7 @@
|
|||
android:layout_height="match_parent" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/divider_color_basic" />
|
||||
<include layout="@layout/divider" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/content_container"
|
||||
|
@ -88,27 +83,25 @@
|
|||
|
||||
</ScrollView>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/divider_color_basic" />
|
||||
<include layout="@layout/divider" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/save_button_bg"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/list_background_color"
|
||||
android:minHeight="@dimen/dialog_button_ex_height"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:paddingTop="@dimen/content_padding_small"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingBottom="@dimen/content_padding_small">
|
||||
android:paddingBottom="@dimen/content_padding_small"
|
||||
tools:background="?attr/list_background_color">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/save_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dialog_button_height"
|
||||
android:layout_gravity="center"
|
||||
android:background="?attr/dlg_btn_primary">
|
||||
tools:background="?attr/dlg_btn_primary">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/save_button_title"
|
||||
|
@ -118,7 +111,7 @@
|
|||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:text="@string/shared_string_save"
|
||||
android:textColor="?attr/dlg_btn_primary_text" />
|
||||
tools:textColor="?attr/dlg_btn_primary_text" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
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>
|
||||
<string name="details_dialog_decr">Control visibility of additional details shown on the map</string>
|
||||
|
|
|
@ -1141,15 +1141,17 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
}
|
||||
});
|
||||
}
|
||||
item = optionsMenu.getMenu().add(R.string.shared_string_rename)
|
||||
.setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
performBasicOperation(R.string.shared_string_rename, info);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (info.getType() != LocalIndexType.TILES_DATA) {
|
||||
item = optionsMenu.getMenu().add(R.string.shared_string_rename)
|
||||
.setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
performBasicOperation(R.string.shared_string_rename, info);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (info.getType() == LocalIndexType.TILES_DATA
|
||||
&& ((info.getAttachedObject() instanceof TileSourceManager.TileSourceTemplate)
|
||||
|| ((info.getAttachedObject() instanceof SQLiteTileSource)
|
||||
|
|
|
@ -120,8 +120,11 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
|
|||
elliptic = savedInstanceState.getBoolean(ELLIPTIC_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.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);
|
||||
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);
|
||||
|
@ -145,6 +148,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
|
|||
int boxStrokeColor = nightMode
|
||||
? ContextCompat.getColor(app, R.color.app_bar_color_light)
|
||||
: 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);
|
||||
nameInputLayout.setBoxStrokeColor(boxStrokeColor);
|
||||
nameEditText = root.findViewById(R.id.name_edit_text);
|
||||
|
@ -155,7 +159,12 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
|
|||
urlEditText.addTextChangedListener(getTextWatcher());
|
||||
contentContainer = root.findViewById(R.id.content_container);
|
||||
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.setTextColor(ContextCompat.getColorStateList(app,
|
||||
nightMode ? R.color.dlg_btn_primary_text_dark : R.color.dlg_btn_primary_text_light));
|
||||
saveBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -270,19 +279,22 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
|
|||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
String s = charSequence.toString();
|
||||
if (Algorithms.isEmpty(s)) {
|
||||
saveBtn.setEnabled(false);
|
||||
saveBtnTitle.setEnabled(false);
|
||||
} else {
|
||||
saveBtn.setEnabled(true);
|
||||
saveBtnTitle.setEnabled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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);
|
||||
saveBtnTitle.setEnabled(false);
|
||||
} else {
|
||||
saveBtn.setEnabled(true);
|
||||
saveBtnTitle.setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -396,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:
|
||||
|
|
|
@ -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 NEW_MAP_SOURCE = "new_map_source";
|
||||
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 newMapSource;
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fm,
|
||||
@Nullable Fragment targetFragment,
|
||||
int sliderDescr,
|
||||
int dialogDescr,
|
||||
int minZoom,
|
||||
int maxZoom) {
|
||||
int maxZoom,
|
||||
boolean newMapSource) {
|
||||
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.setNewMapSource(newMapSource);
|
||||
bottomSheet.show(fm, TAG);
|
||||
}
|
||||
|
||||
|
@ -70,8 +77,9 @@ 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);
|
||||
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));
|
||||
items.add(titleItem);
|
||||
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(SLIDER_DESCR_RES_KEY, sliderDescrRes);
|
||||
outState.putInt(DIALOG_DESCR_RES_KEY, dialogDescrRes);
|
||||
outState.putBoolean(NEW_MAP_SOURCE, newMapSource);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRightBottomButtonClick() {
|
||||
Fragment fragment = getTargetFragment();
|
||||
if (fragment instanceof OnZoomSetListener) {
|
||||
((OnZoomSetListener) fragment).onZoomSet(minZoom, maxZoom);
|
||||
if (!newMapSource) {
|
||||
showClearTilesWarningDialog();
|
||||
} else {
|
||||
applySelectedZooms();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -155,6 +164,29 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
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) {
|
||||
SpannableString spannable = new SpannableString(text);
|
||||
for (String t : textToStyle) {
|
||||
|
@ -188,6 +220,10 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
this.maxZoom = maxZoom;
|
||||
}
|
||||
|
||||
public void setNewMapSource(boolean newMapSource) {
|
||||
this.newMapSource = newMapSource;
|
||||
}
|
||||
|
||||
public interface OnZoomSetListener {
|
||||
void onZoomSet(int min, int max);
|
||||
}
|
||||
|
|
|
@ -90,8 +90,10 @@ public class MercatorProjectionBottomSheet extends MenuBottomSheetDialogFragment
|
|||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mercatorProjection = m;
|
||||
populateValuesList();
|
||||
if (mercatorProjection != m){
|
||||
mercatorProjection = m;
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -90,8 +90,10 @@ public class TileStorageFormatBottomSheet extends MenuBottomSheetDialogFragment
|
|||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
tileStorageFormat = m;
|
||||
populateValuesList();
|
||||
if (tileStorageFormat != m) {
|
||||
tileStorageFormat = m;
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue