Fix #5517
This commit is contained in:
parent
00edc64b24
commit
af0ab94504
3 changed files with 35 additions and 7 deletions
|
@ -3,6 +3,7 @@ package net.osmand.plus.wikivoyage.data;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||||
|
@ -13,9 +14,11 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
public class TravelLocalDataHelper {
|
public class TravelLocalDataHelper {
|
||||||
|
@ -27,10 +30,14 @@ public class TravelLocalDataHelper {
|
||||||
private Map<String, WikivoyageSearchHistoryItem> historyMap = new HashMap<>();
|
private Map<String, WikivoyageSearchHistoryItem> historyMap = new HashMap<>();
|
||||||
private List<TravelArticle> savedArticles = new ArrayList<>();
|
private List<TravelArticle> savedArticles = new ArrayList<>();
|
||||||
|
|
||||||
private Listener listener;
|
private Set<Listener> listeners = new HashSet<>();
|
||||||
|
|
||||||
public void setListener(Listener listener) {
|
public void addListener(Listener listener) {
|
||||||
this.listener = listener;
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeListener(Listener listener) {
|
||||||
|
listeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
TravelLocalDataHelper(OsmandApplication app) {
|
TravelLocalDataHelper(OsmandApplication app) {
|
||||||
|
@ -139,7 +146,7 @@ public class TravelLocalDataHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifySavedUpdated() {
|
private void notifySavedUpdated() {
|
||||||
if (listener != null) {
|
for (Listener listener : listeners) {
|
||||||
listener.savedArticlesUpdated();
|
listener.savedArticlesUpdated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import net.osmand.plus.download.DownloadValidationManager;
|
||||||
import net.osmand.plus.download.IndexItem;
|
import net.osmand.plus.download.IndexItem;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
|
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.ArticleTravelCard;
|
||||||
import net.osmand.plus.wikivoyage.explore.travelcards.BaseTravelCard;
|
import net.osmand.plus.wikivoyage.explore.travelcards.BaseTravelCard;
|
||||||
import net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard;
|
import net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard;
|
||||||
|
@ -42,7 +43,7 @@ import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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";
|
private static final String WORLD_WIKIVOYAGE_FILE_NAME = "World_wikivoyage.sqlite";
|
||||||
|
|
||||||
|
@ -85,12 +86,25 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
OsmandApplication app = getMyApplication();
|
||||||
|
if (app != null) {
|
||||||
|
app.getTravelDbHelper().getLocalDataHelper().addListener(this);
|
||||||
|
}
|
||||||
WikivoyageExploreActivity exploreActivity = getExploreActivity();
|
WikivoyageExploreActivity exploreActivity = getExploreActivity();
|
||||||
if (exploreActivity != null) {
|
if (exploreActivity != null) {
|
||||||
exploreActivity.onTabFragmentResume(this);
|
exploreActivity.onTabFragmentResume(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
OsmandApplication app = getMyApplication();
|
||||||
|
if (app != null) {
|
||||||
|
app.getTravelDbHelper().getLocalDataHelper().removeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newDownloadIndexes() {
|
public void newDownloadIndexes() {
|
||||||
if (waitForIndexes) {
|
if (waitForIndexes) {
|
||||||
|
@ -130,6 +144,13 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void savedArticlesUpdated() {
|
||||||
|
if (adapter != null && isAdded()) {
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private WikivoyageExploreActivity getExploreActivity() {
|
private WikivoyageExploreActivity getExploreActivity() {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Trav
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (dataHelper != null) {
|
if (dataHelper != null) {
|
||||||
dataHelper.setListener(this);
|
dataHelper.addListener(this);
|
||||||
}
|
}
|
||||||
WikivoyageExploreActivity exploreActivity = getExploreActivity();
|
WikivoyageExploreActivity exploreActivity = getExploreActivity();
|
||||||
if (exploreActivity != null) {
|
if (exploreActivity != null) {
|
||||||
|
@ -77,7 +77,7 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Trav
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (dataHelper != null) {
|
if (dataHelper != null) {
|
||||||
dataHelper.setListener(null);
|
dataHelper.removeListener(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue