diff --git a/OsmAnd/res/layout/send_gpx_fragment.xml b/OsmAnd/res/layout/send_gpx_fragment.xml new file mode 100644 index 0000000000..5e7edddd7b --- /dev/null +++ b/OsmAnd/res/layout/send_gpx_fragment.xml @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/send_gpx_osm.xml b/OsmAnd/res/layout/send_gpx_osm.xml deleted file mode 100644 index 2fd9794b7f..0000000000 --- a/OsmAnd/res/layout/send_gpx_osm.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 5209a248b3..9fab85bfcb 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 Markers history OsmAnd Live subscription is on hold OsmAnd Live subscription has been paused @@ -23,11 +29,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/activities/EnumAdapter.java b/OsmAnd/src/net/osmand/plus/activities/EnumAdapter.java deleted file mode 100644 index 519952b8e3..0000000000 --- a/OsmAnd/src/net/osmand/plus/activities/EnumAdapter.java +++ /dev/null @@ -1,38 +0,0 @@ -package net.osmand.plus.activities; - -import net.osmand.plus.activities.EnumAdapter.IEnumWithResource; -import android.content.Context; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.TextView; - -public class EnumAdapter - extends ArrayAdapter -{ - - public EnumAdapter(Context context, int textViewResourceId, T[] enums) - { - super(context, textViewResourceId, enums); - } - - @Override - public View getDropDownView(int position, View convertView, ViewGroup parent) { - TextView textView = (TextView) super.getDropDownView(position, convertView, parent); - T item = getItem(position); - textView.setText(item.stringResource()); - return textView; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - TextView textView = (TextView) super.getView(position, convertView, parent); - T item = getItem(position); - textView.setText(item.stringResource()); - return textView; - } - - public static interface IEnumWithResource { - int stringResource(); - } -} 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..3b11e7a309 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,8 +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; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; @@ -45,6 +39,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; @@ -437,24 +432,34 @@ 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); - private final int resourceId; + public enum UploadVisibility { + PUBLIC(R.string.gpxup_public, R.string.gpx_upload_public_visibility_descr), + IDENTIFIABLE(R.string.gpxup_identifiable, R.string.gpx_upload_identifiable_visibility_descr), + TRACKABLE(R.string.gpxup_trackable, R.string.gpx_upload_trackable_visibility_descr), + PRIVATE(R.string.gpxup_private, R.string.gpx_upload_private_visibility_descr); - UploadVisibility(int resourceId) { - this.resourceId = resourceId; + @StringRes + private final int titleId; + @StringRes + private final int descriptionId; + + UploadVisibility(int titleId, int descriptionId) { + this.titleId = titleId; + this.descriptionId = descriptionId; } public String asURLparam() { return name().toLowerCase(); } - @Override - public int stringResource() { - return resourceId; + @StringRes + public int getTitleId() { + return titleId; + } + + @StringRes + public int getDescriptionId() { + return descriptionId; } } @@ -465,35 +470,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(), info); + 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/UploadGPXFilesTask.java b/OsmAnd/src/net/osmand/plus/osmedit/UploadGPXFilesTask.java index c49b49aad0..7ef392acf9 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/UploadGPXFilesTask.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/UploadGPXFilesTask.java @@ -1,29 +1,36 @@ package net.osmand.plus.osmedit; -import java.io.File; +import android.app.Activity; +import android.os.AsyncTask; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import net.osmand.AndroidUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo; import net.osmand.plus.osmedit.OsmEditingPlugin.UploadVisibility; -import android.app.Activity; -import android.os.AsyncTask; -import android.widget.Toast; + +import java.io.File; +import java.lang.ref.WeakReference; public class UploadGPXFilesTask extends AsyncTask { + private final OsmandApplication app; + private final WeakReference activityRef; + private final String visibility; private final String description; private final String tagstring; - private Activity la; - public UploadGPXFilesTask(Activity la, - String description, String tagstring, UploadVisibility visibility) { - this.la = la; + public UploadGPXFilesTask(@NonNull Activity activity, String description, String tagsString, + @Nullable UploadVisibility visibility) { + app = (OsmandApplication) activity.getApplication(); + this.activityRef = new WeakReference<>(activity); this.description = description; - this.tagstring = tagstring; - this.visibility = visibility != null ? visibility.asURLparam() : UploadVisibility.Private.asURLparam(); - + this.tagstring = tagsString; + this.visibility = visibility != null ? visibility.asURLparam() : UploadVisibility.PRIVATE.asURLparam(); } @Override @@ -32,10 +39,9 @@ public class UploadGPXFilesTask extends AsyncTask { int total = 0; for (GpxInfo info : params) { if (!isCancelled() && info.file != null) { - String warning = null; File file = info.file; - warning = new OpenstreetmapRemoteUtil((OsmandApplication) la.getApplication()).uploadGPXFile(tagstring, description, visibility, - file); + OpenstreetmapRemoteUtil remoteUtil = new OpenstreetmapRemoteUtil(app); + String warning = remoteUtil.uploadGPXFile(tagstring, description, visibility, file); total++; if (warning == null) { count++; @@ -44,7 +50,7 @@ public class UploadGPXFilesTask extends AsyncTask { } } } - return la.getString(R.string.local_index_items_uploaded, count, total); + return app.getString(R.string.local_index_items_uploaded, count, total); } @Override @@ -57,19 +63,24 @@ public class UploadGPXFilesTask extends AsyncTask { } b.append(values[i]); } - Toast.makeText(la, b.toString(), Toast.LENGTH_LONG).show(); + app.showToastMessage(b.toString()); } } @Override protected void onPreExecute() { - la.setProgressBarIndeterminateVisibility(true); + Activity activity = activityRef.get(); + if (AndroidUtils.isActivityNotDestroyed(activity)) { + activity.setProgressBarIndeterminateVisibility(true); + } } @Override protected void onPostExecute(String result) { - la.setProgressBarIndeterminateVisibility(false); - Toast.makeText(la, result, Toast.LENGTH_LONG).show(); + Activity activity = activityRef.get(); + if (AndroidUtils.isActivityNotDestroyed(activity)) { + activity.setProgressBarIndeterminateVisibility(false); + } + app.showToastMessage(result); } - } \ No newline at end of file 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..f9e8e6d00a --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java @@ -0,0 +1,145 @@ +package net.osmand.plus.osmedit.dialogs; + +import android.os.AsyncTask; +import android.os.Bundle; +import android.text.Editable; +import android.view.LayoutInflater; +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.FragmentActivity; +import androidx.fragment.app.FragmentManager; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.textfield.TextInputEditText; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.UiUtilities.DialogButtonType; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter; +import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionAdapterListener; +import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionItem; +import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo; +import net.osmand.plus.osmedit.OsmEditingPlugin; +import net.osmand.plus.osmedit.OsmEditingPlugin.UploadVisibility; +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.class.getSimpleName(); + + private GpxInfo[] gpxInfos; + private UploadVisibility selectedUploadVisibility = UploadVisibility.PUBLIC; + + private TextInputEditText tagsField; + private TextInputEditText messageField; + + public void setGpxInfos(GpxInfo[] gpxInfos) { + this.gpxInfos = gpxInfos; + } + + @Override + public void createMenuItems(Bundle savedInstanceState) { + OsmandApplication app = requiredMyApplication(); + OsmandSettings settings = app.getSettings(); + + LayoutInflater themedInflater = UiUtilities.getInflater(app, nightMode); + View sendOsmPoiView = themedInflater.inflate(R.layout.send_gpx_fragment, null); + + tagsField = sendOsmPoiView.findViewById(R.id.tags_field); + messageField = sendOsmPoiView.findViewById(R.id.message_field); + + TextView accountName = sendOsmPoiView.findViewById(R.id.user_name); + if (!Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get())) { + accountName.setText(settings.USER_DISPLAY_NAME.get()); + } else { + accountName.setText(settings.USER_NAME.get()); + } + + String fileName = gpxInfos[0].getFileName(); + messageField.setText(Algorithms.getFileNameWithoutExtension(fileName)); + + final TextView visibilityName = sendOsmPoiView.findViewById(R.id.visibility_name); + final TextView visibilityDescription = sendOsmPoiView.findViewById(R.id.visibility_description); + visibilityName.setText(selectedUploadVisibility.getTitleId()); + visibilityDescription.setText(selectedUploadVisibility.getDescriptionId()); + + List itemsVisibility = new ArrayList<>(); + for (UploadVisibility visibilityType : UploadVisibility.values()) { + String title = getString(visibilityType.getTitleId()); + HorizontalSelectionItem item = new HorizontalSelectionAdapter.HorizontalSelectionItem(title, visibilityType); + itemsVisibility.add(item); + } + + final HorizontalSelectionAdapter horizontalSelectionAdapter = new HorizontalSelectionAdapter(app, nightMode); + horizontalSelectionAdapter.setItems(itemsVisibility); + horizontalSelectionAdapter.setSelectedItemByTitle(getString(selectedUploadVisibility.getTitleId())); + horizontalSelectionAdapter.setListener(new HorizontalSelectionAdapterListener() { + @Override + public void onItemSelected(HorizontalSelectionAdapter.HorizontalSelectionItem item) { + selectedUploadVisibility = (OsmEditingPlugin.UploadVisibility) item.getObject(); + visibilityName.setText(selectedUploadVisibility.getTitleId()); + visibilityDescription.setText(selectedUploadVisibility.getDescriptionId()); + horizontalSelectionAdapter.notifyDataSetChanged(); + } + + }); + + RecyclerView iconCategoriesRecyclerView = sendOsmPoiView.findViewById(R.id.description_view); + iconCategoriesRecyclerView.setAdapter(horizontalSelectionAdapter); + iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false)); + horizontalSelectionAdapter.notifyDataSetChanged(); + + SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() + .setCustomView(sendOsmPoiView) + .create(); + items.add(titleItem); + } + + @Override + protected DialogButtonType getRightBottomButtonType() { + return DialogButtonType.PRIMARY; + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_upload; + } + + @Override + protected void onRightBottomButtonClick() { + FragmentActivity activity = getActivity(); + if (activity != null) { + Editable tagsText = tagsField.getText(); + Editable descrText = messageField.getText(); + String tags = tagsText != null ? tagsText.toString() : ""; + String descr = descrText != null ? descrText.toString() : ""; + + UploadGPXFilesTask uploadGPXFilesTask = new UploadGPXFilesTask(activity, descr, tags, selectedUploadVisibility); + uploadGPXFilesTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxInfos); + } + dismiss(); + } + + public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment targetFragment, GpxInfo[] info) { + if (!fragmentManager.isStateSaved()) { + SendGpxBottomSheetFragment fragment = new SendGpxBottomSheetFragment(); + fragment.setTargetFragment(targetFragment, 0); + fragment.setGpxInfos(info); + fragment.setRetainInstance(true); + fragment.show(fragmentManager, TAG); + } + } +} \ No newline at end of file