Local profile clone support

This commit is contained in:
Milos Kozak 2019-11-28 23:18:42 +01:00
parent 8a75d4f6b9
commit 2dd7c758f4
5 changed files with 137 additions and 96 deletions

View file

@ -133,13 +133,26 @@ class LocalProfileFragment : Fragment() {
})
localprofile_profile_add.setOnClickListener {
LocalProfilePlugin.addNewProfile()
build()
if (LocalProfilePlugin.isEdited) {
activity?.let { OKDialog.show(it, "", MainApp.gs(R.string.saveorresetchangesfirst), null) }
} else {
LocalProfilePlugin.addNewProfile()
build()
}
}
localprofile_profile_clone.setOnClickListener {
if (LocalProfilePlugin.isEdited) {
activity?.let { OKDialog.show(it, "", MainApp.gs(R.string.saveorresetchangesfirst), null) }
} else {
LocalProfilePlugin.cloneProfile()
build()
}
}
localprofile_profile_remove.setOnClickListener {
activity?.let { activity ->
OKDialog.showConfirmation(activity, MainApp.gs(R.string.doyouwantswitchprofile), {
OKDialog.showConfirmation(activity, MainApp.gs(R.string.deletecurrentprofile), {
LocalProfilePlugin.removeCurrentProfile()
build()
}, null)
@ -149,10 +162,8 @@ class LocalProfileFragment : Fragment() {
// this is probably not possible because it leads to invalid profile
// if (!pumpDescription.isTempBasalCapable) localprofile_basal.visibility = View.GONE
localprofile_mgdl.isChecked = LocalProfilePlugin.currentProfile().mgdl
localprofile_mmol.isChecked = !LocalProfilePlugin.currentProfile().mgdl
localprofile_mgdl.isEnabled = false
localprofile_mmol.isEnabled = false
@Suppress("SETTEXTL18N")
localprofile_units.text = MainApp.gs(R.string.units_colon) + " " + (if (LocalProfilePlugin.currentProfile().mgdl) MainApp.gs(R.string.mgdl) else MainApp.gs(R.string.mmol))
localprofile_profileswitch.setOnClickListener {
// TODO: select in dialog LocalProfilePlugin.currentProfileIndex
@ -165,8 +176,8 @@ class LocalProfileFragment : Fragment() {
localprofile_reset.setOnClickListener {
LocalProfilePlugin.loadSettings()
localprofile_mgdl.isChecked = LocalProfilePlugin.currentProfile().mgdl
localprofile_mmol.isChecked = !LocalProfilePlugin.currentProfile().mgdl
@Suppress("SETTEXTL18N")
localprofile_units.text = MainApp.gs(R.string.units) + ": " + (if (LocalProfilePlugin.currentProfile().mgdl) MainApp.gs(R.string.mgdl) else MainApp.gs(R.string.mmol))
localprofile_dia.setParams(LocalProfilePlugin.currentProfile().dia, MIN_DIA, 12.0, 0.1, DecimalFormat("0.0"), false, localprofile_save, textWatch)
TimeListEdit(context, view, R.id.localprofile_ic, MainApp.gs(R.string.nsprofileview_ic_label) + ":", LocalProfilePlugin.currentProfile().ic, null, 0.5, 50.0, 0.1, DecimalFormat("0.0"), save)
TimeListEdit(context, view, R.id.localprofile_isf, MainApp.gs(R.string.nsprofileview_isf_label) + ":", LocalProfilePlugin.currentProfile().isf, null, 0.5, 500.0, 0.1, DecimalFormat("0.0"), save)

View file

@ -52,6 +52,19 @@ object LocalProfilePlugin : PluginBase(PluginDescription()
internal var basal: JSONArray? = null
internal var targetLow: JSONArray? = null
internal var targetHigh: JSONArray? = null
fun deepClone() : SingleProfile {
val sp = SingleProfile()
sp.name = name
sp.mgdl = mgdl
sp.dia = dia
sp.ic = JSONArray(ic.toString())
sp.isf = JSONArray(isf.toString())
sp.basal = JSONArray(basal.toString())
sp.targetLow = JSONArray(targetLow.toString())
sp.targetHigh = JSONArray(targetHigh.toString())
return sp
}
}
var isEdited: Boolean = false
@ -315,6 +328,16 @@ object LocalProfilePlugin : PluginBase(PluginDescription()
storeSettings()
}
fun cloneProfile() {
val p = profiles[currentProfileIndex].deepClone()
p.name = p.name + " copy"
profiles.add(p)
currentProfileIndex = profiles.size - 1
numOfProfiles++
createAndStoreConvertedProfile()
storeSettings()
}
fun removeCurrentProfile() {
profiles.removeAt(currentProfileIndex)
numOfProfiles--

Binary file not shown.

After

Width:  |  Height:  |  Size: 643 B

View file

@ -32,14 +32,47 @@
android:layout_marginStart="10dp"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:gravity="start"
android:orientation="horizontal">
<TextView
android:id="@+id/localprofile_units"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp"
android:text="@string/units_colon"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<ImageView
android:id="@+id/localprofile_profile_add"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="15dp"
android:src="@drawable/add"
android:contentDescription="@string/addnew" />
android:contentDescription="@string/addnew"
android:src="@drawable/add" />
<ImageView
android:id="@+id/localprofile_profile_clone"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="15dp"
android:contentDescription="@string/clone_label"
android:src="@drawable/clone" />
<ImageView
android:id="@+id/localprofile_profile_remove"
@ -47,70 +80,8 @@
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="15dp"
android:layout_marginEnd="10dp"
android:src="@drawable/remove"
android:contentDescription="@string/remove_label"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="start"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginBottom="10dp"
android:text="@string/profile_name"
android:labelFor="@+id/localprofile_name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/localprofile_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:ems="10"
android:inputType="text"
android:importantForAutofill="no" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="start"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginBottom="20dp"
android:text="@string/units_colon"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<RadioButton
android:id="@+id/localprofile_mgdl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mgdl" />
<RadioButton
android:id="@+id/localprofile_mmol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:text="@string/mmol" />
android:contentDescription="@string/remove_label"
android:src="@drawable/remove" />
</LinearLayout>
@ -180,35 +151,68 @@
android:id="@+id/localprofile_dia_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingTop="5dp">
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="10dp"
android:text="@string/dia"
android:textAppearance="?android:attr/textAppearanceMedium" />
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<info.nightscout.androidaps.utils.NumberPicker
android:id="@+id/localprofile_dia"
android:layout_width="130dp"
android:layout_height="40dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginBottom="10dp"
android:labelFor="@+id/localprofile_name"
android:text="@string/profile_name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
<EditText
android:id="@+id/localprofile_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:ems="10"
android:importantForAutofill="no"
android:inputType="text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/hours"
android:textAppearance="?android:attr/textAppearanceSmall" />
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="10dp"
android:text="@string/dia"
android:textAppearance="?android:attr/textAppearanceMedium" />
<info.nightscout.androidaps.utils.NumberPicker
android:id="@+id/localprofile_dia"
android:layout_width="130dp"
android:layout_height="40dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/hours"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/localprofile_ic"
android:layout_width="match_parent"

View file

@ -1649,5 +1649,8 @@
<string name="ic_short">IC</string>
<string name="isf_short">ISF</string>
<string name="target_short">TARG</string>
<string name="clone_label">CLONE</string>
<string name="saveorresetchangesfirst">Save or reset current changes first</string>
<string name="deletecurrentprofile">Delete current profile?</string>
</resources>