many fixes

This commit is contained in:
Skalii 2021-02-16 03:08:39 +02:00
parent e1ea331bfb
commit ce9b56de2d
7 changed files with 80 additions and 126 deletions

View file

@ -413,6 +413,4 @@
<dimen name="radioButtonSize">32dp</dimen>
<dimen name="checkBoxSize">24dp</dimen>
<dimen name="zero">0dp</dimen>
</resources>

View file

@ -1,11 +1,8 @@
package net.osmand.plus.monitoring;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@ -15,10 +12,8 @@ import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
import net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.ItemType;
import net.osmand.plus.widgets.TextViewEx;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
@ -46,7 +41,7 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
items.add(new DividerSpaceItem(app, verticalBig));
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(setupBtn(inflater, ItemType.CLEAR_DATA))
.setCustomView(TripRecordingActiveBottomSheet.createButton(inflater, ItemType.CLEAR_DATA, nightMode))
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -59,7 +54,7 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
items.add(new DividerSpaceItem(app, verticalBig));
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(setupBtn(inflater, ItemType.CANCEL))
.setCustomView(TripRecordingActiveBottomSheet.createButton(inflater, ItemType.CANCEL, nightMode))
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -71,41 +66,6 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
items.add(new DividerSpaceItem(app, verticalSmall));
}
private View setupBtn(LayoutInflater inflater, ItemType type) {
View button = inflater.inflate(R.layout.bottom_sheet_button_with_icon, null);
button.setTag(type);
Context context = button.getContext();
LinearLayout container = button.findViewById(R.id.button_container);
container.setClickable(false);
container.setFocusable(false);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
int horizontal = context.getResources().getDimensionPixelSize(R.dimen.content_padding);
params.setMargins(horizontal, 0, horizontal, 0);
button.setLayoutParams(params);
if (type.getTitleId() != null) {
UiUtilities.setupDialogButton(nightMode, button, type.getEffect(), type.getTitleId());
}
TextViewEx title = button.findViewById(R.id.button_text);
int margin = context.getResources().getDimensionPixelSize(R.dimen.context_menu_padding_margin_medium);
UiUtilities.setMargins(title, 0, margin, 0, margin);
int colorRes;
if (type.getEffect() == UiUtilities.DialogButtonType.SECONDARY_HARMFUL) {
colorRes = R.color.color_osm_edit_delete;
} else {
colorRes = nightMode ? R.color.dlg_btn_secondary_text_dark : R.color.dlg_btn_secondary_text_light;
}
AppCompatImageView icon = button.findViewById(R.id.icon);
if (type.getIconId() != null) {
icon.setImageDrawable(getIcon(type.getIconId(), colorRes));
}
return button;
}
@Override
public void onResume() {
super.onResume();

View file

@ -19,6 +19,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.AppCompatCheckBox;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import com.google.android.material.slider.Slider;
@ -326,13 +327,13 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
}
public void controlDialog(final Activity activity, final boolean showTrackSelection) {
FragmentManager fragmentManager = ((FragmentActivity) activity).getSupportFragmentManager();
if (hasDataToSave() || wasTrackMonitored()) {
FragmentActivity fragmentActivity = (FragmentActivity) activity;
TripRecordingActiveBottomSheet.showInstance(fragmentActivity.getSupportFragmentManager(), getCurrentTrack());
TripRecordingActiveBottomSheet.showInstance(fragmentManager, getCurrentTrack());
} else {
FragmentActivity fragmentActivity = (FragmentActivity) activity;
TripRecordingBottomSheet.showInstance(fragmentActivity.getSupportFragmentManager());
TripRecordingBottomSheet.showInstance(fragmentManager);
}
/*final boolean wasTrackMonitored = settings.SAVE_GLOBAL_TRACK_TO_GPX.get();
final boolean nightMode;
if (activity instanceof MapActivity) {

View file

@ -1,17 +1,13 @@
package net.osmand.plus.monitoring;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
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.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
@ -19,10 +15,8 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
import net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.ItemType;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.widgets.TextViewEx;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
@ -60,7 +54,7 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
items.add(new DividerSpaceItem(app, verticalBig));
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(setupButton(inflater, ItemType.STOP_AND_DISCARD))
.setCustomView(TripRecordingActiveBottomSheet.createButton(inflater, ItemType.STOP_AND_DISCARD, nightMode))
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -78,7 +72,7 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
items.add(new DividerSpaceItem(app, verticalBig));
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(setupButton(inflater, ItemType.SAVE_AND_STOP))
.setCustomView(TripRecordingActiveBottomSheet.createButton(inflater, ItemType.SAVE_AND_STOP, nightMode))
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -95,7 +89,7 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
items.add(new DividerSpaceItem(app, verticalSmall));
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(setupButton(inflater, ItemType.CANCEL))
.setCustomView(TripRecordingActiveBottomSheet.createButton(inflater, ItemType.CANCEL, nightMode))
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -108,47 +102,6 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
items.add(new DividerSpaceItem(app, verticalSmall));
}
private View setupButton(LayoutInflater inflater, ItemType type) {
View button = inflater.inflate(R.layout.bottom_sheet_button_with_icon, null);
button.setTag(type);
Context context = button.getContext();
LinearLayout container = button.findViewById(R.id.button_container);
container.setClickable(false);
container.setFocusable(false);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
int horizontal = context.getResources().getDimensionPixelSize(R.dimen.content_padding);
params.setMargins(horizontal, 0, horizontal, 0);
button.setLayoutParams(params);
if (type.getTitleId() != null) {
UiUtilities.setupDialogButton(nightMode, button, type.getEffect(), type.getTitleId());
}
TextViewEx title = button.findViewById(R.id.button_text);
int margin = context.getResources().getDimensionPixelSize(R.dimen.context_menu_padding_margin_medium);
UiUtilities.setMargins(title, 0, margin, 0, margin);
int colorRes;
if (type.getEffect() == DialogButtonType.SECONDARY_HARMFUL) {
colorRes = R.color.color_osm_edit_delete;
} else {
colorRes = nightMode ? R.color.dlg_btn_secondary_text_dark : R.color.dlg_btn_secondary_text_light;
}
AppCompatImageView icon = button.findViewById(R.id.icon);
if (type.getIconId() != null) {
icon.setImageDrawable(getIcon(type.getIconId(), colorRes));
}
if (type == ItemType.STOP_AND_DISCARD) {
int size = context.getResources().getDimensionPixelSize(R.dimen.map_widget_height);
LinearLayout.LayoutParams iconParams = new LinearLayout.LayoutParams(size, size);
icon.setLayoutParams(iconParams);
}
return button;
}
@Override
public void onResume() {
super.onResume();

View file

@ -1,5 +1,6 @@
package net.osmand.plus.monitoring;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
@ -27,9 +28,9 @@ import androidx.annotation.StringRes;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.SwitchCompat;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;
@ -47,7 +48,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SavingTrackHelper.SaveGpxResult;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.myplaces.SaveCurrentTrackTask;
@ -69,7 +70,8 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
public static final String TAG = TripRecordingActiveBottomSheet.class.getSimpleName();
private static final Log log = PlatformUtil.getLog(TripRecordingActiveBottomSheet.class);
private static final String UPDATE_CURRENT_GPX_FILE = "update_current_gpx_file";
private static final int GENERAL_UPDATE_INTERVAL = 1000;
private static final int GENERAL_UPDATE_GPS_INTERVAL = 1000;
private static final int GENERAL_UPDATE_SAVE_INTERVAL = 1000;
private OsmandApplication app;
private OsmandSettings settings;
@ -121,7 +123,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
final FragmentManager fragmentManager = getFragmentManager();
View itemView = inflater.inflate(R.layout.trip_recording_active_fragment, null, false);
items.add(new BottomSheetItemWithDescription.Builder()
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(itemView)
.create());
@ -141,7 +143,8 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
RecyclerView statBlocks = itemView.findViewById(R.id.block_statistics);
if (savedInstanceState != null) {
if (savedInstanceState.containsKey(UPDATE_CURRENT_GPX_FILE) && savedInstanceState.getBoolean(UPDATE_CURRENT_GPX_FILE)) {
if (savedInstanceState.containsKey(UPDATE_CURRENT_GPX_FILE)
&& savedInstanceState.getBoolean(UPDATE_CURRENT_GPX_FILE)) {
selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
}
}
@ -332,6 +335,43 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
setItemBackground(button != null ? button : (LinearLayout) view, enabled);
}
protected static View createButton(LayoutInflater inflater, ItemType type, boolean nightMode) {
View button = inflater.inflate(R.layout.bottom_sheet_button_with_icon, null);
button.setTag(type);
Context context = button.getContext();
LinearLayout container = button.findViewById(R.id.button_container);
container.setClickable(false);
container.setFocusable(false);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
int horizontal = context.getResources().getDimensionPixelSize(R.dimen.content_padding);
params.setMargins(horizontal, 0, horizontal, 0);
button.setLayoutParams(params);
if (type.getTitleId() != null) {
UiUtilities.setupDialogButton(nightMode, button, type.getEffect(), type.getTitleId());
}
TextViewEx title = button.findViewById(R.id.button_text);
int margin = context.getResources().getDimensionPixelSize(R.dimen.context_menu_padding_margin_medium);
UiUtilities.setMargins(title, 0, margin, 0, margin);
int colorRes;
if (type.getEffect() == UiUtilities.DialogButtonType.SECONDARY_HARMFUL) {
colorRes = R.color.color_osm_edit_delete;
} else {
colorRes = nightMode ? R.color.dlg_btn_secondary_text_dark : R.color.dlg_btn_secondary_text_light;
}
AppCompatImageView icon = button.findViewById(R.id.icon);
if (type.getIconId() != null) {
Drawable drawable = AppCompatResources.getDrawable(context, type.getIconId());
UiUtilities.tintDrawable(drawable, ContextCompat.getColor(context, colorRes));
icon.setImageDrawable(drawable);
}
return button;
}
private String getTimeTrackSaved() {
long timeTrackSaved = helper.getLastTimeFileSaved();
if (timeTrackSaved != 0) {
@ -369,7 +409,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
public void run() {
int interval = app.getSettings().SAVE_GLOBAL_TRACK_INTERVAL.get();
updateStatus();
handler.postDelayed(this, Math.max(GENERAL_UPDATE_INTERVAL, interval));
handler.postDelayed(this, Math.max(GENERAL_UPDATE_GPS_INTERVAL, interval));
}
};
handler.post(updatingGPS);
@ -385,7 +425,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
public void run() {
String time = getTimeTrackSaved();
createItem(buttonSave, ItemType.SAVE, hasDataToSave(), !Algorithms.isEmpty(time) ? time : null);
handler.postDelayed(this, GENERAL_UPDATE_INTERVAL);
handler.postDelayed(this, GENERAL_UPDATE_SAVE_INTERVAL);
}
};
handler.post(updatingTimeTrackSaved);
@ -405,22 +445,23 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
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),
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
final FragmentManager fragmentManager = mapActivityRef.get().getSupportFragmentManager();
@SuppressLint({"StringFormatInvalid", "LocalSuppress"})
Snackbar snackbar = Snackbar.make(getView(),
app.getResources().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());
fragmentManager.beginTransaction().remove(TripRecordingActiveBottomSheet.this).commitAllowingStateLoss();
SaveGPXBottomSheetFragment.showInstance(fragmentManager, result.getFilenames());
}
});
View view = snackbar.getView();
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) view.getLayoutParams();
params.gravity = Gravity.TOP;
final int dp16 = AndroidUtils.dpToPx(mapActivity, 16f);
AndroidUtils.setMargins(params, 0, AndroidUtils.getStatusBarHeight(context) + dp16, 0, 0);
AndroidUtils.setMargins(params, 0, AndroidUtils.getStatusBarHeight(context), 0, 0);
view.setLayoutParams(params);
UiUtilities.setupSnackbar(snackbar, nightMode);
snackbar.show();
@ -521,11 +562,9 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
public void setTextColor(TextView tv, boolean enabled, boolean nightMode, ItemType type) {
if (tv != null) {
ColorStateList textColorStateList = AndroidUtils.createPressedColorStateList(
app, enabled ? type == ItemType.CLEAR_DATA ? R.color.color_osm_edit_delete
: getActiveTextColorId(nightMode) : getSecondaryTextColorId(nightMode),
getPressedColorId(nightMode)
);
int activeColorId = type == ItemType.CLEAR_DATA ? R.color.color_osm_edit_delete : getActiveTextColorId(nightMode);
int normalColorId = enabled ? activeColorId : getSecondaryTextColorId(nightMode);
ColorStateList textColorStateList = AndroidUtils.createPressedColorStateList(app, normalColorId, getPressedColorId(nightMode));
tv.setTextColor(textColorStateList);
}
}
@ -534,11 +573,9 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
Integer iconId = type.getIconId();
if (iv != null && iconId != null) {
Drawable icon = AppCompatResources.getDrawable(app, iconId);
ColorStateList iconColorStateList = AndroidUtils.createPressedColorStateList(
app, enabled ? type == ItemType.CLEAR_DATA ? R.color.color_osm_edit_delete
: getActiveIconColorId(nightMode) : getSecondaryIconColorId(nightMode),
getPressedColorId(nightMode)
);
int activeColorId = type == ItemType.CLEAR_DATA ? R.color.color_osm_edit_delete : getActiveIconColorId(nightMode);
int normalColorId = enabled ? activeColorId : getSecondaryIconColorId(nightMode);
ColorStateList iconColorStateList = AndroidUtils.createPressedColorStateList(app, normalColorId, getPressedColorId(nightMode));
if (icon != null) {
DrawableCompat.setTintList(icon, iconColorStateList);
}

View file

@ -282,7 +282,10 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment {
helper.startNewSegment();
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(true);
app.startNavigationService(NavigationService.USED_BY_GPX);
TripRecordingActiveBottomSheet.showInstance(getMapActivity().getSupportFragmentManager(), helper.getCurrentTrack());
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
TripRecordingActiveBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), helper.getCurrentTrack());
}
dismiss();
}

View file

@ -51,9 +51,11 @@ public class SaveCurrentTrackTask extends AsyncTask<Void, Void, Boolean> {
}
for (final String f : files.keySet()) {
File fout = new File(dir, f + IndexConstants.GPX_FILE_EXT);
GPXUtilities.writeGpxFile(fout, gpx);
Exception exception = GPXUtilities.writeGpxFile(fout, gpx);
if (exception == null) {
app.getSavingTrackHelper().setLastTimeFileSaved(fout.lastModified());
}
}
return shouldClearPath;
}