diff --git a/android/app/src/main/java/app/organicmaps/editor/Editor.java b/android/app/src/main/java/app/organicmaps/editor/Editor.java index 5faa0720e9..827d98af5a 100644 --- a/android/app/src/main/java/app/organicmaps/editor/Editor.java +++ b/android/app/src/main/java/app/organicmaps/editor/Editor.java @@ -87,6 +87,17 @@ public final class Editor public static native boolean nativeHasWifi(); public static native void nativeSetHasWifi(boolean hasWifi); + public static void nativeSetSwitchInput(int id, Boolean switchValue, String checkedValue, String uncheckedValue) + { + nativeSetMetadata(id, switchValue ? checkedValue : uncheckedValue); + } + + public static boolean nativeGetSwitchInput(int id, String checkedValue) + { + String value = nativeGetMetadata(id); + return value.equals(checkedValue); + } + public static native boolean nativeIsAddressEditable(); public static native boolean nativeIsNameEditable(); public static native boolean nativeIsPointType(); diff --git a/android/app/src/main/java/app/organicmaps/editor/EditorFragment.java b/android/app/src/main/java/app/organicmaps/editor/EditorFragment.java index 9513817091..01b04535f1 100644 --- a/android/app/src/main/java/app/organicmaps/editor/EditorFragment.java +++ b/android/app/src/main/java/app/organicmaps/editor/EditorFragment.java @@ -101,6 +101,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe private TextView mEditPhoneLink; private TextView mCuisine; private SwitchCompat mWifi; + private TextView mSelfService; // Default Metadata entries. private static final class MetadataEntry @@ -192,6 +193,8 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe initMetadataEntry(Metadata.MetadataType.FMD_CONTACT_LINE, R.string.error_enter_correct_line_page); mCuisine.setText(Editor.nativeGetFormattedCuisine()); + String selfServiceMetadata = Editor.nativeGetMetadata(Metadata.MetadataType.FMD_SELF_SERVICE.toInt()); + mSelfService.setText(Utils.getTagValueLocalized(view.getContext(), "self_service", selfServiceMetadata)); initMetadataEntry(Metadata.MetadataType.FMD_OPERATOR, 0); mWifi.setChecked(Editor.nativeHasWifi()); refreshOpeningTime(); @@ -452,6 +455,11 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe View blockWifi = view.findViewById(R.id.block_wifi); mWifi = view.findViewById(R.id.sw__wifi); blockWifi.setOnClickListener(this); + + View blockSelfService = view.findViewById(R.id.block_self_service); + blockSelfService.setOnClickListener(this); + mSelfService = view.findViewById(R.id.self_service); + View blockOpeningHours = view.findViewById(R.id.block_opening_hours); mEditOpeningHours = blockOpeningHours.findViewById(R.id.edit_opening_hours); mEditOpeningHours.setOnClickListener(this); @@ -469,6 +477,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe mDetailsBlocks.put(Metadata.MetadataType.FMD_PHONE_NUMBER, blockPhone); mDetailsBlocks.put(Metadata.MetadataType.FMD_CUISINE, blockCuisine); mDetailsBlocks.put(Metadata.MetadataType.FMD_INTERNET, blockWifi); + mDetailsBlocks.put(Metadata.MetadataType.FMD_SELF_SERVICE, blockSelfService); mDetailsBlocks.put(Metadata.MetadataType.FMD_WEBSITE, websiteBlock); mDetailsBlocks.put(Metadata.MetadataType.FMD_WEBSITE_MENU, websiteMenuBlock); mDetailsBlocks.put(Metadata.MetadataType.FMD_EMAIL, emailBlock); @@ -508,6 +517,8 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe mParent.editPhone(); else if (id == R.id.block_wifi) mWifi.toggle(); + else if (id == R.id.block_self_service) + mParent.editSelfService(); else if (id == R.id.block_street) mParent.editStreet(); else if (id == R.id.block_cuisine) diff --git a/android/app/src/main/java/app/organicmaps/editor/EditorHostFragment.java b/android/app/src/main/java/app/organicmaps/editor/EditorHostFragment.java index 3b7aba405a..69e3634347 100644 --- a/android/app/src/main/java/app/organicmaps/editor/EditorHostFragment.java +++ b/android/app/src/main/java/app/organicmaps/editor/EditorHostFragment.java @@ -19,6 +19,7 @@ import androidx.fragment.app.FragmentManager; import app.organicmaps.MwmApplication; import app.organicmaps.R; import app.organicmaps.base.BaseMwmToolbarFragment; +import app.organicmaps.bookmarks.data.Metadata; import app.organicmaps.editor.data.Language; import app.organicmaps.editor.data.LocalizedName; import app.organicmaps.editor.data.LocalizedStreet; @@ -50,7 +51,8 @@ public class EditorHostFragment extends BaseMwmToolbarFragment implements View.O STREET, CUISINE, LANGUAGE, - PHONE + PHONE, + SELF_SERVICE } private Mode mMode; @@ -171,7 +173,7 @@ public class EditorHostFragment extends BaseMwmToolbarFragment implements View.O { switch (mMode) { - case OPENING_HOURS, STREET, CUISINE, LANGUAGE, PHONE -> editMapObject(); + case OPENING_HOURS, STREET, CUISINE, LANGUAGE, PHONE, SELF_SERVICE -> editMapObject(); default -> Utils.navigateToParent(requireActivity()); } return true; @@ -224,6 +226,11 @@ public class EditorHostFragment extends BaseMwmToolbarFragment implements View.O editWithFragment(Mode.CUISINE, R.string.select_cuisine, null, CuisineFragment.class, true); } + protected void editSelfService() + { + editWithFragment(Mode.SELF_SERVICE, R.string.select_option, null, SelfServiceFragment.class, false); + } + protected void addLanguage() { Bundle args = new Bundle(); @@ -298,6 +305,8 @@ public class EditorHostFragment extends BaseMwmToolbarFragment implements View.O Editor.nativeSetSelectedCuisines(cuisines); editMapObject(); } + case SELF_SERVICE -> + setSelection(Metadata.MetadataType.FMD_SELF_SERVICE, ((SelfServiceFragment) getChildFragmentManager().findFragmentByTag(SelfServiceFragment.class.getName())).getSelection()); case LANGUAGE -> editMapObject(); case MAP_OBJECT -> { @@ -394,6 +403,12 @@ public class EditorHostFragment extends BaseMwmToolbarFragment implements View.O editMapObject(); } + public void setSelection(Metadata.MetadataType metadata, String selection) + { + Editor.nativeSetMetadata(metadata.toInt(), selection); + editMapObject(); + } + public boolean addingNewObject() { return mIsNewObject; diff --git a/android/app/src/main/java/app/organicmaps/editor/SelfServiceAdapter.java b/android/app/src/main/java/app/organicmaps/editor/SelfServiceAdapter.java new file mode 100644 index 0000000000..69cc020327 --- /dev/null +++ b/android/app/src/main/java/app/organicmaps/editor/SelfServiceAdapter.java @@ -0,0 +1,86 @@ +package app.organicmaps.editor; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CompoundButton; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import app.organicmaps.R; +import app.organicmaps.util.UiUtils; +import app.organicmaps.util.Utils; + +public class SelfServiceAdapter extends RecyclerView.Adapter +{ + private final String[] mItems = new String[]{"yes", "only", "partially", "no"}; + private final SelfServiceFragment mFragment; + private String mSelectedOption; + + + public SelfServiceAdapter(@NonNull SelfServiceFragment host, @NonNull String selected) + { + mFragment = host; + mSelectedOption = selected; + } + + public String getSelected() + { + return mSelectedOption; + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) + { + return new SelfServiceAdapter.ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_selection, parent, false)); + } + + @Override + public void onBindViewHolder(SelfServiceAdapter.ViewHolder holder, int position) + { + holder.bind(position); + } + + @Override + public int getItemCount() + { + return mItems.length; + } + + protected class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener + { + final TextView selfServiceDef; + final CompoundButton selected; + + public ViewHolder(View itemView) + { + super(itemView); + selfServiceDef = itemView.findViewById(R.id.self_service_default); + selected = itemView.findViewById(R.id.self_service_selected); + itemView.setOnClickListener(this); + selected.setOnClickListener(v -> { + selected.toggle(); + SelfServiceAdapter.ViewHolder.this.onClick(selected); + }); + } + + public void bind(int position) + { + Context context = itemView.getContext(); + selected.setChecked(mSelectedOption.equals(mItems[position])); + String text = Utils.getTagValueLocalized(context, "self_service", mItems[position]); + selfServiceDef.setText(text); + } + + @Override + public void onClick(View v) + { + mSelectedOption = mItems[getBindingAdapterPosition()]; + notifyDataSetChanged(); + mFragment.saveSelection(mSelectedOption); + } + } +} diff --git a/android/app/src/main/java/app/organicmaps/editor/SelfServiceFragment.java b/android/app/src/main/java/app/organicmaps/editor/SelfServiceFragment.java new file mode 100644 index 0000000000..8acd7edc5f --- /dev/null +++ b/android/app/src/main/java/app/organicmaps/editor/SelfServiceFragment.java @@ -0,0 +1,52 @@ +package app.organicmaps.editor; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.CallSuper; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import app.organicmaps.base.BaseMwmRecyclerFragment; +import app.organicmaps.bookmarks.data.Metadata; +import app.organicmaps.editor.data.LocalizedStreet; + +public class SelfServiceFragment extends BaseMwmRecyclerFragment +{ + private String mSelectedString; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) + { + return super.onCreateView(inflater, container, savedInstanceState); + } + + @NonNull + public String getSelection() + { + return getAdapter().getSelected(); + } + + @CallSuper + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) + { + mSelectedString = Editor.nativeGetMetadata(Metadata.MetadataType.FMD_SELF_SERVICE.toInt()); + super.onViewCreated(view, savedInstanceState); + } + + @NonNull + @Override + protected SelfServiceAdapter createAdapter() + { + return new SelfServiceAdapter(this, mSelectedString); + } + + protected void saveSelection(String selection) + { + if (getParentFragment() instanceof EditorHostFragment) + ((EditorHostFragment) getParentFragment()).setSelection(Metadata.MetadataType.FMD_SELF_SERVICE, selection); + } +} diff --git a/android/app/src/main/res/layout/fragment_editor.xml b/android/app/src/main/res/layout/fragment_editor.xml index bd69463653..eff7e123b9 100644 --- a/android/app/src/main/res/layout/fragment_editor.xml +++ b/android/app/src/main/res/layout/fragment_editor.xml @@ -241,6 +241,40 @@ android:layout_centerVertical="true"/> + + + + + + + + + + + + + + + + + + diff --git a/data/editor.config b/data/editor.config index 1213162e6a..1d67eb952d 100644 --- a/data/editor.config +++ b/data/editor.config @@ -99,6 +99,15 @@