pluginDescription as constructor declaration only

This commit is contained in:
AdrianLxM 2020-01-06 15:51:10 +01:00
parent fa8197f7f9
commit 5d975197bd
7 changed files with 12 additions and 20 deletions

View file

@ -202,7 +202,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
menu.clear();
for (PluginBase p : MainApp.getPluginsList()) {
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.setCheckable(true);
menuItem.setOnMenuItemClickListener(item -> {

View file

@ -20,7 +20,8 @@ import org.slf4j.LoggerFactory
/**
* Created by mike on 09.06.2016.
*/
abstract class PluginBase(pluginDesc: PluginDescription) {
abstract class PluginBase(public val pluginDescription: PluginDescription) {
companion object {
private val log = LoggerFactory.getLogger(L.CORE)
}
@ -29,17 +30,11 @@ abstract class PluginBase(pluginDesc: PluginDescription) {
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 fragmentVisible = false
// Specific plugin with more Interfaces
protected var isProfileInterfaceEnabled = false
init {
pluginDescription = pluginDesc
}
// Default always calls invoke
// Plugins that have special constraints if they get switched to may override this method
open fun switchAllowed(newState: Boolean, activity: FragmentActivity?, type: PluginType) {

View file

@ -66,7 +66,6 @@ public class ConfigBuilderPlugin extends PluginBase {
private CommandQueue commandQueue = new CommandQueue();
private final Lazy<MainApp> mainApp;
private final Lazy<InsulinOrefRapidActingPlugin> insulinOrefRapidActingPlugin;
private final Lazy<LocalProfilePlugin> localProfilePlugin;
private final Lazy<VirtualPumpPlugin> virtualPumpPlugin;
@ -80,7 +79,6 @@ public class ConfigBuilderPlugin extends PluginBase {
* */
@Inject
public ConfigBuilderPlugin(
Lazy<MainApp> mainApp,
Lazy<InsulinOrefRapidActingPlugin> insulinOrefRapidActingPlugin,
Lazy<LocalProfilePlugin> localProfilePlugin,
Lazy<VirtualPumpPlugin> virtualPumpPlugin,
@ -98,7 +96,6 @@ public class ConfigBuilderPlugin extends PluginBase {
.shortName(R.string.configbuilder_shortname)
.description(R.string.description_config_builder)
);
this.mainApp = mainApp;
this.insulinOrefRapidActingPlugin = insulinOrefRapidActingPlugin;
this.localProfilePlugin = localProfilePlugin;
this.virtualPumpPlugin = virtualPumpPlugin;
@ -118,7 +115,7 @@ public class ConfigBuilderPlugin extends PluginBase {
private void setAlwaysEnabledPluginsEnabled() {
for (PluginBase plugin : pluginList) {
if (plugin.pluginDescription.alwaysEnabled)
if (plugin.getPluginDescription().alwaysEnabled)
plugin.setPluginEnabled(plugin.getType(), true);
}
storeSettings("setAlwaysEnabledPluginsEnabled");
@ -132,9 +129,9 @@ public class ConfigBuilderPlugin extends PluginBase {
for (PluginBase p : pluginList) {
PluginType type = p.getType();
if (p.pluginDescription.alwaysEnabled && p.pluginDescription.alwaysVisible)
if (p.getPluginDescription().alwaysEnabled && p.getPluginDescription().alwaysVisible)
continue;
if (p.pluginDescription.alwaysEnabled && p.pluginDescription.neverVisible)
if (p.getPluginDescription().alwaysEnabled && p.getPluginDescription().neverVisible)
continue;
savePref(p, type, true);
if (type == PluginType.PUMP) {
@ -175,7 +172,7 @@ public class ConfigBuilderPlugin extends PluginBase {
String settingEnabled = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Enabled";
if (sp.contains(settingEnabled))
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);
}
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";
if (sp.contains(settingVisible))
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);
}
aapsLogger.debug(LTag.CONFIGBUILDER, "Loaded: " + settingVisible + ":" + p.isFragmentVisible());

View file

@ -82,7 +82,7 @@ public class NSClientPlugin extends PluginBase {
);
if (Config.NSCLIENT) {
pluginDescription.alwaysEnabled(true).visibleByDefault(true);
getPluginDescription().alwaysEnabled(true).visibleByDefault(true);
}
paused = SP.getBoolean(R.string.key_nsclientinternal_paused, false);
autoscroll = SP.getBoolean(R.string.key_nsclientinternal_autoscroll, true);

View file

@ -80,7 +80,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
this.constraintChecker = constraintChecker;
this.treatmentsPlugin = treatmentsPlugin;
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);
pumpDescription.setPumpDescription(PumpType.DanaRKorean);

View file

@ -80,7 +80,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
this.constraintChecker = constraintChecker;
this.treatmentsPlugin = treatmentsPlugin;
this.sp = sp;
pluginDescription.description(R.string.description_pump_dana_r_v2);
getPluginDescription().description(R.string.description_pump_dana_r_v2);
useExtendedBoluses = false;
pumpDescription.setPumpDescription(PumpType.DanaRv2);

View file

@ -37,7 +37,7 @@ public class TabPageAdapter extends FragmentPagerAdapter {
@Nullable
public Fragment getItem(int 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) {