mirror of
https://github.com/dzeiocom/OpenHealth.git
synced 2025-04-22 19:02:16 +00:00
fix: Add service boot item
This commit is contained in:
parent
1f780ae2c4
commit
de2ca726f6
@ -7,6 +7,7 @@ charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
max_line_length = 120
|
||||
|
||||
[*.md]
|
||||
indent_size = 2
|
||||
trim_trailing_whitespace = false
|
||||
|
@ -9,13 +9,13 @@
|
||||
<!-- Phone Sensors for Steps -->
|
||||
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
|
||||
|
||||
<!-- Bluetooth Connection -->
|
||||
<!-- Bluetooth Scales Connection -->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
|
||||
<!-- Application Service-->
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<application
|
||||
android:name=".Application"
|
||||
@ -52,12 +52,22 @@
|
||||
android:name="com.google.android.gms.oss.licenses.OssLicensesActivity"
|
||||
android:theme="@style/Theme.OpenHealth" />
|
||||
|
||||
<!-- the Service for the application -->
|
||||
<receiver
|
||||
android:name=".services.ServiceBoot"
|
||||
android:exported="false"
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<!-- the OpenHealth Service for the application -->
|
||||
<service
|
||||
android:name=".services.OpenHealthService"
|
||||
android:enabled="true"
|
||||
android:permission="android.permission.ACTIVITY_RECOGNITION" />
|
||||
|
||||
<!-- Android 13 Locales management if I remember correctly -->
|
||||
<!-- Android 13 Locales management -->
|
||||
<service
|
||||
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
|
||||
android:enabled="false"
|
||||
|
@ -13,6 +13,8 @@ import com.dzeio.openhealth.data.water.Water
|
||||
import com.dzeio.openhealth.data.water.WaterDao
|
||||
import com.dzeio.openhealth.data.weight.Weight
|
||||
import com.dzeio.openhealth.data.weight.WeightDao
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* ROOM SQLite database for the application
|
||||
@ -46,6 +48,11 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
*/
|
||||
private const val DATABASE_NAME = "open_health"
|
||||
|
||||
private const val BACKUP_DATABASE = "-bkp"
|
||||
|
||||
private const val SQLITE_SHMFILE_SUFFIX = "-wal"
|
||||
private const val SQLITE_WALFILE_SUFFIX = "-shm"
|
||||
|
||||
// For Singleton instantiation
|
||||
@Volatile
|
||||
private var instance: AppDatabase? = null
|
||||
@ -66,4 +73,57 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
fun backup(context: Context): Int {
|
||||
var result = -99
|
||||
if (instance == null) return result
|
||||
|
||||
val dbFile = context.getDatabasePath(DATABASE_NAME)
|
||||
val dbWalFile = File(dbFile.path + SQLITE_WALFILE_SUFFIX)
|
||||
val dbShmFile = File(dbFile.path + SQLITE_SHMFILE_SUFFIX)
|
||||
val bkpFile = File(dbFile.path + BACKUP_DATABASE)
|
||||
val bkpWalFile = File(bkpFile.path + SQLITE_WALFILE_SUFFIX)
|
||||
val bkpShmFile = File(bkpFile.path + SQLITE_SHMFILE_SUFFIX)
|
||||
if (bkpFile.exists()) bkpFile.delete()
|
||||
if (bkpWalFile.exists()) bkpWalFile.delete()
|
||||
if (bkpShmFile.exists()) bkpShmFile.delete()
|
||||
checkpoint()
|
||||
try {
|
||||
dbFile.copyTo(bkpFile, true)
|
||||
if (dbWalFile.exists()) dbWalFile.copyTo(bkpWalFile, true)
|
||||
if (dbShmFile.exists()) dbShmFile.copyTo(bkpShmFile, true)
|
||||
result = 0
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun restore(context: Context) {
|
||||
if (!File(context.getDatabasePath(DATABASE_NAME).path + BACKUP_DATABASE).exists()) {
|
||||
return
|
||||
}
|
||||
if (instance == null) return
|
||||
val dbpath = instance!!.openHelper.readableDatabase.path
|
||||
val dbFile = File(dbpath)
|
||||
val dbWalFile = File(dbFile.path + SQLITE_WALFILE_SUFFIX)
|
||||
val dbShmFile = File(dbFile.path + SQLITE_SHMFILE_SUFFIX)
|
||||
val bkpFile = File(dbFile.path + BACKUP_DATABASE)
|
||||
val bkpWalFile = File(bkpFile.path + SQLITE_WALFILE_SUFFIX)
|
||||
val bkpShmFile = File(bkpFile.path + SQLITE_SHMFILE_SUFFIX)
|
||||
try {
|
||||
bkpFile.copyTo(dbFile, true)
|
||||
if (bkpWalFile.exists()) bkpWalFile.copyTo(dbWalFile, true)
|
||||
if (bkpShmFile.exists()) bkpShmFile.copyTo(dbShmFile, true)
|
||||
checkpoint()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkpoint() {
|
||||
val db = this.openHelper.writableDatabase
|
||||
db.query("PRAGMA wal_checkpoint(FULL);", emptyArray())
|
||||
db.query("PRAGMA wal_checkpoint(TRUNCATE);", emptyArray())
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.dzeio.openhealth.services
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import com.dzeio.openhealth.utils.ServiceUtils
|
||||
|
||||
class ServiceBoot : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (context != null) {
|
||||
ServiceUtils.startService(context, OpenHealthService::class.java)
|
||||
Log.i("ServiceBoot", "started")
|
||||
}
|
||||
}
|
||||
}
|
@ -99,8 +99,7 @@ class ListWeightFragment :
|
||||
val permissions = arrayOf(
|
||||
Manifest.permission.BLUETOOTH,
|
||||
Manifest.permission.BLUETOOTH_CONNECT,
|
||||
Manifest.permission.BLUETOOTH_SCAN,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
Manifest.permission.BLUETOOTH_SCAN
|
||||
)
|
||||
val hasPermission = PermissionsManager.hasPermission(requireContext(), permissions)
|
||||
if (!hasPermission) {
|
||||
@ -142,6 +141,16 @@ class ListWeightFragment :
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.goalWeight.observe(viewLifecycleOwner) {
|
||||
val chart = binding.chart
|
||||
if (it != null) {
|
||||
chart.yAxis.addLine(
|
||||
it,
|
||||
Line(true, Paint(chart.yAxis.linePaint).apply { strokeWidth = 4f })
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val chart = binding.chart
|
||||
|
||||
val serie = LineSerie(chart).apply {
|
||||
@ -223,13 +232,6 @@ class ListWeightFragment :
|
||||
}
|
||||
serie.entries = entries
|
||||
|
||||
if (viewModel.goalWeight.value != null) {
|
||||
chart.yAxis.addLine(
|
||||
viewModel.goalWeight.value!!,
|
||||
Line(true, Paint(chart.yAxis.linePaint).apply { strokeWidth = 4f })
|
||||
)
|
||||
}
|
||||
|
||||
if (list.isEmpty()) {
|
||||
chart.xAxis.x = 0.0
|
||||
} else {
|
||||
|
@ -10,10 +10,10 @@ import com.dzeio.openhealth.data.weight.WeightRepository
|
||||
import com.dzeio.openhealth.units.Units
|
||||
import com.dzeio.openhealth.utils.Configuration
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
import kotlin.random.Random
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
import kotlin.random.Random
|
||||
|
||||
@HiltViewModel
|
||||
class ListWeightViewModel @Inject internal constructor(
|
||||
@ -24,8 +24,7 @@ class ListWeightViewModel @Inject internal constructor(
|
||||
private val _massUnit = MutableLiveData(Units.Mass.KILOGRAM)
|
||||
val massUnit: LiveData<Units.Mass> = _massUnit
|
||||
|
||||
private val _goalWeight = settings.getFloat(Settings.WEIGHT_GOAL)
|
||||
val goalWeight = _goalWeight.toLiveData()
|
||||
val goalWeight = settings.getFloat(Settings.WEIGHT_GOAL).toLiveData()
|
||||
|
||||
private val _weights = MutableLiveData<List<Weight>?>(null)
|
||||
val weights: LiveData<List<Weight>?> = _weights
|
||||
|
@ -0,0 +1 @@
|
||||
Your privacy-friendly FOSS Health Application
|
Loading…
x
Reference in New Issue
Block a user