Add SelectTrackToFollowCard
This commit is contained in:
parent
2bd533e496
commit
040de95f9a
4 changed files with 204 additions and 7 deletions
40
OsmAnd/res/layout/follow_track_card.xml
Normal file
40
OsmAnd/res/layout/follow_track_card.xml
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/prev_route_card"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/top_divider"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_marginStart="@dimen/content_padding"
|
||||||
|
android:layout_marginLeft="@dimen/content_padding"
|
||||||
|
android:background="?attr/divider_color_basic"
|
||||||
|
android:focusable="false" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/group_name_recycler_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingLeft="@dimen/content_padding"
|
||||||
|
android:paddingTop="@dimen/content_padding_half"
|
||||||
|
android:paddingRight="@dimen/content_padding"
|
||||||
|
android:paddingBottom="@dimen/content_padding_half"
|
||||||
|
tools:itemCount="3"
|
||||||
|
tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
|
tools:listitem="@layout/point_editor_icon_category_item" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/items"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/card_and_list_background_basic"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingBottom="@dimen/route_info_button_go_margin" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -21,6 +21,7 @@ import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.MapActivityLayers;
|
import net.osmand.plus.activities.MapActivityLayers;
|
||||||
import net.osmand.plus.activities.PluginActivity;
|
import net.osmand.plus.activities.PluginActivity;
|
||||||
|
import net.osmand.plus.helpers.GpxUiHelper;
|
||||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||||
import net.osmand.plus.poi.PoiUIFilter;
|
import net.osmand.plus.poi.PoiUIFilter;
|
||||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||||
|
@ -29,7 +30,6 @@ import net.osmand.plus.transport.TransportLinesMenu;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -47,10 +47,7 @@ final class MapLayerMenuListener extends OnRowItemClick {
|
||||||
GpxSelectionHelper selectedGpxHelper = mapActivity.getMyApplication().getSelectedGpxHelper();
|
GpxSelectionHelper selectedGpxHelper = mapActivity.getMyApplication().getSelectedGpxHelper();
|
||||||
List<SelectedGpxFile> selectedGpxFiles = selectedGpxHelper.getSelectedGPXFiles();
|
List<SelectedGpxFile> selectedGpxFiles = selectedGpxHelper.getSelectedGPXFiles();
|
||||||
|
|
||||||
List<String> files = new ArrayList<>();
|
List<String> files = GpxUiHelper.getSelectedTrackNames(mapActivity.getMyApplication());
|
||||||
for (SelectedGpxFile file : selectedGpxFiles) {
|
|
||||||
files.add(file.getGpxFile().path);
|
|
||||||
}
|
|
||||||
if (selectedGpxFiles.isEmpty()) {
|
if (selectedGpxFiles.isEmpty()) {
|
||||||
Map<GPXFile, Long> fls = selectedGpxHelper.getSelectedGpxFilesBackUp();
|
Map<GPXFile, Long> fls = selectedGpxHelper.getSelectedGpxFilesBackUp();
|
||||||
for (Map.Entry<GPXFile, Long> f : fls.entrySet()) {
|
for (Map.Entry<GPXFile, Long> f : fls.entrySet()) {
|
||||||
|
|
|
@ -810,6 +810,14 @@ public class GpxUiHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> getSelectedTrackNames(OsmandApplication app) {
|
||||||
|
List<String> trackNames = new ArrayList<>();
|
||||||
|
for (SelectedGpxFile file : app.getSelectedGpxHelper().getSelectedGPXFiles()) {
|
||||||
|
trackNames.add(file.getGpxFile().path);
|
||||||
|
}
|
||||||
|
return trackNames;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<GPXInfo> getSortedGPXFilesInfoByDate(File dir, boolean absolutePath) {
|
public static List<GPXInfo> getSortedGPXFilesInfoByDate(File dir, boolean absolutePath) {
|
||||||
final List<GPXInfo> list = new ArrayList<>();
|
final List<GPXInfo> list = new ArrayList<>();
|
||||||
readGpxDirectory(dir, list, "", absolutePath);
|
readGpxDirectory(dir, list, "", absolutePath);
|
||||||
|
@ -913,8 +921,7 @@ public class GpxUiHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void loadGPXFileInDifferentThread(final Activity activity, final CallbackWithObject<GPXFile[]> callbackWithObject,
|
||||||
static void loadGPXFileInDifferentThread(final Activity activity, final CallbackWithObject<GPXFile[]> callbackWithObject,
|
|
||||||
final File dir, final GPXFile currentFile, final String... filename) {
|
final File dir, final GPXFile currentFile, final String... filename) {
|
||||||
final ProgressDialog dlg = ProgressDialog.show(activity, activity.getString(R.string.loading_smth, ""),
|
final ProgressDialog dlg = ProgressDialog.show(activity, activity.getString(R.string.loading_smth, ""),
|
||||||
activity.getString(R.string.loading_data));
|
activity.getString(R.string.loading_data));
|
||||||
|
|
|
@ -0,0 +1,153 @@
|
||||||
|
package net.osmand.plus.routepreparationmenu.cards;
|
||||||
|
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.CallbackWithObject;
|
||||||
|
import net.osmand.IndexConstants;
|
||||||
|
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.UiUtilities;
|
||||||
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.helpers.GpxUiHelper;
|
||||||
|
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
||||||
|
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SelectTrackToFollowCard extends BaseCard {
|
||||||
|
|
||||||
|
private Map<String, List<GPXInfo>> data;
|
||||||
|
|
||||||
|
private List<GPXInfo> gpxInfoList;
|
||||||
|
private String selectedCategory;
|
||||||
|
private CallbackWithObject<GPXInfo> gpxInfoCallback;
|
||||||
|
|
||||||
|
public SelectTrackToFollowCard(MapActivity mapActivity, List<GPXInfo> gpxInfoList) {
|
||||||
|
super(mapActivity);
|
||||||
|
this.gpxInfoList = gpxInfoList;
|
||||||
|
data = getGpxInfoCategories();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGpxInfoCallback(CallbackWithObject<GPXInfo> gpxInfoCallback) {
|
||||||
|
this.gpxInfoCallback = gpxInfoCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCardLayoutId() {
|
||||||
|
return R.layout.follow_track_card;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateContent() {
|
||||||
|
setupCategoriesRow();
|
||||||
|
setupTracksItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupTracksItems() {
|
||||||
|
LinearLayout tracks = view.findViewById(R.id.items);
|
||||||
|
tracks.removeAllViews();
|
||||||
|
|
||||||
|
final List<GPXInfo> infoItems = data.get(selectedCategory);
|
||||||
|
if (!Algorithms.isEmpty(infoItems)) {
|
||||||
|
int minCardHeight = app.getResources().getDimensionPixelSize(R.dimen.route_info_card_row_min_height);
|
||||||
|
int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding);
|
||||||
|
|
||||||
|
LayoutInflater inflater = UiUtilities.getInflater(mapActivity, nightMode);
|
||||||
|
for (int i = 0; i < infoItems.size(); i++) {
|
||||||
|
final GPXInfo item = infoItems.get(i);
|
||||||
|
View trackView = inflater.inflate(R.layout.gpx_track_item, tracks, false);
|
||||||
|
|
||||||
|
String fileName = Algorithms.getFileWithoutDirs(item.getFileName());
|
||||||
|
String title = GpxUiHelper.getGpxTitle(fileName);
|
||||||
|
GpxDataItem dataItem = getDataItem(item);
|
||||||
|
GpxUiHelper.updateGpxInfoView(trackView, title, item, dataItem, false, app);
|
||||||
|
|
||||||
|
ImageView icon = trackView.findViewById(R.id.icon);
|
||||||
|
icon.setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark));
|
||||||
|
icon.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
LinearLayout container = trackView.findViewById(R.id.container);
|
||||||
|
container.setMinimumHeight(minCardHeight);
|
||||||
|
AndroidUtils.setPadding(container, contentPadding, 0, 0, 0);
|
||||||
|
trackView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (gpxInfoCallback != null) {
|
||||||
|
gpxInfoCallback.processResult(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tracks.addView(trackView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private GpxDataItem getDataItem(GPXInfo info) {
|
||||||
|
return app.getGpxDbHelper().getItem(new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), info.getFileName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupCategoriesRow() {
|
||||||
|
final HorizontalSelectionAdapter selectionAdapter = new HorizontalSelectionAdapter(app, nightMode);
|
||||||
|
selectionAdapter.setItems(new ArrayList<>(data.keySet()));
|
||||||
|
selectionAdapter.setSelectedItem(selectedCategory);
|
||||||
|
selectionAdapter.setListener(new HorizontalSelectionAdapter.HorizontalSelectionAdapterListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemSelected(String item) {
|
||||||
|
setSelectedCategory(item);
|
||||||
|
selectionAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
RecyclerView iconCategoriesRecyclerView = view.findViewById(R.id.group_name_recycler_view);
|
||||||
|
iconCategoriesRecyclerView.setAdapter(selectionAdapter);
|
||||||
|
iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false));
|
||||||
|
selectionAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setSelectedCategory(String category) {
|
||||||
|
selectedCategory = category;
|
||||||
|
setupTracksItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, List<GPXInfo>> getGpxInfoCategories() {
|
||||||
|
String all = app.getString(R.string.shared_string_all);
|
||||||
|
String visible = app.getString(R.string.shared_string_visible);
|
||||||
|
Map<String, List<GPXInfo>> gpxInfoCategories = new LinkedHashMap<>();
|
||||||
|
for (GPXInfo info : gpxInfoList) {
|
||||||
|
if (info.isSelected()) {
|
||||||
|
addGpxInfoCategory(gpxInfoCategories, info, visible);
|
||||||
|
}
|
||||||
|
if (!Algorithms.isEmpty(info.getFileName())) {
|
||||||
|
File file = new File(info.getFileName());
|
||||||
|
String dirName = file.getParent();
|
||||||
|
if (dirName != null && !IndexConstants.GPX_INDEX_DIR.equals(dirName)) {
|
||||||
|
addGpxInfoCategory(gpxInfoCategories, info, dirName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addGpxInfoCategory(gpxInfoCategories, info, all);
|
||||||
|
}
|
||||||
|
|
||||||
|
return gpxInfoCategories;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addGpxInfoCategory(Map<String, List<GPXInfo>> data, GPXInfo info, String category) {
|
||||||
|
List<GPXInfo> items = data.get(category);
|
||||||
|
if (items == null) {
|
||||||
|
items = new ArrayList<>();
|
||||||
|
data.put(category, items);
|
||||||
|
}
|
||||||
|
items.add(info);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue