fix ability to click on statistics blocks;

add functionality of the button "start new segment";
add snackbar with file rename to "save and stop recording" button;
some fixes;
This commit is contained in:
Skalii 2021-02-10 16:04:25 +02:00
parent 7f395a612a
commit c36d007b5c
3 changed files with 72 additions and 52 deletions

View file

@ -1,12 +1,13 @@
package net.osmand.plus.monitoring;
import android.app.Dialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
@ -15,7 +16,9 @@ import net.osmand.plus.UiUtilities.DialogButtonType;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.myplaces.SaveCurrentTrackTask;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
import net.osmand.plus.widgets.TextViewEx;
import androidx.annotation.DimenRes;
@ -33,6 +36,16 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
private OsmandApplication app;
private OsmandSettings settings;
private OsmandMonitoringPlugin plugin;
private GPXFile gpxFile;
private SaveGpxListener saveGpxListener;
public void setGpxFile(GPXFile gpxFile) {
this.gpxFile = gpxFile;
}
public void setSaveGpxListener(SaveGpxListener saveGpxListener) {
this.saveGpxListener = saveGpxListener;
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
@ -118,7 +131,8 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
app.getSavingTrackHelper().clearRecordedData(true);
} else if (tag == ButtonType.SAVE_AND_STOP) {
if (plugin != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
plugin.saveCurrentTrack();
new SaveCurrentTrackTask(app, gpxFile, saveGpxListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
plugin.stopRecording();
app.getNotificationHelper().refreshNotifications();
}
}
@ -169,9 +183,11 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
return true;
}
public static void showInstance(@NonNull FragmentManager fragmentManager, @NonNull Fragment target) {
public static void showInstance(GPXFile gpxFile, SaveGpxListener saveGpxListener, @NonNull FragmentManager fragmentManager, @NonNull Fragment target) {
if (!fragmentManager.isStateSaved()) {
StopTrackRecordingBottomFragment fragment = new StopTrackRecordingBottomFragment();
fragment.setGpxFile(gpxFile);
fragment.setSaveGpxListener(saveGpxListener);
fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, TAG);
}

View file

@ -90,7 +90,6 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
private final Handler handler = new Handler();
private Runnable updatingGPS;
private Runnable updatingTimeTrackSaved;
private SaveGpxListener saveGpxListener;
private GPXFile getGPXFile() {
return selectedGpxFile.getGpxFile();
@ -145,7 +144,6 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
createItem(buttonClear, ItemType.CLEAR_DATA, hasDataToSave, null);
createItem(buttonStart, ItemType.START_SEGMENT, wasTrackMonitored, null);
// createItem(buttonSave, ItemType.SAVE, hasDataToSave, getTimeTrackSaved());
createItem(buttonPause, wasTrackMonitored ? ItemType.PAUSE : ItemType.RESUME, true, null);
createItem(buttonStop, ItemType.STOP, true, null);
@ -153,8 +151,9 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
updateStatus();
RecyclerView statBlocks = itemView.findViewById(R.id.block_statistics);
blockStatisticsBuilder = new GpxBlockStatisticsBuilder(app, selectedGpxFile, null);
blockStatisticsBuilder = new GpxBlockStatisticsBuilder(app, selectedGpxFile);
blockStatisticsBuilder.setBlocksView(statBlocks);
blockStatisticsBuilder.setBlocksClickable(false);
blockStatisticsBuilder.initStatBlocks(null, ContextCompat.getColor(app, getActiveTextColorId(nightMode)), nightMode);
LinearLayout showTrackOnMapView = itemView.findViewById(R.id.show_track_on_map);
@ -226,18 +225,17 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
@Override
public void onClick(View v) {
if (wasTrackMonitored) {
helper.startNewSegment();
}
}
});
setSaveListener();
buttonSave.findViewById(R.id.button_container).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (hasDataToSave) {
final GPXFile gpxFile = getGPXFile();
new SaveCurrentTrackTask(app, gpxFile, saveGpxListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new SaveCurrentTrackTask(app, gpxFile, createSaveListener()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
});
@ -263,7 +261,8 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
@Override
public void onClick(View v) {
if (fragmentManager != null) {
StopTrackRecordingBottomFragment.showInstance(fragmentManager, TripRecordingActiveBottomSheet.this);
final GPXFile gpxFile = getGPXFile();
StopTrackRecordingBottomFragment.showInstance(gpxFile, createSaveListener(), fragmentManager, TripRecordingActiveBottomSheet.this);
}
}
});
@ -307,6 +306,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
AndroidUiHelper.updateVisibility(desc, isShowDesc);
UiUtilities.setMargins(title, 0, marginDesc, 0, marginDesc);
desc.setText(description);
type.setTextColor(desc, app, false, false, nightMode);
}
}
@ -378,43 +378,41 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
handler.post(updatingTimeTrackSaved);
}
private void setSaveListener() {
if (saveGpxListener == null) {
saveGpxListener = new SaveGpxListener() {
private SaveGpxListener createSaveListener() {
return new SaveGpxListener() {
@Override
public void gpxSavingStarted() {
}
@Override
public void gpxSavingStarted() {
}
@Override
public void gpxSavingFinished(Exception errorMessage) {
String gpxFileName = Algorithms.getFileWithoutDirs(getGPXFile().path);
final MapActivity mapActivity = getMapActivity();
final Context context = getContext();
final SaveGpxResult result = helper.saveDataToGpx(app.getAppCustomization().getTracksDir());
if (mapActivity != null && context != null) {
Snackbar snackbar = Snackbar.make(mapActivity.getLayout(),
getString(R.string.shared_string_file_is_saved, gpxFileName),
Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_rename, new View.OnClickListener() {
@Override
public void onClick(View view) {
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
final FragmentActivity fragmentActivity = mapActivityRef.get();
SaveGPXBottomSheetFragment.showInstance(fragmentActivity.getSupportFragmentManager(), result.getFilenames());
}
});
View view = snackbar.getView();
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
params.gravity = Gravity.TOP;
AndroidUtils.setMargins(params, 0, AndroidUtils.getStatusBarHeight(context), 0, 0);
view.setLayoutParams(params);
UiUtilities.setupSnackbar(snackbar, nightMode);
snackbar.show();
}
@Override
public void gpxSavingFinished(Exception errorMessage) {
String gpxFileName = Algorithms.getFileWithoutDirs(getGPXFile().path);
final MapActivity mapActivity = getMapActivity();
final Context context = getContext();
final SaveGpxResult result = helper.saveDataToGpx(app.getAppCustomization().getTracksDir());
if (mapActivity != null && context != null) {
Snackbar snackbar = Snackbar.make(mapActivity.getLayout(),
getString(R.string.shared_string_file_is_saved, gpxFileName),
Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_rename, new View.OnClickListener() {
@Override
public void onClick(View view) {
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
final FragmentActivity fragmentActivity = mapActivityRef.get();
SaveGPXBottomSheetFragment.showInstance(fragmentActivity.getSupportFragmentManager(), result.getFilenames());
}
});
View view = snackbar.getView();
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
params.gravity = Gravity.TOP;
AndroidUtils.setMargins(params, 0, AndroidUtils.getStatusBarHeight(context), 0, 0);
view.setLayoutParams(params);
UiUtilities.setupSnackbar(snackbar, nightMode);
snackbar.show();
}
};
}
}
};
}
@Nullable
@ -508,12 +506,12 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
public void setTintedIcon(AppCompatImageView iv, Context context, boolean enabled, boolean pressed, boolean nightMode) {
if (iv != null) {
int iconColor = ContextCompat.getColor(context,
enabled ? pressed ? getPressedColorId(nightMode)
: this == ItemType.CLEAR_DATA ? R.color.color_osm_edit_delete
: getActiveIconColorId(nightMode) : getSecondaryIconColorId(nightMode));
Drawable icon = UiUtilities.createTintedDrawable(context, iconId, iconColor);
iv.setImageDrawable(icon);
Drawable icon = AppCompatResources.getDrawable(context, iconId);
int iconColor = enabled ? pressed ? getPressedColorId(nightMode)
: this == ItemType.CLEAR_DATA ? R.color.color_osm_edit_delete
: getActiveIconColorId(nightMode) : getSecondaryIconColorId(nightMode);
Drawable tintedIcon = UiUtilities.tintDrawable(icon, ContextCompat.getColor(context, iconColor));
iv.setImageDrawable(tintedIcon);
if (this == ItemType.STOP) {
int stopSize = iv.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin_large);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(stopSize, stopSize);

View file

@ -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,6 +53,10 @@ public class GpxBlockStatisticsBuilder {
this.selectedGpxFile = selectedGpxFile;
}
public void setBlocksClickable(boolean blocksClickable) {
this.blocksClickable = blocksClickable;
}
public void setBlocksView(RecyclerView blocksView) {
this.blocksView = blocksView;
}
@ -63,7 +69,7 @@ public class GpxBlockStatisticsBuilder {
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);
@ -237,7 +243,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) {