Skip to content

Commit

Permalink
Merge pull request #184 from pachi81/1.3
Browse files Browse the repository at this point in the history
v1.3
  • Loading branch information
pachi81 authored Jan 22, 2025
2 parents f546973 + e74aa76 commit 8485b00
Show file tree
Hide file tree
Showing 169 changed files with 6,861 additions and 1,530 deletions.
26 changes: 22 additions & 4 deletions auto/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "de.michelinside.glucodataauto"
minSdk rootProject.minSdk
targetSdk rootProject.targetSdk
versionCode 1028
versionName "1.2"
versionCode 1029
versionName "1.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -37,6 +37,14 @@ android {
minifyEnabled false
resValue "string", "app_name", "GlucoDataAuto Debug"
}
second {
applicationIdSuffix '.second'
versionNameSuffix '_SECOND'
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
resValue "string", "app_name", "GDA Second"
signingConfig signingConfigs.debug
}
applicationVariants.all {
// this method is use to rename your all apk weather
// it may be signed or unsigned(debug apk)
Expand Down Expand Up @@ -75,7 +83,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
implementation 'com.joaomgcd:taskerpluginlibrary:0.4.10'
implementation project(path: ':common')
implementation "androidx.car.app:app:1.4.0"
Expand Down Expand Up @@ -105,4 +113,14 @@ afterEvaluate {
into rootProject.releasePath
}
assembleDevRelease.finalizedBy(copyAndroidDevApksPostBuild)
}

//noinspection ConfigurationAvoidance
def assembleSecond = tasks.getByPath(':auto:assembleSecond')
def copyAndroidSecondApksPostBuild = tasks.register('copyAndroidSecondApksPostBuild', Copy) {
dependsOn assembleSecond
from "${projectDir}/second"
include '**/*.apk'
into rootProject.releasePath
}
assembleSecond.finalizedBy(copyAndroidSecondApksPostBuild)
}
Binary file added auto/src/main/ic_launcher-second-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added auto/src/main/ic_launcher-second.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class GlucoDataServiceAuto: Service(), SharedPreferences.OnSharedPreferenceChang
private var dexcomReceiver: DexcomBroadcastReceiver? = null
private var nsEmulatorReceiver: NsEmulatorReceiver? = null
private var diaboxReceiver: DiaboxReceiver? = null
private var patient_name: String? = null
val patientName: String? get() = patient_name

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

Expand All @@ -72,12 +74,18 @@ class GlucoDataServiceAuto: Service(), SharedPreferences.OnSharedPreferenceChang
Log.v(LOG_ID, "migrateSettings called")
GlucoDataService.migrateSettings(context)
val sharedPref = context.getSharedPreferences(Constants.SHARED_PREF_TAG, Context.MODE_PRIVATE)
if(sharedPref.getBoolean(Constants.SHARED_PREF_NIGHTSCOUT_IOB_COB, true)) {
if(!sharedPref.contains(Constants.SHARED_PREF_NIGHTSCOUT_IOB_COB)) {
with(sharedPref.edit()) {
putBoolean(Constants.SHARED_PREF_NIGHTSCOUT_IOB_COB, false)
apply()
}
}
if(Constants.IS_SECOND && !sharedPref.contains(Constants.PATIENT_NAME)) {
with(sharedPref.edit()) {
putString(Constants.PATIENT_NAME, "SECOND")
apply()
}
}
}

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

private fun sendStateBroadcast(context: Context, enabled: Boolean) {
try {
Log.d(LOG_ID, "Sending state broadcast for state: " + enabled)
Log.i(LOG_ID, "Sending state broadcast for state: $enabled - to ${Constants.PACKAGE_GLUCODATAHANDLER}")
val intent = Intent(Constants.GLUCODATAAUTO_STATE_ACTION)
intent.setPackage(Constants.PACKAGE_GLUCODATAHANDLER)
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
intent.putExtra(Constants.GLUCODATAAUTO_STATE_EXTRA, enabled)
context.sendBroadcast(intent)
Expand Down Expand Up @@ -346,6 +355,7 @@ class GlucoDataServiceAuto: Service(), SharedPreferences.OnSharedPreferenceChang
TextToSpeechUtils.initTextToSpeech(this)
val sharedPref = getSharedPreferences(Constants.SHARED_PREF_TAG, Context.MODE_PRIVATE)
sharedPref.registerOnSharedPreferenceChangeListener(this)
patient_name = sharedPref.getString(Constants.PATIENT_NAME, "")
val isForeground = (if(intent != null) intent.getBooleanExtra(Constants.SHARED_PREF_FOREGROUND_SERVICE, false) else false) || sharedPref.getBoolean(Constants.SHARED_PREF_FOREGROUND_SERVICE, false)
if (isForeground && !isForegroundService) {
Log.i(LOG_ID, "Starting service in foreground!")
Expand Down Expand Up @@ -399,7 +409,7 @@ class GlucoDataServiceAuto: Service(), SharedPreferences.OnSharedPreferenceChang
.build()
}

override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) {
try {
Log.d(LOG_ID, "onSharedPreferenceChanged called with key $key")
when(key) {
Expand All @@ -412,6 +422,9 @@ class GlucoDataServiceAuto: Service(), SharedPreferences.OnSharedPreferenceChang
if(dataSyncCount>0)
updateSourceReceiver(this, key)
}
Constants.PATIENT_NAME -> {
patient_name = sharedPreferences.getString(Constants.PATIENT_NAME, "")
}
}
} catch (exc: Exception) {
Log.e(LOG_ID, "onSharedPreferenceChanged exception: " + exc.toString())
Expand Down
130 changes: 102 additions & 28 deletions auto/src/main/java/de/michelinside/glucodataauto/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.michelinside.glucodataauto

import android.annotation.SuppressLint
import android.app.Activity
import android.app.AlarmManager
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
Expand Down Expand Up @@ -46,15 +46,15 @@ import de.michelinside.glucodatahandler.common.utils.GitHubVersionChecker
import de.michelinside.glucodatahandler.common.utils.Utils
import de.michelinside.glucodatahandler.common.ui.Dialogs
import de.michelinside.glucodatahandler.common.utils.TextToSpeechUtils
import java.text.DateFormat
import java.util.Date
import de.michelinside.glucodatahandler.common.R as CR

class MainActivity : AppCompatActivity(), NotifierInterface {
private lateinit var txtBgValue: TextView
private lateinit var viewIcon: ImageView
private lateinit var timeText: TextView
private lateinit var deltaText: TextView
private lateinit var iobText: TextView
private lateinit var cobText: TextView
private lateinit var txtLastValue: TextView
private lateinit var txtVersion: TextView
private lateinit var tableDetails: TableLayout
Expand All @@ -79,6 +79,8 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
viewIcon = findViewById(R.id.viewIcon)
timeText = findViewById(R.id.timeText)
deltaText = findViewById(R.id.deltaText)
iobText = findViewById(R.id.iobText)
cobText = findViewById(R.id.cobText)
txtLastValue = findViewById(R.id.txtLastValue)
btnSources = findViewById(R.id.btnSources)
tableConnections = findViewById(R.id.tableConnections)
Expand Down Expand Up @@ -165,6 +167,7 @@ class MainActivity : AppCompatActivity(), NotifierInterface {

GlucoDataServiceAuto.startDataSync()
versionChecker.checkVersion(1)
checkNewSettings()
} catch (exc: Exception) {
Log.e(LOG_ID, "onResume exception: " + exc.message.toString() )
}
Expand All @@ -178,27 +181,12 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
return false
}
}
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val alarmManager = this.getSystemService(Context.ALARM_SERVICE) as AlarmManager
if (!alarmManager.canScheduleExactAlarms()) {
Log.i(LOG_ID, "Request exact alarm permission...")
startActivity(Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM))
}
}
requestExactAlarmPermission()
return true
}

private fun canScheduleExactAlarms(): Boolean {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val alarmManager = this.getSystemService(Context.ALARM_SERVICE) as AlarmManager
return alarmManager.canScheduleExactAlarms()
}
return true
}

private fun requestExactAlarmPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !canScheduleExactAlarms()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !Utils.canScheduleExactAlarms(this)) {
Log.i(LOG_ID, "Request exact alarm permission...")
val builder: AlertDialog.Builder = AlertDialog.Builder(this)
builder
Expand All @@ -215,6 +203,49 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
}
}

private fun checkNewSettings() {
try {
if(!sharedPref.contains(Constants.SHARED_PREF_DISCLAIMER_SHOWN)) {
Dialogs.showOkDialog(this,
CR.string.gdh_disclaimer_title,
CR.string.gdh_disclaimer_message,
null
)
with(sharedPref.edit()) {
putString(Constants.SHARED_PREF_DISCLAIMER_SHOWN, BuildConfig.VERSION_NAME)
apply()
}
}
if(!sharedPref.contains(Constants.SHARED_PREF_LIBRE_AUTO_ACCEPT_TOU)) {
if(sharedPref.getBoolean(Constants.SHARED_PREF_LIBRE_ENABLED, false)) {
Dialogs.showOkCancelDialog(this,
resources.getString(CR.string.src_cat_libreview),
resources.getString(CR.string.src_libre_tou_message),
{ _, _ ->
with(sharedPref.edit()) {
putBoolean(Constants.SHARED_PREF_LIBRE_AUTO_ACCEPT_TOU, true)
apply()
}
},
{ _, _ ->
with(sharedPref.edit()) {
putBoolean(Constants.SHARED_PREF_LIBRE_AUTO_ACCEPT_TOU, false)
apply()
}
})
} else {
with(sharedPref.edit()) {
putBoolean(Constants.SHARED_PREF_LIBRE_AUTO_ACCEPT_TOU, true)
apply()
}
}
}

} catch (exc: Exception) {
Log.e(LOG_ID, "checkNewSettings exception: " + exc.message.toString() )
}
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
try {
Log.v(LOG_ID, "onCreateOptionsMenu called")
Expand Down Expand Up @@ -311,6 +342,14 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
startActivity(mailIntent)
return true
}
R.id.action_google_groups -> {
val browserIntent = Intent(
Intent.ACTION_VIEW,
Uri.parse(resources.getText(CR.string.google_gdh_group_url).toString())
)
startActivity(browserIntent)
return true
}
R.id.action_facebook -> {
val browserIntent = Intent(
Intent.ACTION_VIEW,
Expand Down Expand Up @@ -355,6 +394,7 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
return super.onOptionsItemSelected(item)
}

@SuppressLint("SetTextI18n")
private fun update() {
try {
Log.v(LOG_ID, "update values")
Expand All @@ -370,6 +410,12 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
timeText.text = "🕒 ${ReceiveData.getElapsedRelativeTimeAsString(this)}"
timeText.contentDescription = ReceiveData.getElapsedRelativeTimeAsString(this, true)
deltaText.text = "Δ ${ReceiveData.getDeltaAsString()}"
iobText.text = "💉 " + ReceiveData.getIobAsString()
iobText.contentDescription = getString(CR.string.info_label_iob) + " " + ReceiveData.getIobAsString()
iobText.visibility = if (ReceiveData.isIobCobObsolete()) View.GONE else View.VISIBLE
cobText.text = "🍔 " + ReceiveData.getCobAsString()
cobText.contentDescription = getString(CR.string.info_label_cob) + " " + ReceiveData.getCobAsString()
cobText.visibility = iobText.visibility

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

private fun updateConnectionsTable() {
tableConnections.removeViews(1, maxOf(0, tableConnections.childCount - 1))
if (SourceStateData.lastState != SourceState.NONE)
tableConnections.addView(createRow(
SourceStateData.lastSource.resId,
SourceStateData.getStateMessage(this)))
if (SourceStateData.lastState != SourceState.NONE) {
val msg = SourceStateData.getStateMessage(this)
tableConnections.addView(createRow(SourceStateData.lastSource.resId,msg))
if(SourceStateData.lastState == SourceState.ERROR && SourceStateData.lastSource == DataSource.DEXCOM_SHARE) {
if (msg.contains("500:")) { // invalid password
val us_account = sharedPref.getBoolean(Constants.SHARED_PREF_DEXCOM_SHARE_USE_US_URL, false)
val browserIntent = Intent(
Intent.ACTION_VIEW,
Uri.parse(resources.getString(if(us_account)CR.string.dexcom_account_us_url else CR.string.dexcom_account_non_us_url))
)
val onClickListener = View.OnClickListener {
startActivity(browserIntent)
}
tableConnections.addView(
createRow(
SourceStateData.lastSource.resId,
resources.getString(if(us_account) CR.string.dexcom_share_check_us_account else CR.string.dexcom_share_check_non_us_account),
onClickListener
)
)
}
}
if(SourceStateData.lastErrorInfo.isNotEmpty()) {
// add error specific information in an own row
tableConnections.addView(createRow(SourceStateData.lastErrorInfo))
}
tableConnections.addView(createRow(CR.string.request_timestamp, Utils.getUiTimeStamp(SourceStateData.lastStateTime)))
}
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)))
checkTableVisibility(tableConnections)
}

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

private fun updateDetailsTable() {
tableDetails.removeViews(1, maxOf(0, tableDetails.childCount - 1))
if(!GlucoDataServiceAuto.patientName.isNullOrEmpty()) {
tableDetails.addView(createRow(CR.string.patient_name, GlucoDataServiceAuto.patientName!!))
}

if(ReceiveData.time > 0) {
if (ReceiveData.isMmol)
tableDetails.addView(createRow(CR.string.info_label_raw, "${ReceiveData.rawValue} mg/dl"))
tableDetails.addView(createRow(CR.string.info_label_timestamp, DateFormat.getTimeInstance(DateFormat.DEFAULT).format(Date(ReceiveData.time))))
tableDetails.addView(createRow(CR.string.info_label_timestamp, Utils.getUiTimeStamp(ReceiveData.time)))
if (ReceiveData.sensorID?.isNotEmpty() == true) {
tableDetails.addView(createRow(CR.string.info_label_sensor_id, if(BuildConfig.DEBUG) "ABCDE12345" else ReceiveData.sensorID!!))
}
Expand Down Expand Up @@ -520,12 +594,12 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
return row
}

private fun createRow(key: String, onClickListener: View.OnClickListener? = null) : TableRow {
private fun createRow(value: String, onClickListener: View.OnClickListener? = null) : TableRow {
val row = TableRow(this)
row.weightSum = 1f
//row.setBackgroundColor(resources.getColor(R.color.table_row))
row.setPadding(Utils.dpToPx(5F, this))
row.addView(createColumn(key, false, onClickListener))
row.addView(createColumn(value, false, onClickListener))
return row
}

Expand Down
Loading

0 comments on commit 8485b00

Please sign in to comment.