Merge pull request #11001 from osmandapp/master

update test branch
This commit is contained in:
Hardy 2021-02-24 20:42:51 +01:00 committed by GitHub
commit a3355cefd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 163 additions and 102 deletions

View file

@ -279,6 +279,19 @@ public class Amenity extends MapObject {
}
public String getTagContent(String tag, String lang) {
String translateName = getStrictTagContent(tag, lang);
if (translateName != null) {
return translateName;
}
for (String nm : getAdditionalInfoKeys()) {
if (nm.startsWith(tag + ":")) {
return getAdditionalInfo(nm);
}
}
return null;
}
public String getStrictTagContent(String tag, String lang) {
if (lang != null) {
String translateName = getAdditionalInfo(tag + ":" + lang);
if (!Algorithms.isEmpty(translateName)) {
@ -293,11 +306,6 @@ public class Amenity extends MapObject {
if (!Algorithms.isEmpty(enName)) {
return enName;
}
for (String nm : getAdditionalInfoKeys()) {
if (nm.startsWith(tag + ":")) {
return getAdditionalInfo(nm);
}
}
return null;
}

View file

@ -24,6 +24,7 @@
android:id="@+id/name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapSentences"
android:lineSpacingMultiplier="@dimen/bottom_sheet_text_spacing_multiplier" />
</com.google.android.material.textfield.TextInputLayout>

View file

@ -39,6 +39,8 @@ import net.osmand.plus.base.bottomsheetmenu.HorizontalRecyclerBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.measurementtool.adapter.FolderListAdapter;
import net.osmand.plus.myplaces.AddNewTrackFolderBottomSheet;
import net.osmand.plus.myplaces.AddNewTrackFolderBottomSheet.OnTrackFolderAddListener;
import net.osmand.plus.myplaces.MoveGpxFileBottomSheet;
import net.osmand.plus.myplaces.MoveGpxFileBottomSheet.OnTrackFileMoveListener;
import net.osmand.util.Algorithms;
@ -49,7 +51,8 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFragment implements OnTrackFileMoveListener {
public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFragment
implements OnTrackFileMoveListener, OnTrackFolderAddListener {
public static final String TAG = SaveAsNewTrackBottomSheetDialogFragment.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(SaveAsNewTrackBottomSheetDialogFragment.class);
@ -127,6 +130,8 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
.create();
this.items.add(editFileName);
updateFileNameFromEditText(fileName);
int contentPaddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
int contentPaddingHalf = app.getResources().getDimensionPixelSize(R.dimen.content_padding_half);
@ -140,7 +145,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
if (activity != null) {
File dest = getFile(app, folderName, fileName);
MoveGpxFileBottomSheet.showInstance(activity.getSupportFragmentManager(),
SaveAsNewTrackBottomSheetDialogFragment.this, dest.getAbsolutePath(), usedOnMap);
SaveAsNewTrackBottomSheetDialogFragment.this, dest.getAbsolutePath(), usedOnMap, true);
}
}
});
@ -250,6 +255,15 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
updateFileNameFromEditText(editText.getText().toString());
}
}
@Override
public void onAddNewItemSelected() {
FragmentActivity activity = getActivity();
if (activity != null) {
AddNewTrackFolderBottomSheet.showInstance(activity.getSupportFragmentManager(),
SaveAsNewTrackBottomSheetDialogFragment.this, usedOnMap);
}
}
};
}
@ -348,9 +362,10 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
nameTextBox.setError(getString(R.string.file_with_name_already_exist));
} else {
nameTextBox.setError(null);
fileName = text;
nameTextBox.setErrorEnabled(false);
rightButtonEnabled = true;
}
fileName = text;
updateBottomButtons();
}
@ -392,6 +407,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
if (position != -1) {
recyclerView.scrollToPosition(position);
}
updateFileNameFromEditText(Algorithms.getFileNameWithoutExtension(dest.getName()));
}
}
@ -400,6 +416,13 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
return nightMode ? R.color.activity_background_color_dark : R.color.list_background_color_light;
}
@Override
public void onTrackFolderAdd(String folderName) {
File file = getFile(app, this.folderName, fileName);
File destFolder = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), folderName);
this.onFileMove(file, new File(destFolder, file.getName()));
}
public interface SaveAsNewTrackFragmentListener {
void onSaveAsNewTrack(String folderName, String fileName, boolean showOnMap, boolean simplifiedTrack);

View file

@ -1,5 +1,6 @@
package net.osmand.plus.measurementtool.adapter;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.text.TextUtils;
@ -24,12 +25,14 @@ import java.util.List;
public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.GroupsViewHolder> {
List<String> items = new ArrayList<>();
private static final int VIEW_TYPE_FOOTER = 1;
private static final int VIEW_TYPE_CELL = 0;
private final List<String> items = new ArrayList<>();
String selectedItemName;
OsmandApplication app;
boolean nightMode;
FolderListAdapterListener listener;
private String selectedItemName;
private final OsmandApplication app;
private final boolean nightMode;
private FolderListAdapterListener listener;
public FolderListAdapter(OsmandApplication app, boolean nightMode, String folderName) {
this.app = app;
@ -59,12 +62,37 @@ public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.Gr
groupName.setMaxLines(1);
groupName.setEllipsize(TextUtils.TruncateAt.END);
groupName.setTextColor(ContextCompat.getColor(app, activeColorRes));
if (viewType != VIEW_TYPE_CELL) {
groupName.setText(R.string.add_new_folder);
int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
Drawable iconAdd = app.getUIUtilities().getIcon(R.drawable.ic_action_add, activeColorResId);
ImageView groupIcon = view.findViewById(R.id.groupIcon);
groupIcon.setImageDrawable(iconAdd);
GradientDrawable rectContourDrawable = (GradientDrawable) AppCompatResources.getDrawable(app,
R.drawable.bg_select_group_button_outline);
if (rectContourDrawable != null) {
int strokeColor = ContextCompat.getColor(app, nightMode ? R.color.stroked_buttons_and_links_outline_dark
: R.color.stroked_buttons_and_links_outline_light);
rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, 1), strokeColor);
((ImageView) view.findViewById(R.id.outlineRect)).setImageDrawable(rectContourDrawable);
}
((TextView) view.findViewById(R.id.groupName)).setTextColor(app.getResources().getColor(activeColorResId));
}
return new FolderListAdapter.GroupsViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final GroupsViewHolder holder, int position) {
if (position == items.size()) {
holder.groupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.onAddNewItemSelected();
}
}
});
} else {
holder.groupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -99,15 +127,21 @@ public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.Gr
int iconID;
iconID = R.drawable.ic_action_folder;
holder.groupIcon.setImageDrawable(app.getUIUtilities().getIcon(iconID, activeColorRes));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(app, holder.groupButton, nightMode, R.drawable.ripple_solid_light_6dp,
R.drawable.ripple_solid_dark_6dp);
}
}
@Override
public int getItemViewType(int position) {
return (position == items.size()) ? VIEW_TYPE_FOOTER : VIEW_TYPE_CELL;
}
@Override
public int getItemCount() {
return items == null ? 0 : items.size();
return items == null ? 0 : items.size() + 1;
}
int getItemPosition(String name) {
@ -135,5 +169,7 @@ public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.Gr
public interface FolderListAdapterListener {
void onItemSelected(String item);
void onAddNewItemSelected();
}
}

View file

@ -51,8 +51,6 @@ public class AddNewTrackFolderBottomSheet extends MenuBottomSheetDialogFragment
app = requiredMyApplication();
if (savedInstanceState != null) {
folderName = savedInstanceState.getString(FOLDER_NAME_KEY);
} else if (Algorithms.isEmpty(folderName)) {
folderName = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getName();
}
items.add(new TitleItem(getString(R.string.add_new_folder)));
@ -92,20 +90,23 @@ public class AddNewTrackFolderBottomSheet extends MenuBottomSheetDialogFragment
private void updateFileNameFromEditText(String name) {
rightButtonEnabled = false;
if (Algorithms.isBlank(name)) {
nameTextBox.setError(getString(R.string.empty_filename));
} else {
if (ILLEGAL_PATH_NAME_CHARACTERS.matcher(name).find()) {
nameTextBox.setError(getString(R.string.file_name_containes_illegal_char));
} else if (Algorithms.isEmpty(name.trim())) {
nameTextBox.setError(getString(R.string.empty_filename));
} else {
File destFolder = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), name);
if (destFolder.exists()) {
nameTextBox.setError(getString(R.string.file_with_name_already_exist));
} else {
nameTextBox.setError(null);
folderName = name;
nameTextBox.setErrorEnabled(false);
rightButtonEnabled = true;
}
}
}
folderName = name;
updateBottomButtons();
}
@ -119,11 +120,15 @@ public class AddNewTrackFolderBottomSheet extends MenuBottomSheetDialogFragment
protected void onRightBottomButtonClick() {
AndroidUtils.hideSoftKeyboard(requireActivity(), editText);
Fragment fragment = getTargetFragment();
if (!Algorithms.isBlank(folderName)) {
if (fragment instanceof OnTrackFolderAddListener) {
OnTrackFolderAddListener listener = (OnTrackFolderAddListener) fragment;
listener.onTrackFolderAdd(folderName);
}
dismiss();
} else {
updateFileNameFromEditText(folderName);
}
}
@Override
@ -141,12 +146,10 @@ public class AddNewTrackFolderBottomSheet extends MenuBottomSheetDialogFragment
void onTrackFolderAdd(String folderName);
}
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target,
@NonNull String folderName, boolean usedOnMap) {
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target, boolean usedOnMap) {
try {
if (!fragmentManager.isStateSaved() && fragmentManager.findFragmentByTag(AddNewTrackFolderBottomSheet.TAG) == null) {
AddNewTrackFolderBottomSheet fragment = new AddNewTrackFolderBottomSheet();
fragment.folderName = folderName;
fragment.setUsedOnMap(usedOnMap);
fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, AddNewTrackFolderBottomSheet.TAG);

View file

@ -780,7 +780,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
private void moveGpx(final GpxInfo info) {
FragmentActivity activity = getActivity();
if (activity != null) {
MoveGpxFileBottomSheet.showInstance(activity.getSupportFragmentManager(), this, info.file.getAbsolutePath(), false);
MoveGpxFileBottomSheet.showInstance(activity.getSupportFragmentManager(), this, info.file.getAbsolutePath(), false, false);
}
}

View file

@ -38,15 +38,18 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem
public static final String TAG = MoveGpxFileBottomSheet.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(MoveGpxFileBottomSheet.class);
private static final String FILE_PATH_KEY = "file_path_key";
private static final String SHOW_ALL_FOLDERS_KEY = "show_all_folders_key";
private OsmandApplication app;
private String filePath;
private boolean showAllFolders = false;
@Override
public void createMenuItems(Bundle savedInstanceState) {
app = requiredMyApplication();
if (savedInstanceState != null) {
filePath = savedInstanceState.getString(FILE_PATH_KEY);
showAllFolders = savedInstanceState.getBoolean(SHOW_ALL_FOLDERS_KEY);
}
if (filePath == null) {
return;
@ -74,7 +77,7 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem
FragmentActivity activity = getActivity();
if (activity != null) {
AddNewTrackFolderBottomSheet.showInstance(activity.getSupportFragmentManager(),
MoveGpxFileBottomSheet.this, fileDir.getName(), usedOnMap);
MoveGpxFileBottomSheet.this, usedOnMap);
}
}
})
@ -87,8 +90,8 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem
items.add(dividerItem);
final List<File> dirs = new ArrayList<>();
collectDirs(app.getAppPath(IndexConstants.GPX_INDEX_DIR), dirs, fileDir);
if (!Algorithms.objectEquals(fileDir, app.getAppPath(IndexConstants.GPX_INDEX_DIR))) {
collectDirs(app.getAppPath(IndexConstants.GPX_INDEX_DIR), dirs, showAllFolders ? null : fileDir);
if (showAllFolders || !Algorithms.objectEquals(fileDir, app.getAppPath(IndexConstants.GPX_INDEX_DIR))) {
dirs.add(0, app.getAppPath(IndexConstants.GPX_INDEX_DIR));
}
String gpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getPath();
@ -135,6 +138,7 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(FILE_PATH_KEY, filePath);
outState.putBoolean(SHOW_ALL_FOLDERS_KEY, showAllFolders);
}
@Override
@ -163,12 +167,13 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem
}
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target,
@NonNull String filePath, boolean usedOnMap) {
@NonNull String filePath, boolean usedOnMap, boolean showAllFolders) {
try {
if (!fragmentManager.isStateSaved() && fragmentManager.findFragmentByTag(MoveGpxFileBottomSheet.TAG) == null) {
MoveGpxFileBottomSheet fragment = new MoveGpxFileBottomSheet();
fragment.filePath = filePath;
fragment.setUsedOnMap(usedOnMap);
fragment.showAllFolders = showAllFolders;
fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, MoveGpxFileBottomSheet.TAG);
}

View file

@ -846,7 +846,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
FileUtils.renameFile(mapActivity, new File(gpxFile.path), this, true);
} else if (buttonIndex == CHANGE_FOLDER_BUTTON_INDEX) {
FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
MoveGpxFileBottomSheet.showInstance(fragmentManager, this, gpxFile.path, true);
MoveGpxFileBottomSheet.showInstance(fragmentManager, this, gpxFile.path, true, false);
} else if (buttonIndex == DELETE_BUTTON_INDEX) {
String fileName = Algorithms.getFileWithoutDirs(gpxFile.path);

View file

@ -35,21 +35,9 @@ public class WikivoyageShowPicturesDialogFragment extends BottomSheetDialogFragm
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
nightMode = !getMyApplication().getSettings().isLightContent();
View view = inflater.inflate(R.layout.fragment_wikivoyage_show_images_first_time, container, false);
view.findViewById(R.id.button_no).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OsmandApplication app = getMyApplication();
if (app != null) {
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(WikiArticleShowImages.OFF);
}
sendResult();
dismiss();
}
});
TextView buttonDownload = view.findViewById(R.id.button_download);
if (getMyApplication().getSettings().isWifiConnected()) {
buttonDownload.setText(R.string.shared_string_only_with_wifi);
buttonDownload.setOnClickListener(new View.OnClickListener() {
TextView buttonNo = view.findViewById(R.id.button_no);
buttonNo.setText(R.string.shared_string_only_with_wifi);
buttonNo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OsmandApplication app = getMyApplication();
@ -60,8 +48,8 @@ public class WikivoyageShowPicturesDialogFragment extends BottomSheetDialogFragm
dismiss();
}
});
} else {
buttonDownload.setText(R.string.shared_string_show);
TextView buttonDownload = view.findViewById(R.id.button_download);
buttonDownload.setText(R.string.shared_string_always);
buttonDownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -73,10 +61,7 @@ public class WikivoyageShowPicturesDialogFragment extends BottomSheetDialogFragm
dismiss();
}
});
}
setupHeightAndBackground(view);
return view;
}

View file

@ -280,7 +280,7 @@ public class TravelObfHelper implements TravelHelper {
res.originalId = 0;
res.lang = lang;
res.contentsJson = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.CONTENT_JSON, lang));
res.aggregatedPartOf = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.IS_AGGR_PART, lang));
res.aggregatedPartOf = Algorithms.emptyIfNull(amenity.getStrictTagContent(Amenity.IS_AGGR_PART, lang));
return res;
}