From 8d61f1afe091ebd0f5c8fd924ef516d3e5d09410 Mon Sep 17 00:00:00 2001 From: Alexander Marchuk Date: Fri, 5 Feb 2016 18:38:46 +0300 Subject: [PATCH] [new downloader][android] fix: Simple location listener. --- .../maps/bookmarks/BookmarkListAdapter.java | 31 +++++-------- .../maps/location/LocationHelper.java | 12 +++++ .../maps/location/TrackRecorder.java | 5 +-- .../maps/search/SearchFragment.java | 44 +++++++++---------- .../mapswithme/maps/widget/menu/MainMenu.java | 9 ++-- .../com/mapswithme/util/ThemeSwitcher.java | 6 +-- 6 files changed, 51 insertions(+), 56 deletions(-) diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java index ad09d084a1..75017b2ea9 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java @@ -23,7 +23,6 @@ import com.mapswithme.util.Graphics; public class BookmarkListAdapter extends BaseAdapter - implements LocationHelper.LocationListener { private final Activity mActivity; private final BookmarkCategory mCategory; @@ -36,6 +35,15 @@ public class BookmarkListAdapter extends BaseAdapter private static final int SECTION_TRACKS = 0; private static final int SECTION_BMKS = 1; + private final LocationHelper.LocationListener mLocationListener = new LocationHelper.SimpleLocationListener() + { + @Override + public void onLocationUpdated(Location l) + { + notifyDataSetChanged(); + } + }; + public BookmarkListAdapter(Activity activity, BookmarkCategory cat) { mActivity = activity; @@ -44,12 +52,12 @@ public class BookmarkListAdapter extends BaseAdapter public void startLocationUpdate() { - LocationHelper.INSTANCE.addLocationListener(this, true); + LocationHelper.INSTANCE.addLocationListener(mLocationListener, true); } public void stopLocationUpdate() { - LocationHelper.INSTANCE.removeLocationListener(this); + LocationHelper.INSTANCE.removeLocationListener(mLocationListener); } @Override @@ -140,23 +148,6 @@ public class BookmarkListAdapter extends BaseAdapter return position; } - @Override - public void onLocationUpdated(final Location l) - { - notifyDataSetChanged(); - } - - @Override - public void onCompassUpdated(long time, double magneticNorth, double trueNorth, double accuracy) - { - // We don't show any arrows for bookmarks any more. - } - - @Override - public void onLocationError(int errorCode) - { - } - private class PinHolder { ImageView icon; diff --git a/android/src/com/mapswithme/maps/location/LocationHelper.java b/android/src/com/mapswithme/maps/location/LocationHelper.java index b5d74d3fd4..75fc0e9cc7 100644 --- a/android/src/com/mapswithme/maps/location/LocationHelper.java +++ b/android/src/com/mapswithme/maps/location/LocationHelper.java @@ -50,6 +50,18 @@ public enum LocationHelper implements SensorEventListener void onLocationError(int errorCode); } + public static class SimpleLocationListener implements LocationListener + { + @Override + public void onLocationUpdated(Location l) {} + + @Override + public void onCompassUpdated(long time, double magneticNorth, double trueNorth, double accuracy) {} + + @Override + public void onLocationError(int errorCode) {} + } + private final Listeners mListeners = new Listeners<>(); private boolean mActive; diff --git a/android/src/com/mapswithme/maps/location/TrackRecorder.java b/android/src/com/mapswithme/maps/location/TrackRecorder.java index 757ad8a894..dc827a67a8 100644 --- a/android/src/com/mapswithme/maps/location/TrackRecorder.java +++ b/android/src/com/mapswithme/maps/location/TrackRecorder.java @@ -38,7 +38,7 @@ public final class TrackRecorder private static Boolean sEnableLogging; private static Logger sLogger; - private static final LocationHelper.LocationListener sLocationListener = new LocationHelper.LocationListener() + private static final LocationHelper.LocationListener sLocationListener = new LocationHelper.SimpleLocationListener() { @Override public void onLocationUpdated(Location location) @@ -57,9 +57,6 @@ public final class TrackRecorder // Unrecoverable error occured: GPS disabled or inaccessible setEnabled(false); } - - @Override - public void onCompassUpdated(long time, double magneticNorth, double trueNorth, double accuracy) {} }; private TrackRecorder() {} diff --git a/android/src/com/mapswithme/maps/search/SearchFragment.java b/android/src/com/mapswithme/maps/search/SearchFragment.java index e944d07d46..c2dc94dd10 100644 --- a/android/src/com/mapswithme/maps/search/SearchFragment.java +++ b/android/src/com/mapswithme/maps/search/SearchFragment.java @@ -20,9 +20,8 @@ import android.view.ViewGroup; import java.util.ArrayList; import java.util.List; -import com.mapswithme.country.ActiveCountryTree; -import com.mapswithme.country.CountrySuggestFragment; -import com.mapswithme.country.DownloadFragment; +import com.mapswithme.maps.downloader.country.OldActiveCountryTree; +import com.mapswithme.maps.downloader.country.OldDownloadFragment; import com.mapswithme.maps.Framework; import com.mapswithme.maps.MwmActivity; import com.mapswithme.maps.R; @@ -30,6 +29,7 @@ import com.mapswithme.maps.base.BaseMwmFragment; import com.mapswithme.maps.base.BaseMwmFragmentActivity; import com.mapswithme.maps.base.OnBackPressListener; import com.mapswithme.maps.bookmarks.data.MapObject; +import com.mapswithme.maps.downloader.CountrySuggestFragment; import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.maps.routing.RoutingController; import com.mapswithme.maps.widget.SearchToolbarController; @@ -42,8 +42,7 @@ import com.mapswithme.util.statistics.Statistics; public class SearchFragment extends BaseMwmFragment - implements LocationHelper.LocationListener, - OnBackPressListener, + implements OnBackPressListener, NativeSearchListener, SearchToolbarController.Container, CategoriesAdapter.OnCategorySelectedListener @@ -144,9 +143,21 @@ public class SearchFragment extends BaseMwmFragment private String mInitialQuery; private boolean mFromRoutePlan; + private final LocationHelper.LocationListener mLocationListener = new LocationHelper.SimpleLocationListener() + { + @Override + public void onLocationUpdated(Location l) + { + mLastPosition.set(l.getLatitude(), l.getLongitude()); + + if (!TextUtils.isEmpty(getQuery())) + mSearchAdapter.notifyDataSetChanged(); + } + }; + private static boolean doShowDownloadSuggest() { - return ActiveCountryTree.getTotalDownloadedCount() == 0; + return OldActiveCountryTree.getTotalDownloadedCount() == 0; } private void showDownloadSuggest() @@ -176,7 +187,7 @@ public class SearchFragment extends BaseMwmFragment public void showDownloader() { - ((BaseMwmFragmentActivity)getActivity()).replaceFragment(DownloadFragment.class, null, null); + ((BaseMwmFragmentActivity)getActivity()).replaceFragment(OldDownloadFragment.class, null, null); UiUtils.hide(mResultsFrame, mResultsPlaceholder, mTabFrame); } @@ -272,13 +283,13 @@ public class SearchFragment extends BaseMwmFragment public void onResume() { super.onResume(); - LocationHelper.INSTANCE.addLocationListener(this, true); + LocationHelper.INSTANCE.addLocationListener(mLocationListener, true); } @Override public void onPause() { - LocationHelper.INSTANCE.removeLocationListener(this); + LocationHelper.INSTANCE.removeLocationListener(mLocationListener); super.onPause(); } @@ -387,21 +398,6 @@ public class SearchFragment extends BaseMwmFragment Statistics.INSTANCE.trackEvent(Statistics.EventName.SEARCH_ON_MAP_CLICKED); } - @Override - public void onLocationUpdated(final Location l) - { - mLastPosition.set(l.getLatitude(), l.getLongitude()); - - if (!TextUtils.isEmpty(getQuery())) - mSearchAdapter.notifyDataSetChanged(); - } - - @Override - public void onCompassUpdated(long time, double magneticNorth, double trueNorth, double accuracy) {} - - @Override - public void onLocationError(int errorCode) {} - private void onSearchEnd() { mSearchRunning = false; diff --git a/android/src/com/mapswithme/maps/widget/menu/MainMenu.java b/android/src/com/mapswithme/maps/widget/menu/MainMenu.java index 19d7b1990c..8c2f3b0b2e 100644 --- a/android/src/com/mapswithme/maps/widget/menu/MainMenu.java +++ b/android/src/com/mapswithme/maps/widget/menu/MainMenu.java @@ -18,11 +18,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.mapswithme.country.ActiveCountryTree; import com.mapswithme.maps.Framework; import com.mapswithme.maps.MwmActivity; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.R; +import com.mapswithme.maps.downloader.MapManager; +import com.mapswithme.maps.downloader.UpdateInfo; import com.mapswithme.maps.routing.RoutingInfo; import com.mapswithme.maps.widget.RotateByAlphaDrawable; import com.mapswithme.maps.widget.TrackedTransitionDrawable; @@ -314,8 +315,10 @@ public class MainMenu private void updateMarker() { - int count = ActiveCountryTree.getOutOfDateCount(); - boolean show = (ActiveCountryTree.isLegacyMode() || count > 0) && + UpdateInfo info = MapManager.nativeGetUpdateInfo(); + int count = (info == null ? 0 : info.filesCount); + + boolean show = (MapManager.nativeIsLegacyMode() || count > 0) && (!mCollapsed || mCollapseViews.isEmpty()) && !isOpen(); diff --git a/android/src/com/mapswithme/util/ThemeSwitcher.java b/android/src/com/mapswithme/util/ThemeSwitcher.java index d2173c2260..d0e5be9168 100644 --- a/android/src/com/mapswithme/util/ThemeSwitcher.java +++ b/android/src/com/mapswithme/util/ThemeSwitcher.java @@ -15,7 +15,7 @@ public final class ThemeSwitcher private static final Runnable sCheckProc = new Runnable() { - private final LocationHelper.LocationListener mLocationListener = new LocationHelper.LocationListener() + private final LocationHelper.LocationListener mLocationListener = new LocationHelper.SimpleLocationListener() { @Override public void onLocationUpdated(Location l) @@ -29,10 +29,6 @@ public final class ThemeSwitcher { LocationHelper.INSTANCE.removeLocationListener(this); } - - @Override - public void onCompassUpdated(long time, double magneticNorth, double trueNorth, double accuracy) - {} }; @Override