Add menu for selecting waypoint categories for import to markers
This commit is contained in:
parent
3a7d6a9626
commit
a58359b442
7 changed files with 187 additions and 85 deletions
|
@ -9,6 +9,8 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="select_waypoints_category_description">You can add all of the track\'s waypoints, or select separate categories.</string>
|
||||
<string name="shared_string_total">Total</string>
|
||||
<string name="clear_all_intermediates">Clear all intermediate points</string>
|
||||
<string name="group_deleted">Group deleted</string>
|
||||
<string name="rendering_attr_whiteWaterSports_name">Whitewater sports</string>
|
||||
|
|
|
@ -19,6 +19,10 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
|
|||
|
||||
private CompoundButton compoundButton;
|
||||
|
||||
public boolean isChecked() {
|
||||
return checked;
|
||||
}
|
||||
|
||||
public BottomSheetItemWithCompoundButton(View customView,
|
||||
@LayoutRes int layoutId,
|
||||
Object tag,
|
||||
|
|
|
@ -6,6 +6,7 @@ import net.osmand.plus.FavouritesDbHelper;
|
|||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
||||
import net.osmand.plus.mapmarkers.adapters.FavouritesGroupsAdapter;
|
||||
import net.osmand.plus.mapmarkers.adapters.GroupsAdapter;
|
||||
|
||||
public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomSheetDialogFragment {
|
||||
|
||||
|
@ -18,16 +19,17 @@ public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomS
|
|||
}
|
||||
|
||||
@Override
|
||||
public MarkersSyncGroup createMapMarkersSyncGroup(int position) {
|
||||
public GroupsAdapter createAdapter() {
|
||||
return new FavouritesGroupsAdapter(getContext(), favouritesDbHelper.getFavoriteGroups());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onItemClick(int position) {
|
||||
showProgressBar();
|
||||
FavoriteGroup group = favouritesDbHelper.getFavoriteGroups().get(position - 1);
|
||||
if (!group.visible) {
|
||||
favouritesDbHelper.editFavouriteGroup(group, group.name, group.color, true);
|
||||
}
|
||||
return new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAdapter() {
|
||||
adapter = new FavouritesGroupsAdapter(getContext(), favouritesDbHelper.getFavoriteGroups());
|
||||
addAndSyncGroup(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.mapmarkers;
|
|||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.ContextThemeWrapper;
|
||||
|
@ -18,20 +19,8 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
|
||||
public static final String TAG = "AddGroupBottomSheetDialogFragment";
|
||||
|
||||
private AddGroupListener listener;
|
||||
protected View mainView;
|
||||
protected GroupsAdapter adapter;
|
||||
protected MapMarkersHelper mapMarkersHelper;
|
||||
|
||||
public void setListener(AddGroupListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mapMarkersHelper = getMyApplication().getMapMarkersHelper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
|
@ -41,26 +30,14 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
|
||||
final RecyclerView recyclerView = mainView.findViewById(R.id.groups_recycler_view);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
createAdapter();
|
||||
adapter = createAdapter();
|
||||
adapter.setAdapterListener(new GroupsAdapter.GroupsAdapterListener() {
|
||||
@Override
|
||||
public void onItemClick(View view) {
|
||||
int position = recyclerView.getChildAdapterPosition(view);
|
||||
if (position == RecyclerView.NO_POSITION) {
|
||||
return;
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
AddGroupBottomSheetDialogFragment.this.onItemClick(position);
|
||||
}
|
||||
showProgressBar();
|
||||
MarkersSyncGroup group = createMapMarkersSyncGroup(position);
|
||||
mapMarkersHelper.addMarkersSyncGroup(group);
|
||||
mapMarkersHelper.syncGroupAsync(group, new MapMarkersHelper.OnGroupSyncedListener() {
|
||||
@Override
|
||||
public void onSyncDone() {
|
||||
if (listener != null) {
|
||||
listener.onGroupAdded();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
@ -82,16 +59,27 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
return false;
|
||||
}
|
||||
|
||||
private void showProgressBar() {
|
||||
protected void addAndSyncGroup(MarkersSyncGroup syncGroup) {
|
||||
MapMarkersHelper mapMarkersHelper = getMyApplication().getMapMarkersHelper();
|
||||
mapMarkersHelper.addMarkersSyncGroup(syncGroup);
|
||||
mapMarkersHelper.syncGroupAsync(syncGroup, new MapMarkersHelper.OnGroupSyncedListener() {
|
||||
@Override
|
||||
public void onSyncDone() {
|
||||
Fragment parent = getParentFragment();
|
||||
if (parent instanceof MapMarkersGroupsFragment) {
|
||||
((MapMarkersGroupsFragment) parent).updateAdapter();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void showProgressBar() {
|
||||
mainView.findViewById(R.id.groups_recycler_view).setVisibility(View.GONE);
|
||||
mainView.findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
protected abstract void createAdapter();
|
||||
protected abstract GroupsAdapter createAdapter();
|
||||
|
||||
protected abstract MarkersSyncGroup createMapMarkersSyncGroup(int position);
|
||||
|
||||
public interface AddGroupListener {
|
||||
void onGroupAdded();
|
||||
}
|
||||
protected abstract void onItemClick(int position);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.mapmarkers;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -20,6 +21,7 @@ import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
|||
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.mapmarkers.adapters.GroupsAdapter;
|
||||
import net.osmand.plus.mapmarkers.adapters.TracksGroupsAdapter;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -33,13 +35,6 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
|
|||
|
||||
private ProcessGpxTask asyncProcessor;
|
||||
private List<GpxDataItem> gpxList;
|
||||
private GpxSelectionHelper gpxSelectionHelper;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
gpxSelectionHelper = getMyApplication().getSelectedGpxHelper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
|
@ -48,24 +43,6 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
|
|||
asyncProcessor.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAdapter() {
|
||||
gpxList = new ArrayList<>();
|
||||
adapter = new TracksGroupsAdapter(getContext(), gpxList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkersSyncGroup createMapMarkersSyncGroup(int position) {
|
||||
GpxDataItem gpxDataItem = gpxList.get(position - 1);
|
||||
File gpx = gpxDataItem.getFile();
|
||||
SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(gpx.getAbsolutePath());
|
||||
if (selectedGpxFile == null) {
|
||||
GPXFile res = GPXUtilities.loadGPXFile(getContext(), gpx);
|
||||
gpxSelectionHelper.selectGpxFile(res, true, false, false);
|
||||
}
|
||||
return new MarkersSyncGroup(gpx.getAbsolutePath(), AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
@ -75,12 +52,48 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupsAdapter createAdapter() {
|
||||
gpxList = new ArrayList<>();
|
||||
return new TracksGroupsAdapter(getContext(), gpxList);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onItemClick(int position) {
|
||||
GpxDataItem dataItem = gpxList.get(position - 1);
|
||||
if (dataItem.getAnalysis().wptCategoryNames != null && dataItem.getAnalysis().wptCategoryNames.size() > 1) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(SelectWptCategoriesBottomSheetDialogFragment.GPX_FILE_PATH_KEY, dataItem.getFile().getAbsolutePath());
|
||||
|
||||
SelectWptCategoriesBottomSheetDialogFragment fragment = new SelectWptCategoriesBottomSheetDialogFragment();
|
||||
fragment.setArguments(args);
|
||||
fragment.setUsedOnMap(false);
|
||||
fragment.show(getParentFragment().getChildFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
|
||||
dismiss();
|
||||
} else {
|
||||
showProgressBar();
|
||||
addAndSyncGroup(createMapMarkersSyncGroup(getMyApplication(), dataItem));
|
||||
}
|
||||
}
|
||||
|
||||
public static MarkersSyncGroup createMapMarkersSyncGroup(OsmandApplication app, GpxDataItem gpxDataItem) {
|
||||
GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper();
|
||||
File gpx = gpxDataItem.getFile();
|
||||
SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(gpx.getAbsolutePath());
|
||||
if (selectedGpxFile == null) {
|
||||
GPXFile res = GPXUtilities.loadGPXFile(app, gpx);
|
||||
gpxSelectionHelper.selectGpxFile(res, true, false, false);
|
||||
}
|
||||
return new MarkersSyncGroup(gpx.getAbsolutePath(), AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public class ProcessGpxTask extends AsyncTask<Void, GpxDataItem, Void> {
|
||||
|
||||
private OsmandApplication app = getMyApplication();
|
||||
private Map<File, GpxDataItem> processedDataFiles = new HashMap<>();
|
||||
private GPXDatabase db = app.getGpxDatabase();
|
||||
private ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar);;
|
||||
private ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar);
|
||||
private RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.groups_recycler_view);
|
||||
private TextView lookingForTracksText = (TextView) mainView.findViewById(R.id.looking_for_tracks_text);
|
||||
|
||||
|
|
|
@ -69,10 +69,6 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
|
|||
if (selectionMarkersGroupFragment != null) {
|
||||
((SelectionMarkersGroupBottomSheetDialogFragment) selectionMarkersGroupFragment).setListener(createAddMarkersGroupFragmentListener());
|
||||
}
|
||||
Fragment addGroupFragment = getChildFragmentManager().findFragmentByTag(AddGroupBottomSheetDialogFragment.TAG);
|
||||
if (addGroupFragment != null) {
|
||||
((AddGroupBottomSheetDialogFragment) addGroupFragment).setListener(createAddGroupListener());
|
||||
}
|
||||
Fragment historyMarkerMenuFragment = getChildFragmentManager().findFragmentByTag(HistoryMarkerMenuBottomSheetDialogFragment.TAG);
|
||||
if (historyMarkerMenuFragment != null) {
|
||||
((HistoryMarkerMenuBottomSheetDialogFragment) historyMarkerMenuFragment).setListener(createHistoryMarkerMenuListener());
|
||||
|
@ -373,33 +369,21 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
|
|||
}
|
||||
|
||||
private void openAddGroupMenu(AddGroupBottomSheetDialogFragment fragment) {
|
||||
fragment.setListener(createAddGroupListener());
|
||||
fragment.setUsedOnMap(false);
|
||||
fragment.setRetainInstance(true);
|
||||
fragment.show(getChildFragmentManager(), AddGroupBottomSheetDialogFragment.TAG);
|
||||
}
|
||||
|
||||
private AddGroupBottomSheetDialogFragment.AddGroupListener createAddGroupListener() {
|
||||
return new AddGroupBottomSheetDialogFragment.AddGroupListener() {
|
||||
@Override
|
||||
public void onGroupAdded() {
|
||||
updateAdapter();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private AddMarkersGroupFragmentListener createAddMarkersGroupFragmentListener() {
|
||||
return new AddMarkersGroupFragmentListener() {
|
||||
@Override
|
||||
public void favouritesOnClick() {
|
||||
AddFavouritesGroupBottomSheetDialogFragment fragment = new AddFavouritesGroupBottomSheetDialogFragment();
|
||||
openAddGroupMenu(fragment);
|
||||
openAddGroupMenu(new AddFavouritesGroupBottomSheetDialogFragment());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waypointsOnClick() {
|
||||
AddTracksGroupBottomSheetDialogFragment fragment = new AddTracksGroupBottomSheetDialogFragment();
|
||||
openAddGroupMenu(fragment);
|
||||
openAddGroupMenu(new AddTracksGroupBottomSheetDialogFragment());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
package net.osmand.plus.mapmarkers;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = "SelectWptCategoriesBottomSheetDialogFragment";
|
||||
public static final String GPX_FILE_PATH_KEY = "gpx_file_path";
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
GPXFile gpxFile = getGpxFile();
|
||||
if (gpxFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
items.add(new TitleItem(getGpxName(gpxFile)));
|
||||
|
||||
items.add(new DescriptionItem(getString(R.string.select_waypoints_category_description)));
|
||||
|
||||
final BottomSheetItemWithCompoundButton[] selectAllItem = new BottomSheetItemWithCompoundButton[1];
|
||||
selectAllItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
|
||||
.setDescription(getString(R.string.shared_string_total) + ": " + gpxFile.getPoints().size())
|
||||
.setIcon(getContentIcon(R.drawable.ic_action_group_select_all))
|
||||
.setTitle(getString(R.string.shared_string_select_all))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
selectAllItem[0].setChecked(!selectAllItem[0].isChecked());
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(selectAllItem[0]);
|
||||
|
||||
items.add(new DividerItem(getContext()));
|
||||
|
||||
Map<String, List<WptPt>> pointsByCategories = gpxFile.getPointsByCategories();
|
||||
|
||||
for (String category : pointsByCategories.keySet()) {
|
||||
final BottomSheetItemWithCompoundButton[] categoryItem = new BottomSheetItemWithCompoundButton[1];
|
||||
categoryItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
|
||||
.setDescription(String.valueOf(pointsByCategories.get(category).size()))
|
||||
.setIcon(getContentIcon(R.drawable.ic_action_folder)) // todo
|
||||
.setTitle(category.equals("") ? getString(R.string.waypoints) : category)
|
||||
.setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp)
|
||||
.setTag(category)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
categoryItem[0].setChecked(!categoryItem[0].isChecked());
|
||||
Toast.makeText(getContext(), (String) v.getTag(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(categoryItem[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRightBottomButtonTextId() {
|
||||
return R.string.shared_string_import;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRightBottomButtonClick() {
|
||||
Toast.makeText(getContext(), "import", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private String getGpxName(GPXFile gpxFile) {
|
||||
return new File(gpxFile.path).getName()
|
||||
.replace(".gpx", "")
|
||||
.replace("/", " ")
|
||||
.replace("_", " ");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private GPXFile getGpxFile() {
|
||||
String filePath = getArguments().getString(GPX_FILE_PATH_KEY);
|
||||
if (filePath != null) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
SelectedGpxFile selectedGpx = app.getSelectedGpxHelper().getSelectedFileByPath(filePath);
|
||||
if (selectedGpx != null && selectedGpx.getGpxFile() != null) {
|
||||
return selectedGpx.getGpxFile();
|
||||
}
|
||||
return GPXUtilities.loadGPXFile(app, new File(filePath));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue