OSM Renovation - Send GPX

Final
This commit is contained in:
androiddevkkotlin 2020-11-11 00:12:17 +02:00
parent 1a2eb66263
commit c80a358b45
2 changed files with 74 additions and 51 deletions

View file

@ -469,7 +469,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment.getTargetFragment()); LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment.getTargetFragment());
return false; return false;
} else { } else {
SendGpxBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment.getTargetFragment()); SendGpxBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), fragment.getTargetFragment(), info);
return true; return true;
} }
} }

View file

@ -9,20 +9,23 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; 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.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter; 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;
import net.osmand.plus.osmedit.OsmEditingPlugin.UploadVisibility;
import net.osmand.plus.osmedit.UploadGPXFilesTask; import net.osmand.plus.osmedit.UploadGPXFilesTask;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -32,68 +35,79 @@ import java.util.List;
public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { 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 TextInputEditText tagsField;
private List<AvailableGPXFragment.GpxInfo> info; private TextInputEditText messageField;
private String selectedVisibilityType;
protected OsmandApplication getMyApplication() { public void setGpxInfos(GpxInfo[] gpxInfos) {
return (OsmandApplication) getActivity().getApplication(); this.gpxInfos = gpxInfos;
}
private boolean isLoginOAuth() {
return !Algorithms.isEmpty(getMyApplication().getSettings().USER_DISPLAY_NAME.get());
} }
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.send_gpx_fragment, null); 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(); messageField = sendOsmPoiView.findViewById(R.id.message_field);
String userNameOAuth = settings.USER_DISPLAY_NAME.get(); tagsField = sendOsmPoiView.findViewById(R.id.tags_field);
String userNameOpenID = settings.USER_NAME.get();
String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID; OsmandSettings settings = requiredMyApplication().getSettings();
accountName.setText(userName);
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 visibilityName = sendOsmPoiView.findViewById(R.id.visibility_name);
final TextView visibilityDescription = sendOsmPoiView.findViewById(R.id.visibility_description); final TextView visibilityDescription = sendOsmPoiView.findViewById(R.id.visibility_description);
HorizontalSelectionAdapter horizontalSelectionAdapter = new HorizontalSelectionAdapter(getMyApplication(), nightMode); visibilityName.setText(selectedUploadVisibility.stringResource());
List<HorizontalSelectionAdapter.HorizontalSelectionItem> itemsVisibility = new ArrayList<>(); visibilityDescription.setText(selectedUploadVisibility.getDescriptionId());
for (OsmEditingPlugin.UploadVisibility visibilityType : OsmEditingPlugin.UploadVisibility.values()) {
String title = getMyApplication().getString(visibilityType.stringResource()); List<HorizontalSelectionItem> itemsVisibility = new ArrayList<>();
HorizontalSelectionAdapter.HorizontalSelectionItem item = new HorizontalSelectionAdapter.HorizontalSelectionItem(title, visibilityType); for (UploadVisibility visibilityType : UploadVisibility.values()) {
String title = getString(visibilityType.stringResource());
HorizontalSelectionItem item = new HorizontalSelectionAdapter.HorizontalSelectionItem(title, visibilityType);
itemsVisibility.add(item); itemsVisibility.add(item);
} }
final HorizontalSelectionAdapter horizontalSelectionAdapter = new HorizontalSelectionAdapter(getMyApplication(), nightMode);
horizontalSelectionAdapter.setItems(itemsVisibility); horizontalSelectionAdapter.setItems(itemsVisibility);
// horizontalSelectionAdapter.setSelectedItemByTitle(selectedVisibilityType); horizontalSelectionAdapter.setSelectedItemByTitle(getString(selectedUploadVisibility.stringResource()));
horizontalSelectionAdapter.setListener(new HorizontalSelectionAdapter.HorizontalSelectionAdapterListener() { horizontalSelectionAdapter.setListener(new HorizontalSelectionAdapterListener() {
@Override @Override
public void onItemSelected(HorizontalSelectionAdapter.HorizontalSelectionItem item) { public void onItemSelected(HorizontalSelectionAdapter.HorizontalSelectionItem item) {
uploadVisibility = (OsmEditingPlugin.UploadVisibility) item.getObject(); selectedUploadVisibility = (OsmEditingPlugin.UploadVisibility) item.getObject();
visibilityName.setText(uploadVisibility.stringResource()); visibilityName.setText(selectedUploadVisibility.stringResource());
visibilityDescription.setText(uploadVisibility.getDescriptionId()); visibilityDescription.setText(selectedUploadVisibility.getDescriptionId());
horizontalSelectionAdapter.notifyDataSetChanged();
} }
}); });
RecyclerView iconCategoriesRecyclerView = sendOsmPoiView.findViewById(R.id.description_view); RecyclerView iconCategoriesRecyclerView = sendOsmPoiView.findViewById(R.id.description_view);
iconCategoriesRecyclerView.setAdapter(horizontalSelectionAdapter); iconCategoriesRecyclerView.setAdapter(horizontalSelectionAdapter);
iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(getMyApplication(), RecyclerView.HORIZONTAL, false)); iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(getMyApplication(), RecyclerView.HORIZONTAL, false));
horizontalSelectionAdapter.notifyDataSetChanged(); horizontalSelectionAdapter.notifyDataSetChanged();
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
.setCustomView(sendOsmPoiView) .setCustomView(sendOsmPoiView)
.create(); .create();
items.add(titleItem); items.add(titleItem);
} }
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment targetFragment, final AvailableGPXFragment.GpxInfo... info) { private boolean isLoginOAuth() {
if (!fragmentManager.isStateSaved()) { return !Algorithms.isEmpty(getMyApplication().getSettings().USER_DISPLAY_NAME.get());
SendGpxBottomSheetFragment fragment = new SendGpxBottomSheetFragment();
fragment.setTargetFragment(targetFragment, 0);
fragment.show(fragmentManager, TAG);
}
} }
@Override @Override
@ -101,21 +115,30 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
return (UiUtilities.DialogButtonType.PRIMARY); 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 @Override
protected int getRightBottomButtonTextId() { protected int getRightBottomButtonTextId() {
return R.string.shared_string_upload; 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);
}
}
}