Skip to content

Commit

Permalink
Update to radar-commons-android 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
blootsvoets committed Oct 12, 2020
1 parent 554cea0 commit eb5aa55
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 103 deletions.
34 changes: 14 additions & 20 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ android {
applicationId 'org.radarcns.detail'
minSdkVersion 21
targetSdkVersion 29
versionCode 42
versionName '1.0.3'
versionCode 45
versionName '1.0.6'
manifestPlaceholders = ['appAuthRedirectScheme': 'org.radarbase.passive.app']
multiDexEnabled true
// Comment the next line out for x86 emulator support. In that case, disable the Empatica plugin.
ndk { abiFilters "armeabi", "armeabi-v7a" }
}
lintOptions {
abortOnError false
Expand Down Expand Up @@ -59,21 +57,24 @@ repositories {
maven { url 'https://repo.thehyve.nl/content/repositories/snapshots' }
}

ext.radarCommonsVersion = '1.0.0-alpha3'
ext.radarCommonsVersion = '1.0.0'

dependencies {
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
api "org.radarbase:radar-commons-android:$radarCommonsVersion"

implementation "org.radarbase:radar-android-login-qr:$radarCommonsVersion"
implementation 'com.google.firebase:firebase-core:17.4.3'
implementation 'com.google.firebase:firebase-config:19.1.4'
implementation 'com.google.firebase:firebase-core:17.5.1'
implementation 'com.google.firebase:firebase-config:19.2.0'
implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

implementation 'org.slf4j:slf4j-api:1.7.30'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'sk.baka.slf4j:slf4j-handroid:1.7.31'

implementation 'com.google.firebase:firebase-crashlytics:17.2.2'
implementation 'com.google.firebase:firebase-analytics:17.6.0'

implementation 'sk.baka.slf4j:slf4j-handroid:1.7.32'

implementation "org.radarbase:radar-android-phone:$radarCommonsVersion"
implementation "org.radarbase:radar-android-phone-usage:$radarCommonsVersion"
Expand All @@ -86,25 +87,18 @@ dependencies {
implementation "org.radarbase:radar-android-ppg:$radarCommonsVersion"

implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'

testImplementation 'junit:junit:4.13'
testRuntimeOnly 'org.slf4j:slf4j-simple:1.7.30'
}

tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

kotlinOptions {
jvmTarget = '1.8'
apiVersion = '1.3'
languageVersion = '1.3'
apiVersion = '1.4'
languageVersion = '1.4'
}
}

Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/org/radarcns/detail/InfoActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ class InfoActivity : AppCompatActivity() {

findViewById<TextView>(R.id.app_name).setText(R.string.app_name)
findViewById<TextView>(R.id.version).text = BuildConfig.VERSION_NAME
findViewById<TextView>(R.id.server_base_url).text = radarConfig.getString(BASE_URL_KEY, "")

policyUrl = radarConfig.optString(PRIVACY_POLICY)
radarConfig.config.observe(this, { config ->
findViewById<TextView>(R.id.server_base_url).text = config.getString(BASE_URL_KEY, "")

if (policyUrl == null) {
findViewById<TextView>(R.id.privacyStatement).apply {
visibility = View.GONE
policyUrl = config.optString(PRIVACY_POLICY)

if (policyUrl == null) {
findViewById<TextView>(R.id.privacyStatement).apply {
visibility = View.GONE
}
}
}
})

setSupportActionBar(findViewById<Toolbar>(R.id.toolbar).apply {
setTitle(R.string.info)
Expand Down
35 changes: 15 additions & 20 deletions app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import android.view.ViewGroup
import android.widget.*
import android.widget.LinearLayout.VERTICAL
import androidx.fragment.app.Fragment
import com.crashlytics.android.Crashlytics
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.remoteconfig.FirebaseRemoteConfigException
import kotlinx.android.synthetic.main.activity_login.*
Expand Down Expand Up @@ -123,14 +122,12 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne
}

private fun applyMpManager(callback: (AuthService.AuthServiceBinder, ManagementPortalLoginManager, AppAuthState) -> Unit) {
authConnection.applyBinder { auth ->
auth.managers.find { it is ManagementPortalLoginManager }
?.let { it as ManagementPortalLoginManager }
?.also { manager ->
auth.applyState { authState ->
callback(auth, manager, authState)
}
}
authConnection.applyBinder {
val manager = managers.find { it is ManagementPortalLoginManager }
as? ManagementPortalLoginManager ?: return@applyBinder
applyState {
callback(this@applyBinder, manager, this)
}
}
}

Expand Down Expand Up @@ -198,9 +195,6 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne
onDoneProcessing()
runOnUiThread {
if (authState.isPrivacyPolicyAccepted) {
val firebase = FirebaseAnalytics.getInstance(this)
firebase.setUserProperty(USER_ID_KEY, authState.userId)
firebase.setUserProperty(PROJECT_ID_KEY, authState.projectId)
super.loginSucceeded(manager, authState)
if (!didCreate) {
overridePendingTransition(0, 0)
Expand All @@ -223,8 +217,7 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne
val fragment = PrivacyPolicyFragment.newInstance(this, state)
createFragmentLayout(R.id.privacy_policy_fragment, fragment)
} catch (ex: IllegalStateException) {
logger.error("Failed to start privacy policy fragment:" + " is LoginActivity is already closed?", ex)
Crashlytics.logException(ex)
logger.error("Failed to start privacy policy fragment: is LoginActivity is already closed?", ex)
}

}
Expand All @@ -240,13 +233,13 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne
}

override fun onAcceptPrivacyPolicy() {
authConnection.applyBinder { binder ->
binder.updateState {
authConnection.applyBinder {
updateState {
isPrivacyPolicyAccepted = true
}
binder.applyState {
logger.info("Updating privacyPolicyAccepted {}", it)
super.loginSucceeded(null, it)
applyState {
logger.info("Updating privacyPolicyAccepted {}", this)
super.loginSucceeded(null, this)
}
}
}
Expand All @@ -255,7 +248,9 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne
val baseUrlInput = EditText(this).apply {
inputType = InputType.TYPE_CLASS_TEXT
setCompoundDrawables(TextDrawable(this, "https://"), null, null, null)
setText(radarConfig.getString(BASE_URL_KEY, ""))
radarConfig.config.observe(this@LoginActivityImpl, {
setText(it.getString(BASE_URL_KEY, ""))
})
}
val tokenInput = EditText(this).apply {
inputType = InputType.TYPE_CLASS_TEXT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.widget.Toast
import com.crashlytics.android.Crashlytics
import com.google.firebase.crashlytics.FirebaseCrashlytics
import org.radarbase.android.util.Boast

/**
Expand All @@ -42,6 +42,6 @@ class MainActivityBootStarter : BroadcastReceiver() {
private fun startApp(context: Context) {
context.packageManager.getLaunchIntentForPackage(context.packageName)?.also {
context.startActivity(it)
} ?: Crashlytics.logException(IllegalStateException("Cannot start RADAR app ${context.packageName} without launch intent"))
} ?: FirebaseCrashlytics.getInstance().recordException(IllegalStateException("Cannot start RADAR app ${context.packageName} without launch intent"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class PrivacyPolicyFragment : Fragment() {
putString(USER_ID_KEY, state.userId)
putString(BASE_URL_PROPERTY, state.getAttribute(BASE_URL_PROPERTY))
putString(PRIVACY_POLICY_URL_PROPERTY, state.getAttribute(PRIVACY_POLICY_URL_PROPERTY))
putString(PRIVACY_POLICY, context.radarConfig.optString(PRIVACY_POLICY))
putString(PRIVACY_POLICY, context.radarConfig.latestConfig.optString(PRIVACY_POLICY))
}
}
}
Expand Down
24 changes: 17 additions & 7 deletions app/src/main/java/org/radarcns/detail/RadarApplicationImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.SystemClock
import com.crashlytics.android.Crashlytics
import com.google.firebase.analytics.FirebaseAnalytics
import org.radarbase.android.FirebaseRadarConfiguration
import com.google.firebase.crashlytics.FirebaseCrashlytics
import org.radarbase.android.AbstractRadarApplication
import org.radarbase.android.RadarApplication
import org.radarbase.android.RadarConfiguration
import org.radarbase.android.config.AppConfigRadarConfiguration
import org.radarbase.android.config.FirebaseRemoteConfiguration
import org.radarbase.android.config.RemoteConfig
import org.slf4j.LoggerFactory
import org.slf4j.impl.HandroidLoggerAdapter
import kotlin.system.exitProcess

/**
* Radar application class for the detailed application.
*/
class RadarApplicationImpl : RadarApplication() {
class RadarApplicationImpl : AbstractRadarApplication() {
fun enableCrashProcessing() {
val defaultHandler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
Expand All @@ -43,7 +47,8 @@ class RadarApplicationImpl : RadarApplication() {
putExtra("crash", true)
}
if (intent == null) {
Crashlytics.logException(IllegalStateException("Cannot find launch intent for app"))
FirebaseCrashlytics.getInstance()
.recordException(IllegalStateException("Cannot find launch intent for app"))
return@setDefaultUncaughtExceptionHandler
}

Expand All @@ -52,7 +57,7 @@ class RadarApplicationImpl : RadarApplication() {
.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 100, pendingIntent)

defaultHandler?.uncaughtException(thread, throwable)
System.exit(2)
exitProcess(2)
}
}

Expand All @@ -66,12 +71,17 @@ class RadarApplicationImpl : RadarApplication() {

override val smallIcon = R.drawable.ic_bt_connected

override fun createRemoteConfiguration(): List<RemoteConfig> = listOf(
FirebaseRemoteConfiguration(this, BuildConfig.DEBUG, R.xml.remote_config_defaults),
AppConfigRadarConfiguration(this)
)


override fun createConfiguration(): RadarConfiguration {
FirebaseAnalytics.getInstance(this).apply {
setUserProperty(TEST_PHASE, if (BuildConfig.DEBUG) "dev" else "production")
}

return FirebaseRadarConfiguration(this, true, R.xml.remote_config_defaults).apply {
return super.createConfiguration().apply {
fetch()
}
}
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/org/radarcns/detail/RadarServiceImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.radarcns.detail
import android.Manifest.permission.RECEIVE_BOOT_COMPLETED
import android.os.Build
import org.radarbase.android.RadarService
import org.radarbase.android.config.SingleRadarConfiguration
import org.radarbase.android.source.SourceProvider
import org.radarbase.monitor.application.ApplicationStatusProvider
import org.radarbase.passive.audio.OpenSmileAudioProvider
Expand Down Expand Up @@ -59,8 +60,8 @@ class RadarServiceImpl : RadarService() {
}
}

override fun doConfigure() {
super.doConfigure()
configureRunAtBoot(MainActivityBootStarter::class.java)
override fun doConfigure(config: SingleRadarConfiguration) {
super.doConfigure(config)
configureRunAtBoot(config, MainActivityBootStarter::class.java)
}
}
26 changes: 10 additions & 16 deletions app/src/main/java/org/radarcns/detail/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package org.radarcns.detail
import android.app.AlertDialog
import android.os.Bundle
import android.view.View
import android.widget.Switch
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SwitchCompat
import androidx.appcompat.widget.Toolbar
import org.radarbase.android.RadarApplication.Companion.radarConfig
import org.radarbase.android.RadarConfiguration

class SettingsActivity : AppCompatActivity() {
private lateinit var enableDataButton: Switch
private lateinit var enableDataPriorityButton: Switch
private lateinit var config: RadarConfiguration

override fun onCreate(bundle: Bundle?) {
Expand All @@ -27,27 +25,24 @@ class SettingsActivity : AppCompatActivity() {
setDisplayHomeAsUpEnabled(true)
}

enableDataButton = findViewById(R.id.enableDataSwitch)
val enableDataButton: SwitchCompat = findViewById(R.id.enableDataSwitch)
enableDataButton.setOnCheckedChangeListener { _, isChecked ->
config.put(RadarConfiguration.SEND_ONLY_WITH_WIFI, !isChecked)
config.persistChanges()
enableDataPriorityButton.isEnabled = isChecked
}
enableDataPriorityButton = findViewById(R.id.enableDataHighPrioritySwitch)
val enableDataPriorityButton: SwitchCompat = findViewById(R.id.enableDataHighPrioritySwitch)
enableDataPriorityButton.setOnCheckedChangeListener { _, isChecked ->
config.put(RadarConfiguration.SEND_OVER_DATA_HIGH_PRIORITY, isChecked)
config.persistChanges()
}
}

override fun onStart() {
super.onStart()
updateView()
}

private fun updateView() {
enableDataButton.isChecked = !config.getBoolean(RadarConfiguration.SEND_ONLY_WITH_WIFI, RadarConfiguration.SEND_ONLY_WITH_WIFI_DEFAULT)
enableDataPriorityButton.isChecked = config.getBoolean(RadarConfiguration.SEND_OVER_DATA_HIGH_PRIORITY, RadarConfiguration.SEND_ONLY_WITH_WIFI_DEFAULT)
config.config.observe(this, { config ->
val useData = !config.getBoolean(RadarConfiguration.SEND_ONLY_WITH_WIFI, true)
val useHighPriority = config.getBoolean(RadarConfiguration.SEND_OVER_DATA_HIGH_PRIORITY, false)
enableDataButton.isChecked = useData
enableDataPriorityButton.isEnabled = useData
enableDataPriorityButton.isChecked = useData && useHighPriority
})
}

fun startReset(@Suppress("UNUSED_PARAMETER") view: View) {
Expand All @@ -57,7 +52,6 @@ class SettingsActivity : AppCompatActivity() {
setIcon(android.R.drawable.ic_dialog_alert)
setPositiveButton(android.R.string.yes) { _, _ ->
config.reset(*MANAGED_SETTINGS)
updateView()
}
setNegativeButton(android.R.string.no, null)
}.show()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
app:layout_constraintBottom_toTopOf="@id/enableDataSwitch"
android:textColor="?attr/colorPrimaryDark"/>

<Switch
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/enableDataSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -43,7 +43,7 @@
app:layout_constraintTop_toBottomOf="@id/network_settings_header"
app:layout_constraintBottom_toTopOf="@id/enableDataHighPrioritySwitch"/>

<Switch
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/enableDataHighPrioritySwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
11 changes: 5 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.72'
ext.kotlin_version = '1.4.10'
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.android.tools.build:gradle:4.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.3.3'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'
classpath 'com.google.gms:google-services:4.3.4'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.3.0'
classpath 'com.google.android.gms:oss-licenses-plugin:0.10.2'
}
}

wrapper {
gradleVersion '6.4.1'
gradleVersion '6.6.1'
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Loading

0 comments on commit eb5aa55

Please sign in to comment.