From f76c511e6b7169a9f41f49dbc858ff2763e34f10 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 23 Mar 2018 16:54:58 +0200 Subject: [PATCH 1/7] added asyncTask --- .../search/QuickSearchDialogFragment.java | 4 +- .../plus/search/QuickSearchListFragment.java | 39 +++++++++++++------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 4daa33a964..0bc6bfa716 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -988,12 +988,12 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo()); } - private void showProgressBar() { + void showProgressBar() { updateClearButtonVisibility(false); progressBar.setVisibility(View.VISIBLE); } - private void hideProgressBar() { + void hideProgressBar() { updateClearButtonVisibility(true); progressBar.setVisibility(View.GONE); } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index 82aa807b36..a0eae562fd 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.search; +import android.os.AsyncTask; import android.os.Bundle; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -86,7 +87,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { if (item.getType() == QuickSearchListItemType.BUTTON) { ((QuickSearchButtonListItem) item).getOnClickListener().onClick(view); } else if (item.getType() == QuickSearchListItemType.SEARCH_RESULT) { - SearchResult sr = item.getSearchResult(); + final SearchResult sr = item.getSearchResult(); if (sr.objectType == ObjectType.POI || sr.objectType == ObjectType.LOCATION @@ -97,22 +98,37 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { || sr.objectType == ObjectType.STREET_INTERSECTION) { showResult(sr); - } else { - if ((sr.objectType == ObjectType.CITY || sr.objectType == ObjectType.VILLAGE) - && sr.file != null && sr.object instanceof City) { - City c = (City) sr.object; - if (c.getStreets().isEmpty()) { + } else if ((sr.objectType == ObjectType.CITY || sr.objectType == ObjectType.VILLAGE) + && sr.file != null && sr.object instanceof City) { + final City c = (City) sr.object; + new AsyncTask() { + @Override + protected void onPreExecute() { + dialogFragment.showProgressBar(); + } + + @Override + protected Void doInBackground(Void... voids) { try { sr.file.preloadStreets(c, null); - if (c.getStreets().isEmpty()) { - showResult(sr); - return; - } } catch (IOException e) { e.printStackTrace(); } + return null; } - } + + @Override + protected void onPostExecute(Void aVoid) { + dialogFragment.hideProgressBar(); + if (c.getStreets().isEmpty()) { + showResult(sr); + return; + } else { + dialogFragment.completeQueryWithObject(sr); + } + } + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else { dialogFragment.completeQueryWithObject(sr); } } @@ -120,6 +136,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { } } + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); From c12f99cef5915d9f4f9cb4d33e160281eaea0ba3 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 23 Mar 2018 16:56:14 +0200 Subject: [PATCH 2/7] refactored some code --- OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index a0eae562fd..bbb5b9498e 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -127,7 +127,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { dialogFragment.completeQueryWithObject(sr); } } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + }.execute(); } else { dialogFragment.completeQueryWithObject(sr); } From c919b7e37d20700657cd439a87e6347f0b1d870a Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 23 Mar 2018 17:57:14 +0200 Subject: [PATCH 3/7] added resultMatcher --- .../plus/search/QuickSearchListFragment.java | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index bbb5b9498e..23f5acddc8 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -11,6 +11,8 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; +import net.osmand.ResultMatcher; +import net.osmand.binary.BinaryMapIndexReader; import net.osmand.data.Amenity; import net.osmand.data.City; import net.osmand.data.FavouritePoint; @@ -98,37 +100,36 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { || sr.objectType == ObjectType.STREET_INTERSECTION) { showResult(sr); - } else if ((sr.objectType == ObjectType.CITY || sr.objectType == ObjectType.VILLAGE) - && sr.file != null && sr.object instanceof City) { - final City c = (City) sr.object; - new AsyncTask() { - @Override - protected void onPreExecute() { - dialogFragment.showProgressBar(); - } + } else { + if ((sr.objectType == ObjectType.CITY || sr.objectType == ObjectType.VILLAGE) + && sr.file != null && sr.object instanceof City) { + City c = (City) sr.object; + if (c.getStreets().isEmpty()) { + ResultMatcher resultMatcher = new ResultMatcher() { + boolean isCancelled = false; - @Override - protected Void doInBackground(Void... voids) { + @Override + public boolean publish(Street object) { + isCancelled = true; + return true; + } + + @Override + public boolean isCancelled() { + return isCancelled; + } + }; try { - sr.file.preloadStreets(c, null); + sr.file.preloadStreets(c, BinaryMapIndexReader.buildAddressRequest(resultMatcher)); + if (c.getStreets().isEmpty()) { + showResult(sr); + return; + } } catch (IOException e) { e.printStackTrace(); } - return null; } - - @Override - protected void onPostExecute(Void aVoid) { - dialogFragment.hideProgressBar(); - if (c.getStreets().isEmpty()) { - showResult(sr); - return; - } else { - dialogFragment.completeQueryWithObject(sr); - } - } - }.execute(); - } else { + } dialogFragment.completeQueryWithObject(sr); } } @@ -137,6 +138,8 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { } + + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); From 49cd81865f6aff9aacc3beeb9c128143945dc0d9 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 23 Mar 2018 18:02:03 +0200 Subject: [PATCH 4/7] refactored some code --- .../net/osmand/plus/search/QuickSearchDialogFragment.java | 4 ++-- .../src/net/osmand/plus/search/QuickSearchListFragment.java | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 0bc6bfa716..4daa33a964 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -988,12 +988,12 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo()); } - void showProgressBar() { + private void showProgressBar() { updateClearButtonVisibility(false); progressBar.setVisibility(View.VISIBLE); } - void hideProgressBar() { + private void hideProgressBar() { updateClearButtonVisibility(true); progressBar.setVisibility(View.GONE); } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index 23f5acddc8..86b13f5a38 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -1,6 +1,5 @@ package net.osmand.plus.search; -import android.os.AsyncTask; import android.os.Bundle; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -105,7 +104,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { && sr.file != null && sr.object instanceof City) { City c = (City) sr.object; if (c.getStreets().isEmpty()) { - ResultMatcher resultMatcher = new ResultMatcher() { + ResultMatcher resultMatcher = new ResultMatcher() { boolean isCancelled = false; @Override @@ -137,9 +136,6 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { } } - - - @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); From 8fd6142a8bfdff7a21a72397e80994b4e9d4551b Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 23 Mar 2018 18:12:06 +0200 Subject: [PATCH 5/7] deleted unnecessary code --- OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index 86b13f5a38..c28a1bc988 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -88,7 +88,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { if (item.getType() == QuickSearchListItemType.BUTTON) { ((QuickSearchButtonListItem) item).getOnClickListener().onClick(view); } else if (item.getType() == QuickSearchListItemType.SEARCH_RESULT) { - final SearchResult sr = item.getSearchResult(); + SearchResult sr = item.getSearchResult(); if (sr.objectType == ObjectType.POI || sr.objectType == ObjectType.LOCATION From befaa12c8070760ebf2bc09cee685ff05068d4a3 Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 26 Mar 2018 10:47:37 +0300 Subject: [PATCH 6/7] added method isCityEmpty for checking streets --- .../plus/search/QuickSearchListFragment.java | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index c28a1bc988..651749aa2f 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -103,30 +103,9 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { if ((sr.objectType == ObjectType.CITY || sr.objectType == ObjectType.VILLAGE) && sr.file != null && sr.object instanceof City) { City c = (City) sr.object; - if (c.getStreets().isEmpty()) { - ResultMatcher resultMatcher = new ResultMatcher() { - boolean isCancelled = false; - - @Override - public boolean publish(Street object) { - isCancelled = true; - return true; - } - - @Override - public boolean isCancelled() { - return isCancelled; - } - }; - try { - sr.file.preloadStreets(c, BinaryMapIndexReader.buildAddressRequest(resultMatcher)); - if (c.getStreets().isEmpty()) { - showResult(sr); - return; - } - } catch (IOException e) { - e.printStackTrace(); - } + if (isCityEmpty(c, sr)) { + showResult(sr); + return; } } dialogFragment.completeQueryWithObject(sr); @@ -136,6 +115,37 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { } } + public boolean isCityEmpty(City c, SearchResult sr) { + if (c.getStreets().isEmpty()) { + ResultMatcher resultMatcher = new ResultMatcher() { + boolean isCancelled = false; + + @Override + public boolean publish(Street object) { + isCancelled = true; + return true; + } + + @Override + public boolean isCancelled() { + return isCancelled; + } + }; + try { + sr.file.preloadStreets(c, BinaryMapIndexReader.buildAddressRequest(resultMatcher)); + if (c.getStreets().isEmpty()) { + return true; + } else { + c.unregisterStreet(c.getStreets().get(0)); + return false; + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return false; + } + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); From 2cacac9b60667498aa8b6ea02fd965727d51c55c Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 26 Mar 2018 11:33:46 +0300 Subject: [PATCH 7/7] added boolean isEmpty and refactored some code --- .../plus/search/QuickSearchListFragment.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index 651749aa2f..96626656c7 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -116,6 +116,8 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { } public boolean isCityEmpty(City c, SearchResult sr) { + final boolean isEmpty[] = new boolean[1]; + isEmpty[0] = true; if (c.getStreets().isEmpty()) { ResultMatcher resultMatcher = new ResultMatcher() { boolean isCancelled = false; @@ -123,7 +125,8 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { @Override public boolean publish(Street object) { isCancelled = true; - return true; + isEmpty[0] = false; + return false; } @Override @@ -133,17 +136,13 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { }; try { sr.file.preloadStreets(c, BinaryMapIndexReader.buildAddressRequest(resultMatcher)); - if (c.getStreets().isEmpty()) { - return true; - } else { - c.unregisterStreet(c.getStreets().get(0)); - return false; - } } catch (IOException e) { e.printStackTrace(); } + } else { + isEmpty[0] = false; } - return false; + return isEmpty[0]; } @Override