From 43b94f923b8f6a9a326f33b3aa5fcf14168f980e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20P=C3=B3=C5=82grabia?= Date: Sun, 9 Oct 2016 21:45:32 +0200 Subject: [PATCH] Fix of refresh for google places fragment. --- .../fragments/PlacesFragment.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PlacesFragment.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PlacesFragment.java index 62d38a3..be79ab2 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PlacesFragment.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PlacesFragment.java @@ -40,9 +40,7 @@ import pl.tpolgrabia.urbanexplorerutils.utils.SettingsUtils; import java.io.*; import java.util.ArrayList; import java.util.List; -import java.util.Locale; import java.util.concurrent.Semaphore; -import java.util.regex.Pattern; /** @@ -165,6 +163,8 @@ public class PlacesFragment extends Fragment { location.getLatitude(), location.getLongitude()), Toast.LENGTH_SHORT).show(); + cleanAdapter(); + places = null; nextPageToken = null; noMoreResults = false; @@ -333,6 +333,14 @@ public class PlacesFragment extends Fragment { public void refresh(RefreshEvent event) { lg.debug("Refreshing event..."); Toast.makeText(getActivity(), "Refreshing event google places", Toast.LENGTH_SHORT).show(); + + if (getView() == null) { + lg.debug("Sorry, headless fragment"); + return; + } + + cleanAdapter(); + pageId = 0L; places = null; nextPageToken = null; @@ -340,4 +348,10 @@ public class PlacesFragment extends Fragment { fetchNearbyPlacesAndPresent(LocationUtils.getLastKnownLocation(getActivity())); } + private void cleanAdapter() { + ListView plagesWidget = (ListView) getView().findViewById(R.id.google_places); + PlacesAdapter adapter = (PlacesAdapter) plagesWidget.getAdapter(); + adapter.clear(); + } + }