feat: Global update
166
app/build.gradle
@ -1,166 +0,0 @@
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
id 'kotlin-kapt'
|
||||
id 'dagger.hilt.android.plugin'
|
||||
|
||||
// Safe Navigation
|
||||
id 'androidx.navigation.safeargs'
|
||||
}
|
||||
|
||||
android {
|
||||
|
||||
signingConfigs {
|
||||
|
||||
release {
|
||||
|
||||
def keystorePropertiesFile = rootProject.file("./keystore.properties")
|
||||
def keystoreProperties = new Properties()
|
||||
try {
|
||||
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
|
||||
} catch (FileNotFoundException ignored) {
|
||||
keystoreProperties = null
|
||||
}
|
||||
|
||||
if (keystoreProperties != null) {
|
||||
storePassword keystoreProperties["storePassword"]
|
||||
keyPassword keystoreProperties["keyPassword"]
|
||||
keyAlias keystoreProperties["keyAlias"]
|
||||
storeFile file(keystoreProperties["storeFile"])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
compileSdk 32
|
||||
|
||||
defaultConfig {
|
||||
// App ID
|
||||
applicationId "com.dzeio.openhealth"
|
||||
|
||||
// Android 5 Lollipop
|
||||
minSdk 21
|
||||
|
||||
// Android 12
|
||||
targetSdk 32
|
||||
|
||||
// Semantic Versioning
|
||||
versionName "1.0.0"
|
||||
versionCode 1
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
// Languages
|
||||
def locales = ["en", "fr"]
|
||||
|
||||
buildConfigField "String[]", "LOCALES", "new String[]{\""+locales.join("\",\"")+"\"}"
|
||||
resConfigs locales
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
||||
release {
|
||||
// Slimmer version
|
||||
minifyEnabled true
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
|
||||
debug {
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
applicationIdSuffix ".dev"
|
||||
versionNameSuffix '-dev'
|
||||
debuggable true
|
||||
|
||||
// make it debuggable
|
||||
renderscriptDebuggable true
|
||||
|
||||
// Optimization Level
|
||||
renderscriptOptimLevel 0
|
||||
}
|
||||
}
|
||||
|
||||
// Compile using JAVA 8
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
|
||||
// Enable View Binding and Data Binding
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
dataBinding true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Dzeio Charts
|
||||
implementation project(path: ":charts")
|
||||
|
||||
// Core dependencies
|
||||
implementation 'androidx.core:core-ktx:1.8.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.4.2'
|
||||
implementation 'javax.inject:javax.inject:1'
|
||||
implementation 'com.google.android.material:material:1.7.0-alpha03'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.0'
|
||||
|
||||
// Coroutines
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.3"
|
||||
|
||||
// Settings
|
||||
implementation "androidx.preference:preference-ktx:1.2.0"
|
||||
|
||||
// DataStore
|
||||
implementation "androidx.datastore:datastore:1.0.0"
|
||||
|
||||
// Navigation
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.0'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.5.0'
|
||||
|
||||
// Paging
|
||||
implementation "androidx.paging:paging-runtime:3.1.1"
|
||||
implementation "androidx.paging:paging-runtime-ktx:3.1.1"
|
||||
|
||||
|
||||
// Services
|
||||
implementation 'androidx.work:work-runtime-ktx:2.7.1'
|
||||
|
||||
// Tests
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
|
||||
// Graph
|
||||
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
|
||||
|
||||
// Graphs test 2
|
||||
implementation 'com.github.HackPlan:AndroidCharts:1.0.4'
|
||||
|
||||
// Hilt
|
||||
implementation 'com.google.dagger:hilt-android:2.43'
|
||||
kapt 'com.google.dagger:hilt-compiler:2.43'
|
||||
|
||||
// Google Fit
|
||||
implementation "com.google.android.gms:play-services-fitness:21.1.0"
|
||||
implementation "com.google.android.gms:play-services-auth:20.2.0"
|
||||
|
||||
// Samsung Health
|
||||
implementation files('libs/samsung-health-data-1.5.0.aar')
|
||||
implementation 'com.google.code.gson:gson:2.9.0'
|
||||
|
||||
// ROOM
|
||||
implementation "androidx.room:room-runtime:2.4.2"
|
||||
kapt "androidx.room:room-compiler:2.4.2"
|
||||
implementation "androidx.room:room-ktx:2.4.2"
|
||||
testImplementation "androidx.room:room-testing:2.4.2"
|
||||
|
||||
// Futures
|
||||
implementation 'com.google.guava:guava:31.1-jre'
|
||||
implementation "androidx.concurrent:concurrent-futures:1.1.0"
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.6.3'
|
||||
}
|
174
app/build.gradle.kts
Normal file
@ -0,0 +1,174 @@
|
||||
import java.util.Properties
|
||||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
kotlin("android")
|
||||
kotlin("kapt")
|
||||
id("dagger.hilt.android.plugin")
|
||||
|
||||
// Safe Navigation
|
||||
id("androidx.navigation.safeargs")
|
||||
}
|
||||
|
||||
android {
|
||||
|
||||
signingConfigs {
|
||||
|
||||
create("release") {
|
||||
|
||||
val keystoreProperties = Properties().apply {
|
||||
load(rootProject.file("./keystore.properties").reader())
|
||||
}
|
||||
|
||||
if (keystoreProperties.isNotEmpty()) {
|
||||
storePassword = keystoreProperties["storePassword"] as String
|
||||
keyPassword = keystoreProperties["keyPassword"] as String
|
||||
keyAlias = keystoreProperties["keyAlias"] as String
|
||||
storeFile = file(keystoreProperties["storeFile"] as String)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
compileSdk = 33
|
||||
|
||||
defaultConfig {
|
||||
// App ID
|
||||
applicationId = "com.dzeio.openhealth"
|
||||
|
||||
// Android 5 Lollipop
|
||||
minSdk = 21
|
||||
|
||||
// Android 12
|
||||
targetSdk = 33
|
||||
|
||||
// Semantic Versioning
|
||||
versionName = "1.0.0"
|
||||
versionCode = 1
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
// Languages
|
||||
val locales = listOf("en", "fr")
|
||||
|
||||
buildConfigField(
|
||||
"String[]",
|
||||
"LOCALES",
|
||||
"new String[]{\"" + locales.joinToString("\",\"") + "\"}"
|
||||
)
|
||||
resourceConfigurations += locales
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
||||
getByName("release") {
|
||||
// Slimmer version
|
||||
isMinifyEnabled = true
|
||||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
||||
signingConfig = signingConfigs.getByName("release")
|
||||
}
|
||||
|
||||
getByName("debug") {
|
||||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
||||
applicationIdSuffix = ".dev"
|
||||
versionNameSuffix = "-dev"
|
||||
isDebuggable = true
|
||||
|
||||
// make it debuggable
|
||||
isRenderscriptDebuggable = true
|
||||
|
||||
// Optimization Level
|
||||
renderscriptOptimLevel = 0
|
||||
}
|
||||
}
|
||||
|
||||
// Compile using JAVA 8
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
// Enable View Binding and Data Binding
|
||||
buildFeatures {
|
||||
viewBinding = true
|
||||
dataBinding = true
|
||||
}
|
||||
namespace = "com.dzeio.openhealth"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Dzeio Charts
|
||||
implementation(project(":charts"))
|
||||
// implementation(project(":CrashHandler"))
|
||||
|
||||
implementation("com.dzeio:crashhandler:1.0.1")
|
||||
|
||||
// Core dependencies
|
||||
implementation("androidx.core:core-ktx:1.8.0")
|
||||
implementation("androidx.appcompat:appcompat:1.6.0-alpha05")
|
||||
implementation("javax.inject:javax.inject:1")
|
||||
implementation("com.google.android.material:material:1.7.0-alpha03")
|
||||
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
|
||||
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.5.1")
|
||||
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1")
|
||||
|
||||
// implementation("com.github.Aviortheking:crashhandler:0.2.3")
|
||||
|
||||
// Coroutines
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
|
||||
|
||||
// Settings
|
||||
implementation("androidx.preference:preference-ktx:1.2.0")
|
||||
|
||||
// DataStore
|
||||
implementation("androidx.datastore:datastore:1.0.0")
|
||||
|
||||
// Navigation
|
||||
implementation("androidx.navigation:navigation-fragment-ktx:2.5.1")
|
||||
implementation("androidx.navigation:navigation-ui-ktx:2.5.1")
|
||||
|
||||
// Paging
|
||||
implementation("androidx.paging:paging-runtime:3.1.1")
|
||||
implementation("androidx.paging:paging-runtime-ktx:3.1.1")
|
||||
|
||||
|
||||
// Services
|
||||
implementation("androidx.work:work-runtime-ktx:2.7.1")
|
||||
|
||||
// Tests
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.3")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
|
||||
|
||||
// Graph
|
||||
implementation("com.github.PhilJay:MPAndroidChart:v3.1.0")
|
||||
|
||||
// Graphs test 2
|
||||
implementation("com.github.HackPlan:AndroidCharts:1.0.4")
|
||||
|
||||
// Hilt
|
||||
implementation("com.google.dagger:hilt-android:2.43.2")
|
||||
kapt("com.google.dagger:hilt-compiler:2.43.2")
|
||||
|
||||
// Google Fit
|
||||
implementation("com.google.android.gms:play-services-fitness:21.1.0")
|
||||
implementation("com.google.android.gms:play-services-auth:20.2.0")
|
||||
|
||||
// Samsung Health
|
||||
implementation(files("libs/samsung-health-data-1.5.0.aar"))
|
||||
implementation("com.google.code.gson:gson:2.9.1")
|
||||
|
||||
// ROOM
|
||||
implementation("androidx.room:room-runtime:2.4.3")
|
||||
kapt("androidx.room:room-compiler:2.4.3")
|
||||
implementation("androidx.room:room-ktx:2.4.3")
|
||||
testImplementation("androidx.room:room-testing:2.4.3")
|
||||
|
||||
// Futures
|
||||
implementation("com.google.guava:guava:31.1-jre")
|
||||
implementation("androidx.concurrent:concurrent-futures:1.1.0")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.6.4")
|
||||
}
|
2
app/proguard-rules.pro
vendored
@ -1,6 +1,6 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
# proguardFiles setting in build.gradle.kts.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
@ -1,7 +1,7 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:width="80dp"
|
||||
android:height="80dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<group android:scaleX="0.15074074"
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/vector_logo_background"/>
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||
<background android:drawable="@drawable/vector_logo_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
Before Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 9.2 KiB |
Before Width: | Height: | Size: 13 KiB |
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name" translatable="false">OpenHealth - Debug</string>
|
||||
<string name="app_name" translatable="false">Open Health - Debug</string>
|
||||
</resources>
|
||||
|
@ -1,6 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.dzeio.openhealth">
|
||||
<manifest xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- Notifications -->
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||
|
||||
<!-- Google Fit -->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
@ -15,11 +18,11 @@
|
||||
</queries>
|
||||
|
||||
<application
|
||||
android:name=".Application"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:name=".Application"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:localeConfig="@xml/locales"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.OpenHealth">
|
||||
|
||||
@ -44,14 +47,22 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- Activity for error handling -->
|
||||
<activity android:name=".ui.ErrorActivity"
|
||||
android:theme="@style/Theme.OpenHealth"
|
||||
android:exported="false" />
|
||||
|
||||
<service
|
||||
android:name=".services.OpenHealthService"
|
||||
android:permission="android.permission.ACTIVITY_RECOGNITION" />
|
||||
|
||||
<service
|
||||
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
|
||||
android:enabled="false"
|
||||
android:exported="false">
|
||||
<meta-data
|
||||
android:name="autoStoreLocales"
|
||||
android:value="true" />
|
||||
</service>
|
||||
|
||||
<activity android:name=".ui.ErrorActivity"
|
||||
android:theme="@style/Theme.OpenHealth.NoActionBar"
|
||||
android:exported="false" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
@ -1,16 +1,13 @@
|
||||
package com.dzeio.openhealth
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Process
|
||||
import android.util.Log
|
||||
import android.content.Context
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.dzeio.crashhandler.CrashHandler
|
||||
import com.dzeio.openhealth.ui.ErrorActivity
|
||||
import com.dzeio.openhealth.utils.LocaleUtils
|
||||
import com.google.android.material.color.DynamicColors
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import java.util.Locale
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
@HiltAndroidApp
|
||||
class Application : Application() {
|
||||
@ -20,42 +17,24 @@ class Application : Application() {
|
||||
|
||||
override fun onCreate() {
|
||||
|
||||
// Application Error Handling
|
||||
Thread.setDefaultUncaughtExceptionHandler { paramThread, paramThrowable ->
|
||||
//Log error to logcat if it wasn't done before
|
||||
Log.e(TAG, "En error was detected in the Thread ${paramThread.id}, trying to go to ErrorActivity")
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
|
||||
// send use to the Error Activity
|
||||
val intent = Intent(applicationContext, ErrorActivity::class.java)
|
||||
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
|
||||
intent.putExtra("error", paramThrowable.stackTraceToString())
|
||||
intent.putExtra("threadId", paramThread.id)
|
||||
startActivity(intent)
|
||||
Log.e(TAG, "Activity should have started")
|
||||
|
||||
Process.killProcess(Process.myPid())
|
||||
exitProcess(10)
|
||||
}
|
||||
CrashHandler.Builder()
|
||||
.withActivity(ErrorActivity::class.java)
|
||||
.withPrefs(prefs)
|
||||
.witheErrorReporterCrashKey(R.string.error_reporter_crash)
|
||||
.withPrefsKey(Settings.CRASH_LAST_TIME)
|
||||
.withPrefix("${BuildConfig.APPLICATION_ID} v${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})")
|
||||
.build()
|
||||
.setup(this)
|
||||
|
||||
// Android Dynamics Colors
|
||||
DynamicColors.applyToActivitiesIfAvailable(this)
|
||||
|
||||
// Change application Language based on setting
|
||||
val preferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
val lang = preferences.getString("global_language", Locale.getDefault().language)
|
||||
if (lang == null) {
|
||||
Log.e(TAG, "lang is null")
|
||||
} else {
|
||||
val locale = Locale(lang)
|
||||
Locale.setDefault(locale)
|
||||
}
|
||||
|
||||
// val overrideConfiguration = baseContext.resources.configuration
|
||||
// overrideConfiguration.locale = locale
|
||||
// val context: Context = createConfigurationContext(overrideConfiguration)
|
||||
// val resources: Resources = context.resources
|
||||
|
||||
super.onCreate()
|
||||
}
|
||||
|
||||
override fun attachBaseContext(base: Context) {
|
||||
super.attachBaseContext(LocaleUtils.onAttach(base))
|
||||
}
|
||||
}
|
||||
|
19
app/src/main/java/com/dzeio/openhealth/Settings.kt
Normal file
@ -0,0 +1,19 @@
|
||||
package com.dzeio.openhealth
|
||||
|
||||
object Settings {
|
||||
|
||||
/**
|
||||
* get the last time the Application has crashed
|
||||
*
|
||||
* type: Long
|
||||
*/
|
||||
const val CRASH_LAST_TIME = "com.dzeio.open-health.crash.last_time"
|
||||
|
||||
/**
|
||||
* The software override application language
|
||||
*
|
||||
* note: also change it in `preferences.xml`
|
||||
*/
|
||||
const val APP_LANGUAGE = "com.dzeio.open-health.app.language"
|
||||
|
||||
}
|
@ -10,8 +10,6 @@ import android.util.Log
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.dzeio.openhealth.Application
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
class StepSource(
|
||||
@ -78,7 +76,9 @@ class StepSource(
|
||||
timeSinceLastRecord = timeSinceLastBoot
|
||||
|
||||
runBlocking {
|
||||
events.send(diff)
|
||||
if (events != null) {
|
||||
events.send(diff)
|
||||
}
|
||||
}
|
||||
callback?.invoke(diff)
|
||||
}
|
||||
|
@ -120,9 +120,9 @@ class OpenHealthService : Service() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_IMMUTABLE else 0
|
||||
val intent = NavDeepLinkBuilder(this)
|
||||
.setGraph(R.navigation.mobile_navigation)
|
||||
.setDestination(R.id.nav_home)
|
||||
// Will nav to water home when there will be a way to add it there
|
||||
// .setDestination(R.id.nav_water_home)
|
||||
// .setDestination(R.id.nav_home)
|
||||
// Will nav to water home when there will be a way to add it there
|
||||
.setDestination(R.id.nav_steps_home)
|
||||
.createTaskStackBuilder()
|
||||
.getPendingIntent(0, flag)
|
||||
|
||||
|
@ -17,7 +17,7 @@ import kotlin.system.exitProcess
|
||||
class ErrorActivity : BaseActivity<ActivityErrorBinding>() {
|
||||
|
||||
companion object {
|
||||
const val TAG = "${Application.TAG}/ErrorActivity"
|
||||
const val TAG = "${Application.TAG}/ErrorActivit"
|
||||
}
|
||||
|
||||
override val bindingInflater: (LayoutInflater) -> ActivityErrorBinding =
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.dzeio.openhealth.ui
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
@ -12,7 +11,9 @@ import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.WindowManager
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
@ -26,8 +27,8 @@ import com.dzeio.openhealth.core.BaseActivity
|
||||
import com.dzeio.openhealth.databinding.ActivityMainBinding
|
||||
import com.dzeio.openhealth.interfaces.NotificationChannels
|
||||
import com.dzeio.openhealth.services.OpenHealthService
|
||||
import com.dzeio.openhealth.utils.ServiceUtils
|
||||
import com.dzeio.openhealth.workers.WaterReminderWorker
|
||||
import com.google.android.material.color.MaterialColors
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
@ -55,28 +56,52 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
|
||||
setSupportActionBar(binding.toolbar)
|
||||
|
||||
window.navigationBarColor = MaterialColors.getColor(
|
||||
window.decorView,
|
||||
com.google.android.material.R.attr.colorSecondaryContainer
|
||||
)
|
||||
window.statusBarColor = MaterialColors.getColor(
|
||||
window.decorView,
|
||||
com.google.android.material.R.attr.colorSecondaryContainer
|
||||
)
|
||||
// Comportement chelou API 28-
|
||||
// Comportement normal 31+
|
||||
|
||||
when (this.resources.configuration.uiMode.and(Configuration.UI_MODE_NIGHT_MASK)) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> {
|
||||
WindowCompat.getInsetsController(window, window.decorView).apply {
|
||||
isAppearanceLightNavigationBars = true
|
||||
isAppearanceLightStatusBars = false
|
||||
}
|
||||
}
|
||||
Configuration.UI_MODE_NIGHT_NO, Configuration.UI_MODE_NIGHT_UNDEFINED -> {
|
||||
WindowCompat.getInsetsController(window, window.decorView).apply {
|
||||
isAppearanceLightNavigationBars = false
|
||||
isAppearanceLightStatusBars = true
|
||||
// do not do the cool status/navigation bars for API 29 & 30
|
||||
if (Build.VERSION.SDK_INT != Build.VERSION_CODES.R && Build.VERSION.SDK_INT != Build.VERSION_CODES.Q) {
|
||||
// allow to put the content behind the status bar & Navigation bar (one of them at least lul)
|
||||
// ALSO: make the status/navigation bars semi-transparent
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
|
||||
|
||||
// Make the color of the navigation bar semi-transparent
|
||||
// window.navigationBarColor = Color.TRANSPARENT
|
||||
// Make the color of the status bar transparent
|
||||
// window.statusBarColor = Color.TRANSPARENT
|
||||
// Apply the previous changes
|
||||
// window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
||||
|
||||
// Update toolbar height with the statusbar size included
|
||||
// ALSO: make both the status/navigation bars transparent (WHYYYYYYY)
|
||||
val toolbarHeight = binding.toolbar.layoutParams.height
|
||||
window.decorView.setOnApplyWindowInsetsListener { _, insets ->
|
||||
val statusBarSize = insets.systemWindowInsetTop
|
||||
// Add padding to the toolbar (YaY I know how something works)
|
||||
binding.toolbar.updatePadding(top = statusBarSize)
|
||||
binding.toolbar.layoutParams.height = toolbarHeight + statusBarSize
|
||||
return@setOnApplyWindowInsetsListener insets
|
||||
}
|
||||
|
||||
// normally makes sure icons are at the correct color but idk if it works
|
||||
when (this.resources.configuration.uiMode.and(Configuration.UI_MODE_NIGHT_MASK)) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> {
|
||||
WindowCompat.getInsetsController(window, window.decorView).apply {
|
||||
// force to display the bars in light color
|
||||
isAppearanceLightNavigationBars = true
|
||||
isAppearanceLightStatusBars = false // WHY
|
||||
}
|
||||
}
|
||||
Configuration.UI_MODE_NIGHT_NO, Configuration.UI_MODE_NIGHT_UNDEFINED -> {
|
||||
WindowCompat.getInsetsController(window, window.decorView).apply {
|
||||
// force to display the bars in dark color
|
||||
isAppearanceLightNavigationBars = false
|
||||
isAppearanceLightStatusBars = true // WHY
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
val navHostFragment =
|
||||
@ -108,20 +133,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
WaterReminderWorker.setup(this)
|
||||
// StepCountService.setup(this)
|
||||
|
||||
this.betterStartService(OpenHealthService::class.java)
|
||||
ServiceUtils.startService(this, OpenHealthService::class.java)
|
||||
}
|
||||
|
||||
private fun <T> betterStartService(service: Class<T>) {
|
||||
val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
for (runninService in activityManager.getRunningServices(Integer.MAX_VALUE)) {
|
||||
if (service.name.equals(runninService.service.className)) {
|
||||
Log.w(TAG, "Service already existing, not starting again")
|
||||
return
|
||||
}
|
||||
}
|
||||
Log.i(TAG, "Starting service ${service.name}")
|
||||
Intent(this, service).also { intent -> startService(intent) }
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
super.onCreateOptionsMenu(menu)
|
||||
|
@ -31,9 +31,9 @@ class BrowseFragment :
|
||||
|
||||
private lateinit var button: MaterialCardView
|
||||
private val activityResult = registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
ActivityResultContracts.RequestMultiplePermissions()
|
||||
) {
|
||||
if (!it) {
|
||||
if (it.containsValue(false)) {
|
||||
// TODO: Show a popup with choice to change it
|
||||
Toast.makeText(requireContext(), R.string.permission_declined, Toast.LENGTH_LONG).show()
|
||||
return@registerForActivityResult
|
||||
@ -55,14 +55,29 @@ class BrowseFragment :
|
||||
|
||||
binding.steps.setOnClickListener {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val hasPermission = PermissionsManager.hasPermission(
|
||||
val activityPermission = PermissionsManager.hasPermission(
|
||||
requireContext(),
|
||||
Manifest.permission.ACTIVITY_RECOGNITION
|
||||
)
|
||||
|
||||
if (!hasPermission) {
|
||||
val notificationPermission = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && PermissionsManager.hasPermission(
|
||||
requireContext(),
|
||||
Manifest.permission.POST_NOTIFICATIONS
|
||||
)
|
||||
|
||||
val permissionsToAsk = arrayListOf<String>()
|
||||
|
||||
if (!activityPermission) {
|
||||
permissionsToAsk.add(Manifest.permission.ACTIVITY_RECOGNITION)
|
||||
}
|
||||
|
||||
if (!notificationPermission && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
permissionsToAsk.add(Manifest.permission.POST_NOTIFICATIONS)
|
||||
}
|
||||
|
||||
if (permissionsToAsk.isNotEmpty()) {
|
||||
button = binding.steps
|
||||
activityResult.launch(Manifest.permission.ACTIVITY_RECOGNITION)
|
||||
activityResult.launch(permissionsToAsk.toTypedArray())
|
||||
return@setOnClickListener
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,7 @@ import android.content.SharedPreferences
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.RectF
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
@ -37,9 +35,8 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
|
||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
// Bindings
|
||||
binding.addWeight.setOnClickListener {
|
||||
AddWeightDialog().show(requireActivity().supportFragmentManager, null)
|
||||
@ -56,10 +53,12 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
|
||||
viewModel.updateWater(water)
|
||||
}
|
||||
}
|
||||
val waterUnit =
|
||||
UnitFactory.volume(settings.getString("water_unit", "milliliter") ?: "Milliliter")
|
||||
|
||||
binding.fragmentHomeWaterTotal.text =
|
||||
String.format(
|
||||
resources.getString(viewModel.waterUnit.unit),
|
||||
resources.getString(waterUnit.unit),
|
||||
viewModel.dailyWaterIntake
|
||||
)
|
||||
|
||||
@ -94,6 +93,21 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
|
||||
com.google.android.material.R.attr.colorOnBackground
|
||||
)
|
||||
)
|
||||
|
||||
lifecycleScope.launchWhenStarted {
|
||||
viewModel.fetchWeights().collectLatest {
|
||||
updateGraph(it)
|
||||
}
|
||||
updateWater(0)
|
||||
}
|
||||
|
||||
viewModel.water.observe(viewLifecycleOwner) {
|
||||
if (it != null) {
|
||||
updateWater(it.value)
|
||||
} else {
|
||||
updateWater(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateGraph(list: List<Weight>) {
|
||||
@ -119,25 +133,6 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
|
||||
// }
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
|
||||
lifecycleScope.launchWhenStarted {
|
||||
viewModel.fetchWeights().collectLatest {
|
||||
updateGraph(it)
|
||||
}
|
||||
updateWater(0)
|
||||
}
|
||||
|
||||
viewModel.water.observe(viewLifecycleOwner) {
|
||||
if (it != null) {
|
||||
updateWater(it.value)
|
||||
} else {
|
||||
updateWater(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var oldValue = 0f
|
||||
|
||||
private fun updateWater(newValue: Int) {
|
||||
@ -151,6 +146,12 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
|
||||
(newValue * waterUnit.modifier).toInt()
|
||||
)
|
||||
|
||||
binding.fragmentHomeWaterTotal.text =
|
||||
String.format(
|
||||
resources.getString(waterUnit.unit),
|
||||
viewModel.dailyWaterIntake
|
||||
)
|
||||
|
||||
var width = 1500
|
||||
var height = 750
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.dzeio.openhealth.ui.settings
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.Configuration
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.util.Log
|
||||
@ -9,13 +9,20 @@ import androidx.preference.EditTextPreference
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.dzeio.openhealth.Application
|
||||
import com.dzeio.openhealth.BuildConfig
|
||||
import com.dzeio.openhealth.R
|
||||
import com.dzeio.openhealth.Settings
|
||||
import com.dzeio.openhealth.units.UnitFactory
|
||||
import com.dzeio.openhealth.utils.LocaleUtils
|
||||
import java.util.Locale
|
||||
|
||||
class SettingsFragment : PreferenceFragmentCompat() {
|
||||
|
||||
private companion object {
|
||||
const val TAG = "${Application.TAG}/SttngsFrgmnt"
|
||||
}
|
||||
|
||||
val settings: SharedPreferences by lazy {
|
||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
}
|
||||
@ -71,8 +78,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||
}
|
||||
}
|
||||
|
||||
val languagesPreference = findPreference<ListPreference>("global_language")
|
||||
Log.d("TAG", Locale.getDefault().language)
|
||||
val languagesPreference = findPreference<ListPreference>(Settings.APP_LANGUAGE)
|
||||
Log.d(TAG, Locale.getDefault().language)
|
||||
languagesPreference?.apply {
|
||||
entries = BuildConfig.LOCALES
|
||||
entryValues = BuildConfig.LOCALES
|
||||
@ -81,17 +88,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||
|
||||
// Update App Locale
|
||||
languagesPreference?.setOnPreferenceChangeListener { _, newValue ->
|
||||
val locale = Locale(newValue as String)
|
||||
Locale.setDefault(locale)
|
||||
val config = Configuration()
|
||||
config.locale = locale
|
||||
|
||||
requireActivity().baseContext.resources.updateConfiguration(
|
||||
config,
|
||||
requireActivity().baseContext.resources.displayMetrics
|
||||
)
|
||||
|
||||
requireActivity().recreate()
|
||||
LocaleUtils.setLanguage(requireContext(), newValue as String)
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
||||
requireActivity().recreate()
|
||||
}
|
||||
|
||||
return@setOnPreferenceChangeListener true
|
||||
}
|
||||
|
@ -13,9 +13,6 @@ import com.dzeio.openhealth.core.BaseFragment
|
||||
import com.dzeio.openhealth.databinding.FragmentStepsHomeBinding
|
||||
import com.google.android.material.color.MaterialColors
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.text.DateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
@AndroidEntryPoint
|
||||
class StepsHomeFragment :
|
||||
@ -50,66 +47,64 @@ class StepsHomeFragment :
|
||||
|
||||
val chart = binding.chart
|
||||
|
||||
val serie = BarSerie()
|
||||
val serie = BarSerie(chart)
|
||||
|
||||
chart.series = arrayListOf(serie)
|
||||
|
||||
viewModel.items.observe(viewLifecycleOwner) { list ->
|
||||
adapter.set(list)
|
||||
|
||||
// chart.debug = true
|
||||
|
||||
chart.xAxis.entriesDisplayed = 10
|
||||
// chart.numberOfLabels = 2
|
||||
chart.debug = true
|
||||
|
||||
// chart.animation.enabled = false
|
||||
chart.animation.refreshRate = 60
|
||||
chart.animation.duration = 300
|
||||
// chart.animation.refreshRate = 60
|
||||
// chart.animation.duration = 300
|
||||
|
||||
chart.scroller.zoomEnabled = false
|
||||
// chart.scroller.zoomEnabled = false
|
||||
|
||||
chart.xAxis.labels.color = MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorOnBackground
|
||||
)
|
||||
// chart.xAxis.labels.color = MaterialColors.getColor(
|
||||
// requireView(),
|
||||
// com.google.android.material.R.attr.colorOnBackground
|
||||
// )
|
||||
|
||||
chart.xAxis.labels.size = 32f
|
||||
// chart.xAxis.labels.size = 32f
|
||||
chart.yAxis.apply {
|
||||
color = MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorPrimary
|
||||
)
|
||||
textPaint.color = MaterialColors.getColor(
|
||||
setYMin(0f)
|
||||
textLabel.color = MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorOnBackground
|
||||
)
|
||||
linePaint.color = MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorOutline
|
||||
)
|
||||
onValueFormat = onValueFormat@{ value, short ->
|
||||
if (short) {
|
||||
return@onValueFormat value.toInt().toString()
|
||||
} else {
|
||||
return@onValueFormat "${value.toInt()} steps"
|
||||
}
|
||||
}
|
||||
// linePaint.color = MaterialColors.getColor(
|
||||
// requireView(),
|
||||
// com.google.android.material.R.attr.colorOutline
|
||||
// )
|
||||
// onValueFormat = onValueFormat@{ value, short ->
|
||||
// if (short) {
|
||||
// return@onValueFormat value.toInt().toString()
|
||||
// } else {
|
||||
// return@onValueFormat "${value.toInt()} steps"
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
serie.datas = list.reversed().map {
|
||||
serie.entries = list.reversed().map {
|
||||
return@map Entry(it.timestamp.toDouble(), it.value.toFloat())
|
||||
} as ArrayList<Entry>
|
||||
|
||||
chart.xAxis.onValueFormat = onValueFormat@{
|
||||
val formatter = DateFormat.getDateTimeInstance(
|
||||
DateFormat.SHORT,
|
||||
DateFormat.SHORT,
|
||||
Locale.getDefault()
|
||||
)
|
||||
return@onValueFormat formatter.format(Date(it.toLong()))
|
||||
chart.xAxis.apply {
|
||||
increment = (1000 * 60 * 60).toDouble()
|
||||
displayCount = 24 * 7
|
||||
x = serie.entries.first().x
|
||||
}
|
||||
|
||||
// chart.yAxis.max = (total / list.size).toInt()
|
||||
// chart.xAxis.onValueFormat = onValueFormat@{
|
||||
// val formatter = DateFormat.getDateTimeInstance(
|
||||
// DateFormat.SHORT,
|
||||
// DateFormat.SHORT,
|
||||
// Locale.getDefault()
|
||||
// )
|
||||
// return@onValueFormat formatter.format(Date(it.toLong()))
|
||||
// }
|
||||
|
||||
chart.refresh()
|
||||
}
|
||||
|
76
app/src/main/java/com/dzeio/openhealth/utils/LocaleUtils.kt
Normal file
@ -0,0 +1,76 @@
|
||||
package com.dzeio.openhealth.utils
|
||||
|
||||
import android.app.LocaleManager
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.os.Build
|
||||
import android.os.LocaleList
|
||||
import android.util.Log
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.dzeio.openhealth.Settings
|
||||
import java.util.Locale
|
||||
|
||||
|
||||
/**
|
||||
* Utils object for [Locale]
|
||||
*
|
||||
* @see https://github.com/gunhansancar/ChangeLanguageExample/blob/master/app/src/main/java/com/gunhansancar/changelanguageexample/helper/LocaleHelper.java
|
||||
*/
|
||||
object LocaleUtils {
|
||||
fun onAttach(context: Context): Context {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
||||
val lang = getPersistedData(context)
|
||||
return setLanguage(context, lang)
|
||||
}
|
||||
return context
|
||||
}
|
||||
|
||||
fun getLanguage(context: Context): String {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
return context.getSystemService(LocaleManager::class.java)
|
||||
.applicationLocales.get(0).language
|
||||
}
|
||||
return getPersistedData(context)
|
||||
}
|
||||
|
||||
fun setLanguage(context: Context, language: String): Context {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
context.getSystemService(LocaleManager::class.java)
|
||||
.applicationLocales =
|
||||
LocaleList.forLanguageTags(language)
|
||||
}
|
||||
persist(context, language)
|
||||
return updateResources(context, language)
|
||||
}
|
||||
|
||||
private fun getPersistedData(context: Context): String {
|
||||
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
return preferences.getString(Settings.APP_LANGUAGE, Locale.getDefault().language)
|
||||
?: Locale.getDefault().language
|
||||
}
|
||||
|
||||
private fun persist(context: Context, language: String?) {
|
||||
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
preferences.edit().putString(Settings.APP_LANGUAGE, language).apply()
|
||||
}
|
||||
|
||||
private fun updateResources(context: Context, language: String): Context {
|
||||
Log.d("LocaleUtils", language)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
val locale = Locale(language)
|
||||
Locale.setDefault(locale)
|
||||
val configuration = context.resources.configuration
|
||||
configuration.setLocale(locale)
|
||||
configuration.setLayoutDirection(locale)
|
||||
return context.createConfigurationContext(configuration)
|
||||
}
|
||||
val locale = Locale(language)
|
||||
Locale.setDefault(locale)
|
||||
val resources = context.resources
|
||||
val configuration: Configuration = resources.configuration
|
||||
configuration.locale = locale
|
||||
configuration.setLayoutDirection(locale)
|
||||
resources.updateConfiguration(configuration, resources.displayMetrics)
|
||||
return context
|
||||
}
|
||||
}
|
@ -2,10 +2,20 @@ package com.dzeio.openhealth.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import androidx.core.content.ContextCompat
|
||||
|
||||
object PermissionsManager {
|
||||
|
||||
fun hasPermission(context: Context, permission: String): Boolean = context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED
|
||||
fun hasPermission(context: Context, permission: String): Boolean =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED
|
||||
} else {
|
||||
ContextCompat.checkSelfPermission(
|
||||
context,
|
||||
permission
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
|
||||
fun hasPermission(context: Context, permissions: Array<String>): Boolean {
|
||||
for (permission in permissions) {
|
||||
|
21
app/src/main/java/com/dzeio/openhealth/utils/ServiceUtils.kt
Normal file
@ -0,0 +1,21 @@
|
||||
package com.dzeio.openhealth.utils
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import com.dzeio.openhealth.ui.MainActivity
|
||||
|
||||
object ServiceUtils {
|
||||
fun <T> startService(context: Context, service: Class<T>) {
|
||||
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
for (runninService in activityManager.getRunningServices(Integer.MAX_VALUE)) {
|
||||
if (service.name.equals(runninService.service.className)) {
|
||||
Log.w(MainActivity.TAG, "Service already existing, not starting again")
|
||||
return
|
||||
}
|
||||
}
|
||||
Log.i(MainActivity.TAG, "Starting service ${service.name}")
|
||||
Intent(context, service).also { intent -> context.startService(intent) }
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:fitsSystemWindows="false"
|
||||
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
@ -14,28 +15,32 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:fitsSystemWindows="false"
|
||||
tools:context=".ui.MainActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/app_bar"
|
||||
style="@style/Widget.Material3.AppBarLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:fitsSystemWindows="false">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/toolbar"
|
||||
style="@style/ThemeOverlay.Material3.Toolbar.Surface"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
app:titleCentered="true" />
|
||||
android:fitsSystemWindows="false"
|
||||
android:background="@android:color/transparent"
|
||||
app:titleCentered="true"
|
||||
app:layout_collapseMode="pin"
|
||||
android:elevation="0dp" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/scrollView"
|
||||
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
@ -59,6 +64,7 @@
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
android:id="@+id/bottom_nav"
|
||||
android:layout_width="match_parent"
|
||||
android:fitsSystemWindows="false"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
|
@ -109,9 +109,8 @@
|
||||
style="?attr/materialCardViewFilledStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:layout_marginBottom="16dp">
|
||||
android:layout_marginBottom="16dp"
|
||||
app:cardBackgroundColor="?attr/colorOnSurfaceInverse">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -124,11 +123,12 @@
|
||||
<ImageView
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:paddingVertical="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:src="@drawable/ic_outline_favorite_24"
|
||||
android:background="@drawable/shape_circle"
|
||||
app:tint="?colorOnPrimary" />
|
||||
android:paddingVertical="8dp"
|
||||
android:src="@drawable/ic_outline_favorite_24"
|
||||
app:backgroundTint="@android:color/transparent"
|
||||
app:tint="?attr/colorSurfaceInverse" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -138,7 +138,15 @@
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Heart Rate" />
|
||||
android:text="Heart Rate"
|
||||
android:textColor="?attr/colorSurfaceInverse" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Coming soon"
|
||||
android:textColor="?attr/colorSurfaceInverse" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@ -209,10 +217,9 @@
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/height"
|
||||
style="?attr/materialCardViewFilledStyle"
|
||||
app:cardBackgroundColor="?attr/colorOnSurfaceInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:layout_marginBottom="16dp">
|
||||
|
||||
<LinearLayout
|
||||
@ -230,7 +237,8 @@
|
||||
android:layout_marginEnd="16dp"
|
||||
android:src="@drawable/ic_baseline_height_24"
|
||||
android:background="@drawable/shape_circle"
|
||||
app:tint="?colorOnPrimary" />
|
||||
app:backgroundTint="@android:color/transparent"
|
||||
app:tint="?attr/colorSurfaceInverse" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -240,12 +248,14 @@
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?attr/colorSurfaceInverse"
|
||||
android:paddingBottom="4dp"
|
||||
android:text="Height" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?attr/colorSurfaceInverse"
|
||||
android:text="Coming soon" />
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -17,9 +17,8 @@
|
||||
style="?attr/materialCardViewFilledStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<LinearLayout
|
||||
@ -29,31 +28,24 @@
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="54dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginVertical="8dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="2">
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
style="@style/TextAppearance.Material3.TitleMedium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/water_intake" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="end">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/goto_water_home"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/ic_outline_hexagon_24" />
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:id="@+id/goto_water_home"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/ic_outline_hexagon_24" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@ -90,17 +82,23 @@
|
||||
<TextView
|
||||
android:id="@+id/fragment_home_water_current"
|
||||
style="@style/TextAppearance.Material3.LabelMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/unit_volume_milliliter_unit"
|
||||
android:textAlignment="center" />
|
||||
android:textAlignment="center"
|
||||
android:textColor="?attr/colorPrimary" />
|
||||
|
||||
<com.google.android.material.divider.MaterialDivider
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dp"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fragment_home_water_total"
|
||||
style="@style/TextAppearance.Material3.LabelMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textColor="?attr/colorOnBackground"
|
||||
android:text="@string/unit_volume_milliliter_unit"
|
||||
android:textAlignment="center" />
|
||||
|
||||
@ -135,6 +133,113 @@
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
style="?attr/materialCardViewFilledStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="12dp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="2">
|
||||
|
||||
<TextView
|
||||
style="@style/TextAppearance.Material3.TitleMedium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/steps_taken" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="end">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/nav_steps_home"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/ic_outline_hexagon_24" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:gravity="bottom"
|
||||
android:weightSum="3">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/steps_current"
|
||||
style="@style/TextAppearance.Material3.LabelMedium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/unit_volume_milliliter_unit"
|
||||
android:textAlignment="center"
|
||||
android:textColor="?attr/colorPrimary" />
|
||||
|
||||
<com.google.android.material.divider.MaterialDivider
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dp"
|
||||
/>
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/steps_total"
|
||||
style="@style/TextAppearance.Material3.LabelMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:textColor="?attr/colorOnBackground"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/unit_volume_milliliter_unit"
|
||||
android:textAlignment="center" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/steps_background"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
tools:src="@drawable/ic_outline_hexagon_24"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintDimensionRatio="2:1"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<!-- Unused Currently -->
|
||||
<!-- <com.google.android.material.card.MaterialCardView-->
|
||||
<!-- style="?attr/materialCardViewFilledStyle"-->
|
||||
@ -153,9 +258,8 @@
|
||||
style="?attr/materialCardViewFilledStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp">
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginTop="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -164,7 +268,8 @@
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="54dp"
|
||||
android:layout_marginVertical="12dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
|
@ -2,4 +2,5 @@
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/vector_logo_background"/>
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
||||
|
@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
Before Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 8.8 KiB |
Before Width: | Height: | Size: 13 KiB |
@ -170,7 +170,7 @@
|
||||
app:destination="@id/nav_list_weight" />
|
||||
<action
|
||||
android:id="@+id/action_nav_browse_to_stepsHomeFragment"
|
||||
app:destination="@id/stepsHomeFragment" />
|
||||
app:destination="@id/nav_steps_home" />
|
||||
</fragment>
|
||||
|
||||
|
||||
@ -180,7 +180,7 @@
|
||||
android:label="@string/menu_activity"
|
||||
tools:layout="@layout/fragment_activity" />
|
||||
<fragment
|
||||
android:id="@+id/stepsHomeFragment"
|
||||
android:id="@+id/nav_steps_home"
|
||||
android:name="com.dzeio.openhealth.ui.steps.StepsHomeFragment"
|
||||
android:label="@string/menu_steps"
|
||||
tools:layout="@layout/fragment_steps_home" />
|
||||
|
@ -47,4 +47,7 @@
|
||||
<string name="report_email">Envoyer par Email</string>
|
||||
<string name="report_github">Envoyer depuis Github</string>
|
||||
<string name="quit">Quitter</string>
|
||||
<string name="steps_taken">Pas pris</string>
|
||||
<string name="error_reporter_crash">Erreur lors de la géneration d\'un rapport d\'erreur</string>
|
||||
|
||||
</resources>
|
||||
|
@ -1,3 +1,4 @@
|
||||
<resources>
|
||||
<style name="Theme.OpenHealth" parent="Theme.Material3.DynamicColors.DayNight" />
|
||||
|
||||
</resources>
|
@ -59,4 +59,6 @@
|
||||
<string name="report_github">Report on Github</string>
|
||||
<string name="report_email">Report via Email</string>
|
||||
<string name="quit">Quit</string>
|
||||
<string name="steps_taken">Steps taken</string>
|
||||
<string name="error_reporter_crash">An error occurred while making the error report</string>
|
||||
</resources>
|
||||
|
@ -1,18 +1,10 @@
|
||||
<resources>
|
||||
|
||||
<style name="Theme.OpenHealth" parent="Theme.Material3.DayNight.NoActionBar">
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
</style>
|
||||
<style name="Theme.OpenHealth" parent="Theme.Material3.DynamicColors.DayNight" />
|
||||
|
||||
<style name="Theme.OpenHealth.NoActionBar" parent="Theme.OpenHealth">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
</style>
|
||||
|
||||
<style name="ShapeAppearance.OpenHealth.Corner.Medium" parent="">
|
||||
<item name="cornerFamily">rounded</item>
|
||||
<item name="cornerSize">16dp</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.OpenHealth.SplashScreen" parent="Theme.OpenHealth.NoActionBar">
|
||||
|
5
app/src/main/res/xml/locales.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<locale android:name="en"/>
|
||||
<locale android:name="fr"/>
|
||||
</locale-config>
|
@ -10,7 +10,7 @@
|
||||
android:title="Gender" />
|
||||
|
||||
<ListPreference
|
||||
android:key="global_language"
|
||||
android:key="com.dzeio.open-health.app.language"
|
||||
android:title="@string/languages" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="Weight Settings">
|
||||
|