[new downloader][android] fix: Simple location listener.

This commit is contained in:
Alexander Marchuk 2016-02-05 18:38:46 +03:00 committed by Sergey Yershov
parent 9501304248
commit 8d61f1afe0
6 changed files with 51 additions and 56 deletions

View file

@ -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;

View file

@ -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<LocationListener> mListeners = new Listeners<>();
private boolean mActive;

View file

@ -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() {}

View file

@ -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;

View file

@ -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();

View file

@ -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