Merge branch 'r3.3'
This commit is contained in:
commit
b892082d71
3 changed files with 95 additions and 43 deletions
|
@ -244,7 +244,9 @@ public class GpxSelectionHelper {
|
|||
if (g.tracks.size() > 0) {
|
||||
for (int i = 0; i < g.tracks.size(); i++) {
|
||||
GpxDisplayGroup group = buildGpxDisplayGroup(g, i, name);
|
||||
dg.add(group);
|
||||
if (group.getModifiableList().size() > 0) {
|
||||
dg.add(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (g.routes.size() > 0) {
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.io.File;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
@ -362,6 +363,31 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
|||
} while (query.moveToNext());
|
||||
}
|
||||
query.close();
|
||||
|
||||
// drop empty tracks
|
||||
List<String> datesToRemove = new ArrayList<>();
|
||||
for (Map.Entry<String, GPXFile> entry : dataTracks.entrySet()) {
|
||||
GPXFile file = entry.getValue();
|
||||
Iterator<Track> it = file.tracks.iterator();
|
||||
while (it.hasNext()) {
|
||||
Track t = it.next();
|
||||
Iterator<TrkSegment> its = t.segments.iterator();
|
||||
while (its.hasNext()) {
|
||||
if (its.next().points.size() == 0) {
|
||||
its.remove();
|
||||
}
|
||||
}
|
||||
if (t.segments.size() == 0) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
if (file.tracks.size() == 0) {
|
||||
datesToRemove.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
for (String date : datesToRemove) {
|
||||
dataTracks.remove(date);
|
||||
}
|
||||
}
|
||||
|
||||
public void startNewSegment() {
|
||||
|
|
|
@ -26,17 +26,17 @@ import android.widget.ProgressBar;
|
|||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.GPXUtilities.GPXTrackAnalysis;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
|
||||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
|
||||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.TrackActivity;
|
||||
import net.osmand.plus.helpers.FontCache;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -72,7 +72,8 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
app = getMyApplication();
|
||||
TrackActivity trackActivity = requireTrackActivity();
|
||||
app = trackActivity.getMyApplication();
|
||||
ic = app.getUIUtilities();
|
||||
boolean isLightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
|
||||
int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
|
||||
|
@ -82,21 +83,23 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
TrackActivity trackActivity = requireTrackActivity();
|
||||
listView.setBackgroundColor(getResources().getColor(
|
||||
getMyApplication().getSettings().isLightContent() ? R.color.ctx_menu_info_view_bg_light
|
||||
trackActivity.getMyApplication().getSettings().isLightContent() ? R.color.ctx_menu_info_view_bg_light
|
||||
: R.color.ctx_menu_info_view_bg_dark));
|
||||
getTrackActivity().onAttachFragment(this);
|
||||
trackActivity.onAttachFragment(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
minMaxSpeedPaint = new Paint();
|
||||
minMaxSpeedPaint.setTextSize(getResources().getDimension(R.dimen.default_split_segments_data));
|
||||
minMaxSpeedPaint.setTypeface(FontCache.getFont(getContext(), "fonts/Roboto-Medium.ttf"));
|
||||
minMaxSpeedPaint.setStyle(Paint.Style.FILL);
|
||||
minMaxSpeedTextBounds = new Rect();
|
||||
|
||||
final View view = getActivity().getLayoutInflater().inflate(R.layout.split_segments_layout, container, false);
|
||||
TrackActivity trackActivity = requireTrackActivity();
|
||||
final View view = trackActivity.getLayoutInflater().inflate(R.layout.split_segments_layout, container, false);
|
||||
|
||||
Toolbar toolbar = (Toolbar) view.findViewById(R.id.split_interval_toolbar);
|
||||
TextView titleTextView = (TextView) toolbar.findViewById(R.id.title);
|
||||
|
@ -105,11 +108,11 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
} else {
|
||||
titleTextView.setTextAppearance(getContext(), R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);
|
||||
}
|
||||
ActionBar trackActivityActionBar = getTrackActivity().getSupportActionBar();
|
||||
ActionBar trackActivityActionBar = trackActivity.getSupportActionBar();
|
||||
if (trackActivityActionBar != null) {
|
||||
titleTextView.setText(trackActivityActionBar.getTitle());
|
||||
}
|
||||
toolbar.setNavigationIcon(getMyApplication().getUIUtilities().getIcon(R.drawable.ic_arrow_back));
|
||||
toolbar.setNavigationIcon(ic.getIcon(R.drawable.ic_arrow_back));
|
||||
toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -128,8 +131,8 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
headerView = view.findViewById(R.id.header_layout);
|
||||
((ImageView) headerView.findViewById(R.id.header_split_image)).setImageDrawable(ic.getIcon(R.drawable.ic_action_split_interval, app.getSettings().isLightContent() ? R.color.icon_color : 0));
|
||||
|
||||
listView.addHeaderView(getActivity().getLayoutInflater().inflate(R.layout.gpx_split_segments_empty_header, null, false));
|
||||
listView.addFooterView(getActivity().getLayoutInflater().inflate(R.layout.list_shadow_footer, null, false));
|
||||
listView.addHeaderView(trackActivity.getLayoutInflater().inflate(R.layout.gpx_split_segments_empty_header, null, false));
|
||||
listView.addFooterView(trackActivity.getLayoutInflater().inflate(R.layout.list_shadow_footer, null, false));
|
||||
|
||||
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
int previousYPos = -1;
|
||||
|
@ -170,7 +173,7 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
updateContent();
|
||||
}
|
||||
|
@ -187,21 +190,21 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
splitIntervalView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final ListPopupWindow popup = new ListPopupWindow(getActivity());
|
||||
final ListPopupWindow popup = new ListPopupWindow(v.getContext());
|
||||
popup.setAnchorView(splitIntervalView);
|
||||
popup.setContentWidth(AndroidUtils.dpToPx(app, 200f));
|
||||
popup.setModal(true);
|
||||
popup.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
|
||||
popup.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
|
||||
popup.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
|
||||
popup.setAdapter(new ArrayAdapter<>(getTrackActivity(),
|
||||
popup.setAdapter(new ArrayAdapter<>(v.getContext(),
|
||||
R.layout.popup_list_text_item, options));
|
||||
popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
selectedSplitInterval = position;
|
||||
GpxSelectionHelper.SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), true, false);
|
||||
SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), true, false);
|
||||
final List<GpxDisplayGroup> groups = getDisplayGroups();
|
||||
if (groups.size() > 0) {
|
||||
updateSplit(groups, sf);
|
||||
|
@ -234,11 +237,11 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private void updateSplit(List<GpxDisplayGroup> groups, GpxSelectionHelper.SelectedGpxFile sf) {
|
||||
private void updateSplit(@NonNull List<GpxDisplayGroup> groups, @Nullable SelectedGpxFile sf) {
|
||||
new SplitTrackAsyncTask(sf, groups).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
|
||||
}
|
||||
|
||||
private void setupSplitIntervalView(View view) {
|
||||
private void setupSplitIntervalView(@NonNull View view) {
|
||||
final TextView title = (TextView) view.findViewById(R.id.split_interval_title);
|
||||
final TextView text = (TextView) view.findViewById(R.id.split_interval_text);
|
||||
final ImageView img = (ImageView) view.findViewById(R.id.split_interval_arrow);
|
||||
|
@ -254,7 +257,7 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
int color = app.getResources().getColor(colorId);
|
||||
title.setTextColor(color);
|
||||
text.setTextColor(color);
|
||||
img.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_arrow_drop_down, colorId));
|
||||
img.setImageDrawable(ic.getIcon(R.drawable.ic_action_arrow_drop_down, colorId));
|
||||
}
|
||||
|
||||
private void updateSplitIntervalView(View view) {
|
||||
|
@ -266,14 +269,22 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private GPXUtilities.GPXFile getGpx() {
|
||||
return getTrackActivity().getGpx();
|
||||
@Nullable
|
||||
private GPXFile getGpx() {
|
||||
TrackActivity trackActivity = getTrackActivity();
|
||||
return trackActivity != null ? trackActivity.getGpx() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TrackActivity getTrackActivity() {
|
||||
return (TrackActivity) getActivity();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public TrackActivity requireTrackActivity() {
|
||||
return (TrackActivity) requireActivity();
|
||||
}
|
||||
|
||||
private void prepareSplitIntervalAdapterData() {
|
||||
final List<GpxDisplayGroup> groups = getDisplayGroups();
|
||||
|
||||
|
@ -307,6 +318,7 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
addOptionSplit(3600, false, groups);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private List<GpxDisplayGroup> getDisplayGroups() {
|
||||
return filterGroups(true);
|
||||
}
|
||||
|
@ -336,6 +348,7 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private List<GpxDisplayGroup> filterGroups(boolean useDisplayGroups) {
|
||||
List<GpxDisplayGroup> groups = new ArrayList<>();
|
||||
if (getTrackActivity() != null) {
|
||||
|
@ -351,22 +364,30 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
return groups;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private List<GpxDisplayItem> getSplitSegments() {
|
||||
List<GpxDisplayGroup> result = getTrackActivity().getGpxFile(true);
|
||||
TrackActivity trackActivity = getTrackActivity();
|
||||
List<GpxDisplayItem> splitSegments = new ArrayList<>();
|
||||
if (result != null && result.size() > 0) {
|
||||
if (result.get(0).isSplitDistance() || result.get(0).isSplitTime()) {
|
||||
splitSegments.addAll(result.get(0).getModifiableList());
|
||||
if (trackActivity != null) {
|
||||
List<GpxDisplayGroup> result = trackActivity.getGpxFile(true);
|
||||
if (result != null && result.size() > 0) {
|
||||
if (result.get(0).isSplitDistance() || result.get(0).isSplitTime()) {
|
||||
splitSegments.addAll(result.get(0).getModifiableList());
|
||||
}
|
||||
}
|
||||
}
|
||||
return splitSegments;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private GpxDisplayItem getOverviewSegment() {
|
||||
List<GpxDisplayGroup> result = getTrackActivity().getGpxFile(false);
|
||||
TrackActivity trackActivity = getTrackActivity();
|
||||
GpxDisplayItem overviewSegment = null;
|
||||
if (result.size() > 0) {
|
||||
overviewSegment = result.get(0).getModifiableList().get(0);
|
||||
if (trackActivity != null) {
|
||||
List<GpxDisplayGroup> result = trackActivity.getGpxFile(false);
|
||||
if (result.size() > 0 && result.get(0).getModifiableList().size() > 0) {
|
||||
overviewSegment = result.get(0).getModifiableList().get(0);
|
||||
}
|
||||
}
|
||||
return overviewSegment;
|
||||
}
|
||||
|
@ -382,20 +403,26 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
getTrackActivity().updateSplitView();
|
||||
TrackActivity trackActivity = getTrackActivity();
|
||||
if (trackActivity != null) {
|
||||
trackActivity.updateSplitView();
|
||||
}
|
||||
super.dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
getTrackActivity().updateSplitView();
|
||||
TrackActivity trackActivity = getTrackActivity();
|
||||
if (trackActivity != null) {
|
||||
trackActivity.updateSplitView();
|
||||
}
|
||||
super.onCancel(dialog);
|
||||
}
|
||||
|
||||
private class SplitSegmentsAdapter extends ArrayAdapter<GpxDisplayItem> {
|
||||
|
||||
SplitSegmentsAdapter(List<GpxDisplayItem> items) {
|
||||
super(getActivity(), 0, items);
|
||||
super(requireActivity(), 0, items);
|
||||
}
|
||||
|
||||
ColorStateList defaultTextColor;
|
||||
|
@ -404,8 +431,9 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
@Override
|
||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
GpxDisplayItem currentGpxDisplayItem = getItem(position);
|
||||
TrackActivity trackActivity = requireTrackActivity();
|
||||
if (convertView == null) {
|
||||
convertView = getTrackActivity().getLayoutInflater().inflate(R.layout.gpx_split_segment_fragment, parent, false);
|
||||
convertView = trackActivity.getLayoutInflater().inflate(R.layout.gpx_split_segment_fragment, parent, false);
|
||||
}
|
||||
convertView.setOnClickListener(null);
|
||||
TextView overviewTextView = (TextView) convertView.findViewById(R.id.overview_text);
|
||||
|
@ -588,12 +616,12 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
|
||||
if (minMaxSpeedLayoutWidth == 0) {
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
trackActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
int screenWidth = metrics.widthPixels;
|
||||
int widthWithoutSidePadding = screenWidth - AndroidUtils.dpToPx(getActivity(), 32);
|
||||
int widthWithoutSidePadding = screenWidth - AndroidUtils.dpToPx(trackActivity, 32);
|
||||
int singleLayoutWidth = widthWithoutSidePadding / 3;
|
||||
int twoLayouts = 2 * (singleLayoutWidth + AndroidUtils.dpToPx(getActivity(), 3));
|
||||
minMaxSpeedLayoutWidth = widthWithoutSidePadding - twoLayouts - AndroidUtils.dpToPx(getActivity(), 28);
|
||||
int twoLayouts = 2 * (singleLayoutWidth + AndroidUtils.dpToPx(trackActivity, 3));
|
||||
minMaxSpeedLayoutWidth = widthWithoutSidePadding - twoLayouts - AndroidUtils.dpToPx(trackActivity, 28);
|
||||
}
|
||||
|
||||
minMaxSpeedPaint.getTextBounds(maxMinSpeed, 0, maxMinSpeed.length(), minMaxSpeedTextBounds);
|
||||
|
@ -647,11 +675,11 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
|
||||
private class SplitTrackAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
@Nullable
|
||||
private final GpxSelectionHelper.SelectedGpxFile mSelectedGpxFile;
|
||||
private final SelectedGpxFile mSelectedGpxFile;
|
||||
|
||||
private final List<GpxDisplayGroup> groups;
|
||||
|
||||
SplitTrackAsyncTask(@Nullable GpxSelectionHelper.SelectedGpxFile selectedGpxFile, List<GpxDisplayGroup> groups) {
|
||||
SplitTrackAsyncTask(@Nullable SelectedGpxFile selectedGpxFile, @NonNull List<GpxDisplayGroup> groups) {
|
||||
mSelectedGpxFile = selectedGpxFile;
|
||||
this.groups = groups;
|
||||
}
|
||||
|
@ -685,10 +713,6 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
||||
public static boolean showInstance(@NonNull TrackActivity trackActivity) {
|
||||
try {
|
||||
SplitSegmentDialogFragment fragment = new SplitSegmentDialogFragment();
|
||||
|
|
Loading…
Reference in a new issue