Merge pull request #1035 from Bars107/master

Added favourites updated event
This commit is contained in:
vshcherb 2015-01-12 15:33:13 +03:00
commit b94aa69b61
3 changed files with 38 additions and 7 deletions

View file

@ -30,6 +30,12 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
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);
public static final String FILE_TO_SAVE = "favourites.gpx"; //$NON-NLS-1$
@ -82,10 +88,25 @@ public class FavouritesDbHelper {
if(changed) {
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) {
boolean changed = false;

View file

@ -491,11 +491,6 @@ public class MainMenuActivity extends BaseDownloadActivity implements OsmAndLoca
if (f instanceof DashDownloadMapsFragment && !f.isDetached()) {
((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();
}
}
}

View file

@ -38,7 +38,7 @@ import android.widget.TextView;
/**
* 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";
private net.osmand.Location location = null;
private LatLon loc = null;
@ -92,10 +92,16 @@ public class DashFavoritesFragment extends DashBaseFragment {
} else {
loc = new LatLon(0f, 0f);
}
getMyApplication().getFavorites().addFavoritesUpdatedListener(this);
setupFavorites();
}
@Override
public void onPause() {
super.onPause();
getMyApplication().getFavorites().removeFavoritesUpdatedListener(this);
}
public void setupFavorites(){
View mainView = getView();
@ -250,4 +256,13 @@ public class DashFavoritesFragment extends DashBaseFragment {
updateArrows();
}
@Override
public void updateFavourites() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setupFavorites();
}
});
}
}