From 7944fc3a2b504b06796b095ad93e22ada12f36e5 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 22 Dec 2020 19:23:32 +0200 Subject: [PATCH 1/7] Fix Wikivoyage Card to suggest download maps --- .../net/osmand/plus/download/DownloadResources.java | 2 +- .../net/osmand/plus/wikipedia/WikiArticleHelper.java | 2 +- .../osmand/plus/wikivoyage/data/TravelDbHelper.java | 6 ++++++ .../osmand/plus/wikivoyage/data/TravelHelper.java | 2 ++ .../osmand/plus/wikivoyage/data/TravelObfHelper.java | 11 +++++++++-- .../plus/wikivoyage/explore/ExploreTabFragment.java | 12 +----------- .../explore/WikivoyageExploreActivity.java | 7 ++++++- 7 files changed, 26 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index 2bff73d7b2..b66ca9c467 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -80,7 +80,7 @@ public class DownloadResources extends DownloadResourceGroup { List items = getWikivoyageItems(); if (items != null) { for (IndexItem ii : items) { - if (ii.getFileName().equals(fileName)) { + if (ii.getTargetFile(app).getName().equals(fileName)) { return ii; } } diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java index 9caf70d5b9..b4f21895f4 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java @@ -301,7 +301,7 @@ public class WikiArticleHelper { return null; } String firstParagraphHtml = content.substring(firstParagraphStart, firstParagraphEnd + P_CLOSED.length()); - while (firstParagraphHtml.length() == (P_OPENED.length() + P_CLOSED.length()) + while (firstParagraphHtml.substring(P_OPENED.length(), firstParagraphHtml.length() - P_CLOSED.length()).trim().isEmpty() && (firstParagraphEnd + P_CLOSED.length()) < content.length()) { firstParagraphStart = content.indexOf(P_OPENED, firstParagraphEnd); firstParagraphEnd = firstParagraphStart == -1 ? -1 : content.indexOf(P_CLOSED, firstParagraphStart); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java index d50d05e42b..ef6dbd921e 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java @@ -46,6 +46,7 @@ public class TravelDbHelper implements TravelHelper { private static final Log LOG = PlatformUtil.getLog(TravelDbHelper.class); + private static final String WORLD_WIKIVOYAGE_FILE_NAME = "World_wikivoyage.sqlite"; private static final String ARTICLES_TABLE_NAME = "travel_articles"; private static final String POPULAR_TABLE_NAME = "popular_articles"; private static final String ARTICLES_POP_INDEX = "popularity_index"; @@ -185,6 +186,11 @@ public class TravelDbHelper implements TravelHelper { return null; } + @Override + public String getWikivoyageFileName() { + return WORLD_WIKIVOYAGE_FILE_NAME; + } + public List getExistingTravelBooks() { return existingTravelBooks; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java index b55c398817..d8112cee0c 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java @@ -49,4 +49,6 @@ public interface TravelHelper { // For TravelOBFHelper it could always return "" and should be no problem // Bookmarks should be refactored properly to support multiple files String getSelectedTravelBookName(); + + String getWikivoyageFileName(); } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index e1dc65ebfd..94d342ddc6 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -37,8 +37,10 @@ import static net.osmand.CollatorStringMatcher.StringMatcherMode.CHECK_EQUALS_FR public class TravelObfHelper implements TravelHelper { private static final Log LOG = PlatformUtil.getLog(TravelObfHelper.class); - public static final String ROUTE_ARTICLE = "route_article"; - public static final int SEARCH_RADIUS = 100000; + + private static final String WORLD_WIKIVOYAGE_FILE_NAME = "World_wikivoyage.travel.obf"; + private static final String ROUTE_ARTICLE = "route_article"; + private static final int SEARCH_RADIUS = 100000; private final OsmandApplication app; private final Collator collator; @@ -392,4 +394,9 @@ public class TravelObfHelper implements TravelHelper { public String getSelectedTravelBookName() { return ""; } + + @Override + public String getWikivoyageFileName() { + return WORLD_WIKIVOYAGE_FILE_NAME; + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java index 22310e4292..c53027fb7a 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java @@ -45,8 +45,6 @@ import java.util.List; public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEvents, TravelLocalDataHelper.Listener { - private static final String WORLD_WIKIVOYAGE_FILE_NAME = "World_wikivoyage.sqlite"; - private static boolean SHOW_TRAVEL_UPDATE_CARD = true; private static boolean SHOW_TRAVEL_NEEDED_MAPS_CARD = true; @@ -342,14 +340,6 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv return res.toArray(new IndexItem[0]); } - @NonNull - private String getWikivoyageFileName() { -// OsmandApplication app = getMyApplication(); -// File selectedTravelBook = app != null ? app.getTravelDbHelper().getSelectedTravelBook() : null; -// return selectedTravelBook == null ? WORLD_WIKIVOYAGE_FILE_NAME : selectedTravelBook.getName(); - return WORLD_WIKIVOYAGE_FILE_NAME; - } - private void removeDownloadUpdateCard() { if (adapter != null) { adapter.removeDownloadUpdateCard(); @@ -379,7 +369,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv ProcessIndexItemsTask(ExploreTabFragment fragment) { app = fragment.getMyApplication(); weakFragment = new WeakReference<>(fragment); - fileName = fragment.getWikivoyageFileName(); + fileName = app.getTravelHelper().getWikivoyageFileName(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreActivity.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreActivity.java index 45047e2e1c..a3522a8329 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreActivity.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreActivity.java @@ -61,6 +61,7 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv protected List> fragments = new ArrayList<>(); private LockableViewPager viewPager; + private boolean finishDownloading = false; @Override public void onCreate(Bundle savedInstanceState) { @@ -313,10 +314,12 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv public void populateData() { switchProgressBarVisibility(true); + finishDownloading = false; new LoadWikivoyageData(this).execute(); } private void onDataLoaded() { + finishDownloading = true; switchProgressBarVisibility(false); updateSearchBarVisibility(); updateFragments(); @@ -353,7 +356,9 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv } public void onTabFragmentResume(Fragment fragment) { - updateFragments(); + if(finishDownloading) { + updateFragments(); + } } @Override From 777d93f69612a4057ca16feba3a49ea13651f827 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 28 Dec 2020 13:27:16 +0200 Subject: [PATCH 2/7] Add logs for index item update --- .../plus/download/DownloadResources.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index 2bff73d7b2..c8951b29f7 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -8,9 +8,9 @@ import net.osmand.PlatformUtil; import net.osmand.data.LatLon; import net.osmand.map.OsmandRegions; import net.osmand.map.WorldRegion; +import net.osmand.plus.CustomRegion; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.CustomRegion; import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem; import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.util.Algorithms; @@ -21,6 +21,7 @@ import java.io.File; import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; +import java.text.DateFormat; import java.text.ParseException; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -177,6 +178,8 @@ public class DownloadResources extends DownloadResourceGroup { } } if (date != null && !date.equals(indexActivatedDate) && !date.equals(indexFilesDate)) { + long oldItemSize = 0; + long itemSize = item.getContentSize(); if ((item.getType() == DownloadActivityType.NORMAL_FILE && !item.extra) || item.getType() == DownloadActivityType.ROADS_FILE || item.getType() == DownloadActivityType.WIKIPEDIA_FILE @@ -185,15 +188,12 @@ public class DownloadResources extends DownloadResourceGroup { outdated = true; } else if (item.getType() == DownloadActivityType.WIKIVOYAGE_FILE || item.getType() == DownloadActivityType.TRAVEL_FILE) { - long itemSize = item.getContentSize(); - long oldItemSize = app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR + + oldItemSize = app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR + item.getTargetFileName()).length(); if (itemSize != oldItemSize) { outdated = true; } } else { - long itemSize = item.getContentSize(); - long oldItemSize = 0; if (parsed && item.getTimestamp() > item.getLocalTimestamp()) { outdated = true; } else if (item.getType() == DownloadActivityType.VOICE_FILE) { @@ -223,12 +223,23 @@ public class DownloadResources extends DownloadResourceGroup { outdated = true; } } + if (outdated) { + logItemUpdateInfo(item, format, itemSize, oldItemSize); + } } item.setOutdated(outdated); return outdated; } - + private void logItemUpdateInfo(IndexItem item, DateFormat format, long itemSize, long oldItemSize) { + String date = item.getDate(format); + String sfName = item.getTargetFileName(); + String indexActivatedDate = indexActivatedFileNames.get(sfName); + String indexFilesDate = indexFileNames.get(sfName); + LOG.info("timestamp " + item.timestamp + " localTimestamp " + item.localTimestamp + " date " + date + + " indexActivatedDate " + indexActivatedDate + " indexFilesDate " + indexFilesDate + + " itemSize " + itemSize + " oldItemSize " + oldItemSize); + } protected void updateFilesToUpdate() { initAlreadyLoadedFiles(); From 144f812f40dfc8c8b9075f0d5776361f17dcafa1 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 28 Dec 2020 17:14:18 +0200 Subject: [PATCH 3/7] Fix review --- .../osmand/plus/wikivoyage/explore/ExploreRvAdapter.java | 1 + .../plus/wikivoyage/explore/WikivoyageExploreActivity.java | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java index 29951db19a..c0ab357e0c 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java @@ -182,6 +182,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter> fragments = new ArrayList<>(); private LockableViewPager viewPager; - private boolean finishDownloading = false; @Override public void onCreate(Bundle savedInstanceState) { @@ -314,12 +313,10 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv public void populateData() { switchProgressBarVisibility(true); - finishDownloading = false; new LoadWikivoyageData(this).execute(); } private void onDataLoaded() { - finishDownloading = true; switchProgressBarVisibility(false); updateSearchBarVisibility(); updateFragments(); @@ -356,9 +353,7 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv } public void onTabFragmentResume(Fragment fragment) { - if(finishDownloading) { - updateFragments(); - } + updateFragments(); } @Override From 75afb2b2270204e30ed30f1a1f034eeda808d119 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 29 Dec 2020 10:17:41 +0200 Subject: [PATCH 4/7] Fix review --- .../src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java | 1 - .../plus/wikivoyage/explore/WikivoyageExploreActivity.java | 1 - 2 files changed, 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java index c0ab357e0c..29951db19a 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java @@ -182,7 +182,6 @@ public class ExploreRvAdapter extends RecyclerView.Adapter Date: Tue, 29 Dec 2020 10:36:20 +0200 Subject: [PATCH 5/7] Add file name --- OsmAnd/src/net/osmand/plus/download/DownloadResources.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index c8951b29f7..648d3d3a00 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -236,7 +236,7 @@ public class DownloadResources extends DownloadResourceGroup { String sfName = item.getTargetFileName(); String indexActivatedDate = indexActivatedFileNames.get(sfName); String indexFilesDate = indexFileNames.get(sfName); - LOG.info("timestamp " + item.timestamp + " localTimestamp " + item.localTimestamp + " date " + date + LOG.info("name " + item.getFileName() + " timestamp " + item.timestamp + " localTimestamp " + item.localTimestamp + " date " + date + " indexActivatedDate " + indexActivatedDate + " indexFilesDate " + indexFilesDate + " itemSize " + itemSize + " oldItemSize " + oldItemSize); } From 8716d49a25a1aa3efc008d744e114d80beb5ed20 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 29 Dec 2020 11:16:11 +0200 Subject: [PATCH 6/7] Fix ExploreRvAdapter --- .../osmand/plus/wikivoyage/explore/ExploreRvAdapter.java | 8 ++++++-- .../wikivoyage/explore/WikivoyageExploreActivity.java | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java index 29951db19a..a95614bdb8 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java @@ -142,7 +142,9 @@ public class ExploreRvAdapter extends RecyclerView.Adapter Date: Tue, 29 Dec 2020 11:49:02 +0200 Subject: [PATCH 7/7] change default settings for the "Close changeset" switch --- .../dialogs/SendPoiBottomSheetFragment.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java index a715c33354..21b61d1fe3 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java @@ -72,20 +72,13 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { String userNameOpenID = settings.USER_NAME.get(); String userName = isLoginOAuth(settings) ? userNameOAuth : userNameOpenID; accountName.setText(userName); - closeChangeSet.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg); final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small); - closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0); + closeChangeSet.setChecked(true); + setCloseChangeSet(isNightMode, paddingSmall); closeChangeSet.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isNightMode) { - closeChangeSet.setBackgroundResource( - isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); - } else { - closeChangeSet.setBackgroundResource( - isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg); - } - closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0); + setCloseChangeSet(isNightMode, paddingSmall); } }); LinearLayout account = sendOsmPoiView.findViewById(R.id.account_container); @@ -254,5 +247,16 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { } return comment; } + + private void setCloseChangeSet(boolean isNightMode, int paddingSmall) { + if (isNightMode) { + closeChangeSet.setBackgroundResource( + closeChangeSet.isChecked() ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark); + } else { + closeChangeSet.setBackgroundResource( + closeChangeSet.isChecked() ? R.drawable.layout_bg_solid : R.drawable.layout_bg); + } + closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0); + } }