diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index 39ebaa4052..d8f1ac1423 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -469,7 +469,7 @@ public class OsmEditingPlugin extends OsmandPlugin { LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment.getTargetFragment()); return false; } else { - SendGpxBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment.getTargetFragment()); + SendGpxBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment.getTargetFragment(), info); return true; } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java index 0ad89d1504..6b3476670c 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java @@ -9,20 +9,23 @@ 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.TextInputLayout; +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.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.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; @@ -32,68 +35,79 @@ import java.util.List; public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { - public static final String TAG = "SendGpxBottomSheetFragment"; + public static final String TAG = SendGpxBottomSheetFragment.class.getSimpleName(); - protected OsmandSettings settings; + private GpxInfo[] gpxInfos; + private UploadVisibility selectedUploadVisibility = UploadVisibility.Public; - private OsmEditingPlugin.UploadVisibility uploadVisibility; - private List info; - private String selectedVisibilityType; + private TextInputEditText tagsField; + private TextInputEditText messageField; - protected OsmandApplication getMyApplication() { - return (OsmandApplication) getActivity().getApplication(); - } - - private boolean isLoginOAuth() { - return !Algorithms.isEmpty(getMyApplication().getSettings().USER_DISPLAY_NAME.get()); + public void setGpxInfos(GpxInfo[] gpxInfos) { + this.gpxInfos = gpxInfos; } @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); + View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.send_gpx_fragment, null); + + messageField = sendOsmPoiView.findViewById(R.id.message_field); + tagsField = sendOsmPoiView.findViewById(R.id.tags_field); + + OsmandSettings settings = requiredMyApplication().getSettings(); + + 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()); + } + + if (gpxInfos.length > 0 && gpxInfos[0].getFileName() != null) { + int dt = gpxInfos[0].getFileName().indexOf('.'); + messageField.setText(gpxInfos[0].getFileName().substring(0, dt)); + } + tagsField.setText(R.string.app_name_osmand); + 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); + visibilityName.setText(selectedUploadVisibility.stringResource()); + visibilityDescription.setText(selectedUploadVisibility.getDescriptionId()); + + List itemsVisibility = new ArrayList<>(); + for (UploadVisibility visibilityType : UploadVisibility.values()) { + String title = getString(visibilityType.stringResource()); + HorizontalSelectionItem item = new HorizontalSelectionAdapter.HorizontalSelectionItem(title, visibilityType); itemsVisibility.add(item); } + + final HorizontalSelectionAdapter horizontalSelectionAdapter = new HorizontalSelectionAdapter(getMyApplication(), nightMode); horizontalSelectionAdapter.setItems(itemsVisibility); -// horizontalSelectionAdapter.setSelectedItemByTitle(selectedVisibilityType); - horizontalSelectionAdapter.setListener(new HorizontalSelectionAdapter.HorizontalSelectionAdapterListener() { + horizontalSelectionAdapter.setSelectedItemByTitle(getString(selectedUploadVisibility.stringResource())); + horizontalSelectionAdapter.setListener(new HorizontalSelectionAdapterListener() { @Override public void onItemSelected(HorizontalSelectionAdapter.HorizontalSelectionItem item) { - uploadVisibility = (OsmEditingPlugin.UploadVisibility) item.getObject(); - visibilityName.setText(uploadVisibility.stringResource()); - visibilityDescription.setText(uploadVisibility.getDescriptionId()); + selectedUploadVisibility = (OsmEditingPlugin.UploadVisibility) item.getObject(); + visibilityName.setText(selectedUploadVisibility.stringResource()); + visibilityDescription.setText(selectedUploadVisibility.getDescriptionId()); + horizontalSelectionAdapter.notifyDataSetChanged(); } }); + 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() + 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); - } + private boolean isLoginOAuth() { + return !Algorithms.isEmpty(getMyApplication().getSettings().USER_DISPLAY_NAME.get()); } @Override @@ -101,21 +115,30 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { 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; } -} + @Override + protected void onRightBottomButtonClick() { + FragmentActivity activity = getActivity(); + if (activity != null) { + String tags = tagsField.getText().toString(); + String descr = messageField.getText().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.show(fragmentManager, TAG); + } + } +} \ No newline at end of file