pluginDescription as constructor declaration only
This commit is contained in:
parent
fa8197f7f9
commit
5d975197bd
7 changed files with 12 additions and 20 deletions
|
@ -202,7 +202,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
menu.clear();
|
menu.clear();
|
||||||
for (PluginBase p : MainApp.getPluginsList()) {
|
for (PluginBase p : MainApp.getPluginsList()) {
|
||||||
pageAdapter.registerNewFragment(p);
|
pageAdapter.registerNewFragment(p);
|
||||||
if (p.hasFragment() && !p.isFragmentVisible() && p.isEnabled(p.pluginDescription.getType()) && !p.pluginDescription.neverVisible) {
|
if (p.hasFragment() && !p.isFragmentVisible() && p.isEnabled(p.getPluginDescription().getType()) && !p.getPluginDescription().neverVisible) {
|
||||||
MenuItem menuItem = menu.add(p.getName());
|
MenuItem menuItem = menu.add(p.getName());
|
||||||
menuItem.setCheckable(true);
|
menuItem.setCheckable(true);
|
||||||
menuItem.setOnMenuItemClickListener(item -> {
|
menuItem.setOnMenuItemClickListener(item -> {
|
||||||
|
|
|
@ -20,7 +20,8 @@ import org.slf4j.LoggerFactory
|
||||||
/**
|
/**
|
||||||
* Created by mike on 09.06.2016.
|
* Created by mike on 09.06.2016.
|
||||||
*/
|
*/
|
||||||
abstract class PluginBase(pluginDesc: PluginDescription) {
|
abstract class PluginBase(public val pluginDescription: PluginDescription) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val log = LoggerFactory.getLogger(L.CORE)
|
private val log = LoggerFactory.getLogger(L.CORE)
|
||||||
}
|
}
|
||||||
|
@ -29,17 +30,11 @@ abstract class PluginBase(pluginDesc: PluginDescription) {
|
||||||
NOT_INITIALIZED, ENABLED, DISABLED
|
NOT_INITIALIZED, ENABLED, DISABLED
|
||||||
}
|
}
|
||||||
|
|
||||||
lateinit var pluginDescription: PluginDescription // TODO: workaround to have pluginDescription accessible in child classes
|
|
||||||
|
|
||||||
private var state = State.NOT_INITIALIZED
|
private var state = State.NOT_INITIALIZED
|
||||||
private var fragmentVisible = false
|
private var fragmentVisible = false
|
||||||
// Specific plugin with more Interfaces
|
// Specific plugin with more Interfaces
|
||||||
protected var isProfileInterfaceEnabled = false
|
protected var isProfileInterfaceEnabled = false
|
||||||
|
|
||||||
init {
|
|
||||||
pluginDescription = pluginDesc
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default always calls invoke
|
// Default always calls invoke
|
||||||
// Plugins that have special constraints if they get switched to may override this method
|
// Plugins that have special constraints if they get switched to may override this method
|
||||||
open fun switchAllowed(newState: Boolean, activity: FragmentActivity?, type: PluginType) {
|
open fun switchAllowed(newState: Boolean, activity: FragmentActivity?, type: PluginType) {
|
||||||
|
|
|
@ -66,7 +66,6 @@ public class ConfigBuilderPlugin extends PluginBase {
|
||||||
|
|
||||||
private CommandQueue commandQueue = new CommandQueue();
|
private CommandQueue commandQueue = new CommandQueue();
|
||||||
|
|
||||||
private final Lazy<MainApp> mainApp;
|
|
||||||
private final Lazy<InsulinOrefRapidActingPlugin> insulinOrefRapidActingPlugin;
|
private final Lazy<InsulinOrefRapidActingPlugin> insulinOrefRapidActingPlugin;
|
||||||
private final Lazy<LocalProfilePlugin> localProfilePlugin;
|
private final Lazy<LocalProfilePlugin> localProfilePlugin;
|
||||||
private final Lazy<VirtualPumpPlugin> virtualPumpPlugin;
|
private final Lazy<VirtualPumpPlugin> virtualPumpPlugin;
|
||||||
|
@ -80,7 +79,6 @@ public class ConfigBuilderPlugin extends PluginBase {
|
||||||
* */
|
* */
|
||||||
@Inject
|
@Inject
|
||||||
public ConfigBuilderPlugin(
|
public ConfigBuilderPlugin(
|
||||||
Lazy<MainApp> mainApp,
|
|
||||||
Lazy<InsulinOrefRapidActingPlugin> insulinOrefRapidActingPlugin,
|
Lazy<InsulinOrefRapidActingPlugin> insulinOrefRapidActingPlugin,
|
||||||
Lazy<LocalProfilePlugin> localProfilePlugin,
|
Lazy<LocalProfilePlugin> localProfilePlugin,
|
||||||
Lazy<VirtualPumpPlugin> virtualPumpPlugin,
|
Lazy<VirtualPumpPlugin> virtualPumpPlugin,
|
||||||
|
@ -98,7 +96,6 @@ public class ConfigBuilderPlugin extends PluginBase {
|
||||||
.shortName(R.string.configbuilder_shortname)
|
.shortName(R.string.configbuilder_shortname)
|
||||||
.description(R.string.description_config_builder)
|
.description(R.string.description_config_builder)
|
||||||
);
|
);
|
||||||
this.mainApp = mainApp;
|
|
||||||
this.insulinOrefRapidActingPlugin = insulinOrefRapidActingPlugin;
|
this.insulinOrefRapidActingPlugin = insulinOrefRapidActingPlugin;
|
||||||
this.localProfilePlugin = localProfilePlugin;
|
this.localProfilePlugin = localProfilePlugin;
|
||||||
this.virtualPumpPlugin = virtualPumpPlugin;
|
this.virtualPumpPlugin = virtualPumpPlugin;
|
||||||
|
@ -118,7 +115,7 @@ public class ConfigBuilderPlugin extends PluginBase {
|
||||||
|
|
||||||
private void setAlwaysEnabledPluginsEnabled() {
|
private void setAlwaysEnabledPluginsEnabled() {
|
||||||
for (PluginBase plugin : pluginList) {
|
for (PluginBase plugin : pluginList) {
|
||||||
if (plugin.pluginDescription.alwaysEnabled)
|
if (plugin.getPluginDescription().alwaysEnabled)
|
||||||
plugin.setPluginEnabled(plugin.getType(), true);
|
plugin.setPluginEnabled(plugin.getType(), true);
|
||||||
}
|
}
|
||||||
storeSettings("setAlwaysEnabledPluginsEnabled");
|
storeSettings("setAlwaysEnabledPluginsEnabled");
|
||||||
|
@ -132,9 +129,9 @@ public class ConfigBuilderPlugin extends PluginBase {
|
||||||
|
|
||||||
for (PluginBase p : pluginList) {
|
for (PluginBase p : pluginList) {
|
||||||
PluginType type = p.getType();
|
PluginType type = p.getType();
|
||||||
if (p.pluginDescription.alwaysEnabled && p.pluginDescription.alwaysVisible)
|
if (p.getPluginDescription().alwaysEnabled && p.getPluginDescription().alwaysVisible)
|
||||||
continue;
|
continue;
|
||||||
if (p.pluginDescription.alwaysEnabled && p.pluginDescription.neverVisible)
|
if (p.getPluginDescription().alwaysEnabled && p.getPluginDescription().neverVisible)
|
||||||
continue;
|
continue;
|
||||||
savePref(p, type, true);
|
savePref(p, type, true);
|
||||||
if (type == PluginType.PUMP) {
|
if (type == PluginType.PUMP) {
|
||||||
|
@ -175,7 +172,7 @@ public class ConfigBuilderPlugin extends PluginBase {
|
||||||
String settingEnabled = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Enabled";
|
String settingEnabled = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Enabled";
|
||||||
if (sp.contains(settingEnabled))
|
if (sp.contains(settingEnabled))
|
||||||
p.setPluginEnabled(type, sp.getBoolean(settingEnabled, false));
|
p.setPluginEnabled(type, sp.getBoolean(settingEnabled, false));
|
||||||
else if (p.getType() == type && (p.pluginDescription.enableByDefault || p.pluginDescription.alwaysEnabled)) {
|
else if (p.getType() == type && (p.getPluginDescription().enableByDefault || p.getPluginDescription().alwaysEnabled)) {
|
||||||
p.setPluginEnabled(type, true);
|
p.setPluginEnabled(type, true);
|
||||||
}
|
}
|
||||||
aapsLogger.debug(LTag.CONFIGBUILDER, "Loaded: " + settingEnabled + ":" + p.isEnabled(type));
|
aapsLogger.debug(LTag.CONFIGBUILDER, "Loaded: " + settingEnabled + ":" + p.isEnabled(type));
|
||||||
|
@ -183,7 +180,7 @@ public class ConfigBuilderPlugin extends PluginBase {
|
||||||
String settingVisible = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Visible";
|
String settingVisible = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Visible";
|
||||||
if (sp.contains(settingVisible))
|
if (sp.contains(settingVisible))
|
||||||
p.setFragmentVisible(type, sp.getBoolean(settingVisible, false) && sp.getBoolean(settingEnabled, false));
|
p.setFragmentVisible(type, sp.getBoolean(settingVisible, false) && sp.getBoolean(settingEnabled, false));
|
||||||
else if (p.getType() == type && p.pluginDescription.visibleByDefault) {
|
else if (p.getType() == type && p.getPluginDescription().visibleByDefault) {
|
||||||
p.setFragmentVisible(type, true);
|
p.setFragmentVisible(type, true);
|
||||||
}
|
}
|
||||||
aapsLogger.debug(LTag.CONFIGBUILDER, "Loaded: " + settingVisible + ":" + p.isFragmentVisible());
|
aapsLogger.debug(LTag.CONFIGBUILDER, "Loaded: " + settingVisible + ":" + p.isFragmentVisible());
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class NSClientPlugin extends PluginBase {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Config.NSCLIENT) {
|
if (Config.NSCLIENT) {
|
||||||
pluginDescription.alwaysEnabled(true).visibleByDefault(true);
|
getPluginDescription().alwaysEnabled(true).visibleByDefault(true);
|
||||||
}
|
}
|
||||||
paused = SP.getBoolean(R.string.key_nsclientinternal_paused, false);
|
paused = SP.getBoolean(R.string.key_nsclientinternal_paused, false);
|
||||||
autoscroll = SP.getBoolean(R.string.key_nsclientinternal_autoscroll, true);
|
autoscroll = SP.getBoolean(R.string.key_nsclientinternal_autoscroll, true);
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
||||||
this.constraintChecker = constraintChecker;
|
this.constraintChecker = constraintChecker;
|
||||||
this.treatmentsPlugin = treatmentsPlugin;
|
this.treatmentsPlugin = treatmentsPlugin;
|
||||||
this.sp = sp;
|
this.sp = sp;
|
||||||
pluginDescription.description(R.string.description_pump_dana_r_korean);
|
getPluginDescription().description(R.string.description_pump_dana_r_korean);
|
||||||
|
|
||||||
useExtendedBoluses = sp.getBoolean(R.string.key_danar_useextended, false);
|
useExtendedBoluses = sp.getBoolean(R.string.key_danar_useextended, false);
|
||||||
pumpDescription.setPumpDescription(PumpType.DanaRKorean);
|
pumpDescription.setPumpDescription(PumpType.DanaRKorean);
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
||||||
this.constraintChecker = constraintChecker;
|
this.constraintChecker = constraintChecker;
|
||||||
this.treatmentsPlugin = treatmentsPlugin;
|
this.treatmentsPlugin = treatmentsPlugin;
|
||||||
this.sp = sp;
|
this.sp = sp;
|
||||||
pluginDescription.description(R.string.description_pump_dana_r_v2);
|
getPluginDescription().description(R.string.description_pump_dana_r_v2);
|
||||||
|
|
||||||
useExtendedBoluses = false;
|
useExtendedBoluses = false;
|
||||||
pumpDescription.setPumpDescription(PumpType.DanaRv2);
|
pumpDescription.setPumpDescription(PumpType.DanaRv2);
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class TabPageAdapter extends FragmentPagerAdapter {
|
||||||
@Nullable
|
@Nullable
|
||||||
public Fragment getItem(int position) {
|
public Fragment getItem(int position) {
|
||||||
//Fragment fragment = (Fragment) visibleFragmentList.get(position);
|
//Fragment fragment = (Fragment) visibleFragmentList.get(position);
|
||||||
return Fragment.instantiate(context, visibleFragmentList.get(position).pluginDescription.getFragmentClass());
|
return Fragment.instantiate(context, visibleFragmentList.get(position).getPluginDescription().getFragmentClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginBase getPluginAt(int position) {
|
public PluginBase getPluginAt(int position) {
|
||||||
|
|
Loading…
Reference in a new issue