From 1a2eb6626373ea86e566932b9a2c6bc5ed32d60e Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Tue, 10 Nov 2020 18:25:05 +0200 Subject: [PATCH] test --- OsmAnd/res/layout/send_gpx_fragment.xml | 198 ++++++++++++++++++ OsmAnd/res/values/strings.xml | 10 +- .../LoginBottomSheetFragment.java | 2 +- .../osmand/plus/osmedit/OsmEditingPlugin.java | 56 ++--- .../dialogs/SendGpxBottomSheetFragment.java | 121 +++++++++++ 5 files changed, 345 insertions(+), 42 deletions(-) create mode 100644 OsmAnd/res/layout/send_gpx_fragment.xml create mode 100644 OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java diff --git a/OsmAnd/res/layout/send_gpx_fragment.xml b/OsmAnd/res/layout/send_gpx_fragment.xml new file mode 100644 index 0000000000..234ccfb9dc --- /dev/null +++ b/OsmAnd/res/layout/send_gpx_fragment.xml @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index dc262a8b1b..8519838557 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,12 @@ Thx - Hardy --> + Trackable means that the trace will not show up in any public listings but trackpoints from it will still be available through the public GPS API with timestamps. Other users will only be able to download processed trackpoints from your trace which can\'t be associated with you directly. + Identifiable means that the trace will be shown publicly in Your GPS traces and in public GPS trace listings, i.e. other users will be able to download the raw trace and associate it with your username. Data served via the trackpoints API will reference your original trace page. Timestamps of the trace points are available through the public GPS API. + Private means that the trace will not show up in any public listings, but trackpoints from it will still be available through the public GPS API without timestamps but will not be chronologically ordered. + Public means that the trace will be shown publicly in Your GPS traces and in public GPS trace listings. Data served via the API does not reference your trace page. Timestamps of the trace points are not available through the public GPS API, and the points are not chronologically ordered. However, other users are still able to download the raw trace from the public trace list and any timestamps contained within. + Enter tags separated by comma. + Send GPX file to OpenStreetMap OsmAnd Live subscription is on hold OsmAnd Live subscription has been paused OsmAnd Live subscription has been expired @@ -22,11 +28,11 @@ Use login and password You need to login to upload new or modified changes. \n\nYou can log in using the safe OAuth method or use your login and password. You can view all your unloaded edits or OSM bugs in %1$s. Uploaded points don’t show in OsmAnd. - Sing in with OpenStreetMap + Sign in with OpenStreetMap Login to OpenStreetMap.org Login to OpenStreetMap These plugin setting are global, and apply to all profiles - You must add at least two points. + You need to add at least two points Travel Emergency Sport diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java index 44547815ce..5eed849b92 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/LoginBottomSheetFragment.java @@ -67,7 +67,7 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment { @Override protected int getThirdBottomButtonTextId() { - return R.string.sing_in_with_open_street_map; + return R.string.sign_in_with_open_street_map; } @Override diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index 71da65bf20..39ebaa4052 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -6,18 +6,14 @@ import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.graphics.Typeface; import android.graphics.drawable.Drawable; -import android.os.AsyncTask; import android.text.SpannableString; import android.text.TextUtils; import android.text.style.StyleSpan; -import android.view.LayoutInflater; import android.view.View; import android.widget.ArrayAdapter; -import android.widget.EditText; -import android.widget.Spinner; import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; +import androidx.annotation.StringRes; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; @@ -34,7 +30,6 @@ import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; -import net.osmand.plus.activities.EnumAdapter; import net.osmand.plus.activities.EnumAdapter.IEnumWithResource; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TabActivity; @@ -45,6 +40,7 @@ import net.osmand.plus.myplaces.AvailableGPXFragment; import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.osmedit.OsmPoint.Action; +import net.osmand.plus.osmedit.dialogs.SendGpxBottomSheetFragment; import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.settings.backend.OsmandPreference; import net.osmand.plus.settings.backend.OsmandSettings; @@ -438,14 +434,16 @@ public class OsmEditingPlugin extends OsmandPlugin { } public enum UploadVisibility implements IEnumWithResource { - Public(R.string.gpxup_public), - Identifiable(R.string.gpxup_identifiable), - Trackable(R.string.gpxup_trackable), - Private(R.string.gpxup_private); + Public(R.string.gpxup_public, R.string.public_visibility), + Identifiable(R.string.gpxup_identifiable, R.string.identifiable_visibility), + Trackable(R.string.gpxup_trackable, R.string.trackable_visibility), + Private(R.string.gpxup_private, R.string.private_visibility); private final int resourceId; + private final int descriptionId; - UploadVisibility(int resourceId) { + UploadVisibility(int resourceId,int descriptionId ) { this.resourceId = resourceId; + this.descriptionId = descriptionId; } public String asURLparam() { @@ -456,6 +454,11 @@ public class OsmEditingPlugin extends OsmandPlugin { public int stringResource() { return resourceId; } + + @StringRes + public int getDescriptionId() { + return descriptionId; + } } public boolean sendGPXFiles(final FragmentActivity activity, AvailableGPXFragment fragment, final GpxInfo... info) { @@ -465,35 +468,10 @@ public class OsmEditingPlugin extends OsmandPlugin { if ((Algorithms.isEmpty(name) || Algorithms.isEmpty(pwd)) && Algorithms.isEmpty(authToken)) { LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment.getTargetFragment()); return false; + } else { + SendGpxBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment.getTargetFragment()); + return true; } - AlertDialog.Builder builder = new AlertDialog.Builder(activity); - LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - final View view = inflater.inflate(R.layout.send_gpx_osm, null); - final EditText descr = (EditText) view.findViewById(R.id.memory_size); - if (info.length > 0 && info[0].getFileName() != null) { - int dt = info[0].getFileName().indexOf('.'); - descr.setText(info[0].getFileName().substring(0, dt)); - } - final EditText tags = (EditText) view.findViewById(R.id.TagsText); - final Spinner visibility = ((Spinner) view.findViewById(R.id.Visibility)); - EnumAdapter adapter = new EnumAdapter<>(activity, android.R.layout.simple_spinner_item, UploadVisibility.values()); - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - visibility.setAdapter(adapter); - visibility.setSelection(0); - - builder.setView(view); - builder.setNegativeButton(R.string.shared_string_no, null); - builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - new UploadGPXFilesTask(activity, descr.getText().toString(), tags.getText().toString(), - (UploadVisibility) visibility.getItemAtPosition(visibility.getSelectedItemPosition()) - ).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, info); - } - }); - builder.show(); - return true; } @Override diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java new file mode 100644 index 0000000000..0ad89d1504 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java @@ -0,0 +1,121 @@ +package net.osmand.plus.osmedit.dialogs; + +import android.os.AsyncTask; +import android.os.Bundle; +import android.view.ContextThemeWrapper; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.textfield.TextInputLayout; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter; +import net.osmand.plus.myplaces.AvailableGPXFragment; +import net.osmand.plus.osmedit.OsmEditingPlugin; +import net.osmand.plus.osmedit.UploadGPXFilesTask; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.util.Algorithms; + +import java.util.ArrayList; +import java.util.List; + +public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { + + public static final String TAG = "SendGpxBottomSheetFragment"; + + protected OsmandSettings settings; + + private OsmEditingPlugin.UploadVisibility uploadVisibility; + private List info; + private String selectedVisibilityType; + + protected OsmandApplication getMyApplication() { + return (OsmandApplication) getActivity().getApplication(); + } + + private boolean isLoginOAuth() { + return !Algorithms.isEmpty(getMyApplication().getSettings().USER_DISPLAY_NAME.get()); + } + + @Override + public void createMenuItems(Bundle savedInstanceState) { + final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.send_gpx_fragment, null); + final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name); + settings = getMyApplication().getSettings(); + String userNameOAuth = settings.USER_DISPLAY_NAME.get(); + String userNameOpenID = settings.USER_NAME.get(); + String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID; + accountName.setText(userName); + final TextView visibilityName = sendOsmPoiView.findViewById(R.id.visibility_name); + final TextView visibilityDescription = sendOsmPoiView.findViewById(R.id.visibility_description); + HorizontalSelectionAdapter horizontalSelectionAdapter = new HorizontalSelectionAdapter(getMyApplication(), nightMode); + List itemsVisibility = new ArrayList<>(); + for (OsmEditingPlugin.UploadVisibility visibilityType : OsmEditingPlugin.UploadVisibility.values()) { + String title = getMyApplication().getString(visibilityType.stringResource()); + HorizontalSelectionAdapter.HorizontalSelectionItem item = new HorizontalSelectionAdapter.HorizontalSelectionItem(title, visibilityType); + itemsVisibility.add(item); + } + horizontalSelectionAdapter.setItems(itemsVisibility); +// horizontalSelectionAdapter.setSelectedItemByTitle(selectedVisibilityType); + horizontalSelectionAdapter.setListener(new HorizontalSelectionAdapter.HorizontalSelectionAdapterListener() { + @Override + public void onItemSelected(HorizontalSelectionAdapter.HorizontalSelectionItem item) { + uploadVisibility = (OsmEditingPlugin.UploadVisibility) item.getObject(); + visibilityName.setText(uploadVisibility.stringResource()); + visibilityDescription.setText(uploadVisibility.getDescriptionId()); + } + + }); + RecyclerView iconCategoriesRecyclerView = sendOsmPoiView.findViewById(R.id.description_view); + iconCategoriesRecyclerView.setAdapter(horizontalSelectionAdapter); + iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(getMyApplication(), RecyclerView.HORIZONTAL, false)); + horizontalSelectionAdapter.notifyDataSetChanged(); + + final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() + .setCustomView(sendOsmPoiView) + .create(); + items.add(titleItem); + } + + public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment targetFragment, final AvailableGPXFragment.GpxInfo... info) { + if (!fragmentManager.isStateSaved()) { + SendGpxBottomSheetFragment fragment = new SendGpxBottomSheetFragment(); + fragment.setTargetFragment(targetFragment, 0); + fragment.show(fragmentManager, TAG); + } + } + + @Override + protected UiUtilities.DialogButtonType getRightBottomButtonType() { + return (UiUtilities.DialogButtonType.PRIMARY); + } + + @Override + protected void onRightBottomButtonClick() { + final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.send_gpx_fragment, null); + final TextInputLayout descr = sendOsmPoiView.findViewById(R.id.message_field); + final TextInputLayout tags = sendOsmPoiView.findViewById(R.id.tags_field); + +// new UploadGPXFilesTask(getActivity(), descr.getEditText().toString(), tags.getEditText().toString(), +// uploadVisibility +// ).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, info); + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_upload; + } + +} +