fix "Currently recording track" showing with same name;
add update statistics blocks in "Overview" if the current recording track is open;
This commit is contained in:
parent
5fda894c9a
commit
e5bf00162e
3 changed files with 43 additions and 19 deletions
|
@ -11,6 +11,7 @@ import androidx.annotation.ColorInt;
|
|||
import androidx.annotation.ColorRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
@ -41,6 +42,7 @@ public class GpxBlockStatisticsBuilder {
|
|||
|
||||
private BlockStatisticsAdapter adapter;
|
||||
private final List<StatBlock> items = new ArrayList<>();
|
||||
private boolean blocksClickable = true;
|
||||
|
||||
private final Handler handler = new Handler();
|
||||
private Runnable updatingItems;
|
||||
|
@ -51,28 +53,34 @@ public class GpxBlockStatisticsBuilder {
|
|||
this.selectedGpxFile = selectedGpxFile;
|
||||
}
|
||||
|
||||
public boolean isUpdateRunning() {
|
||||
return updateRunning;
|
||||
}
|
||||
|
||||
public void setBlocksClickable(boolean blocksClickable) {
|
||||
this.blocksClickable = blocksClickable;
|
||||
}
|
||||
|
||||
public void setBlocksView(RecyclerView blocksView) {
|
||||
this.blocksView = blocksView;
|
||||
}
|
||||
|
||||
private GpxDisplayItem getDisplayItem(GPXFile gpxFile) {
|
||||
return GpxUiHelper.makeGpxDisplayItem(app, gpxFile);
|
||||
@Nullable
|
||||
public GpxDisplayItem getDisplayItem(GPXFile gpxFile) {
|
||||
return gpxFile.tracks.size() > 0 ? GpxUiHelper.makeGpxDisplayItem(app, gpxFile) : null;
|
||||
}
|
||||
|
||||
private GPXFile getGPXFile() {
|
||||
return selectedGpxFile.getGpxFile();
|
||||
}
|
||||
|
||||
public void initStatBlocks(SegmentActionsListener actionsListener, @ColorInt int activeColor, boolean nightMode) {
|
||||
public void initStatBlocks(@Nullable SegmentActionsListener actionsListener, @ColorInt int activeColor, boolean nightMode) {
|
||||
initItems();
|
||||
boolean isNotEmpty = !Algorithms.isEmpty(items);
|
||||
AndroidUiHelper.updateVisibility(blocksView, isNotEmpty);
|
||||
if (isNotEmpty) {
|
||||
adapter = new BlockStatisticsAdapter(getDisplayItem(getGPXFile()), actionsListener, activeColor, nightMode);
|
||||
adapter.setItems(items);
|
||||
blocksView.setLayoutManager(new LinearLayoutManager(app, LinearLayoutManager.HORIZONTAL, false));
|
||||
blocksView.setAdapter(adapter);
|
||||
}
|
||||
adapter = new BlockStatisticsAdapter(getDisplayItem(getGPXFile()), actionsListener, activeColor, nightMode);
|
||||
adapter.setItems(items);
|
||||
blocksView.setLayoutManager(new LinearLayoutManager(app, LinearLayoutManager.HORIZONTAL, false));
|
||||
blocksView.setAdapter(adapter);
|
||||
AndroidUiHelper.updateVisibility(blocksView, !Algorithms.isEmpty(items));
|
||||
}
|
||||
|
||||
public void stopUpdatingStatBlocks() {
|
||||
|
@ -84,11 +92,11 @@ public class GpxBlockStatisticsBuilder {
|
|||
updatingItems = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
initItems();
|
||||
if (adapter != null) {
|
||||
initItems();
|
||||
adapter.setItems(items);
|
||||
AndroidUiHelper.updateVisibility(blocksView, !Algorithms.isEmpty(items));
|
||||
}
|
||||
AndroidUiHelper.updateVisibility(blocksView, !Algorithms.isEmpty(items));
|
||||
int interval = app.getSettings().SAVE_GLOBAL_TRACK_INTERVAL.get();
|
||||
handler.postDelayed(this, Math.max(1000, interval));
|
||||
}
|
||||
|
@ -98,12 +106,9 @@ public class GpxBlockStatisticsBuilder {
|
|||
|
||||
public void initItems() {
|
||||
GPXFile gpxFile = getGPXFile();
|
||||
GpxDisplayItem gpxDisplayItem = null;
|
||||
GpxDisplayItem gpxDisplayItem = getDisplayItem(gpxFile);
|
||||
GPXTrackAnalysis analysis = null;
|
||||
boolean withoutGaps = true;
|
||||
if (gpxFile.tracks.size() > 0) {
|
||||
gpxDisplayItem = getDisplayItem(gpxFile);
|
||||
}
|
||||
if (gpxDisplayItem != null) {
|
||||
analysis = gpxDisplayItem.analysis;
|
||||
withoutGaps = !selectedGpxFile.isJoinSegments() && gpxDisplayItem.isGeneralTrack();
|
||||
|
@ -237,7 +242,7 @@ public class GpxBlockStatisticsBuilder {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
GPXTrackAnalysis analysis = displayItem != null ? displayItem.analysis : null;
|
||||
if (analysis != null) {
|
||||
if (blocksClickable && analysis != null && actionsListener != null) {
|
||||
ArrayList<GPXDataSetType> list = new ArrayList<>();
|
||||
if (analysis.hasElevationData || analysis.isSpeedSpecified() || analysis.hasSpeedData) {
|
||||
if (item.firstType != null) {
|
||||
|
|
|
@ -43,6 +43,10 @@ public class OverviewCard extends BaseCard {
|
|||
private final SelectedGpxFile selectedGpxFile;
|
||||
private final GpxBlockStatisticsBuilder blockStatisticsBuilder;
|
||||
|
||||
public GpxBlockStatisticsBuilder getBlockStatisticsBuilder() {
|
||||
return blockStatisticsBuilder;
|
||||
}
|
||||
|
||||
public OverviewCard(@NonNull MapActivity mapActivity, @NonNull SegmentActionsListener actionsListener, SelectedGpxFile selectedGpxFile) {
|
||||
super(mapActivity);
|
||||
this.actionsListener = actionsListener;
|
||||
|
|
|
@ -231,7 +231,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
}
|
||||
displayHelper.setGpx(selectedGpxFile.getGpxFile());
|
||||
String fileName = Algorithms.getFileWithoutDirs(getGpx().path);
|
||||
gpxTitle = GpxUiHelper.getGpxTitle(fileName);
|
||||
gpxTitle = !isCurrentRecordingTrack() ? GpxUiHelper.getGpxTitle(fileName)
|
||||
: app.getResources().getString(R.string.shared_string_currently_recording_track);
|
||||
toolbarHeightPx = getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar);
|
||||
|
||||
FragmentActivity activity = requireMyActivity();
|
||||
|
@ -330,8 +331,13 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
overviewCard.setListener(this);
|
||||
headerContainer.addView(overviewCard.build(getMapActivity()));
|
||||
}
|
||||
GpxBlockStatisticsBuilder blocksBuilder = overviewCard.getBlockStatisticsBuilder();
|
||||
if (isCurrentRecordingTrack() && !blocksBuilder.isUpdateRunning()) {
|
||||
blocksBuilder.runUpdatingStatBlocks();
|
||||
}
|
||||
} else {
|
||||
if (overviewCard != null && overviewCard.getView() != null) {
|
||||
overviewCard.getBlockStatisticsBuilder().stopUpdatingStatBlocks();
|
||||
headerContainer.removeView(overviewCard.getView());
|
||||
}
|
||||
boolean isOptions = menuType == TrackMenuType.OPTIONS;
|
||||
|
@ -544,6 +550,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
}
|
||||
updateControlsVisibility(true);
|
||||
startLocationUpdate();
|
||||
GpxBlockStatisticsBuilder blockStats = overviewCard.getBlockStatisticsBuilder();
|
||||
if (menuType == TrackMenuType.OVERVIEW && isCurrentRecordingTrack() && !blockStats.isUpdateRunning()) {
|
||||
blockStats.runUpdatingStatBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -555,6 +565,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
}
|
||||
updateControlsVisibility(false);
|
||||
stopLocationUpdate();
|
||||
overviewCard.getBlockStatisticsBuilder().stopUpdatingStatBlocks();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1120,6 +1131,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
private boolean isCurrentRecordingTrack() {
|
||||
return app.getSavingTrackHelper().getCurrentTrack() == selectedGpxFile;
|
||||
}
|
||||
|
||||
private void hide() {
|
||||
try {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
|
|
Loading…
Reference in a new issue