From 9cf86aae5748b67c14c73f5bfb4dcc3b064f6f5d Mon Sep 17 00:00:00 2001 From: ENT8R Date: Thu, 23 Nov 2017 17:22:13 +0100 Subject: [PATCH 1/6] Add the option to flush the quest cache --- .../java/de/westnordost/streetcomplete/Prefs.java | 3 ++- .../streetcomplete/data/AQuestDao.java | 6 ++++++ .../streetcomplete/settings/SettingsFragment.java | 15 +++++++++++++++ .../main/res/drawable/ic_delete_black_24dp.xml | 9 +++++++++ app/src/main/res/layout/widget_image_delete.xml | 6 ++++++ app/src/main/res/values/strings.xml | 3 +++ app/src/main/res/xml/preferences.xml | 7 +++++++ 7 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/ic_delete_black_24dp.xml create mode 100644 app/src/main/res/layout/widget_image_delete.xml diff --git a/app/src/main/java/de/westnordost/streetcomplete/Prefs.java b/app/src/main/java/de/westnordost/streetcomplete/Prefs.java index b4351a775e..f4af7e9017 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/Prefs.java +++ b/app/src/main/java/de/westnordost/streetcomplete/Prefs.java @@ -18,7 +18,8 @@ public class Prefs // not shown anywhere directly public static final String - QUEST_ORDER = "quests.order"; + QUEST_ORDER = "quests.order", + QUEST_DELETION = "quests.deletion"; public enum Autosync { diff --git a/app/src/main/java/de/westnordost/streetcomplete/data/AQuestDao.java b/app/src/main/java/de/westnordost/streetcomplete/data/AQuestDao.java index d05ffb4caf..fb95d1a79b 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/data/AQuestDao.java +++ b/app/src/main/java/de/westnordost/streetcomplete/data/AQuestDao.java @@ -216,6 +216,12 @@ private int insertAll(Collection quests, boolean replace) return addRows; } + public void clear() + { + SQLiteDatabase db = dbHelper.getReadableDatabase(); + db.execSQL("DELETE FROM " + getTableName()); + } + /** Add given quest to DB and sets the quest's id after inserting it * @return true if successfully inserted, false if quest already exists in DB (= not inserted) */ public boolean add(T quest) diff --git a/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java b/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java index 0d11787eba..66039d7f77 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java +++ b/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java @@ -7,6 +7,7 @@ import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceFragmentCompat; import android.support.v7.preference.PreferenceManager; +import android.widget.Toast; import javax.inject.Inject; import javax.inject.Provider; @@ -15,6 +16,9 @@ import de.westnordost.streetcomplete.Injector; import de.westnordost.streetcomplete.IntentListener; import de.westnordost.streetcomplete.Prefs; +import de.westnordost.streetcomplete.data.osm.persist.AOsmQuestDao; +import de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao; +import de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuestDao; import de.westnordost.streetcomplete.oauth.OAuthPrefs; import de.westnordost.streetcomplete.R; import de.westnordost.streetcomplete.oauth.OsmOAuthDialogFragment; @@ -27,6 +31,8 @@ public class SettingsFragment extends PreferenceFragmentCompat @Inject SharedPreferences prefs; @Inject OAuthPrefs oAuth; @Inject Provider applyNoteVisibilityChangedTask; + @Inject OsmNoteQuestDao osmNoteQuestDao; + @Inject OsmQuestDao osmQuestDao; @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { @@ -47,6 +53,15 @@ public class SettingsFragment extends PreferenceFragmentCompat getFragmentActivity().setCurrentFragment(new QuestSelectionFragment()); return true; }); + + Preference questsDeletion = getPreferenceScreen().findPreference("quests.deletion"); + questsDeletion.setOnPreferenceClickListener(preference -> + { + osmQuestDao.clear(); + osmNoteQuestDao.clear(); + Toast.makeText(getContext(), R.string.deletion_success, Toast.LENGTH_SHORT).show(); + return true; + }); } @Override diff --git a/app/src/main/res/drawable/ic_delete_black_24dp.xml b/app/src/main/res/drawable/ic_delete_black_24dp.xml new file mode 100644 index 0000000000..39e64d6980 --- /dev/null +++ b/app/src/main/res/drawable/ic_delete_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/widget_image_delete.xml b/app/src/main/res/layout/widget_image_delete.xml new file mode 100644 index 0000000000..46d805a1ee --- /dev/null +++ b/app/src/main/res/layout/widget_image_delete.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 74cc3d5867..c43f1b5941 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -440,4 +440,7 @@ Otherwise, you can download another keyboard in the app store. Popular keyboards A conscription number must be specified Also cycleway on other side You need to specify both sides + Delete all quests + Useful if you think that some quests are outdated + Deleted successfully diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 514c09c5b8..f6ab0f5eea 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -76,6 +76,13 @@ android:widgetLayout="@layout/widget_image_next" /> + + \ No newline at end of file From bb45ad043069499173746daaf6835a0243140b94 Mon Sep 17 00:00:00 2001 From: ENT8R Date: Thu, 23 Nov 2017 17:26:54 +0100 Subject: [PATCH 2/6] Remove unused import statement --- .../de/westnordost/streetcomplete/settings/SettingsFragment.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java b/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java index 66039d7f77..35fb7b2790 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java +++ b/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java @@ -16,7 +16,6 @@ import de.westnordost.streetcomplete.Injector; import de.westnordost.streetcomplete.IntentListener; import de.westnordost.streetcomplete.Prefs; -import de.westnordost.streetcomplete.data.osm.persist.AOsmQuestDao; import de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao; import de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuestDao; import de.westnordost.streetcomplete.oauth.OAuthPrefs; From d6f7fec33d6f144db4bb7367129586ac4c13535a Mon Sep 17 00:00:00 2001 From: ENT8R Date: Fri, 24 Nov 2017 16:04:02 +0100 Subject: [PATCH 3/6] Invalidate the quest cache instead of delete all quests --- .../de/westnordost/streetcomplete/Prefs.java | 2 +- .../streetcomplete/data/AQuestDao.java | 6 -- .../data/tiles/DownloadedTilesDao.java | 6 ++ .../settings/SettingsFragment.java | 58 ++++++++++++++++--- .../streetcomplete/tangram/MapFragment.java | 9 +-- .../res/drawable/ic_delete_black_24dp.xml | 9 --- .../main/res/layout/widget_image_delete.xml | 6 -- app/src/main/res/values/strings.xml | 10 +++- app/src/main/res/xml/preferences.xml | 7 +-- 9 files changed, 71 insertions(+), 42 deletions(-) delete mode 100644 app/src/main/res/drawable/ic_delete_black_24dp.xml delete mode 100644 app/src/main/res/layout/widget_image_delete.xml diff --git a/app/src/main/java/de/westnordost/streetcomplete/Prefs.java b/app/src/main/java/de/westnordost/streetcomplete/Prefs.java index f4af7e9017..49f861952b 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/Prefs.java +++ b/app/src/main/java/de/westnordost/streetcomplete/Prefs.java @@ -19,7 +19,7 @@ public class Prefs // not shown anywhere directly public static final String QUEST_ORDER = "quests.order", - QUEST_DELETION = "quests.deletion"; + QUEST_INVALIDATION = "quests.invalidation"; public enum Autosync { diff --git a/app/src/main/java/de/westnordost/streetcomplete/data/AQuestDao.java b/app/src/main/java/de/westnordost/streetcomplete/data/AQuestDao.java index fb95d1a79b..d05ffb4caf 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/data/AQuestDao.java +++ b/app/src/main/java/de/westnordost/streetcomplete/data/AQuestDao.java @@ -216,12 +216,6 @@ private int insertAll(Collection quests, boolean replace) return addRows; } - public void clear() - { - SQLiteDatabase db = dbHelper.getReadableDatabase(); - db.execSQL("DELETE FROM " + getTableName()); - } - /** Add given quest to DB and sets the quest's id after inserting it * @return true if successfully inserted, false if quest already exists in DB (= not inserted) */ public boolean add(T quest) diff --git a/app/src/main/java/de/westnordost/streetcomplete/data/tiles/DownloadedTilesDao.java b/app/src/main/java/de/westnordost/streetcomplete/data/tiles/DownloadedTilesDao.java index 7f3b13e958..9fd268fe6a 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/data/tiles/DownloadedTilesDao.java +++ b/app/src/main/java/de/westnordost/streetcomplete/data/tiles/DownloadedTilesDao.java @@ -70,6 +70,12 @@ public int remove(Point tile) DownloadedTilesTable.Columns.Y + " = ?", whereArgs); } + public void removeAll() + { + SQLiteDatabase db = dbHelper.getReadableDatabase(); + db.execSQL("DELETE FROM " + DownloadedTilesTable.NAME); + } + /** @return a list of quest type names which have already been downloaded in every tile in the * given tile range */ public List get(Rect tiles, long ignoreOlderThan) diff --git a/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java b/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java index 35fb7b2790..56261aca51 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java +++ b/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java @@ -1,7 +1,9 @@ package de.westnordost.streetcomplete.settings; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Point; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v7.preference.Preference; @@ -9,18 +11,27 @@ import android.support.v7.preference.PreferenceManager; import android.widget.Toast; +import com.mapzen.tangram.LngLat; + import javax.inject.Inject; import javax.inject.Provider; +import de.westnordost.streetcomplete.ApplicationConstants; import de.westnordost.streetcomplete.FragmentContainerActivity; import de.westnordost.streetcomplete.Injector; import de.westnordost.streetcomplete.IntentListener; import de.westnordost.streetcomplete.Prefs; -import de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao; -import de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuestDao; +import de.westnordost.streetcomplete.data.tiles.DownloadedTilesDao; import de.westnordost.streetcomplete.oauth.OAuthPrefs; import de.westnordost.streetcomplete.R; import de.westnordost.streetcomplete.oauth.OsmOAuthDialogFragment; +import de.westnordost.streetcomplete.util.SlippyMapMath; +import de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder; + +import static de.westnordost.streetcomplete.tangram.MapFragment.PREF_LAT; +import static de.westnordost.streetcomplete.tangram.MapFragment.PREF_LON; +import static de.westnordost.streetcomplete.tangram.MapFragment.PREF_NAME; +import static de.westnordost.streetcomplete.tangram.TangramConst.toLatLon; public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener, IntentListener @@ -30,8 +41,7 @@ public class SettingsFragment extends PreferenceFragmentCompat @Inject SharedPreferences prefs; @Inject OAuthPrefs oAuth; @Inject Provider applyNoteVisibilityChangedTask; - @Inject OsmNoteQuestDao osmNoteQuestDao; - @Inject OsmQuestDao osmQuestDao; + @Inject DownloadedTilesDao downloadedTilesDao; @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { @@ -53,12 +63,27 @@ public class SettingsFragment extends PreferenceFragmentCompat return true; }); - Preference questsDeletion = getPreferenceScreen().findPreference("quests.deletion"); - questsDeletion.setOnPreferenceClickListener(preference -> + Preference questsInvalidation = getPreferenceScreen().findPreference("quests.invalidation"); + questsInvalidation.setOnPreferenceClickListener(preference -> { - osmQuestDao.clear(); - osmNoteQuestDao.clear(); - Toast.makeText(getContext(), R.string.deletion_success, Toast.LENGTH_SHORT).show(); + new AlertDialogBuilder(getContext()) + .setMessage(R.string.invalidation_dialog_message) + .setPositiveButton(R.string.invalidate_shown_tile, (dialog, which) -> { + if (getShownTile() != null) + { + downloadedTilesDao.remove(getShownTile()); + Toast.makeText(getContext(), R.string.invalidation_success, Toast.LENGTH_SHORT).show(); + } else + { + Toast.makeText(getContext(), R.string.invalidation_error, Toast.LENGTH_SHORT).show(); + } + }) + .setNeutralButton(R.string.invalidate_whole_cache, (dialog, which) -> { + downloadedTilesDao.removeAll(); + Toast.makeText(getContext(), R.string.invalidation_success, Toast.LENGTH_SHORT).show(); + }) + .setNegativeButton(android.R.string.cancel, (dialog, which) -> {}) + .show(); return true; }); } @@ -71,6 +96,21 @@ public void onStart() getActivity().setTitle(R.string.action_settings); } + private Point getShownTile() + { + SharedPreferences preferences = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); + if(preferences.contains(PREF_LAT) && preferences.contains(PREF_LON)) + { + LngLat pos = new LngLat( + Double.longBitsToDouble(preferences.getLong(PREF_LON,0)), + Double.longBitsToDouble(preferences.getLong(PREF_LAT,0)) + ); + return SlippyMapMath.enclosingTile(toLatLon(pos), ApplicationConstants.QUEST_TILE_ZOOM); + + } + return null; + } + private void updateOsmAuthSummary() { Preference oauth = getPreferenceScreen().findPreference("oauth"); diff --git a/app/src/main/java/de/westnordost/streetcomplete/tangram/MapFragment.java b/app/src/main/java/de/westnordost/streetcomplete/tangram/MapFragment.java index 3b7992f9bd..8d96403811 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/tangram/MapFragment.java +++ b/app/src/main/java/de/westnordost/streetcomplete/tangram/MapFragment.java @@ -525,18 +525,19 @@ private float meters2Pixels(LngLat at, float meters) { ); } - private static final String + public static final String PREF_ROTATION = "map_rotation", PREF_TILT = "map_tilt", PREF_ZOOM = "map_zoom", PREF_LAT = "map_lat", PREF_LON = "map_lon", PREF_FOLLOWING = "map_following", - PREF_COMPASS_MODE = "map_compass_mode"; + PREF_COMPASS_MODE = "map_compass_mode", + PREF_NAME = "map_settings"; private void restoreMapState() { - SharedPreferences prefs = getActivity().getPreferences(Activity.MODE_PRIVATE); + SharedPreferences prefs = getActivity().getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE); if(prefs.contains(PREF_ROTATION)) controller.setRotation(prefs.getFloat(PREF_ROTATION,0)); if(prefs.contains(PREF_TILT)) controller.setTilt(prefs.getFloat(PREF_TILT,0)); @@ -559,7 +560,7 @@ private void saveMapState() { if(controller == null) return; - SharedPreferences.Editor editor = getActivity().getPreferences(Activity.MODE_PRIVATE).edit(); + SharedPreferences.Editor editor = getActivity().getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE).edit(); editor.putFloat(PREF_ROTATION, controller.getRotation()); editor.putFloat(PREF_TILT, controller.getTilt()); editor.putFloat(PREF_ZOOM, controller.getZoom()); diff --git a/app/src/main/res/drawable/ic_delete_black_24dp.xml b/app/src/main/res/drawable/ic_delete_black_24dp.xml deleted file mode 100644 index 39e64d6980..0000000000 --- a/app/src/main/res/drawable/ic_delete_black_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/layout/widget_image_delete.xml b/app/src/main/res/layout/widget_image_delete.xml deleted file mode 100644 index 46d805a1ee..0000000000 --- a/app/src/main/res/layout/widget_image_delete.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c43f1b5941..a79c5ccc8a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -440,7 +440,11 @@ Otherwise, you can download another keyboard in the app store. Popular keyboards A conscription number must be specified Also cycleway on other side You need to specify both sides - Delete all quests - Useful if you think that some quests are outdated - Deleted successfully + Invalidate Quest Cache + Useful if you think that some quests are outdated + Invalidate shown tile + Invalidate whole cache + Invalidation successful + Invalidation went wrong + Invalidating the cache causes the quests to be updated next time they are downloaded each. The quest cache is invalidated automatically after one week and immediately when a quest you solved turns out to be already answered by someone else. diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index f6ab0f5eea..77d4f16b8a 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -77,10 +77,9 @@ /> From e7b85c6723031f37b3d1972630607f0a70e1ba0d Mon Sep 17 00:00:00 2001 From: ENT8R Date: Fri, 24 Nov 2017 17:54:42 +0100 Subject: [PATCH 4/6] Fix issues --- .../data/tiles/DownloadedTilesDao.java | 2 +- .../visiblequests/VisibleQuestTypeDao.java | 2 +- .../settings/SettingsFragment.java | 52 +++++++++---------- app/src/main/res/values/strings.xml | 7 ++- 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/data/tiles/DownloadedTilesDao.java b/app/src/main/java/de/westnordost/streetcomplete/data/tiles/DownloadedTilesDao.java index 9fd268fe6a..bd84732522 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/data/tiles/DownloadedTilesDao.java +++ b/app/src/main/java/de/westnordost/streetcomplete/data/tiles/DownloadedTilesDao.java @@ -72,7 +72,7 @@ public int remove(Point tile) public void removeAll() { - SQLiteDatabase db = dbHelper.getReadableDatabase(); + SQLiteDatabase db = dbHelper.getWritableDatabase(); db.execSQL("DELETE FROM " + DownloadedTilesTable.NAME); } diff --git a/app/src/main/java/de/westnordost/streetcomplete/data/visiblequests/VisibleQuestTypeDao.java b/app/src/main/java/de/westnordost/streetcomplete/data/visiblequests/VisibleQuestTypeDao.java index 041b8a417d..d3e4b91a57 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/data/visiblequests/VisibleQuestTypeDao.java +++ b/app/src/main/java/de/westnordost/streetcomplete/data/visiblequests/VisibleQuestTypeDao.java @@ -96,7 +96,7 @@ public synchronized void setVisible(QuestType questType, boolean visible) public synchronized void clear() { - SQLiteDatabase db = dbHelper.getReadableDatabase(); + SQLiteDatabase db = dbHelper.getWritableDatabase(); db.execSQL("DELETE FROM " + QuestVisibilityTable.NAME); questTypeVisibilities = null; } diff --git a/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java b/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java index 56261aca51..94b931efb5 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java +++ b/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java @@ -6,16 +6,15 @@ import android.graphics.Point; import android.os.Bundle; import android.support.v4.app.DialogFragment; +import android.support.v7.app.AlertDialog; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceFragmentCompat; import android.support.v7.preference.PreferenceManager; -import android.widget.Toast; - -import com.mapzen.tangram.LngLat; import javax.inject.Inject; import javax.inject.Provider; +import de.westnordost.osmapi.map.data.OsmLatLon; import de.westnordost.streetcomplete.ApplicationConstants; import de.westnordost.streetcomplete.FragmentContainerActivity; import de.westnordost.streetcomplete.Injector; @@ -25,14 +24,10 @@ import de.westnordost.streetcomplete.oauth.OAuthPrefs; import de.westnordost.streetcomplete.R; import de.westnordost.streetcomplete.oauth.OsmOAuthDialogFragment; +import de.westnordost.streetcomplete.tangram.MapFragment; import de.westnordost.streetcomplete.util.SlippyMapMath; import de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder; -import static de.westnordost.streetcomplete.tangram.MapFragment.PREF_LAT; -import static de.westnordost.streetcomplete.tangram.MapFragment.PREF_LON; -import static de.westnordost.streetcomplete.tangram.MapFragment.PREF_NAME; -import static de.westnordost.streetcomplete.tangram.TangramConst.toLatLon; - public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener, IntentListener { @@ -66,24 +61,26 @@ public class SettingsFragment extends PreferenceFragmentCompat Preference questsInvalidation = getPreferenceScreen().findPreference("quests.invalidation"); questsInvalidation.setOnPreferenceClickListener(preference -> { - new AlertDialogBuilder(getContext()) + AlertDialog alertDialog = new AlertDialogBuilder(getContext()) + .setTitle(R.string.invalidation_dialog_title) .setMessage(R.string.invalidation_dialog_message) - .setPositiveButton(R.string.invalidate_shown_tile, (dialog, which) -> { - if (getShownTile() != null) - { - downloadedTilesDao.remove(getShownTile()); - Toast.makeText(getContext(), R.string.invalidation_success, Toast.LENGTH_SHORT).show(); - } else - { - Toast.makeText(getContext(), R.string.invalidation_error, Toast.LENGTH_SHORT).show(); - } + .setPositiveButton(R.string.invalidate_here, (dialog, which) -> { + downloadedTilesDao.remove(getShownTile()); }) - .setNeutralButton(R.string.invalidate_whole_cache, (dialog, which) -> { + .setNeutralButton(R.string.invalidate_everywhere, (dialog, which) -> { downloadedTilesDao.removeAll(); - Toast.makeText(getContext(), R.string.invalidation_success, Toast.LENGTH_SHORT).show(); }) .setNegativeButton(android.R.string.cancel, (dialog, which) -> {}) - .show(); + .create(); + alertDialog.setOnShowListener((dialog) -> + { + if (getShownTile() == null) + { + ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); + } + }); + alertDialog.show(); + return true; }); } @@ -98,14 +95,13 @@ public void onStart() private Point getShownTile() { - SharedPreferences preferences = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); - if(preferences.contains(PREF_LAT) && preferences.contains(PREF_LON)) + SharedPreferences preferences = getActivity().getSharedPreferences(MapFragment.PREF_NAME, Context.MODE_PRIVATE); + if(preferences.contains(MapFragment.PREF_LAT) && preferences.contains(MapFragment.PREF_LON)) { - LngLat pos = new LngLat( - Double.longBitsToDouble(preferences.getLong(PREF_LON,0)), - Double.longBitsToDouble(preferences.getLong(PREF_LAT,0)) - ); - return SlippyMapMath.enclosingTile(toLatLon(pos), ApplicationConstants.QUEST_TILE_ZOOM); + OsmLatLon pos = new OsmLatLon( + Double.longBitsToDouble(preferences.getLong(MapFragment.PREF_LON,0)), + Double.longBitsToDouble(preferences.getLong(MapFragment.PREF_LAT,0))); + return SlippyMapMath.enclosingTile(pos, ApplicationConstants.QUEST_TILE_ZOOM); } return null; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a79c5ccc8a..224aceae0a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -442,9 +442,8 @@ Otherwise, you can download another keyboard in the app store. Popular keyboards You need to specify both sides Invalidate Quest Cache Useful if you think that some quests are outdated - Invalidate shown tile - Invalidate whole cache - Invalidation successful - Invalidation went wrong + Where to invalidate the cache? + Here + Everywhere Invalidating the cache causes the quests to be updated next time they are downloaded each. The quest cache is invalidated automatically after one week and immediately when a quest you solved turns out to be already answered by someone else. From 18c8c4598a19caa26563e58152a3635a283dc656 Mon Sep 17 00:00:00 2001 From: ENT8R Date: Sat, 25 Nov 2017 19:30:19 +0100 Subject: [PATCH 5/6] Remove the option to invalidate only a specific tile --- .../settings/SettingsFragment.java | 33 +++---------------- .../streetcomplete/tangram/MapFragment.java | 7 ++-- app/src/main/res/values/strings.xml | 4 +-- 3 files changed, 8 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java b/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java index 94b931efb5..2b1708878c 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java +++ b/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java @@ -61,25 +61,14 @@ public class SettingsFragment extends PreferenceFragmentCompat Preference questsInvalidation = getPreferenceScreen().findPreference("quests.invalidation"); questsInvalidation.setOnPreferenceClickListener(preference -> { - AlertDialog alertDialog = new AlertDialogBuilder(getContext()) - .setTitle(R.string.invalidation_dialog_title) + new AlertDialogBuilder(getContext()) .setMessage(R.string.invalidation_dialog_message) - .setPositiveButton(R.string.invalidate_here, (dialog, which) -> { - downloadedTilesDao.remove(getShownTile()); - }) - .setNeutralButton(R.string.invalidate_everywhere, (dialog, which) -> { + .setPositiveButton(R.string.invalidate_confirmation, (dialog, which) -> { downloadedTilesDao.removeAll(); }) .setNegativeButton(android.R.string.cancel, (dialog, which) -> {}) - .create(); - alertDialog.setOnShowListener((dialog) -> - { - if (getShownTile() == null) - { - ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); - } - }); - alertDialog.show(); + .create() + .show(); return true; }); @@ -93,20 +82,6 @@ public void onStart() getActivity().setTitle(R.string.action_settings); } - private Point getShownTile() - { - SharedPreferences preferences = getActivity().getSharedPreferences(MapFragment.PREF_NAME, Context.MODE_PRIVATE); - if(preferences.contains(MapFragment.PREF_LAT) && preferences.contains(MapFragment.PREF_LON)) - { - OsmLatLon pos = new OsmLatLon( - Double.longBitsToDouble(preferences.getLong(MapFragment.PREF_LON,0)), - Double.longBitsToDouble(preferences.getLong(MapFragment.PREF_LAT,0))); - return SlippyMapMath.enclosingTile(pos, ApplicationConstants.QUEST_TILE_ZOOM); - - } - return null; - } - private void updateOsmAuthSummary() { Preference oauth = getPreferenceScreen().findPreference("oauth"); diff --git a/app/src/main/java/de/westnordost/streetcomplete/tangram/MapFragment.java b/app/src/main/java/de/westnordost/streetcomplete/tangram/MapFragment.java index 8d96403811..be90848609 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/tangram/MapFragment.java +++ b/app/src/main/java/de/westnordost/streetcomplete/tangram/MapFragment.java @@ -532,12 +532,11 @@ private float meters2Pixels(LngLat at, float meters) { PREF_LAT = "map_lat", PREF_LON = "map_lon", PREF_FOLLOWING = "map_following", - PREF_COMPASS_MODE = "map_compass_mode", - PREF_NAME = "map_settings"; + PREF_COMPASS_MODE = "map_compass_mode"; private void restoreMapState() { - SharedPreferences prefs = getActivity().getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE); + SharedPreferences prefs = getActivity().getPreferences(Activity.MODE_PRIVATE); if(prefs.contains(PREF_ROTATION)) controller.setRotation(prefs.getFloat(PREF_ROTATION,0)); if(prefs.contains(PREF_TILT)) controller.setTilt(prefs.getFloat(PREF_TILT,0)); @@ -560,7 +559,7 @@ private void saveMapState() { if(controller == null) return; - SharedPreferences.Editor editor = getActivity().getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE).edit(); + SharedPreferences.Editor editor = getActivity().getPreferences(Activity.MODE_PRIVATE).edit(); editor.putFloat(PREF_ROTATION, controller.getRotation()); editor.putFloat(PREF_TILT, controller.getTilt()); editor.putFloat(PREF_ZOOM, controller.getZoom()); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 224aceae0a..a280d2132f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -442,8 +442,6 @@ Otherwise, you can download another keyboard in the app store. Popular keyboards You need to specify both sides Invalidate Quest Cache Useful if you think that some quests are outdated - Where to invalidate the cache? - Here - Everywhere + Invalidate Invalidating the cache causes the quests to be updated next time they are downloaded each. The quest cache is invalidated automatically after one week and immediately when a quest you solved turns out to be already answered by someone else. From a2b7519ecd4f60aa4fbc11f962119f012935568b Mon Sep 17 00:00:00 2001 From: ENT8R Date: Sat, 25 Nov 2017 20:59:32 +0100 Subject: [PATCH 6/6] Use null instead of empty function --- .../westnordost/streetcomplete/settings/SettingsFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java b/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java index 2b1708878c..9a0091acbe 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java +++ b/app/src/main/java/de/westnordost/streetcomplete/settings/SettingsFragment.java @@ -66,7 +66,7 @@ public class SettingsFragment extends PreferenceFragmentCompat .setPositiveButton(R.string.invalidate_confirmation, (dialog, which) -> { downloadedTilesDao.removeAll(); }) - .setNegativeButton(android.R.string.cancel, (dialog, which) -> {}) + .setNegativeButton(android.R.string.cancel, null) .create() .show();