Confirmation dialogs cleanup

This commit is contained in:
Milos Kozak 2019-12-22 21:37:26 +01:00
parent 808dd92de1
commit 91000dc1bb
46 changed files with 867 additions and 1114 deletions

View file

@ -42,7 +42,6 @@ import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
import info.nightscout.androidaps.activities.PreferencesActivity;
import info.nightscout.androidaps.activities.SingleFragmentActivity;
import info.nightscout.androidaps.activities.StatsActivity;
import info.nightscout.androidaps.activities.SurveyActivity;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRebuildTabs;
@ -58,6 +57,7 @@ import info.nightscout.androidaps.tabs.TabPageAdapter;
import info.nightscout.androidaps.utils.AndroidPermission;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.LocaleHelper;
import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.PasswordProtection;
import info.nightscout.androidaps.utils.SP;
import io.reactivex.android.schedulers.AndroidSchedulers;
@ -239,10 +239,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
switch (requestCode) {
case AndroidPermission.CASE_STORAGE:
//show dialog after permission is granted
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setMessage(R.string.alert_dialog_storage_permission_text);
alert.setPositiveButton(R.string.ok, null);
alert.show();
OKDialog.show(this, "", MainApp.gs(R.string.alert_dialog_storage_permission_text));
break;
case AndroidPermission.CASE_LOCATION:
case AndroidPermission.CASE_SMS:

View file

@ -89,7 +89,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
return;
}
if (key.equals(MainApp.gs(R.string.key_openapsama_useautosens)) && SP.getBoolean(R.string.key_openapsama_useautosens, false)) {
OKDialog.show(this, MainApp.gs(R.string.configbuilder_sensitivity), MainApp.gs(R.string.sensitivity_warning), null);
OKDialog.show(this, MainApp.gs(R.string.configbuilder_sensitivity), MainApp.gs(R.string.sensitivity_warning));
}
updatePrefSummary(myPreferenceFragment.findPreference(key));
}

View file

@ -1,60 +0,0 @@
package info.nightscout.androidaps.activities;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.utils.PasswordProtection;
public class SingleFragmentActivity extends AppCompatActivity {
private PluginBase plugin;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_fragment);
this.plugin = MainApp.getPluginsList().get(getIntent().getIntExtra("plugin", -1));
setTitle(plugin.getName());
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout,
Fragment.instantiate(this, plugin.pluginDescription.getFragmentClass())).commit();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
else if (item.getItemId() == R.id.nav_plugin_preferences) {
PasswordProtection.QueryPassword(this, R.string.settings_password, "settings_password", () -> {
Intent i = new Intent(this, PreferencesActivity.class);
i.putExtra("id", plugin.getPreferencesId());
startActivity(i);
}, null);
return true;
}
return false;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (plugin.getPreferencesId() != -1)
getMenuInflater().inflate(R.menu.menu_single_fragment, menu);
return super.onCreateOptionsMenu(menu);
}
}

View file

@ -0,0 +1,53 @@
package info.nightscout.androidaps.activities
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.utils.LocaleHelper
import info.nightscout.androidaps.utils.PasswordProtection
class SingleFragmentActivity : AppCompatActivity() {
private var plugin: PluginBase? = null
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_single_fragment)
plugin = MainApp.getPluginsList()[intent.getIntExtra("plugin", -1)]
title = plugin?.name
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
if (savedInstanceState == null) {
supportFragmentManager.beginTransaction().replace(R.id.frame_layout,
supportFragmentManager.fragmentFactory.instantiate(ClassLoader.getSystemClassLoader(), plugin?.pluginDescription?.fragmentClass!!)).commit()
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
finish()
return true
} else if (item.itemId == R.id.nav_plugin_preferences) {
PasswordProtection.QueryPassword(this, R.string.settings_password, "settings_password", Runnable {
val i = Intent(this, PreferencesActivity::class.java)
i.putExtra("id", plugin?.preferencesId)
startActivity(i)
}, null)
return true
}
return false
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
if (plugin?.preferencesId != -1) menuInflater.inflate(R.menu.menu_single_fragment, menu)
return super.onCreateOptionsMenu(menu)
}
public override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(LocaleHelper.wrap(newBase))
}
}

View file

@ -22,10 +22,10 @@ class StatsActivity : NoSplashAppCompatActivity() {
ok.setOnClickListener { finish() }
stats_reset.setOnClickListener {
OKDialog.showConfirmation(this, MainApp.gs(R.string.doyouwantresetstats)) {
OKDialog.showConfirmation(this, MainApp.gs(R.string.doyouwantresetstats), Runnable {
ActivityMonitor.reset()
recreate()
}
})
}
}
}

View file

@ -52,16 +52,17 @@ class CalibrationDialog : DialogFragmentWithDate() {
val unitLabel = if (units == Constants.MMOL) MainApp.gs(R.string.mmol) else MainApp.gs(R.string.mgdl)
val actions: LinkedList<String?> = LinkedList()
val bg = overview_calibration_bg.value
actions.add("<b>" + MainApp.gs(R.string.overview_calibration) + "</b>")
actions.add(MainApp.gs(R.string.treatments_wizard_bg_label) + ": " + Profile.toCurrentUnitsString(bg) + " " + unitLabel)
if (bg > 0) {
activity?.let { activity ->
OKDialog.showConfirmation(activity, HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions))) {
OKDialog.showConfirmation(activity, MainApp.gs(R.string.overview_calibration), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
XdripCalibrations.confirmAndSendCalibration(bg, context)
}
})
}
} else
OKDialog.show(activity, "", MainApp.gs(R.string.no_action_selected), null)
activity?.let { activity ->
OKDialog.show(activity, MainApp.gs(R.string.overview_calibration), MainApp.gs(R.string.no_action_selected))
}
return true
}
}

View file

@ -172,7 +172,7 @@ class CarbsDialog : DialogFragmentWithDate() {
if (carbsAfterConstraints > 0 || activitySelected || eatingSoonSelected || hypoSelected) {
activity?.let { activity ->
OKDialog.showConfirmation(activity, HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions))) {
OKDialog.showConfirmation(activity, MainApp.gs(R.string.carbs), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
if (activitySelected) {
val tempTarget = TempTarget()
.date(System.currentTimeMillis())
@ -209,10 +209,12 @@ class CarbsDialog : DialogFragmentWithDate() {
NSUpload.uploadEvent(CareportalEvent.NOTE, DateUtil.now() - 2000, MainApp.gs(R.string.generated_ecarbs_note, carbsAfterConstraints, duration, timeOffset))
}
}
}
}, null)
}
} else
OKDialog.show(activity, "", MainApp.gs(R.string.no_action_selected), null)
activity?.let { activity ->
OKDialog.show(activity, MainApp.gs(R.string.carbs), MainApp.gs(R.string.no_action_selected))
}
return true
}
}

View file

@ -109,7 +109,6 @@ class CareDialog : DialogFragmentWithDate() {
val json = JSONObject()
val actions: LinkedList<String> = LinkedList()
actions.add("<b>" + MainApp.gs(event) + "</b>")
if (options == EventType.BGCHECK) {
val type =
when {
@ -141,10 +140,10 @@ class CareDialog : DialogFragmentWithDate() {
json.put("enteredBy", enteredBy)
activity?.let { activity ->
OKDialog.showConfirmation(activity, HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions))) {
OKDialog.showConfirmation(activity, MainApp.gs(event), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
MainApp.getDbHelper().createCareportalEventFromJsonIfNotExists(json)
NSUpload.uploadCareportalEntryToNS(json)
}
}, null)
}
return true
}

View file

@ -55,7 +55,6 @@ class ExtendedBolusDialog : DialogFragmentWithDate() {
val insulin = SafeParse.stringToDouble(actions_extendedbolus_insulin.text)
val durationInMinutes = SafeParse.stringToInt(actions_extendedbolus_duration.text)
val actions: LinkedList<String> = LinkedList()
actions.add("<b>" + MainApp.gs(R.string.setextendedbolusquestion) + "</b>")
val insulinAfterConstraint = MainApp.getConstraintChecker().applyExtendedBolusConstraints(Constraint(insulin)).value()
actions.add(MainApp.gs(R.string.formatinsulinunits, insulinAfterConstraint))
actions.add(MainApp.gs(R.string.duration) + ": " + MainApp.gs(R.string.format_mins, durationInMinutes))
@ -63,7 +62,7 @@ class ExtendedBolusDialog : DialogFragmentWithDate() {
actions.add("<font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.constraintapllied) + "</font>")
activity?.let { activity ->
OKDialog.showConfirmation(activity, HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions))) {
OKDialog.showConfirmation(activity, MainApp.gs(R.string.extended_bolus), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
ConfigBuilderPlugin.getPlugin().commandQueue.extendedBolus(insulinAfterConstraint, durationInMinutes, object : Callback() {
override fun run() {
if (!result.success) {
@ -76,7 +75,7 @@ class ExtendedBolusDialog : DialogFragmentWithDate() {
}
}
})
}
}, null)
}
return true
}

View file

@ -96,7 +96,7 @@ class FillDialog : DialogFragmentWithDate() {
if (insulinAfterConstraints > 0 || fill_catheter_change.isChecked || fill_cartridge_change.isChecked) {
activity?.let { activity ->
OKDialog.showConfirmation(activity, HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions))) {
OKDialog.showConfirmation(activity, MainApp.gs(R.string.primefill), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
if (insulinAfterConstraints > 0) {
val detailedBolusInfo = DetailedBolusInfo()
detailedBolusInfo.insulin = insulinAfterConstraints
@ -119,10 +119,12 @@ class FillDialog : DialogFragmentWithDate() {
}
if (siteChange) NSUpload.uploadEvent(CareportalEvent.SITECHANGE, eventTime, notes)
if (insulinChange) NSUpload.uploadEvent(CareportalEvent.INSULINCHANGE, eventTime + 1000, notes)
}
}, null)
}
} else {
OKDialog.show(activity, "", MainApp.gs(R.string.no_action_selected), null)
activity?.let { activity ->
OKDialog.show(activity, MainApp.gs(R.string.primefill), MainApp.gs(R.string.no_action_selected))
}
}
dismiss()
return true

View file

@ -145,7 +145,7 @@ class InsulinDialog : DialogFragmentWithDate() {
if (insulinAfterConstraints > 0 || eatingSoonChecked) {
activity?.let { activity ->
OKDialog.showConfirmation(activity, HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions))) {
OKDialog.showConfirmation(activity, MainApp.gs(R.string.bolus), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
if (eatingSoonChecked) {
val tempTarget = TempTarget()
.date(System.currentTimeMillis())
@ -182,10 +182,12 @@ class InsulinDialog : DialogFragmentWithDate() {
})
}
}
}
})
}
} else
OKDialog.show(activity, "", MainApp.gs(R.string.no_action_selected), null)
activity?.let { activity ->
OKDialog.show(activity, MainApp.gs(R.string.bolus), MainApp.gs(R.string.no_action_selected))
}
return true
}
}

View file

@ -96,9 +96,9 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
actions.add(MainApp.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime))
activity?.let { activity ->
OKDialog.showConfirmation(activity, HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions))) {
OKDialog.showConfirmation(activity, MainApp.gs(R.string.careportal_profileswitch), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
ProfileFunctions.doProfileSwitch(profileStore, profile, duration.toInt(), percent, timeShift, eventTime)
}
})
}
return true
}

View file

@ -75,23 +75,22 @@ class TempBasalDialog : DialogFragmentWithDate() {
val durationInMinutes = SafeParse.stringToInt(actions_tempbasal_duration.text)
val profile = ProfileFunctions.getInstance().profile ?: return false
val actions: LinkedList<String> = LinkedList()
actions.add("<b>" + MainApp.gs(R.string.setbasalquestion) + "</b>")
if (isPercentPump) {
val basalPercentInput = SafeParse.stringToInt(actions_tempbasal_basalpercentinput.text)
percent = MainApp.getConstraintChecker().applyBasalPercentConstraints(Constraint(basalPercentInput), profile).value()
actions.add("$percent%")
actions.add(MainApp.gs(R.string.pump_tempbasal_label)+ ": $percent%")
actions.add(MainApp.gs(R.string.duration) + ": " + MainApp.gs(R.string.format_mins, durationInMinutes))
if (percent != basalPercentInput) actions.add(MainApp.gs(R.string.constraintapllied))
} else {
val basalAbsoluteInput = SafeParse.stringToDouble(actions_tempbasal_basalabsoluteinput.text)
absolute = MainApp.getConstraintChecker().applyBasalConstraints(Constraint(basalAbsoluteInput), profile).value()
actions.add(MainApp.gs(R.string.pump_basebasalrate, absolute))
actions.add(MainApp.gs(R.string.pump_tempbasal_label)+ ": " + MainApp.gs(R.string.pump_basebasalrate, absolute))
actions.add(MainApp.gs(R.string.duration) + ": " + MainApp.gs(R.string.format_mins, durationInMinutes))
if (abs(absolute - basalAbsoluteInput) > 0.01)
actions.add("<font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.constraintapllied) + "</font>")
}
activity?.let { activity ->
OKDialog.showConfirmation(activity, HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions))) {
OKDialog.showConfirmation(activity, MainApp.gs(R.string.pump_tempbasal_label), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
val callback: Callback = object : Callback() {
override fun run() {
if (!result.success) {
@ -109,7 +108,7 @@ class TempBasalDialog : DialogFragmentWithDate() {
} else {
ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalAbsolute(absolute, durationInMinutes, true, profile, callback)
}
}
})
}
return true
}

View file

@ -126,7 +126,7 @@ class TempTargetDialog : DialogFragmentWithDate() {
actions.add(MainApp.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime))
activity?.let { activity ->
OKDialog.showConfirmation(activity, HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions))) {
OKDialog.showConfirmation(activity, MainApp.gs(R.string.careportal_temporarytarget), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
if (target == 0.0 || duration == 0.0) {
val tempTarget = TempTarget()
.date(eventTime)
@ -145,7 +145,7 @@ class TempTargetDialog : DialogFragmentWithDate() {
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget)
}
if (duration == 10.0) SP.putBoolean(R.string.key_objectiveusetemptarget, true)
}
})
}
return true
}

View file

@ -84,7 +84,6 @@ class TreatmentDialog : DialogFragmentWithDate() {
val insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(Constraint(insulin)).value()
val carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(Constraint(carbs)).value()
actions.add("<b>" + MainApp.gs(R.string.entertreatmentquestion) + "</b>")
if (insulinAfterConstraints > 0) {
actions.add(MainApp.gs(R.string.bolus) + ": " + "<font color='" + MainApp.gc(R.color.bolus) + "'>" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + MainApp.gs(R.string.insulin_unit_shortname) + "</font>")
if (recordOnlyChecked)
@ -99,7 +98,7 @@ class TreatmentDialog : DialogFragmentWithDate() {
}
if (insulinAfterConstraints > 0 || carbsAfterConstraints > 0) {
activity?.let { activity ->
OKDialog.showConfirmation(activity, HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions))) {
OKDialog.showConfirmation(activity, MainApp.gs(R.string.overview_treatment_label), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
val detailedBolusInfo = DetailedBolusInfo()
if (insulinAfterConstraints == 0.0) detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION
if (carbsAfterConstraints == 0) detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS
@ -122,10 +121,12 @@ class TreatmentDialog : DialogFragmentWithDate() {
})
} else
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false)
}
})
}
} else
OKDialog.show(activity, "", MainApp.gs(R.string.no_action_selected), null)
activity?.let { activity ->
OKDialog.show(activity, MainApp.gs(R.string.overview_treatment_label), MainApp.gs(R.string.no_action_selected))
}
return true
}
}

View file

@ -4,7 +4,6 @@ import android.os.SystemClock;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
import org.jetbrains.annotations.NotNull;
@ -20,6 +19,7 @@ import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.EventConfigBuilderUpdateGui;
import info.nightscout.androidaps.queue.CommandQueue;
import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.SP;
/**
@ -58,20 +58,16 @@ public abstract class PluginBase {
if (allowHardwarePump || activity == null) {
performPluginSwitch(newState, type);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setMessage(R.string.allow_hardware_pump_text)
.setPositiveButton(R.string.yes, (dialog, id) -> {
performPluginSwitch(newState, type);
SP.putBoolean("allow_hardware_pump", true);
if (L.isEnabled(L.PUMP))
log.debug("First time HW pump allowed!");
})
.setNegativeButton(R.string.cancel, (dialog, id) -> {
RxBus.INSTANCE.send(new EventConfigBuilderUpdateGui());
if (L.isEnabled(L.PUMP))
log.debug("User does not allow switching to HW pump!");
});
builder.create().show();
OKDialog.showConfirmation(activity, MainApp.gs(R.string.allow_hardware_pump_text), () -> {
performPluginSwitch(newState, type);
SP.putBoolean("allow_hardware_pump", true);
if (L.isEnabled(L.PUMP))
log.debug("First time HW pump allowed!");
}, () -> {
RxBus.INSTANCE.send(new EventConfigBuilderUpdateGui());
if (L.isEnabled(L.PUMP))
log.debug("User does not allow switching to HW pump!");
});
}
} else {
performPluginSwitch(newState, type);

View file

@ -72,13 +72,13 @@ class ObjectivesFragment : Fragment() {
override fun onResume() {
super.onResume()
disposable.add(RxBus
.toObservable(EventObjectivesUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
objectives_recyclerview.adapter?.notifyDataSetChanged()
}, {
FabricPrivacy.logException(it)
})
.toObservable(EventObjectivesUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
objectives_recyclerview.adapter?.notifyDataSetChanged()
}, {
FabricPrivacy.logException(it)
})
)
}
@ -285,11 +285,13 @@ class ObjectivesFragment : Fragment() {
}.start()
}
holder.unStart.setOnClickListener {
OKDialog.showConfirmation(activity, MainApp.gs(R.string.doyouwantresetstart)) {
objective.startedOn = 0
scrollToCurrentObjective()
RxBus.send(EventObjectivesUpdateGui())
RxBus.send(EventSWUpdate(false))
activity?.let { activity ->
OKDialog.showConfirmation(activity, MainApp.gs(R.string.objectives), MainApp.gs(R.string.doyouwantresetstart), Runnable {
objective.startedOn = 0
scrollToCurrentObjective()
RxBus.send(EventObjectivesUpdateGui())
RxBus.send(EventSWUpdate(false))
})
}
}
holder.unFinish.setOnClickListener {
@ -320,7 +322,6 @@ class ObjectivesFragment : Fragment() {
}
}
override fun getItemCount(): Int {
return ObjectivesPlugin.objectives.size
}

View file

@ -122,9 +122,9 @@ object ObjectivesPlugin : PluginBase(PluginDescription()
SP.putLong("Objectives_" + "smb" + "_started", DateUtil.now())
SP.putLong("Objectives_" + "smb" + "_accomplished", DateUtil.now())
setupObjectives()
OKDialog.show(activity, "", MainApp.gs(R.string.codeaccepted), null)
OKDialog.show(activity, MainApp.gs(R.string.objectives), MainApp.gs(R.string.codeaccepted))
} else {
OKDialog.show(activity, "", MainApp.gs(R.string.codeinvalid), null)
OKDialog.show(activity, MainApp.gs(R.string.objectives), MainApp.gs(R.string.codeinvalid))
}
}

View file

@ -93,7 +93,7 @@ public class TriggerTempTarget extends Trigger {
@Override
public int friendlyName() {
return R.string.temptarget;
return R.string.careportal_temporarytarget;
}
@Override
@ -124,7 +124,7 @@ public class TriggerTempTarget extends Trigger {
@Override
public void generateDialog(LinearLayout root, FragmentManager fragmentManager) {
new LayoutBuilder()
.add(new StaticLabel(R.string.temptarget))
.add(new StaticLabel(R.string.careportal_temporarytarget))
.add(comparator)
.build(root);
}

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.plugins.general.careportal.Dialogs;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
@ -20,7 +19,6 @@ import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatDialogFragment;
import androidx.fragment.app.DialogFragment;
@ -58,6 +56,7 @@ import info.nightscout.androidaps.utils.DefaultValueHelper;
import info.nightscout.androidaps.utils.HardLimits;
import info.nightscout.androidaps.utils.JsonHelper;
import info.nightscout.androidaps.utils.NumberPicker;
import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.SafeParse;
import info.nightscout.androidaps.utils.Translator;
@ -595,12 +594,12 @@ public class NewNSTreatmentDialog extends AppCompatDialogFragment implements Vie
String buildConfirmText(JSONObject data) {
String ret = "";
if (data.has("eventType")) {
ret += MainApp.gs(R.string.careportal_newnstreatment_eventtype);
ret += ": ";
ret += Translator.translate(JsonHelper.safeGetString(data, "eventType", ""));
ret += "\n";
}
// if (data.has("eventType")) {
// ret += MainApp.gs(R.string.careportal_newnstreatment_eventtype);
// ret += ": ";
// ret += Translator.translate(JsonHelper.safeGetString(data, "eventType", ""));
// ret += "\n";
// }
if (data.has("glucose")) {
ret += MainApp.gs(R.string.treatments_wizard_bg_label);
ret += ": ";
@ -697,18 +696,9 @@ public class NewNSTreatmentDialog extends AppCompatDialogFragment implements Vie
return ret;
}
void confirmNSTreatmentCreation() {
Context context = getContext();
if (context != null) {
final JSONObject data = gatherData();
final String confirmText = buildConfirmText(data);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(confirmText);
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> createNSTreatment(data));
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
}
private void confirmNSTreatmentCreation() {
final JSONObject data = gatherData();
OKDialog.showConfirmation(getContext(), Translator.translate(JsonHelper.safeGetString(data, "eventType", MainApp.gs(R.string.overview_treatment_label))), buildConfirmText(data), () -> createNSTreatment(data));
}

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.general.food;
import android.content.DialogInterface;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.Editable;
@ -14,14 +13,11 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@ -33,6 +29,7 @@ import info.nightscout.androidaps.events.EventFoodDatabaseChanged;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.SpinnerHelper;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
@ -42,43 +39,36 @@ import io.reactivex.disposables.CompositeDisposable;
*/
public class FoodFragment extends Fragment {
private static Logger log = LoggerFactory.getLogger(FoodFragment.class);
private CompositeDisposable disposable = new CompositeDisposable();
EditText filter;
ImageView clearFilter;
SpinnerHelper category;
SpinnerHelper subcategory;
RecyclerView recyclerView;
private EditText filter;
private SpinnerHelper category;
private SpinnerHelper subcategory;
private RecyclerView recyclerView;
List<Food> unfiltered;
List<Food> filtered;
ArrayList<CharSequence> categories;
ArrayList<CharSequence> subcategories;
private List<Food> unfiltered;
private List<Food> filtered;
final String EMPTY = MainApp.gs(R.string.none);
private final String EMPTY = MainApp.gs(R.string.none);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.food_fragment, container, false);
filter = (EditText) view.findViewById(R.id.food_filter);
clearFilter = (ImageView) view.findViewById(R.id.food_clearfilter);
filter = view.findViewById(R.id.food_filter);
ImageView clearFilter = view.findViewById(R.id.food_clearfilter);
category = new SpinnerHelper(view.findViewById(R.id.food_category));
subcategory = new SpinnerHelper(view.findViewById(R.id.food_subcategory));
recyclerView = (RecyclerView) view.findViewById(R.id.food_recyclerview);
recyclerView = view.findViewById(R.id.food_recyclerview);
recyclerView.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(llm);
clearFilter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
filter.setText("");
category.setSelection(0);
subcategory.setSelection(0);
filterData();
}
clearFilter.setOnClickListener(v -> {
filter.setText("");
category.setSelection(0);
subcategory.setSelection(0);
filterData();
});
category.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@ -149,11 +139,11 @@ public class FoodFragment extends Fragment {
disposable.clear();
}
void loadData() {
private void loadData() {
unfiltered = FoodPlugin.getPlugin().getService().getFoodData();
}
void fillCategories() {
private void fillCategories() {
Set<CharSequence> catSet = new HashSet<>();
for (Food f : unfiltered) {
@ -162,7 +152,7 @@ public class FoodFragment extends Fragment {
}
// make it unique
categories = new ArrayList<>(catSet);
ArrayList<CharSequence> categories = new ArrayList<>(catSet);
categories.add(0, MainApp.gs(R.string.none));
ArrayAdapter<CharSequence> adapterCategories = new ArrayAdapter<>(getContext(),
@ -170,7 +160,7 @@ public class FoodFragment extends Fragment {
category.setAdapter(adapterCategories);
}
void fillSubcategories() {
private void fillSubcategories() {
String categoryFilter = category.getSelectedItem().toString();
Set<CharSequence> subCatSet = new HashSet<>();
@ -184,7 +174,7 @@ public class FoodFragment extends Fragment {
}
// make it unique
subcategories = new ArrayList<>(subCatSet);
ArrayList<CharSequence> subcategories = new ArrayList<>(subCatSet);
subcategories.add(0, MainApp.gs(R.string.none));
ArrayAdapter<CharSequence> adapterSubcategories = new ArrayAdapter<>(getContext(),
@ -192,7 +182,7 @@ public class FoodFragment extends Fragment {
subcategory.setAdapter(adapterSubcategories);
}
void filterData() {
private void filterData() {
String textFilter = filter.getText().toString();
String categoryFilter = category.getSelectedItem().toString();
String subcategoryFilter = subcategory.getSelectedItem().toString();
@ -227,6 +217,7 @@ public class FoodFragment extends Fragment {
this.foodList = foodList;
}
@NonNull
@Override
public FoodsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.food_item, viewGroup, false);
@ -257,7 +248,7 @@ public class FoodFragment extends Fragment {
return foodList.size();
}
class FoodsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
class FoodsViewHolder extends RecyclerView.ViewHolder {
TextView name;
TextView portion;
TextView carbs;
@ -269,43 +260,26 @@ public class FoodFragment extends Fragment {
FoodsViewHolder(View itemView) {
super(itemView);
name = (TextView) itemView.findViewById(R.id.food_name);
portion = (TextView) itemView.findViewById(R.id.food_portion);
carbs = (TextView) itemView.findViewById(R.id.food_carbs);
fat = (TextView) itemView.findViewById(R.id.food_fat);
protein = (TextView) itemView.findViewById(R.id.food_protein);
energy = (TextView) itemView.findViewById(R.id.food_energy);
ns = (TextView) itemView.findViewById(R.id.ns_sign);
remove = (TextView) itemView.findViewById(R.id.food_remove);
remove.setOnClickListener(this);
name = itemView.findViewById(R.id.food_name);
portion = itemView.findViewById(R.id.food_portion);
carbs = itemView.findViewById(R.id.food_carbs);
fat = itemView.findViewById(R.id.food_fat);
protein = itemView.findViewById(R.id.food_protein);
energy = itemView.findViewById(R.id.food_energy);
ns = itemView.findViewById(R.id.ns_sign);
remove = itemView.findViewById(R.id.food_remove);
remove.setOnClickListener(v -> {
final Food food = (Food) v.getTag();
OKDialog.showConfirmation(getContext(), MainApp.gs(R.string.confirmation), MainApp.gs(R.string.removerecord) + "\n" + food.name, (dialog, id) -> {
final String _id = food._id;
if (_id != null && !_id.equals("")) {
NSUpload.removeFoodFromNS(_id);
}
FoodPlugin.getPlugin().getService().delete(food);
}, null);
});
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
@Override
public void onClick(View v) {
final Food food = (Food) v.getTag();
switch (v.getId()) {
case R.id.food_remove:
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + food.name);
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
final String _id = food._id;
if (_id != null && !_id.equals("")) {
NSUpload.removeFoodFromNS(_id);
}
FoodPlugin.getPlugin().getService().delete(food);
}
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
break;
}
}
}
}
}

View file

@ -2,15 +2,14 @@ package info.nightscout.androidaps.plugins.general.maintenance;
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Environment;
import android.preference.PreferenceManager;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -39,7 +38,7 @@ import info.nightscout.androidaps.utils.ToastUtils;
public class ImportExportPrefs {
private static Logger log = LoggerFactory.getLogger(L.CORE);
static File path = new File(Environment.getExternalStorageDirectory().toString());
private static File path = new File(Environment.getExternalStorageDirectory().toString());
static public final File file = new File(path, MainApp.gs(R.string.app_name) + "Preferences");
private static final int REQUEST_EXTERNAL_STORAGE = 1;
@ -48,21 +47,7 @@ public class ImportExportPrefs {
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
public static void verifyStoragePermissions(Activity activity) {
// Check if we have write permission
int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(
activity,
PERMISSIONS_STORAGE,
REQUEST_EXTERNAL_STORAGE
);
}
}
public static void verifyStoragePermissions(Fragment fragment) {
static void verifyStoragePermissions(Fragment fragment) {
int permission = ContextCompat.checkSelfPermission(fragment.getContext(),
Manifest.permission.WRITE_EXTERNAL_STORAGE);
@ -73,85 +58,73 @@ public class ImportExportPrefs {
}
public static void exportSharedPreferences(final Fragment f) {
static void exportSharedPreferences(final Fragment f) {
exportSharedPreferences(f.getContext());
}
public static void exportSharedPreferences(final Context c) {
new AlertDialog.Builder(c)
.setMessage(MainApp.gs(R.string.export_to) + " " + file + " ?")
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
try {
FileWriter fw = new FileWriter(file);
PrintWriter pw = new PrintWriter(fw);
Map<String, ?> prefsMap = prefs.getAll();
for (Map.Entry<String, ?> entry : prefsMap.entrySet()) {
pw.println(entry.getKey() + "::" + entry.getValue().toString());
}
pw.close();
fw.close();
ToastUtils.showToastInUiThread(c, MainApp.gs(R.string.exported));
} catch (FileNotFoundException e) {
ToastUtils.showToastInUiThread(c, MainApp.gs(R.string.filenotfound) + " " + file);
log.error("Unhandled exception", e);
} catch (IOException e) {
log.error("Unhandled exception", e);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
private static void exportSharedPreferences(final Context context) {
OKDialog.showConfirmation(context, MainApp.gs(R.string.maintenance), MainApp.gs(R.string.export_to) + " " + file + " ?", () -> {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
try {
FileWriter fw = new FileWriter(file);
PrintWriter pw = new PrintWriter(fw);
Map<String, ?> prefsMap = prefs.getAll();
for (Map.Entry<String, ?> entry : prefsMap.entrySet()) {
pw.println(entry.getKey() + "::" + entry.getValue().toString());
}
pw.close();
fw.close();
ToastUtils.showToastInUiThread(context, MainApp.gs(R.string.exported));
} catch (FileNotFoundException e) {
ToastUtils.showToastInUiThread(context, MainApp.gs(R.string.filenotfound) + " " + file);
log.error("Unhandled exception", e);
} catch (IOException e) {
log.error("Unhandled exception", e);
}
});
}
public static void importSharedPreferences(final Fragment fragment) {
static void importSharedPreferences(final Fragment fragment) {
importSharedPreferences(fragment.getContext());
}
public static void importSharedPreferences(final Context context) {
new AlertDialog.Builder(context)
.setMessage(MainApp.gs(R.string.import_from) + " " + file + " ?")
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
OKDialog.showConfirmation(context, MainApp.gs(R.string.maintenance), MainApp.gs(R.string.import_from) + " " + file + " ?", () -> {
String line;
String[] lineParts;
try {
SP.clear();
String line;
String[] lineParts;
try {
SP.clear();
BufferedReader reader = new BufferedReader(new FileReader(file));
while ((line = reader.readLine()) != null) {
lineParts = line.split("::");
if (lineParts.length == 2) {
if (lineParts[1].equals("true") || lineParts[1].equals("false")) {
SP.putBoolean(lineParts[0], Boolean.parseBoolean(lineParts[1]));
} else {
SP.putString(lineParts[0], lineParts[1]);
}
}
BufferedReader reader = new BufferedReader(new FileReader(file));
while ((line = reader.readLine()) != null) {
lineParts = line.split("::");
if (lineParts.length == 2) {
if (lineParts[1].equals("true") || lineParts[1].equals("false")) {
SP.putBoolean(lineParts[0], Boolean.parseBoolean(lineParts[1]));
} else {
SP.putString(lineParts[0], lineParts[1]);
}
reader.close();
SP.putBoolean(R.string.key_setupwizard_processed, true);
OKDialog.show(context, MainApp.gs(R.string.setting_imported), MainApp.gs(R.string.restartingapp), () -> {
log.debug("Exiting");
MainApp.instance().stopKeepAliveService();
RxBus.INSTANCE.send(new EventAppExit());
MainApp.closeDbHelper();
if (context instanceof Activity) {
((Activity)context).finish();
}
System.runFinalization();
System.exit(0);
});
} catch (FileNotFoundException e) {
ToastUtils.showToastInUiThread(context, MainApp.gs(R.string.filenotfound) + " " + file);
log.error("Unhandled exception", e);
} catch (IOException e) {
log.error("Unhandled exception", e);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
reader.close();
SP.putBoolean(R.string.key_setupwizard_processed, true);
OKDialog.show(context, MainApp.gs(R.string.setting_imported), MainApp.gs(R.string.restartingapp), () -> {
log.debug("Exiting");
MainApp.instance().stopKeepAliveService();
RxBus.INSTANCE.send(new EventAppExit());
MainApp.closeDbHelper();
if (context instanceof Activity) {
((Activity) context).finish();
}
System.runFinalization();
System.exit(0);
});
} catch (FileNotFoundException e) {
ToastUtils.showToastInUiThread(context, MainApp.gs(R.string.filenotfound) + " " + file);
log.error("Unhandled exception", e);
} catch (IOException e) {
log.error("Unhandled exception", e);
}
});
}
}

View file

@ -2,81 +2,58 @@ package info.nightscout.androidaps.plugins.general.maintenance;
import android.content.Intent;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.general.food.FoodPlugin;
import info.nightscout.androidaps.plugins.general.maintenance.activities.LogSettingActivity;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.OKDialog;
/**
*
*/
public class MaintenanceFragment extends Fragment {
private Fragment f;
@Override
public void onResume() {
super.onResume();
this.f = this;
}
@Override
public void onPause() {
super.onPause();
this.f = null;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.maintenance_fragment, container, false);
final Fragment f = this;
view.findViewById(R.id.log_send).setOnClickListener(view1 -> MaintenancePlugin.getPlugin().sendLogs());
view.findViewById(R.id.log_delete).setOnClickListener(view1 -> MaintenancePlugin.getPlugin().deleteLogs());
view.findViewById(R.id.nav_resetdb).setOnClickListener(view1 -> new AlertDialog.Builder(f.getContext())
.setTitle(R.string.nav_resetdb)
.setMessage(R.string.reset_db_confirm)
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
view.findViewById(R.id.nav_resetdb).setOnClickListener(view1 ->
OKDialog.showConfirmation(getContext(), MainApp.gs(R.string.maintenance), MainApp.gs(R.string.reset_db_confirm), () -> {
MainApp.getDbHelper().resetDatabases();
// should be handled by Plugin-Interface and
// additional service interface and plugin registry
FoodPlugin.getPlugin().getService().resetFood();
TreatmentsPlugin.getPlugin().getService().resetTreatments();
})
.create()
.show());
);
view.findViewById(R.id.nav_export).setOnClickListener(view1 -> {
// start activity for checking permissions...
ImportExportPrefs.verifyStoragePermissions(f);
ImportExportPrefs.exportSharedPreferences(f);
ImportExportPrefs.verifyStoragePermissions(this);
ImportExportPrefs.exportSharedPreferences(this);
});
view.findViewById(R.id.nav_import).setOnClickListener(view1 -> {
// start activity for checking permissions...
ImportExportPrefs.verifyStoragePermissions(f);
ImportExportPrefs.importSharedPreferences(f);
ImportExportPrefs.verifyStoragePermissions(this);
ImportExportPrefs.importSharedPreferences(this);
});
view.findViewById(R.id.nav_logsettings).setOnClickListener(view1 -> {
startActivity(new Intent(getActivity(), LogSettingActivity.class));
});
return view;
}

View file

@ -1,9 +1,6 @@
package info.nightscout.androidaps.plugins.general.nsclient;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.Html;
@ -25,6 +22,7 @@ import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientN
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.SP;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
@ -113,20 +111,11 @@ public class NSClientFragment extends Fragment implements View.OnClickListener,
NSClientPlugin.getPlugin().clearLog();
break;
case R.id.nsclientinternal_clearqueue:
final Context context = getContext();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage("Clear queue? All data in queue will be lost!");
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
UploadQueue.clearQueue();
updateGui();
FabricPrivacy.getInstance().logCustom("NSClientClearQueue");
}
OKDialog.showConfirmation(getContext(),MainApp.gs(R.string.nsclientinternal), MainApp.gs(R.string.clearqueueconfirm), () -> {
UploadQueue.clearQueue();
updateGui();
FabricPrivacy.getInstance().logCustom("NSClientClearQueue");
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
break;
case R.id.nsclientinternal_showqueue:
RxBus.INSTANCE.send(new EventNSClientNewLog("QUEUE", NSClientPlugin.getPlugin().queue().textList()));

View file

@ -61,6 +61,14 @@ import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.dialogs.CalibrationDialog;
import info.nightscout.androidaps.dialogs.CarbsDialog;
import info.nightscout.androidaps.dialogs.InsulinDialog;
import info.nightscout.androidaps.dialogs.ProfileSwitchDialog;
import info.nightscout.androidaps.dialogs.ProfileViewerDialog;
import info.nightscout.androidaps.dialogs.TempTargetDialog;
import info.nightscout.androidaps.dialogs.TreatmentDialog;
import info.nightscout.androidaps.dialogs.WizardDialog;
import info.nightscout.androidaps.events.EventAcceptOpenLoopChange;
import info.nightscout.androidaps.events.EventCareportalEventChange;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
@ -87,13 +95,6 @@ import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus;
import info.nightscout.androidaps.plugins.general.overview.activities.QuickWizardListActivity;
import info.nightscout.androidaps.dialogs.CalibrationDialog;
import info.nightscout.androidaps.dialogs.CarbsDialog;
import info.nightscout.androidaps.dialogs.InsulinDialog;
import info.nightscout.androidaps.dialogs.TreatmentDialog;
import info.nightscout.androidaps.dialogs.ProfileSwitchDialog;
import info.nightscout.androidaps.dialogs.TempTargetDialog;
import info.nightscout.androidaps.dialogs.WizardDialog;
import info.nightscout.androidaps.plugins.general.overview.graphData.GraphData;
import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
@ -105,7 +106,6 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCa
import info.nightscout.androidaps.plugins.source.SourceDexcomPlugin;
import info.nightscout.androidaps.plugins.source.SourceXdripPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.dialogs.ProfileViewerDialog;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.utils.BolusWizard;
import info.nightscout.androidaps.utils.DateUtil;
@ -883,10 +883,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
getContext().startActivity(intent);
return true;
} catch (ActivityNotFoundException e) {
new AlertDialog.Builder(getContext())
.setMessage(R.string.error_starting_cgm)
.setPositiveButton("OK", null)
.show();
OKDialog.show(getContext(), "", MainApp.gs(R.string.error_starting_cgm));
return false;
}
}
@ -912,16 +909,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
LoopPlugin.getPlugin().invoke("Accept temp button", false);
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
if (finalLastRun != null && finalLastRun.lastAPSRun != null && finalLastRun.constraintsProcessed.isChangeRequested()) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed);
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
OKDialog.showConfirmation(context, MainApp.gs(R.string.pump_tempbasal_label), finalLastRun.constraintsProcessed.toSpanned(), () -> {
hideTempRecommendation();
clearNotification();
LoopPlugin.getPlugin().acceptChangeRequest();
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
}
}
}
@ -941,7 +933,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(quickWizardEntry.carbs())).value();
if (Math.abs(wizard.getInsulinAfterConstraints() - wizard.getCalculatedTotalInsulin()) >= pump.getPumpDescription().pumpType.determineCorrectBolusStepSize(wizard.getInsulinAfterConstraints()) || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) {
OKDialog.show(getContext(), MainApp.gs(R.string.treatmentdeliveryerror), MainApp.gs(R.string.constraints_violation) + "\n" + MainApp.gs(R.string.changeyourinput), null);
OKDialog.show(getContext(), MainApp.gs(R.string.treatmentdeliveryerror), MainApp.gs(R.string.constraints_violation) + "\n" + MainApp.gs(R.string.changeyourinput));
return;
}
@ -1170,7 +1162,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (activeTemp != null) {
fullText += MainApp.gs(R.string.pump_tempbasal_label) + ": " + activeTemp.toStringFull();
}
OKDialog.show(getActivity(), MainApp.gs(R.string.basal), fullText, null);
OKDialog.show(getActivity(), MainApp.gs(R.string.basal), fullText);
});
} else {
@ -1206,7 +1198,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
extendedBolusView.setText(extendedBolusText);
if (Config.NSCLIENT) {
extendedBolusView.setOnClickListener(v -> OKDialog.show(getActivity(), MainApp.gs(R.string.extendedbolus), extendedBolus.toString(), null));
extendedBolusView.setOnClickListener(v -> OKDialog.show(getActivity(), MainApp.gs(R.string.extended_bolus), extendedBolus.toString()));
}
if (extendedBolusText.equals(""))
extendedBolusView.setVisibility(Config.NSCLIENT ? View.INVISIBLE : View.GONE);
@ -1300,7 +1292,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
String iobtext1 = DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U\n"
+ MainApp.gs(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U\n"
+ MainApp.gs(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U\n";
OKDialog.show(getActivity(), MainApp.gs(R.string.iob), iobtext1, null);
OKDialog.show(getActivity(), MainApp.gs(R.string.iob), iobtext1);
});
} else if (MainApp.sResources.getBoolean(R.bool.isTablet)) {
String iobtext = DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
@ -1352,19 +1344,19 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
// pump status from ns
if (pumpDeviceStatusView != null) {
pumpDeviceStatusView.setText(NSDeviceStatus.getInstance().getPumpStatus());
pumpDeviceStatusView.setOnClickListener(v -> OKDialog.show(getActivity(), MainApp.gs(R.string.pump), NSDeviceStatus.getInstance().getExtendedPumpStatus(), null));
pumpDeviceStatusView.setOnClickListener(v -> OKDialog.show(getActivity(), MainApp.gs(R.string.pump), NSDeviceStatus.getInstance().getExtendedPumpStatus()));
}
// OpenAPS status from ns
if (openapsDeviceStatusView != null) {
openapsDeviceStatusView.setText(NSDeviceStatus.getInstance().getOpenApsStatus());
openapsDeviceStatusView.setOnClickListener(v -> OKDialog.show(getActivity(), MainApp.gs(R.string.openaps), NSDeviceStatus.getInstance().getExtendedOpenApsStatus(), null));
openapsDeviceStatusView.setOnClickListener(v -> OKDialog.show(getActivity(), MainApp.gs(R.string.openaps), NSDeviceStatus.getInstance().getExtendedOpenApsStatus()));
}
// Uploader status from ns
if (uploaderDeviceStatusView != null) {
uploaderDeviceStatusView.setText(NSDeviceStatus.getInstance().getUploaderStatusSpanned());
uploaderDeviceStatusView.setOnClickListener(v -> OKDialog.show(getActivity(), MainApp.gs(R.string.uploader), NSDeviceStatus.getInstance().getExtendedUploaderStatus(), null));
uploaderDeviceStatusView.setOnClickListener(v -> OKDialog.show(getActivity(), MainApp.gs(R.string.uploader), NSDeviceStatus.getInstance().getExtendedUploaderStatus()));
}
// Sensitivity

View file

@ -116,13 +116,13 @@ object TidepoolUploader {
val call = session.service?.getLogin(it)
call?.enqueue(TidepoolCallback<AuthReplyMessage>(session, "Login", {
OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), "Successfully logged into Tidepool.", null)
OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), "Successfully logged into Tidepool.")
}, {
OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), "Failed to log into Tidepool.\nCheck that your user name and password are correct.", null)
OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), "Failed to log into Tidepool.\nCheck that your user name and password are correct.")
}))
}
?: OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), "Cannot do login as user credentials have not been set correctly", null)
?: OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), "Cannot do login as user credentials have not been set correctly")
}

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.profile.local
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
@ -14,9 +13,9 @@ import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.dialogs.ProfileSwitchDialog
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.dialogs.ProfileSwitchDialog
import info.nightscout.androidaps.plugins.insulin.InsulinOrefBasePlugin.MIN_DIA
import info.nightscout.androidaps.plugins.profile.local.events.EventLocalProfileChanged
import info.nightscout.androidaps.utils.*
@ -107,7 +106,7 @@ class LocalProfileFragment : Fragment() {
// Spinner
spinner = SpinnerHelper(view?.findViewById(R.id.localprofile_spinner))
val profileList: ArrayList<CharSequence> = LocalProfilePlugin.profile?.getProfileList()
?: ArrayList()
?: ArrayList()
context?.let { context ->
val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList)
spinner?.adapter = adapter
@ -120,10 +119,10 @@ class LocalProfileFragment : Fragment() {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
if (LocalProfilePlugin.isEdited) {
activity?.let { activity ->
OKDialog.showConfirmation(activity, MainApp.gs(R.string.doyouwantswitchprofile), {
OKDialog.showConfirmation(activity, MainApp.gs(R.string.doyouwantswitchprofile), Runnable {
LocalProfilePlugin.currentProfileIndex = position
build()
}, {
}, Runnable {
spinner?.setSelection(LocalProfilePlugin.currentProfileIndex)
})
}
@ -136,7 +135,7 @@ class LocalProfileFragment : Fragment() {
localprofile_profile_add.setOnClickListener {
if (LocalProfilePlugin.isEdited) {
activity?.let { OKDialog.show(it, "", MainApp.gs(R.string.saveorresetchangesfirst), null) }
activity?.let { OKDialog.show(it, "", MainApp.gs(R.string.saveorresetchangesfirst)) }
} else {
LocalProfilePlugin.addNewProfile()
build()
@ -145,7 +144,7 @@ class LocalProfileFragment : Fragment() {
localprofile_profile_clone.setOnClickListener {
if (LocalProfilePlugin.isEdited) {
activity?.let { OKDialog.show(it, "", MainApp.gs(R.string.saveorresetchangesfirst), null) }
activity?.let { OKDialog.show(it, "", MainApp.gs(R.string.saveorresetchangesfirst)) }
} else {
LocalProfilePlugin.cloneProfile()
build()
@ -154,7 +153,7 @@ class LocalProfileFragment : Fragment() {
localprofile_profile_remove.setOnClickListener {
activity?.let { activity ->
OKDialog.showConfirmation(activity, MainApp.gs(R.string.deletecurrentprofile), {
OKDialog.showConfirmation(activity, MainApp.gs(R.string.deletecurrentprofile), Runnable {
LocalProfilePlugin.removeCurrentProfile()
build()
}, null)
@ -199,9 +198,9 @@ class LocalProfileFragment : Fragment() {
override fun onResume() {
super.onResume()
disposable.add(RxBus
.toObservable(EventLocalProfileChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ build() }, { FabricPrivacy.logException(it) })
.toObservable(EventLocalProfileChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ build() }, { FabricPrivacy.logException(it) })
)
build()
}

View file

@ -27,11 +27,11 @@ import java.util.*
import kotlin.collections.ArrayList
object LocalProfilePlugin : PluginBase(PluginDescription()
.mainType(PluginType.PROFILE)
.fragmentClass(LocalProfileFragment::class.java.name)
.pluginName(R.string.localprofile)
.shortName(R.string.localprofile_shortname)
.description(R.string.description_profile_local)), ProfileInterface {
.mainType(PluginType.PROFILE)
.fragmentClass(LocalProfileFragment::class.java.name)
.pluginName(R.string.localprofile)
.shortName(R.string.localprofile_shortname)
.description(R.string.description_profile_local)), ProfileInterface {
override fun onStart() {
super.onStart()
@ -98,7 +98,7 @@ object LocalProfilePlugin : PluginBase(PluginDescription()
@Synchronized
fun isValidEditState(): Boolean {
return createProfileStore().getDefaultProfile()?.isValid(MainApp.gs(R.string.localprofile), false)
?: false
?: false
}
@Synchronized
@ -132,7 +132,7 @@ object LocalProfilePlugin : PluginBase(PluginDescription()
rawProfile?.let { NSUpload.uploadProfileStore(it.data) }
else
activity?.let {
OKDialog.show(it,"", MainApp.gs(R.string.profilenamecontainsdot), null)
OKDialog.show(it, "", MainApp.gs(R.string.profilenamecontainsdot))
}
}
@ -423,7 +423,7 @@ object LocalProfilePlugin : PluginBase(PluginDescription()
override fun getProfileName(): String {
return DecimalFormatter.to2Decimal(rawProfile?.getDefaultProfile()?.percentageBasalSum()
?: 0.0) + "U "
?: 0.0) + "U "
}
}

View file

@ -22,7 +22,6 @@ import kotlinx.android.synthetic.main.close.*
import kotlinx.android.synthetic.main.nsprofile_fragment.*
import kotlinx.android.synthetic.main.profileviewer_fragment.*
class NSProfileFragment : Fragment() {
private var disposable: CompositeDisposable = CompositeDisposable()
@ -40,10 +39,11 @@ class NSProfileFragment : Fragment() {
val name = nsprofile_spinner.selectedItem?.toString() ?: ""
NSProfilePlugin.getPlugin().profile?.let { store ->
store.getSpecificProfile(name)?.let {
OKDialog.showConfirmation(activity,
MainApp.gs(R.string.activate_profile) + ": " + name + " ?"
) {
ProfileFunctions.doProfileSwitch(store, name, 0, 100, 0, DateUtil.now())
activity?.let { activity ->
OKDialog.showConfirmation(activity, MainApp.gs(R.string.nsprofile),
MainApp.gs(R.string.activate_profile) + ": " + name + " ?", Runnable {
ProfileFunctions.doProfileSwitch(store, name, 0, 100, 0, DateUtil.now())
})
}
}
}
@ -97,13 +97,9 @@ class NSProfileFragment : Fragment() {
override fun onResume() {
super.onResume()
disposable.add(RxBus
.toObservable(EventNSProfileUpdateGUI::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
updateGUI()
}, {
FabricPrivacy.logException(it)
})
.toObservable(EventNSProfileUpdateGUI::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }, { FabricPrivacy.logException(it) })
)
updateGUI()
}

View file

@ -1,14 +1,13 @@
package info.nightscout.androidaps.plugins.pump.common.utils;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Build;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.utils.OKDialog;
/**
* Helper for checking if location services are enabled on the device.
@ -45,18 +44,9 @@ public class LocationHelper {
}
// Shamelessly borrowed from http://stackoverflow.com/a/10311877/868533
AlertDialog.Builder builder = new AlertDialog.Builder(parent);
builder.setTitle(R.string.location_not_found_title);
builder.setMessage(R.string.location_not_found_message);
builder.setPositiveButton(R.string.location_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
parent.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
OKDialog.showConfirmation(parent, MainApp.gs(R.string.location_not_found_title), MainApp.gs(R.string.location_not_found_message), () -> {
parent.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
});
builder.setNegativeButton(R.string.location_no, null);
builder.create().show();
}

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.source;
import android.content.DialogInterface;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -9,7 +8,6 @@ import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@ -25,6 +23,7 @@ import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.T;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
@ -35,17 +34,17 @@ import io.reactivex.disposables.CompositeDisposable;
public class BGSourceFragment extends Fragment {
private CompositeDisposable disposable = new CompositeDisposable();
RecyclerView recyclerView;
private RecyclerView recyclerView;
final long MILLS_TO_THE_PAST = T.hours(12).msecs();
private final long MILLS_TO_THE_PAST = T.hours(12).msecs();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
View view = inflater.inflate(R.layout.bgsource_fragment, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.bgsource_recyclerview);
recyclerView = view.findViewById(R.id.bgsource_recyclerview);
recyclerView.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(llm);
@ -91,6 +90,7 @@ public class BGSourceFragment extends Fragment {
this.bgReadings = bgReadings;
}
@NonNull
@Override
public BgReadingsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.bgsource_item, viewGroup, false);
@ -113,7 +113,7 @@ public class BGSourceFragment extends Fragment {
return bgReadings.size();
}
class BgReadingsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
class BgReadingsViewHolder extends RecyclerView.ViewHolder {
TextView date;
TextView value;
TextView direction;
@ -123,46 +123,22 @@ public class BGSourceFragment extends Fragment {
BgReadingsViewHolder(View itemView) {
super(itemView);
date = (TextView) itemView.findViewById(R.id.bgsource_date);
value = (TextView) itemView.findViewById(R.id.bgsource_value);
direction = (TextView) itemView.findViewById(R.id.bgsource_direction);
invalid = (TextView) itemView.findViewById(R.id.invalid_sign);
ns = (TextView) itemView.findViewById(R.id.ns_sign);
remove = (TextView) itemView.findViewById(R.id.bgsource_remove);
remove.setOnClickListener(this);
date = itemView.findViewById(R.id.bgsource_date);
value = itemView.findViewById(R.id.bgsource_value);
direction = itemView.findViewById(R.id.bgsource_direction);
invalid = itemView.findViewById(R.id.invalid_sign);
ns = itemView.findViewById(R.id.ns_sign);
remove = itemView.findViewById(R.id.bgsource_remove);
remove.setOnClickListener(v -> {
final BgReading bgReading = (BgReading) v.getTag();
OKDialog.showConfirmation(getContext(), MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(bgReading.date) + "\n" + bgReading.valueToUnitsToString(ProfileFunctions.getSystemUnits()), () -> {
bgReading.isValid = false;
MainApp.getDbHelper().update(bgReading);
updateGUI();
});
});
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
@Override
public void onClick(View v) {
final BgReading bgReading = (BgReading) v.getTag();
switch (v.getId()) {
case R.id.bgsource_remove:
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(bgReading.date) + "\n" + bgReading.valueToUnitsToString(ProfileFunctions.getSystemUnits()));
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
/* final String _id = bgReading._id;
if (NSUpload.isIdValid(_id)) {
NSUpload.removeFoodFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
}
*/
bgReading.isValid = false;
MainApp.getDbHelper().update(bgReading);
updateGUI();
}
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
break;
}
}
}
}
}

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.plugins.treatments.fragments;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -10,7 +8,7 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
@ -38,24 +36,21 @@ import info.nightscout.androidaps.plugins.treatments.dialogs.WizardInfoDialog;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.SP;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import static info.nightscout.androidaps.utils.DateUtil.now;
public class TreatmentsBolusFragment extends Fragment implements View.OnClickListener {
public class TreatmentsBolusFragment extends Fragment {
private CompositeDisposable disposable = new CompositeDisposable();
RecyclerView recyclerView;
LinearLayoutManager llm;
private RecyclerView recyclerView;
TextView iobTotal;
TextView activityTotal;
Button refreshFromNS;
Button deleteFutureTreatments;
Context context;
private TextView iobTotal;
private TextView activityTotal;
private Button deleteFutureTreatments;
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.TreatmentsViewHolder> {
@ -65,6 +60,7 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
this.treatments = treatments;
}
@NonNull
@Override
public TreatmentsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.treatments_bolus_item, viewGroup, false);
@ -72,16 +68,16 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
}
@Override
public void onBindViewHolder(TreatmentsViewHolder holder, int position) {
public void onBindViewHolder(@NonNull TreatmentsViewHolder holder, int position) {
Profile profile = ProfileFunctions.getInstance().getProfile();
if (profile == null)
return;
Treatment t = treatments.get(position);
holder.date.setText(DateUtil.dateAndTimeString(t.date));
holder.insulin.setText(DecimalFormatter.toPumpSupportedBolus(t.insulin) + " U");
holder.carbs.setText(DecimalFormatter.to0Decimal(t.carbs) + " g");
holder.insulin.setText(MainApp.gs(R.string.formatinsulinunits, t.insulin));
holder.carbs.setText(MainApp.gs(R.string.format_carbs, (int) t.carbs));
Iob iob = t.iobCalc(System.currentTimeMillis(), profile.getDia());
holder.iob.setText(DecimalFormatter.to2Decimal(iob.iobContrib) + " U");
holder.iob.setText(MainApp.gs(R.string.formatinsulinunits, iob.iobContrib));
holder.mealOrCorrection.setText(t.isSMB ? "SMB" : t.mealBolus ? MainApp.gs(R.string.mealbolus) : MainApp.gs(R.string.correctionbous));
holder.ph.setVisibility(t.source == Source.PUMP ? View.VISIBLE : View.GONE);
holder.ns.setVisibility(NSUpload.isIdValid(t._id) ? View.VISIBLE : View.GONE);
@ -105,7 +101,7 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
@ -124,19 +120,19 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
TreatmentsViewHolder(View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.treatments_cardview);
date = (TextView) itemView.findViewById(R.id.treatments_date);
insulin = (TextView) itemView.findViewById(R.id.treatments_insulin);
carbs = (TextView) itemView.findViewById(R.id.treatments_carbs);
iob = (TextView) itemView.findViewById(R.id.treatments_iob);
mealOrCorrection = (TextView) itemView.findViewById(R.id.treatments_mealorcorrection);
ph = (TextView) itemView.findViewById(R.id.pump_sign);
ns = (TextView) itemView.findViewById(R.id.ns_sign);
invalid = (TextView) itemView.findViewById(R.id.invalid_sign);
calculation = (TextView) itemView.findViewById(R.id.treatments_calculation);
cv = itemView.findViewById(R.id.treatments_cardview);
date = itemView.findViewById(R.id.treatments_date);
insulin = itemView.findViewById(R.id.treatments_insulin);
carbs = itemView.findViewById(R.id.treatments_carbs);
iob = itemView.findViewById(R.id.treatments_iob);
mealOrCorrection = itemView.findViewById(R.id.treatments_mealorcorrection);
ph = itemView.findViewById(R.id.pump_sign);
ns = itemView.findViewById(R.id.ns_sign);
invalid = itemView.findViewById(R.id.invalid_sign);
calculation = itemView.findViewById(R.id.treatments_calculation);
calculation.setOnClickListener(this);
calculation.setPaintFlags(calculation.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
remove = (TextView) itemView.findViewById(R.id.treatments_remove);
remove = itemView.findViewById(R.id.treatments_remove);
remove.setOnClickListener(this);
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
@ -148,28 +144,25 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
return;
switch (v.getId()) {
case R.id.treatments_remove:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(treatment.date));
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
final String _id = treatment._id;
if (treatment.source == Source.PUMP) {
treatment.isValid = false;
TreatmentsPlugin.getPlugin().getService().update(treatment);
} else {
if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id);
OKDialog.showConfirmation(getContext(), MainApp.gs(R.string.removerecord),
MainApp.gs(R.string.configbuilder_insulin) + ": " + MainApp.gs(R.string.formatinsulinunits, treatment.insulin) +
"\n" + MainApp.gs(R.string.carbs) + ": " + MainApp.gs(R.string.format_carbs, (int) treatment.carbs) +
"\n" + MainApp.gs(R.string.date) + ": " + DateUtil.dateAndTimeString(treatment.date),
(dialog, id) -> {
final String _id = treatment._id;
if (treatment.source == Source.PUMP) {
treatment.isValid = false;
TreatmentsPlugin.getPlugin().getService().update(treatment);
} else {
UploadQueue.removeID("dbAdd", _id);
if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
}
TreatmentsPlugin.getPlugin().getService().delete(treatment);
}
TreatmentsPlugin.getPlugin().getService().delete(treatment);
}
updateGui();
}
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
updateGui();
}, null);
break;
case R.id.treatments_calculation:
FragmentManager manager = getFragmentManager();
@ -193,71 +186,48 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.treatments_bolus_fragment, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.treatments_recyclerview);
recyclerView = view.findViewById(R.id.treatments_recyclerview);
recyclerView.setHasFixedSize(true);
llm = new LinearLayoutManager(view.getContext());
LinearLayoutManager llm = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(llm);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getTreatmentsFromHistory());
recyclerView.setAdapter(adapter);
iobTotal = (TextView) view.findViewById(R.id.treatments_iobtotal);
activityTotal = (TextView) view.findViewById(R.id.treatments_iobactivitytotal);
iobTotal = view.findViewById(R.id.treatments_iobtotal);
activityTotal = view.findViewById(R.id.treatments_iobactivitytotal);
refreshFromNS = (Button) view.findViewById(R.id.treatments_reshreshfromnightscout);
refreshFromNS.setOnClickListener(this);
Button refreshFromNS = view.findViewById(R.id.treatments_reshreshfromnightscout);
refreshFromNS.setOnClickListener(v -> OKDialog.showConfirmation(getContext(), MainApp.gs(R.string.refresheventsfromnightscout) + "?", () -> {
TreatmentsPlugin.getPlugin().getService().resetTreatments();
RxBus.INSTANCE.send(new EventNSClientRestart());
}));
deleteFutureTreatments = (Button) view.findViewById(R.id.treatments_delete_future_treatments);
deleteFutureTreatments.setOnClickListener(this);
deleteFutureTreatments = view.findViewById(R.id.treatments_delete_future_treatments);
deleteFutureTreatments.setOnClickListener(v -> {
OKDialog.showConfirmation(getContext(), MainApp.gs(R.string.overview_treatment_label), MainApp.gs(R.string.deletefuturetreatments) + "?", () -> {
final List<Treatment> futureTreatments = TreatmentsPlugin.getPlugin().getService()
.getTreatmentDataFromTime(now() + 1000, true);
for (Treatment treatment : futureTreatments) {
final String _id = treatment._id;
if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
}
TreatmentsPlugin.getPlugin().getService().delete(treatment);
}
updateGui();
});
});
boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false);
if (nsUploadOnly)
refreshFromNS.setVisibility(View.GONE);
context = getContext();
return view;
}
@Override
public void onClick(View view) {
AlertDialog.Builder builder;
switch (view.getId()) {
case R.id.treatments_reshreshfromnightscout:
builder = new AlertDialog.Builder(this.getContext());
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.refresheventsfromnightscout) + "?");
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
TreatmentsPlugin.getPlugin().getService().resetTreatments();
RxBus.INSTANCE.send(new EventNSClientRestart());
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
break;
case R.id.treatments_delete_future_treatments:
builder = new AlertDialog.Builder(this.getContext());
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.deletefuturetreatments) + "?");
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
final List<Treatment> futureTreatments = TreatmentsPlugin.getPlugin().getService()
.getTreatmentDataFromTime(now() + 1000, true);
for (Treatment treatment : futureTreatments) {
final String _id = treatment._id;
if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
}
TreatmentsPlugin.getPlugin().getService().delete(treatment);
}
updateGui();
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
break;
}
}
@Override
public synchronized void onResume() {
super.onResume();
@ -292,5 +262,4 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
deleteFutureTreatments.setVisibility(View.GONE);
}
}
}

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.plugins.treatments.fragments;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -10,7 +8,7 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -28,6 +26,7 @@ import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue;
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.Translator;
import io.reactivex.android.schedulers.AndroidSchedulers;
@ -37,14 +36,10 @@ import io.reactivex.disposables.CompositeDisposable;
* Created by mike on 13/01/17.
*/
public class TreatmentsCareportalFragment extends Fragment implements View.OnClickListener {
public class TreatmentsCareportalFragment extends Fragment {
private CompositeDisposable disposable = new CompositeDisposable();
RecyclerView recyclerView;
LinearLayoutManager llm;
Button refreshFromNS;
Context context;
private RecyclerView recyclerView;
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.CareportalEventsViewHolder> {
@ -54,11 +49,11 @@ public class TreatmentsCareportalFragment extends Fragment implements View.OnCli
this.careportalEventList = careportalEventList;
}
@NonNull
@Override
public CareportalEventsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.treatments_careportal_item, viewGroup, false);
CareportalEventsViewHolder CareportalEventsViewHolder = new CareportalEventsViewHolder(v);
return CareportalEventsViewHolder;
return new CareportalEventsViewHolder(v);
}
@Override
@ -77,11 +72,11 @@ public class TreatmentsCareportalFragment extends Fragment implements View.OnCli
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
public class CareportalEventsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
class CareportalEventsViewHolder extends RecyclerView.ViewHolder {
CardView cv;
TextView date;
TextView type;
@ -91,38 +86,30 @@ public class TreatmentsCareportalFragment extends Fragment implements View.OnCli
CareportalEventsViewHolder(View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.careportal_cardview);
date = (TextView) itemView.findViewById(R.id.careportal_date);
type = (TextView) itemView.findViewById(R.id.careportal_type);
note = (TextView) itemView.findViewById(R.id.careportal_note);
ns = (TextView) itemView.findViewById(R.id.ns_sign);
remove = (TextView) itemView.findViewById(R.id.careportal_remove);
remove.setOnClickListener(this);
cv = itemView.findViewById(R.id.careportal_cardview);
date = itemView.findViewById(R.id.careportal_date);
type = itemView.findViewById(R.id.careportal_type);
note = itemView.findViewById(R.id.careportal_note);
ns = itemView.findViewById(R.id.ns_sign);
remove = itemView.findViewById(R.id.careportal_remove);
remove.setOnClickListener(v -> {
final CareportalEvent careportalEvent = (CareportalEvent) v.getTag();
OKDialog.showConfirmation(getContext(), MainApp.gs(R.string.removerecord),
"\n" + MainApp.gs(R.string.careportal_newnstreatment_eventtype) + ": " + Translator.translate(careportalEvent.eventType) +
"\n" + MainApp.gs(R.string.careportal_newnstreatment_notes_label) + ": " + careportalEvent.getNotes() +
"\n" + MainApp.gs(R.string.date) + ": " + DateUtil.dateAndTimeString(careportalEvent.date),
(dialog, id) -> {
final String _id = careportalEvent._id;
if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
}
MainApp.getDbHelper().delete(careportalEvent);
}, null);
});
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
@Override
public void onClick(View v) {
final CareportalEvent careportalEvent = (CareportalEvent) v.getTag();
switch (v.getId()) {
case R.id.careportal_remove:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(careportalEvent.date));
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
final String _id = careportalEvent._id;
if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
}
MainApp.getDbHelper().delete(careportalEvent);
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
break;
}
}
}
}
@ -131,20 +118,23 @@ public class TreatmentsCareportalFragment extends Fragment implements View.OnCli
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.treatments_careportal_fragment, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.careportal_recyclerview);
recyclerView = view.findViewById(R.id.careportal_recyclerview);
recyclerView.setHasFixedSize(true);
llm = new LinearLayoutManager(view.getContext());
LinearLayoutManager llm = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(llm);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getDbHelper().getCareportalEvents(false));
recyclerView.setAdapter(adapter);
refreshFromNS = (Button) view.findViewById(R.id.careportal_refreshfromnightscout);
refreshFromNS.setOnClickListener(this);
Button refreshFromNS = view.findViewById(R.id.careportal_refreshfromnightscout);
refreshFromNS.setOnClickListener(v ->
OKDialog.showConfirmation(getContext(), MainApp.gs(R.string.careportal), MainApp.gs(R.string.refresheventsfromnightscout) + " ?", () -> {
MainApp.getDbHelper().resetCareportalEvents();
RxBus.INSTANCE.send(new EventNSClientRestart());
}));
view.findViewById(R.id.careportal_removeandroidapsstartedevents).setOnClickListener(this);
context = getContext();
view.findViewById(R.id.careportal_removeandroidapsstartedevents).setOnClickListener(v ->
OKDialog.showConfirmation(getContext(), MainApp.gs(R.string.careportal), MainApp.gs(R.string.careportal_removestartedevents), this::removeAndroidAPSStatedEvents));
boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false);
if (nsUploadOnly)
@ -170,36 +160,6 @@ public class TreatmentsCareportalFragment extends Fragment implements View.OnCli
disposable.clear();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.careportal_refreshfromnightscout:
AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.refresheventsfromnightscout) + " ?");
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MainApp.getDbHelper().resetCareportalEvents();
RxBus.INSTANCE.send(new EventNSClientRestart());
}
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
break;
case R.id.careportal_removeandroidapsstartedevents:
builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.careportal_removestartedevents));
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
removeAndroidAPSStatedEvents();
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
break;
}
}
private void updateGui() {
recyclerView.swapAdapter(new RecyclerViewAdapter(MainApp.getDbHelper().getCareportalEvents(false)), false);
}

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.plugins.treatments.fragments;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -9,7 +7,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
@ -31,6 +29,7 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.OKDialog;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
@ -38,10 +37,7 @@ import io.reactivex.disposables.CompositeDisposable;
public class TreatmentsExtendedBolusesFragment extends Fragment {
private CompositeDisposable disposable = new CompositeDisposable();
RecyclerView recyclerView;
LinearLayoutManager llm;
Context context;
private RecyclerView recyclerView;
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ExtendedBolusesViewHolder> {
@ -51,6 +47,7 @@ public class TreatmentsExtendedBolusesFragment extends Fragment {
this.extendedBolusList = extendedBolusList;
}
@NonNull
@Override
public ExtendedBolusesViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.treatments_extendedbolus_item, viewGroup, false);
@ -101,11 +98,11 @@ public class TreatmentsExtendedBolusesFragment extends Fragment {
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
public class ExtendedBolusesViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
class ExtendedBolusesViewHolder extends RecyclerView.ViewHolder {
CardView cv;
TextView date;
TextView duration;
@ -120,31 +117,22 @@ public class TreatmentsExtendedBolusesFragment extends Fragment {
ExtendedBolusesViewHolder(View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.extendedboluses_cardview);
date = (TextView) itemView.findViewById(R.id.extendedboluses_date);
duration = (TextView) itemView.findViewById(R.id.extendedboluses_duration);
insulin = (TextView) itemView.findViewById(R.id.extendedboluses_insulin);
realDuration = (TextView) itemView.findViewById(R.id.extendedboluses_realduration);
ratio = (TextView) itemView.findViewById(R.id.extendedboluses_ratio);
insulinSoFar = (TextView) itemView.findViewById(R.id.extendedboluses_netinsulin);
iob = (TextView) itemView.findViewById(R.id.extendedboluses_iob);
ph = (TextView) itemView.findViewById(R.id.pump_sign);
ns = (TextView) itemView.findViewById(R.id.ns_sign);
remove = (TextView) itemView.findViewById(R.id.extendedboluses_remove);
remove.setOnClickListener(this);
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
@Override
public void onClick(View v) {
final ExtendedBolus extendedBolus = (ExtendedBolus) v.getTag();
switch (v.getId()) {
case R.id.extendedboluses_remove:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(extendedBolus.date));
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
cv = itemView.findViewById(R.id.extendedboluses_cardview);
date = itemView.findViewById(R.id.extendedboluses_date);
duration = itemView.findViewById(R.id.extendedboluses_duration);
insulin = itemView.findViewById(R.id.extendedboluses_insulin);
realDuration = itemView.findViewById(R.id.extendedboluses_realduration);
ratio = itemView.findViewById(R.id.extendedboluses_ratio);
insulinSoFar = itemView.findViewById(R.id.extendedboluses_netinsulin);
iob = itemView.findViewById(R.id.extendedboluses_iob);
ph = itemView.findViewById(R.id.pump_sign);
ns = itemView.findViewById(R.id.ns_sign);
remove = itemView.findViewById(R.id.extendedboluses_remove);
remove.setOnClickListener(v -> {
final ExtendedBolus extendedBolus = (ExtendedBolus) v.getTag();
OKDialog.showConfirmation(getContext(), MainApp.gs(R.string.removerecord),
MainApp.gs(R.string.extended_bolus)
+ "\n" + MainApp.gs(R.string.date) + ": " + DateUtil.dateAndTimeString(extendedBolus.date), (dialog, id) -> {
final String _id = extendedBolus._id;
if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id);
@ -152,12 +140,9 @@ public class TreatmentsExtendedBolusesFragment extends Fragment {
UploadQueue.removeID("dbAdd", _id);
}
MainApp.getDbHelper().delete(extendedBolus);
}
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
break;
}
}, null);
});
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
}
}
@ -167,16 +152,14 @@ public class TreatmentsExtendedBolusesFragment extends Fragment {
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.treatments_extendedbolus_fragment, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.extendedboluses_recyclerview);
recyclerView = view.findViewById(R.id.extendedboluses_recyclerview);
recyclerView.setHasFixedSize(true);
llm = new LinearLayoutManager(view.getContext());
LinearLayoutManager llm = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(llm);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getExtendedBolusesFromHistory());
recyclerView.setAdapter(adapter);
context = getContext();
return view;
}
@ -205,5 +188,4 @@ public class TreatmentsExtendedBolusesFragment extends Fragment {
private void updateGui() {
recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getExtendedBolusesFromHistory()), false);
}
}

View file

@ -6,7 +6,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.cardview.widget.CardView
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
@ -42,18 +41,15 @@ class TreatmentsProfileSwitchFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
profileswitch_recyclerview.setHasFixedSize(true)
profileswitch_recyclerview.layoutManager = LinearLayoutManager(view.context)
profileswitch_recyclerview.adapter = RecyclerProfileViewAdapter(MainApp.getDbHelper().getProfileSwitchData(DateUtil.now() - T.days(30).msecs(),false))
profileswitch_recyclerview.adapter = RecyclerProfileViewAdapter(MainApp.getDbHelper().getProfileSwitchData(DateUtil.now() - T.days(30).msecs(), false))
profileswitch_refreshfromnightscout.setOnClickListener {
val builder = AlertDialog.Builder(this.context!!)
builder.setTitle(MainApp.gs(R.string.confirmation))
builder.setMessage(MainApp.gs(R.string.refresheventsfromnightscout) + "?")
builder.setPositiveButton(MainApp.gs(R.string.ok)) { _ , _->
MainApp.getDbHelper().resetProfileSwitch()
RxBus.send(EventNSClientRestart())
activity?.let { activity ->
OKDialog.showConfirmation(activity, MainApp.gs(R.string.refresheventsfromnightscout) + "?", Runnable {
MainApp.getDbHelper().resetProfileSwitch()
RxBus.send(EventNSClientRestart())
})
}
builder.setNegativeButton(MainApp.gs(R.string.cancel), null)
builder.show()
}
if (SP.getBoolean(R.string.key_ns_upload_only, false)) profileswitch_refreshfromnightscout.visibility = View.GONE
@ -63,9 +59,9 @@ class TreatmentsProfileSwitchFragment : Fragment() {
override fun onResume() {
super.onResume()
disposable.add(RxBus
.toObservable(EventProfileNeedsUpdate::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }) { FabricPrivacy.logException(it) }
.toObservable(EventProfileNeedsUpdate::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }) { FabricPrivacy.logException(it) }
)
updateGUI()
}
@ -77,7 +73,7 @@ class TreatmentsProfileSwitchFragment : Fragment() {
}
fun updateGUI() =
profileswitch_recyclerview?.swapAdapter(RecyclerProfileViewAdapter(MainApp.getDbHelper().getProfileSwitchData(DateUtil.now() - T.days(30).msecs(),false)), false)
profileswitch_recyclerview?.swapAdapter(RecyclerProfileViewAdapter(MainApp.getDbHelper().getProfileSwitchData(DateUtil.now() - T.days(30).msecs(), false)), false)
inner class RecyclerProfileViewAdapter(private var profileSwitchList: List<ProfileSwitch>) : RecyclerView.Adapter<ProfileSwitchViewHolder>() {
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ProfileSwitchViewHolder {
@ -121,21 +117,28 @@ class TreatmentsProfileSwitchFragment : Fragment() {
override fun onClick(v: View) {
val profileSwitch = v.tag as ProfileSwitch
when (v.id) {
R.id.profileswitch_remove ->
OKDialog.showConfirmation(activity, MainApp.gs(R.string.removerecord) + "\n" + profileSwitch.profileName + "\n" + DateUtil.dateAndTimeString(profileSwitch.date)) {
val id = profileSwitch._id
if (NSUpload.isIdValid(id)) NSUpload.removeCareportalEntryFromNS(id)
else UploadQueue.removeID("dbAdd", id)
MainApp.getDbHelper().delete(profileSwitch)
R.id.profileswitch_remove ->
activity?.let { activity ->
OKDialog.showConfirmation(activity, MainApp.gs(R.string.removerecord),
MainApp.gs(R.string.careportal_profileswitch) + ": " + profileSwitch.profileName +
"\n" + MainApp.gs(R.string.date) + ": " + DateUtil.dateAndTimeString(profileSwitch.date), Runnable {
val id = profileSwitch._id
if (NSUpload.isIdValid(id)) NSUpload.removeCareportalEntryFromNS(id)
else UploadQueue.removeID("dbAdd", id)
MainApp.getDbHelper().delete(profileSwitch)
})
}
R.id.profileswitch_clone ->
OKDialog.showConfirmation(activity, MainApp.gs(R.string.copytolocalprofile) + "\n" + profileSwitch.customizedName + "\n" + DateUtil.dateAndTimeString(profileSwitch.date)) {
profileSwitch.profileObject?.let {
val nonCustomized = it.convertToNonCustomizedProfile()
LocalProfilePlugin.addProfile(LocalProfilePlugin.SingleProfile().copyFrom(nonCustomized, profileSwitch.customizedName + " " + DateUtil.dateAndTimeString(profileSwitch.date).replace(".", "_")))
RxBus.send(EventLocalProfileChanged())
}
R.id.profileswitch_clone ->
activity?.let { activity ->
OKDialog.showConfirmation(activity, MainApp.gs(R.string.careportal_profileswitch), MainApp.gs(R.string.copytolocalprofile) + "\n" + profileSwitch.customizedName + "\n" + DateUtil.dateAndTimeString(profileSwitch.date), Runnable {
profileSwitch.profileObject?.let {
val nonCustomized = it.convertToNonCustomizedProfile()
LocalProfilePlugin.addProfile(LocalProfilePlugin.SingleProfile().copyFrom(nonCustomized, profileSwitch.customizedName + " " + DateUtil.dateAndTimeString(profileSwitch.date).replace(".", "_")))
RxBus.send(EventLocalProfileChanged())
}
})
}
R.id.profileswitch_date, R.id.profileswitch_name -> {
val args = Bundle()
args.putLong("time", (v.tag as ProfileSwitch).date)

View file

@ -1,8 +1,5 @@
package info.nightscout.androidaps.plugins.treatments.fragments;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -11,7 +8,7 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
@ -33,6 +30,7 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.SP;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
@ -41,14 +39,10 @@ import io.reactivex.disposables.CompositeDisposable;
* Created by mike on 13/01/17.
*/
public class TreatmentsTempTargetFragment extends Fragment implements View.OnClickListener {
public class TreatmentsTempTargetFragment extends Fragment {
private CompositeDisposable disposable = new CompositeDisposable();
RecyclerView recyclerView;
LinearLayoutManager llm;
Button refreshFromNS;
Context context;
private RecyclerView recyclerView;
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.TempTargetsViewHolder> {
@ -60,11 +54,11 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
currentlyActiveTarget = tempTargetList.getValueByInterval(System.currentTimeMillis());
}
@NonNull
@Override
public TempTargetsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.treatments_temptarget_item, viewGroup, false);
TempTargetsViewHolder TempTargetsViewHolder = new TempTargetsViewHolder(v);
return TempTargetsViewHolder;
return new TempTargetsViewHolder(v);
}
@Override
@ -104,11 +98,11 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
public class TempTargetsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
class TempTargetsViewHolder extends RecyclerView.ViewHolder {
CardView cv;
TextView date;
TextView duration;
@ -123,31 +117,23 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
TempTargetsViewHolder(View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.temptargetrange_cardview);
date = (TextView) itemView.findViewById(R.id.temptargetrange_date);
duration = (TextView) itemView.findViewById(R.id.temptargetrange_duration);
low = (TextView) itemView.findViewById(R.id.temptargetrange_low);
high = (TextView) itemView.findViewById(R.id.temptargetrange_high);
reason = (TextView) itemView.findViewById(R.id.temptargetrange_reason);
reasonLabel = (TextView) itemView.findViewById(R.id.temptargetrange_reason_label);
reasonColon = (TextView) itemView.findViewById(R.id.temptargetrange_reason_colon);
ph = (TextView) itemView.findViewById(R.id.pump_sign);
ns = (TextView) itemView.findViewById(R.id.ns_sign);
remove = (TextView) itemView.findViewById(R.id.temptargetrange_remove);
remove.setOnClickListener(this);
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
@Override
public void onClick(View v) {
final TempTarget tempTarget = (TempTarget) v.getTag();
switch (v.getId()) {
case R.id.temptargetrange_remove:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(tempTarget.date));
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
cv = itemView.findViewById(R.id.temptargetrange_cardview);
date = itemView.findViewById(R.id.temptargetrange_date);
duration = itemView.findViewById(R.id.temptargetrange_duration);
low = itemView.findViewById(R.id.temptargetrange_low);
high = itemView.findViewById(R.id.temptargetrange_high);
reason = itemView.findViewById(R.id.temptargetrange_reason);
reasonLabel = itemView.findViewById(R.id.temptargetrange_reason_label);
reasonColon = itemView.findViewById(R.id.temptargetrange_reason_colon);
ph = itemView.findViewById(R.id.pump_sign);
ns = itemView.findViewById(R.id.ns_sign);
remove = itemView.findViewById(R.id.temptargetrange_remove);
remove.setOnClickListener(v -> {
final TempTarget tempTarget = (TempTarget) v.getTag();
OKDialog.showConfirmation(getContext(), MainApp.gs(R.string.removerecord),
MainApp.gs(R.string.careportal_temporarytarget) + ": " + tempTarget.friendlyDescription(ProfileFunctions.getSystemUnits()) +
"\n" + DateUtil.dateAndTimeString(tempTarget.date),
(dialog, id) -> {
final String _id = tempTarget._id;
if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id);
@ -155,12 +141,9 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
UploadQueue.removeID("dbAdd", _id);
}
MainApp.getDbHelper().delete(tempTarget);
}
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
break;
}
}, null);
});
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
}
}
@ -170,18 +153,20 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.treatments_temptarget_fragment, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.temptargetrange_recyclerview);
recyclerView = view.findViewById(R.id.temptargetrange_recyclerview);
recyclerView.setHasFixedSize(true);
llm = new LinearLayoutManager(view.getContext());
LinearLayoutManager llm = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(llm);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getTempTargetsFromHistory());
recyclerView.setAdapter(adapter);
refreshFromNS = (Button) view.findViewById(R.id.temptargetrange_refreshfromnightscout);
refreshFromNS.setOnClickListener(this);
context = getContext();
Button refreshFromNS = view.findViewById(R.id.temptargetrange_refreshfromnightscout);
refreshFromNS.setOnClickListener(v ->
OKDialog.showConfirmation(getContext(), MainApp.gs(R.string.refresheventsfromnightscout) + " ?", () -> {
MainApp.getDbHelper().resetTempTargets();
RxBus.INSTANCE.send(new EventNSClientRestart());
}));
boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false);
if (nsUploadOnly)
@ -207,26 +192,6 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
disposable.clear();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.temptargetrange_refreshfromnightscout:
AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.refresheventsfromnightscout) + " ?");
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MainApp.getDbHelper().resetTempTargets();
RxBus.INSTANCE.send(new EventNSClientRestart());
}
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
break;
}
}
private void updateGui() {
recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getTempTargetsFromHistory()), false);
}

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.treatments.fragments;
import android.content.Context;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -9,7 +8,6 @@ import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
@ -33,6 +31,7 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.OKDialog;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
@ -40,12 +39,9 @@ import io.reactivex.disposables.CompositeDisposable;
public class TreatmentsTemporaryBasalsFragment extends Fragment {
private CompositeDisposable disposable = new CompositeDisposable();
RecyclerView recyclerView;
LinearLayoutManager llm;
private RecyclerView recyclerView;
TextView tempBasalTotalView;
Context context;
private TextView tempBasalTotalView;
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.TempBasalsViewHolder> {
@ -55,6 +51,7 @@ public class TreatmentsTemporaryBasalsFragment extends Fragment {
this.tempBasalList = tempBasalList;
}
@NonNull
@Override
public TempBasalsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.treatments_tempbasals_item, viewGroup, false);
@ -123,11 +120,11 @@ public class TreatmentsTemporaryBasalsFragment extends Fragment {
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
public class TempBasalsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
class TempBasalsViewHolder extends RecyclerView.ViewHolder {
CardView cv;
TextView date;
TextView duration;
@ -144,45 +141,37 @@ public class TreatmentsTemporaryBasalsFragment extends Fragment {
TempBasalsViewHolder(View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.tempbasals_cardview);
date = (TextView) itemView.findViewById(R.id.tempbasals_date);
duration = (TextView) itemView.findViewById(R.id.tempbasals_duration);
absolute = (TextView) itemView.findViewById(R.id.tempbasals_absolute);
percent = (TextView) itemView.findViewById(R.id.tempbasals_percent);
realDuration = (TextView) itemView.findViewById(R.id.tempbasals_realduration);
netRatio = (TextView) itemView.findViewById(R.id.tempbasals_netratio);
netInsulin = (TextView) itemView.findViewById(R.id.tempbasals_netinsulin);
iob = (TextView) itemView.findViewById(R.id.tempbasals_iob);
extendedFlag = (TextView) itemView.findViewById(R.id.tempbasals_extendedflag);
ph = (TextView) itemView.findViewById(R.id.pump_sign);
ns = (TextView) itemView.findViewById(R.id.ns_sign);
remove = (TextView) itemView.findViewById(R.id.tempbasals_remove);
remove.setOnClickListener(this);
cv = itemView.findViewById(R.id.tempbasals_cardview);
date = itemView.findViewById(R.id.tempbasals_date);
duration = itemView.findViewById(R.id.tempbasals_duration);
absolute = itemView.findViewById(R.id.tempbasals_absolute);
percent = itemView.findViewById(R.id.tempbasals_percent);
realDuration = itemView.findViewById(R.id.tempbasals_realduration);
netRatio = itemView.findViewById(R.id.tempbasals_netratio);
netInsulin = itemView.findViewById(R.id.tempbasals_netinsulin);
iob = itemView.findViewById(R.id.tempbasals_iob);
extendedFlag = itemView.findViewById(R.id.tempbasals_extendedflag);
ph = itemView.findViewById(R.id.pump_sign);
ns = itemView.findViewById(R.id.ns_sign);
remove = itemView.findViewById(R.id.tempbasals_remove);
remove.setOnClickListener(v -> {
final TemporaryBasal tempBasal = (TemporaryBasal) v.getTag();
OKDialog.showConfirmation(getContext(), MainApp.gs(R.string.removerecord),
MainApp.gs(R.string.pump_tempbasal_label) + ": " + tempBasal.toStringFull() +
"\n" + MainApp.gs(R.string.date) + ": " + DateUtil.dateAndTimeString(tempBasal.date),
((dialog, id) -> {
final String _id = tempBasal._id;
if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
}
MainApp.getDbHelper().delete(tempBasal);
}), null);
});
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
@Override
public void onClick(View v) {
final TemporaryBasal tempBasal = (TemporaryBasal) v.getTag();
switch (v.getId()) {
case R.id.tempbasals_remove:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(tempBasal.date));
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
final String _id = tempBasal._id;
if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
}
MainApp.getDbHelper().delete(tempBasal);
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
break;
}
}
}
}
@ -191,17 +180,15 @@ public class TreatmentsTemporaryBasalsFragment extends Fragment {
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.treatments_tempbasals_fragment, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.tempbasals_recyclerview);
recyclerView = view.findViewById(R.id.tempbasals_recyclerview);
recyclerView.setHasFixedSize(true);
llm = new LinearLayoutManager(view.getContext());
LinearLayoutManager llm = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(llm);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getTemporaryBasalsFromHistory());
recyclerView.setAdapter(adapter);
tempBasalTotalView = (TextView) view.findViewById(R.id.tempbasals_totaltempiob);
context = getContext();
tempBasalTotalView = view.findViewById(R.id.tempbasals_totaltempiob);
return view;
}

View file

@ -295,7 +295,7 @@ public class SWDefinition {
.validator(() -> LocalProfilePlugin.INSTANCE.getProfile() != null && LocalProfilePlugin.INSTANCE.getProfile().getDefaultProfile() != null && LocalProfilePlugin.INSTANCE.getProfile().getDefaultProfile().isValid("StartupWizard"))
.visibility(() -> LocalProfilePlugin.INSTANCE.isEnabled(PluginType.PROFILE));
private SWScreen screenProfileSwitch = new SWScreen(R.string.profileswitch)
private SWScreen screenProfileSwitch = new SWScreen(R.string.careportal_profileswitch)
.skippable(false)
.add(new SWInfotext()
.label(R.string.profileswitch_ismissing))

View file

@ -8,13 +8,10 @@ import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.MainActivity;
@ -37,8 +34,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
public class SetupWizardActivity extends NoSplashAppCompatActivity {
//logging
private static Logger log = LoggerFactory.getLogger(SetupWizardActivity.class);
private CompositeDisposable disposable = new CompositeDisposable();
ScrollView scrollView;
@ -54,7 +49,7 @@ public class SetupWizardActivity extends NoSplashAppCompatActivity {
LocaleHelper.INSTANCE.update(getApplicationContext());
setContentView(R.layout.activity_setupwizard);
scrollView = (ScrollView) findViewById(R.id.sw_scrollview);
scrollView = findViewById(R.id.sw_scrollview);
Intent intent = getIntent();
currentWizardPage = intent.getIntExtra(SetupWizardActivity.INTENT_MESSAGE, 0);
@ -62,7 +57,7 @@ public class SetupWizardActivity extends NoSplashAppCompatActivity {
SWScreen currentScreen = screens.get(currentWizardPage);
//Set screen name
TextView screenName = (TextView) findViewById(R.id.sw_content);
TextView screenName = findViewById(R.id.sw_content);
screenName.setText(currentScreen.getHeader());
swDefinition.setActivity(this);
@ -187,7 +182,7 @@ public class SetupWizardActivity extends NoSplashAppCompatActivity {
return page;
page++;
}
return Math.min(currentWizardPage, screens.size() -1);
return Math.min(currentWizardPage, screens.size() - 1);
}
private int previousPage() {
@ -201,17 +196,14 @@ public class SetupWizardActivity extends NoSplashAppCompatActivity {
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (permissions.length != 0) {
if (ActivityCompat.checkSelfPermission(this, permissions[0]) == PackageManager.PERMISSION_GRANTED) {
switch (requestCode) {
case AndroidPermission.CASE_STORAGE:
//show dialog after permission is granted
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setMessage(R.string.alert_dialog_storage_permission_text);
alert.setPositiveButton(R.string.ok, null);
alert.show();
OKDialog.show(this, MainApp.gs(R.string.permission), MainApp.gs(R.string.alert_dialog_storage_permission_text));
break;
case AndroidPermission.CASE_LOCATION:
case AndroidPermission.CASE_SMS:

View file

@ -2,9 +2,9 @@ package info.nightscout.androidaps.utils
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AlertDialog
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.db.CareportalEvent
@ -20,7 +20,6 @@ import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
@ -127,8 +126,8 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
if (useBg && bg > 0) {
bgDiff = when {
bg in targetBGLow..targetBGHigh -> 0.0
bg <= targetBGLow -> bg - targetBGLow
else -> bg - targetBGHigh
bg <= targetBGLow -> bg - targetBGLow
else -> bg - targetBGHigh
}
insulinFromBG = bgDiff / sens
}
@ -142,7 +141,6 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
}
}
// Insulin from carbs
ic = profile.ic
insulinFromCarbs = carbs / ic
@ -185,7 +183,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
}
val bolusStep = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription?.bolusStep
?: 0.1
?: 0.1
calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, bolusStep)
insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(Constraint(calculatedTotalInsulin)).value()
@ -236,7 +234,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
private fun confirmMessageAfterConstraints(pump: PumpInterface): String {
var confirmMessage = MainApp.gs(R.string.entertreatmentquestion)
var confirmMessage = ""
if (insulinAfterConstraints > 0) {
val pct = if (percentageCorrection != 100.0) " (" + percentageCorrection.toInt() + "%)" else ""
confirmMessage += "<br/>" + MainApp.gs(R.string.bolus) + ": " + "<font color='" + MainApp.gc(R.color.bolus) + "'>" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + "U" + pct + "</font>"
@ -268,89 +266,83 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
val pump = ConfigBuilderPlugin.getPlugin().activePump ?: return
if (calculatedTotalInsulin > 0.0 || carbs > 0.0) {
if (accepted) {
log.debug("guarding: already accepted")
return
}
accepted = true
val confirmMessage = confirmMessageAfterConstraints(pump)
val builder = AlertDialog.Builder(context)
builder.setTitle(MainApp.gs(R.string.confirmation))
builder.setMessage(HtmlHelper.fromHtml(confirmMessage))
builder.setPositiveButton(MainApp.gs(R.string.ok)) { _, _ ->
synchronized(builder) {
if (accepted) {
log.debug("guarding: already accepted")
return@setPositiveButton
}
accepted = true
if (insulinAfterConstraints > 0 || carbs > 0) {
if (useSuperBolus) {
val loopPlugin = LoopPlugin.getPlugin()
if (loopPlugin.isEnabled(PluginType.LOOP)) {
loopPlugin.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000)
RxBus.send(EventRefreshOverview("WizardDialog"))
}
val pump1 = ConfigBuilderPlugin.getPlugin().activePump
if (pump1?.pumpDescription?.tempBasalStyle == PumpDescription.ABSOLUTE) {
ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalAbsolute(0.0, 120, true, profile, object : Callback() {
override fun run() {
if (!result.success) {
val i = Intent(MainApp.instance(), ErrorHelperActivity::class.java)
i.putExtra("soundid", R.raw.boluserror)
i.putExtra("status", result.comment)
i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror))
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
MainApp.instance().startActivity(i)
}
}
})
} else {
ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalPercent(0, 120, true, profile, object : Callback() {
override fun run() {
if (!result.success) {
val i = Intent(MainApp.instance(), ErrorHelperActivity::class.java)
i.putExtra("soundid", R.raw.boluserror)
i.putExtra("status", result.comment)
i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror))
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
MainApp.instance().startActivity(i)
}
}
})
}
OKDialog.showConfirmation(context, MainApp.gs(R.string.boluswizard), HtmlHelper.fromHtml(confirmMessage), Runnable {
if (insulinAfterConstraints > 0 || carbs > 0) {
if (useSuperBolus) {
val loopPlugin = LoopPlugin.getPlugin()
if (loopPlugin.isEnabled(PluginType.LOOP)) {
loopPlugin.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000)
RxBus.send(EventRefreshOverview("WizardDialog"))
}
val detailedBolusInfo = DetailedBolusInfo()
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD
detailedBolusInfo.insulin = insulinAfterConstraints
detailedBolusInfo.carbs = carbs.toDouble()
detailedBolusInfo.context = context
detailedBolusInfo.glucose = bg
detailedBolusInfo.glucoseType = "Manual"
detailedBolusInfo.carbTime = carbTime
detailedBolusInfo.boluscalc = nsJSON()
detailedBolusInfo.source = Source.USER
detailedBolusInfo.notes = notes
if (detailedBolusInfo.insulin > 0 || ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription?.storesCarbInfo == true) {
ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() {
val pump1 = ConfigBuilderPlugin.getPlugin().activePump
if (pump1?.pumpDescription?.tempBasalStyle == PumpDescription.ABSOLUTE) {
ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalAbsolute(0.0, 120, true, profile, object : Callback() {
override fun run() {
if (!result.success) {
val i = Intent(MainApp.instance(), ErrorHelperActivity::class.java)
i.putExtra("soundid", R.raw.boluserror)
i.putExtra("status", result.comment)
i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror))
i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror))
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
MainApp.instance().startActivity(i)
}
}
})
} else {
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false)
ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalPercent(0, 120, true, profile, object : Callback() {
override fun run() {
if (!result.success) {
val i = Intent(MainApp.instance(), ErrorHelperActivity::class.java)
i.putExtra("soundid", R.raw.boluserror)
i.putExtra("status", result.comment)
i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror))
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
MainApp.instance().startActivity(i)
}
}
})
}
}
val detailedBolusInfo = DetailedBolusInfo()
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD
detailedBolusInfo.insulin = insulinAfterConstraints
detailedBolusInfo.carbs = carbs.toDouble()
detailedBolusInfo.context = context
detailedBolusInfo.glucose = bg
detailedBolusInfo.glucoseType = "Manual"
detailedBolusInfo.carbTime = carbTime
detailedBolusInfo.boluscalc = nsJSON()
detailedBolusInfo.source = Source.USER
detailedBolusInfo.notes = notes
if (detailedBolusInfo.insulin > 0 || ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription?.storesCarbInfo == true) {
ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() {
override fun run() {
if (!result.success) {
val i = Intent(MainApp.instance(), ErrorHelperActivity::class.java)
i.putExtra("soundid", R.raw.boluserror)
i.putExtra("status", result.comment)
i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror))
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
MainApp.instance().startActivity(i)
}
}
})
} else {
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false)
}
}
}
builder.setNegativeButton(MainApp.gs(R.string.cancel), null)
builder.show()
})
}
}
}

View file

@ -1,127 +0,0 @@
package info.nightscout.androidaps.utils;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.os.SystemClock;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.view.ContextThemeWrapper;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
public class OKDialog {
public static void show(final Context context, String title, String message, final Runnable runnable) {
if (title.isEmpty()) title = MainApp.gs(R.string.message);
View titleLayout = LayoutInflater.from(context).inflate(R.layout.dialog_alert_custom, null);
((TextView)titleLayout.findViewById(R.id.alertdialog_title)).setText(title);
((ImageView)titleLayout.findViewById(R.id.alertdialog_icon)).setImageResource(R.drawable.ic_check_while_48dp);
new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.AppTheme))
.setCustomTitle(titleLayout)
.setMessage(message)
.setPositiveButton(MainApp.gs(R.string.ok), (dialog, which) -> {
dialog.dismiss();
if (runnable != null) {
SystemClock.sleep(100);
runOnUiThread(runnable);
}
})
.show()
.setCanceledOnTouchOutside(false);
}
public static boolean runOnUiThread(Runnable theRunnable) {
final Handler mainHandler = new Handler(MainApp.instance().getApplicationContext().getMainLooper());
return mainHandler.post(theRunnable);
}
public static void show(final Activity activity, String title, Spanned message, final Runnable runnable) {
if (title.isEmpty()) title = MainApp.gs(R.string.message);
View titleLayout = activity.getLayoutInflater().inflate(R.layout.dialog_alert_custom, null);
((TextView)titleLayout.findViewById(R.id.alertdialog_title)).setText(title);
((ImageView)titleLayout.findViewById(R.id.alertdialog_icon)).setImageResource(R.drawable.ic_check_while_48dp);
new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme))
.setCustomTitle(titleLayout)
.setMessage(message)
.setPositiveButton(MainApp.gs(R.string.ok), (dialog, which) -> {
dialog.dismiss();
if (runnable != null) {
SystemClock.sleep(100);
activity.runOnUiThread(runnable);
}
})
.show()
.setCanceledOnTouchOutside(false);
}
public static void showConfirmation(final Activity activity, String message, final Runnable ok) {
showConfirmation(activity, message, ok, null);
}
public static void showConfirmation(final Activity activity, Spanned message, final Runnable ok) {
showConfirmation(activity, message, ok, null);
}
public static void showConfirmation(final Activity activity, Spanned message, final Runnable ok, final Runnable cancel) {
View titleLayout = activity.getLayoutInflater().inflate(R.layout.dialog_alert_custom, null);
((TextView)titleLayout.findViewById(R.id.alertdialog_title)).setText(R.string.confirmation);
((ImageView)titleLayout.findViewById(R.id.alertdialog_icon)).setImageResource(R.drawable.ic_check_while_48dp);
new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme))
.setMessage(message)
.setCustomTitle(titleLayout)
.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);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show()
.setCanceledOnTouchOutside(false);
}
public static void showConfirmation(final Activity activity, String message, final Runnable ok, final Runnable cancel) {
View titleLayout = activity.getLayoutInflater().inflate(R.layout.dialog_alert_custom, null);
((TextView)titleLayout.findViewById(R.id.alertdialog_title)).setText(R.string.confirmation);
((ImageView)titleLayout.findViewById(R.id.alertdialog_icon)).setImageResource(R.drawable.ic_check_while_48dp);
new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme))
.setMessage(message)
.setCustomTitle(titleLayout)
.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()
.setCanceledOnTouchOutside(false);
}
}

View file

@ -0,0 +1,203 @@
package info.nightscout.androidaps.utils
import android.app.Activity
import android.content.Context
import android.content.DialogInterface
import android.os.Handler
import android.os.SystemClock
import android.text.Spanned
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.view.ContextThemeWrapper
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
object OKDialog {
@JvmStatic
@JvmOverloads
fun show(context: Context, title: String, message: String, runnable: Runnable? = null) {
var notEmptytitle = title
if (notEmptytitle.isEmpty()) notEmptytitle = MainApp.gs(R.string.message)
val titleLayout = LayoutInflater.from(context).inflate(R.layout.dialog_alert_custom, null)
(titleLayout.findViewById<View>(R.id.alertdialog_title) as TextView).text = notEmptytitle
(titleLayout.findViewById<View>(R.id.alertdialog_icon) as ImageView).setImageResource(R.drawable.ic_check_while_48dp)
AlertDialog.Builder(ContextThemeWrapper(context, R.style.AppTheme))
.setCustomTitle(titleLayout)
.setMessage(message)
.setPositiveButton(MainApp.gs(R.string.ok)) { dialog: DialogInterface, _: Int ->
dialog.dismiss()
SystemClock.sleep(100)
runOnUiThread(runnable)
}
.show()
.setCanceledOnTouchOutside(false)
}
fun runOnUiThread(theRunnable: Runnable?) {
val mainHandler = Handler(MainApp.instance().applicationContext.mainLooper)
theRunnable?.let { mainHandler.post(it) }
}
@JvmStatic
@JvmOverloads
fun show(activity: Activity, title: String, message: Spanned, runnable: Runnable? = null) {
var notEmptytitle = title
if (notEmptytitle.isEmpty()) notEmptytitle = MainApp.gs(R.string.message)
val titleLayout = activity.layoutInflater.inflate(R.layout.dialog_alert_custom, null)
(titleLayout.findViewById<View>(R.id.alertdialog_title) as TextView).text = notEmptytitle
(titleLayout.findViewById<View>(R.id.alertdialog_icon) as ImageView).setImageResource(R.drawable.ic_check_while_48dp)
AlertDialog.Builder(ContextThemeWrapper(activity, R.style.AppTheme))
.setCustomTitle(titleLayout)
.setMessage(message)
.setPositiveButton(MainApp.gs(R.string.ok)) { dialog: DialogInterface, _: Int ->
dialog.dismiss()
SystemClock.sleep(100)
runnable?.let { activity.runOnUiThread(it) }
}
.show()
.setCanceledOnTouchOutside(false)
}
@JvmStatic
@JvmOverloads
fun showConfirmation(activity: Activity, message: String, ok: Runnable?) {
showConfirmation(activity, MainApp.gs(R.string.confirmation), message, ok, null)
}
@JvmStatic
@JvmOverloads
fun showConfirmation(activity: Activity, message: Spanned, ok: Runnable?) {
showConfirmation(activity, MainApp.gs(R.string.confirmation), message, ok, null)
}
@JvmStatic
@JvmOverloads
fun showConfirmation(activity: Activity, title: String, message: Spanned, ok: Runnable?, cancel: Runnable? = null) {
val titleLayout = activity.layoutInflater.inflate(R.layout.dialog_alert_custom, null)
(titleLayout.findViewById<View>(R.id.alertdialog_title) as TextView).text = title
(titleLayout.findViewById<View>(R.id.alertdialog_icon) as ImageView).setImageResource(R.drawable.ic_check_while_48dp)
AlertDialog.Builder(ContextThemeWrapper(activity, R.style.AppTheme))
.setMessage(message)
.setCustomTitle(titleLayout)
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int ->
dialog.dismiss()
SystemClock.sleep(100)
ok?.let { activity.runOnUiThread(it) }
}
.setNegativeButton(android.R.string.cancel) { dialog: DialogInterface, _: Int ->
dialog.dismiss()
SystemClock.sleep(100)
cancel?.let { activity.runOnUiThread(it) }
}
.setNegativeButton(android.R.string.cancel, null)
.show()
.setCanceledOnTouchOutside(false)
}
@JvmStatic
fun showConfirmation(activity: Activity, title: String, message: String, ok: Runnable?, cancel: Runnable? = null) {
val titleLayout = activity.layoutInflater.inflate(R.layout.dialog_alert_custom, null)
(titleLayout.findViewById<View>(R.id.alertdialog_title) as TextView).text = title
(titleLayout.findViewById<View>(R.id.alertdialog_icon) as ImageView).setImageResource(R.drawable.ic_check_while_48dp)
AlertDialog.Builder(ContextThemeWrapper(activity, R.style.AppTheme))
.setMessage(message)
.setCustomTitle(titleLayout)
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int ->
dialog.dismiss()
SystemClock.sleep(100)
ok?.let { activity.runOnUiThread(it) }
}
.setNegativeButton(android.R.string.cancel) { dialog: DialogInterface, _: Int ->
dialog.dismiss()
SystemClock.sleep(100)
cancel?.let { activity.runOnUiThread(it) }
}
.show()
.setCanceledOnTouchOutside(false)
}
@JvmStatic
@JvmOverloads
fun showConfirmation(context: Context, message: Spanned, ok: Runnable?, cancel: Runnable? = null) {
showConfirmation(context, MainApp.gs(R.string.confirmation), message, ok, cancel)
}
@JvmStatic
@JvmOverloads
fun showConfirmation(context: Context, title: String, message: Spanned, ok: Runnable?, cancel: Runnable? = null) {
val titleLayout = LayoutInflater.from(context).inflate(R.layout.dialog_alert_custom, null)
(titleLayout.findViewById<View>(R.id.alertdialog_title) as TextView).text = title
(titleLayout.findViewById<View>(R.id.alertdialog_icon) as ImageView).setImageResource(R.drawable.ic_check_while_48dp)
AlertDialog.Builder(ContextThemeWrapper(context, R.style.AppTheme))
.setMessage(message)
.setCustomTitle(titleLayout)
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int ->
dialog.dismiss()
SystemClock.sleep(100)
runOnUiThread(ok)
}
.setNegativeButton(android.R.string.cancel) { dialog: DialogInterface, _: Int ->
dialog.dismiss()
SystemClock.sleep(100)
runOnUiThread(cancel)
}
.setNegativeButton(android.R.string.cancel, null)
.show()
.setCanceledOnTouchOutside(false)
}
@JvmStatic
@JvmOverloads
fun showConfirmation(context: Context, message: String, ok: Runnable?, cancel: Runnable? = null) {
showConfirmation(context, MainApp.gs(R.string.confirmation), message, ok, cancel)
}
@JvmStatic
@JvmOverloads
fun showConfirmation(context: Context, title: String, message: String, ok: Runnable?, cancel: Runnable? = null) {
val titleLayout = LayoutInflater.from(context).inflate(R.layout.dialog_alert_custom, null)
(titleLayout.findViewById<View>(R.id.alertdialog_title) as TextView).text = title
(titleLayout.findViewById<View>(R.id.alertdialog_icon) as ImageView).setImageResource(R.drawable.ic_check_while_48dp)
AlertDialog.Builder(ContextThemeWrapper(context, R.style.AppTheme))
.setMessage(message)
.setCustomTitle(titleLayout)
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int ->
dialog.dismiss()
SystemClock.sleep(100)
runOnUiThread(ok)
}
.setNegativeButton(android.R.string.cancel) { dialog: DialogInterface, _: Int ->
dialog.dismiss()
SystemClock.sleep(100)
runOnUiThread(cancel)
}
.show()
.setCanceledOnTouchOutside(false)
}
@JvmStatic
@JvmOverloads
fun showConfirmation(context: Context, title: String, message: String, ok: DialogInterface.OnClickListener?, cancel: DialogInterface.OnClickListener? = null) {
val titleLayout = LayoutInflater.from(context).inflate(R.layout.dialog_alert_custom, null)
(titleLayout.findViewById<View>(R.id.alertdialog_title) as TextView).text = title
(titleLayout.findViewById<View>(R.id.alertdialog_icon) as ImageView).setImageResource(R.drawable.ic_check_while_48dp)
AlertDialog.Builder(ContextThemeWrapper(context, R.style.AppTheme))
.setMessage(message)
.setCustomTitle(titleLayout)
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, which: Int ->
dialog.dismiss()
SystemClock.sleep(100)
ok?.onClick(dialog, which)
}
.setNegativeButton(android.R.string.cancel) { dialog: DialogInterface, which: Int ->
dialog.dismiss()
SystemClock.sleep(100)
cancel?.onClick(dialog, which)
}
.show()
.setCanceledOnTouchOutside(false)
}
}

View file

@ -2,10 +2,10 @@ package info.nightscout.androidaps.utils;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import info.nightscout.androidaps.MainApp;
@ -18,10 +18,7 @@ import info.nightscout.androidaps.R;
public class PasswordProtection {
static public boolean isLocked(String preference) {
final String password = SP.getString(preference, "");
if (password.equals("")) {
return false;
}
return true;
return !password.equals("");
}
static public void QueryPassword(final Context context, int stringID, String preference, final Runnable ok, final Runnable fail) {
@ -30,39 +27,38 @@ public class PasswordProtection {
if (ok != null) ok.run();
return;
}
LayoutInflater li = LayoutInflater.from(context);
View promptsView = li.inflate(R.layout.passwordprompt, null);
View promptsView = LayoutInflater.from(context).inflate(R.layout.passwordprompt, null);
View titleLayout = LayoutInflater.from(context).inflate(R.layout.dialog_alert_custom, null);
((TextView) titleLayout.findViewById(R.id.alertdialog_title)).setText(R.string.confirmation);
((ImageView) titleLayout.findViewById(R.id.alertdialog_icon)).setImageResource(R.drawable.ic_check_while_48dp);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setView(promptsView);
alertDialogBuilder.setCustomTitle(titleLayout);
final TextView label = (TextView) promptsView.findViewById(R.id.passwordprompt_text);
final TextView label = promptsView.findViewById(R.id.passwordprompt_text);
label.setText(MainApp.gs(stringID));
final EditText userInput = (EditText) promptsView.findViewById(R.id.passwordprompt_pass);
final EditText userInput = promptsView.findViewById(R.id.passwordprompt_pass);
// set dialog message
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
String enteredPassword = userInput.getText().toString();
if (password.equals(enteredPassword)) {
if (ok != null) ok.run();
} else {
ToastUtils.showToastInUiThread(context, MainApp.gs(R.string.wrongpassword));
if (fail != null) fail.run();
}
.setPositiveButton(android.R.string.ok,
(dialog, id) -> {
String enteredPassword = userInput.getText().toString();
if (password.equals(enteredPassword)) {
if (ok != null) ok.run();
} else {
ToastUtils.showToastInUiThread(context, MainApp.gs(R.string.wrongpassword));
if (fail != null) fail.run();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
.setNegativeButton(android.R.string.cancel,
(dialog, id) -> dialog.cancel());
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
alertDialog.setCanceledOnTouchOutside(false);
}
}

View file

@ -1,11 +1,9 @@
package info.nightscout.androidaps.utils;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import androidx.appcompat.app.AlertDialog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -25,20 +23,10 @@ import info.nightscout.androidaps.services.Intents;
public class XdripCalibrations {
private static Logger log = LoggerFactory.getLogger(XdripCalibrations.class);
public static void confirmAndSendCalibration(final Double bg, Context parentContext) {
public static void confirmAndSendCalibration(final Double bg, final Context parentContext) {
if (parentContext != null) {
String confirmMessage = String.format(MainApp.gs(R.string.send_calibration), bg);
AlertDialog.Builder builder = new AlertDialog.Builder(parentContext);
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(confirmMessage);
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
sendIntent(bg);
}
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
OKDialog.showConfirmation(parentContext, confirmMessage, () -> sendIntent(bg));
}
}

View file

@ -38,7 +38,7 @@
android:gravity="center_vertical|center_horizontal"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="@string/extendedbolus" />
android:text="@string/extended_bolus" />
<TextView
android:id="@+id/treatments_tempbasals"
@ -48,7 +48,7 @@
android:gravity="center_vertical|center_horizontal"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="@string/tempbasal" />
android:text="@string/pump_tempbasal_label" />
<TextView
android:id="@+id/treatments_temptargets"
@ -58,7 +58,7 @@
android:gravity="center_vertical|center_horizontal"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="@string/temptarget" />
android:text="@string/careportal_temporarytarget" />
<TextView
android:id="@+id/treatments_profileswitches"
@ -68,7 +68,7 @@
android:gravity="center_vertical|center_horizontal"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="@string/profileswitch" />
android:text="@string/careportal_profileswitch" />
<TextView
android:id="@+id/treatments_careportal"

View file

@ -136,7 +136,6 @@
<string name="overview">Overview</string>
<string name="nsprofile">NS Profile</string>
<string name="simpleprofile">Simple profile</string>
<string name="tempbasal">TempBasal</string>
<string name="treatments">Treatments</string>
<string name="virtualpump">Virtual Pump</string>
<string name="careportal">Careportal</string>
@ -177,14 +176,12 @@
<string name="overview_calculator_label">Calculator</string>
<string name="constraintapllied">Constraint applied!</string>
<string name="confirmation">Confirmation</string>
<string name="entertreatmentquestion">Enter new treatment:</string>
<string name="bolus">Bolus</string>
<string name="sms_bolus">Bolus:</string>
<string name="basal">Basal</string>
<string name="sms_basal">Basal:</string>
<string name="carbs">Carbs</string>
<string name="changeyourinput">Change your input!</string>
<string name="setextendedbolusquestion">Set new extended bolus:</string>
<string name="configbuilder_bgsource">BG Source</string>
<string name="configbuilder_bgsource_description">Where should AndroidAPS gain it\'s data from?</string>
<string name="xdrip">xDrip</string>
@ -213,7 +210,7 @@
<string name="careportal_cgmsensorinsert">CGM Sensor Insert</string>
<string name="careportal_cgmsensorstart">CGM Sensor Start</string>
<string name="careportal_insulincartridgechange">Insulin Cartridge Change</string>
<string name="careportal_profileswitch">Profile Switch</string>
<string name="careportal_profileswitch">Profile switch</string>
<string name="careportal_snackbolus">Snack Bolus</string>
<string name="careportal_mealbolus">Meal Bolus</string>
<string name="careportal_correctionbolus">Correction Bolus</string>
@ -312,8 +309,8 @@
<string name="glucosetype_finger">Finger</string>
<string name="glucosetype_sensor">Sensor</string>
<string name="manual">Manual</string>
<string name="careportal_temporarytarget">Temporary Target</string>
<string name="careportal_temporarytargetcancel">Temporary Target Cancel</string>
<string name="careportal_temporarytarget">Temporary target</string>
<string name="careportal_temporarytargetcancel">Temporary target cancel</string>
<string name="danarprofile">DanaR profile settings</string>
<string name="danarprofile_dia">DIA [h]</string>
<string name="danarprofile_dia_summary">Duration of Insulin Activity</string>
@ -453,7 +450,7 @@
<string name="eatingsoon">Eating Soon</string>
<string name="hypo">Hypo</string>
<string name="activity">Activity</string>
<string name="removerecord">Remove record:</string>
<string name="removerecord">Remove record</string>
<string name="danar_stats">DanaR Stats</string>
<string name="danar_stats_cumulative_tdd">Cumulative TDD</string>
<string name="danar_stats_expweight">Exponentially Weighted TDD</string>
@ -648,15 +645,12 @@
<string name="key_ns_noupload" translatable="false">ns_noupload</string>
<string name="basal_step">Basal Step</string>
<string name="bolus_step">Bolus Step</string>
<string name="extendedbolus">ExtendedBolus</string>
<string name="temptarget">TempTarget</string>
<string name="overview_extendedbolus_cancel_button">Cancel Extended Bolus</string>
<string name="careportal_sensorage_label">Sensor age</string>
<string name="careportal_canulaage_label">Canula age</string>
<string name="careportal_insulinage_label">Insulin age</string>
<string name="hours">hours</string>
<string name="invalidprofile">Invalid profile !!!</string>
<string name="profileswitch">ProfileSwitch</string>
<string name="doprofileswitch">Do Profile Switch</string>
<string name="careportal_pbage_label">Pump battery age</string>
<string name="careportal_pumpbatterychange">Pump Battery Change</string>
@ -1692,5 +1686,6 @@
<string name="automation_event">Automation event</string>
<string name="alreadyset">Already set</string>
<string name="message">Message</string>
<string name="clearqueueconfirm">Clear queue? All data in queue will be lost!</string>
</resources>