Add the ability to subscribe on wikivoyage saved articles updates
This commit is contained in:
parent
fcb5703db7
commit
c1b12a6724
1 changed files with 19 additions and 0 deletions
|
@ -25,6 +25,12 @@ public class WikivoyageLocalDataHelper {
|
|||
private TLongObjectHashMap<WikivoyageSearchHistoryItem> historyMap;
|
||||
private List<WikivoyageArticle> savedArticles;
|
||||
|
||||
private Listener listener;
|
||||
|
||||
public void setListener(Listener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
private WikivoyageLocalDataHelper(OsmandApplication app) {
|
||||
dbHelper = new WikivoyageLocalDataDbHelper(app);
|
||||
historyMap = dbHelper.getAllHistoryMap();
|
||||
|
@ -99,6 +105,7 @@ public class WikivoyageLocalDataHelper {
|
|||
saved.content = article.getPartialContent();
|
||||
savedArticles.add(saved);
|
||||
dbHelper.addSavedArticle(saved);
|
||||
notifySavedUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,6 +114,7 @@ public class WikivoyageLocalDataHelper {
|
|||
if (savedArticle != null) {
|
||||
savedArticles.remove(savedArticle);
|
||||
dbHelper.removeSavedArticle(savedArticle);
|
||||
notifySavedUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,6 +122,12 @@ public class WikivoyageLocalDataHelper {
|
|||
return getArticle(article.cityId, article.lang) != null;
|
||||
}
|
||||
|
||||
private void notifySavedUpdated() {
|
||||
if (listener != null) {
|
||||
listener.savedArticlesUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private WikivoyageArticle getArticle(long cityId, String lang) {
|
||||
for (WikivoyageArticle article : savedArticles) {
|
||||
|
@ -124,6 +138,11 @@ public class WikivoyageLocalDataHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
public interface Listener {
|
||||
|
||||
void savedArticlesUpdated();
|
||||
}
|
||||
|
||||
private static class WikivoyageLocalDataDbHelper {
|
||||
|
||||
private static final int DB_VERSION = 2;
|
||||
|
|
Loading…
Reference in a new issue