small code cleanup;

This commit is contained in:
Skalii 2021-02-10 19:22:29 +02:00
parent b7497338b3
commit 26083c53a3
4 changed files with 35 additions and 66 deletions

View file

@ -22,7 +22,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
@ -854,10 +853,8 @@ public class MapActivityActions implements DialogProvider {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
app.logEvent("trip_recording_open");
MapActivity.clearPrevActivityIntent();
if (monitoringPlugin.isHasDataToSave() || monitoringPlugin.isWasTrackMonitored()) {
TripRecordingActiveBottomSheet.showInstance(mapActivity.getSupportFragmentManager(),
monitoringPlugin.getCurrentTrack(), monitoringPlugin.isWasTrackMonitored(),
monitoringPlugin.isHasDataToSave(), monitoringPlugin.isSearchingGPS());
if (monitoringPlugin.hasDataToSave() || monitoringPlugin.wasTrackMonitored()) {
TripRecordingActiveBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), monitoringPlugin.getCurrentTrack());
} else {
TripRecordingBottomSheet.showInstance(mapActivity.getSupportFragmentManager());
}

View file

@ -1,9 +1,7 @@
package net.osmand.plus.monitoring;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
@ -19,7 +17,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.AppCompatCheckBox;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
@ -28,11 +25,9 @@ import com.google.android.material.slider.Slider;
import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.ValueHolder;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmAndTaskManager.OsmAndTaskRunnable;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -45,7 +40,6 @@ import net.osmand.plus.dashboard.tools.DashFragmentData;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType;
import net.osmand.plus.track.TrackDisplayHelper;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.layers.MapInfoLayer;
@ -55,8 +49,6 @@ import net.osmand.util.Algorithms;
import java.lang.ref.WeakReference;
import java.util.List;
import gnu.trove.list.array.TIntArrayList;
import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT;
public class OsmandMonitoringPlugin extends OsmandPlugin {
@ -165,9 +157,9 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
}
}
public static final int[] SECONDS = new int[] {0, 1, 2, 3, 5, 10, 15, 20, 30, 60, 90};
public static final int[] MINUTES = new int[] {2, 3, 5};
public static final int[] MAX_INTERVAL_TO_SEND_MINUTES = new int[] {1, 2, 5, 10, 15, 20, 30, 60, 90, 2 * 60, 3 * 60, 4 * 60, 6 * 60, 12 * 60, 24 * 60};
public static final int[] SECONDS = new int[]{0, 1, 2, 3, 5, 10, 15, 20, 30, 60, 90};
public static final int[] MINUTES = new int[]{2, 3, 5};
public static final int[] MAX_INTERVAL_TO_SEND_MINUTES = new int[]{1, 2, 5, 10, 15, 20, 30, 60, 90, 2 * 60, 3 * 60, 4 * 60, 6 * 60, 12 * 60, 24 * 60};
@Override
public SettingsScreenType getSettingsScreenType() {
@ -185,9 +177,10 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
private TextInfoWidget createMonitoringControl(final MapActivity map) {
monitoringControl = new TextInfoWidget(map) {
long lastUpdateTime;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
if(isSaving){
if (isSaving) {
setText(map.getString(R.string.shared_string_save), "");
setIcons(R.drawable.widget_monitoring_rec_big_day, R.drawable.widget_monitoring_rec_big_night);
return true;
@ -215,7 +208,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
}
final boolean liveMonitoringEnabled = liveMonitoringHelper.isLiveMonitoringEnabled();
if(globalRecord) {
if (globalRecord) {
//indicates global recording (+background recording)
if (liveMonitoringEnabled) {
dn = R.drawable.widget_live_monitoring_rec_big_night;
@ -324,25 +317,18 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
return app.getSavingTrackHelper().getCurrentTrack();
}
public boolean isWasTrackMonitored() {
public boolean wasTrackMonitored() {
return settings.SAVE_GLOBAL_TRACK_TO_GPX.get();
}
public boolean isHasDataToSave() {
public boolean hasDataToSave() {
return app.getSavingTrackHelper().hasDataToSave();
}
public boolean isSearchingGPS() {
OsmAndLocationProvider locationProvider = app.getLocationProvider();
Location lastKnownLocation = locationProvider.getLastKnownLocation();
return lastKnownLocation == null;
}
public void controlDialog(final Activity activity, final boolean showTrackSelection) {
if (isHasDataToSave() || isWasTrackMonitored()) {
if (hasDataToSave() || wasTrackMonitored()) {
FragmentActivity fragmentActivity = (FragmentActivity) activity;
TripRecordingActiveBottomSheet.showInstance(fragmentActivity.getSupportFragmentManager(),
getCurrentTrack(), isWasTrackMonitored(), isHasDataToSave(), isSearchingGPS());
TripRecordingActiveBottomSheet.showInstance(fragmentActivity.getSupportFragmentManager(), getCurrentTrack());
} else {
FragmentActivity fragmentActivity = (FragmentActivity) activity;
TripRecordingBottomSheet.showInstance(fragmentActivity.getSupportFragmentManager());
@ -507,7 +493,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
}
}
public void stopRecording(){
public void stopRecording() {
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(false);
if (app.getNavigationService() != null) {
app.getNavigationService().stopIfNeeded(app, NavigationService.USED_BY_GPX);
@ -596,11 +582,11 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
String s;
int progress = (int) value;
if(progress == 0) {
if (progress == 0) {
s = uiCtx.getString(R.string.int_continuosly);
v.value = 0;
} else {
if(progress < secondsLength) {
if (progress < secondsLength) {
s = seconds[progress] + " " + uiCtx.getString(R.string.int_seconds);
v.value = seconds[progress] * 1000;
} else {

View file

@ -37,10 +37,8 @@ import com.google.android.material.snackbar.Snackbar;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
@ -74,9 +72,6 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
private OsmandSettings settings;
private SavingTrackHelper helper;
private SelectedGpxFile selectedGpxFile;
private boolean wasTrackMonitored = false;
private boolean hasDataToSave = false;
private boolean searchingGPS = false;
private View statusContainer;
private View buttonSave;
@ -94,26 +89,22 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
this.selectedGpxFile = selectedGpxFile;
}
public void setWasTrackMonitored(boolean wasTrackMonitored) {
this.wasTrackMonitored = wasTrackMonitored;
public boolean hasDataToSave() {
return app.getSavingTrackHelper().hasDataToSave();
}
public void setHasDataToSave(boolean hasDataToSave) {
this.hasDataToSave = hasDataToSave;
public boolean searchingGPS() {
return app.getLocationProvider().getLastKnownLocation() == null;
}
public void setSearchingGPS(boolean searchingGPS) {
this.searchingGPS = searchingGPS;
public boolean wasTrackMonitored() {
return settings != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get();
}
public static void showInstance(@NonNull FragmentManager fragmentManager, SelectedGpxFile selectedGpxFile,
boolean wasTrackMonitored, boolean hasDataToSave, boolean searchingGPS) {
public static void showInstance(@NonNull FragmentManager fragmentManager, SelectedGpxFile selectedGpxFile) {
if (!fragmentManager.isStateSaved()) {
TripRecordingActiveBottomSheet fragment = new TripRecordingActiveBottomSheet();
fragment.setSelectedGpxFile(selectedGpxFile);
fragment.setWasTrackMonitored(wasTrackMonitored);
fragment.setHasDataToSave(hasDataToSave);
fragment.setSearchingGPS(searchingGPS);
fragment.show(fragmentManager, TAG);
}
}
@ -137,9 +128,9 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
final View buttonPause = itemView.findViewById(R.id.button_pause);
View buttonStop = itemView.findViewById(R.id.button_stop);
createItem(buttonClear, ItemType.CLEAR_DATA, hasDataToSave, null);
createItem(buttonStart, ItemType.START_SEGMENT, wasTrackMonitored, null);
createItem(buttonPause, wasTrackMonitored ? ItemType.PAUSE : ItemType.RESUME, true, null);
createItem(buttonClear, ItemType.CLEAR_DATA, hasDataToSave(), null);
createItem(buttonStart, ItemType.START_SEGMENT, wasTrackMonitored(), null);
createItem(buttonPause, wasTrackMonitored() ? ItemType.PAUSE : ItemType.RESUME, true, null);
createItem(buttonStop, ItemType.STOP, true, null);
statusContainer = itemView.findViewById(R.id.status_container);
@ -210,7 +201,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
buttonClear.findViewById(R.id.button_container).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (fragmentManager != null && hasDataToSave) {
if (fragmentManager != null && hasDataToSave()) {
ClearRecordedDataBottomSheetFragment.showInstance(fragmentManager, TripRecordingActiveBottomSheet.this);
}
}
@ -219,7 +210,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
buttonStart.findViewById(R.id.button_container).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (wasTrackMonitored) {
if (wasTrackMonitored()) {
helper.startNewSegment();
}
}
@ -228,7 +219,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
buttonSave.findViewById(R.id.button_container).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (hasDataToSave) {
if (hasDataToSave()) {
final GPXFile gpxFile = getGPXFile();
new SaveCurrentTrackTask(app, gpxFile, createSaveListener(new Runnable() {
@Override
@ -247,14 +238,13 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
buttonPause.findViewById(R.id.button_container).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean wasTrackMonitored = !settings.SAVE_GLOBAL_TRACK_TO_GPX.get();
boolean wasTrackMonitored = !wasTrackMonitored();
createItem(buttonPause, wasTrackMonitored ? ItemType.PAUSE : ItemType.RESUME, true, null);
if (!wasTrackMonitored) {
blockStatisticsBuilder.stopUpdatingStatBlocks();
} else {
blockStatisticsBuilder.runUpdatingStatBlocks();
}
TripRecordingActiveBottomSheet.this.wasTrackMonitored = wasTrackMonitored;
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(wasTrackMonitored);
updateStatus();
}
@ -273,7 +263,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
private void updateStatus() {
TextView statusTitle = statusContainer.findViewById(R.id.text_status);
AppCompatImageView statusIcon = statusContainer.findViewById(R.id.icon_status);
ItemType status = searchingGPS ? ItemType.SEARCHING_GPS : !wasTrackMonitored ? ItemType.ON_PAUSE : ItemType.RECORDING;
ItemType status = searchingGPS() ? ItemType.SEARCHING_GPS : !wasTrackMonitored() ? ItemType.ON_PAUSE : ItemType.RECORDING;
statusTitle.setText(status.getTitleId());
int colorText = status.equals(ItemType.SEARCHING_GPS) ? getSecondaryTextColorId(nightMode) : getOsmandIconColorId(nightMode);
statusTitle.setTextColor(ContextCompat.getColor(app, colorText));
@ -348,9 +338,6 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
@Override
public void run() {
int interval = app.getSettings().SAVE_GLOBAL_TRACK_INTERVAL.get();
OsmAndLocationProvider locationProvider = app.getLocationProvider();
Location lastKnownLocation = locationProvider.getLastKnownLocation();
searchingGPS = lastKnownLocation == null;
updateStatus();
handler.postDelayed(this, Math.max(1000, interval));
}
@ -367,7 +354,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
@Override
public void run() {
String time = getTimeTrackSaved();
createItem(buttonSave, ItemType.SAVE, hasDataToSave, !Algorithms.isEmpty(time) ? time : null);
createItem(buttonSave, ItemType.SAVE, hasDataToSave(), !Algorithms.isEmpty(time) ? time : null);
handler.postDelayed(this, 60000);
}
};

View file

@ -28,11 +28,11 @@ import net.osmand.AndroidUtils;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.UiUtilities.DialogButtonType;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.helpers.AndroidUiHelper;
@ -278,12 +278,11 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment {
@Override
protected void onRightBottomButtonClick() {
app.getSavingTrackHelper().startNewSegment();
SavingTrackHelper helper = app.getSavingTrackHelper();
helper.startNewSegment();
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(true);
app.startNavigationService(NavigationService.USED_BY_GPX);
OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
TripRecordingActiveBottomSheet.showInstance(getMapActivity().getSupportFragmentManager(),
plugin.getCurrentTrack(), plugin.isWasTrackMonitored(), plugin.isHasDataToSave(), plugin.isSearchingGPS());
TripRecordingActiveBottomSheet.showInstance(getMapActivity().getSupportFragmentManager(), helper.getCurrentTrack());
dismiss();
}