remove some static dependencies

This commit is contained in:
Milos Kozak 2020-04-27 23:55:06 +02:00
parent c0f6f1a5e9
commit a2ebcb5ff0
11 changed files with 78 additions and 118 deletions

View file

@ -217,16 +217,6 @@ public class MainApp extends DaggerApplication {
return sResources.getString(id, args); 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 @Deprecated
public static MainApp instance() { public static MainApp instance() {
return sInstance; return sInstance;

View file

@ -42,6 +42,7 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval {
@Inject ProfileFunction profileFunction; @Inject ProfileFunction profileFunction;
@Inject ResourceHelper resourceHelper; @Inject ResourceHelper resourceHelper;
@Inject AAPSLogger aapsLogger; @Inject AAPSLogger aapsLogger;
@Inject Translator translator;
@DatabaseField(id = true) @DatabaseField(id = true)
public long date; public long date;
@ -227,7 +228,7 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval {
} catch (JSONException e) { } catch (JSONException e) {
aapsLogger.error("Unhandled exception", e); aapsLogger.error("Unhandled exception", e);
} }
return Translator.translate(eventType); return translator.translate(eventType);
} }
public String getNotes() { public String getNotes() {

View file

@ -3,15 +3,12 @@ package info.nightscout.androidaps.db;
import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable; import com.j256.ormlite.table.DatabaseTable;
import org.slf4j.Logger; import java.util.Locale;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; 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.plugins.pump.common.utils.DateTimeUtil;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
/** /**
* Created by mike on 20.09.2017. * Created by mike on 20.09.2017.
@ -20,7 +17,6 @@ import info.nightscout.androidaps.utils.DateUtil;
@DatabaseTable(tableName = DatabaseHelper.DATABASE_TDDS) @DatabaseTable(tableName = DatabaseHelper.DATABASE_TDDS)
public class TDD { public class TDD {
private static Logger log = StacktraceLoggerWrapper.getLogger(L.DATABASE);
@DatabaseField(id = true) @DatabaseField(id = true)
public long date; public long date;
@ -40,7 +36,8 @@ public class TDD {
} }
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.date = date;
@ -61,11 +58,11 @@ public class TDD {
']'; ']';
} }
public String toText() { public String toText(ResourceHelper resourceHelper) {
return MainApp.gs(R.string.tddformat, DateUtil.dateStringShort(date), total, bolus, basal); return resourceHelper.gs(R.string.tddformat, DateUtil.dateStringShort(date), total, bolus, basal);
} }
public String toText(int days) { public String toText(ResourceHelper resourceHelper, int days) {
return MainApp.gs(R.string.tddformat, String.format("%d ", days) + MainApp.gs(R.string.days), total, bolus, basal); return resourceHelper.gs(R.string.tddformat, String.format(Locale.getDefault(), "%d ", days) + resourceHelper.gs(R.string.days), total, bolus, basal);
} }
} }

View file

@ -36,6 +36,7 @@ class CareDialog : DialogFragmentWithDate() {
@Inject lateinit var mainApp: MainApp @Inject lateinit var mainApp: MainApp
@Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var translator: Translator
enum class EventType { enum class EventType {
BGCHECK, BGCHECK,
@ -149,7 +150,7 @@ class CareDialog : DialogFragmentWithDate() {
actions_care_sensor.isChecked -> "Sensor" actions_care_sensor.isChecked -> "Sensor"
else -> "Manual" 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)) 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("glucose", actions_care_bg.value)
json.put("glucoseType", type) json.put("glucoseType", type)

View file

@ -78,6 +78,7 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O
@Inject ActivePluginProvider activePlugin; @Inject ActivePluginProvider activePlugin;
@Inject TreatmentsPlugin treatmentsPlugin; @Inject TreatmentsPlugin treatmentsPlugin;
@Inject HardLimits hardLimits; @Inject HardLimits hardLimits;
@Inject Translator translator;
private static OptionsToShow options; private static OptionsToShow options;
private static @StringRes int event; private static @StringRes int event;
@ -623,7 +624,7 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O
if (data.has("glucoseType")) { if (data.has("glucoseType")) {
ret += resourceHelper.gs(R.string.careportal_newnstreatment_glucosetype); ret += resourceHelper.gs(R.string.careportal_newnstreatment_glucosetype);
ret += ": "; ret += ": ";
ret += Translator.translate(JsonHelper.safeGetString(data, "glucoseType", "")); ret += translator.translate(JsonHelper.safeGetString(data, "glucoseType", ""));
ret += "\n"; ret += "\n";
} }
if (data.has("carbs")) { if (data.has("carbs")) {
@ -712,7 +713,7 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O
private void confirmNSTreatmentCreation() { private void confirmNSTreatmentCreation() {
final JSONObject data = gatherData(); 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()));
} }

View file

@ -37,6 +37,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
@Inject lateinit var sp: SP @Inject lateinit var sp: SP
@Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var translator: Translator
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? { savedInstanceState: Bundle?): View? {
@ -108,7 +109,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
holder.date.text = DateUtil.dateAndTimeString(careportalEvent.date) holder.date.text = DateUtil.dateAndTimeString(careportalEvent.date)
holder.duration.text = if (careportalEvent.durationInMsec() == 0L) "" else DateUtil.niceTimeScalar(careportalEvent.durationInMsec(), resourceHelper) holder.duration.text = if (careportalEvent.durationInMsec() == 0L) "" else DateUtil.niceTimeScalar(careportalEvent.durationInMsec(), resourceHelper)
holder.note.text = careportalEvent.notes holder.note.text = careportalEvent.notes
holder.type.text = Translator.translate(careportalEvent.eventType) holder.type.text = translator.translate(careportalEvent.eventType)
holder.remove.tag = careportalEvent holder.remove.tag = careportalEvent
} }
@ -129,7 +130,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
remove.setOnClickListener { v: View -> remove.setOnClickListener { v: View ->
val careportalEvent = v.tag as CareportalEvent val careportalEvent = v.tag as CareportalEvent
activity?.let { activity -> 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.careportal_newnstreatment_notes_label) + ": " + careportalEvent.notes + "\n" +
resourceHelper.gs(R.string.date) + ": " + DateUtil.dateAndTimeString(careportalEvent.date) resourceHelper.gs(R.string.date) + ": " + DateUtil.dateAndTimeString(careportalEvent.date)
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable {

View file

@ -5,7 +5,6 @@ import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.text.method.DigitsKeyListener;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -15,24 +14,18 @@ import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
/** /**
* Created by mike on 28.06.2016. * Created by mike on 28.06.2016.
*/ */
public class NumberPicker extends LinearLayout implements View.OnKeyListener, public class NumberPicker extends LinearLayout implements View.OnKeyListener,
View.OnTouchListener, View.OnClickListener { View.OnTouchListener, View.OnClickListener {
private static Logger log = StacktraceLoggerWrapper.getLogger(NumberPicker.class);
public interface OnValueChangedListener { public interface OnValueChangedListener {
void onValueChanged(double value); void onValueChanged(double value);
@ -172,14 +165,14 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
value = SafeParse.stringToDouble(editText.getText().toString()); value = SafeParse.stringToDouble(editText.getText().toString());
if (value > maxValue) { if (value > maxValue) {
value = maxValue; value = maxValue;
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.youareonallowedlimit)); ToastUtils.showToastInUiThread(getContext(), getContext().getString(R.string.youareonallowedlimit));
updateEditText(); updateEditText();
if (okButton != null) if (okButton != null)
okButton.setVisibility(VISIBLE); okButton.setVisibility(VISIBLE);
} }
if (value < minValue) { if (value < minValue) {
value = minValue; value = minValue;
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.youareonallowedlimit)); ToastUtils.showToastInUiThread(getContext(), getContext().getString(R.string.youareonallowedlimit));
updateEditText(); updateEditText();
if (okButton != null) if (okButton != null)
okButton.setVisibility(VISIBLE); okButton.setVisibility(VISIBLE);
@ -244,7 +237,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
if (value > maxValue) { if (value > maxValue) {
value = maxValue; value = maxValue;
callValueChangedListener(); callValueChangedListener();
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.youareonallowedlimit)); ToastUtils.showToastInUiThread(getContext(), getContext().getString(R.string.youareonallowedlimit));
stopUpdating(); stopUpdating();
} }
updateEditText(); updateEditText();
@ -255,7 +248,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
if (value < minValue) { if (value < minValue) {
value = minValue; value = minValue;
callValueChangedListener(); callValueChangedListener();
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.youareonallowedlimit)); ToastUtils.showToastInUiThread(getContext(), getContext().getString(R.string.youareonallowedlimit));
stopUpdating(); stopUpdating();
} }
updateEditText(); updateEditText();
@ -275,7 +268,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
private void startUpdating(boolean inc) { private void startUpdating(boolean inc) {
if (mUpdater != null) { if (mUpdater != null) {
log.debug("Another executor is still active"); //log.debug("Another executor is still active");
return; return;
} }
mUpdater = Executors.newSingleThreadScheduledExecutor(); mUpdater = Executors.newSingleThreadScheduledExecutor();

View file

@ -14,7 +14,6 @@ import android.widget.Toast;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import androidx.appcompat.view.ContextThemeWrapper; import androidx.appcompat.view.ContextThemeWrapper;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
@ -43,7 +42,7 @@ public class ToastUtils {
} }
public static void showToastInUiThread(final Context ctx, final int stringId) { 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) { public static void warnToast(final Context ctx, final String string) {
@ -86,9 +85,7 @@ public class ToastUtils {
public static void showToastInUiThread(final Context ctx, final String string) { public static void showToastInUiThread(final Context ctx, final String string) {
Handler mainThread = new Handler(Looper.getMainLooper()); Handler mainThread = new Handler(Looper.getMainLooper());
mainThread.post(() -> { mainThread.post(() -> Toast.makeText(ctx, string, Toast.LENGTH_SHORT).show());
Toast.makeText(ctx, string, Toast.LENGTH_SHORT).show();
});
} }
public static void showToastInUiThread(final Context ctx, final RxBusWrapper rxBus, public static void showToastInUiThread(final Context ctx, final RxBusWrapper rxBus,

View file

@ -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;
}
}

View file

@ -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)
}
}

View file

@ -92,14 +92,14 @@ class TddCalculator @Inject constructor(
"<b>" + resourceHelper.gs(R.string.tdd) + ":</b><br>" + "<b>" + resourceHelper.gs(R.string.tdd) + ":</b><br>" +
toText(tdds) + toText(tdds) +
"<b>" + resourceHelper.gs(R.string.average) + ":</b><br>" + "<b>" + resourceHelper.gs(R.string.average) + ":</b><br>" +
averageTdd.toText(tdds.size()) averageTdd.toText(resourceHelper, tdds.size())
) )
} }
private fun toText(tdds: LongSparseArray<TDD>): String { private fun toText(tdds: LongSparseArray<TDD>): String {
var t = "" var t = ""
for (i in 0 until tdds.size()) { for (i in 0 until tdds.size()) {
t += "${tdds.valueAt(i).toText()}<br>" t += "${tdds.valueAt(i).toText(resourceHelper)}<br>"
} }
return t return t
} }