LocalProfile tweaking switching profiles
This commit is contained in:
parent
b6b748fc4a
commit
3397659320
|
@ -65,7 +65,7 @@ class LocalProfileFragment : Fragment() {
|
||||||
|
|
||||||
fun build() {
|
fun build() {
|
||||||
val pumpDescription = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription ?: return
|
val pumpDescription = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription ?: return
|
||||||
val units = ProfileFunctions.getSystemUnits()
|
val units = if (LocalProfilePlugin.currentProfile().mgdl) Constants.MGDL else Constants.MMOL
|
||||||
|
|
||||||
localprofile_name.setText(LocalProfilePlugin.currentProfile().name)
|
localprofile_name.setText(LocalProfilePlugin.currentProfile().name)
|
||||||
localprofile_dia.setParams(LocalProfilePlugin.currentProfile().dia, HardLimits.MINDIA, HardLimits.MAXDIA, 0.1, DecimalFormat("0.0"), false, localprofile_save, textWatch)
|
localprofile_dia.setParams(LocalProfilePlugin.currentProfile().dia, HardLimits.MINDIA, HardLimits.MAXDIA, 0.1, DecimalFormat("0.0"), false, localprofile_save, textWatch)
|
||||||
|
@ -94,11 +94,13 @@ class LocalProfileFragment : Fragment() {
|
||||||
|
|
||||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||||
if (LocalProfilePlugin.isEdited) {
|
if (LocalProfilePlugin.isEdited) {
|
||||||
context?.let { context ->
|
activity?.let { activity ->
|
||||||
OKDialog.show(context, MainApp.gs(R.string.confirmation), MainApp.gs(R.string.doyouwantswitchprofile)) {
|
OKDialog.showConfirmation(activity, MainApp.gs(R.string.doyouwantswitchprofile), {
|
||||||
LocalProfilePlugin.currentProfileIndex = position
|
LocalProfilePlugin.currentProfileIndex = position
|
||||||
build()
|
build()
|
||||||
}
|
}, {
|
||||||
|
spinner?.setSelection(LocalProfilePlugin.currentProfileIndex)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LocalProfilePlugin.currentProfileIndex = position
|
LocalProfilePlugin.currentProfileIndex = position
|
||||||
|
@ -113,8 +115,12 @@ class LocalProfileFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
localprofile_profile_remove.setOnClickListener {
|
localprofile_profile_remove.setOnClickListener {
|
||||||
LocalProfilePlugin.removeCurrentProfile()
|
activity?.let { activity ->
|
||||||
build()
|
OKDialog.showConfirmation(activity, MainApp.gs(R.string.doyouwantswitchprofile), {
|
||||||
|
LocalProfilePlugin.removeCurrentProfile()
|
||||||
|
build()
|
||||||
|
}, null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is probably not possible because it leads to invalid profile
|
// this is probably not possible because it leads to invalid profile
|
||||||
|
|
|
@ -83,4 +83,24 @@ public class OKDialog {
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void showConfirmation(final Activity activity, String message, final Runnable ok, final Runnable cancel) {
|
||||||
|
AlertDialog alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme))
|
||||||
|
.setMessage(message)
|
||||||
|
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||||
|
dialog.dismiss();
|
||||||
|
if (ok != null) {
|
||||||
|
SystemClock.sleep(100);
|
||||||
|
activity.runOnUiThread(ok);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
|
||||||
|
dialog.dismiss();
|
||||||
|
if (cancel != null) {
|
||||||
|
SystemClock.sleep(100);
|
||||||
|
activity.runOnUiThread(cancel);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue