remove some static dependencies
This commit is contained in:
parent
c0f6f1a5e9
commit
a2ebcb5ff0
11 changed files with 78 additions and 118 deletions
|
@ -217,16 +217,6 @@ public class MainApp extends DaggerApplication {
|
|||
return sResources.getString(id, args);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static int gc(@ColorRes int id) {
|
||||
return ContextCompat.getColor(instance(), id);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Resources resources() {
|
||||
return sResources;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static MainApp instance() {
|
||||
return sInstance;
|
||||
|
|
|
@ -42,6 +42,7 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval {
|
|||
@Inject ProfileFunction profileFunction;
|
||||
@Inject ResourceHelper resourceHelper;
|
||||
@Inject AAPSLogger aapsLogger;
|
||||
@Inject Translator translator;
|
||||
|
||||
@DatabaseField(id = true)
|
||||
public long date;
|
||||
|
@ -227,7 +228,7 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval {
|
|||
} catch (JSONException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return Translator.translate(eventType);
|
||||
return translator.translate(eventType);
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
|
|
|
@ -3,15 +3,12 @@ package info.nightscout.androidaps.db;
|
|||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.util.Locale;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
||||
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||
|
||||
/**
|
||||
* Created by mike on 20.09.2017.
|
||||
|
@ -20,7 +17,6 @@ import info.nightscout.androidaps.utils.DateUtil;
|
|||
|
||||
@DatabaseTable(tableName = DatabaseHelper.DATABASE_TDDS)
|
||||
public class TDD {
|
||||
private static Logger log = StacktraceLoggerWrapper.getLogger(L.DATABASE);
|
||||
|
||||
@DatabaseField(id = true)
|
||||
public long date;
|
||||
|
@ -35,14 +31,15 @@ public class TDD {
|
|||
public double total;
|
||||
|
||||
|
||||
public double getTotal(){
|
||||
return (total > 0d) ? total:(bolus+basal);
|
||||
public double getTotal() {
|
||||
return (total > 0d) ? total : (bolus + basal);
|
||||
}
|
||||
|
||||
|
||||
public TDD() { }
|
||||
public TDD() {
|
||||
}
|
||||
|
||||
public TDD(long date, double bolus, double basal, double total){
|
||||
public TDD(long date, double bolus, double basal, double total) {
|
||||
this.date = date;
|
||||
this.bolus = bolus;
|
||||
this.basal = basal;
|
||||
|
@ -61,11 +58,11 @@ public class TDD {
|
|||
']';
|
||||
}
|
||||
|
||||
public String toText() {
|
||||
return MainApp.gs(R.string.tddformat, DateUtil.dateStringShort(date), total, bolus, basal);
|
||||
public String toText(ResourceHelper resourceHelper) {
|
||||
return resourceHelper.gs(R.string.tddformat, DateUtil.dateStringShort(date), total, bolus, basal);
|
||||
}
|
||||
|
||||
public String toText(int days) {
|
||||
return MainApp.gs(R.string.tddformat, String.format("%d ", days) + MainApp.gs(R.string.days), total, bolus, basal);
|
||||
public String toText(ResourceHelper resourceHelper, int days) {
|
||||
return resourceHelper.gs(R.string.tddformat, String.format(Locale.getDefault(), "%d ", days) + resourceHelper.gs(R.string.days), total, bolus, basal);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ class CareDialog : DialogFragmentWithDate() {
|
|||
@Inject lateinit var mainApp: MainApp
|
||||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var profileFunction: ProfileFunction
|
||||
@Inject lateinit var translator: Translator
|
||||
|
||||
enum class EventType {
|
||||
BGCHECK,
|
||||
|
@ -149,7 +150,7 @@ class CareDialog : DialogFragmentWithDate() {
|
|||
actions_care_sensor.isChecked -> "Sensor"
|
||||
else -> "Manual"
|
||||
}
|
||||
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_glucosetype) + ": " + Translator.translate(type))
|
||||
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_glucosetype) + ": " + translator.translate(type))
|
||||
actions.add(resourceHelper.gs(R.string.treatments_wizard_bg_label) + ": " + Profile.toCurrentUnitsString(profileFunction, actions_care_bg.value) + " " + resourceHelper.gs(unitResId))
|
||||
json.put("glucose", actions_care_bg.value)
|
||||
json.put("glucoseType", type)
|
||||
|
|
|
@ -78,6 +78,7 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O
|
|||
@Inject ActivePluginProvider activePlugin;
|
||||
@Inject TreatmentsPlugin treatmentsPlugin;
|
||||
@Inject HardLimits hardLimits;
|
||||
@Inject Translator translator;
|
||||
|
||||
private static OptionsToShow options;
|
||||
private static @StringRes int event;
|
||||
|
@ -623,7 +624,7 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O
|
|||
if (data.has("glucoseType")) {
|
||||
ret += resourceHelper.gs(R.string.careportal_newnstreatment_glucosetype);
|
||||
ret += ": ";
|
||||
ret += Translator.translate(JsonHelper.safeGetString(data, "glucoseType", ""));
|
||||
ret += translator.translate(JsonHelper.safeGetString(data, "glucoseType", ""));
|
||||
ret += "\n";
|
||||
}
|
||||
if (data.has("carbs")) {
|
||||
|
@ -712,7 +713,7 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O
|
|||
|
||||
private void confirmNSTreatmentCreation() {
|
||||
final JSONObject data = gatherData();
|
||||
OKDialog.showConfirmation(getContext(), Translator.translate(JsonHelper.safeGetString(data, "eventType", resourceHelper.gs(R.string.overview_treatment_label))), buildConfirmText(data), () -> NSUpload.createNSTreatment(data, profileStore, profileFunction, eventTime.getTime()));
|
||||
OKDialog.showConfirmation(getContext(), translator.translate(JsonHelper.safeGetString(data, "eventType", resourceHelper.gs(R.string.overview_treatment_label))), buildConfirmText(data), () -> NSUpload.createNSTreatment(data, profileStore, profileFunction, eventTime.getTime()));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
@Inject lateinit var sp: SP
|
||||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Inject lateinit var translator: Translator
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
|
@ -108,7 +109,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
holder.date.text = DateUtil.dateAndTimeString(careportalEvent.date)
|
||||
holder.duration.text = if (careportalEvent.durationInMsec() == 0L) "" else DateUtil.niceTimeScalar(careportalEvent.durationInMsec(), resourceHelper)
|
||||
holder.note.text = careportalEvent.notes
|
||||
holder.type.text = Translator.translate(careportalEvent.eventType)
|
||||
holder.type.text = translator.translate(careportalEvent.eventType)
|
||||
holder.remove.tag = careportalEvent
|
||||
}
|
||||
|
||||
|
@ -129,7 +130,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
remove.setOnClickListener { v: View ->
|
||||
val careportalEvent = v.tag as CareportalEvent
|
||||
activity?.let { activity ->
|
||||
val text = resourceHelper.gs(R.string.careportal_newnstreatment_eventtype) + ": " + Translator.translate(careportalEvent.eventType) + "\n" +
|
||||
val text = resourceHelper.gs(R.string.careportal_newnstreatment_eventtype) + ": " + translator.translate(careportalEvent.eventType) + "\n" +
|
||||
resourceHelper.gs(R.string.careportal_newnstreatment_notes_label) + ": " + careportalEvent.notes + "\n" +
|
||||
resourceHelper.gs(R.string.date) + ": " + DateUtil.dateAndTimeString(careportalEvent.date)
|
||||
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable {
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.os.Handler;
|
|||
import android.os.Message;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.method.DigitsKeyListener;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -15,24 +14,18 @@ import android.widget.Button;
|
|||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
||||
|
||||
/**
|
||||
* Created by mike on 28.06.2016.
|
||||
*/
|
||||
public class NumberPicker extends LinearLayout implements View.OnKeyListener,
|
||||
View.OnTouchListener, View.OnClickListener {
|
||||
private static Logger log = StacktraceLoggerWrapper.getLogger(NumberPicker.class);
|
||||
|
||||
public interface OnValueChangedListener {
|
||||
void onValueChanged(double value);
|
||||
|
@ -172,14 +165,14 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
|
|||
value = SafeParse.stringToDouble(editText.getText().toString());
|
||||
if (value > maxValue) {
|
||||
value = maxValue;
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.youareonallowedlimit));
|
||||
ToastUtils.showToastInUiThread(getContext(), getContext().getString(R.string.youareonallowedlimit));
|
||||
updateEditText();
|
||||
if (okButton != null)
|
||||
okButton.setVisibility(VISIBLE);
|
||||
}
|
||||
if (value < minValue) {
|
||||
value = minValue;
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.youareonallowedlimit));
|
||||
ToastUtils.showToastInUiThread(getContext(), getContext().getString(R.string.youareonallowedlimit));
|
||||
updateEditText();
|
||||
if (okButton != null)
|
||||
okButton.setVisibility(VISIBLE);
|
||||
|
@ -244,7 +237,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
|
|||
if (value > maxValue) {
|
||||
value = maxValue;
|
||||
callValueChangedListener();
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.youareonallowedlimit));
|
||||
ToastUtils.showToastInUiThread(getContext(), getContext().getString(R.string.youareonallowedlimit));
|
||||
stopUpdating();
|
||||
}
|
||||
updateEditText();
|
||||
|
@ -255,7 +248,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
|
|||
if (value < minValue) {
|
||||
value = minValue;
|
||||
callValueChangedListener();
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.youareonallowedlimit));
|
||||
ToastUtils.showToastInUiThread(getContext(), getContext().getString(R.string.youareonallowedlimit));
|
||||
stopUpdating();
|
||||
}
|
||||
updateEditText();
|
||||
|
@ -275,7 +268,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
|
|||
|
||||
private void startUpdating(boolean inc) {
|
||||
if (mUpdater != null) {
|
||||
log.debug("Another executor is still active");
|
||||
//log.debug("Another executor is still active");
|
||||
return;
|
||||
}
|
||||
mUpdater = Executors.newSingleThreadScheduledExecutor();
|
||||
|
|
|
@ -14,7 +14,6 @@ import android.widget.Toast;
|
|||
import androidx.annotation.DrawableRes;
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
|
@ -30,20 +29,20 @@ public class ToastUtils {
|
|||
}
|
||||
|
||||
public static void infoToast(final Context ctx, final String string) {
|
||||
graphicalToast(ctx, string, R.drawable.ic_toast_info,false);
|
||||
graphicalToast(ctx, string, R.drawable.ic_toast_info, false);
|
||||
}
|
||||
|
||||
public static void okToast(final Context ctx, final String string) {
|
||||
graphicalToast(ctx, string, R.drawable.ic_toast_check,false);
|
||||
graphicalToast(ctx, string, R.drawable.ic_toast_check, false);
|
||||
}
|
||||
|
||||
public static void errorToast(final Context ctx, final String string) {
|
||||
graphicalToast(ctx, string, R.drawable.ic_toast_error,false);
|
||||
graphicalToast(ctx, string, R.drawable.ic_toast_error, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void showToastInUiThread(final Context ctx, final int stringId) {
|
||||
showToastInUiThread(ctx, MainApp.gs(stringId));
|
||||
showToastInUiThread(ctx, ctx.getString(stringId));
|
||||
}
|
||||
|
||||
public static void warnToast(final Context ctx, final String string) {
|
||||
|
@ -70,7 +69,7 @@ public class ToastUtils {
|
|||
public static void graphicalToast(final Context ctx, final String string, @DrawableRes int iconId, boolean isShort) {
|
||||
Handler mainThread = new Handler(Looper.getMainLooper());
|
||||
mainThread.post(() -> {
|
||||
View toastRoot =LayoutInflater.from(new ContextThemeWrapper(ctx, R.style.AppTheme)).inflate(R.layout.toast, null);
|
||||
View toastRoot = LayoutInflater.from(new ContextThemeWrapper(ctx, R.style.AppTheme)).inflate(R.layout.toast, null);
|
||||
TextView toastMessage = toastRoot.findViewById(android.R.id.message);
|
||||
toastMessage.setText(string);
|
||||
|
||||
|
@ -86,9 +85,7 @@ public class ToastUtils {
|
|||
|
||||
public static void showToastInUiThread(final Context ctx, final String string) {
|
||||
Handler mainThread = new Handler(Looper.getMainLooper());
|
||||
mainThread.post(() -> {
|
||||
Toast.makeText(ctx, string, Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
mainThread.post(() -> Toast.makeText(ctx, string, Toast.LENGTH_SHORT).show());
|
||||
}
|
||||
|
||||
public static void showToastInUiThread(final Context ctx, final RxBusWrapper rxBus,
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
package info.nightscout.androidaps.utils;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
|
||||
/**
|
||||
* Created by mike on 15.07.2016.
|
||||
*/
|
||||
public class Translator {
|
||||
|
||||
public static String translate(String text) {
|
||||
switch (text) {
|
||||
|
||||
case "BG Check":
|
||||
return MainApp.gs(R.string.careportal_bgcheck);
|
||||
case "Snack Bolus":
|
||||
return MainApp.gs(R.string.careportal_snackbolus);
|
||||
case "Meal Bolus":
|
||||
return MainApp.gs(R.string.careportal_mealbolus);
|
||||
case "Correction Bolus":
|
||||
return MainApp.gs(R.string.careportal_correctionbolus);
|
||||
case "Carb Correction":
|
||||
return MainApp.gs(R.string.careportal_carbscorrection);
|
||||
case "Combo Bolus":
|
||||
return MainApp.gs(R.string.careportal_combobolus);
|
||||
case "Announcement":
|
||||
return MainApp.gs(R.string.careportal_announcement);
|
||||
case "Note":
|
||||
return MainApp.gs(R.string.careportal_note);
|
||||
case "Question":
|
||||
return MainApp.gs(R.string.careportal_question);
|
||||
case "Exercise":
|
||||
return MainApp.gs(R.string.careportal_exercise);
|
||||
case "Site Change":
|
||||
return MainApp.gs(R.string.careportal_pumpsitechange);
|
||||
case "Pump Battery Change":
|
||||
return MainApp.gs(R.string.careportal_pumpbatterychange);
|
||||
case "Sensor Start":
|
||||
return MainApp.gs(R.string.careportal_cgmsensorstart);
|
||||
case "Sensor Change":
|
||||
return MainApp.gs(R.string.careportal_cgmsensorinsert);
|
||||
case "Insulin Change":
|
||||
return MainApp.gs(R.string.careportal_insulincartridgechange);
|
||||
case "Temp Basal Start":
|
||||
return MainApp.gs(R.string.careportal_tempbasalstart);
|
||||
case "Temp Basal End":
|
||||
return MainApp.gs(R.string.careportal_tempbasalend);
|
||||
case "Profile Switch":
|
||||
return MainApp.gs(R.string.careportal_profileswitch);
|
||||
case "Temporary Target":
|
||||
return MainApp.gs(R.string.careportal_temporarytarget);
|
||||
case "Temporary Target Cancel":
|
||||
return MainApp.gs(R.string.careportal_temporarytargetcancel);
|
||||
case "OpenAPS Offline":
|
||||
return MainApp.gs(R.string.careportal_openapsoffline);
|
||||
case "Finger":
|
||||
return MainApp.gs(R.string.glucosetype_finger);
|
||||
case "Sensor":
|
||||
return MainApp.gs(R.string.glucosetype_sensor);
|
||||
case "Manual":
|
||||
return MainApp.gs(R.string.manual);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package info.nightscout.androidaps.utils
|
||||
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Created by mike on 15.07.2016.
|
||||
*/
|
||||
@Singleton
|
||||
class Translator @Inject internal constructor(
|
||||
private val resourceHelper: ResourceHelper
|
||||
) {
|
||||
|
||||
fun translate(text: String): String =
|
||||
when (text) {
|
||||
"BG Check" -> resourceHelper.gs(R.string.careportal_bgcheck)
|
||||
"Snack Bolus" -> resourceHelper.gs(R.string.careportal_snackbolus)
|
||||
"Meal Bolus" -> resourceHelper.gs(R.string.careportal_mealbolus)
|
||||
"Correction Bolus" -> resourceHelper.gs(R.string.careportal_correctionbolus)
|
||||
"Carb Correction" -> resourceHelper.gs(R.string.careportal_carbscorrection)
|
||||
"Combo Bolus" -> resourceHelper.gs(R.string.careportal_combobolus)
|
||||
"Announcement" -> resourceHelper.gs(R.string.careportal_announcement)
|
||||
"Note" -> resourceHelper.gs(R.string.careportal_note)
|
||||
"Question" -> resourceHelper.gs(R.string.careportal_question)
|
||||
"Exercise" -> resourceHelper.gs(R.string.careportal_exercise)
|
||||
"Site Change" -> resourceHelper.gs(R.string.careportal_pumpsitechange)
|
||||
"Pump Battery Change" -> resourceHelper.gs(R.string.careportal_pumpbatterychange)
|
||||
"Sensor Start" -> resourceHelper.gs(R.string.careportal_cgmsensorstart)
|
||||
"Sensor Change" -> resourceHelper.gs(R.string.careportal_cgmsensorinsert)
|
||||
"Insulin Change" -> resourceHelper.gs(R.string.careportal_insulincartridgechange)
|
||||
"Temp Basal Start" -> resourceHelper.gs(R.string.careportal_tempbasalstart)
|
||||
"Temp Basal End" -> resourceHelper.gs(R.string.careportal_tempbasalend)
|
||||
"Profile Switch" -> resourceHelper.gs(R.string.careportal_profileswitch)
|
||||
"Temporary Target" -> resourceHelper.gs(R.string.careportal_temporarytarget)
|
||||
"Temporary Target Cancel" -> resourceHelper.gs(R.string.careportal_temporarytargetcancel)
|
||||
"OpenAPS Offline" -> resourceHelper.gs(R.string.careportal_openapsoffline)
|
||||
"Finger" -> resourceHelper.gs(R.string.glucosetype_finger)
|
||||
"Sensor" -> resourceHelper.gs(R.string.glucosetype_sensor)
|
||||
"Manual" -> resourceHelper.gs(R.string.manual)
|
||||
else -> resourceHelper.gs(R.string.unknown)
|
||||
}
|
||||
}
|
|
@ -92,14 +92,14 @@ class TddCalculator @Inject constructor(
|
|||
"<b>" + resourceHelper.gs(R.string.tdd) + ":</b><br>" +
|
||||
toText(tdds) +
|
||||
"<b>" + resourceHelper.gs(R.string.average) + ":</b><br>" +
|
||||
averageTdd.toText(tdds.size())
|
||||
averageTdd.toText(resourceHelper, tdds.size())
|
||||
)
|
||||
}
|
||||
|
||||
private fun toText(tdds: LongSparseArray<TDD>): String {
|
||||
var t = ""
|
||||
for (i in 0 until tdds.size()) {
|
||||
t += "${tdds.valueAt(i).toText()}<br>"
|
||||
t += "${tdds.valueAt(i).toText(resourceHelper)}<br>"
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue