diff --git a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java index 7bd2c89e05..dd3800b4b0 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java @@ -41,6 +41,7 @@ public class FavoritesActivity extends TabActivity { // private static final String SELECTED_TRACK = "SELECTED_TRACK"; public static String TAB_PARAM = "TAB_PARAM"; protected List> fragList = new ArrayList>(); + private int tabSize; @Override public void onCreate(Bundle icicle) { @@ -49,6 +50,33 @@ public class FavoritesActivity extends TabActivity { getSupportActionBar().setTitle(R.string.shared_string_my_places); getSupportActionBar().setElevation(0); + + setContentView(R.layout.tab_content); + List mTabs = getTabItems(); + setTabs(mTabs); + // setupHomeButton(); + } + + + + private void setTabs(List mTabs) { + PagerSlidingTabStrip mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tabs); + OsmandSettings settings = ((OsmandApplication) getApplication()).getSettings(); + ViewPager mViewPager = (ViewPager) findViewById(R.id.pager); + Integer tabId = settings.FAVORITES_TAB.get(); + int tab = 0; + for(int i = 0; i < mTabs.size(); i++) { + if(mTabs.get(i).resId == tabId) { + tab = i; + } + } + tabSize = mTabs.size(); + setViewPagerAdapter(mViewPager, mTabs); + mSlidingTabLayout.setViewPager(mViewPager); + mViewPager.setCurrentItem(tab); + } + + private List getTabItems() { File[] lf = ((OsmandApplication) getApplication()).getAppPath(TRACKS).listFiles(); boolean hasGpx = false; if (lf != null) { @@ -60,30 +88,13 @@ public class FavoritesActivity extends TabActivity { } } - setContentView(R.layout.tab_content); - - PagerSlidingTabStrip mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tabs); - OsmandSettings settings = ((OsmandApplication) getApplication()).getSettings(); - - ViewPager mViewPager = (ViewPager) findViewById(R.id.pager); - List mTabs = new ArrayList(); mTabs.add(getTabIndicator(R.string.shared_string_my_favorites, FavoritesTreeFragment.class)); if (hasGpx) { mTabs.add(getTabIndicator(R.string.shared_string_my_tracks, AvailableGPXFragment.class)); } OsmandPlugin.addMyPlacesTabPlugins(this, mTabs, getIntent()); - Integer tabId = settings.FAVORITES_TAB.get(); - int tab = 0; - for(int i = 0; i < mTabs.size(); i++) { - if(mTabs.get(i).resId == tabId) { - tab = i; - } - } - setViewPagerAdapter(mViewPager, mTabs); - mSlidingTabLayout.setViewPager(mViewPager); - mViewPager.setCurrentItem(tab); - // setupHomeButton(); + return mTabs; } @Override @@ -94,7 +105,10 @@ public class FavoritesActivity extends TabActivity { @Override protected void onResume() { super.onResume(); - + List mTabs = getTabItems(); + if(mTabs.size() != tabSize ) { + setTabs(mTabs); + } } public OsmandApplication getMyApplication() { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsDbHelper.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsDbHelper.java index d3ae3afb72..c2a84f8256 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsDbHelper.java @@ -39,7 +39,10 @@ public class OsmBugsDbHelper extends SQLiteOpenHelper { public List getOsmbugsPoints() { if (cache == null) { - return checkOsmbugsPoints(); + SQLiteDatabase db = getReadableDatabase(); + List res = checkOsmbugsPoints(db); + db.close(); + return res; } return cache; } @@ -52,8 +55,8 @@ public class OsmBugsDbHelper extends SQLiteOpenHelper { + OSMBUGS_COL_LON + "," + OSMBUGS_COL_ACTION + "," + OSMBUGS_COL_AUTHOR + ")" + " VALUES (?, ?, ?, ?, ?, ?)", new Object[] { p.getId(), p.getText(), p.getLatitude(), p.getLongitude(), OsmPoint.stringAction.get(p.getAction()), p.getAuthor() }); //$NON-NLS-1$ //$NON-NLS-2$ + checkOsmbugsPoints(db); db.close(); - checkOsmbugsPoints(); return true; } return false; @@ -64,15 +67,14 @@ public class OsmBugsDbHelper extends SQLiteOpenHelper { if (db != null) { db.execSQL("DELETE FROM " + OSMBUGS_TABLE_NAME + " WHERE " + OSMBUGS_COL_ID + " = ?", new Object[] { p.getId() }); //$NON-NLS-1$ //$NON-NLS-2$ + checkOsmbugsPoints(db); db.close(); - checkOsmbugsPoints(); return true; } return false; } - private List checkOsmbugsPoints(){ - SQLiteDatabase db = getReadableDatabase(); + private List checkOsmbugsPoints(SQLiteDatabase db){ List cachedOsmbugsPoints = new ArrayList(); if (db != null) { Cursor query = db.rawQuery("SELECT " + OSMBUGS_COL_ID + ", " + OSMBUGS_COL_TEXT + ", " + OSMBUGS_COL_LAT + "," + OSMBUGS_COL_LON + "," + OSMBUGS_COL_ACTION + "," + OSMBUGS_COL_AUTHOR + " FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ @@ -92,9 +94,8 @@ public class OsmBugsDbHelper extends SQLiteOpenHelper { } while (query.moveToNext()); } query.close(); - db.close(); + cache = cachedOsmbugsPoints; } - cache = cachedOsmbugsPoints; return cachedOsmbugsPoints; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java index cd2bb2e22c..b00b996fe3 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java @@ -77,7 +77,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider public OsmBugsLayer(MapActivity activity, OsmEditingPlugin plugin){ this.activity = activity; this.plugin = plugin; - local = new OsmBugsLocalUtil(activity); + local = new OsmBugsLocalUtil(activity, plugin.getDBBug()); remote = new OsmBugsRemoteUtil(activity.getMyApplication()); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLocalUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLocalUtil.java index c412b291b7..54426c90ae 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLocalUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLocalUtil.java @@ -12,9 +12,9 @@ public class OsmBugsLocalUtil implements OsmBugsUtil { private final Context ctx; private final OsmBugsDbHelper db; - public OsmBugsLocalUtil(Context uiContext) { + public OsmBugsLocalUtil(Context uiContext, OsmBugsDbHelper db) { this.ctx = uiContext; - this.db = new OsmBugsDbHelper(ctx); + this.db = db; } @Override diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index f86277070c..15071e291d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -371,6 +371,7 @@ public class OsmEditsFragment extends OsmAndListFragment { public OsmEditsAdapter(List points) { super(getActivity(), net.osmand.plus.R.layout.note, points); + dataPoints = points; } public void setNewList(List dp) {