groups) {
StringBuilder html = new StringBuilder();
+ StringBuilder buffer = new StringBuilder();
html.append("My Favorites
");
- int addedPoints = 0;
for (FavoriteGroup group : groups) {
- html.append("").append(group.getDisplayName(app)).append("
");
- for (FavouritePoint fp : group.getPoints()) {
- if (addedPoints >= MAX_POINTS_IN_DESCRIPTION) {
- break;
- }
-
- float lat = (float) fp.getLatitude();
- float lon = (float) fp.getLongitude();
- String url = "geo:" + lat + "," + lon + "?m=" + fp.getName();
- html.append("")
- .append(fp.getDisplayName(app))
- .append(" - geo:")
- .append(lat).append(",").append(lon)
- .append("
");
- addedPoints++;
+ buffer.setLength(0);
+ buffer.append("").append(group.getDisplayName(app)).append("
");
+ if (buffer.length() + html.length() > MAX_CHARS_IN_DESCRIPTION) {
+ return html.append("...
").toString();
}
- if (addedPoints >= MAX_POINTS_IN_DESCRIPTION) {
- html.append("...
");
- break;
+ html.append(buffer);
+ boolean reachedLimit = generateHtmlForGroup(group.getPoints(), html);
+ if (reachedLimit) {
+ return html.append("...
").toString();
}
}
+
return html.toString();
}
+ private boolean generateHtmlForGroup(List points, StringBuilder html) {
+ StringBuilder buffer = new StringBuilder();
+
+ for (FavouritePoint fp : points) {
+ buffer.setLength(0);
+
+ float lat = (float) fp.getLatitude();
+ float lon = (float) fp.getLongitude();
+ String url = "geo:" + lat + "," + lon + "?m=" + fp.getName();
+ buffer.append("")
+ .append(fp.getDisplayName(app))
+ .append(" - geo:")
+ .append(lat).append(",").append(lon)
+ .append("
");
+
+ if (buffer.length() + html.length() > MAX_CHARS_IN_DESCRIPTION) {
+ return true;
+ }
+
+ html.append(buffer);
+ }
+
+ return false;
+ }
+
private void shareFavourites() {
if (favouritesAdapter.isEmpty()) {
Toast.makeText(getActivity(), R.string.no_fav_to_save, Toast.LENGTH_LONG).show();
diff --git a/OsmAnd/src/net/osmand/plus/audionotes/MultimediaNotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/MultimediaNotesFragment.java
index 4c1178ef61..3123b81c9b 100644
--- a/OsmAnd/src/net/osmand/plus/audionotes/MultimediaNotesFragment.java
+++ b/OsmAnd/src/net/osmand/plus/audionotes/MultimediaNotesFragment.java
@@ -384,8 +384,12 @@ public class MultimediaNotesFragment extends BaseSettingsFragment implements Cop
File dir = app.getAppPath("").getParentFile();
long size = 0;
if (dir.canRead()) {
- StatFs fs = new StatFs(dir.getAbsolutePath());
- size = ((long) fs.getBlockSize() * (long) fs.getBlockCount()) / (1 << 30);
+ try {
+ StatFs fs = new StatFs(dir.getAbsolutePath());
+ size = ((long) fs.getBlockSize() * (long) fs.getBlockCount()) / (1 << 30);
+ } catch (IllegalArgumentException e) {
+ log.error(e);
+ }
}
if (size > 0) {
int value = 1;
diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashChooseAppDirFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashChooseAppDirFragment.java
index e976d0b4ea..bd8918ac4d 100644
--- a/OsmAnd/src/net/osmand/plus/dashboard/DashChooseAppDirFragment.java
+++ b/OsmAnd/src/net/osmand/plus/dashboard/DashChooseAppDirFragment.java
@@ -31,6 +31,7 @@ import androidx.fragment.app.FragmentActivity;
import net.osmand.AndroidUtils;
import net.osmand.FileUtils;
+import net.osmand.PlatformUtil;
import net.osmand.ValueHolder;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
@@ -39,6 +40,8 @@ import net.osmand.plus.R;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.util.Algorithms;
+import org.apache.commons.logging.Log;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -52,7 +55,7 @@ import java.util.Locale;
import gnu.trove.list.array.TIntArrayList;
public class DashChooseAppDirFragment {
-
+ private static final Log LOG = PlatformUtil.getLog(DashChooseAppDirFragment.class);
public static class ChooseAppDirFragment {
public static final int VERSION_DEFAULTLOCATION_CHANGED = 19;
@@ -92,8 +95,12 @@ public class DashChooseAppDirFragment {
private String getFreeSpace(File dir) {
if (dir.canRead()) {
- StatFs fs = new StatFs(dir.getAbsolutePath());
- return AndroidUtils.formatSize(activity, (long) fs.getAvailableBlocks() * fs.getBlockSize() );
+ try {
+ StatFs fs = new StatFs(dir.getAbsolutePath());
+ return AndroidUtils.formatSize(activity, (long) fs.getAvailableBlocks() * fs.getBlockSize());
+ } catch (IllegalArgumentException e) {
+ LOG.error(e);
+ }
}
return "";
}
diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java
index bc92fc050f..ebbd7d4e3b 100644
--- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java
+++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java
@@ -22,6 +22,8 @@ import android.widget.ProgressBar;
import android.widget.Space;
import android.widget.TextView;
+import com.ibm.icu.impl.IllegalIcuArgumentException;
+
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
@@ -653,9 +655,13 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
String size = "";
int percent = 0;
if (dir.canRead()) {
- StatFs fs = new StatFs(dir.getAbsolutePath());
- size = AndroidUtils.formatSize(activity, ((long) fs.getAvailableBlocks()) * fs.getBlockSize());
- percent = 100 - (int) ((long) fs.getAvailableBlocks() * 100 / fs.getBlockCount());
+ try {
+ StatFs fs = new StatFs(dir.getAbsolutePath());
+ size = AndroidUtils.formatSize(activity, ((long) fs.getAvailableBlocks()) * fs.getBlockSize());
+ percent = 100 - (int) ((long) fs.getAvailableBlocks() * 100 / fs.getBlockCount());
+ } catch (IllegalIcuArgumentException e) {
+ LOG.error(e);
+ }
}
sizeProgress.setIndeterminate(false);
sizeProgress.setProgress(percent);
diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java
index 20ac836139..8b16e48d84 100644
--- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java
+++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java
@@ -304,8 +304,12 @@ public class DownloadIndexesThread {
File dir = app.getAppPath("").getParentFile();
double asz = -1;
if (dir.canRead()) {
- StatFs fs = new StatFs(dir.getAbsolutePath());
- asz = (((long) fs.getAvailableBlocks()) * fs.getBlockSize()) / (1 << 20);
+ try {
+ StatFs fs = new StatFs(dir.getAbsolutePath());
+ asz = (((long) fs.getAvailableBlocks()) * fs.getBlockSize()) / (1 << 20);
+ } catch (IllegalArgumentException e) {
+ LOG.error(e);
+ }
}
return asz;
}
diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java
index a90275c40d..40f4a7488a 100644
--- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java
+++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java
@@ -50,10 +50,10 @@ public class DownloadResources extends DownloadResourceGroup {
public static final String WORLD_SEAMARKS_NAME = "World_seamarks";
public static final String WORLD_SEAMARKS_OLD_KEY = "world_seamarks_basemap";
public static final String WORLD_SEAMARKS_OLD_NAME = "World_seamarks_basemap";
+ public static final String WIKIVOYAGE_FILE_FILTER = "wikivoyage";
private static final Log LOG = PlatformUtil.getLog(DownloadResources.class);
-
-
+
public DownloadResources(OsmandApplication app) {
super(null, DownloadResourceGroupType.WORLD, "");
this.region = app.getRegions().getWorldRegion();
@@ -369,7 +369,9 @@ public class DownloadResources extends DownloadResourceGroup {
continue;
}
if (ii.getType() == DownloadActivityType.TRAVEL_FILE) {
- wikivoyageMaps.addItem(ii);
+ if (ii.getFileName().contains(WIKIVOYAGE_FILE_FILTER)) {
+ wikivoyageMaps.addItem(ii);
+ }
continue;
}
String basename = ii.getBasename().toLowerCase();
diff --git a/OsmAnd/src/net/osmand/plus/download/ui/DataStoragePlaceDialogFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/DataStoragePlaceDialogFragment.java
index f97784cb36..be619f324f 100644
--- a/OsmAnd/src/net/osmand/plus/download/ui/DataStoragePlaceDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/download/ui/DataStoragePlaceDialogFragment.java
@@ -17,12 +17,15 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
+import com.ibm.icu.impl.IllegalIcuArgumentException;
+
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils;
import net.osmand.FileUtils;
import net.osmand.IProgress;
+import net.osmand.PlatformUtil;
import net.osmand.plus.OnDismissDialogFragmentListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
@@ -32,9 +35,12 @@ import net.osmand.plus.dashboard.DashChooseAppDirFragment;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadIndexesThread;
+import org.apache.commons.logging.Log;
+
import java.io.File;
public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
+ private static final Log LOG = PlatformUtil.getLog(DataStoragePlaceDialogFragment.class);
public static final String TAG = "DataStoragePlaceDialogFragment";
private static final String STORAGE_READOLNY_KEY = "storage_readolny_key";
@@ -189,11 +195,15 @@ public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
private String getFreeSpace(File dir) {
String sz = "";
if (dir != null && dir.canRead()) {
- StatFs fs = new StatFs(dir.getAbsolutePath());
- @SuppressWarnings("deprecation")
- long size = (long) fs.getAvailableBlocks() * fs.getBlockSize();
- if (size > 0) {
- sz = AndroidUtils.formatSize(getActivity(), size);
+ try {
+ StatFs fs = new StatFs(dir.getAbsolutePath());
+ @SuppressWarnings("deprecation")
+ long size = (long) fs.getAvailableBlocks() * fs.getBlockSize();
+ if (size > 0) {
+ sz = AndroidUtils.formatSize(getActivity(), size);
+ }
+ } catch (IllegalIcuArgumentException e) {
+ LOG.error(e);
}
}
return sz;
diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java
index 1a4449132d..7a8deaf506 100644
--- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java
+++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java
@@ -335,7 +335,8 @@ public class ItemViewHolder {
clickAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_ENABLE;
}
- } else if (item.getType() == DownloadActivityType.WIKIPEDIA_FILE
+ } else if ((item.getType() == DownloadActivityType.WIKIPEDIA_FILE
+ || item.getType() == DownloadActivityType.TRAVEL_FILE)
&& !Version.isPaidVersion(context.getMyApplication())) {
clickAction = RightButtonAction.ASK_FOR_FULL_VERSION_PURCHASE;
} else if (item.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE && !depthContoursPurchased) {
diff --git a/OsmAnd/src/net/osmand/plus/firstusage/FirstUsageWizardFragment.java b/OsmAnd/src/net/osmand/plus/firstusage/FirstUsageWizardFragment.java
index 9fa4c1efe0..f8c3935b25 100644
--- a/OsmAnd/src/net/osmand/plus/firstusage/FirstUsageWizardFragment.java
+++ b/OsmAnd/src/net/osmand/plus/firstusage/FirstUsageWizardFragment.java
@@ -26,6 +26,7 @@ import androidx.fragment.app.FragmentActivity;
import net.osmand.AndroidNetworkUtils;
import net.osmand.AndroidUtils;
import net.osmand.Location;
+import net.osmand.PlatformUtil;
import net.osmand.ValueHolder;
import net.osmand.binary.BinaryMapDataObject;
import net.osmand.data.LatLon;
@@ -67,6 +68,8 @@ import java.util.TimerTask;
public class FirstUsageWizardFragment extends BaseOsmAndFragment implements OsmAndLocationListener,
AppInitializeListener, DownloadEvents {
+ private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(FirstUsageWizardFragment.class);
+
public static final String TAG = "FirstUsageWizardFrag";
public static final int FIRST_USAGE_LOCATION_PERMISSION = 300;
public static final int FIRST_USAGE_REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION = 400;
@@ -736,8 +739,12 @@ public class FirstUsageWizardFragment extends BaseOsmAndFragment implements OsmA
private String getFreeSpace(File dir) {
if (dir.canRead()) {
- StatFs fs = new StatFs(dir.getAbsolutePath());
- return AndroidUtils.formatSize(getActivity(), (long) fs.getAvailableBlocks() * fs.getBlockSize() );
+ try {
+ StatFs fs = new StatFs(dir.getAbsolutePath());
+ return AndroidUtils.formatSize(getActivity(), (long) fs.getAvailableBlocks() * fs.getBlockSize());
+ } catch (IllegalArgumentException e) {
+ LOG.error(e);
+ }
}
return "";
}
diff --git a/OsmAnd/src/net/osmand/plus/monitoring/ClearRecordedDataBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/ClearRecordedDataBottomSheetFragment.java
index e52462fca7..9a5e40ab95 100644
--- a/OsmAnd/src/net/osmand/plus/monitoring/ClearRecordedDataBottomSheetFragment.java
+++ b/OsmAnd/src/net/osmand/plus/monitoring/ClearRecordedDataBottomSheetFragment.java
@@ -23,12 +23,23 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
private OsmandApplication app;
+ public static void showInstance(@NonNull FragmentManager fragmentManager, @NonNull Fragment target) {
+ if (!fragmentManager.isStateSaved()) {
+ ClearRecordedDataBottomSheetFragment fragment = new ClearRecordedDataBottomSheetFragment();
+ fragment.setTargetFragment(target, 0);
+ fragment.show(fragmentManager, TAG);
+ }
+ }
+
@Override
public void createMenuItems(Bundle savedInstanceState) {
app = requiredMyApplication();
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin);
- int verticalSmall = getResources().getDimensionPixelSize(R.dimen.content_padding_small);
+ int verticalNormal = getResources().getDimensionPixelSize(R.dimen.content_padding);
+
+ final View buttonClear = createItem(inflater, ItemType.CLEAR_DATA);
+ final View buttonCancel = createItem(inflater, ItemType.CANCEL);
items.add(new BottomSheetItemWithDescription.Builder()
.setDescription(app.getString(R.string.clear_recorded_data_warning))
@@ -41,7 +52,7 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
items.add(new DividerSpaceItem(app, verticalBig));
items.add(new BaseBottomSheetItem.Builder()
- .setCustomView(TripRecordingActiveBottomSheet.createButton(inflater, ItemType.CLEAR_DATA, nightMode))
+ .setCustomView(buttonClear)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -54,7 +65,7 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
items.add(new DividerSpaceItem(app, verticalBig));
items.add(new BaseBottomSheetItem.Builder()
- .setCustomView(TripRecordingActiveBottomSheet.createButton(inflater, ItemType.CANCEL, nightMode))
+ .setCustomView(buttonCancel)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -63,7 +74,11 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
})
.create());
- items.add(new DividerSpaceItem(app, verticalSmall));
+ items.add(new DividerSpaceItem(app, verticalNormal));
+ }
+
+ private View createItem(LayoutInflater inflater, ItemType type) {
+ return TripRecordingActiveBottomSheet.createItem(app, nightMode, inflater, type);
}
@Override
@@ -88,12 +103,4 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
protected boolean hideButtonsContainer() {
return true;
}
-
- public static void showInstance(@NonNull FragmentManager fragmentManager, @NonNull Fragment target) {
- if (!fragmentManager.isStateSaved()) {
- ClearRecordedDataBottomSheetFragment fragment = new ClearRecordedDataBottomSheetFragment();
- fragment.setTargetFragment(target, 0);
- fragment.show(fragmentManager, TAG);
- }
- }
}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/monitoring/StopTrackRecordingBottomFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/StopTrackRecordingBottomFragment.java
index ac3ffaf2a5..d996a8a1cd 100644
--- a/OsmAnd/src/net/osmand/plus/monitoring/StopTrackRecordingBottomFragment.java
+++ b/OsmAnd/src/net/osmand/plus/monitoring/StopTrackRecordingBottomFragment.java
@@ -34,6 +34,15 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
this.mapActivity = mapActivity;
}
+ public static void showInstance(MapActivity mapActivity, @NonNull FragmentManager fragmentManager, @NonNull Fragment target) {
+ if (!fragmentManager.isStateSaved()) {
+ StopTrackRecordingBottomFragment fragment = new StopTrackRecordingBottomFragment();
+ fragment.setMapActivity(mapActivity);
+ fragment.setTargetFragment(target, 0);
+ fragment.show(fragmentManager, TAG);
+ }
+ }
+
@Override
public void createMenuItems(Bundle savedInstanceState) {
app = requiredMyApplication();
@@ -41,7 +50,11 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class);
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin);
- int verticalSmall = getResources().getDimensionPixelSize(R.dimen.content_padding_small);
+ int verticalNormal = getResources().getDimensionPixelSize(R.dimen.content_padding);
+
+// final View buttonDiscard = createItem(inflater, ItemType.STOP_AND_DISCARD);
+ final View buttonSave = createItem(inflater, ItemType.STOP_AND_SAVE);
+ final View buttonCancel = createItem(inflater, ItemType.CANCEL);
items.add(new BottomSheetItemWithDescription.Builder()
.setDescription(app.getString(R.string.track_recording_description))
@@ -53,12 +66,12 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
items.add(new DividerSpaceItem(app, verticalBig));
- items.add(new BaseBottomSheetItem.Builder()
- .setCustomView(TripRecordingActiveBottomSheet.createButton(inflater, ItemType.STOP_AND_DISCARD, nightMode))
+ /*items.add(new BaseBottomSheetItem.Builder()
+ .setCustomView(buttonDiscard)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- tag = ItemType.STOP_AND_DISCARD;
+ tag = (ItemType) buttonDiscard.getTag();
if (plugin != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
plugin.stopRecording();
app.getNotificationHelper().refreshNotifications();
@@ -69,14 +82,14 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
})
.create());
- items.add(new DividerSpaceItem(app, verticalBig));
+ items.add(new DividerSpaceItem(app, verticalBig));*/
items.add(new BaseBottomSheetItem.Builder()
- .setCustomView(TripRecordingActiveBottomSheet.createButton(inflater, ItemType.SAVE_AND_STOP, nightMode))
+ .setCustomView(buttonSave)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- tag = ItemType.SAVE_AND_STOP;
+ tag = (ItemType) buttonSave.getTag();
if (plugin != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
plugin.saveCurrentTrack(null, mapActivity);
app.getNotificationHelper().refreshNotifications();
@@ -86,20 +99,24 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
})
.create());
- items.add(new DividerSpaceItem(app, verticalSmall));
+ items.add(new DividerSpaceItem(app, verticalNormal));
items.add(new BaseBottomSheetItem.Builder()
- .setCustomView(TripRecordingActiveBottomSheet.createButton(inflater, ItemType.CANCEL, nightMode))
+ .setCustomView(buttonCancel)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- tag = ItemType.CANCEL;
+ tag = (ItemType) buttonCancel.getTag();
dismiss();
}
})
.create());
- items.add(new DividerSpaceItem(app, verticalSmall));
+ items.add(new DividerSpaceItem(app, verticalNormal));
+ }
+
+ private View createItem(LayoutInflater inflater, ItemType type) {
+ return TripRecordingActiveBottomSheet.createItem(app, nightMode, inflater, type);
}
@Override
@@ -114,10 +131,13 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
@Override
public void onPause() {
super.onPause();
- if (tag == ItemType.CANCEL) {
- Fragment target = getTargetFragment();
- if (target instanceof TripRecordingActiveBottomSheet) {
- ((TripRecordingActiveBottomSheet) target).show();
+ Fragment target = getTargetFragment();
+ if (target instanceof TripRecordingActiveBottomSheet) {
+ TripRecordingActiveBottomSheet tripRec = (TripRecordingActiveBottomSheet) target;
+ if (tag == ItemType.CANCEL) {
+ tripRec.show();
+ } else {
+ tripRec.dismiss();
}
}
}
@@ -126,13 +146,4 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
protected boolean hideButtonsContainer() {
return true;
}
-
- public static void showInstance(MapActivity mapActivity, @NonNull FragmentManager fragmentManager, @NonNull Fragment target) {
- if (!fragmentManager.isStateSaved()) {
- StopTrackRecordingBottomFragment fragment = new StopTrackRecordingBottomFragment();
- fragment.setMapActivity(mapActivity);
- fragment.setTargetFragment(target, 0);
- fragment.show(fragmentManager, TAG);
- }
- }
}
diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingActiveBottomSheet.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingActiveBottomSheet.java
index 6dcca6d355..af636b3424 100644
--- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingActiveBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingActiveBottomSheet.java
@@ -43,7 +43,6 @@ import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmandApplication;
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.activities.SavingTrackHelper.SaveGpxResult;
@@ -62,6 +61,8 @@ import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.lang.ref.WeakReference;
+import java.util.Arrays;
+import java.util.List;
import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT;
@@ -79,6 +80,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
private SelectedGpxFile selectedGpxFile;
private View statusContainer;
+ private LinearLayout buttonAppearance;
private View buttonSave;
private GpxBlockStatisticsBuilder blockStatisticsBuilder;
@@ -128,15 +130,19 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
.create());
View buttonClear = itemView.findViewById(R.id.button_clear);
+ final View buttonOnline = itemView.findViewById(R.id.button_online);
View buttonSegment = itemView.findViewById(R.id.button_segment);
buttonSave = itemView.findViewById(R.id.button_save);
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(buttonSegment, ItemType.START_SEGMENT, wasTrackMonitored(), null);
- createItem(buttonPause, wasTrackMonitored() ? ItemType.PAUSE : ItemType.RESUME, true, null);
- createItem(buttonStop, ItemType.STOP, true, null);
+ createItem(buttonClear, ItemType.CLEAR_DATA, hasDataToSave());
+ createItem(buttonOnline, ItemType.STOP_ONLINE, hasDataToSave());
+ createItem(buttonSegment, ItemType.START_SEGMENT, wasTrackMonitored());
+ createItem(buttonPause, wasTrackMonitored() ? ItemType.PAUSE : ItemType.RESUME, true);
+ createItem(buttonStop, ItemType.STOP, true);
+
+ AndroidUiHelper.updateVisibility(buttonOnline, app.getLiveMonitoringHelper().isLiveMonitoringEnabled());
statusContainer = itemView.findViewById(R.id.status_container);
updateStatus();
@@ -162,31 +168,25 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
if (showTitle != null) {
showTrackTitle.setText(showTitle);
}
+ AndroidUtils.setPadding(buttonShow, AndroidUtils.dpToPx(app, 12f), 0, buttonShow.getPaddingRight(), 0);
showTrackTitle.setTextColor(ContextCompat.getColor(app, getActiveIconColorId(nightMode)));
showTrackTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(R.dimen.default_desc_text_size));
Typeface typeface = FontCache.getFont(app, app.getResources().getString(R.string.font_roboto_medium));
showTrackTitle.setTypeface(typeface);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- float letterSpacing = AndroidUtils.getFloatValueFromRes(app, R.dimen.description_letter_spacing);
+ float letterSpacing = AndroidUtils.getFloatValueFromRes(app, R.dimen.text_button_letter_spacing);
showTrackTitle.setLetterSpacing(letterSpacing);
}
final SwitchCompat showTrackOnMapButton = buttonShow.findViewById(R.id.switch_button);
showTrackOnMapButton.setChecked(app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null);
UiUtilities.setupCompoundButton(showTrackOnMapButton, nightMode, PROFILE_DEPENDENT);
- final LinearLayout buttonAppearance = showTrackContainer.findViewById(R.id.additional_button);
+ buttonAppearance = showTrackContainer.findViewById(R.id.additional_button);
View divider = buttonAppearance.getChildAt(0);
AndroidUiHelper.setVisibility(View.GONE, divider);
int marginS = app.getResources().getDimensionPixelSize(R.dimen.context_menu_padding_margin_small);
UiUtilities.setMargins(buttonAppearance, marginS, 0, 0, 0);
- String width = settings.CURRENT_TRACK_WIDTH.get();
- boolean showArrows = settings.CURRENT_TRACK_SHOW_ARROWS.get();
- int color = settings.CURRENT_TRACK_COLOR.get();
- Drawable appearanceDrawable = TrackAppearanceFragment.getTrackIcon(app, width, showArrows, color);
- AppCompatImageView appearanceIcon = buttonAppearance.findViewById(R.id.icon_after_divider);
- int marginTrackIconH = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
- UiUtilities.setMargins(appearanceIcon, marginTrackIconH, 0, marginTrackIconH, 0);
- appearanceIcon.setImageDrawable(appearanceDrawable);
+ updateTrackIcon(buttonAppearance);
buttonAppearance.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -200,7 +200,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
}
});
- createItem(buttonAppearance, ItemType.APPEARANCE, showTrackOnMapButton.isChecked(), null);
+ createItem(buttonAppearance, ItemType.APPEARANCE, showTrackOnMapButton.isChecked());
setShowOnMapBackground(buttonShow, app, showTrackOnMapButton.isChecked(), nightMode);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
buttonShow.setBackgroundTintList(null);
@@ -211,7 +211,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
boolean checked = !showTrackOnMapButton.isChecked();
showTrackOnMapButton.setChecked(checked);
app.getSelectedGpxHelper().selectGpxFile(app.getSavingTrackHelper().getCurrentGpx(), checked, false);
- createItem(buttonAppearance, ItemType.APPEARANCE, checked, null);
+ createItem(buttonAppearance, ItemType.APPEARANCE, checked);
setShowOnMapBackground(buttonShow, app, checked, nightMode);
}
});
@@ -225,6 +225,14 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
});
+ buttonOnline.findViewById(R.id.button_container).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ settings.LIVE_MONITORING.set(false);
+ AndroidUiHelper.updateVisibility(buttonOnline, false);
+ }
+ });
+
buttonSegment.findViewById(R.id.button_container).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -265,7 +273,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(wasTrackMonitored);
updateStatus();
- createItem(buttonPause, wasTrackMonitored ? ItemType.PAUSE : ItemType.RESUME, true, null);
+ createItem(buttonPause, wasTrackMonitored ? ItemType.PAUSE : ItemType.RESUME, true);
}
});
@@ -279,12 +287,6 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
});
}
- @Override
- public void onSaveInstanceState(@NonNull Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putBoolean(UPDATE_CURRENT_GPX_FILE, true);
- }
-
private void updateStatus() {
TextView statusTitle = statusContainer.findViewById(R.id.text_status);
AppCompatImageView statusIcon = statusContainer.findViewById(R.id.icon_status);
@@ -304,72 +306,67 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
}
+ private void updateTrackIcon(View buttonAppearance) {
+ String width = settings.CURRENT_TRACK_WIDTH.get();
+ boolean showArrows = settings.CURRENT_TRACK_SHOW_ARROWS.get();
+ int color = settings.CURRENT_TRACK_COLOR.get();
+ Drawable appearanceDrawable = TrackAppearanceFragment.getTrackIcon(app, width, showArrows, color);
+ AppCompatImageView appearanceIcon = buttonAppearance.findViewById(R.id.icon_after_divider);
+ int marginTrackIconH = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
+ UiUtilities.setMargins(appearanceIcon, marginTrackIconH, 0, marginTrackIconH, 0);
+ appearanceIcon.setImageDrawable(appearanceDrawable);
+ }
+
+ private void createItem(View view, ItemType type, boolean enabled) {
+ createItem(app, nightMode, view, type, enabled, null);
+ }
+
private void createItem(View view, ItemType type, boolean enabled, @Nullable String description) {
+ createItem(app, nightMode, view, type, enabled, description);
+ }
+
+ public static View createItem(Context context, boolean nightMode, LayoutInflater inflater, ItemType type) {
+ View button = inflater.inflate(R.layout.bottom_sheet_button_with_icon, null);
+ 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);
+ LinearLayout container = button.findViewById(R.id.button_container);
+ container.setClickable(false);
+ container.setFocusable(false);
+ createItem(context, nightMode, button, type, true, null);
+ return button;
+ }
+
+ public static void createItem(Context context, boolean nightMode, View view, ItemType type, boolean enabled, @Nullable String description) {
view.setTag(type);
LinearLayout button = view.findViewById(R.id.button_container);
AppCompatImageView icon = view.findViewById(R.id.icon);
if (icon != null) {
- setTintedIcon(icon, enabled, nightMode, type);
+ setTintedIcon(context, icon, enabled, nightMode, type);
}
TextView title = view.findViewById(R.id.button_text);
Integer titleId = type.getTitleId();
if (title != null && titleId != null) {
title.setText(titleId);
- setTextColor(title, enabled, nightMode, type);
+ setTextColor(context, title, enabled, nightMode, type);
}
TextViewEx desc = view.findViewById(R.id.desc);
if (desc != null) {
boolean isShowDesc = !Algorithms.isBlank(description);
- int marginDesc = isShowDesc ? 0 : app.getResources().getDimensionPixelSize(R.dimen.context_menu_padding_margin_medium);
+ int marginDesc = isShowDesc ? 0 : context.getResources().getDimensionPixelSize(R.dimen.context_menu_padding_margin_medium);
AndroidUiHelper.updateVisibility(desc, isShowDesc);
if (title != null) {
UiUtilities.setMargins(title, 0, marginDesc, 0, marginDesc);
}
desc.setText(description);
- setTextColor(desc, false, nightMode, type);
+ setTextColor(context, desc, false, nightMode, type);
}
- 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;
+ setItemBackground(context, nightMode, button != null ? button : (LinearLayout) view, enabled);
}
private String getTimeTrackSaved() {
@@ -383,6 +380,12 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
}
+ @Override
+ public void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putBoolean(UPDATE_CURRENT_GPX_FILE, true);
+ }
+
@Override
public void onResume() {
super.onResume();
@@ -489,6 +492,13 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
}
+ public void show(boolean updateTrackIcon) {
+ show();
+ if (updateTrackIcon && buttonAppearance != null) {
+ updateTrackIcon(buttonAppearance);
+ }
+ }
+
public void hide() {
Dialog dialog = getDialog();
if (dialog != null) {
@@ -497,31 +507,31 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
public enum ItemType {
- SHOW_TRACK(R.string.shared_string_show_on_map, null, null),
- APPEARANCE(null, null, null),
- SEARCHING_GPS(R.string.searching_gps, R.drawable.ic_action_gps_info, null),
- RECORDING(R.string.recording_default_name, R.drawable.ic_action_track_recordable, null),
- ON_PAUSE(R.string.on_pause, R.drawable.ic_pause, null),
- CLEAR_DATA(R.string.clear_recorded_data, R.drawable.ic_action_delete_dark, UiUtilities.DialogButtonType.SECONDARY_HARMFUL),
- START_SEGMENT(R.string.gpx_start_new_segment, R.drawable.ic_action_new_segment, null),
- SAVE(R.string.shared_string_save, R.drawable.ic_action_save_to_file, null),
- PAUSE(R.string.shared_string_pause, R.drawable.ic_pause, null),
- RESUME(R.string.shared_string_resume, R.drawable.ic_play_dark, null),
- STOP(R.string.shared_string_control_stop, R.drawable.ic_action_rec_stop, null),
- STOP_AND_DISCARD(R.string.track_recording_stop_without_saving, R.drawable.ic_action_rec_stop, DialogButtonType.SECONDARY_HARMFUL),
- SAVE_AND_STOP(R.string.track_recording_save_and_stop, R.drawable.ic_action_save_to_file, DialogButtonType.SECONDARY),
- CANCEL(R.string.shared_string_cancel, R.drawable.ic_action_close, DialogButtonType.SECONDARY);
+ SHOW_TRACK(R.string.shared_string_show_on_map, null),
+ APPEARANCE(null, null),
+ SEARCHING_GPS(R.string.searching_gps, R.drawable.ic_action_gps_info),
+ RECORDING(R.string.recording_default_name, R.drawable.ic_action_track_recordable),
+ ON_PAUSE(R.string.on_pause, R.drawable.ic_pause),
+ CLEAR_DATA(R.string.clear_recorded_data, R.drawable.ic_action_delete_dark),
+ START_SEGMENT(R.string.gpx_start_new_segment, R.drawable.ic_action_new_segment),
+ SAVE(R.string.shared_string_save, R.drawable.ic_action_save_to_file),
+ PAUSE(R.string.shared_string_pause, R.drawable.ic_pause),
+ RESUME(R.string.shared_string_resume, R.drawable.ic_play_dark),
+ STOP(R.string.shared_string_control_stop, R.drawable.ic_action_rec_stop),
+ STOP_AND_DISCARD(R.string.track_recording_stop_without_saving, R.drawable.ic_action_rec_stop),
+ STOP_AND_SAVE(R.string.track_recording_save_and_stop, R.drawable.ic_action_save_to_file),
+ STOP_ONLINE(R.string.live_monitoring_stop, R.drawable.ic_world_globe_dark),
+ CANCEL(R.string.shared_string_cancel, R.drawable.ic_action_close);
@StringRes
private final Integer titleId;
@DrawableRes
private final Integer iconId;
- private final DialogButtonType effect;
+ private static final List negative = Arrays.asList(CLEAR_DATA, STOP_AND_DISCARD);
- ItemType(@Nullable @StringRes Integer titleId, @Nullable @DrawableRes Integer iconId, @Nullable DialogButtonType effect) {
+ ItemType(@Nullable @StringRes Integer titleId, @Nullable @DrawableRes Integer iconId) {
this.titleId = titleId;
this.iconId = iconId;
- this.effect = effect;
}
@Nullable
@@ -534,53 +544,52 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
return iconId;
}
- @Nullable
- public DialogButtonType getEffect() {
- return effect;
+ public boolean isNegative() {
+ return negative.contains(this);
}
}
- private void setItemBackground(LinearLayout view, boolean enabled) {
- Drawable background = AppCompatResources.getDrawable(app, R.drawable.btn_background_inactive_light);
+ public static void setItemBackground(Context context, boolean nightMode, LinearLayout view, boolean enabled) {
+ Drawable background = AppCompatResources.getDrawable(context, R.drawable.btn_background_inactive_light);
if (background != null && enabled) {
ColorStateList iconColorStateList = AndroidUtils.createPressedColorStateList(
- app, getInactiveButtonColorId(nightMode), getActiveButtonColorId(nightMode)
+ context, getInactiveButtonColorId(nightMode), getActiveButtonColorId(nightMode)
);
DrawableCompat.setTintList(background, iconColorStateList);
} else {
- UiUtilities.tintDrawable(background, ContextCompat.getColor(app, getInactiveButtonColorId(nightMode)));
+ UiUtilities.tintDrawable(background, ContextCompat.getColor(context, getInactiveButtonColorId(nightMode)));
}
view.setBackgroundDrawable(background);
}
- private static void setShowOnMapBackground(LinearLayout view, Context context, boolean checked, boolean nightMode) {
+ public static void setShowOnMapBackground(LinearLayout view, Context context, boolean checked, boolean nightMode) {
Drawable background = AppCompatResources.getDrawable(context,
nightMode ? checked ? R.drawable.btn_background_inactive_dark : R.drawable.btn_background_stroked_inactive_dark
: checked ? R.drawable.btn_background_inactive_light : R.drawable.btn_background_stroked_inactive_light);
view.setBackgroundDrawable(background);
}
- public void setTextColor(TextView tv, boolean enabled, boolean nightMode, ItemType type) {
+ public static void setTextColor(Context context, TextView tv, boolean enabled, boolean nightMode, ItemType type) {
if (tv != null) {
- int activeColorId = type == ItemType.CLEAR_DATA ? R.color.color_osm_edit_delete : getActiveTextColorId(nightMode);
+ int activeColorId = type.isNegative() ? R.color.color_osm_edit_delete : getActiveTextColorId(nightMode);
int normalColorId = enabled ? activeColorId : getSecondaryTextColorId(nightMode);
- ColorStateList textColorStateList = AndroidUtils.createPressedColorStateList(app, normalColorId, getPressedColorId(nightMode));
+ ColorStateList textColorStateList = AndroidUtils.createPressedColorStateList(context, normalColorId, getPressedColorId(nightMode));
tv.setTextColor(textColorStateList);
}
}
- public void setTintedIcon(AppCompatImageView iv, boolean enabled, boolean nightMode, ItemType type) {
+ public static void setTintedIcon(Context context, AppCompatImageView iv, boolean enabled, boolean nightMode, ItemType type) {
Integer iconId = type.getIconId();
if (iv != null && iconId != null) {
- Drawable icon = AppCompatResources.getDrawable(app, iconId);
- int activeColorId = type == ItemType.CLEAR_DATA ? R.color.color_osm_edit_delete : getActiveIconColorId(nightMode);
+ Drawable icon = AppCompatResources.getDrawable(context, iconId);
+ int activeColorId = type.isNegative() ? R.color.color_osm_edit_delete : getActiveIconColorId(nightMode);
int normalColorId = enabled ? activeColorId : getSecondaryIconColorId(nightMode);
- ColorStateList iconColorStateList = AndroidUtils.createPressedColorStateList(app, normalColorId, getPressedColorId(nightMode));
+ ColorStateList iconColorStateList = AndroidUtils.createPressedColorStateList(context, normalColorId, getPressedColorId(nightMode));
if (icon != null) {
DrawableCompat.setTintList(icon, iconColorStateList);
}
iv.setImageDrawable(icon);
- if (type == ItemType.STOP) {
+ if (type.iconId == R.drawable.ic_action_rec_stop) {
int stopSize = iv.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin_large);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(stopSize, stopSize);
iv.setLayoutParams(params);
@@ -589,42 +598,42 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
@ColorRes
- private static int getActiveTextColorId(boolean nightMode) {
+ public static int getActiveTextColorId(boolean nightMode) {
return nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
}
@ColorRes
- private static int getSecondaryTextColorId(boolean nightMode) {
+ public static int getSecondaryTextColorId(boolean nightMode) {
return nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light;
}
@ColorRes
- private static int getActiveIconColorId(boolean nightMode) {
+ public static int getActiveIconColorId(boolean nightMode) {
return nightMode ? R.color.icon_color_active_dark : R.color.icon_color_active_light;
}
@ColorRes
- private static int getSecondaryIconColorId(boolean nightMode) {
+ public static int getSecondaryIconColorId(boolean nightMode) {
return nightMode ? R.color.icon_color_secondary_dark : R.color.icon_color_secondary_light;
}
@ColorRes
- private static int getActiveButtonColorId(boolean nightMode) {
+ public static int getActiveButtonColorId(boolean nightMode) {
return nightMode ? R.color.active_buttons_and_links_bg_pressed_dark : R.color.active_buttons_and_links_bg_pressed_light;
}
@ColorRes
- private static int getInactiveButtonColorId(boolean nightMode) {
+ public static int getInactiveButtonColorId(boolean nightMode) {
return nightMode ? R.color.inactive_buttons_and_links_bg_dark : R.color.inactive_buttons_and_links_bg_light;
}
@ColorRes
- private static int getOsmandIconColorId(boolean nightMode) {
+ public static int getOsmandIconColorId(boolean nightMode) {
return nightMode ? R.color.icon_color_osmand_dark : R.color.icon_color_osmand_light;
}
@ColorRes
- private static int getPressedColorId(boolean nightMode) {
+ public static int getPressedColorId(boolean nightMode) {
return nightMode ? R.color.active_buttons_and_links_text_dark : R.color.active_buttons_and_links_text_light;
}
diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java
index 47b4b037df..e48e37878a 100644
--- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java
+++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java
@@ -88,6 +88,7 @@ public class ResourceManager {
public static final String VECTOR_MAP = "#vector_map"; //$NON-NLS-1$
private static final String INDEXES_CACHE = "ind.cache";
+ public static final String DEFAULT_WIKIVOYAGE_TRAVEL_OBF = "Default_wikivoyage.travel.obf";
private static final Log log = PlatformUtil.getLog(ResourceManager.class);
@@ -638,6 +639,8 @@ public class ResourceManager {
if (Version.isPaidVersion(context)) {
collectFiles(context.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
collectFiles(context.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT, files);
+ } else {
+ collectFiles(context.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), DEFAULT_WIKIVOYAGE_TRAVEL_OBF, files);
}
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isContourLinesPurchased(context)) {
collectFiles(context.getAppPath(IndexConstants.SRTM_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
@@ -701,7 +704,7 @@ public class ResourceManager {
}
boolean wikiMap = (f.getName().contains("_wiki") || f.getName().contains(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT));
boolean srtmMap = f.getName().contains(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT);
- if (mapReader == null || (!Version.isPaidVersion(context) && wikiMap)) {
+ if (mapReader == null || (!Version.isPaidVersion(context) && wikiMap && !f.getName().equals(DEFAULT_WIKIVOYAGE_TRAVEL_OBF))) {
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
} else {
if (mapReader.isBasemap()) {
diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
index eb1ffedae5..3f0a30c99f 100644
--- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
+++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
@@ -424,16 +424,13 @@ public class RouteProvider {
if (gpxParams.reverse && gpxParams.routePoints.size() > 1) {
List gpxRouteLocations = new ArrayList<>();
List gpxRoute = new ArrayList<>();
- Location start = null;
- for (int i = 0; i < gpxParams.routePoints.size(); i++) {
- WptPt pt = gpxParams.routePoints.get(i);
- ApplicationMode appMode = ApplicationMode.valueOfStringKey(pt.getProfileType(), ApplicationMode.DEFAULT);
- LatLon end = new LatLon(pt.getLatitude(), pt.getLongitude());
- if (start == null) {
- start = new Location("");
- start.setLatitude(routeParams.start.getLatitude());
- start.setLongitude(routeParams.start.getLongitude());
- }
+ WptPt firstGpxPoint = gpxParams.routePoints.get(0);
+ Location start = new Location("", firstGpxPoint.getLatitude(), firstGpxPoint.getLongitude());
+
+ for (int i = 1; i < gpxParams.routePoints.size(); i++) {
+ WptPt gpxPoint = gpxParams.routePoints.get(i);
+ ApplicationMode appMode = ApplicationMode.valueOfStringKey(gpxPoint.getProfileType(), ApplicationMode.DEFAULT);
+ LatLon end = new LatLon(gpxPoint.getLatitude(), gpxPoint.getLongitude());
RouteCalculationParams params = new RouteCalculationParams();
params.inSnapToRoadMode = true;
@@ -457,7 +454,7 @@ public class RouteProvider {
routeParams.mode.getDefaultSpeed(), new LocationsHolder(locations).getLatLonList()));
}
gpxRouteLocations.addAll(locations);
- if (i > 0 && !gpxRouteLocations.isEmpty()) {
+ if (!gpxRouteLocations.isEmpty()) {
gpxRouteLocations.remove(gpxRouteLocations.size() - 1);
}
gpxRoute.addAll(route);
@@ -478,29 +475,29 @@ public class RouteProvider {
RouteCalculationResult result = new RouteCalculationResult(gpxRouteResult, routeParams.start, routeParams.end,
routeParams.intermediates, routeParams.ctx, routeParams.leftSide, null, null, routeParams.mode, false);
List gpxRouteLocations = result.getImmutableAllLocations();
- int gpxNextIndex = calcWholeRoute ? 0 : findStartIndexFromRoute(gpxRouteLocations, routeParams.start, calculateOsmAndRouteParts);
- Location gpxNextLocation = null;
+ int nearestGpxPointInd = calcWholeRoute ? 0 : findNearestGpxPointIndexFromRoute(gpxRouteLocations, routeParams.start, calculateOsmAndRouteParts);
+ Location nearestGpxLocation = null;
Location gpxLastLocation = !gpxRouteLocations.isEmpty() ? gpxRouteLocations.get(gpxRouteLocations.size() - 1) : null;
List firstSegmentRoute = null;
List lastSegmentRoute = null;
List gpxRoute;
- if (gpxNextIndex > 0) {
- gpxNextLocation = gpxRouteLocations.get(gpxNextIndex);
- gpxRoute = result.getOriginalRoute(gpxNextIndex);
+ if (nearestGpxPointInd > 0) {
+ nearestGpxLocation = gpxRouteLocations.get(nearestGpxPointInd);
+ gpxRoute = result.getOriginalRoute(nearestGpxPointInd);
if (gpxRoute.size() > 0) {
gpxRoute.remove(0);
}
} else {
if (!gpxRouteLocations.isEmpty()) {
- gpxNextLocation = gpxRouteLocations.get(0);
+ nearestGpxLocation = gpxRouteLocations.get(0);
}
gpxRoute = result.getOriginalRoute();
}
if (calculateOsmAndRouteParts
- && routeParams.start != null && gpxNextLocation != null
- && gpxNextLocation.distanceTo(routeParams.start) > MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT) {
+ && routeParams.start != null && nearestGpxLocation != null
+ && nearestGpxLocation.distanceTo(routeParams.start) > MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT) {
RouteCalculationResult firstSegmentResult = findOfflineRouteSegment(
- routeParams, routeParams.start, new LatLon(gpxNextLocation.getLatitude(), gpxNextLocation.getLongitude()));
+ routeParams, routeParams.start, new LatLon(nearestGpxLocation.getLatitude(), nearestGpxLocation.getLongitude()));
firstSegmentRoute = firstSegmentResult.getOriginalRoute();
}
if (calculateOsmAndRouteParts
@@ -750,28 +747,28 @@ public class RouteProvider {
return sublist;
}
- private int findStartIndexFromRoute(List route, Location startLoc, boolean calculateOsmAndRouteParts) {
+ private int findNearestGpxPointIndexFromRoute(List route, Location startLoc, boolean calculateOsmAndRouteParts) {
float minDist = Integer.MAX_VALUE;
- int start = 0;
+ int nearestPointIndex = 0;
if (startLoc != null) {
for (int i = 0; i < route.size(); i++) {
float d = route.get(i).distanceTo(startLoc);
if (d < minDist) {
- start = i;
+ nearestPointIndex = i;
minDist = d;
}
}
}
- if (start > 0 && calculateOsmAndRouteParts) {
- Location newStartLoc = route.get(start);
- for (int i = start + 1; i < route.size(); i++) {
- Location loc = route.get(i);
- if (loc.distanceTo(newStartLoc) >= ADDITIONAL_DISTANCE_FOR_START_POINT) {
+ if (nearestPointIndex > 0 && calculateOsmAndRouteParts) {
+ Location nearestLocation = route.get(nearestPointIndex);
+ for (int i = nearestPointIndex + 1; i < route.size(); i++) {
+ Location nextLocation = route.get(i);
+ if (nextLocation.distanceTo(nearestLocation) >= ADDITIONAL_DISTANCE_FOR_START_POINT) {
return i;
}
}
}
- return start;
+ return nearestPointIndex;
}
protected String getString(Context ctx, int resId){
diff --git a/OsmAnd/src/net/osmand/plus/settings/datastorage/DataStorageHelper.java b/OsmAnd/src/net/osmand/plus/settings/datastorage/DataStorageHelper.java
index ecc0f04842..67fd73897e 100644
--- a/OsmAnd/src/net/osmand/plus/settings/datastorage/DataStorageHelper.java
+++ b/OsmAnd/src/net/osmand/plus/settings/datastorage/DataStorageHelper.java
@@ -39,6 +39,7 @@ public class DataStorageHelper {
public final static String MANUALLY_SPECIFIED = "manually_specified";
public final static String MAPS_MEMORY = "maps_memory_used";
+ public final static String TRAVEL_MEMORY = "travel_memory_used";
public final static String TERRAIN_MEMORY = "terrain_memory_used";
public final static String TRACKS_MEMORY = "tracks_memory_used";
public final static String NOTES_MEMORY = "notes_memory_used";
@@ -52,6 +53,7 @@ public class DataStorageHelper {
private ArrayList memoryItems = new ArrayList<>();
private MemoryItem mapsMemory;
+ private MemoryItem travelMemory;
private MemoryItem terrainMemory;
private MemoryItem tracksMemory;
private MemoryItem notesMemory;
@@ -184,11 +186,18 @@ public class DataStorageHelper {
createDirectory(MAPS_PATH, false, EXTENSIONS, true),
createDirectory(ROADS_INDEX_DIR, true, EXTENSIONS, true),
createDirectory(WIKI_INDEX_DIR, true, EXTENSIONS, true),
- createDirectory(WIKIVOYAGE_INDEX_DIR, true, EXTENSIONS, true),
createDirectory(BACKUP_INDEX_DIR, true, EXTENSIONS, true))
.createItem();
memoryItems.add(mapsMemory);
+ travelMemory = MemoryItem.builder()
+ .setKey(TRAVEL_MEMORY)
+ .setExtensions(IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT)
+ .setDirectories(
+ createDirectory(WIKIVOYAGE_INDEX_DIR, true, EXTENSIONS, true))
+ .createItem();
+ memoryItems.add(travelMemory);
+
terrainMemory = MemoryItem.builder()
.setKey(TERRAIN_MEMORY)
.setExtensions(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)
@@ -270,7 +279,7 @@ public class DataStorageHelper {
public RefreshUsedMemoryTask calculateMemoryUsedInfo(UpdateMemoryInfoUIAdapter uiAdapter) {
File rootDir = new File(currentStoragePath);
RefreshUsedMemoryTask task = new RefreshUsedMemoryTask(uiAdapter, otherMemory, rootDir, null, null, OTHER_MEMORY);
- task.execute(mapsMemory, terrainMemory, tracksMemory, notesMemory);
+ task.execute(mapsMemory, travelMemory, terrainMemory, tracksMemory, notesMemory);
return task;
}
diff --git a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java
index d75416052e..09adb88117 100644
--- a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java
+++ b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java
@@ -1,6 +1,7 @@
package net.osmand.plus.track;
import android.graphics.drawable.Drawable;
+import android.os.Build;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
@@ -250,7 +251,11 @@ public class GpxBlockStatisticsBuilder {
holder.valueText.setTextColor(activeColor);
holder.titleText.setText(item.title);
holder.titleText.setTextColor(app.getResources().getColor(R.color.text_color_secondary_light));
- holder.titleText.setWidth(calculateWidthWithin(item.title, item.value));
+ float letterSpacing = 0.00f;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ letterSpacing = Math.max(holder.valueText.getLetterSpacing(), holder.titleText.getLetterSpacing());
+ }
+ holder.titleText.setMinWidth(calculateWidthWithin(letterSpacing, item.title, item.value));
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -283,8 +288,11 @@ public class GpxBlockStatisticsBuilder {
notifyDataSetChanged();
}
- public int calculateWidthWithin(String... texts) {
+ public int calculateWidthWithin(float letterSpacing, String... texts) {
int textWidth = AndroidUtils.getTextMaxWidth(textSize, Arrays.asList(texts));
+ if (letterSpacing != 0.00f) {
+ textWidth += Math.ceil(textWidth * letterSpacing);
+ }
return Math.min(maxWidthPx, Math.max(minWidthPx, textWidth));
}
}
diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java
index 0ad5475337..eda708dbc9 100644
--- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java
+++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java
@@ -385,7 +385,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
if (target instanceof TripRecordingBottomSheet) {
((TripRecordingBottomSheet) target).show();
} else if (target instanceof TripRecordingActiveBottomSheet) {
- ((TripRecordingActiveBottomSheet) target).show();
+ ((TripRecordingActiveBottomSheet) target).show(true);
}
}
diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java
index fb72c0a9c8..36fb29caa6 100644
--- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java
+++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java
@@ -83,6 +83,7 @@ import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
+import net.osmand.plus.track.TrackSelectSegmentBottomSheet.OnSegmentSelectedListener;
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
import net.osmand.plus.widgets.IconPopupMenu;
import net.osmand.util.Algorithms;
@@ -94,6 +95,8 @@ import java.io.File;
import java.lang.ref.WeakReference;
import java.util.List;
+import static net.osmand.plus.activities.MapActivityActions.KEY_LATITUDE;
+import static net.osmand.plus.activities.MapActivityActions.KEY_LONGITUDE;
import static net.osmand.plus.activities.TrackActivity.CURRENT_RECORDING;
import static net.osmand.plus.activities.TrackActivity.TRACK_FILE_NAME;
import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.isGpxFileSelected;
@@ -115,7 +118,7 @@ import static net.osmand.plus.track.TrackPointsCard.OPEN_WAYPOINT_INDEX;
public class TrackMenuFragment extends ContextMenuScrollFragment implements CardListener,
SegmentActionsListener, RenameCallback, OnTrackFileMoveListener, OnPointsDeleteListener,
- OsmAndLocationListener, OsmAndCompassListener, TrackSelectSegmentBottomSheet.OnSegmentSelectedListener {
+ OsmAndLocationListener, OsmAndCompassListener, OnSegmentSelectedListener {
public static final String OPEN_TRACK_MENU = "open_track_menu";
public static final String RETURN_SCREEN_NAME = "return_screen_name";
@@ -226,18 +229,32 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
app = requireMyApplication();
displayHelper = new TrackDisplayHelper(app);
updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache();
-
- if (!selectedGpxFile.isShowCurrentTrack()) {
- File file = new File(selectedGpxFile.getGpxFile().path);
- displayHelper.setFile(file);
- displayHelper.setGpxDataItem(app.getGpxDbHelper().getItem(file));
- }
- displayHelper.setGpx(selectedGpxFile.getGpxFile());
- String fileName = Algorithms.getFileWithoutDirs(getGpx().path);
- gpxTitle = !isCurrentRecordingTrack() ? GpxUiHelper.getGpxTitle(fileName)
- : app.getResources().getString(R.string.shared_string_currently_recording_track);
toolbarHeightPx = getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar);
+ if (selectedGpxFile == null && savedInstanceState != null) {
+ String path = savedInstanceState.getString(TRACK_FILE_NAME);
+ boolean showCurrentTrack = savedInstanceState.getBoolean(CURRENT_RECORDING);
+ MapActivity mapActivity = requireMapActivity();
+ loadSelectedGpxFile(mapActivity, path, showCurrentTrack, new CallbackWithObject() {
+ @Override
+ public boolean processResult(SelectedGpxFile result) {
+ selectedGpxFile = result;
+ setupDisplayHelper();
+ if (getView() != null) {
+ initContent(getView());
+ }
+ return true;
+ }
+ });
+ if (savedInstanceState.containsKey(KEY_LATITUDE) && savedInstanceState.containsKey(KEY_LONGITUDE)) {
+ double latitude = savedInstanceState.getDouble(KEY_LATITUDE);
+ double longitude = savedInstanceState.getDouble(KEY_LONGITUDE);
+ latLon = new LatLon(latitude, longitude);
+ }
+ } else if (selectedGpxFile != null) {
+ setupDisplayHelper();
+ }
+
FragmentActivity activity = requireMyActivity();
activity.getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
public void handleOnBackPressed() {
@@ -261,6 +278,18 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
});
}
+ private void setupDisplayHelper() {
+ if (!selectedGpxFile.isShowCurrentTrack()) {
+ File file = new File(selectedGpxFile.getGpxFile().path);
+ displayHelper.setFile(file);
+ displayHelper.setGpxDataItem(app.getGpxDbHelper().getItem(file));
+ }
+ displayHelper.setGpx(selectedGpxFile.getGpxFile());
+ String fileName = Algorithms.getFileWithoutDirs(getGpx().path);
+ gpxTitle = !isCurrentRecordingTrack() ? GpxUiHelper.getGpxTitle(fileName)
+ : app.getResources().getString(R.string.shared_string_currently_recording_track);
+ }
+
public GPXFile getGpx() {
return displayHelper.getGpx();
}
@@ -300,21 +329,26 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
params.gravity = Gravity.BOTTOM | Gravity.START;
bottomNav.setLayoutParams(params);
}
-
- setupCards();
- setupToolbar();
- updateHeader();
- setupButtons(view);
- updateCardsLayout();
- if (menuType == TrackMenuType.OVERVIEW && isPortrait()) {
- calculateLayoutAndShowHeader();
- } else {
- calculateLayoutAndUpdateMenuState();
+ if (selectedGpxFile != null) {
+ initContent(view);
}
}
return view;
}
+ private void initContent(@NonNull View view) {
+ setupCards();
+ setupToolbar();
+ updateHeader();
+ setupButtons(view);
+ updateCardsLayout();
+ if (menuType == TrackMenuType.OVERVIEW && isPortrait()) {
+ calculateLayoutAndShowHeader();
+ } else {
+ calculateLayoutAndUpdateMenuState();
+ }
+ }
+
private void setHeaderTitle(String text, boolean iconVisibility) {
headerTitle.setText(text);
AndroidUiHelper.updateVisibility(headerIcon, iconVisibility);
@@ -553,9 +587,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
}
updateControlsVisibility(true);
startLocationUpdate();
- GpxBlockStatisticsBuilder blockStats = overviewCard.getBlockStatisticsBuilder();
- if (menuType == TrackMenuType.OVERVIEW && isCurrentRecordingTrack()) {
- blockStats.runUpdatingStatBlocksIfNeeded();
+ if (overviewCard != null && menuType == TrackMenuType.OVERVIEW && isCurrentRecordingTrack()) {
+ overviewCard.getBlockStatisticsBuilder().runUpdatingStatBlocksIfNeeded();
}
}
@@ -568,7 +601,9 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
}
updateControlsVisibility(false);
stopLocationUpdate();
- overviewCard.getBlockStatisticsBuilder().stopUpdatingStatBlocks();
+ if (overviewCard != null) {
+ overviewCard.getBlockStatisticsBuilder().stopUpdatingStatBlocks();
+ }
}
@Override
@@ -603,8 +638,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
private void updateDistanceDirection() {
MapActivity mapActivity = getMapActivity();
- View view = overviewCard.getView();
- if (mapActivity != null && view != null) {
+ if (mapActivity != null && overviewCard != null && overviewCard.getView() != null) {
+ View view = overviewCard.getView();
TextView distanceText = view.findViewById(R.id.distance);
ImageView direction = view.findViewById(R.id.direction);
app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, latLon);
@@ -677,6 +712,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putString(TRACK_FILE_NAME, getGpx().path);
outState.putBoolean(CURRENT_RECORDING, selectedGpxFile.isShowCurrentTrack());
+ if (latLon != null) {
+ outState.putDouble(KEY_LATITUDE, latLon.getLatitude());
+ outState.putDouble(KEY_LONGITUDE, latLon.getLongitude());
+ }
super.onSaveInstanceState(outState);
}
@@ -763,7 +802,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
segment = segments.get(0);
}
}
- GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT};
+ GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT};
List items = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes));
if (segment != null && !Algorithms.isEmpty(items)) {
SplitSegmentDialogFragment.showInstance(fragmentManager, displayHelper, items.get(0), segment);
@@ -888,9 +927,9 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
}
private void adjustMapPosition(int y) {
+ GPXFile gpxFile = getGpx();
MapActivity mapActivity = getMapActivity();
- if (mapActivity != null && mapActivity.getMapView() != null) {
- GPXFile gpxFile = getGpx();
+ if (mapActivity != null && mapActivity.getMapView() != null && gpxFile != null) {
QuadRect r = gpxFile.getRect();
RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy();
@@ -1148,7 +1187,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
@Override
public void gpxSavingFinished(Exception errorMessage) {
if (selectedGpxFile != null) {
- List groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT});
+ List groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT});
selectedGpxFile.setDisplayGroups(groups, app);
selectedGpxFile.processPoints(app);
}
@@ -1204,8 +1243,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
}
}
- public static void showInstance(@NonNull MapActivity mapActivity, @Nullable String path,
- boolean showCurrentTrack, @Nullable final LatLon latLon, @Nullable final String returnScreenName) {
+ private static void loadSelectedGpxFile(@NonNull MapActivity mapActivity, @Nullable String path,
+ boolean showCurrentTrack, final CallbackWithObject callback) {
OsmandApplication app = mapActivity.getMyApplication();
SelectedGpxFile selectedGpxFile;
if (showCurrentTrack) {
@@ -1214,7 +1253,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(path);
}
if (selectedGpxFile != null) {
- showInstance(mapActivity, selectedGpxFile, latLon, returnScreenName);
+ callback.processResult(selectedGpxFile);
} else if (!Algorithms.isEmpty(path)) {
String title = app.getString(R.string.loading_smth, "");
final ProgressDialog progress = ProgressDialog.show(mapActivity, title, app.getString(R.string.loading_data));
@@ -1228,7 +1267,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
OsmandApplication app = mapActivity.getMyApplication();
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().selectGpxFile(result, true, false);
if (selectedGpxFile != null) {
- showInstance(mapActivity, selectedGpxFile, latLon, returnScreenName);
+ callback.processResult(selectedGpxFile);
}
}
if (progress != null && AndroidUtils.isActivityNotDestroyed(mapActivity)) {
@@ -1241,6 +1280,21 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
}
}
+ public static void showInstance(@NonNull MapActivity mapActivity, @Nullable String path,
+ boolean showCurrentTrack, @Nullable final LatLon latLon, @Nullable final String returnScreenName) {
+ final WeakReference mapActivityRef = new WeakReference<>(mapActivity);
+ loadSelectedGpxFile(mapActivity, path, showCurrentTrack, new CallbackWithObject() {
+ @Override
+ public boolean processResult(SelectedGpxFile selectedGpxFile) {
+ MapActivity mapActivity = mapActivityRef.get();
+ if (mapActivity != null && selectedGpxFile != null) {
+ showInstance(mapActivity, selectedGpxFile, latLon, returnScreenName);
+ }
+ return true;
+ }
+ });
+ }
+
public static boolean showInstance(@NonNull MapActivity mapActivity, @NonNull SelectedGpxFile selectedGpxFile,
@Nullable LatLon latLon, @Nullable String returnScreenName) {
try {
diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/PopularArticles.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/PopularArticles.java
new file mode 100644
index 0000000000..e354825b17
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/PopularArticles.java
@@ -0,0 +1,48 @@
+package net.osmand.plus.wikivoyage.data;
+
+import androidx.annotation.NonNull;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PopularArticles {
+
+ public static final int ARTICLES_PER_PAGE = 30;
+
+ private List articles;
+
+ public PopularArticles() {
+ this.articles = new ArrayList<>();
+ }
+
+ public PopularArticles(@NonNull PopularArticles articles) {
+ this.articles = articles.articles;
+ }
+
+ public void clear() {
+ articles = new ArrayList<>();
+ }
+
+ @NonNull
+ public List getArticles() {
+ return new ArrayList<>(articles);
+ }
+
+ public boolean add(@NonNull TravelArticle article) {
+ articles.add(article);
+ return articles.size() % ARTICLES_PER_PAGE != 0;
+ }
+
+ public boolean contains(@NonNull TravelArticle article) {
+ return articles.contains(article);
+ }
+
+ public boolean containsByRouteId(@NonNull String routeId) {
+ for (TravelArticle article : articles) {
+ if (article.getRouteId().equals(routeId)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java
index 2b08f7a1e3..e58b8057c6 100644
--- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java
+++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java
@@ -55,6 +55,7 @@ import static net.osmand.GPXUtilities.TrkSegment;
import static net.osmand.GPXUtilities.WptPt;
import static net.osmand.GPXUtilities.writeGpxFile;
import static net.osmand.plus.helpers.GpxUiHelper.getGpxTitle;
+import static net.osmand.plus.wikivoyage.data.PopularArticles.ARTICLES_PER_PAGE;
import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELE_DOWN;
import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELE_UP;
import static net.osmand.plus.wikivoyage.data.TravelGpx.DISTANCE;
@@ -69,16 +70,16 @@ public class TravelObfHelper implements TravelHelper {
public static final String ROUTE_ARTICLE = "route_article";
public static final String ROUTE_ARTICLE_POINT = "route_article_point";
public static final String ROUTE_TRACK = "route_track";
- public static final int ARTICLE_SEARCH_RADIUS = 50000;
- public static final int SAVED_ARTICLE_SEARCH_RADIUS = 30000;
- public static final int MAX_POPULAR_ARTICLES_COUNT = 30;
+ public static final int ARTICLE_SEARCH_RADIUS = 50 * 1000;
+ public static final int SAVED_ARTICLE_SEARCH_RADIUS = 30 * 1000;
+ public static final int MAX_SEARCH_RADIUS = 10000 * 1000;
public static final String REF_TAG = "ref";
public static final String NAME_TAG = "name";
private final OsmandApplication app;
private final Collator collator;
- private List popularArticles = new ArrayList<>();
+ private PopularArticles popularArticles = new PopularArticles();
private final Map> cachedArticles = new ConcurrentHashMap<>();
private final TravelLocalDataHelper localDataHelper;
private int searchRadius = ARTICLE_SEARCH_RADIUS;
@@ -113,13 +114,13 @@ public class TravelObfHelper implements TravelHelper {
}
@NonNull
- public synchronized List loadPopularArticles() {
+ public synchronized PopularArticles loadPopularArticles() {
String lang = app.getLanguage();
- List popularArticles = new ArrayList<>(this.popularArticles);
- int pagesCount;
+ PopularArticles popularArticles = new PopularArticles(this.popularArticles);
if (isAnyTravelBookPresent()) {
+ boolean articlesLimitReached = false;
do {
- if (foundAmenities.size() - foundAmenitiesIndex < MAX_POPULAR_ARTICLES_COUNT) {
+ if (foundAmenities.size() - foundAmenitiesIndex < ARTICLES_PER_PAGE) {
final LatLon location = app.getMapViewTrackingUtilities().getMapLocation();
for (final BinaryMapIndexReader reader : getReaders()) {
try {
@@ -145,21 +146,25 @@ public class TravelObfHelper implements TravelHelper {
}
searchRadius *= 2;
}
- pagesCount = popularArticles.size() / MAX_POPULAR_ARTICLES_COUNT;
while (foundAmenitiesIndex < foundAmenities.size() - 1) {
- Pair amenity = foundAmenities.get(foundAmenitiesIndex);
- if (!Algorithms.isEmpty(amenity.second.getName(lang))) {
- TravelArticle article = cacheTravelArticles(amenity.first, amenity.second, lang, false, null);
- if (article != null && !popularArticles.contains(article)) {
- popularArticles.add(article);
- if (popularArticles.size() >= (pagesCount + 1) * MAX_POPULAR_ARTICLES_COUNT) {
- break;
+ Pair fileAmenity = foundAmenities.get(foundAmenitiesIndex);
+ File file = fileAmenity.first;
+ Amenity amenity = fileAmenity.second;
+ if (!Algorithms.isEmpty(amenity.getName(lang))) {
+ String routeId = amenity.getAdditionalInfo(Amenity.ROUTE_ID);
+ if (!popularArticles.containsByRouteId(routeId)) {
+ TravelArticle article = cacheTravelArticles(file, amenity, lang, false, null);
+ if (article != null && !popularArticles.contains(article)) {
+ if (!popularArticles.add(article)) {
+ articlesLimitReached = true;
+ break;
+ }
}
}
}
foundAmenitiesIndex++;
}
- } while (popularArticles.size() < (pagesCount + 1) * MAX_POPULAR_ARTICLES_COUNT);
+ } while (!articlesLimitReached && searchRadius < MAX_SEARCH_RADIUS);
}
this.popularArticles = popularArticles;
return popularArticles;
@@ -526,7 +531,7 @@ public class TravelObfHelper implements TravelHelper {
@NonNull
@Override
public List getPopularArticles() {
- return popularArticles;
+ return popularArticles.getArticles();
}
@NonNull
diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java
index 923645b775..d39e228abb 100644
--- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java
+++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java
@@ -156,7 +156,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter position && items.get(position).getCardType() == TravelNeededMapsCard.TYPE;
- }
-
public void addDownloadUpdateCard(TravelDownloadUpdateCard card) {
this.downloadCard = card;
- if (downloadUpdateCardExists(getDownloadUpdateCardPosition())) {
+ int pos = getDownloadUpdateCardPosition();
+ if (isCardExists(pos, TravelDownloadUpdateCard.TYPE)) {
updateDownloadUpdateCard(false);
- } else if (addItem(getDownloadUpdateCardPosition(), card)) {
+ } else if (addItem(pos, card)) {
notifyDataSetChanged();
}
}
public void updateDownloadUpdateCard(boolean onlyProgress) {
- if(onlyProgress) {
+ if (onlyProgress) {
TravelDownloadUpdateCard dc = this.downloadCard;
- if(dc != null) {
+ if (dc != null) {
dc.updateView();
}
return;
}
int pos = getDownloadUpdateCardPosition();
- if (downloadUpdateCardExists(pos)) {
+ if (isCardExists(pos, TravelDownloadUpdateCard.TYPE)) {
notifyItemChanged(pos);
}
}
@@ -223,7 +220,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter position && items.get(position).getCardType() == TravelDownloadUpdateCard.TYPE;
+ private boolean isCardExists(int position, int cardType) {
+ return items.size() > position && items.get(position).getCardType() == cardType;
}
}
diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java
index 7255694422..1d6d86daa2 100644
--- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java
+++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java
@@ -15,6 +15,7 @@ import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
+import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@@ -46,6 +47,8 @@ import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
+import static net.osmand.plus.download.DownloadResources.WIKIVOYAGE_FILE_FILTER;
+import static net.osmand.plus.resources.ResourceManager.DEFAULT_WIKIVOYAGE_TRAVEL_OBF;
import static net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity.*;
public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEvents, TravelLocalDataHelper.Listener {
@@ -186,7 +189,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
}
}
}
- if (app.getTravelHelper().isAnyTravelBookPresent()) {
+ if (!isOnlyDefaultTravelBookPresent()) {
TravelButtonCard travelButtonCard = new TravelButtonCard(app, nightMode);
travelButtonCard.setListener(new TravelNeededMapsCard.CardListener() {
@Override
@@ -248,8 +251,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
}
private void addIndexItemCards(List mainIndexItem, List neededIndexItems) {
- final OsmandApplication app = getMyApplication();
- if (app != null && !app.getTravelHelper().isAnyTravelBookPresent()) {
+ if (isOnlyDefaultTravelBookPresent()) {
this.mainIndexItems.clear();
this.mainIndexItems.addAll(mainIndexItem);
addDownloadUpdateCard();
@@ -259,6 +261,18 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
addNeededMapsCard();
}
+ private boolean isOnlyDefaultTravelBookPresent() {
+ OsmandApplication app = getMyApplication();
+ if (app != null && !app.isApplicationInitializing()) {
+ for (BinaryMapIndexReader reader : app.getResourceManager().getTravelRepositories()) {
+ if (!reader.getFile().getName().equals(DEFAULT_WIKIVOYAGE_TRAVEL_OBF)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
private void addDownloadUpdateCard() {
final OsmandApplication app = getMyApplication();
if (app != null && !mainIndexItems.isEmpty() && SHOW_TRAVEL_UPDATE_CARD) {
@@ -286,7 +300,8 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
@Override
public void onIndexItemClick(IndexItem item) {
- if (item.getType() == DownloadActivityType.WIKIPEDIA_FILE && !Version.isPaidVersion(app)) {
+ if ((item.getType() == DownloadActivityType.WIKIPEDIA_FILE
+ || item.getType() == DownloadActivityType.TRAVEL_FILE) && !Version.isPaidVersion(app)) {
FragmentManager fm = getFragmentManager();
if (fm != null) {
ChoosePlanDialogFragment.showWikipediaInstance(fm);
@@ -341,7 +356,8 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
@Override
public void onIndexItemClick(IndexItem item) {
- if (item.getType() == DownloadActivityType.WIKIPEDIA_FILE && !Version.isPaidVersion(app)) {
+ if ((item.getType() == DownloadActivityType.WIKIPEDIA_FILE
+ || item.getType() == DownloadActivityType.TRAVEL_FILE) && !Version.isPaidVersion(app)) {
FragmentManager fm = getFragmentManager();
if (fm != null) {
ChoosePlanDialogFragment.showWikipediaInstance(fm);
@@ -403,7 +419,9 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
List allWikivoyageItems = app.getDownloadThread().getIndexes().getWikivoyageItems();
if (allWikivoyageItems != null) {
for (IndexItem item : allWikivoyageItems) {
- if (!item.isDownloaded() && !mainItems.contains(item)) {
+ if (!item.isDownloaded()
+ && !mainItems.contains(item)
+ && item.getFileName().contains(WIKIVOYAGE_FILE_FILTER)) {
mainItems.add(item);
}
}
diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelNeededMapsCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelNeededMapsCard.java
index 900c80f1a2..cf1e7ba446 100644
--- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelNeededMapsCard.java
+++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelNeededMapsCard.java
@@ -111,7 +111,7 @@ public class TravelNeededMapsCard extends BaseTravelCard {
boolean downloading = downloadThread.isDownloading(item);
boolean currentDownloading = downloading && downloadThread.getCurrentDownloadingItem() == item;
boolean lastItem = i == items.size() - 1;
- View view = holder.itemsContainer.getChildAt(i);
+ final View view = holder.itemsContainer.getChildAt(i);
if (item.isDownloaded()) {
view.setOnClickListener(null);
@@ -131,12 +131,23 @@ public class TravelNeededMapsCard extends BaseTravelCard {
if (item.isDownloaded()) {
iconAction.setVisibility(View.GONE);
buttonAction.setVisibility(View.GONE);
+
} else {
- boolean showBtn = !paidVersion && item.getType() == DownloadActivityType.WIKIPEDIA_FILE;
+ boolean showBtn = !paidVersion
+ && (item.getType() == DownloadActivityType.WIKIPEDIA_FILE
+ || item.getType() == DownloadActivityType.TRAVEL_FILE);
iconAction.setVisibility(showBtn ? View.GONE : View.VISIBLE);
buttonAction.setVisibility(showBtn ? View.VISIBLE : View.GONE);
- if (!showBtn) {
+ if (showBtn) {
+ buttonAction.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ view.callOnClick();
+ }
+ });
+ } else {
iconAction.setImageDrawable(downloading ? cancelIcon : downloadIcon);
+ buttonAction.setOnClickListener(null);
}
}
@@ -195,7 +206,7 @@ public class TravelNeededMapsCard extends BaseTravelCard {
* @return true if button is visible, false otherwise.
*/
private boolean updatePrimaryButton(NeededMapsVH vh) {
- if (showPrimaryButton()) {
+ if (showPrimaryButton() && Version.isPaidVersion(app)) {
boolean enabled = isInternetAvailable();
vh.primaryBtnContainer.setVisibility(View.VISIBLE);
vh.primaryBtnContainer.setBackgroundResource(getPrimaryBtnBgRes(enabled));