Merge branch 'dagger3' of https://github.com/MilosKozak/AndroidAPS into dagger3
This commit is contained in:
commit
a2d2dd38e3
|
@ -1,133 +0,0 @@
|
|||
package info.nightscout.androidaps.logging;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
public class L {
|
||||
|
||||
public static class LogElement {
|
||||
public String name;
|
||||
boolean defaultValue;
|
||||
public boolean enabled;
|
||||
boolean requiresRestart = false;
|
||||
|
||||
LogElement(String name, boolean defaultValue) {
|
||||
this.name = name;
|
||||
this.defaultValue = defaultValue;
|
||||
enabled = SP.getBoolean(getSPName(), defaultValue);
|
||||
}
|
||||
|
||||
LogElement(String name, boolean defaultValue, boolean requiresRestart) {
|
||||
this.name = name;
|
||||
this.defaultValue = defaultValue;
|
||||
this.requiresRestart = requiresRestart;
|
||||
enabled = SP.getBoolean(getSPName(), defaultValue);
|
||||
}
|
||||
|
||||
LogElement(boolean defaultValue) {
|
||||
this.name = "NONEXISTING";
|
||||
this.defaultValue = defaultValue;
|
||||
enabled = defaultValue;
|
||||
}
|
||||
|
||||
private String getSPName() {
|
||||
return "log_" + name;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
SP.putBoolean(getSPName(), enabled);
|
||||
}
|
||||
|
||||
void resetToDefault() {
|
||||
setEnabled(defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<LogElement> logElements;
|
||||
|
||||
static {
|
||||
initialize();
|
||||
}
|
||||
|
||||
private static LogElement findByName(String name) {
|
||||
for (LogElement element : logElements) {
|
||||
if (element.name.equals(name))
|
||||
return element;
|
||||
}
|
||||
return new LogElement(false);
|
||||
}
|
||||
|
||||
public static boolean isEnabled(String name) {
|
||||
return findByName(name).enabled;
|
||||
}
|
||||
|
||||
public static List<LogElement> getLogElements() {
|
||||
return logElements;
|
||||
}
|
||||
|
||||
public static void resetToDefaults() {
|
||||
for (LogElement element : logElements) {
|
||||
element.resetToDefault();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final String CORE = "CORE";
|
||||
public static final String AUTOSENS = "AUTOSENS";
|
||||
public static final String AUTOMATION = "AUTOMATION";
|
||||
public static final String EVENTS = "EVENTS";
|
||||
public static final String GLUCOSE = "GLUCOSE";
|
||||
public static final String BGSOURCE = "BGSOURCE";
|
||||
public static final String OVERVIEW = "OVERVIEW";
|
||||
public static final String NOTIFICATION = "NOTIFICATION";
|
||||
public static final String DATASERVICE = "DATASERVICE";
|
||||
public static final String DATABASE = "DATABASE";
|
||||
public static final String DATAFOOD = "DATAFOOD";
|
||||
public static final String DATATREATMENTS = "DATATREATMENTS";
|
||||
public static final String NSCLIENT = "NSCLIENT";
|
||||
public static final String TIDEPOOL = "TIDEPOOL";
|
||||
public static final String CONSTRAINTS = "CONSTRAINTS";
|
||||
public static final String PUMP = "PUMP";
|
||||
public static final String PUMPQUEUE = "PUMPQUEUE";
|
||||
public static final String PUMPCOMM = "PUMPCOMM";
|
||||
public static final String PUMPBTCOMM = "PUMPBTCOMM";
|
||||
public static final String APS = "APS";
|
||||
public static final String PROFILE = "PROFILE";
|
||||
public static final String CONFIGBUILDER = "CONFIGBUILDER";
|
||||
public static final String UI = "UI";
|
||||
public static final String LOCATION = "LOCATION";
|
||||
public static final String SMS = "SMS";
|
||||
|
||||
private static void initialize() {
|
||||
logElements = new ArrayList<>();
|
||||
logElements.add(new LogElement(APS, true));
|
||||
logElements.add(new LogElement(AUTOMATION, true));
|
||||
logElements.add(new LogElement(AUTOSENS, false));
|
||||
logElements.add(new LogElement(BGSOURCE, true));
|
||||
logElements.add(new LogElement(GLUCOSE, false));
|
||||
logElements.add(new LogElement(CONFIGBUILDER, false));
|
||||
logElements.add(new LogElement(CONSTRAINTS, true));
|
||||
logElements.add(new LogElement(CORE, true));
|
||||
logElements.add(new LogElement(DATABASE, true));
|
||||
logElements.add(new LogElement(DATAFOOD, false));
|
||||
logElements.add(new LogElement(DATASERVICE, true));
|
||||
logElements.add(new LogElement(DATATREATMENTS, true));
|
||||
logElements.add(new LogElement(EVENTS, false, true));
|
||||
logElements.add(new LogElement(LOCATION, true));
|
||||
logElements.add(new LogElement(NOTIFICATION, true));
|
||||
logElements.add(new LogElement(NSCLIENT, true));
|
||||
logElements.add(new LogElement(TIDEPOOL, true));
|
||||
logElements.add(new LogElement(OVERVIEW, true));
|
||||
logElements.add(new LogElement(PROFILE, true));
|
||||
logElements.add(new LogElement(PUMP, true));
|
||||
logElements.add(new LogElement(PUMPBTCOMM, false));
|
||||
logElements.add(new LogElement(PUMPCOMM, true));
|
||||
logElements.add(new LogElement(PUMPQUEUE, true));
|
||||
logElements.add(new LogElement(SMS, true));
|
||||
logElements.add(new LogElement(UI, true));
|
||||
}
|
||||
|
||||
}
|
121
app/src/main/java/info/nightscout/androidaps/logging/L.kt
Normal file
121
app/src/main/java/info/nightscout/androidaps/logging/L.kt
Normal file
|
@ -0,0 +1,121 @@
|
|||
package info.nightscout.androidaps.logging
|
||||
|
||||
import info.nightscout.androidaps.utils.SP
|
||||
import java.util.*
|
||||
|
||||
object L {
|
||||
private var logElements: MutableList<LogElement> = ArrayList()
|
||||
|
||||
const val CORE = "CORE"
|
||||
const val AUTOSENS = "AUTOSENS"
|
||||
const val AUTOMATION = "AUTOMATION"
|
||||
const val EVENTS = "EVENTS"
|
||||
const val GLUCOSE = "GLUCOSE"
|
||||
const val BGSOURCE = "BGSOURCE"
|
||||
const val OVERVIEW = "OVERVIEW"
|
||||
const val NOTIFICATION = "NOTIFICATION"
|
||||
const val DATASERVICE = "DATASERVICE"
|
||||
const val DATABASE = "DATABASE"
|
||||
const val DATAFOOD = "DATAFOOD"
|
||||
const val DATATREATMENTS = "DATATREATMENTS"
|
||||
const val NSCLIENT = "NSCLIENT"
|
||||
const val TIDEPOOL = "TIDEPOOL"
|
||||
const val CONSTRAINTS = "CONSTRAINTS"
|
||||
const val PUMP = "PUMP"
|
||||
const val PUMPQUEUE = "PUMPQUEUE"
|
||||
const val PUMPCOMM = "PUMPCOMM"
|
||||
const val PUMPBTCOMM = "PUMPBTCOMM"
|
||||
const val APS = "APS"
|
||||
const val PROFILE = "PROFILE"
|
||||
const val CONFIGBUILDER = "CONFIGBUILDER"
|
||||
const val UI = "UI"
|
||||
const val LOCATION = "LOCATION"
|
||||
const val SMS = "SMS"
|
||||
|
||||
init {
|
||||
logElements.add(LogElement(APS, defaultValue = true))
|
||||
logElements.add(LogElement(AUTOMATION, defaultValue = true))
|
||||
logElements.add(LogElement(AUTOSENS, defaultValue = false))
|
||||
logElements.add(LogElement(BGSOURCE, defaultValue = true))
|
||||
logElements.add(LogElement(GLUCOSE, defaultValue = false))
|
||||
logElements.add(LogElement(CONFIGBUILDER, defaultValue = false))
|
||||
logElements.add(LogElement(CONSTRAINTS, defaultValue = true))
|
||||
logElements.add(LogElement(CORE, defaultValue = true))
|
||||
logElements.add(LogElement(DATABASE, defaultValue = true))
|
||||
logElements.add(LogElement(DATAFOOD, false))
|
||||
logElements.add(LogElement(DATASERVICE, true))
|
||||
logElements.add(LogElement(DATATREATMENTS, true))
|
||||
logElements.add(LogElement(EVENTS, false, requiresRestart = true))
|
||||
logElements.add(LogElement(LOCATION, true))
|
||||
logElements.add(LogElement(NOTIFICATION, true))
|
||||
logElements.add(LogElement(NSCLIENT, true))
|
||||
logElements.add(LogElement(TIDEPOOL, true))
|
||||
logElements.add(LogElement(OVERVIEW, true))
|
||||
logElements.add(LogElement(PROFILE, true))
|
||||
logElements.add(LogElement(PUMP, true))
|
||||
logElements.add(LogElement(PUMPBTCOMM, false))
|
||||
logElements.add(LogElement(PUMPCOMM, true))
|
||||
logElements.add(LogElement(PUMPQUEUE, true))
|
||||
logElements.add(LogElement(SMS, true))
|
||||
logElements.add(LogElement(UI, true))
|
||||
}
|
||||
|
||||
private fun findByName(name: String): LogElement {
|
||||
for (element in logElements) {
|
||||
if (element.name == name) return element
|
||||
}
|
||||
return LogElement(false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isEnabled(name: String): Boolean {
|
||||
return findByName(name).enabled
|
||||
}
|
||||
|
||||
fun getLogElements(): List<LogElement> {
|
||||
return logElements
|
||||
}
|
||||
|
||||
fun resetToDefaults() {
|
||||
for (element in logElements) {
|
||||
element.resetToDefault()
|
||||
}
|
||||
}
|
||||
|
||||
class LogElement {
|
||||
var name: String
|
||||
var defaultValue: Boolean
|
||||
var enabled: Boolean
|
||||
private var requiresRestart = false
|
||||
|
||||
internal constructor(name: String, defaultValue: Boolean) {
|
||||
this.name = name
|
||||
this.defaultValue = defaultValue
|
||||
enabled = SP.getBoolean(getSPName(), defaultValue)
|
||||
}
|
||||
|
||||
internal constructor(name: String, defaultValue: Boolean, requiresRestart: Boolean) {
|
||||
this.name = name
|
||||
this.defaultValue = defaultValue
|
||||
this.requiresRestart = requiresRestart
|
||||
enabled = SP.getBoolean(getSPName(), defaultValue)
|
||||
}
|
||||
|
||||
internal constructor(defaultValue: Boolean) {
|
||||
name = "NONEXISTING"
|
||||
this.defaultValue = defaultValue
|
||||
enabled = defaultValue
|
||||
}
|
||||
|
||||
private fun getSPName(): String = "log_$name"
|
||||
|
||||
fun enable(enabled: Boolean) {
|
||||
this.enabled = enabled
|
||||
SP.putBoolean(getSPName(), enabled)
|
||||
}
|
||||
|
||||
fun resetToDefault() {
|
||||
enable(defaultValue)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -40,7 +40,7 @@ class LogSettingActivity : NoSplashAppCompatActivity() {
|
|||
(baseView.findViewById<View>(R.id.logsettings_description) as TextView).text = element.name
|
||||
val enabled = baseView.findViewById<CheckBox>(R.id.logsettings_visibility)
|
||||
enabled.isChecked = element.enabled
|
||||
enabled.setOnClickListener { element.setEnabled(enabled.isChecked) }
|
||||
enabled.setOnClickListener { element.enable(enabled.isChecked) }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue