Merge pull request #6158 from osmandapp/startup_time
Improve startup time
This commit is contained in:
commit
3714fcb65b
8 changed files with 134 additions and 22 deletions
|
@ -626,19 +626,23 @@ public class AppInitializer implements IProgress {
|
|||
private void startApplicationBackground() {
|
||||
try {
|
||||
startBgTime = System.currentTimeMillis();
|
||||
app.favorites.loadFavorites();
|
||||
notifyEvent(InitEvents.FAVORITES_INITIALIZED);
|
||||
app.getRendererRegistry().initRenderers(this);
|
||||
notifyEvent(InitEvents.INIT_RENDERERS);
|
||||
// native depends on renderers
|
||||
initOpenGl();
|
||||
notifyEvent(InitEvents.NATIVE_OPEN_GLINITIALIZED);
|
||||
|
||||
// init poi types before indexes and before POI
|
||||
initPoiTypes();
|
||||
notifyEvent(InitEvents.POI_TYPES_INITIALIZED);
|
||||
app.resourceManager.reloadIndexesOnStart(this, warnings);
|
||||
|
||||
app.getRendererRegistry().initRenderers(this);
|
||||
notifyEvent(InitEvents.INIT_RENDERERS);
|
||||
// native depends on renderers
|
||||
initNativeCore();
|
||||
notifyEvent(InitEvents.NATIVE_INITIALIZED);
|
||||
|
||||
app.favorites.loadFavorites();
|
||||
notifyEvent(InitEvents.FAVORITES_INITIALIZED);
|
||||
app.poiFilters.reloadAllPoiFilters();
|
||||
app.poiFilters.loadSelectedPoiFilters();
|
||||
notifyEvent(InitEvents.POI_TYPES_INITIALIZED);
|
||||
|
@ -735,8 +739,7 @@ public class AppInitializer implements IProgress {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void initNativeCore() {
|
||||
private void initOpenGl() {
|
||||
if (!"qnx".equals(System.getProperty("os.name"))) {
|
||||
OsmandSettings osmandSettings = app.getSettings();
|
||||
if (osmandSettings.USE_OPENGL_RENDER.get()) {
|
||||
|
@ -754,6 +757,12 @@ public class AppInitializer implements IProgress {
|
|||
warnings.add("Native OpenGL library is not supported. Please try again after exit");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initNativeCore() {
|
||||
if (!"qnx".equals(System.getProperty("os.name"))) {
|
||||
OsmandSettings osmandSettings = app.getSettings();
|
||||
if (osmandSettings.NATIVE_RENDERING_FAILED.get()) {
|
||||
osmandSettings.SAFE_MODE.set(true);
|
||||
osmandSettings.NATIVE_RENDERING_FAILED.set(false);
|
||||
|
|
|
@ -31,11 +31,10 @@ import java.util.Set;
|
|||
|
||||
public class FavouritesDbHelper {
|
||||
|
||||
public interface FavoritesUpdatedListener {
|
||||
void updateFavourites();
|
||||
public interface FavoritesListener {
|
||||
void onFavoritesLoaded();
|
||||
}
|
||||
|
||||
|
||||
private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(FavouritesDbHelper.class);
|
||||
|
||||
public static final String FILE_TO_SAVE = "favourites.gpx"; //$NON-NLS-1$
|
||||
|
@ -50,6 +49,8 @@ public class FavouritesDbHelper {
|
|||
protected static final String HIDDEN = "HIDDEN";
|
||||
private static final String DELIMETER = "__";
|
||||
|
||||
private Set<FavoritesListener> listeners = new HashSet<>();
|
||||
private boolean favoritesLoaded;
|
||||
|
||||
public FavouritesDbHelper(OsmandApplication context) {
|
||||
this.context = context;
|
||||
|
@ -90,13 +91,28 @@ public class FavouritesDbHelper {
|
|||
if (changed || !getExternalFile().exists()) {
|
||||
saveCurrentPointsIntoFile();
|
||||
}
|
||||
favouritesUpdated();
|
||||
|
||||
favoritesLoaded = true;
|
||||
context.runInUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (FavoritesListener listener : listeners) {
|
||||
listener.onFavoritesLoaded();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void favouritesUpdated() {
|
||||
public boolean isFavoritesLoaded() {
|
||||
return favoritesLoaded;
|
||||
}
|
||||
|
||||
public void addListener(FavoritesListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(FavoritesListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
private boolean merge(Map<String, FavouritePoint> source, Map<String, FavouritePoint> destination) {
|
||||
boolean changed = false;
|
||||
|
|
|
@ -37,8 +37,8 @@ import net.osmand.data.LatLon;
|
|||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoritesListener;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
|
@ -90,13 +90,24 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
private HashMap<String, OsmandSettings.OsmandPreference<Boolean>> preferenceCache = new HashMap<>();
|
||||
private View footerView;
|
||||
|
||||
private FavoritesListener favoritesListener;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
this.app = (OsmandApplication) getActivity().getApplication();
|
||||
|
||||
helper = getMyApplication().getFavorites();
|
||||
favouritesAdapter.synchronizeGroups();
|
||||
if (helper.isFavoritesLoaded()) {
|
||||
favouritesAdapter.synchronizeGroups();
|
||||
} else {
|
||||
helper.addListener(favoritesListener = new FavoritesListener() {
|
||||
@Override
|
||||
public void onFavoritesLoaded() {
|
||||
favouritesAdapter.synchronizeGroups();
|
||||
}
|
||||
});
|
||||
}
|
||||
setAdapter(favouritesAdapter);
|
||||
|
||||
boolean light = getMyApplication().getSettings().isLightContent();
|
||||
|
@ -233,6 +244,10 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
if (actionMode != null) {
|
||||
actionMode.finish();
|
||||
}
|
||||
if (favoritesListener != null) {
|
||||
helper.removeListener(favoritesListener);
|
||||
favoritesListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
private int getSelectedFavoritesCount() {
|
||||
|
|
|
@ -373,7 +373,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
if (tn != null) {
|
||||
((TextView) findViewById(R.id.ProgressMessage)).setText(tn);
|
||||
}
|
||||
if (event == InitEvents.NATIVE_INITIALIZED) {
|
||||
boolean openGlInitialized = event == InitEvents.NATIVE_OPEN_GLINITIALIZED && NativeCoreContext.isInit();
|
||||
if ((openGlInitialized || event == InitEvents.NATIVE_INITIALIZED) && !openGlSetup) {
|
||||
setupOpenGLView(false);
|
||||
openGlSetup = true;
|
||||
}
|
||||
|
@ -386,6 +387,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
app.getTargetPointsHelper().lookupAddessAll();
|
||||
app.getMapMarkersHelper().lookupAddressAll();
|
||||
}
|
||||
if (event == InitEvents.FAVORITES_INITIALIZED) {
|
||||
refreshMap();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,6 +14,7 @@ import net.osmand.data.FavouritePoint;
|
|||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoritesListener;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
|
@ -47,6 +48,8 @@ public class DashFavoritesFragment extends DashLocationFragment {
|
|||
public static final DashFragmentData FRAGMENT_DATA =
|
||||
new DashFragmentData(TAG, DashFavoritesFragment.class, SHOULD_SHOW_FUNCTION, 90, ROW_NUMBER_TAG);
|
||||
|
||||
private FavoritesListener favoritesListener;
|
||||
|
||||
@Override
|
||||
public View initView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_common_fragment, container, false);
|
||||
|
@ -62,7 +65,26 @@ public class DashFavoritesFragment extends DashLocationFragment {
|
|||
|
||||
@Override
|
||||
public void onOpenDash() {
|
||||
setupFavorites();
|
||||
FavouritesDbHelper helper = getMyApplication().getFavorites();
|
||||
if (helper.isFavoritesLoaded()) {
|
||||
setupFavorites();
|
||||
} else {
|
||||
helper.addListener(favoritesListener = new FavoritesListener() {
|
||||
@Override
|
||||
public void onFavoritesLoaded() {
|
||||
setupFavorites();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCloseDash() {
|
||||
super.onCloseDash();
|
||||
if (favoritesListener != null) {
|
||||
getMyApplication().getFavorites().removeListener(favoritesListener);
|
||||
favoritesListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setupFavorites() {
|
||||
|
|
|
@ -12,6 +12,8 @@ import net.osmand.AndroidUtils;
|
|||
import net.osmand.Location;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoritesListener;
|
||||
import net.osmand.plus.OsmAndLocationProvider;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -23,6 +25,7 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemTitleWithDescrAndButt
|
|||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
@ -36,7 +39,7 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
private static final String IS_SORTED = "sorted";
|
||||
private static final String SORTED_BY_TYPE = "sortedByType";
|
||||
|
||||
private List<FavouritePoint> favouritePoints;
|
||||
private List<FavouritePoint> favouritePoints = new ArrayList<>();
|
||||
private FavouritesAdapter adapter;
|
||||
private RecyclerView recyclerView;
|
||||
private boolean sortByDist = true;
|
||||
|
@ -47,6 +50,8 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
private boolean intermediate;
|
||||
private float lastHeading;
|
||||
|
||||
private FavoritesListener favoritesListener;
|
||||
|
||||
@Override
|
||||
public void createMenuItems(final Bundle savedInstanceState) {
|
||||
Bundle args = getArguments();
|
||||
|
@ -57,16 +62,24 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
if (savedInstanceState != null && savedInstanceState.getBoolean(IS_SORTED)) {
|
||||
sortByDist = savedInstanceState.getBoolean(SORTED_BY_TYPE);
|
||||
}
|
||||
favouritePoints = getMyApplication().getFavorites().getVisibleFavouritePoints();
|
||||
if (favouritePoints.isEmpty()) {
|
||||
favouritePoints = getMyApplication().getFavorites().getFavouritePoints();
|
||||
adapter = new FavouritesAdapter(getMyApplication(), favouritePoints);
|
||||
FavouritesDbHelper helper = getMyApplication().getFavorites();
|
||||
if (helper.isFavoritesLoaded()) {
|
||||
loadFavorites();
|
||||
} else {
|
||||
helper.addListener(favoritesListener = new FavoritesListener() {
|
||||
@Override
|
||||
public void onFavoritesLoaded() {
|
||||
loadFavorites();
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
recyclerView = new RecyclerView(getContext());
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
recyclerView = (RecyclerView) View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
||||
R.layout.recyclerview, null);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
adapter = new FavouritesAdapter(getMyApplication(), favouritePoints);
|
||||
sortFavourites();
|
||||
final BottomSheetItemTitleWithDescrAndButton[] title = new BottomSheetItemTitleWithDescrAndButton[1];
|
||||
title[0] = (BottomSheetItemTitleWithDescrAndButton) new BottomSheetItemTitleWithDescrAndButton.Builder()
|
||||
|
@ -110,6 +123,14 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
.create());
|
||||
}
|
||||
|
||||
private void loadFavorites() {
|
||||
favouritePoints.clear();
|
||||
favouritePoints.addAll(getMyApplication().getFavorites().getVisibleFavouritePoints());
|
||||
if (favouritePoints.isEmpty()) {
|
||||
favouritePoints.addAll(getMyApplication().getFavorites().getFavouritePoints());
|
||||
}
|
||||
}
|
||||
|
||||
private Drawable getIconForButton() {
|
||||
return getIcon(sortByDist ? R.drawable.ic_action_list_sort : R.drawable.ic_action_sort_by_name,
|
||||
nightMode ? R.color.multi_selection_menu_close_btn_dark : R.color.multi_selection_menu_close_btn_light);
|
||||
|
@ -170,6 +191,10 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
super.onPause();
|
||||
stopLocationUpdate();
|
||||
setupMapRouteInfoMenuSpinners(getMapRouteInfoMenu());
|
||||
if (favoritesListener != null) {
|
||||
getMyApplication().getFavorites().removeListener(favoritesListener);
|
||||
favoritesListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,12 +4,14 @@ import android.os.Bundle;
|
|||
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoritesListener;
|
||||
import net.osmand.plus.mapmarkers.adapters.FavouritesGroupsAdapter;
|
||||
import net.osmand.plus.mapmarkers.adapters.GroupsAdapter;
|
||||
|
||||
public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomSheetDialogFragment {
|
||||
|
||||
private FavouritesDbHelper favouritesDbHelper;
|
||||
private FavoritesListener favoritesListener;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -17,8 +19,27 @@ public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomS
|
|||
favouritesDbHelper = getMyApplication().getFavorites();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if (favoritesListener != null) {
|
||||
favouritesDbHelper.removeListener(favoritesListener);
|
||||
favoritesListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupsAdapter createAdapter() {
|
||||
if (!favouritesDbHelper.isFavoritesLoaded()) {
|
||||
favouritesDbHelper.addListener(favoritesListener = new FavoritesListener() {
|
||||
@Override
|
||||
public void onFavoritesLoaded() {
|
||||
if (adapter != null) {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return new FavouritesGroupsAdapter(getContext(), favouritesDbHelper.getFavoriteGroups());
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
@Override
|
||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||
cache.clear();
|
||||
if (this.settings.SHOW_FAVORITES.get()) {
|
||||
if (this.settings.SHOW_FAVORITES.get() && favorites.isFavoritesLoaded()) {
|
||||
if (tileBox.getZoom() >= startZoom) {
|
||||
float iconSize = FavoriteImageDrawable.getOrCreate(view.getContext(), 0,
|
||||
true).getIntrinsicWidth() * 3 / 2.5f;
|
||||
|
|
Loading…
Reference in a new issue