diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.java deleted file mode 100644 index 852554ed06..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.java +++ /dev/null @@ -1,80 +0,0 @@ -package info.nightscout.androidaps.plugins.general.maintenance.activities; - -import android.os.Bundle; -import androidx.appcompat.app.AppCompatActivity; -import android.view.View; -import android.widget.CheckBox; -import android.widget.LinearLayout; -import android.widget.TextView; - -import java.util.List; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import butterknife.Unbinder; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.logging.L; - -public class LogSettingActivity extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_logsetting); - ButterKnife.bind(this); - - createViewsForSettings(L.getLogElements()); - } - - private void createViewsForSettings(List elements) { - if (elements.size() == 0) return; - LinearLayout container = (LinearLayout) findViewById(R.id.logsettings_placeholder); - container.removeAllViews(); - for (L.LogElement element : elements) { - PluginViewHolder pluginViewHolder = new PluginViewHolder(element); - container.addView(pluginViewHolder.getBaseView()); - } - } - - @OnClick(R.id.logsettings_reset) - public void onResetClick() { - L.resetToDefaults(); - createViewsForSettings(L.getLogElements()); - } - - public class PluginViewHolder { - - private Unbinder unbinder; - private L.LogElement element; - - LinearLayout baseView; - @BindView(R.id.logsettings_description) - TextView description; - @BindView(R.id.logsettings_visibility) - CheckBox enabled; - - public PluginViewHolder(L.LogElement element) { - this.element = element; - baseView = (LinearLayout) getLayoutInflater().inflate(R.layout.logsettings_item, null); - unbinder = ButterKnife.bind(this, baseView); - - description.setText(element.name); - enabled.setChecked(element.enabled); - } - - public View getBaseView() { - return baseView; - } - - @OnClick(R.id.logsettings_visibility) - void onEnagledChanged() { - element.setEnabled(enabled.isChecked()); - } - - public void unbind() { - unbinder.unbind(); - } - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.kt new file mode 100644 index 0000000000..981e3557ee --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.kt @@ -0,0 +1,47 @@ +package info.nightscout.androidaps.plugins.general.maintenance.activities + +import android.os.Bundle +import android.view.View +import android.widget.CheckBox +import android.widget.LinearLayout +import android.widget.TextView +import info.nightscout.androidaps.R +import info.nightscout.androidaps.activities.NoSplashActivity +import info.nightscout.androidaps.logging.L +import kotlinx.android.synthetic.main.activity_logsetting.* + +class LogSettingActivity : NoSplashActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_logsetting) + + createViewsForSettings() + + logsettings_reset.setOnClickListener { + L.resetToDefaults() + createViewsForSettings() + } + } + + private fun createViewsForSettings() { + logsettings_placeholder.removeAllViews() + for (element in L.getLogElements()) { + val logViewHolder = LogViewHolder(element) + logsettings_placeholder.addView(logViewHolder.baseView) + } + + } + + internal inner class LogViewHolder(element: L.LogElement) { + var baseView: LinearLayout = layoutInflater.inflate(R.layout.logsettings_item, null) as LinearLayout + + init { + (baseView.findViewById(R.id.logsettings_description) as TextView).text = element.name + val enabled = baseView.findViewById(R.id.logsettings_visibility) + enabled.isChecked = element.enabled + enabled.setOnClickListener { v -> element.setEnabled(enabled.isChecked) } + } + + } +}