From 8c38c5e19a64af972798b29a1698a22eb1f2fb7e Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Sun, 12 Mar 2017 10:47:03 +0300 Subject: [PATCH] Fix track thumbnail bug --- OsmAnd/res/layout/gpx_item_list_header.xml | 8 ++ .../plus/myplaces/TrackSegmentFragment.java | 128 +++++++++--------- .../osmand/plus/render/MapVectorLayer.java | 2 +- .../plus/resources/AsyncLoadingThread.java | 10 +- .../plus/resources/ResourceManager.java | 5 +- 5 files changed, 83 insertions(+), 70 deletions(-) diff --git a/OsmAnd/res/layout/gpx_item_list_header.xml b/OsmAnd/res/layout/gpx_item_list_header.xml index 3ba7b4a2fb..c24880506a 100644 --- a/OsmAnd/res/layout/gpx_item_list_header.xml +++ b/OsmAnd/res/layout/gpx_item_list_header.xml @@ -17,6 +17,14 @@ android:layout_height="152dp" android:scaleType="center"/> + + { - private Map pagerAdaptersMap = new HashMap<>(); - SegmentGPXAdapter(List items) { super(getActivity(), R.layout.gpx_list_item_tab_content, items); } @@ -713,21 +720,6 @@ public class TrackSegmentFragment extends OsmAndListFragment { return false; } - @Override - public void clear() { - super.clear(); - pagerAdaptersMap.clear(); - } - - private GPXItemPagerAdapter getPagerAdapter(PagerSlidingTabStrip tabs, GpxDisplayItem gpxItem) { - GPXItemPagerAdapter adapter = pagerAdaptersMap.get(gpxItem); - if (adapter == null) { - adapter = new GPXItemPagerAdapter(tabs, gpxItem); - pagerAdaptersMap.put(gpxItem, adapter); - } - return adapter; - } - @NonNull @Override public View getView(int position, View convertView, @NonNull ViewGroup parent) { @@ -759,7 +751,7 @@ public class TrackSegmentFragment extends OsmAndListFragment { } GpxDisplayItem item = getItem(position); if (item != null) { - pager.setAdapter(getPagerAdapter(tabLayout, item)); + pager.setAdapter(new GPXItemPagerAdapter(tabLayout, item)); if (create) { tabLayout.setViewPager(pager); } else { @@ -1256,17 +1248,21 @@ public class TrackSegmentFragment extends OsmAndListFragment { void updateChart(int position) { View view = getViewAtPosition(position); - updateChart((LineChart) view.findViewById(R.id.chart)); + if (view != null) { + updateChart((LineChart) view.findViewById(R.id.chart)); + } } void updateChart(LineChart chart) { - if (gpxItem.chartMatrix != null) { - chart.getViewPortHandler().refresh(new Matrix(gpxItem.chartMatrix), chart, true); - } - if (gpxItem.chartHighlightPos != -1) { - chart.highlightValue(gpxItem.chartHighlightPos, 0); - } else { - chart.highlightValue(null); + if (chart != null) { + if (gpxItem.chartMatrix != null) { + chart.getViewPortHandler().refresh(new Matrix(gpxItem.chartMatrix), chart, true); + } + if (gpxItem.chartHighlightPos != -1) { + chart.highlightValue(gpxItem.chartHighlightPos, 0); + } else { + chart.highlightValue(null); + } } } diff --git a/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java b/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java index 67ac86ab15..dce4b64c56 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java +++ b/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java @@ -158,7 +158,7 @@ public class MapVectorLayer extends BaseMapLayer { // view.getHeight() / 2); final RotatedTileBox copy = tilesRect.copy(); copy.increasePixelDimensions(copy.getPixWidth() / 3, copy.getPixHeight() / 4); - resourceManager.updateRendererMap(copy); + resourceManager.updateRendererMap(copy, null); } } diff --git a/OsmAnd/src/net/osmand/plus/resources/AsyncLoadingThread.java b/OsmAnd/src/net/osmand/plus/resources/AsyncLoadingThread.java index 08e4f69ca0..a75c5b35b3 100644 --- a/OsmAnd/src/net/osmand/plus/resources/AsyncLoadingThread.java +++ b/OsmAnd/src/net/osmand/plus/resources/AsyncLoadingThread.java @@ -50,6 +50,9 @@ public class AsyncLoadingThread extends Thread { MapLoadRequest r = (MapLoadRequest) req; resourceManger.getRenderer().loadMap(r.tileBox, resourceManger.getMapTileDownloader()); mapLoaded = !resourceManger.getRenderer().wasInterrupted(); + if (r.mapLoadedListener != null) { + r.mapLoadedListener.onMapLoaded(!mapLoaded); + } } } } @@ -182,13 +185,18 @@ public class AsyncLoadingThread extends Thread { } + public interface OnMapLoadedListener { + void onMapLoaded(boolean interrupted); + } protected static class MapLoadRequest { public final RotatedTileBox tileBox; + public final OnMapLoadedListener mapLoadedListener; - public MapLoadRequest(RotatedTileBox tileBox) { + public MapLoadRequest(RotatedTileBox tileBox, OnMapLoadedListener mapLoadedListener) { super(); this.tileBox = tileBox; + this.mapLoadedListener = mapLoadedListener; } } diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index c21be373b0..65fc477f58 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -40,6 +40,7 @@ import net.osmand.plus.Version; import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.render.NativeOsmandLibrary; import net.osmand.plus.resources.AsyncLoadingThread.MapLoadRequest; +import net.osmand.plus.resources.AsyncLoadingThread.OnMapLoadedListener; import net.osmand.plus.resources.AsyncLoadingThread.TileLoadDownloadRequest; import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; @@ -1017,9 +1018,9 @@ public class ResourceManager { return renderer.updateMapIsNeeded(rotatedTileBox, drawSettings); } - public void updateRendererMap(RotatedTileBox rotatedTileBox){ + public void updateRendererMap(RotatedTileBox rotatedTileBox, OnMapLoadedListener mapLoadedListener){ renderer.interruptLoadingMap(); - asyncLoadingThread.requestToLoadMap(new MapLoadRequest(rotatedTileBox)); + asyncLoadingThread.requestToLoadMap(new MapLoadRequest(rotatedTileBox, mapLoadedListener)); } public void interruptRendering(){