-
-
Notifications
You must be signed in to change notification settings - Fork 366
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
Changes from 3 commits
9cf86aa
bb45ad0
d6f7fec
e7b85c6
18c8c45
a2b7519
bd79d4b
e58b5ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,37 @@ | ||
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; | ||
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.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.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 | ||
|
@@ -27,6 +41,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) | ||
{ | ||
|
@@ -47,6 +62,30 @@ 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_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(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please leave out the success and error messages. This will only confuse the users. Instead, just check if getShownTile() is null before building the dialog and only add that answer option ("Only this tile") if the current shown tile can be determined. Or, optionally, if possible, show that option but disable it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But if the invalidation succeeded, there should really be no success message? |
||
}) | ||
.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) -> {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
.show(); | ||
return true; | ||
}); | ||
} | ||
|
||
@Override | ||
|
@@ -57,6 +96,21 @@ public void onStart() | |
getActivity().setTitle(R.string.action_settings); | ||
} | ||
|
||
private Point getShownTile() | ||
{ | ||
SharedPreferences preferences = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to have the static const here fully qualified, i.e. MapFragment.PREF_NAME etc. because this is the SettingsFragment, everything is settings and prefernces here. It is necessary to know the context of any such preference/settings. |
||
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)) | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You create a LngLat here, and then convert the LngLat to a LatLon. Why not simply create a LatLon in the first place? (The default implementation of that interface is OsmLatLon) |
||
return SlippyMapMath.enclosingTile(toLatLon(pos), ApplicationConstants.QUEST_TILE_ZOOM); | ||
|
||
} | ||
return null; | ||
} | ||
|
||
private void updateOsmAuthSummary() | ||
{ | ||
Preference oauth = getPreferenceScreen().findPreference("oauth"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok,... that's the caveat. Hmm, it's a but ugly that other activities access the preferences of the map this way. But I don't have an idea right now to have a cleaner interface there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mmh... me too... |
||
editor.putFloat(PREF_ROTATION, controller.getRotation()); | ||
editor.putFloat(PREF_TILT, controller.getTilt()); | ||
editor.putFloat(PREF_ZOOM, controller.getZoom()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getWritableDatabase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you are doing the same here:
https://github.com/westnordost/StreetComplete/blob/fb3f6ccddf64e35ecb1576a7cb13471474d775f5/app/src/main/java/de/westnordost/streetcomplete/data/visiblequests/VisibleQuestTypeDao.java#L99