Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to invalidate the quest cache #706

Merged
merged 8 commits into from
Jan 7, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/main/java/de/westnordost/streetcomplete/Prefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class Prefs

// not shown anywhere directly
public static final String
QUEST_ORDER = "quests.order";
QUEST_ORDER = "quests.order",
QUEST_INVALIDATION = "quests.invalidation";

public enum Autosync
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public int remove(Point tile)
DownloadedTilesTable.Columns.Y + " = ?", whereArgs);
}

public void removeAll()
{
SQLiteDatabase db = dbHelper.getWritableDatabase();
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<String> get(Rect tiles, long ignoreOlderThan)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
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.app.AlertDialog;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.support.v7.preference.PreferenceManager;

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;
import de.westnordost.streetcomplete.IntentListener;
import de.westnordost.streetcomplete.Prefs;
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.tangram.MapFragment;
import de.westnordost.streetcomplete.util.SlippyMapMath;
import de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder;

public class SettingsFragment extends PreferenceFragmentCompat
implements SharedPreferences.OnSharedPreferenceChangeListener, IntentListener
Expand All @@ -27,6 +36,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
@Inject SharedPreferences prefs;
@Inject OAuthPrefs oAuth;
@Inject Provider<ApplyNoteVisibilityChangedTask> applyNoteVisibilityChangedTask;
@Inject DownloadedTilesDao downloadedTilesDao;

@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey)
{
Expand All @@ -47,6 +57,21 @@ public class SettingsFragment extends PreferenceFragmentCompat
getFragmentActivity().setCurrentFragment(new QuestSelectionFragment());
return true;
});

Preference questsInvalidation = getPreferenceScreen().findPreference("quests.invalidation");
questsInvalidation.setOnPreferenceClickListener(preference ->
{
new AlertDialogBuilder(getContext())
.setMessage(R.string.invalidation_dialog_message)
.setPositiveButton(R.string.invalidate_confirmation, (dialog, which) -> {
downloadedTilesDao.removeAll();
})
.setNegativeButton(android.R.string.cancel, (dialog, which) -> {})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(dialog, which) -> {} can be null, by the way.

.create()
.show();

return true;
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ 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",
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,8 @@ Otherwise, you can download another keyboard in the app store. Popular keyboards
<string name="quest_housenumber_conscription_number_required">A conscription number must be specified</string>
<string name="quest_cycleway_answer_contraflow_cycleway">Also cycleway on other side</string>
<string name="need_specify_both_sides">You need to specify both sides</string>
<string name="pref_title_quests_invalidation">Invalidate Quest Cache</string>
<string name="pref_title_quests_invalidation_summary">Useful if you think that some quests are outdated</string>
<string name="invalidate_confirmation">Invalidate</string>
<string name="invalidation_dialog_message">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.</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@
android:widgetLayout="@layout/widget_image_next"
/>

<Preference
android:key="quests.invalidation"
android:title="@string/pref_title_quests_invalidation"
android:summary="@string/pref_title_quests_invalidation_summary"
/>

</PreferenceCategory>

</PreferenceScreen>