Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(env var): class for read env var #6

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/src/main/java/com/eipsaferoad/owl/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ import androidx.wear.ambient.AmbientLifecycleObserver
import androidx.wear.ambient.AmbientModeSupport
import androidx.wear.ambient.AmbientModeSupport.AmbientCallback
import androidx.wear.compose.material.MaterialTheme
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.TimeText
import com.eipsaferoad.owl.heartRate.HeartRateService
import com.eipsaferoad.owl.presentation.ComposableFun
import com.eipsaferoad.owl.presentation.PagesEnum
import com.eipsaferoad.owl.presentation.home.Home
import com.eipsaferoad.owl.presentation.login.Login
import com.eipsaferoad.owl.presentation.theme.OwlTheme
import com.eipsaferoad.owl.utils.ReadEnvVar
import com.google.android.gms.wearable.CapabilityClient
import com.google.android.gms.wearable.CapabilityInfo
import com.google.android.gms.wearable.DataClient
Expand Down Expand Up @@ -76,6 +78,7 @@ class MainActivity : ComponentActivity(),
filter.addAction("updateHR")
registerReceiver(broadcastReceiver, filter)
setTheme(android.R.style.Theme_DeviceDefault)
val apiUrl = ReadEnvVar.readEnvVar(this, ReadEnvVar.EnvVar.API_URL)
setContent {
WearApp(bpm.value)
}
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/eipsaferoad/owl/utils/ReadEnvVar.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.eipsaferoad.owl.utils

import android.content.Context
import android.util.Log
import com.eipsaferoad.owl.R

class ReadEnvVar {

enum class EnvVar(val str: String) {
API_URL("API_URL")
}

companion object {
fun readEnvVar(context: Context, name: EnvVar): String {
if (vars.containsKey(name))
return vars[name].toString()
val data = context.resources.getString(R.string.api_url)
vars[name] = data
return data
}
private val vars: MutableMap<EnvVar, String> = mutableMapOf()
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values-round/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="hello_world">From the Round world,\nHello, %1$s!</string>
<string name="api_url">http://35.180.167.90:5000</string>
</resources>
6 changes: 1 addition & 5 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<resources>
<string name="app_name">owl</string>
<!--
This string is used for square devices and overridden by hello_world in
values-round/strings.xml for round devices.
-->
<string name="hello_world">From the Square world,\nHello, %1$s!</string>
<string name="api_url">http://35.180.167.90:5000</string>
</resources>
Loading