Added favourites updated event
This commit is contained in:
parent
de522efd0f
commit
9c8aa3300c
3 changed files with 33 additions and 7 deletions
|
@ -30,6 +30,12 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||||
|
|
||||||
public class FavouritesDbHelper {
|
public class FavouritesDbHelper {
|
||||||
|
|
||||||
|
public interface FavoritesUpdatedListener {
|
||||||
|
void updateFavourites();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<FavoritesUpdatedListener> favoritesUpdatedListeners = new ArrayList<FavoritesUpdatedListener>();
|
||||||
|
|
||||||
private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(FavouritesDbHelper.class);
|
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$
|
public static final String FILE_TO_SAVE = "favourites.gpx"; //$NON-NLS-1$
|
||||||
|
@ -82,10 +88,25 @@ public class FavouritesDbHelper {
|
||||||
if(changed) {
|
if(changed) {
|
||||||
saveCurrentPointsIntoFile();
|
saveCurrentPointsIntoFile();
|
||||||
}
|
}
|
||||||
|
favouritesUpdated();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void favouritesUpdated(){
|
||||||
|
for (FavoritesUpdatedListener listener : favoritesUpdatedListeners){
|
||||||
|
listener.updateFavourites();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFavoritesUpdatedListener(FavoritesUpdatedListener listener){
|
||||||
|
if (!favoritesUpdatedListeners.contains(listener)){
|
||||||
|
favoritesUpdatedListeners.add(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeFavoritesUpdatedListener(FavoritesUpdatedListener listener){
|
||||||
|
favoritesUpdatedListeners.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean merge(Map<String, FavouritePoint> source, Map<String, FavouritePoint> destination) {
|
private boolean merge(Map<String, FavouritePoint> source, Map<String, FavouritePoint> destination) {
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
|
|
@ -491,11 +491,6 @@ public class MainMenuActivity extends BaseDownloadActivity implements OsmAndLoca
|
||||||
if (f instanceof DashDownloadMapsFragment && !f.isDetached()) {
|
if (f instanceof DashDownloadMapsFragment && !f.isDetached()) {
|
||||||
((DashDownloadMapsFragment) f).refreshData();
|
((DashDownloadMapsFragment) f).refreshData();
|
||||||
}
|
}
|
||||||
//Needed to reliably initialize DashFavoritesFragement on devices without compass
|
|
||||||
// [Victor]: This doesn't look as a proper place, then it highly depends on internet connection and download list
|
|
||||||
if (f instanceof DashFavoritesFragment && !f.isDetached()) {
|
|
||||||
((DashFavoritesFragment) f).setupFavorites();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ import android.widget.TextView;
|
||||||
/**
|
/**
|
||||||
* Created by Denis on 24.11.2014.
|
* Created by Denis on 24.11.2014.
|
||||||
*/
|
*/
|
||||||
public class DashFavoritesFragment extends DashBaseFragment {
|
public class DashFavoritesFragment extends DashBaseFragment implements FavouritesDbHelper.FavoritesUpdatedListener {
|
||||||
public static final String TAG = "DASH_FAVORITES_FRAGMENT";
|
public static final String TAG = "DASH_FAVORITES_FRAGMENT";
|
||||||
private net.osmand.Location location = null;
|
private net.osmand.Location location = null;
|
||||||
private LatLon loc = null;
|
private LatLon loc = null;
|
||||||
|
@ -92,10 +92,16 @@ public class DashFavoritesFragment extends DashBaseFragment {
|
||||||
} else {
|
} else {
|
||||||
loc = new LatLon(0f, 0f);
|
loc = new LatLon(0f, 0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMyApplication().getFavorites().addFavoritesUpdatedListener(this);
|
||||||
setupFavorites();
|
setupFavorites();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
getMyApplication().getFavorites().removeFavoritesUpdatedListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
public void setupFavorites(){
|
public void setupFavorites(){
|
||||||
View mainView = getView();
|
View mainView = getView();
|
||||||
|
@ -250,4 +256,8 @@ public class DashFavoritesFragment extends DashBaseFragment {
|
||||||
updateArrows();
|
updateArrows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateFavourites() {
|
||||||
|
setupFavorites();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue