Remove unnecessary split from TrackActivityFragmentAdapter

This commit is contained in:
Vitaliy 2020-12-28 03:24:16 +02:00
parent 8fa316b467
commit 38a0fb1f27
7 changed files with 37 additions and 353 deletions

View file

@ -109,61 +109,6 @@
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginStart="@dimen/content_padding" />
<LinearLayout
android:id="@+id/split_color_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<LinearLayout
android:id="@+id/split_interval_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.6"
android:minHeight="@dimen/card_row_min_height"
android:paddingLeft="@dimen/content_padding"
android:paddingStart="@dimen/content_padding"
android:paddingRight="0dp"
android:paddingEnd="0dp"
android:paddingTop="@dimen/content_padding_half"
android:paddingBottom="@dimen/content_padding_half"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
android:id="@+id/split_interval_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
android:text="@string/gpx_split_interval"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/split_interval_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/content_padding_half"
android:paddingRight="@dimen/content_padding_half"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="10 km"
android:paddingEnd="@dimen/content_padding_half"
android:paddingStart="@dimen/content_padding_half" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/split_interval_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
osmand:srcCompat="@drawable/ic_action_arrow_drop_down"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/appearance_view"
android:layout_width="match_parent"

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_overview"
android:icon="@drawable/ic_action_trail_overview"
android:title="@string/shared_string_overview" />
<item
android:id="@+id/action_track"
android:icon="@drawable/ic_action_polygom_dark"
android:title="@string/shared_string_gpx_track" />
<item
android:id="@+id/action_points"
android:icon="@drawable/ic_action_waypoint"
android:title="@string/shared_string_gpx_points" />
<item
android:id="@+id/action_options"
android:icon="@drawable/ic_overflow_menu_white"
android:title="@string/shared_string_options" />
</menu>

View file

@ -266,15 +266,6 @@ public class TrackActivity extends TabActivity {
return false;
}
public void updateSplitView() {
for (WeakReference<Fragment> f : fragList) {
Fragment frag = f.get();
if (frag instanceof TrackSegmentFragment) {
((TrackSegmentFragment) frag).updateSplitView();
}
}
}
public void updateHeader(Fragment sender) {
for (WeakReference<Fragment> f : fragList) {
Fragment frag = f.get();

View file

@ -17,6 +17,7 @@ import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.helpers.GpxUiHelper;
@ -25,6 +26,7 @@ import net.osmand.plus.mapcontextmenu.builders.SelectedGpxMenuBuilder;
import net.osmand.plus.myplaces.SaveCurrentTrackTask;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
import net.osmand.plus.track.TrackMenuFragment;
import net.osmand.util.Algorithms;
import java.io.File;
@ -45,15 +47,21 @@ public class SelectedGpxMenuController extends MenuController {
leftTitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
Intent intent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getTrackActivity());
OsmandApplication app = mapActivity.getMyApplication();
SelectedGpxFile selectedGpxFile = selectedGpxPoint.getSelectedGpxFile();
if (selectedGpxFile.isShowCurrentTrack()) {
intent.putExtra(TrackActivity.CURRENT_RECORDING, true);
if (Version.isDeveloperVersion(app)) {
mapActivity.getContextMenu().hide(false);
TrackMenuFragment.showInstance(mapActivity, selectedGpxFile.getGpxFile().path, selectedGpxFile.isShowCurrentTrack());
} else {
intent.putExtra(TrackActivity.TRACK_FILE_NAME, selectedGpxFile.getGpxFile().path);
Intent intent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getTrackActivity());
if (selectedGpxFile.isShowCurrentTrack()) {
intent.putExtra(TrackActivity.CURRENT_RECORDING, true);
} else {
intent.putExtra(TrackActivity.TRACK_FILE_NAME, selectedGpxFile.getGpxFile().path);
}
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mapActivity.startActivity(intent);
}
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mapActivity.startActivity(intent);
}
};
leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_open_track);

View file

@ -1,7 +1,6 @@
package net.osmand.plus.myplaces;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.graphics.Paint;
import android.graphics.Rect;
@ -434,24 +433,6 @@ public class SplitSegmentDialogFragment extends DialogFragment {
return false;
}
@Override
public void dismiss() {
TrackActivity trackActivity = getTrackActivity();
if (trackActivity != null) {
trackActivity.updateSplitView();
}
super.dismiss();
}
@Override
public void onCancel(DialogInterface dialog) {
TrackActivity trackActivity = getTrackActivity();
if (trackActivity != null) {
trackActivity.updateSplitView();
}
super.onCancel(dialog);
}
private class SplitSegmentsAdapter extends ArrayAdapter<GpxDisplayItem> {
SplitSegmentsAdapter(List<GpxDisplayItem> items) {

View file

@ -6,7 +6,6 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
@ -14,9 +13,7 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
@ -47,8 +44,6 @@ import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
@ -57,9 +52,6 @@ import net.osmand.plus.dialogs.GpxAppearanceAdapter;
import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.track.GpxSplitType;
import net.osmand.plus.track.SplitTrackAsyncTask;
import net.osmand.plus.track.SplitTrackAsyncTask.SplitTrackListener;
import net.osmand.plus.widgets.tools.CropCircleTransformation;
import net.osmand.plus.wikipedia.WikiArticleHelper;
import net.osmand.plus.wikivoyage.WikivoyageUtils;
@ -71,8 +63,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import gnu.trove.list.array.TIntArrayList;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR;
public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
@ -82,10 +72,6 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
private ListView listView;
private GpxDisplayItemType[] filterTypes;
private List<String> options = new ArrayList<>();
private List<Double> distanceSplit = new ArrayList<>();
private TIntArrayList timeSplit = new TIntArrayList();
private int selectedSplitInterval;
private boolean updateEnable;
private View headerView;
private SwitchCompat vis;
@ -108,7 +94,6 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
private View lineTextLayout;
private View overlayView;
ListPopupWindow splitListPopupWindow;
ListPopupWindow colorListPopupWindow;
TrackActivityFragmentAdapter(@NonNull OsmandApplication app,
@ -268,10 +253,8 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
showTemporaryObjectOnMap(getRect());
}
});
final View splitColorView = headerView.findViewById(R.id.split_color_view);
final View appearanceView = headerView.findViewById(R.id.appearance_view);
final View divider = headerView.findViewById(R.id.divider);
final View splitIntervalView = headerView.findViewById(R.id.split_interval_view);
vis = (SwitchCompat) headerView.findViewById(R.id.showOnMapToggle);
final View bottomDivider = headerView.findViewById(R.id.bottom_divider);
GPXFile gpxFile = getGpx();
@ -297,13 +280,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
@Override
public void onClick(View v) {
vis.toggle();
if (!vis.isChecked()) {
selectedSplitInterval = 0;
}
setTrackVisibilityOnMap(vis.isChecked());
if (!showMapOnly) {
updateSplitIntervalView(splitIntervalView);
}
TrackActivity trackActivity = getTrackActivity();
if (trackActivity != null) {
trackActivity.updateHeader(fragment);
@ -312,45 +289,12 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
}
});
splitColorView.setVisibility(View.GONE);
if (showMapOnly) {
splitIntervalView.setVisibility(View.GONE);
appearanceView.setVisibility(View.GONE);
divider.setVisibility(View.GONE);
bottomDivider.setVisibility(View.VISIBLE);
} else {
bottomDivider.setVisibility(View.GONE);
if (hasPath) {
if (!gpxFile.showCurrentTrack && listItemsCount > 0) {
prepareSplitIntervalAdapterData();
setupSplitIntervalView(splitIntervalView);
updateSplitIntervalView(splitIntervalView);
splitIntervalView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TrackActivity activity = getTrackActivity();
if (activity != null) {
ListAdapter adapter = new ArrayAdapter<>(activity, R.layout.popup_list_text_item, options);
OnItemClickListener itemClickListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectedSplitInterval = position;
setTrackVisibilityOnMap(vis.isChecked());
splitListPopupWindow.dismiss();
updateSplitIntervalView(splitIntervalView);
}
};
splitListPopupWindow = createPopupWindow(activity, splitIntervalView, adapter, itemClickListener);
splitListPopupWindow.show();
}
}
});
splitIntervalView.setVisibility(View.VISIBLE);
} else {
splitIntervalView.setVisibility(View.GONE);
}
appearanceView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -363,6 +307,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
appearanceView.setVisibility(View.GONE);
divider.setVisibility(View.GONE);
}
bottomDivider.setVisibility(View.GONE);
}
updateTrackColor();
}
@ -594,17 +539,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
private void setTrackVisibilityOnMap(boolean visible) {
GPXFile gpxFile = getGpx();
if (gpxFile != null) {
GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper();
SelectedGpxFile sf = gpxHelper.selectGpxFile(gpxFile, visible, false);
if (gpxFile.hasTrkPt()) {
List<GpxDisplayGroup> groups = getDisplayGroups();
if (groups.size() > 0) {
updateSplit(groups, visible ? sf : null);
if (getGpxDataItem() != null) {
updateSplitInDatabase();
}
}
}
app.getSelectedGpxHelper().selectGpxFile(gpxFile, visible, false);
}
}
@ -665,52 +600,6 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
return groups;
}
private void setupSplitIntervalView(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);
int colorId;
final List<GpxDisplayGroup> groups = getDisplayGroups();
if (groups.size() > 0) {
colorId = app.getSettings().isLightContent() ?
R.color.text_color_primary_light : R.color.text_color_primary_dark;
} else {
colorId = app.getSettings().isLightContent() ?
R.color.text_color_secondary_light : R.color.text_color_secondary_dark;
}
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));
}
private void updateSplitIntervalView(View view) {
final TextView text = (TextView) view.findViewById(R.id.split_interval_text);
selectedSplitInterval = getSelectedSplitInterval();
if (selectedSplitInterval == 0) {
text.setText(app.getString(R.string.shared_string_none));
} else {
text.setText(options.get(selectedSplitInterval));
}
}
private int getSelectedSplitInterval() {
if (getGpxDataItem() == null) {
return 0;
}
int splitType = getGpxDataItem().getSplitType();
double splitInterval = getGpxDataItem().getSplitInterval();
int position = 0;
if (splitType == GpxSplitType.DISTANCE.getType()) {
position = distanceSplit.indexOf(splitInterval);
} else if (splitType == GpxSplitType.TIME.getType()) {
position = timeSplit.indexOf((int) splitInterval);
}
return Math.max(position, 0);
}
private void updateTrackColor() {
int color = getGpxDataItem() != null ? getGpxDataItem().getColor() : 0;
GPXFile gpxFile = getGpx();
@ -740,146 +629,6 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
return list;
}
private void prepareSplitIntervalAdapterData() {
final List<GpxDisplayGroup> groups = getDisplayGroups();
options.add(app.getString(R.string.shared_string_none));
distanceSplit.add(-1d);
timeSplit.add(-1);
addOptionSplit(30, true, groups); // 50 feet, 20 yards, 20
// m
addOptionSplit(60, true, groups); // 100 feet, 50 yards,
// 50 m
addOptionSplit(150, true, groups); // 200 feet, 100 yards,
// 100 m
addOptionSplit(300, true, groups); // 500 feet, 200 yards,
// 200 m
addOptionSplit(600, true, groups); // 1000 feet, 500 yards,
// 500 m
addOptionSplit(1500, true, groups); // 2000 feet, 1000 yards, 1 km
addOptionSplit(3000, true, groups); // 1 mi, 2 km
addOptionSplit(6000, true, groups); // 2 mi, 5 km
addOptionSplit(15000, true, groups); // 5 mi, 10 km
addOptionSplit(15, false, groups);
addOptionSplit(30, false, groups);
addOptionSplit(60, false, groups);
addOptionSplit(120, false, groups);
addOptionSplit(150, false, groups);
addOptionSplit(300, false, groups);
addOptionSplit(600, false, groups);
addOptionSplit(900, false, groups);
addOptionSplit(1800, false, groups);
addOptionSplit(3600, false, groups);
}
private void updateSplit(@NonNull List<GpxDisplayGroup> groups, @Nullable final SelectedGpxFile selectedGpx) {
GPXFile gpxFile = getGpx();
TrackActivity activity = getTrackActivity();
GpxSplitType gpxSplitType = getGpxSplitType();
if (activity != null && gpxSplitType != null && gpxFile != null) {
int timeSplit = 0;
double distanceSplit = 0;
if (gpxSplitType != GpxSplitType.NO_SPLIT && !gpxFile.showCurrentTrack) {
timeSplit = this.timeSplit.get(selectedSplitInterval);
distanceSplit = this.distanceSplit.get(selectedSplitInterval);
}
SplitTrackListener splitTrackListener = new SplitTrackListener() {
@Override
public void trackSplittingStarted() {
TrackActivity activity = getTrackActivity();
if (activity != null) {
activity.setSupportProgressBarIndeterminateVisibility(true);
}
}
@Override
public void trackSplittingFinished() {
TrackActivity activity = getTrackActivity();
if (activity != null) {
if (AndroidUtils.isActivityNotDestroyed(activity)) {
activity.setSupportProgressBarIndeterminateVisibility(false);
}
if (selectedGpx != null) {
List<GpxDisplayGroup> groups = getDisplayGroups();
selectedGpx.setDisplayGroups(groups, app);
}
}
}
};
new SplitTrackAsyncTask(app, gpxSplitType, groups, splitTrackListener, activity.isJoinSegments(),
timeSplit, distanceSplit).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
private GpxSplitType getGpxSplitType() {
if (selectedSplitInterval == 0) {
return GpxSplitType.NO_SPLIT;
} else if (distanceSplit.get(selectedSplitInterval) > 0) {
return GpxSplitType.DISTANCE;
} else if (timeSplit.get(selectedSplitInterval) > 0) {
return GpxSplitType.TIME;
}
return null;
}
private void addOptionSplit(int value, boolean distance, @NonNull List<GpxDisplayGroup> model) {
if (model.size() > 0) {
if (distance) {
double dvalue = OsmAndFormatter.calculateRoundedDist(value, app);
options.add(OsmAndFormatter.getFormattedDistanceInterval(app, value));
distanceSplit.add(dvalue);
timeSplit.add(-1);
if (Math.abs(model.get(0).getSplitDistance() - dvalue) < 1) {
selectedSplitInterval = distanceSplit.size() - 1;
}
} else {
options.add(OsmAndFormatter.getFormattedTimeInterval(app, value));
distanceSplit.add(-1d);
timeSplit.add(value);
if (model.get(0).getSplitTime() == value) {
selectedSplitInterval = distanceSplit.size() - 1;
}
}
}
}
private void updateSplitInDatabase() {
double splitInterval = 0;
GpxSplitType splitType = null;
if (selectedSplitInterval == 0) {
splitType = GpxSplitType.NO_SPLIT;
splitInterval = 0;
} else if (distanceSplit.get(selectedSplitInterval) > 0) {
splitType = GpxSplitType.DISTANCE;
splitInterval = distanceSplit.get(selectedSplitInterval);
} else if (timeSplit.get(selectedSplitInterval) > 0) {
splitType = GpxSplitType.TIME;
splitInterval = timeSplit.get(selectedSplitInterval);
}
GpxDataItem item = getGpxDataItem();
if (item != null && splitType != null) {
app.getGpxDbHelper().updateSplit(item, splitType, splitInterval);
}
}
public void updateSplitView() {
GPXFile gpxFile = getGpx();
if (gpxFile != null) {
SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpxFile,
((SwitchCompat) headerView.findViewById(R.id.showOnMapToggle)).isChecked(), false);
final List<GpxDisplayGroup> groups = getDisplayGroups();
if (groups.size() > 0) {
updateSplit(groups, ((SwitchCompat) headerView.findViewById(R.id.showOnMapToggle)).isChecked() ? sf : null);
if (getGpxDataItem() != null) {
updateSplitInDatabase();
}
}
updateSplitIntervalView(headerView.findViewById(R.id.split_interval_view));
}
}
public void hideTransparentOverlay() {
overlayView.setVisibility(View.GONE);
}

View file

@ -219,9 +219,6 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
altitudePopupMenu.dismiss();
}
if (fragmentAdapter != null) {
if (fragmentAdapter.splitListPopupWindow != null) {
fragmentAdapter.splitListPopupWindow.dismiss();
}
if (fragmentAdapter.colorListPopupWindow != null) {
fragmentAdapter.colorListPopupWindow.dismiss();
}
@ -269,12 +266,6 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
}
}
public void updateSplitView() {
if (fragmentAdapter != null) {
fragmentAdapter.updateSplitView();
}
}
@Nullable
private List<GpxDisplayItem> flatten(List<GpxDisplayGroup> groups) {
return fragmentAdapter != null ? fragmentAdapter.flatten(groups) : null;
@ -807,7 +798,6 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
public void onClick(View v) {
TrackActivity activity = getTrackActivity();
if (activity != null && activity.setJoinSegments(!activity.isJoinSegments())) {
updateSplitView();
for (int i = 0; i < getCount(); i++) {
View view = getViewAtPosition(i);
updateJoinGapsInfo(view, i);
@ -904,7 +894,6 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
public void onClick(View v) {
TrackActivity activity = getTrackActivity();
if (activity != null && activity.setJoinSegments(!activity.isJoinSegments())) {
updateSplitView();
for (int i = 0; i < getCount(); i++) {
View view = getViewAtPosition(i);
updateJoinGapsInfo(view, i);