Add GPX waypoint action" Bottom Sheet
This commit is contained in:
parent
c6e8c0a7e6
commit
e1e3f17667
6 changed files with 138 additions and 94 deletions
|
@ -47,23 +47,4 @@
|
|||
tools:listitem="@layout/gpx_track_select_item">
|
||||
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/buttons_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingTop="@dimen/content_padding_small"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingBottom="@dimen/content_padding_small">
|
||||
|
||||
<include
|
||||
android:id="@+id/dismiss_button"
|
||||
layout="@layout/bottom_sheet_dialog_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
|
@ -2,7 +2,8 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/settings_divider_margin_start"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="@dimen/settings_divider_margin_start"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:orientation="horizontal">
|
||||
|
||||
|
@ -21,7 +22,7 @@
|
|||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/list_content_padding"
|
||||
android:layout_marginLeft="@dimen/list_content_padding"
|
||||
android:layout_marginEnd="@dimen/list_content_padding"
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.osmand.AndroidUtils;
|
|||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.plus.GPXDatabase;
|
||||
import net.osmand.plus.GpxDbHelper;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -35,11 +36,8 @@ public class GpxTrackAdapter extends RecyclerView.Adapter<GpxTrackAdapter.TrackV
|
|||
private OnItemClickListener onItemClickListener;
|
||||
private UiUtilities iconsCache;
|
||||
|
||||
|
||||
GpxTrackAdapter(Activity activity, List<GpxUiHelper.GPXInfo> gpxInfoList, boolean showCurrentGpx,
|
||||
OnItemClickListener onItemClickListener) {
|
||||
GpxTrackAdapter(Activity activity, List<GpxUiHelper.GPXInfo> gpxInfoList, boolean showCurrentGpx) {
|
||||
this.showCurrentGpx = showCurrentGpx;
|
||||
this.onItemClickListener = onItemClickListener;
|
||||
app = (OsmandApplication) activity.getApplication();
|
||||
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
|
||||
themedInflater = UiUtilities.getInflater(activity, nightMode);
|
||||
|
@ -123,8 +121,26 @@ public class GpxTrackAdapter extends RecyclerView.Adapter<GpxTrackAdapter.TrackV
|
|||
}
|
||||
}
|
||||
|
||||
private GPXDatabase.GpxDataItem getDataItem(GpxUiHelper.GPXInfo info) {
|
||||
return app.getGpxDbHelper().getItem(new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), info.getFileName()));
|
||||
private GPXDatabase.GpxDataItem getDataItem(final GpxUiHelper.GPXInfo info) {
|
||||
GpxDbHelper.GpxDataItemCallback gpxDataItemCallback = new GpxDbHelper.GpxDataItemCallback() {
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGpxDataItemReady(GPXDatabase.GpxDataItem item) {
|
||||
if (item != null && gpxInfoList != null && info != null) {
|
||||
notifyItemChanged(gpxInfoList.indexOf(info));
|
||||
}
|
||||
}
|
||||
};
|
||||
return app.getGpxDbHelper().getItem(new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), info.getFileName())
|
||||
, gpxDataItemCallback);
|
||||
}
|
||||
|
||||
void setAdapterListener(OnItemClickListener onItemClickListener) {
|
||||
this.onItemClickListener = onItemClickListener;
|
||||
}
|
||||
|
||||
static class TrackViewHolder extends RecyclerView.ViewHolder {
|
||||
|
|
|
@ -37,8 +37,6 @@ import androidx.appcompat.widget.ListPopupWindow;
|
|||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.github.mikephil.charting.charts.HorizontalBarChart;
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
|
@ -259,7 +257,7 @@ public class GpxUiHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static AlertDialog selectSingleGPXFile(final Activity activity, boolean showCurrentGpx,
|
||||
public static void selectSingleGPXFile(final MapActivity activity, boolean showCurrentGpx,
|
||||
final CallbackWithObject<GPXFile[]> callbackWithObject) {
|
||||
OsmandApplication app = (OsmandApplication) activity.getApplication();
|
||||
int gpxDirLength = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getAbsolutePath().length();
|
||||
|
@ -279,11 +277,8 @@ public class GpxUiHelper {
|
|||
list.add(new GPXInfo(gpxFile.path.substring(gpxDirLength + 1), gpxFile.modifiedTime, 0));
|
||||
}
|
||||
}
|
||||
|
||||
final ContextMenuAdapter adapter = createGpxContextMenuAdapter(list, null, showCurrentGpx);
|
||||
return createSingleChoiceDialog(activity, showCurrentGpx, callbackWithObject, list, adapter);
|
||||
SelectGpxTrackBottomSheet.showInstance(activity, showCurrentGpx, callbackWithObject, list);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ContextMenuAdapter createGpxContextMenuAdapter(List<GPXInfo> allGpxList,
|
||||
|
@ -350,65 +345,6 @@ public class GpxUiHelper {
|
|||
}, dir, null, filename);
|
||||
}
|
||||
|
||||
private static AlertDialog createSingleChoiceDialog(final Activity activity,
|
||||
final boolean showCurrentGpx,
|
||||
final CallbackWithObject<GPXFile[]> callbackWithObject,
|
||||
final List<GPXInfo> list,
|
||||
final ContextMenuAdapter adapter) {
|
||||
final OsmandApplication app = (OsmandApplication) activity.getApplication();
|
||||
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
|
||||
final View customLayout = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.gpx_track_select_dialog, null);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(activity, nightMode));
|
||||
builder.setView(customLayout);
|
||||
final AlertDialog dlg = builder.create();
|
||||
View cancelButton = customLayout.findViewById(R.id.dismiss_button);
|
||||
UiUtilities.setupDialogButton(nightMode, cancelButton, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_cancel);
|
||||
TextView gpxCounter = customLayout.findViewById(R.id.counter);
|
||||
gpxCounter.setText(String.valueOf(adapter.length()));
|
||||
GpxTrackAdapter gpxTrackAdapter = new GpxTrackAdapter(activity, list, showCurrentGpx,
|
||||
new GpxTrackAdapter.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(int position) {
|
||||
if (position != -1 && position < list.size()) {
|
||||
if (showCurrentGpx && position == 0) {
|
||||
callbackWithObject.processResult(null);
|
||||
app.getSettings().LAST_SELECTED_GPX_TRACK_FOR_NEW_POINT.set(null);
|
||||
} else {
|
||||
String fileName = list.get(position).getFileName();
|
||||
app.getSettings().LAST_SELECTED_GPX_TRACK_FOR_NEW_POINT.set(fileName);
|
||||
SelectedGpxFile selectedGpxFile =
|
||||
app.getSelectedGpxHelper().getSelectedFileByName(fileName);
|
||||
if (selectedGpxFile != null) {
|
||||
callbackWithObject.processResult(new GPXUtilities.GPXFile[]{selectedGpxFile.getGpxFile()});
|
||||
} else {
|
||||
File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
|
||||
GpxUiHelper.loadGPXFileInDifferentThread(activity, callbackWithObject, dir, null, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
dlg.dismiss();
|
||||
}
|
||||
});
|
||||
RecyclerView recyclerView = customLayout.findViewById(R.id.gpx_track_list);
|
||||
recyclerView.setAdapter(gpxTrackAdapter);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(app, LinearLayoutManager.VERTICAL, false));
|
||||
dlg.setCanceledOnTouchOutside(false);
|
||||
dlg.show();
|
||||
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dlg.dismiss();
|
||||
}
|
||||
});
|
||||
try {
|
||||
dlg.getListView().setFastScrollEnabled(true);
|
||||
} catch (Exception e) {
|
||||
// java.lang.ClassCastException: com.android.internal.widget.RoundCornerListAdapter
|
||||
// Unknown reason but on some devices fail
|
||||
}
|
||||
return dlg;
|
||||
}
|
||||
|
||||
private static class DialogGpxDataItemCallback implements GpxDataItemCallback {
|
||||
private static final int UPDATE_GPX_ITEM_MSG_ID = OsmAndConstants.UI_HANDLER_LOCATION_SERVICE + 6;
|
||||
private static final long MIN_UPDATE_INTERVAL = 500;
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
package net.osmand.plus.helpers;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class SelectGpxTrackBottomSheet extends MenuBottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = "SelectGpxTrackBottomSheet";
|
||||
|
||||
protected View mainView;
|
||||
protected GpxTrackAdapter adapter;
|
||||
|
||||
private List<GpxUiHelper.GPXInfo> gpxInfoList;
|
||||
private OsmandApplication app;
|
||||
private boolean showCurrentGpx;
|
||||
private CallbackWithObject<GPXUtilities.GPXFile[]> callbackWithObject;
|
||||
private Activity activity;
|
||||
|
||||
private SelectGpxTrackBottomSheet(Activity activity, boolean showCurrentGpx, CallbackWithObject<GPXUtilities.GPXFile[]> callbackWithObject,
|
||||
List<GpxUiHelper.GPXInfo> gpxInfoList) {
|
||||
super();
|
||||
app = (OsmandApplication) activity.getApplication();
|
||||
this.activity = activity;
|
||||
this.showCurrentGpx = showCurrentGpx;
|
||||
this.gpxInfoList = gpxInfoList;
|
||||
this.callbackWithObject = callbackWithObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
||||
R.layout.gpx_track_select_dialog, null);
|
||||
|
||||
final RecyclerView recyclerView = mainView.findViewById(R.id.gpx_track_list);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
adapter = createAdapter();
|
||||
adapter.setAdapterListener(new GpxTrackAdapter.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(int position) {
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
SelectGpxTrackBottomSheet.this.onItemClick(position);
|
||||
}
|
||||
}
|
||||
});
|
||||
recyclerView.setAdapter(adapter);
|
||||
TextView gpxCounter = mainView.findViewById(R.id.counter);
|
||||
gpxCounter.setText(String.valueOf(adapter.getItemCount()));
|
||||
items.add(new BaseBottomSheetItem.Builder().setCustomView(mainView).create());
|
||||
}
|
||||
|
||||
private GpxTrackAdapter createAdapter() {
|
||||
return new GpxTrackAdapter(activity, gpxInfoList, showCurrentGpx);
|
||||
}
|
||||
|
||||
private void onItemClick(int position) {
|
||||
if (position != -1 && position < gpxInfoList.size()) {
|
||||
if (showCurrentGpx && position == 0) {
|
||||
callbackWithObject.processResult(null);
|
||||
app.getSettings().LAST_SELECTED_GPX_TRACK_FOR_NEW_POINT.set(null);
|
||||
} else {
|
||||
String fileName = gpxInfoList.get(position).getFileName();
|
||||
app.getSettings().LAST_SELECTED_GPX_TRACK_FOR_NEW_POINT.set(fileName);
|
||||
GpxSelectionHelper.SelectedGpxFile selectedGpxFile =
|
||||
app.getSelectedGpxHelper().getSelectedFileByName(fileName);
|
||||
if (selectedGpxFile != null) {
|
||||
callbackWithObject.processResult(new GPXUtilities.GPXFile[]{selectedGpxFile.getGpxFile()});
|
||||
} else {
|
||||
File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
|
||||
GpxUiHelper.loadGPXFileInDifferentThread(activity, callbackWithObject, dir, null, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
public static void showInstance(MapActivity mapActivity, boolean showCurrentGpx,
|
||||
CallbackWithObject<GPXUtilities.GPXFile[]> callbackWithObject, List<GpxUiHelper.GPXInfo> gpxInfoList) {
|
||||
SelectGpxTrackBottomSheet fragment = new SelectGpxTrackBottomSheet(mapActivity, showCurrentGpx, callbackWithObject, gpxInfoList);
|
||||
fragment.setUsedOnMap(true);
|
||||
fragment.setRetainInstance(true);
|
||||
fragment.show(mapActivity.getSupportFragmentManager(), SelectGpxTrackBottomSheet.TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDismissButtonTextId() {
|
||||
return R.string.shared_string_cancel;
|
||||
}
|
||||
|
||||
}
|
|
@ -625,6 +625,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
|
|||
}
|
||||
|
||||
public void dismiss(boolean includingMenu) {
|
||||
hideKeyboard();
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
if (includingMenu) {
|
||||
|
|
Loading…
Reference in a new issue