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 2 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_DELETION = "quests.deletion";

public enum Autosync
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ private int insertAll(Collection<T> quests, boolean replace)
return addRows;
}

public void clear()
{
SQLiteDatabase db = dbHelper.getReadableDatabase();
db.execSQL("DELETE FROM " + getTableName());
}
Copy link
Member

Choose a reason for hiding this comment

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

So this, by the way, also deletes to-be-uploaded quests, reverted quests, ... everything.


/** 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +16,8 @@
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.oauth.OAuthPrefs;
import de.westnordost.streetcomplete.R;
import de.westnordost.streetcomplete.oauth.OsmOAuthDialogFragment;
Expand All @@ -27,6 +30,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
@Inject SharedPreferences prefs;
@Inject OAuthPrefs oAuth;
@Inject Provider<ApplyNoteVisibilityChangedTask> applyNoteVisibilityChangedTask;
@Inject OsmNoteQuestDao osmNoteQuestDao;
@Inject OsmQuestDao osmQuestDao;

@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey)
{
Expand All @@ -47,6 +52,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
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_delete_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
</vector>
6 changes: 6 additions & 0 deletions app/src/main/res/layout/widget_image_delete.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_delete_black_24dp" >
</ImageView>
3 changes: 3 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,7 @@ 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_deletion">Delete all quests</string>
<string name="pref_title_quests_deletion_summary">Useful if you think that some quests are outdated</string>
<string name="deletion_success">Deleted successfully</string>
</resources>
7 changes: 7 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,13 @@
android:widgetLayout="@layout/widget_image_next"
/>

<Preference
android:key="quests.deletion"
android:title="@string/pref_title_quests_deletion"
android:summary="@string/pref_title_quests_deletion_summary"
android:widgetLayout="@layout/widget_image_delete"
Copy link
Member

Choose a reason for hiding this comment

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

I misuse the widget layout in some cases only to signal that something is a subpage or that something leads out of this app (into a browser). It should not be used to generally display an icon.

/>

</PreferenceCategory>

</PreferenceScreen>