diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java index 45af086fa5..775a27ff49 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java @@ -3,6 +3,7 @@ package net.osmand.plus.wikivoyage.data; import android.support.annotation.NonNull; import android.support.annotation.Nullable; + import net.osmand.plus.OsmandApplication; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; @@ -13,9 +14,11 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; public class TravelLocalDataHelper { @@ -27,10 +30,14 @@ public class TravelLocalDataHelper { private Map historyMap = new HashMap<>(); private List savedArticles = new ArrayList<>(); - private Listener listener; + private Set listeners = new HashSet<>(); - public void setListener(Listener listener) { - this.listener = listener; + public void addListener(Listener listener) { + listeners.add(listener); + } + + public void removeListener(Listener listener) { + listeners.remove(listener); } TravelLocalDataHelper(OsmandApplication app) { @@ -139,7 +146,7 @@ public class TravelLocalDataHelper { } private void notifySavedUpdated() { - if (listener != null) { + for (Listener listener : listeners) { listener.savedArticlesUpdated(); } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java index 7f4ac20953..4559c44f28 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java @@ -28,6 +28,7 @@ import net.osmand.plus.download.DownloadValidationManager; import net.osmand.plus.download.IndexItem; import net.osmand.plus.wikivoyage.data.TravelArticle; import net.osmand.plus.wikivoyage.data.TravelDbHelper; +import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; import net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard; import net.osmand.plus.wikivoyage.explore.travelcards.BaseTravelCard; import net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard; @@ -42,7 +43,7 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEvents { +public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEvents, TravelLocalDataHelper.Listener { private static final String WORLD_WIKIVOYAGE_FILE_NAME = "World_wikivoyage.sqlite"; @@ -85,12 +86,25 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv @Override public void onResume() { super.onResume(); + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getTravelDbHelper().getLocalDataHelper().addListener(this); + } WikivoyageExploreActivity exploreActivity = getExploreActivity(); if (exploreActivity != null) { exploreActivity.onTabFragmentResume(this); } } + @Override + public void onPause() { + super.onPause(); + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getTravelDbHelper().getLocalDataHelper().removeListener(this); + } + } + @Override public void newDownloadIndexes() { if (waitForIndexes) { @@ -130,6 +144,13 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv } } + @Override + public void savedArticlesUpdated() { + if (adapter != null && isAdded()) { + adapter.notifyDataSetChanged(); + } + } + @Nullable private WikivoyageExploreActivity getExploreActivity() { Activity activity = getActivity(); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesTabFragment.java index dd52004994..259b48669f 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesTabFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesTabFragment.java @@ -65,7 +65,7 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Trav public void onResume() { super.onResume(); if (dataHelper != null) { - dataHelper.setListener(this); + dataHelper.addListener(this); } WikivoyageExploreActivity exploreActivity = getExploreActivity(); if (exploreActivity != null) { @@ -77,7 +77,7 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Trav public void onPause() { super.onPause(); if (dataHelper != null) { - dataHelper.setListener(null); + dataHelper.removeListener(this); } }