mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Track changes to the preference for tracking changes
Yo Dawg, etc, etc.
This commit is contained in:
parent
1b89d96943
commit
32983db9c2
3 changed files with 40 additions and 3 deletions
|
|
@ -55,6 +55,7 @@ public class CommonsApplication extends Application {
|
||||||
public static final Object[] EVENT_LOGIN_ATTEMPT = {"MobileAppLoginAttempts", 5257721L};
|
public static final Object[] EVENT_LOGIN_ATTEMPT = {"MobileAppLoginAttempts", 5257721L};
|
||||||
public static final Object[] EVENT_SHARE_ATTEMPT = {"MobileAppShareAttempts", 5346170L};
|
public static final Object[] EVENT_SHARE_ATTEMPT = {"MobileAppShareAttempts", 5346170L};
|
||||||
public static final Object[] EVENT_CATEGORIZATION_ATTEMPT = {"MobileAppCategorizationAttempts", 5359208L};
|
public static final Object[] EVENT_CATEGORIZATION_ATTEMPT = {"MobileAppCategorizationAttempts", 5359208L};
|
||||||
|
public static final Object[] EVENT_EVENTLOGGING_CHANGE = {"MobileAppTrackingChange", 5369400L};
|
||||||
|
|
||||||
public static final String DEFAULT_EDIT_SUMMARY = "Uploaded using Android Commons app";
|
public static final String DEFAULT_EDIT_SUMMARY = "Uploaded using Android Commons app";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,15 +96,22 @@ public class EventLog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log() {
|
// force param disregards user preference
|
||||||
|
// Use *only* for tracking the user preference change for EventLogging
|
||||||
|
// Attempting to use anywhere else will cause kitten explosions
|
||||||
|
public void log(boolean force) {
|
||||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(app);
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(app);
|
||||||
if(!settings.getBoolean(Prefs.TRACKING_ENABLED, true)) {
|
if(!settings.getBoolean(Prefs.TRACKING_ENABLED, true) && !force) {
|
||||||
return; // User has disabled tracking
|
return; // User has disabled tracking
|
||||||
}
|
}
|
||||||
LogTask logTask = new LogTask();
|
LogTask logTask = new LogTask();
|
||||||
Utils.executeAsyncTask(logTask, this);
|
Utils.executeAsyncTask(logTask, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void log() {
|
||||||
|
log(false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LogBuilder schema(String schema, long revision) {
|
public static LogBuilder schema(String schema, long revision) {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,42 @@
|
||||||
package org.wikimedia.commons;
|
package org.wikimedia.commons;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.Preference;
|
||||||
import com.actionbarsherlock.app.SherlockPreferenceActivity;
|
import com.actionbarsherlock.app.SherlockPreferenceActivity;
|
||||||
|
|
||||||
public class SettingsActivity extends SherlockPreferenceActivity {
|
public class SettingsActivity extends SherlockPreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
CommonsApplication app;
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
app = (CommonsApplication)getApplicationContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
getPreferenceScreen().getSharedPreferences()
|
||||||
|
.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
getPreferenceScreen().getSharedPreferences()
|
||||||
|
.unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
|
if(key.equals(Prefs.TRACKING_ENABLED)) {
|
||||||
|
// We force log this, so it is logged even if EL is turned off
|
||||||
|
EventLog.schema(CommonsApplication.EVENT_EVENTLOGGING_CHANGE)
|
||||||
|
.param("username", app.getCurrentAccount().name)
|
||||||
|
.param("state", sharedPreferences.getBoolean(key, true))
|
||||||
|
.log(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue