From 5e68d14273ff365a4840e556051fd6d3ab573615 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Sun, 24 Jan 2021 19:30:44 +0200 Subject: [PATCH 01/11] Change UI for graph toggle Change UI for graph toggle (Overview | Altitude | Speed). The same toggle is used in Configure Map -> Terrain. --- OsmAnd/res/layout/center_button_container.xml | 19 ++++ OsmAnd/res/layout/custom_radio_buttons.xml | 56 +----------- .../res/layout/gpx_list_item_tab_content.xml | 2 +- OsmAnd/res/layout/left_button_container.xml | 20 +++++ OsmAnd/res/layout/right_button_container.xml | 19 ++++ OsmAnd/src/net/osmand/plus/UiUtilities.java | 87 +++++++++++++++++++ .../plus/myplaces/GPXItemPagerAdapter.java | 74 +++++++++++----- .../views/controls/PagerSlidingTabStrip.java | 14 +-- 8 files changed, 210 insertions(+), 81 deletions(-) create mode 100644 OsmAnd/res/layout/center_button_container.xml create mode 100644 OsmAnd/res/layout/left_button_container.xml create mode 100644 OsmAnd/res/layout/right_button_container.xml diff --git a/OsmAnd/res/layout/center_button_container.xml b/OsmAnd/res/layout/center_button_container.xml new file mode 100644 index 0000000000..8c8fdf1617 --- /dev/null +++ b/OsmAnd/res/layout/center_button_container.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/custom_radio_buttons.xml b/OsmAnd/res/layout/custom_radio_buttons.xml index d768e58004..d4bd1c8082 100644 --- a/OsmAnd/res/layout/custom_radio_buttons.xml +++ b/OsmAnd/res/layout/custom_radio_buttons.xml @@ -1,6 +1,5 @@ - + - + - - - - - - - - - - - - - + \ No newline at end of file diff --git a/OsmAnd/res/layout/gpx_list_item_tab_content.xml b/OsmAnd/res/layout/gpx_list_item_tab_content.xml index d2ce779b8b..fbe7bf5e1c 100644 --- a/OsmAnd/res/layout/gpx_list_item_tab_content.xml +++ b/OsmAnd/res/layout/gpx_list_item_tab_content.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - + + + + + + diff --git a/OsmAnd/res/layout/right_button_container.xml b/OsmAnd/res/layout/right_button_container.xml new file mode 100644 index 0000000000..bb618949af --- /dev/null +++ b/OsmAnd/res/layout/right_button_container.xml @@ -0,0 +1,19 @@ + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 94bd3c4bcb..7c9546d93d 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -90,6 +90,12 @@ public class UiUtilities { END, } + public enum CustomRadioButtonTypeGroup { + START, + CENTER, + END, + } + public UiUtilities(OsmandApplication app) { this.app = app; } @@ -484,6 +490,87 @@ public class UiUtilities { } } + public static void updateCustomRadioButtonsGroup(Context app, View buttonsView, boolean nightMode, + CustomRadioButtonTypeGroup buttonType) { + int activeColor = ContextCompat.getColor(app, nightMode + ? R.color.active_color_primary_dark + : R.color.active_color_primary_light); + int inActiveColor = ContextCompat.getColor(app, nightMode + ? R.color.text_color_secondary_dark + : R.color.text_color_secondary_light); + int textColor = ContextCompat.getColor(app, nightMode + ? R.color.text_color_primary_dark + : R.color.text_color_primary_light); + int roundedCorner = AndroidUtils.dpToPx(app, 4); + boolean isLayoutRtl = AndroidUtils.isLayoutRtl(app); + + TextView startButtonText = buttonsView.findViewById(R.id.left_button); + View startButtonContainer = buttonsView.findViewById(R.id.left_button_container); + TextView centerButtonText = buttonsView.findViewById(R.id.center_button); + View centerButtonContainer = buttonsView.findViewById(R.id.center_button_container); + TextView endButtonText = buttonsView.findViewById(R.id.right_button); + View endButtonContainer = buttonsView.findViewById(R.id.right_button_container); + GradientDrawable background = new GradientDrawable(); + background.setColor(UiUtilities.getColorWithAlpha(activeColor, 0.1f)); + background.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(activeColor, 0.5f)); + GradientDrawable startButtonSharpCorner = new GradientDrawable(); + startButtonSharpCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f)); + GradientDrawable endButtonRoundedCorner = new GradientDrawable(); + endButtonRoundedCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f)); + GradientDrawable centerButtonSharpCorner = new GradientDrawable(); + centerButtonSharpCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f)); + setStartEndCenterRoundedCorner(roundedCorner, isLayoutRtl, startButtonSharpCorner, endButtonRoundedCorner, centerButtonSharpCorner); + + if (buttonType == CustomRadioButtonTypeGroup.START) { + if (isLayoutRtl) { + background.setCornerRadii(new float[]{0, 0, roundedCorner, roundedCorner, roundedCorner, roundedCorner, 0, 0}); + } else { + background.setCornerRadii(new float[]{roundedCorner, roundedCorner, 0, 0, 0, 0, roundedCorner, roundedCorner}); + } + endButtonContainer.setBackground(endButtonRoundedCorner); + endButtonText.setTextColor(activeColor); + centerButtonContainer.setBackground(centerButtonSharpCorner); + centerButtonText.setTextColor(activeColor); + endButtonText.setTextColor(activeColor); + startButtonContainer.setBackgroundDrawable(background); + startButtonText.setTextColor(textColor); + } else if (buttonType == CustomRadioButtonTypeGroup.CENTER){ + endButtonContainer.setBackground(endButtonRoundedCorner); + endButtonText.setTextColor(activeColor); + startButtonContainer.setBackground(startButtonSharpCorner); + startButtonText.setTextColor(activeColor); + endButtonText.setTextColor(activeColor); + centerButtonContainer.setBackgroundDrawable(background); + centerButtonText.setTextColor(textColor); + } else { + if (isLayoutRtl) { + background.setCornerRadii(new float[]{roundedCorner, roundedCorner, 0, 0, 0, 0, roundedCorner, roundedCorner}); + } else { + background.setCornerRadii(new float[]{0, 0, roundedCorner, roundedCorner, roundedCorner, roundedCorner, 0, 0}); + } + endButtonContainer.setBackgroundDrawable(background); + endButtonText.setTextColor(textColor); + startButtonContainer.setBackground(startButtonSharpCorner); + startButtonText.setTextColor(activeColor); + centerButtonContainer.setBackground(centerButtonSharpCorner); + centerButtonText.setTextColor(activeColor); + } + } + + private static void setStartEndCenterRoundedCorner(int roundedCorner, boolean isLayoutRtl, GradientDrawable startButtonRoundedCorner, GradientDrawable endButtonRoundedCorner, GradientDrawable centerButtonSharpCorner) { + if (isLayoutRtl) { + startButtonRoundedCorner.setCornerRadii(new float[]{0, 0, roundedCorner, roundedCorner, roundedCorner, roundedCorner, 0, 0}); + } else { + startButtonRoundedCorner.setCornerRadii(new float[]{roundedCorner, roundedCorner, 0, 0, 0, 0, roundedCorner, roundedCorner}); + } + if (isLayoutRtl) { + endButtonRoundedCorner.setCornerRadii(new float[]{roundedCorner, roundedCorner, 0, 0, 0, 0, roundedCorner, roundedCorner}); + } else { + endButtonRoundedCorner.setCornerRadii(new float[]{0, 0, roundedCorner, roundedCorner, roundedCorner, roundedCorner, 0, 0}); + } + centerButtonSharpCorner.setCornerRadii(new float[]{0, 0, 0, 0, 0, 0, 0, 0}); + } + public static void setupCompoundButtonDrawable(Context ctx, boolean nightMode, @ColorInt int activeColor, Drawable drawable) { int inactiveColor = ContextCompat.getColor(ctx, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light); int[][] states = new int[][]{ diff --git a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java index 81d9ee9d72..8cd70de903 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java @@ -13,6 +13,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.widget.SwitchCompat; import androidx.viewpager.widget.PagerAdapter; +import androidx.viewpager.widget.ViewPager.OnPageChangeListener; import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.data.Entry; @@ -23,6 +24,7 @@ import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture; import com.github.mikephil.charting.listener.OnChartGestureListener; import com.github.mikephil.charting.listener.OnChartValueSelectedListener; +import net.osmand.AndroidUtils; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXTrackAnalysis; @@ -78,7 +80,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid private boolean chartClicked; - public GPXItemPagerAdapter(@NonNull PagerSlidingTabStrip tabs, + public GPXItemPagerAdapter(@NonNull final PagerSlidingTabStrip tabs, @NonNull GpxDisplayItem gpxItem, @NonNull TrackDisplayHelper displayHelper, @NonNull SegmentActionsListener actionsListener) { @@ -89,6 +91,34 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid this.actionsListener = actionsListener; app = (OsmandApplication) tabs.getContext().getApplicationContext(); iconsCache = app.getUIUtilities(); + + tabs.setOnPageChangeListener(new OnPageChangeListener() { + + @Override + public void onPageSelected(int arg0) { + UiUtilities.CustomRadioButtonTypeGroup type; + if (arg0 == 0) { + type = UiUtilities.CustomRadioButtonTypeGroup.START; + } else if (arg0 == 1) { + type = UiUtilities.CustomRadioButtonTypeGroup.CENTER; + } else { + type = UiUtilities.CustomRadioButtonTypeGroup.END; + } + + View parent = (View) tabs.getChildAt(0); + UiUtilities.updateCustomRadioButtonsGroup(app, parent, false, type); + } + + @Override + public void onPageScrolled(int arg0, float arg1, int arg2) { + } + + @Override + public void onPageScrollStateChanged(int arg0) { + + } + }); + fetchTabTypes(); } @@ -588,7 +618,15 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid @Override public View getCustomTabView(@NonNull ViewGroup parent, int position) { - View tab = LayoutInflater.from(parent.getContext()).inflate(R.layout.gpx_tab, parent, false); + int layoutId; + if (position == 0) { + layoutId = R.layout.left_button_container; + } else if (position == 1) { + layoutId = R.layout.center_button_container; + } else { + layoutId = R.layout.right_button_container; + } + View tab = LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false); tab.setTag(tabTypes[position].name()); deselect(tab); return tab; @@ -597,29 +635,25 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid @Override public void select(View tab) { GPXTabItemType tabType = GPXTabItemType.valueOf((String) tab.getTag()); - ImageView img = tab.findViewById(R.id.tab_image); - switch (tabs.getTabSelectionType()) { - case ALPHA: - img.setAlpha(tabs.getTabTextSelectedAlpha()); - break; - case SOLID_COLOR: - img.setImageDrawable(iconsCache.getPaintedIcon(tabType.getIconId(), tabs.getTextColor())); - break; + UiUtilities.CustomRadioButtonTypeGroup type; + if (tabType == GPXTabItemType.GPX_TAB_ITEM_GENERAL) { + type = UiUtilities.CustomRadioButtonTypeGroup.START; + } else if (tabType == GPXTabItemType.GPX_TAB_ITEM_ALTITUDE) { + type = UiUtilities.CustomRadioButtonTypeGroup.CENTER; + } else { + type = UiUtilities.CustomRadioButtonTypeGroup.END; } + View parent = (View) tab.getParent(); + UiUtilities.updateCustomRadioButtonsGroup(app,parent , false, type); + + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) parent.getLayoutParams(); + int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding); + int containerMargin = app.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_margin_small); + AndroidUtils.setMargins(params, contentPadding, containerMargin, contentPadding, containerMargin); } @Override public void deselect(View tab) { - GPXTabItemType tabType = GPXTabItemType.valueOf((String) tab.getTag()); - ImageView img = tab.findViewById(R.id.tab_image); - switch (tabs.getTabSelectionType()) { - case ALPHA: - img.setAlpha(tabs.getTabTextAlpha()); - break; - case SOLID_COLOR: - img.setImageDrawable(iconsCache.getPaintedIcon(tabType.getIconId(), tabs.getTabInactiveTextColor())); - break; - } } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java b/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java index a92d2c5e0a..e38a8619b0 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java @@ -352,13 +352,6 @@ public class PagerSlidingTabStrip extends HorizontalScrollView { tab_title.setTextColor(pager.getCurrentItem() == i ? tabTextColor : tabInactiveTextColor); break; } - if (pager.getAdapter() instanceof CustomTabProvider) { - if (pager.getCurrentItem() == i) { - ((CustomTabProvider) pager.getAdapter()).select(v); - } else { - ((CustomTabProvider) pager.getAdapter()).deselect(v); - } - } // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a // pre-ICS-build @@ -370,6 +363,13 @@ public class PagerSlidingTabStrip extends HorizontalScrollView { } } } + if (pager.getAdapter() instanceof CustomTabProvider) { + if (pager.getCurrentItem() == i) { + ((CustomTabProvider) pager.getAdapter()).select(v); + } else { + ((CustomTabProvider) pager.getAdapter()).deselect(v); + } + } } } From 3c6b065f50e62d4d1f62a3f123db93b70472afc6 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Sun, 24 Jan 2021 23:36:55 +0200 Subject: [PATCH 02/11] null exeption fix --- .../res/layout/gpx_list_item_tab_content.xml | 2 +- OsmAnd/src/net/osmand/plus/UiUtilities.java | 64 +++++++++++++------ .../plus/myplaces/GPXItemPagerAdapter.java | 2 +- .../plus/myplaces/SegmentGPXAdapter.java | 8 +-- 4 files changed, 47 insertions(+), 29 deletions(-) diff --git a/OsmAnd/res/layout/gpx_list_item_tab_content.xml b/OsmAnd/res/layout/gpx_list_item_tab_content.xml index fbe7bf5e1c..d2ce779b8b 100644 --- a/OsmAnd/res/layout/gpx_list_item_tab_content.xml +++ b/OsmAnd/res/layout/gpx_list_item_tab_content.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - + { PagerSlidingTabStrip tabLayout = row.findViewById(R.id.sliding_tabs); tabLayout.setTabBackground(R.color.color_transparent); - tabLayout.setIndicatorColorResource(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light); - tabLayout.setIndicatorBgColorResource(nightMode ? R.color.divider_color_dark : R.color.divider_color_light); - tabLayout.setIndicatorHeight(AndroidUtils.dpToPx(context, 1f)); - if (!nightMode) { - tabLayout.setTextColor(tabLayout.getIndicatorColor()); - tabLayout.setTabInactiveTextColor(ContextCompat.getColor(row.getContext(), R.color.text_color_secondary_light)); - } + tabLayout.setIndicatorHeight(AndroidUtils.dpToPx(context, 0)); tabLayout.setTextSize(AndroidUtils.spToPx(context, 12f)); tabLayout.setShouldExpand(true); WrapContentHeightViewPager pager = row.findViewById(R.id.pager); From 2cdb8953f6af0c3c679cb2f186a03255b3bf830c Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Sun, 24 Jan 2021 23:54:44 +0200 Subject: [PATCH 03/11] Update UiUtilities.java --- OsmAnd/src/net/osmand/plus/UiUtilities.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 3890725d8a..43c6ca94c5 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -560,7 +560,7 @@ public class UiUtilities { endButtonContainer.setBackground(endButtonRoundedCorner); endButtonText.setTextColor(activeColor); } else { - endButtonRoundedCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f)); + endButtonRoundedCorner.setColor(UiUtilities.getColorWithAlpha(activeColor, 0.1f)); centerButtonContainer.setBackgroundDrawable(endButtonRoundedCorner); centerButtonText.setTextColor(textColor); } From fb9afd7119fd74c78a3f03ed9d4d9c6c1d16876c Mon Sep 17 00:00:00 2001 From: cepprice Date: Thu, 28 Jan 2021 17:18:18 +0500 Subject: [PATCH 04/11] Test solution --- .../osmand/plus/activities/MapActivity.java | 4 +- .../plus/importfiles/SettingsImportTask.java | 2 +- .../backend/backup/SettingsHelper.java | 123 ++++++++++++++---- .../fragments/ExportSettingsFragment.java | 2 +- 4 files changed, 103 insertions(+), 28 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index eb6dcbfbb7..7b81a13e0a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -652,7 +652,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven protected void onNewIntent(final Intent intent) { super.onNewIntent(intent); setIntent(intent); - intentHelper.parseLaunchIntents(); + if (!intentHelper.parseLaunchIntents()) { + intentHelper.parseContentIntent(); + } } @Override diff --git a/OsmAnd/src/net/osmand/plus/importfiles/SettingsImportTask.java b/OsmAnd/src/net/osmand/plus/importfiles/SettingsImportTask.java index 0a5e0370af..1f886a23bb 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/SettingsImportTask.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/SettingsImportTask.java @@ -102,7 +102,7 @@ class SettingsImportTask extends BaseLoadAsyncTask { } } else { Map> allSettingsMap = getSettingsToOperate(pluginIndependentItems, false); - List settingsList = settingsHelper.getFilteredSettingsItems(allSettingsMap, settingsTypes, false); + List settingsList = settingsHelper.getFilteredSettingsItems(allSettingsMap, settingsTypes, pluginIndependentItems, false); settingsHelper.checkDuplicates(file, settingsList, settingsList, getDuplicatesListener(file, replace)); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index 7008425f14..1fdfef081b 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -480,19 +480,21 @@ public class SettingsHelper { typesMap.putAll(getMyPlacesItems()); typesMap.putAll(getResourcesItems()); - return getFilteredSettingsItems(typesMap, settingsTypes, export); + return getFilteredSettingsItems(typesMap, settingsTypes, null, export); } - public List getFilteredSettingsItems(Map> allSettingsMap, - List settingsTypes, boolean export) { - List settingsItems = new ArrayList<>(); + public List getFilteredSettingsItems( + Map> allSettingsMap, List settingsTypes, + List settingsItems, boolean export + ) { + List filteredSettingsItems = new ArrayList<>(); for (ExportSettingsType settingsType : settingsTypes) { List settingsDataObjects = allSettingsMap.get(settingsType); if (settingsDataObjects != null) { - settingsItems.addAll(prepareSettingsItems(settingsDataObjects, export)); + filteredSettingsItems.addAll(prepareSettingsItems(settingsDataObjects, settingsItems, export)); } } - return settingsItems; + return filteredSettingsItems; } public Map getSettingsByCategory(boolean addProfiles) { @@ -693,8 +695,8 @@ public class SettingsHelper { return files; } - public List prepareSettingsItems(List data, boolean export) { - List settingsItems = new ArrayList<>(); + public List prepareSettingsItems(List data, List settingsItems, boolean export) { + List result = new ArrayList<>(); List quickActions = new ArrayList<>(); List poiUIFilters = new ArrayList<>(); List tileSourceTemplates = new ArrayList<>(); @@ -719,9 +721,9 @@ public class SettingsHelper { try { File file = (File) object; if (file.getName().endsWith(IndexConstants.GPX_FILE_EXT)) { - settingsItems.add(new GpxSettingsItem(app, file)); + result.add(new GpxSettingsItem(app, file)); } else { - settingsItems.add(new FileSettingsItem(app, file)); + result.add(new FileSettingsItem(app, file)); } } catch (IllegalArgumentException e) { LOG.warn("Trying to export unsuported file type", e); @@ -746,65 +748,136 @@ public class SettingsHelper { } else if (object instanceof HistoryEntry) { historyEntries.add((HistoryEntry) object); } else if (object instanceof GlobalSettingsItem) { - settingsItems.add((GlobalSettingsItem) object); + result.add((GlobalSettingsItem) object); } else if (object instanceof OnlineRoutingEngine) { onlineRoutingEngines.add((OnlineRoutingEngine) object); } } if (!quickActions.isEmpty()) { - settingsItems.add(new QuickActionsSettingsItem(app, quickActions)); + result.add(new QuickActionsSettingsItem(app, getBaseQuickActionsSettingsItem(settingsItems), quickActions)); } if (!poiUIFilters.isEmpty()) { - settingsItems.add(new PoiUiFiltersSettingsItem(app, poiUIFilters)); + result.add(new PoiUiFiltersSettingsItem(app, getBasePoiUiFiltersSettingsItem(settingsItems), poiUIFilters)); } if (!tileSourceTemplates.isEmpty()) { - settingsItems.add(new MapSourcesSettingsItem(app, tileSourceTemplates)); + result.add(new MapSourcesSettingsItem(app, getBaseMapSourcesSettingsItem(settingsItems), tileSourceTemplates)); } if (!avoidRoads.isEmpty()) { - settingsItems.add(new AvoidRoadsSettingsItem(app, avoidRoads)); + result.add(new AvoidRoadsSettingsItem(app, getBaseAvoidRoadsSettingsItem(settingsItems), avoidRoads)); } if (!appModeBeans.isEmpty()) { for (ApplicationModeBean modeBean : appModeBeans) { if (export) { ApplicationMode mode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null); if (mode != null) { - settingsItems.add(new ProfileSettingsItem(app, mode)); + result.add(new ProfileSettingsItem(app, mode)); } } else { - settingsItems.add(new ProfileSettingsItem(app, null, modeBean)); + result.add(new ProfileSettingsItem(app, getBaseProfileSettingsItem(modeBean, settingsItems), modeBean)); } } } if (!osmNotesPointList.isEmpty()) { - settingsItems.add(new OsmNotesSettingsItem(app, osmNotesPointList)); + OsmNotesSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_NOTES, OsmNotesSettingsItem.class, settingsItems); + result.add(new OsmNotesSettingsItem(app, baseItem, osmNotesPointList)); } if (!osmEditsPointList.isEmpty()) { - settingsItems.add(new OsmEditsSettingsItem(app, osmEditsPointList)); + OsmEditsSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_EDITS, OsmEditsSettingsItem.class, settingsItems); + result.add(new OsmEditsSettingsItem(app, baseItem, osmEditsPointList)); } if (!favoriteGroups.isEmpty()) { - settingsItems.add(new FavoritesSettingsItem(app, favoriteGroups)); + FavoritesSettingsItem baseItem = getBaseItem(SettingsItemType.FAVOURITES, FavoritesSettingsItem.class, settingsItems); + result.add(new FavoritesSettingsItem(app, baseItem, favoriteGroups)); } if (!markersGroups.isEmpty()) { List mapMarkers = new ArrayList<>(); for (MapMarkersGroup group : markersGroups) { mapMarkers.addAll(group.getMarkers()); } - settingsItems.add(new MarkersSettingsItem(app, mapMarkers)); + MarkersSettingsItem baseItem = getBaseItem(SettingsItemType.ACTIVE_MARKERS, MarkersSettingsItem.class, settingsItems); + result.add(new MarkersSettingsItem(app, baseItem, mapMarkers)); } if (!markersHistoryGroups.isEmpty()) { List mapMarkers = new ArrayList<>(); for (MapMarkersGroup group : markersHistoryGroups) { mapMarkers.addAll(group.getMarkers()); } - settingsItems.add(new HistoryMarkersSettingsItem(app, mapMarkers)); + HistoryMarkersSettingsItem baseItem = getBaseItem(SettingsItemType.HISTORY_MARKERS, HistoryMarkersSettingsItem.class, settingsItems); + result.add(new HistoryMarkersSettingsItem(app, baseItem, mapMarkers)); } if (!historyEntries.isEmpty()) { - settingsItems.add(new SearchHistorySettingsItem(app, historyEntries)); + SearchHistorySettingsItem baseItem = getBaseItem(SettingsItemType.SEARCH_HISTORY, SearchHistorySettingsItem.class, settingsItems); + result.add(new SearchHistorySettingsItem(app, baseItem, historyEntries)); } if (!onlineRoutingEngines.isEmpty()) { - settingsItems.add(new OnlineRoutingSettingsItem(app, onlineRoutingEngines)); + OnlineRoutingSettingsItem baseItem = getBaseItem(SettingsItemType.ONLINE_ROUTING_ENGINES, OnlineRoutingSettingsItem.class, settingsItems); + result.add(new OnlineRoutingSettingsItem(app, baseItem, onlineRoutingEngines)); } - return settingsItems; + return result; + } + + @Nullable + private ProfileSettingsItem getBaseProfileSettingsItem(ApplicationModeBean modeBean, List settingsItems) { + for (SettingsItem settingsItem : settingsItems) { + if (settingsItem.getType() == SettingsItemType.PROFILE) { + ProfileSettingsItem profileItem = (ProfileSettingsItem) settingsItem; + ApplicationModeBean bean = profileItem.getModeBean(); + if (Algorithms.objectEquals(bean.stringKey, modeBean.stringKey) && Algorithms.objectEquals(bean.userProfileName, modeBean.userProfileName)) { + return profileItem; + } + } + } + return null; + } + + @Nullable + private QuickActionsSettingsItem getBaseQuickActionsSettingsItem(List settingsItems) { + for (SettingsItem settingsItem : settingsItems) { + if (settingsItem.getType() == SettingsItemType.QUICK_ACTIONS) { + return (QuickActionsSettingsItem) settingsItem; + } + } + return null; + } + + @Nullable + private PoiUiFiltersSettingsItem getBasePoiUiFiltersSettingsItem(List settingsItems) { + for (SettingsItem settingsItem : settingsItems) { + if (settingsItem.getType() == SettingsItemType.POI_UI_FILTERS) { + return (PoiUiFiltersSettingsItem) settingsItem; + } + } + return null; + } + + @Nullable + private MapSourcesSettingsItem getBaseMapSourcesSettingsItem(List settingsItems) { + for (SettingsItem settingsItem : settingsItems) { + if (settingsItem.getType() == SettingsItemType.MAP_SOURCES) { + return (MapSourcesSettingsItem) settingsItem; + } + } + return null; + } + + @Nullable + private AvoidRoadsSettingsItem getBaseAvoidRoadsSettingsItem(List settingsItems) { + for (SettingsItem settingsItem : settingsItems) { + if (settingsItem.getType() == SettingsItemType.AVOID_ROADS) { + return (AvoidRoadsSettingsItem) settingsItem; + } + } + return null; + } + + @Nullable + private T getBaseItem(SettingsItemType settingsItemType, Class clazz, List settingsItems) { + for (SettingsItem settingsItem : settingsItems) { + if (settingsItem.getType() == settingsItemType && clazz.isInstance(settingsItem)) { + return clazz.cast(settingsItem); + } + } + return null; } public static Map getSettingsToOperateByCategory(List items, boolean importComplete) { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java index 586b6f0db3..f38a0ba77a 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java @@ -150,7 +150,7 @@ public class ExportSettingsFragment extends BaseSettingsListFragment { showExportProgressDialog(); File tempDir = FileUtils.getTempDir(app); String fileName = getFileName(); - List items = app.getSettingsHelper().prepareSettingsItems(adapter.getData(), true); + List items = app.getSettingsHelper().prepareSettingsItems(adapter.getData(), null, true); progress.setMax(getMaxProgress(items)); app.getSettingsHelper().exportSettings(tempDir, fileName, getSettingsExportListener(), items, true); } From 1f345d0dfd0a714b65fbaa8b9b53e833a3a33560 Mon Sep 17 00:00:00 2001 From: cepprice Date: Thu, 28 Jan 2021 18:19:30 +0500 Subject: [PATCH 05/11] Small edit --- .../osmand/plus/settings/backend/backup/SettingsHelper.java | 4 ++-- .../plus/settings/fragments/ExportSettingsFragment.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index 1fdfef081b..9a50851a56 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -480,12 +480,12 @@ public class SettingsHelper { typesMap.putAll(getMyPlacesItems()); typesMap.putAll(getResourcesItems()); - return getFilteredSettingsItems(typesMap, settingsTypes, null, export); + return getFilteredSettingsItems(typesMap, settingsTypes, Collections.emptyList(), export); } public List getFilteredSettingsItems( Map> allSettingsMap, List settingsTypes, - List settingsItems, boolean export + @NonNull List settingsItems, boolean export ) { List filteredSettingsItems = new ArrayList<>(); for (ExportSettingsType settingsType : settingsTypes) { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java index f38a0ba77a..6fef4d4e03 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java @@ -36,6 +36,7 @@ import org.apache.commons.logging.Log; import java.io.File; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Locale; @@ -150,7 +151,7 @@ public class ExportSettingsFragment extends BaseSettingsListFragment { showExportProgressDialog(); File tempDir = FileUtils.getTempDir(app); String fileName = getFileName(); - List items = app.getSettingsHelper().prepareSettingsItems(adapter.getData(), null, true); + List items = app.getSettingsHelper().prepareSettingsItems(adapter.getData(), Collections.emptyList(), true); progress.setMax(getMaxProgress(items)); app.getSettingsHelper().exportSettings(tempDir, fileName, getSettingsExportListener(), items, true); } From c50e1d0679f49e2ef4ae1828ec65a80c1df4ad64 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Thu, 28 Jan 2021 18:29:10 +0200 Subject: [PATCH 06/11] Night mode fix, separate layout --- OsmAnd/res/layout/custom_radio_buttons.xml | 55 ++++++++++++++- .../res/layout/custom_radio_buttons_group.xml | 68 +++++++++++++++++++ OsmAnd/src/net/osmand/plus/UiUtilities.java | 7 +- .../plus/myplaces/GPXItemPagerAdapter.java | 9 ++- .../plus/myplaces/SegmentGPXAdapter.java | 6 +- .../net/osmand/plus/track/SegmentsCard.java | 2 +- 6 files changed, 136 insertions(+), 11 deletions(-) create mode 100644 OsmAnd/res/layout/custom_radio_buttons_group.xml diff --git a/OsmAnd/res/layout/custom_radio_buttons.xml b/OsmAnd/res/layout/custom_radio_buttons.xml index d4bd1c8082..d5ef10977d 100644 --- a/OsmAnd/res/layout/custom_radio_buttons.xml +++ b/OsmAnd/res/layout/custom_radio_buttons.xml @@ -1,6 +1,7 @@ - + + - + - + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/custom_radio_buttons_group.xml b/OsmAnd/res/layout/custom_radio_buttons_group.xml new file mode 100644 index 0000000000..f0caa4a375 --- /dev/null +++ b/OsmAnd/res/layout/custom_radio_buttons_group.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 43c6ca94c5..8847f953eb 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -490,6 +490,7 @@ public class UiUtilities { } } + public static void updateCustomRadioButtonsGroup(Context app, View buttonsView, boolean nightMode, CustomRadioButtonTypeGroup buttonType) { int activeColor = ContextCompat.getColor(app, nightMode @@ -513,12 +514,14 @@ public class UiUtilities { GradientDrawable background = new GradientDrawable(); background.setColor(UiUtilities.getColorWithAlpha(activeColor, 0.1f)); background.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(activeColor, 0.5f)); + GradientDrawable startButtonRoundedCorner = new GradientDrawable(); startButtonRoundedCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f)); GradientDrawable endButtonRoundedCorner = new GradientDrawable(); endButtonRoundedCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f)); GradientDrawable centerButtonSharpCorner = new GradientDrawable(); centerButtonSharpCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f)); + setStartEndCenterRoundedCorner(roundedCorner, isLayoutRtl, startButtonRoundedCorner, endButtonRoundedCorner, centerButtonSharpCorner); if (buttonType == CustomRadioButtonTypeGroup.START) { @@ -564,6 +567,7 @@ public class UiUtilities { centerButtonContainer.setBackgroundDrawable(endButtonRoundedCorner); centerButtonText.setTextColor(textColor); } + } else { if (isLayoutRtl) { background.setCornerRadii(new float[]{roundedCorner, roundedCorner, 0, 0, 0, 0, roundedCorner, roundedCorner}); @@ -595,6 +599,7 @@ public class UiUtilities { centerButtonSharpCorner.setCornerRadii(new float[]{0, 0, 0, 0, 0, 0, 0, 0}); } + public static void setupCompoundButtonDrawable(Context ctx, boolean nightMode, @ColorInt int activeColor, Drawable drawable) { int inactiveColor = ContextCompat.getColor(ctx, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light); int[][] states = new int[][]{ @@ -747,7 +752,7 @@ public class UiUtilities { int activeDisableColor = getColorWithAlpha(activeColor, 0.25f); ColorStateList activeCsl = new ColorStateList(states, new int[] {activeColor, activeDisableColor}); int inactiveColor = ContextCompat.getColor(ctx, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_secondary_light); - ColorStateList inactiveCsl = new ColorStateList(states, new int[] {inactiveColor, inactiveColor}); + ColorStateList inactiveCsl = new ColorStateList(states, new int[] {activeDisableColor, inactiveColor}); slider.setTrackActiveTintList(activeCsl); slider.setTrackInactiveTintList(inactiveCsl); slider.setHaloTintList(activeCsl); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java index a9e36ff421..f3238c90b5 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java @@ -78,16 +78,19 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid private SegmentActionsListener actionsListener; private boolean chartClicked; + private boolean nightMode; public GPXItemPagerAdapter(@NonNull final PagerSlidingTabStrip tabs, @NonNull GpxDisplayItem gpxItem, @NonNull TrackDisplayHelper displayHelper, - @NonNull SegmentActionsListener actionsListener) { + @NonNull SegmentActionsListener actionsListener, + final boolean nightMode) { super(); this.tabs = tabs; this.gpxItem = gpxItem; this.displayHelper = displayHelper; + this.nightMode = nightMode; this.actionsListener = actionsListener; app = (OsmandApplication) tabs.getContext().getApplicationContext(); iconsCache = app.getUIUtilities(); @@ -106,7 +109,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid } View parent = (View) tabs.getChildAt(0); - UiUtilities.updateCustomRadioButtonsGroup(app, parent, false, type); + UiUtilities.updateCustomRadioButtonsGroup(app, parent, nightMode, type); } @Override @@ -644,7 +647,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid type = UiUtilities.CustomRadioButtonTypeGroup.END; } View parent = (View) tab.getParent(); - UiUtilities.updateCustomRadioButtonsGroup(app, parent, false, type); + UiUtilities.updateCustomRadioButtonsGroup(app, parent, nightMode, type); ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) parent.getLayoutParams(); int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SegmentGPXAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/SegmentGPXAdapter.java index f2d5c88617..9f2e234dcd 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/SegmentGPXAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/SegmentGPXAdapter.java @@ -1,6 +1,7 @@ package net.osmand.plus.myplaces; import android.content.Context; +import android.graphics.drawable.GradientDrawable; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; @@ -21,7 +22,6 @@ import java.util.List; public class SegmentGPXAdapter extends ArrayAdapter { - private OsmandApplication app; private TrackDisplayHelper displayHelper; private SegmentActionsListener listener; private boolean nightMode; @@ -31,7 +31,7 @@ public class SegmentGPXAdapter extends ArrayAdapter { @NonNull SegmentActionsListener listener, boolean nightMode) { super(context, R.layout.gpx_list_item_tab_content, items); - this.app = (OsmandApplication) context.getApplicationContext(); + OsmandApplication app = (OsmandApplication) context.getApplicationContext(); this.displayHelper = displayHelper; this.listener = listener; this.nightMode = nightMode; @@ -56,7 +56,7 @@ public class SegmentGPXAdapter extends ArrayAdapter { WrapContentHeightViewPager pager = row.findViewById(R.id.pager); PagerSlidingTabStrip tabLayout = row.findViewById(R.id.sliding_tabs); - pager.setAdapter(new GPXItemPagerAdapter(tabLayout, item, displayHelper, listener)); + pager.setAdapter(new GPXItemPagerAdapter(tabLayout, item, displayHelper, listener, nightMode)); if (create) { tabLayout.setViewPager(pager); } else { diff --git a/OsmAnd/src/net/osmand/plus/track/SegmentsCard.java b/OsmAnd/src/net/osmand/plus/track/SegmentsCard.java index b3921a6889..421b8a9a8e 100644 --- a/OsmAnd/src/net/osmand/plus/track/SegmentsCard.java +++ b/OsmAnd/src/net/osmand/plus/track/SegmentsCard.java @@ -48,7 +48,7 @@ public class SegmentsCard extends BaseCard { WrapContentHeightViewPager pager = segmentView.findViewById(R.id.pager); PagerSlidingTabStrip tabLayout = segmentView.findViewById(R.id.sliding_tabs); - pager.setAdapter(new GPXItemPagerAdapter(tabLayout, displayItem, displayHelper, listener)); + pager.setAdapter(new GPXItemPagerAdapter(tabLayout, displayItem, displayHelper, listener, nightMode)); tabLayout.setViewPager(pager); container.addView(segmentView); From 1c904641e00118114c8b17359c2640c741a4bd4e Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Thu, 28 Jan 2021 18:59:37 +0200 Subject: [PATCH 07/11] Check upload success --- .../UploadPhotoProgressBottomSheet.java | 1 - .../mapcontextmenu/UploadPhotosAsyncTask.java | 23 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java index f1c37a55ee..46483ffc9b 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java @@ -87,7 +87,6 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen @Override public void uploadPhotosFinished() { - updateProgress(maxProgress); if (progress == maxProgress) { uploadedPhotosCounter.setText((getString(R.string.uploaded_count, progress, maxProgress))); setDismissButtonTextId(R.string.shared_string_close); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java index 30932e8b42..b47cc51f68 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java @@ -34,6 +34,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.lang.ref.WeakReference; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -45,14 +46,13 @@ public class UploadPhotosAsyncTask extends AsyncTask { private final OsmandApplication app; private final WeakReference activityRef; - private UploadPhotosListener listener; - private final OpenDBAPI openDBAPI = new OpenDBAPI(); private final LatLon latLon; private final List data; private final String[] placeId; private final Map params; private final GetImageCardsListener imageCardListener; + private UploadPhotosListener listener; public UploadPhotosAsyncTask(MapActivity activity, List data, LatLon latLon, String[] placeId, Map params, GetImageCardsListener imageCardListener) { @@ -87,13 +87,16 @@ public class UploadPhotosAsyncTask extends AsyncTask { } protected Void doInBackground(Void... uris) { + List uploadedPhotoUris = new ArrayList<>(); for (int i = 0; i < data.size(); i++) { if (isCancelled()) { break; } Uri uri = data.get(i); - handleSelectedImage(uri); - publishProgress(i + 1); + if (handleSelectedImage(uri)) { + uploadedPhotoUris.add(uri); + publishProgress(uploadedPhotoUris.size()); + } } return null; } @@ -105,12 +108,13 @@ public class UploadPhotosAsyncTask extends AsyncTask { } } - private void handleSelectedImage(final Uri uri) { + private boolean handleSelectedImage(final Uri uri) { + boolean success = false; InputStream inputStream = null; try { inputStream = app.getContentResolver().openInputStream(uri); if (inputStream != null) { - uploadImageToPlace(inputStream); + success = uploadImageToPlace(inputStream); } } catch (Exception e) { LOG.error(e); @@ -118,9 +122,11 @@ public class UploadPhotosAsyncTask extends AsyncTask { } finally { Algorithms.closeStream(inputStream); } + return success; } - private void uploadImageToPlace(InputStream image) { + private boolean uploadImageToPlace(InputStream image) { + boolean success = false; InputStream serverData = new ByteArrayInputStream(compressImageToJpeg(image)); final String baseUrl = OPRConstants.getBaseUrl(app); // all these should be constant @@ -146,6 +152,7 @@ public class UploadPhotosAsyncTask extends AsyncTask { } catch (FailedVerificationException e) { LOG.error(e); checkTokenAndShowScreen(); + } if (res != 200) { //image was uploaded but not added to blockchain @@ -159,10 +166,12 @@ public class UploadPhotosAsyncTask extends AsyncTask { if (activity != null) { MenuBuilder.execute(new GetImageCardsTask(activity, latLon, params, imageCardListener)); } + success = true; } } else { checkTokenAndShowScreen(); } + return success; } //This method runs on non main thread From 46559fc3280a4bbb4dd25a4c0e1a4841afdbf5db Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 1 Feb 2021 01:19:40 +0200 Subject: [PATCH 08/11] Small fix --- .../net/osmand/aidlapi/customization/ProfileSettingsParams.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java b/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java index eee80329f7..a22d4e3c91 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java @@ -16,7 +16,7 @@ public class ProfileSettingsParams extends AidlParams { public static final String VERSION_KEY = "version"; public static final String REPLACE_KEY = "replace"; - public static final String SILENT_IMPORT_KEY = "silent_import"; + public static final String SILENT_IMPORT_KEY = "silentImport"; public static final String LATEST_CHANGES_KEY = "latestChanges"; public static final String PROFILE_SETTINGS_URI_KEY = "profileSettingsUri"; private Uri profileSettingsUri; From 8f8ddbf9b457362e28d8b873ed208c00b871c116 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 1 Feb 2021 01:59:58 +0200 Subject: [PATCH 09/11] Try to remove duplicate code --- .../backend/backup/SettingsHelper.java | 54 +---- .../fragments/ImportSettingsFragment.java | 210 +----------------- 2 files changed, 11 insertions(+), 253 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index 9a50851a56..11fe377040 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -728,6 +728,8 @@ public class SettingsHelper { } catch (IllegalArgumentException e) { LOG.warn("Trying to export unsuported file type", e); } + } else if (object instanceof FileSettingsItem) { + result.add((FileSettingsItem) object); } else if (object instanceof AvoidRoadInfo) { avoidRoads.add((AvoidRoadInfo) object); } else if (object instanceof ApplicationModeBean) { @@ -754,16 +756,20 @@ public class SettingsHelper { } } if (!quickActions.isEmpty()) { - result.add(new QuickActionsSettingsItem(app, getBaseQuickActionsSettingsItem(settingsItems), quickActions)); + QuickActionsSettingsItem baseItem = getBaseItem(SettingsItemType.QUICK_ACTIONS, QuickActionsSettingsItem.class, settingsItems); + result.add(new QuickActionsSettingsItem(app, baseItem, quickActions)); } if (!poiUIFilters.isEmpty()) { - result.add(new PoiUiFiltersSettingsItem(app, getBasePoiUiFiltersSettingsItem(settingsItems), poiUIFilters)); + PoiUiFiltersSettingsItem baseItem = getBaseItem(SettingsItemType.POI_UI_FILTERS, PoiUiFiltersSettingsItem.class, settingsItems); + result.add(new PoiUiFiltersSettingsItem(app, baseItem, poiUIFilters)); } if (!tileSourceTemplates.isEmpty()) { - result.add(new MapSourcesSettingsItem(app, getBaseMapSourcesSettingsItem(settingsItems), tileSourceTemplates)); + MapSourcesSettingsItem baseItem = getBaseItem(SettingsItemType.MAP_SOURCES, MapSourcesSettingsItem.class, settingsItems); + result.add(new MapSourcesSettingsItem(app, baseItem, tileSourceTemplates)); } if (!avoidRoads.isEmpty()) { - result.add(new AvoidRoadsSettingsItem(app, getBaseAvoidRoadsSettingsItem(settingsItems), avoidRoads)); + AvoidRoadsSettingsItem baseItem = getBaseItem(SettingsItemType.AVOID_ROADS, AvoidRoadsSettingsItem.class, settingsItems); + result.add(new AvoidRoadsSettingsItem(app, baseItem, avoidRoads)); } if (!appModeBeans.isEmpty()) { for (ApplicationModeBean modeBean : appModeBeans) { @@ -830,46 +836,6 @@ public class SettingsHelper { return null; } - @Nullable - private QuickActionsSettingsItem getBaseQuickActionsSettingsItem(List settingsItems) { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.QUICK_ACTIONS) { - return (QuickActionsSettingsItem) settingsItem; - } - } - return null; - } - - @Nullable - private PoiUiFiltersSettingsItem getBasePoiUiFiltersSettingsItem(List settingsItems) { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.POI_UI_FILTERS) { - return (PoiUiFiltersSettingsItem) settingsItem; - } - } - return null; - } - - @Nullable - private MapSourcesSettingsItem getBaseMapSourcesSettingsItem(List settingsItems) { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.MAP_SOURCES) { - return (MapSourcesSettingsItem) settingsItem; - } - } - return null; - } - - @Nullable - private AvoidRoadsSettingsItem getBaseAvoidRoadsSettingsItem(List settingsItems) { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.AVOID_ROADS) { - return (AvoidRoadsSettingsItem) settingsItem; - } - } - return null; - } - @Nullable private T getBaseItem(SettingsItemType settingsItemType, Class clazz, List settingsItems) { for (SettingsItem settingsItem : settingsItems) { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java index 83a271b059..b614bc57dd 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java @@ -18,57 +18,24 @@ import androidx.fragment.app.FragmentManager; import com.google.android.material.appbar.CollapsingToolbarLayout; -import net.osmand.IndexConstants; import net.osmand.PlatformUtil; -import net.osmand.map.ITileSource; -import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.plus.AppInitializer; -import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; -import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.download.ReloadIndexesTask; import net.osmand.plus.download.ReloadIndexesTask.ReloadIndexesListener; -import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; -import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; -import net.osmand.plus.mapmarkers.MapMarker; -import net.osmand.plus.mapmarkers.MapMarkersGroup; -import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine; -import net.osmand.plus.osmedit.OpenstreetmapPoint; -import net.osmand.plus.osmedit.OsmNotesPoint; -import net.osmand.plus.poi.PoiUIFilter; -import net.osmand.plus.quickaction.QuickAction; -import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean; -import net.osmand.plus.settings.backend.ExportSettingsType; -import net.osmand.plus.settings.backend.backup.AvoidRoadsSettingsItem; -import net.osmand.plus.settings.backend.backup.FavoritesSettingsItem; import net.osmand.plus.settings.backend.backup.FileSettingsItem; -import net.osmand.plus.settings.backend.backup.GlobalSettingsItem; -import net.osmand.plus.settings.backend.backup.GpxSettingsItem; -import net.osmand.plus.settings.backend.backup.HistoryMarkersSettingsItem; -import net.osmand.plus.settings.backend.backup.MapSourcesSettingsItem; -import net.osmand.plus.settings.backend.backup.MarkersSettingsItem; -import net.osmand.plus.settings.backend.backup.OnlineRoutingSettingsItem; -import net.osmand.plus.settings.backend.backup.OsmEditsSettingsItem; -import net.osmand.plus.settings.backend.backup.OsmNotesSettingsItem; -import net.osmand.plus.settings.backend.backup.PoiUiFiltersSettingsItem; -import net.osmand.plus.settings.backend.backup.ProfileSettingsItem; -import net.osmand.plus.settings.backend.backup.QuickActionsSettingsItem; -import net.osmand.plus.settings.backend.backup.SearchHistorySettingsItem; import net.osmand.plus.settings.backend.backup.SettingsHelper; import net.osmand.plus.settings.backend.backup.SettingsHelper.ImportAsyncTask; import net.osmand.plus.settings.backend.backup.SettingsItem; -import net.osmand.plus.settings.backend.backup.SettingsItemType; -import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; import java.io.File; import java.lang.ref.WeakReference; -import java.util.ArrayList; import java.util.List; public class ImportSettingsFragment extends BaseSettingsListFragment { @@ -177,7 +144,7 @@ public class ImportSettingsFragment extends BaseSettingsListFragment { } private void importItems() { - List selectedItems = getSettingsItemsFromData(adapter.getData()); + List selectedItems = settingsHelper.prepareSettingsItems(adapter.getData(), settingsItems, false); if (file != null && settingsItems != null) { duplicateStartTime = System.currentTimeMillis(); settingsHelper.checkDuplicates(file, settingsItems, selectedItems, getDuplicatesListener()); @@ -272,181 +239,6 @@ public class ImportSettingsFragment extends BaseSettingsListFragment { this.settingsItems = settingsItems; } - @Nullable - private ProfileSettingsItem getBaseProfileSettingsItem(ApplicationModeBean modeBean) { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.PROFILE) { - ProfileSettingsItem profileItem = (ProfileSettingsItem) settingsItem; - ApplicationModeBean bean = profileItem.getModeBean(); - if (Algorithms.objectEquals(bean.stringKey, modeBean.stringKey) && Algorithms.objectEquals(bean.userProfileName, modeBean.userProfileName)) { - return profileItem; - } - } - } - return null; - } - - @Nullable - private QuickActionsSettingsItem getBaseQuickActionsSettingsItem() { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.QUICK_ACTIONS) { - return (QuickActionsSettingsItem) settingsItem; - } - } - return null; - } - - @Nullable - private PoiUiFiltersSettingsItem getBasePoiUiFiltersSettingsItem() { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.POI_UI_FILTERS) { - return (PoiUiFiltersSettingsItem) settingsItem; - } - } - return null; - } - - @Nullable - private MapSourcesSettingsItem getBaseMapSourcesSettingsItem() { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.MAP_SOURCES) { - return (MapSourcesSettingsItem) settingsItem; - } - } - return null; - } - - @Nullable - private AvoidRoadsSettingsItem getBaseAvoidRoadsSettingsItem() { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == SettingsItemType.AVOID_ROADS) { - return (AvoidRoadsSettingsItem) settingsItem; - } - } - return null; - } - - @Nullable - private T getBaseItem(SettingsItemType settingsItemType, Class clazz) { - for (SettingsItem settingsItem : settingsItems) { - if (settingsItem.getType() == settingsItemType && clazz.isInstance(settingsItem)) { - return clazz.cast(settingsItem); - } - } - return null; - } - - private List getSettingsItemsFromData(List data) { - List settingsItems = new ArrayList<>(); - List appModeBeans = new ArrayList<>(); - List quickActions = new ArrayList<>(); - List poiUIFilters = new ArrayList<>(); - List tileSourceTemplates = new ArrayList<>(); - List avoidRoads = new ArrayList<>(); - List osmNotesPointList = new ArrayList<>(); - List osmEditsPointList = new ArrayList<>(); - List favoriteGroups = new ArrayList<>(); - List markersGroups = new ArrayList<>(); - List markersHistoryGroups = new ArrayList<>(); - List historyEntries = new ArrayList<>(); - List onlineRoutingEngines = new ArrayList<>(); - for (Object object : data) { - if (object instanceof ApplicationModeBean) { - appModeBeans.add((ApplicationModeBean) object); - } else if (object instanceof QuickAction) { - quickActions.add((QuickAction) object); - } else if (object instanceof PoiUIFilter) { - poiUIFilters.add((PoiUIFilter) object); - } else if (object instanceof TileSourceTemplate || object instanceof SQLiteTileSource) { - tileSourceTemplates.add((ITileSource) object); - } else if (object instanceof File) { - File file = (File) object; - if (file.getName().endsWith(IndexConstants.GPX_FILE_EXT)) { - settingsItems.add(new GpxSettingsItem(app, file)); - } else { - settingsItems.add(new FileSettingsItem(app, file)); - } - } else if (object instanceof FileSettingsItem) { - settingsItems.add((FileSettingsItem) object); - } else if (object instanceof AvoidRoadInfo) { - avoidRoads.add((AvoidRoadInfo) object); - } else if (object instanceof OsmNotesPoint) { - osmNotesPointList.add((OsmNotesPoint) object); - } else if (object instanceof OpenstreetmapPoint) { - osmEditsPointList.add((OpenstreetmapPoint) object); - } else if (object instanceof FavoriteGroup) { - favoriteGroups.add((FavoriteGroup) object); - } else if (object instanceof GlobalSettingsItem) { - settingsItems.add((GlobalSettingsItem) object); - } else if (object instanceof MapMarkersGroup) { - MapMarkersGroup markersGroup = (MapMarkersGroup) object; - if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) { - markersGroups.add((MapMarkersGroup) object); - } else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) { - markersHistoryGroups.add((MapMarkersGroup) object); - } - } else if (object instanceof HistoryEntry) { - historyEntries.add((HistoryEntry) object); - } else if (object instanceof OnlineRoutingEngine) { - onlineRoutingEngines.add((OnlineRoutingEngine) object); - } - } - if (!appModeBeans.isEmpty()) { - for (ApplicationModeBean modeBean : appModeBeans) { - settingsItems.add(new ProfileSettingsItem(app, getBaseProfileSettingsItem(modeBean), modeBean)); - } - } - if (!quickActions.isEmpty()) { - settingsItems.add(new QuickActionsSettingsItem(app, getBaseQuickActionsSettingsItem(), quickActions)); - } - if (!poiUIFilters.isEmpty()) { - settingsItems.add(new PoiUiFiltersSettingsItem(app, getBasePoiUiFiltersSettingsItem(), poiUIFilters)); - } - if (!tileSourceTemplates.isEmpty()) { - settingsItems.add(new MapSourcesSettingsItem(app, getBaseMapSourcesSettingsItem(), tileSourceTemplates)); - } - if (!avoidRoads.isEmpty()) { - settingsItems.add(new AvoidRoadsSettingsItem(app, getBaseAvoidRoadsSettingsItem(), avoidRoads)); - } - if (!osmNotesPointList.isEmpty()) { - OsmNotesSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_NOTES, OsmNotesSettingsItem.class); - settingsItems.add(new OsmNotesSettingsItem(app, baseItem, osmNotesPointList)); - } - if (!osmEditsPointList.isEmpty()) { - OsmEditsSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_EDITS, OsmEditsSettingsItem.class); - settingsItems.add(new OsmEditsSettingsItem(app, baseItem, osmEditsPointList)); - } - if (!favoriteGroups.isEmpty()) { - FavoritesSettingsItem baseItem = getBaseItem(SettingsItemType.FAVOURITES, FavoritesSettingsItem.class); - settingsItems.add(new FavoritesSettingsItem(app, baseItem, favoriteGroups)); - } - if (!markersGroups.isEmpty()) { - List mapMarkers = new ArrayList<>(); - for (MapMarkersGroup group : markersGroups) { - mapMarkers.addAll(group.getMarkers()); - } - MarkersSettingsItem baseItem = getBaseItem(SettingsItemType.ACTIVE_MARKERS, MarkersSettingsItem.class); - settingsItems.add(new MarkersSettingsItem(app, baseItem, mapMarkers)); - } - if (!markersHistoryGroups.isEmpty()) { - List mapMarkers = new ArrayList<>(); - for (MapMarkersGroup group : markersHistoryGroups) { - mapMarkers.addAll(group.getMarkers()); - } - HistoryMarkersSettingsItem baseItem = getBaseItem(SettingsItemType.HISTORY_MARKERS, HistoryMarkersSettingsItem.class); - settingsItems.add(new HistoryMarkersSettingsItem(app, baseItem, mapMarkers)); - } - if (!historyEntries.isEmpty()) { - SearchHistorySettingsItem baseItem = getBaseItem(SettingsItemType.SEARCH_HISTORY, SearchHistorySettingsItem.class); - settingsItems.add(new SearchHistorySettingsItem(app, baseItem, historyEntries)); - } - if (!onlineRoutingEngines.isEmpty()) { - OnlineRoutingSettingsItem baseItem = getBaseItem(SettingsItemType.ONLINE_ROUTING_ENGINES, OnlineRoutingSettingsItem.class); - settingsItems.add(new OnlineRoutingSettingsItem(app, baseItem, onlineRoutingEngines)); - } - return settingsItems; - } - public void setFile(File file) { this.file = file; } From a70ad01304e2440fd1c8bfca426927afbd528e0e Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 1 Feb 2021 04:05:51 +0200 Subject: [PATCH 10/11] Minor fixes --- .../UploadPhotoProgressBottomSheet.java | 32 +++++++++---------- .../mapcontextmenu/UploadPhotosAsyncTask.java | 7 ++-- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java index 46483ffc9b..05e4bcc468 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/UploadPhotoProgressBottomSheet.java @@ -33,6 +33,7 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen private int progress; private int maxProgress; + private boolean uploadingFinished; @Override public void createMenuItems(Bundle savedInstanceState) { @@ -44,17 +45,12 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen uploadedPhotosCounter = view.findViewById(R.id.description); progressBar = view.findViewById(R.id.progress_bar); progressBar.setMax(maxProgress); - String titleProgress = getString(progress == maxProgress? R.string.upload_photo_completed: R.string.upload_photo); - String descriptionProgress; - if (progress == maxProgress) { - descriptionProgress = getString(R.string.uploaded_count, progress, maxProgress); - } else { - descriptionProgress = getString(R.string.uploading_count, progress, maxProgress); - } + + int descriptionId = uploadingFinished ? R.string.uploaded_count : R.string.uploading_count; BaseBottomSheetItem descriptionItem = new BottomSheetItemWithDescription.Builder() - .setDescription(descriptionProgress) - .setTitle(titleProgress) + .setDescription(getString(descriptionId, progress, maxProgress)) + .setTitle(getString(uploadingFinished ? R.string.upload_photo_completed : R.string.upload_photo)) .setCustomView(view) .create(); items.add(descriptionItem); @@ -74,9 +70,10 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen } private void updateProgress(int progress) { + int descriptionId = uploadingFinished ? R.string.uploaded_count : R.string.uploading_count; progressBar.setProgress(progress); - uploadedPhotosCounter.setText((getString(R.string.uploading_count, progress, maxProgress))); - uploadedPhotosTitle.setText(progress == maxProgress ? R.string.upload_photo_completed : R.string.upload_photo); + uploadedPhotosCounter.setText(getString(descriptionId, progress, maxProgress)); + uploadedPhotosTitle.setText(uploadingFinished ? R.string.upload_photo_completed : R.string.upload_photo); } @Override @@ -87,11 +84,9 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen @Override public void uploadPhotosFinished() { - if (progress == maxProgress) { - uploadedPhotosCounter.setText((getString(R.string.uploaded_count, progress, maxProgress))); - setDismissButtonTextId(R.string.shared_string_close); - UiUtilities.setupDialogButton(nightMode, dismissButton, getDismissButtonType(), getDismissButtonTextId()); - } + uploadingFinished = true; + updateProgress(progress); + UiUtilities.setupDialogButton(nightMode, dismissButton, getDismissButtonType(), getDismissButtonTextId()); } @Override @@ -103,6 +98,11 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen } } + @Override + protected int getDismissButtonTextId() { + return uploadingFinished ? R.string.shared_string_close : R.string.shared_string_cancel; + } + public static UploadPhotosListener showInstance(@NonNull FragmentManager fragmentManager, int maxProgress, OnDismissListener listener) { UploadPhotoProgressBottomSheet fragment = new UploadPhotoProgressBottomSheet(); fragment.setRetainInstance(true); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java index 24d70a83dc..afe492af6f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/UploadPhotosAsyncTask.java @@ -128,7 +128,7 @@ public class UploadPhotosAsyncTask extends AsyncTask { private boolean uploadImageToPlace(InputStream image) { boolean success = false; InputStream serverData = new ByteArrayInputStream(compressImageToJpeg(image)); - final String baseUrl = OPRConstants.getBaseUrl(app); + String baseUrl = OPRConstants.getBaseUrl(app); // all these should be constant String url = baseUrl + "api/ipfs/image"; String response = NetworkUtils.sendPostDataRequest(url, "file", "compressed.jpeg", serverData); @@ -146,18 +146,16 @@ public class UploadPhotosAsyncTask extends AsyncTask { response, error); if (res != 200) { app.showToastMessage(error.toString()); - } else { - //ok, continue } } catch (FailedVerificationException e) { LOG.error(e); checkTokenAndShowScreen(); - } if (res != 200) { //image was uploaded but not added to blockchain checkTokenAndShowScreen(); } else { + success = true; String str = app.getString(R.string.successfully_uploaded_pattern, 1, 1); app.showToastMessage(str); //refresh the image @@ -166,7 +164,6 @@ public class UploadPhotosAsyncTask extends AsyncTask { if (activity != null) { MenuBuilder.execute(new GetImageCardsTask(activity, latLon, params, imageCardListener)); } - success = true; } } else { checkTokenAndShowScreen(); From de773909a0ce3fceb6610eae9821189877d1f1bc Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 1 Feb 2021 11:34:28 +0200 Subject: [PATCH 11/11] Small fixes --- OsmAnd/res/layout/center_button_container.xml | 28 ++-- OsmAnd/res/layout/custom_radio_buttons.xml | 55 ++----- .../res/layout/custom_radio_buttons_group.xml | 68 --------- .../res/layout/gpx_list_item_tab_content.xml | 40 +++--- OsmAnd/res/layout/left_button_container.xml | 7 +- OsmAnd/res/layout/right_button_container.xml | 6 +- OsmAnd/src/net/osmand/plus/UiUtilities.java | 134 +++--------------- .../plus/myplaces/GPXItemPagerAdapter.java | 101 ++++++------- .../plus/myplaces/SegmentGPXAdapter.java | 12 +- .../net/osmand/plus/track/SegmentsCard.java | 2 +- .../views/controls/PagerSlidingTabStrip.java | 115 ++++++++------- 11 files changed, 180 insertions(+), 388 deletions(-) delete mode 100644 OsmAnd/res/layout/custom_radio_buttons_group.xml diff --git a/OsmAnd/res/layout/center_button_container.xml b/OsmAnd/res/layout/center_button_container.xml index 8c8fdf1617..531b6b97e8 100644 --- a/OsmAnd/res/layout/center_button_container.xml +++ b/OsmAnd/res/layout/center_button_container.xml @@ -1,19 +1,19 @@ + xmlns:osmand="http://schemas.android.com/apk/res-auto" + android:id="@+id/center_button_container" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1"> - + \ No newline at end of file diff --git a/OsmAnd/res/layout/custom_radio_buttons.xml b/OsmAnd/res/layout/custom_radio_buttons.xml index d5ef10977d..2ea2775d62 100644 --- a/OsmAnd/res/layout/custom_radio_buttons.xml +++ b/OsmAnd/res/layout/custom_radio_buttons.xml @@ -1,7 +1,6 @@ - - + android:layout_weight="1" /> - - - + android:layout_weight="1" /> - - - - - - - - - + android:layout_weight="1" /> \ No newline at end of file diff --git a/OsmAnd/res/layout/custom_radio_buttons_group.xml b/OsmAnd/res/layout/custom_radio_buttons_group.xml deleted file mode 100644 index f0caa4a375..0000000000 --- a/OsmAnd/res/layout/custom_radio_buttons_group.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OsmAnd/res/layout/gpx_list_item_tab_content.xml b/OsmAnd/res/layout/gpx_list_item_tab_content.xml index d2ce779b8b..ac7918d06a 100644 --- a/OsmAnd/res/layout/gpx_list_item_tab_content.xml +++ b/OsmAnd/res/layout/gpx_list_item_tab_content.xml @@ -1,24 +1,32 @@ + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + + - + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/left_button_container.xml b/OsmAnd/res/layout/left_button_container.xml index c6a32ec74a..e56ec7b06a 100644 --- a/OsmAnd/res/layout/left_button_container.xml +++ b/OsmAnd/res/layout/left_button_container.xml @@ -1,7 +1,6 @@ + osmand:typeface="@string/font_roboto_medium" /> - + \ No newline at end of file diff --git a/OsmAnd/res/layout/right_button_container.xml b/OsmAnd/res/layout/right_button_container.xml index bb618949af..02b237d6c0 100644 --- a/OsmAnd/res/layout/right_button_container.xml +++ b/OsmAnd/res/layout/right_button_container.xml @@ -12,8 +12,8 @@ android:layout_height="match_parent" android:background="?attr/selectableItemBackground" android:gravity="center" + android:text="@string/map_widget_speed" android:textSize="@dimen/default_desc_text_size" - osmand:typeface="@string/font_roboto_medium" - android:text="@string/map_widget_speed"/> + osmand:typeface="@string/font_roboto_medium" /> - + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 8847f953eb..47f3842711 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -86,11 +86,6 @@ public class UiUtilities { } public enum CustomRadioButtonType { - START, - END, - } - - public enum CustomRadioButtonTypeGroup { START, CENTER, END, @@ -462,6 +457,8 @@ public class UiUtilities { TextView startButtonText = buttonsView.findViewById(R.id.left_button); View startButtonContainer = buttonsView.findViewById(R.id.left_button_container); + TextView centerButtonText = buttonsView.findViewById(R.id.center_button); + View centerButtonContainer = buttonsView.findViewById(R.id.center_button_container); TextView endButtonText = buttonsView.findViewById(R.id.right_button); View endButtonContainer = buttonsView.findViewById(R.id.right_button_container); GradientDrawable background = new GradientDrawable(); @@ -477,9 +474,27 @@ public class UiUtilities { endButtonText.setTextColor(activeColor); startButtonContainer.setBackgroundDrawable(background); startButtonText.setTextColor(textColor); + + if (centerButtonContainer != null) { + centerButtonText.setTextColor(activeColor); + centerButtonContainer.setBackgroundColor(Color.TRANSPARENT); + } + } else if (buttonType == CustomRadioButtonType.CENTER) { + background.setCornerRadii(new float[] {0, 0, 0, 0, 0, 0, 0, 0}); + centerButtonContainer.setBackgroundDrawable(background); + centerButtonText.setTextColor(textColor); + + if (endButtonContainer != null) { + endButtonText.setTextColor(activeColor); + endButtonContainer.setBackgroundColor(Color.TRANSPARENT); + } + if (startButtonContainer != null) { + startButtonText.setTextColor(activeColor); + startButtonContainer.setBackgroundColor(Color.TRANSPARENT); + } } else { if (isLayoutRtl) { - background.setCornerRadii(new float[]{radius, radius, 0, 0, 0, 0, radius, radius}); + background.setCornerRadii(new float[] {radius, radius, 0, 0, 0, 0, radius, radius}); } else { background.setCornerRadii(new float[]{0, 0, radius, radius, radius, radius, 0, 0}); } @@ -487,119 +502,14 @@ public class UiUtilities { endButtonText.setTextColor(textColor); startButtonContainer.setBackgroundColor(Color.TRANSPARENT); startButtonText.setTextColor(activeColor); - } - } - - public static void updateCustomRadioButtonsGroup(Context app, View buttonsView, boolean nightMode, - CustomRadioButtonTypeGroup buttonType) { - int activeColor = ContextCompat.getColor(app, nightMode - ? R.color.active_color_primary_dark - : R.color.active_color_primary_light); - int inActiveColor = ContextCompat.getColor(app, nightMode - ? R.color.text_color_secondary_dark - : R.color.text_color_secondary_light); - int textColor = ContextCompat.getColor(app, nightMode - ? R.color.text_color_primary_dark - : R.color.text_color_primary_light); - int roundedCorner = AndroidUtils.dpToPx(app, 4); - boolean isLayoutRtl = AndroidUtils.isLayoutRtl(app); - - TextView startButtonText = buttonsView.findViewById(R.id.left_button); - View startButtonContainer = buttonsView.findViewById(R.id.left_button_container); - TextView centerButtonText = buttonsView.findViewById(R.id.center_button); - View centerButtonContainer = buttonsView.findViewById(R.id.center_button_container); - TextView endButtonText = buttonsView.findViewById(R.id.right_button); - View endButtonContainer = buttonsView.findViewById(R.id.right_button_container); - GradientDrawable background = new GradientDrawable(); - background.setColor(UiUtilities.getColorWithAlpha(activeColor, 0.1f)); - background.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(activeColor, 0.5f)); - - GradientDrawable startButtonRoundedCorner = new GradientDrawable(); - startButtonRoundedCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f)); - GradientDrawable endButtonRoundedCorner = new GradientDrawable(); - endButtonRoundedCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f)); - GradientDrawable centerButtonSharpCorner = new GradientDrawable(); - centerButtonSharpCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f)); - - setStartEndCenterRoundedCorner(roundedCorner, isLayoutRtl, startButtonRoundedCorner, endButtonRoundedCorner, centerButtonSharpCorner); - - if (buttonType == CustomRadioButtonTypeGroup.START) { - if (isLayoutRtl) { - background.setCornerRadii(new float[]{0, 0, roundedCorner, roundedCorner, roundedCorner, roundedCorner, 0, 0}); - } else { - background.setCornerRadii(new float[]{roundedCorner, roundedCorner, 0, 0, 0, 0, roundedCorner, roundedCorner}); - } - - if (endButtonContainer != null && centerButtonContainer != null) { - endButtonContainer.setBackground(endButtonRoundedCorner); - endButtonText.setTextColor(activeColor); - centerButtonContainer.setBackground(centerButtonSharpCorner); - centerButtonText.setTextColor(activeColor); - startButtonContainer.setBackgroundDrawable(background); - startButtonText.setTextColor(textColor); - } else if (centerButtonContainer != null) { - centerButtonContainer.setBackground(endButtonRoundedCorner); - centerButtonText.setTextColor(activeColor); - startButtonContainer.setBackgroundDrawable(background); - startButtonText.setTextColor(textColor); - } else if (endButtonContainer != null) { - endButtonContainer.setBackground(endButtonRoundedCorner); - endButtonText.setTextColor(activeColor); - startButtonContainer.setBackgroundDrawable(background); - startButtonText.setTextColor(textColor); - } else if (endButtonContainer == null && centerButtonContainer == null) { - background.setCornerRadii(new float[]{roundedCorner, roundedCorner, roundedCorner, roundedCorner, roundedCorner, roundedCorner, roundedCorner, roundedCorner}); - startButtonContainer.setBackgroundDrawable(background); - startButtonText.setTextColor(textColor); - } - - } else if (buttonType == CustomRadioButtonTypeGroup.CENTER) { - centerButtonContainer.setBackgroundDrawable(background); - centerButtonText.setTextColor(textColor); - startButtonContainer.setBackground(startButtonRoundedCorner); - startButtonText.setTextColor(activeColor); - if (endButtonContainer != null) { - endButtonContainer.setBackground(endButtonRoundedCorner); - endButtonText.setTextColor(activeColor); - } else { - endButtonRoundedCorner.setColor(UiUtilities.getColorWithAlpha(activeColor, 0.1f)); - centerButtonContainer.setBackgroundDrawable(endButtonRoundedCorner); - centerButtonText.setTextColor(textColor); - } - - } else { - if (isLayoutRtl) { - background.setCornerRadii(new float[]{roundedCorner, roundedCorner, 0, 0, 0, 0, roundedCorner, roundedCorner}); - } else { - background.setCornerRadii(new float[]{0, 0, roundedCorner, roundedCorner, roundedCorner, roundedCorner, 0, 0}); - } - startButtonContainer.setBackground(startButtonRoundedCorner); - startButtonText.setTextColor(activeColor); - endButtonContainer.setBackgroundDrawable(background); - endButtonText.setTextColor(textColor); if (centerButtonContainer != null) { - centerButtonContainer.setBackground(centerButtonSharpCorner); centerButtonText.setTextColor(activeColor); + centerButtonContainer.setBackgroundColor(Color.TRANSPARENT); } } } - private static void setStartEndCenterRoundedCorner(int roundedCorner, boolean isLayoutRtl, GradientDrawable startButtonRoundedCorner, GradientDrawable endButtonRoundedCorner, GradientDrawable centerButtonSharpCorner) { - if (isLayoutRtl) { - startButtonRoundedCorner.setCornerRadii(new float[]{0, 0, roundedCorner, roundedCorner, roundedCorner, roundedCorner, 0, 0}); - } else { - startButtonRoundedCorner.setCornerRadii(new float[]{roundedCorner, roundedCorner, 0, 0, 0, 0, roundedCorner, roundedCorner}); - } - if (isLayoutRtl) { - endButtonRoundedCorner.setCornerRadii(new float[]{roundedCorner, roundedCorner, 0, 0, 0, 0, roundedCorner, roundedCorner}); - } else { - endButtonRoundedCorner.setCornerRadii(new float[]{0, 0, roundedCorner, roundedCorner, roundedCorner, roundedCorner, 0, 0}); - } - centerButtonSharpCorner.setCornerRadii(new float[]{0, 0, 0, 0, 0, 0, 0, 0}); - } - - public static void setupCompoundButtonDrawable(Context ctx, boolean nightMode, @ColorInt int activeColor, Drawable drawable) { int inactiveColor = ContextCompat.getColor(ctx, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light); int[][] states = new int[][]{ diff --git a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java index e712d3ca01..0b167e4c97 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java @@ -7,13 +7,13 @@ import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.ViewGroup.MarginLayoutParams; import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.widget.SwitchCompat; import androidx.viewpager.widget.PagerAdapter; -import androidx.viewpager.widget.ViewPager.OnPageChangeListener; import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.data.Entry; @@ -24,7 +24,6 @@ import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture; import com.github.mikephil.charting.listener.OnChartGestureListener; import com.github.mikephil.charting.listener.OnChartValueSelectedListener; -import net.osmand.AndroidUtils; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXTrackAnalysis; @@ -37,6 +36,7 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; +import net.osmand.plus.UiUtilities.CustomRadioButtonType; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType; @@ -44,7 +44,6 @@ import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.helpers.GpxUiHelper.LineGraphType; import net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet; import net.osmand.plus.track.TrackDisplayHelper; -import net.osmand.plus.views.controls.PagerSlidingTabStrip; import net.osmand.plus.views.controls.PagerSlidingTabStrip.CustomTabProvider; import net.osmand.plus.views.controls.WrapContentHeightViewPager.ViewAtPositionInterface; import net.osmand.util.Algorithms; @@ -53,6 +52,7 @@ import net.osmand.util.MapUtils; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -74,7 +74,6 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid private GpxDisplayItem gpxItem; private GPXTabItemType[] tabTypes; - private PagerSlidingTabStrip tabs; private SparseArray views = new SparseArray<>(); private SegmentActionsListener actionsListener; @@ -82,47 +81,17 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid private boolean nightMode; - public GPXItemPagerAdapter(@NonNull final PagerSlidingTabStrip tabs, + public GPXItemPagerAdapter(@NonNull OsmandApplication app, @NonNull GpxDisplayItem gpxItem, @NonNull TrackDisplayHelper displayHelper, - @NonNull SegmentActionsListener actionsListener, - final boolean nightMode) { + boolean nightMode, @NonNull SegmentActionsListener actionsListener) { super(); - this.tabs = tabs; + this.app = app; this.gpxItem = gpxItem; - this.displayHelper = displayHelper; this.nightMode = nightMode; + this.displayHelper = displayHelper; this.actionsListener = actionsListener; - app = (OsmandApplication) tabs.getContext().getApplicationContext(); iconsCache = app.getUIUtilities(); - - tabs.setOnPageChangeListener(new OnPageChangeListener() { - - @Override - public void onPageSelected(int arg0) { - UiUtilities.CustomRadioButtonTypeGroup type; - if (arg0 == 0) { - type = UiUtilities.CustomRadioButtonTypeGroup.START; - } else if (arg0 == 1) { - type = UiUtilities.CustomRadioButtonTypeGroup.CENTER; - } else { - type = UiUtilities.CustomRadioButtonTypeGroup.END; - } - - View parent = (View) tabs.getChildAt(0); - UiUtilities.updateCustomRadioButtonsGroup(app, parent, nightMode, type); - } - - @Override - public void onPageScrolled(int arg0, float arg1, int arg2) { - } - - @Override - public void onPageScrollStateChanged(int arg0) { - - } - }); - fetchTabTypes(); } @@ -589,44 +558,60 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid return view == object; } + int singleTabLayoutId[] = {R.layout.center_button_container}; + int doubleTabsLayoutIds[] = {R.layout.left_button_container, R.layout.right_button_container}; + int tripleTabsLayoutIds[] = {R.layout.left_button_container, R.layout.center_button_container, R.layout.right_button_container}; + @Override public View getCustomTabView(@NonNull ViewGroup parent, int position) { int layoutId; - if (position == 0) { - layoutId = R.layout.left_button_container; - } else if (position == 1) { - layoutId = R.layout.center_button_container; + int count = getCount(); + if (count == 1) { + layoutId = singleTabLayoutId[position]; + } else if (count == 2) { + layoutId = doubleTabsLayoutIds[position]; } else { - layoutId = R.layout.right_button_container; + layoutId = tripleTabsLayoutIds[position]; } View tab = LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false); tab.setTag(tabTypes[position].name()); - deselect(tab); return tab; } @Override public void select(View tab) { GPXTabItemType tabType = GPXTabItemType.valueOf((String) tab.getTag()); - UiUtilities.CustomRadioButtonTypeGroup type; - if (tabType == GPXTabItemType.GPX_TAB_ITEM_GENERAL) { - type = UiUtilities.CustomRadioButtonTypeGroup.START; - } else if (tabType == GPXTabItemType.GPX_TAB_ITEM_ALTITUDE) { - type = UiUtilities.CustomRadioButtonTypeGroup.CENTER; - } else { - type = UiUtilities.CustomRadioButtonTypeGroup.END; - } + int index = Arrays.asList(tabTypes).indexOf(tabType); View parent = (View) tab.getParent(); - UiUtilities.updateCustomRadioButtonsGroup(app, parent, nightMode, type); - - ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) parent.getLayoutParams(); - int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding); - int containerMargin = app.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_margin_small); - AndroidUtils.setMargins(params, contentPadding, containerMargin, contentPadding, containerMargin); + UiUtilities.updateCustomRadioButtons(app, parent, nightMode, getCustomRadioButtonType(index)); } @Override public void deselect(View tab) { + + } + + @Override + public void tabStylesUpdated(View tabsContainer, int currentPosition) { + ViewGroup.MarginLayoutParams params = (MarginLayoutParams) tabsContainer.getLayoutParams(); + params.height = app.getResources().getDimensionPixelSize(R.dimen.dialog_button_height); + tabsContainer.setLayoutParams(params); + UiUtilities.updateCustomRadioButtons(app, tabsContainer, nightMode, getCustomRadioButtonType(currentPosition)); + } + + private CustomRadioButtonType getCustomRadioButtonType(int index) { + int count = getCount(); + CustomRadioButtonType type = CustomRadioButtonType.CENTER; + if (count == 2) { + type = index > 0 ? CustomRadioButtonType.END : CustomRadioButtonType.START; + } else if (count == 3) { + if (index == 0) { + type = CustomRadioButtonType.START; + } else if (index == 2) { + type = CustomRadioButtonType.END; + } + } + return type; } @Override diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SegmentGPXAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/SegmentGPXAdapter.java index 9f2e234dcd..60141d5ccf 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/SegmentGPXAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/SegmentGPXAdapter.java @@ -1,13 +1,11 @@ package net.osmand.plus.myplaces; import android.content.Context; -import android.graphics.drawable.GradientDrawable; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; import net.osmand.AndroidUtils; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; @@ -22,6 +20,7 @@ import java.util.List; public class SegmentGPXAdapter extends ArrayAdapter { + private OsmandApplication app; private TrackDisplayHelper displayHelper; private SegmentActionsListener listener; private boolean nightMode; @@ -31,7 +30,7 @@ public class SegmentGPXAdapter extends ArrayAdapter { @NonNull SegmentActionsListener listener, boolean nightMode) { super(context, R.layout.gpx_list_item_tab_content, items); - OsmandApplication app = (OsmandApplication) context.getApplicationContext(); + this.app = (OsmandApplication) context.getApplicationContext(); this.displayHelper = displayHelper; this.listener = listener; this.nightMode = nightMode; @@ -56,7 +55,7 @@ public class SegmentGPXAdapter extends ArrayAdapter { WrapContentHeightViewPager pager = row.findViewById(R.id.pager); PagerSlidingTabStrip tabLayout = row.findViewById(R.id.sliding_tabs); - pager.setAdapter(new GPXItemPagerAdapter(tabLayout, item, displayHelper, listener, nightMode)); + pager.setAdapter(new GPXItemPagerAdapter(app, item, displayHelper, nightMode, listener)); if (create) { tabLayout.setViewPager(pager); } else { @@ -72,9 +71,8 @@ public class SegmentGPXAdapter extends ArrayAdapter { View row = UiUtilities.getInflater(context, nightMode).inflate(R.layout.gpx_list_item_tab_content, root, false); PagerSlidingTabStrip tabLayout = row.findViewById(R.id.sliding_tabs); - tabLayout.setTabBackground(R.color.color_transparent); - tabLayout.setIndicatorHeight(AndroidUtils.dpToPx(context, 0)); - tabLayout.setTextSize(AndroidUtils.spToPx(context, 12f)); + tabLayout.setTabBackground(AndroidUtils.resolveAttribute(context, R.attr.btn_bg_border_inactive)); + tabLayout.setIndicatorHeight(0); tabLayout.setShouldExpand(true); WrapContentHeightViewPager pager = row.findViewById(R.id.pager); pager.setSwipeable(false); diff --git a/OsmAnd/src/net/osmand/plus/track/SegmentsCard.java b/OsmAnd/src/net/osmand/plus/track/SegmentsCard.java index 9aa7c91391..ad266fc2ab 100644 --- a/OsmAnd/src/net/osmand/plus/track/SegmentsCard.java +++ b/OsmAnd/src/net/osmand/plus/track/SegmentsCard.java @@ -47,7 +47,7 @@ public class SegmentsCard extends BaseCard { WrapContentHeightViewPager pager = segmentView.findViewById(R.id.pager); PagerSlidingTabStrip tabLayout = segmentView.findViewById(R.id.sliding_tabs); - pager.setAdapter(new GPXItemPagerAdapter(tabLayout, displayItem, displayHelper, listener, nightMode)); + pager.setAdapter(new GPXItemPagerAdapter(app, displayItem, displayHelper, nightMode, listener)); tabLayout.setViewPager(pager); container.addView(segmentView); diff --git a/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java b/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java index e38a8619b0..f6d5bdd4fd 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java @@ -68,6 +68,7 @@ public class PagerSlidingTabStrip extends HorizontalScrollView { public View getCustomTabView(@NonNull ViewGroup parent, int position); public void select(View tab); public void deselect(View tab); + public void tabStylesUpdated(View tabsContainer, int currentPosition); } public interface OnTabReselectedListener { @@ -307,6 +308,10 @@ public class PagerSlidingTabStrip extends HorizontalScrollView { } } + public int getCurrentPosition() { + return currentPosition; + } + private void addTab(final int position, CharSequence title, View tabView) { TextView textView = (TextView) tabView.findViewById(R.id.tab_title); if (textView != null) { @@ -332,42 +337,32 @@ public class PagerSlidingTabStrip extends HorizontalScrollView { private void updateTabStyles() { tabsContainer.setBackgroundResource(tabBackgroundResId); - for (int i = 0; i < tabCount; i++) { - View v = tabsContainer.getChildAt(i); - v.setBackgroundResource(tabBackgroundResId); - v.setPadding(tabPadding, v.getPaddingTop(), tabPadding, v.getPaddingBottom()); - TextView tab_title = (TextView) v.findViewById(R.id.tab_title); + if (pager.getAdapter() instanceof CustomTabProvider) { + ((CustomTabProvider) pager.getAdapter()).tabStylesUpdated(tabsContainer, currentPosition); + } else { + for (int i = 0; i < tabCount; i++) { + View v = tabsContainer.getChildAt(i); + v.setBackgroundResource(tabBackgroundResId); + v.setPadding(tabPadding, v.getPaddingTop(), tabPadding, v.getPaddingBottom()); - if (tab_title != null) { - tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); - tab_title.setTypeface(tabTypeface, pager.getCurrentItem() == i ? tabTypefaceSelectedStyle : tabTypefaceStyle); - switch (tabSelectionType) { - case ALPHA: - float alpha = pager.getCurrentItem() == i ? tabTextSelectedAlpha : tabTextAlpha; - tab_title.setAlpha(alpha); - tab_title.setTextColor(tabTextColor); - break; - case SOLID_COLOR: - tab_title.setAlpha(OPAQUE); - tab_title.setTextColor(pager.getCurrentItem() == i ? tabTextColor : tabInactiveTextColor); - break; - } - - // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a - // pre-ICS-build - if (textAllCaps) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { - tab_title.setAllCaps(true); - } else { - tab_title.setText(tab_title.getText().toString().toUpperCase(locale)); + TextView tabTitle = v.findViewById(R.id.tab_title); + if (tabTitle != null) { + tabTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); + tabTitle.setTypeface(tabTypeface, pager.getCurrentItem() == i ? tabTypefaceSelectedStyle : tabTypefaceStyle); + switch (tabSelectionType) { + case ALPHA: + float alpha = pager.getCurrentItem() == i ? tabTextSelectedAlpha : tabTextAlpha; + tabTitle.setAlpha(alpha); + tabTitle.setTextColor(tabTextColor); + break; + case SOLID_COLOR: + tabTitle.setAlpha(OPAQUE); + tabTitle.setTextColor(pager.getCurrentItem() == i ? tabTextColor : tabInactiveTextColor); + break; + } + if (textAllCaps) { + tabTitle.setAllCaps(true); } - } - } - if (pager.getAdapter() instanceof CustomTabProvider) { - if (pager.getCurrentItem() == i) { - ((CustomTabProvider) pager.getAdapter()).select(v); - } else { - ((CustomTabProvider) pager.getAdapter()).deselect(v); } } } @@ -558,39 +553,41 @@ public class PagerSlidingTabStrip extends HorizontalScrollView { private void notSelected(View tab) { if (tab != null) { - TextView title = (TextView) tab.findViewById(R.id.tab_title); - if (title != null) { - title.setTypeface(tabTypeface, tabTypefaceStyle); - switch (tabSelectionType) { - case ALPHA: - title.setAlpha(tabTextAlpha); - break; - case SOLID_COLOR: - title.setTextColor(tabInactiveTextColor); - break; - } - } if (pager.getAdapter() instanceof CustomTabProvider) { ((CustomTabProvider) pager.getAdapter()).deselect(tab); + } else { + TextView title = tab.findViewById(R.id.tab_title); + if (title != null) { + title.setTypeface(tabTypeface, tabTypefaceStyle); + switch (tabSelectionType) { + case ALPHA: + title.setAlpha(tabTextAlpha); + break; + case SOLID_COLOR: + title.setTextColor(tabInactiveTextColor); + break; + } + } } } } private void selected(View tab) { if (tab != null) { - TextView title = (TextView) tab.findViewById(R.id.tab_title); - if (title != null) { - title.setTypeface(tabTypeface, tabTypefaceSelectedStyle); - switch (tabSelectionType) { - case ALPHA: - title.setAlpha(tabTextSelectedAlpha); - break; - case SOLID_COLOR: - title.setTextColor(tabTextColor); - break; - } - if (pager.getAdapter() instanceof CustomTabProvider) { - ((CustomTabProvider) pager.getAdapter()).select(tab); + if (pager.getAdapter() instanceof CustomTabProvider) { + ((CustomTabProvider) pager.getAdapter()).select(tab); + } else { + TextView title = tab.findViewById(R.id.tab_title); + if (title != null) { + title.setTypeface(tabTypeface, tabTypefaceSelectedStyle); + switch (tabSelectionType) { + case ALPHA: + title.setAlpha(tabTextSelectedAlpha); + break; + case SOLID_COLOR: + title.setTextColor(tabTextColor); + break; + } } } }