Skip to content

Commit 8485b00

Browse files
authored
Merge pull request #184 from pachi81/1.3
v1.3
2 parents f546973 + e74aa76 commit 8485b00

File tree

169 files changed

+6861
-1530
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+6861
-1530
lines changed

auto/build.gradle

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ android {
1313
applicationId "de.michelinside.glucodataauto"
1414
minSdk rootProject.minSdk
1515
targetSdk rootProject.targetSdk
16-
versionCode 1028
17-
versionName "1.2"
16+
versionCode 1029
17+
versionName "1.3"
1818

1919
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2020
}
@@ -37,6 +37,14 @@ android {
3737
minifyEnabled false
3838
resValue "string", "app_name", "GlucoDataAuto Debug"
3939
}
40+
second {
41+
applicationIdSuffix '.second'
42+
versionNameSuffix '_SECOND'
43+
minifyEnabled true
44+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
45+
resValue "string", "app_name", "GDA Second"
46+
signingConfig signingConfigs.debug
47+
}
4048
applicationVariants.all {
4149
// this method is use to rename your all apk weather
4250
// it may be signed or unsigned(debug apk)
@@ -75,7 +83,7 @@ dependencies {
7583
implementation 'androidx.core:core-ktx:1.13.1'
7684
implementation 'androidx.appcompat:appcompat:1.7.0'
7785
implementation 'com.google.android.material:material:1.12.0'
78-
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
86+
implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
7987
implementation 'com.joaomgcd:taskerpluginlibrary:0.4.10'
8088
implementation project(path: ':common')
8189
implementation "androidx.car.app:app:1.4.0"
@@ -105,4 +113,14 @@ afterEvaluate {
105113
into rootProject.releasePath
106114
}
107115
assembleDevRelease.finalizedBy(copyAndroidDevApksPostBuild)
108-
}
116+
117+
//noinspection ConfigurationAvoidance
118+
def assembleSecond = tasks.getByPath(':auto:assembleSecond')
119+
def copyAndroidSecondApksPostBuild = tasks.register('copyAndroidSecondApksPostBuild', Copy) {
120+
dependsOn assembleSecond
121+
from "${projectDir}/second"
122+
include '**/*.apk'
123+
into rootProject.releasePath
124+
}
125+
assembleSecond.finalizedBy(copyAndroidSecondApksPostBuild)
126+
}
59.1 KB
Loading
59.1 KB
Loading

auto/src/main/java/de/michelinside/glucodataauto/GlucoDataServiceAuto.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class GlucoDataServiceAuto: Service(), SharedPreferences.OnSharedPreferenceChang
5454
private var dexcomReceiver: DexcomBroadcastReceiver? = null
5555
private var nsEmulatorReceiver: NsEmulatorReceiver? = null
5656
private var diaboxReceiver: DiaboxReceiver? = null
57+
private var patient_name: String? = null
58+
val patientName: String? get() = patient_name
5759

5860
val connected: Boolean get() = car_connected || CarMediaBrowserService.active
5961

@@ -72,12 +74,18 @@ class GlucoDataServiceAuto: Service(), SharedPreferences.OnSharedPreferenceChang
7274
Log.v(LOG_ID, "migrateSettings called")
7375
GlucoDataService.migrateSettings(context)
7476
val sharedPref = context.getSharedPreferences(Constants.SHARED_PREF_TAG, Context.MODE_PRIVATE)
75-
if(sharedPref.getBoolean(Constants.SHARED_PREF_NIGHTSCOUT_IOB_COB, true)) {
77+
if(!sharedPref.contains(Constants.SHARED_PREF_NIGHTSCOUT_IOB_COB)) {
7678
with(sharedPref.edit()) {
7779
putBoolean(Constants.SHARED_PREF_NIGHTSCOUT_IOB_COB, false)
7880
apply()
7981
}
8082
}
83+
if(Constants.IS_SECOND && !sharedPref.contains(Constants.PATIENT_NAME)) {
84+
with(sharedPref.edit()) {
85+
putString(Constants.PATIENT_NAME, "SECOND")
86+
apply()
87+
}
88+
}
8189
}
8290

8391
private fun startService(context: Context, foreground: Boolean) {
@@ -201,8 +209,9 @@ class GlucoDataServiceAuto: Service(), SharedPreferences.OnSharedPreferenceChang
201209

202210
private fun sendStateBroadcast(context: Context, enabled: Boolean) {
203211
try {
204-
Log.d(LOG_ID, "Sending state broadcast for state: " + enabled)
212+
Log.i(LOG_ID, "Sending state broadcast for state: $enabled - to ${Constants.PACKAGE_GLUCODATAHANDLER}")
205213
val intent = Intent(Constants.GLUCODATAAUTO_STATE_ACTION)
214+
intent.setPackage(Constants.PACKAGE_GLUCODATAHANDLER)
206215
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
207216
intent.putExtra(Constants.GLUCODATAAUTO_STATE_EXTRA, enabled)
208217
context.sendBroadcast(intent)
@@ -346,6 +355,7 @@ class GlucoDataServiceAuto: Service(), SharedPreferences.OnSharedPreferenceChang
346355
TextToSpeechUtils.initTextToSpeech(this)
347356
val sharedPref = getSharedPreferences(Constants.SHARED_PREF_TAG, Context.MODE_PRIVATE)
348357
sharedPref.registerOnSharedPreferenceChangeListener(this)
358+
patient_name = sharedPref.getString(Constants.PATIENT_NAME, "")
349359
val isForeground = (if(intent != null) intent.getBooleanExtra(Constants.SHARED_PREF_FOREGROUND_SERVICE, false) else false) || sharedPref.getBoolean(Constants.SHARED_PREF_FOREGROUND_SERVICE, false)
350360
if (isForeground && !isForegroundService) {
351361
Log.i(LOG_ID, "Starting service in foreground!")
@@ -399,7 +409,7 @@ class GlucoDataServiceAuto: Service(), SharedPreferences.OnSharedPreferenceChang
399409
.build()
400410
}
401411

402-
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
412+
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) {
403413
try {
404414
Log.d(LOG_ID, "onSharedPreferenceChanged called with key $key")
405415
when(key) {
@@ -412,6 +422,9 @@ class GlucoDataServiceAuto: Service(), SharedPreferences.OnSharedPreferenceChang
412422
if(dataSyncCount>0)
413423
updateSourceReceiver(this, key)
414424
}
425+
Constants.PATIENT_NAME -> {
426+
patient_name = sharedPreferences.getString(Constants.PATIENT_NAME, "")
427+
}
415428
}
416429
} catch (exc: Exception) {
417430
Log.e(LOG_ID, "onSharedPreferenceChanged exception: " + exc.toString())

auto/src/main/java/de/michelinside/glucodataauto/MainActivity.kt

Lines changed: 102 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package de.michelinside.glucodataauto
22

3+
import android.annotation.SuppressLint
34
import android.app.Activity
4-
import android.app.AlarmManager
55
import android.content.Context
66
import android.content.Intent
77
import android.content.SharedPreferences
@@ -46,15 +46,15 @@ import de.michelinside.glucodatahandler.common.utils.GitHubVersionChecker
4646
import de.michelinside.glucodatahandler.common.utils.Utils
4747
import de.michelinside.glucodatahandler.common.ui.Dialogs
4848
import de.michelinside.glucodatahandler.common.utils.TextToSpeechUtils
49-
import java.text.DateFormat
50-
import java.util.Date
5149
import de.michelinside.glucodatahandler.common.R as CR
5250

5351
class MainActivity : AppCompatActivity(), NotifierInterface {
5452
private lateinit var txtBgValue: TextView
5553
private lateinit var viewIcon: ImageView
5654
private lateinit var timeText: TextView
5755
private lateinit var deltaText: TextView
56+
private lateinit var iobText: TextView
57+
private lateinit var cobText: TextView
5858
private lateinit var txtLastValue: TextView
5959
private lateinit var txtVersion: TextView
6060
private lateinit var tableDetails: TableLayout
@@ -79,6 +79,8 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
7979
viewIcon = findViewById(R.id.viewIcon)
8080
timeText = findViewById(R.id.timeText)
8181
deltaText = findViewById(R.id.deltaText)
82+
iobText = findViewById(R.id.iobText)
83+
cobText = findViewById(R.id.cobText)
8284
txtLastValue = findViewById(R.id.txtLastValue)
8385
btnSources = findViewById(R.id.btnSources)
8486
tableConnections = findViewById(R.id.tableConnections)
@@ -165,6 +167,7 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
165167

166168
GlucoDataServiceAuto.startDataSync()
167169
versionChecker.checkVersion(1)
170+
checkNewSettings()
168171
} catch (exc: Exception) {
169172
Log.e(LOG_ID, "onResume exception: " + exc.message.toString() )
170173
}
@@ -178,27 +181,12 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
178181
return false
179182
}
180183
}
181-
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
182-
val alarmManager = this.getSystemService(Context.ALARM_SERVICE) as AlarmManager
183-
if (!alarmManager.canScheduleExactAlarms()) {
184-
Log.i(LOG_ID, "Request exact alarm permission...")
185-
startActivity(Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM))
186-
}
187-
}
188184
requestExactAlarmPermission()
189185
return true
190186
}
191187

192-
private fun canScheduleExactAlarms(): Boolean {
193-
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
194-
val alarmManager = this.getSystemService(Context.ALARM_SERVICE) as AlarmManager
195-
return alarmManager.canScheduleExactAlarms()
196-
}
197-
return true
198-
}
199-
200188
private fun requestExactAlarmPermission() {
201-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !canScheduleExactAlarms()) {
189+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !Utils.canScheduleExactAlarms(this)) {
202190
Log.i(LOG_ID, "Request exact alarm permission...")
203191
val builder: AlertDialog.Builder = AlertDialog.Builder(this)
204192
builder
@@ -215,6 +203,49 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
215203
}
216204
}
217205

206+
private fun checkNewSettings() {
207+
try {
208+
if(!sharedPref.contains(Constants.SHARED_PREF_DISCLAIMER_SHOWN)) {
209+
Dialogs.showOkDialog(this,
210+
CR.string.gdh_disclaimer_title,
211+
CR.string.gdh_disclaimer_message,
212+
null
213+
)
214+
with(sharedPref.edit()) {
215+
putString(Constants.SHARED_PREF_DISCLAIMER_SHOWN, BuildConfig.VERSION_NAME)
216+
apply()
217+
}
218+
}
219+
if(!sharedPref.contains(Constants.SHARED_PREF_LIBRE_AUTO_ACCEPT_TOU)) {
220+
if(sharedPref.getBoolean(Constants.SHARED_PREF_LIBRE_ENABLED, false)) {
221+
Dialogs.showOkCancelDialog(this,
222+
resources.getString(CR.string.src_cat_libreview),
223+
resources.getString(CR.string.src_libre_tou_message),
224+
{ _, _ ->
225+
with(sharedPref.edit()) {
226+
putBoolean(Constants.SHARED_PREF_LIBRE_AUTO_ACCEPT_TOU, true)
227+
apply()
228+
}
229+
},
230+
{ _, _ ->
231+
with(sharedPref.edit()) {
232+
putBoolean(Constants.SHARED_PREF_LIBRE_AUTO_ACCEPT_TOU, false)
233+
apply()
234+
}
235+
})
236+
} else {
237+
with(sharedPref.edit()) {
238+
putBoolean(Constants.SHARED_PREF_LIBRE_AUTO_ACCEPT_TOU, true)
239+
apply()
240+
}
241+
}
242+
}
243+
244+
} catch (exc: Exception) {
245+
Log.e(LOG_ID, "checkNewSettings exception: " + exc.message.toString() )
246+
}
247+
}
248+
218249
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
219250
try {
220251
Log.v(LOG_ID, "onCreateOptionsMenu called")
@@ -311,6 +342,14 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
311342
startActivity(mailIntent)
312343
return true
313344
}
345+
R.id.action_google_groups -> {
346+
val browserIntent = Intent(
347+
Intent.ACTION_VIEW,
348+
Uri.parse(resources.getText(CR.string.google_gdh_group_url).toString())
349+
)
350+
startActivity(browserIntent)
351+
return true
352+
}
314353
R.id.action_facebook -> {
315354
val browserIntent = Intent(
316355
Intent.ACTION_VIEW,
@@ -355,6 +394,7 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
355394
return super.onOptionsItemSelected(item)
356395
}
357396

397+
@SuppressLint("SetTextI18n")
358398
private fun update() {
359399
try {
360400
Log.v(LOG_ID, "update values")
@@ -370,6 +410,12 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
370410
timeText.text = "🕒 ${ReceiveData.getElapsedRelativeTimeAsString(this)}"
371411
timeText.contentDescription = ReceiveData.getElapsedRelativeTimeAsString(this, true)
372412
deltaText.text = "Δ ${ReceiveData.getDeltaAsString()}"
413+
iobText.text = "💉 " + ReceiveData.getIobAsString()
414+
iobText.contentDescription = getString(CR.string.info_label_iob) + " " + ReceiveData.getIobAsString()
415+
iobText.visibility = if (ReceiveData.isIobCobObsolete()) View.GONE else View.VISIBLE
416+
cobText.text = "🍔 " + ReceiveData.getCobAsString()
417+
cobText.contentDescription = getString(CR.string.info_label_cob) + " " + ReceiveData.getCobAsString()
418+
cobText.visibility = iobText.visibility
373419

374420
if(ReceiveData.time == 0L) {
375421
txtLastValue.visibility = View.VISIBLE
@@ -394,17 +440,41 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
394440

395441
private fun updateConnectionsTable() {
396442
tableConnections.removeViews(1, maxOf(0, tableConnections.childCount - 1))
397-
if (SourceStateData.lastState != SourceState.NONE)
398-
tableConnections.addView(createRow(
399-
SourceStateData.lastSource.resId,
400-
SourceStateData.getStateMessage(this)))
443+
if (SourceStateData.lastState != SourceState.NONE) {
444+
val msg = SourceStateData.getStateMessage(this)
445+
tableConnections.addView(createRow(SourceStateData.lastSource.resId,msg))
446+
if(SourceStateData.lastState == SourceState.ERROR && SourceStateData.lastSource == DataSource.DEXCOM_SHARE) {
447+
if (msg.contains("500:")) { // invalid password
448+
val us_account = sharedPref.getBoolean(Constants.SHARED_PREF_DEXCOM_SHARE_USE_US_URL, false)
449+
val browserIntent = Intent(
450+
Intent.ACTION_VIEW,
451+
Uri.parse(resources.getString(if(us_account)CR.string.dexcom_account_us_url else CR.string.dexcom_account_non_us_url))
452+
)
453+
val onClickListener = View.OnClickListener {
454+
startActivity(browserIntent)
455+
}
456+
tableConnections.addView(
457+
createRow(
458+
SourceStateData.lastSource.resId,
459+
resources.getString(if(us_account) CR.string.dexcom_share_check_us_account else CR.string.dexcom_share_check_non_us_account),
460+
onClickListener
461+
)
462+
)
463+
}
464+
}
465+
if(SourceStateData.lastErrorInfo.isNotEmpty()) {
466+
// add error specific information in an own row
467+
tableConnections.addView(createRow(SourceStateData.lastErrorInfo))
468+
}
469+
tableConnections.addView(createRow(CR.string.request_timestamp, Utils.getUiTimeStamp(SourceStateData.lastStateTime)))
470+
}
401471
tableConnections.addView(createRow(CR.string.pref_cat_android_auto, if (GlucoDataServiceAuto.connected) resources.getString(CR.string.connected_label) else resources.getString(CR.string.disconnected_label)))
402472
checkTableVisibility(tableConnections)
403473
}
404474

405475
private fun updateNotesTable() {
406476
tableNotes.removeViews(1, maxOf(0, tableNotes.childCount - 1))
407-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !canScheduleExactAlarms()) {
477+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !Utils.canScheduleExactAlarms(this)) {
408478
Log.w(LOG_ID, "Schedule exact alarm is not active!!!")
409479
val onClickListener = View.OnClickListener {
410480
startActivity(Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM))
@@ -469,16 +539,20 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
469539
tableAlarms.addView(createRow(CR.string.info_label_alarm, resources.getString(deltaAlarmType.resId)))
470540
}
471541
if (AlarmHandler.isSnoozeActive)
472-
tableAlarms.addView(createRow(CR.string.snooze, AlarmHandler.snoozeTimestamp))
542+
tableAlarms.addView(createRow(CR.string.snooze_until, AlarmHandler.snoozeTimestamp))
473543
checkTableVisibility(tableAlarms)
474544
}
475545

476546
private fun updateDetailsTable() {
477547
tableDetails.removeViews(1, maxOf(0, tableDetails.childCount - 1))
548+
if(!GlucoDataServiceAuto.patientName.isNullOrEmpty()) {
549+
tableDetails.addView(createRow(CR.string.patient_name, GlucoDataServiceAuto.patientName!!))
550+
}
551+
478552
if(ReceiveData.time > 0) {
479553
if (ReceiveData.isMmol)
480554
tableDetails.addView(createRow(CR.string.info_label_raw, "${ReceiveData.rawValue} mg/dl"))
481-
tableDetails.addView(createRow(CR.string.info_label_timestamp, DateFormat.getTimeInstance(DateFormat.DEFAULT).format(Date(ReceiveData.time))))
555+
tableDetails.addView(createRow(CR.string.info_label_timestamp, Utils.getUiTimeStamp(ReceiveData.time)))
482556
if (ReceiveData.sensorID?.isNotEmpty() == true) {
483557
tableDetails.addView(createRow(CR.string.info_label_sensor_id, if(BuildConfig.DEBUG) "ABCDE12345" else ReceiveData.sensorID!!))
484558
}
@@ -520,12 +594,12 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
520594
return row
521595
}
522596

523-
private fun createRow(key: String, onClickListener: View.OnClickListener? = null) : TableRow {
597+
private fun createRow(value: String, onClickListener: View.OnClickListener? = null) : TableRow {
524598
val row = TableRow(this)
525599
row.weightSum = 1f
526600
//row.setBackgroundColor(resources.getColor(R.color.table_row))
527601
row.setPadding(Utils.dpToPx(5F, this))
528-
row.addView(createColumn(key, false, onClickListener))
602+
row.addView(createColumn(value, false, onClickListener))
529603
return row
530604
}
531605

0 commit comments

Comments
 (0)