|
|
|
|
@ -3,7 +3,6 @@ package org.tasks.preferences;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
import android.content.res.Resources;
|
|
|
|
|
import android.os.Environment;
|
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
|
|
@ -28,14 +27,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
|
|
|
|
|
import ch.qos.logback.classic.Level;
|
|
|
|
|
import ch.qos.logback.classic.LoggerContext;
|
|
|
|
|
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
|
|
|
|
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
|
|
|
|
import ch.qos.logback.core.rolling.FixedWindowRollingPolicy;
|
|
|
|
|
import ch.qos.logback.core.rolling.RollingFileAppender;
|
|
|
|
|
import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy;
|
|
|
|
|
|
|
|
|
|
import static android.content.SharedPreferences.Editor;
|
|
|
|
|
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybean;
|
|
|
|
|
|
|
|
|
|
@ -47,8 +38,6 @@ public class Preferences {
|
|
|
|
|
|
|
|
|
|
private static final String PREF_SORT_SORT = "sort_sort"; //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
private static final String FILE_APPENDER_NAME = "FILE";
|
|
|
|
|
|
|
|
|
|
protected final Context context;
|
|
|
|
|
private final DeviceInfo deviceInfo;
|
|
|
|
|
private final PermissionChecker permissionChecker;
|
|
|
|
|
@ -100,10 +89,6 @@ public class Preferences {
|
|
|
|
|
return defaultCalendar != null && !defaultCalendar.equals("-1") && !defaultCalendar.equals("0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setTrackingEnabled(boolean enabled) {
|
|
|
|
|
setBoolean(R.string.p_collect_statistics, enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isTrackingEnabled() {
|
|
|
|
|
return getBoolean(R.string.p_collect_statistics, true);
|
|
|
|
|
}
|
|
|
|
|
@ -288,59 +273,6 @@ public class Preferences {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setupLogger() {
|
|
|
|
|
if (permissionChecker.canWriteToExternalStorage()) {
|
|
|
|
|
setupLogger(getBoolean(R.string.p_debug_logging, false));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setupLogger(boolean enableDebugLogging) {
|
|
|
|
|
try {
|
|
|
|
|
ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
|
|
|
|
|
if (enableDebugLogging) {
|
|
|
|
|
rootLogger.setLevel(Level.DEBUG);
|
|
|
|
|
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
|
|
|
|
attachRollingFileAppender(rootLogger);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
rootLogger.setLevel(Level.INFO);
|
|
|
|
|
rootLogger.detachAppender(FILE_APPENDER_NAME);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error(e.getMessage(), e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void attachRollingFileAppender(ch.qos.logback.classic.Logger rootLogger) {
|
|
|
|
|
final String path = Environment.getExternalStorageDirectory().getAbsolutePath();
|
|
|
|
|
final LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
|
|
|
|
|
final RollingFileAppender<ILoggingEvent> rfa = new RollingFileAppender<ILoggingEvent>() {{
|
|
|
|
|
setName(FILE_APPENDER_NAME);
|
|
|
|
|
setContext(loggerContext);
|
|
|
|
|
setFile(path + "/tasks-debug.log");
|
|
|
|
|
setEncoder(new PatternLayoutEncoder() {{
|
|
|
|
|
setContext(loggerContext);
|
|
|
|
|
setPattern("%date [%thread] %-5level %logger{35} - %msg%n");
|
|
|
|
|
start();
|
|
|
|
|
}});
|
|
|
|
|
setTriggeringPolicy(new SizeBasedTriggeringPolicy<ILoggingEvent>() {{
|
|
|
|
|
setMaxFileSize("5MB");
|
|
|
|
|
start();
|
|
|
|
|
}});
|
|
|
|
|
}};
|
|
|
|
|
FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy() {{
|
|
|
|
|
setContext(loggerContext);
|
|
|
|
|
setParent(rfa);
|
|
|
|
|
setMinIndex(1);
|
|
|
|
|
setMaxIndex(3);
|
|
|
|
|
setFileNamePattern(path + "/tasks-debug.%i.log.zip");
|
|
|
|
|
start();
|
|
|
|
|
}};
|
|
|
|
|
rfa.setRollingPolicy(rollingPolicy);
|
|
|
|
|
rfa.start();
|
|
|
|
|
rootLogger.addAppender(rfa);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean useNotificationActions() {
|
|
|
|
|
return atLeastJellybean() && getBoolean(R.string.p_rmd_notif_actions_enabled, true);
|
|
|
|
|
}
|
|
|
|
|
@ -413,19 +345,6 @@ public class Preferences {
|
|
|
|
|
return directory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return export directory for tasks, or null if no SD card
|
|
|
|
|
*/
|
|
|
|
|
private static File defaultExportDirectory() {
|
|
|
|
|
String storageState = Environment.getExternalStorageState();
|
|
|
|
|
if (storageState.equals(Environment.MEDIA_MOUNTED)) {
|
|
|
|
|
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
|
|
|
|
|
path = path + "/astrid";
|
|
|
|
|
return new File(path);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long[] getVibrationPattern() {
|
|
|
|
|
int vibrationCount = getIntegerFromString(R.string.p_vibrate_count, 3);
|
|
|
|
|
long vibrationDuration = getIntegerFromString(R.string.p_vibrate_duration, 1000);
|
|
|
|
|
|