LogSettingActivity -> kotlin
This commit is contained in:
parent
949cde143a
commit
fe716bdc2e
|
@ -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<L.LogElement> 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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<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 { v -> element.setEnabled(enabled.isChecked) }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue