From 3f976cec15db7d669175b340f04971add7de6551 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 16 Feb 2021 16:16:41 +0200 Subject: [PATCH 01/25] Add Travel files to Stats to Storage --- OsmAnd/res/xml/data_storage.xml | 12 +++++++++--- .../settings/datastorage/DataStorageHelper.java | 13 +++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/OsmAnd/res/xml/data_storage.xml b/OsmAnd/res/xml/data_storage.xml index 173907c8b0..b4c1615eb6 100644 --- a/OsmAnd/res/xml/data_storage.xml +++ b/OsmAnd/res/xml/data_storage.xml @@ -6,19 +6,25 @@ android:key="osmand_usage" android:layout="@layout/preference_category_with_right_text" android:title="@string/shared_string_osmand_usage" /> - + + + - + 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; } From fcc8297cc681a97497163a0653b32a790500d683 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 16 Feb 2021 20:39:19 +0200 Subject: [PATCH 02/25] Limit listing all files only to "Wikivoyage" --- .../net/osmand/plus/download/DownloadResources.java | 12 +++++++----- .../plus/wikivoyage/explore/ExploreTabFragment.java | 5 ++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index 56d137a696..53521fc5ab 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -40,22 +40,22 @@ public class DownloadResources extends DownloadResourceGroup { private Map indexFileNames = new LinkedHashMap<>(); private Map indexActivatedFileNames = new LinkedHashMap<>(); private List rawResources; - private Map > groupByRegion; + private Map> groupByRegion; private List itemsToUpdate = new ArrayList<>(); public static final String WORLD_SEAMARKS_KEY = "world_seamarks"; 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(); this.app = app; } - + public List getItemsToUpdate() { return itemsToUpdate; } @@ -365,7 +365,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/wikivoyage/explore/ExploreTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java index 7255694422..b8dab7434a 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java @@ -46,6 +46,7 @@ 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.wikivoyage.explore.WikivoyageExploreActivity.*; public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEvents, TravelLocalDataHelper.Listener { @@ -403,7 +404,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); } } From 9586caee3830097a5b21238210a234e58deb5144 Mon Sep 17 00:00:00 2001 From: Skalii Date: Wed, 17 Feb 2021 04:54:22 +0200 Subject: [PATCH 03/25] fix the same clicking effect for all buttons; fix reopened the main trip recording dialog after closing it from "Stop" dialog or "Clear" dialog; some fixes; --- .../ClearRecordedDataBottomSheetFragment.java | 27 ++- .../StopTrackRecordingBottomFragment.java | 49 +++-- .../TripRecordingActiveBottomSheet.java | 177 ++++++++---------- 3 files changed, 127 insertions(+), 126 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/monitoring/ClearRecordedDataBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/ClearRecordedDataBottomSheetFragment.java index e52462fca7..2327109a15 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/ClearRecordedDataBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/ClearRecordedDataBottomSheetFragment.java @@ -23,6 +23,14 @@ 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(); @@ -30,6 +38,9 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin); int verticalSmall = getResources().getDimensionPixelSize(R.dimen.content_padding_small); + 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)) .setDescriptionColorId(!nightMode ? R.color.text_color_primary_light : R.color.text_color_primary_dark) @@ -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) { @@ -66,6 +77,10 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF items.add(new DividerSpaceItem(app, verticalSmall)); } + private View createItem(LayoutInflater inflater, ItemType type) { + return TripRecordingActiveBottomSheet.createItem(app, nightMode, inflater, type); + } + @Override public void onResume() { super.onResume(); @@ -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..d26074dba6 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(); @@ -43,6 +52,10 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin); int verticalSmall = getResources().getDimensionPixelSize(R.dimen.content_padding_small); + 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)) .setDescriptionColorId(!nightMode ? R.color.text_color_primary_light : R.color.text_color_primary_dark) @@ -54,11 +67,11 @@ 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)) + .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(); @@ -72,11 +85,11 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm 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(); @@ -89,11 +102,11 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm items.add(new DividerSpaceItem(app, verticalSmall)); 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(); } }) @@ -102,6 +115,10 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm items.add(new DividerSpaceItem(app, verticalSmall)); } + private View createItem(LayoutInflater inflater, ItemType type) { + return TripRecordingActiveBottomSheet.createItem(app, nightMode, inflater, type); + } + @Override public void onResume() { super.onResume(); @@ -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..f830bea7d0 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; @@ -133,10 +134,10 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen final View buttonPause = itemView.findViewById(R.id.button_pause); View buttonStop = itemView.findViewById(R.id.button_stop); - createItem(buttonClear, ItemType.CLEAR_DATA, hasDataToSave(), null); - createItem(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(buttonSegment, ItemType.START_SEGMENT, wasTrackMonitored()); + createItem(buttonPause, wasTrackMonitored() ? ItemType.PAUSE : ItemType.RESUME, true); + createItem(buttonStop, ItemType.STOP, true); statusContainer = itemView.findViewById(R.id.status_container); updateStatus(); @@ -200,7 +201,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 +212,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); } }); @@ -265,7 +266,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 +280,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 +299,56 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen } } + 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 +362,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(); @@ -497,31 +482,30 @@ 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), + 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 +518,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 +572,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; } From 35bc92244f449477e3eb1acb71e6bf3aac138f09 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 17 Feb 2021 17:50:25 +0200 Subject: [PATCH 04/25] Make Wikivoyage available only for OsmAnd+ --- OsmAnd/res/layout/travel_needed_map_item.xml | 16 ++++----- .../layout/two_line_with_images_list_item.xml | 10 +++--- .../plus/download/ui/ItemViewHolder.java | 3 +- .../wikivoyage/explore/ExploreRvAdapter.java | 33 +++++++++---------- .../explore/ExploreTabFragment.java | 6 ++-- .../travelcards/TravelNeededMapsCard.java | 21 +++++++++--- 6 files changed, 50 insertions(+), 39 deletions(-) diff --git a/OsmAnd/res/layout/travel_needed_map_item.xml b/OsmAnd/res/layout/travel_needed_map_item.xml index 23099784fe..e103901a02 100644 --- a/OsmAnd/res/layout/travel_needed_map_item.xml +++ b/OsmAnd/res/layout/travel_needed_map_item.xml @@ -78,20 +78,20 @@