diff --git a/platform/jvm/gradle-test-app/build.gradle.kts b/platform/jvm/gradle-test-app/build.gradle.kts index 1399e746..4c525292 100644 --- a/platform/jvm/gradle-test-app/build.gradle.kts +++ b/platform/jvm/gradle-test-app/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { implementation("androidx.constraintlayout:constraintlayout:2.1.4") implementation("androidx.navigation:navigation-fragment-ktx:2.5.3") implementation("androidx.navigation:navigation-ui-ktx:2.5.3") + implementation("androidx.preference:preference-ktx:1.2.1") implementation("com.apollographql.apollo3:apollo-runtime:3.8.3") implementation("com.apollographql.apollo3:apollo-runtime:3.8.3") implementation("com.jakewharton.timber:timber:5.0.1") diff --git a/platform/jvm/gradle-test-app/src/androidTest/java/io/bitdrift/gradletestapp/AndroidViewReplayTest.kt b/platform/jvm/gradle-test-app/src/androidTest/java/io/bitdrift/gradletestapp/AndroidViewReplayTest.kt index f2d6b454..0785936b 100644 --- a/platform/jvm/gradle-test-app/src/androidTest/java/io/bitdrift/gradletestapp/AndroidViewReplayTest.kt +++ b/platform/jvm/gradle-test-app/src/androidTest/java/io/bitdrift/gradletestapp/AndroidViewReplayTest.kt @@ -61,8 +61,8 @@ class AndroidViewReplayTest { assertThat(metrics.errorViewCount).isEqualTo(0) assertThat(metrics.exceptionCausingViewCount).isEqualTo(0) // AppCompatTextView multiline label - assertThat(screen).contains(ReplayRect(type = ReplayType.Label, x = 36, y = 235, width = 758, height = 47)) - assertThat(screen).contains(ReplayRect(type = ReplayType.Label, x = 36, y = 277, width = 698, height = 38)) + assertThat(screen).contains(ReplayRect(type = ReplayType.Label, x = 36, y = 421, width = 758, height = 47)) + assertThat(screen).contains(ReplayRect(type = ReplayType.Label, x = 36, y = 463, width = 698, height = 38)) } } } diff --git a/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/BitdriftInit.java b/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/BitdriftInit.java index a080efae..c999d88e 100644 --- a/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/BitdriftInit.java +++ b/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/BitdriftInit.java @@ -20,7 +20,7 @@ import okhttp3.HttpUrl; public class BitdriftInit { - public static void initBitdriftCaptureInJava() { + public static void initBitdriftCaptureInJava(HttpUrl apiUrl, String apiKey) { String userID = UUID.randomUUID().toString(); List fieldProviders = new ArrayList<>(); fieldProviders.add(() -> { @@ -30,12 +30,12 @@ public static void initBitdriftCaptureInJava() { }); Capture.Logger.start( - "", + apiKey, new SessionStrategy.Fixed(), new Configuration(), fieldProviders, null, - HttpUrl.get("https://api.bitdrift.io") + apiUrl ); } } diff --git a/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/ConfigurationSettingsFragment.kt b/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/ConfigurationSettingsFragment.kt new file mode 100644 index 00000000..4977feb4 --- /dev/null +++ b/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/ConfigurationSettingsFragment.kt @@ -0,0 +1,61 @@ +// capture-sdk - bitdrift's client SDK +// Copyright Bitdrift, Inc. All rights reserved. +// +// Use of this source code is governed by a source available license that can be found in the +// LICENSE file or at: +// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt + +package io.bitdrift.gradletestapp + +import android.content.Intent +import android.content.pm.PackageManager +import android.os.Bundle +import androidx.preference.EditTextPreference +import androidx.preference.Preference +import androidx.preference.PreferenceCategory +import androidx.preference.PreferenceFragmentCompat +import kotlin.system.exitProcess + +class ConfigurationSettingsFragment : PreferenceFragmentCompat() { + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + val context = preferenceManager.context + val screen = preferenceManager.createPreferenceScreen(context) + + val backendCategory = PreferenceCategory(context) + backendCategory.key = "control_plane_category" + backendCategory.title = "Control Plane Configuration" + + screen.addPreference(backendCategory) + + val apiUrlPref = EditTextPreference(context) + apiUrlPref.key = "apiUrl" + apiUrlPref.title = "API URL" + apiUrlPref.summary = "App needs to be restarted for changes to take effect" + + backendCategory.addPreference(apiUrlPref) + + val apiKeyPref = EditTextPreference(context) + apiKeyPref.key = "apiKey" + apiKeyPref.title = "API Key" + apiKeyPref.summary = "App needs to be restarted for changes to take effect" + + backendCategory.addPreference(apiKeyPref) + + val restartPreference = Preference(context) + restartPreference.key = "restart" + restartPreference.title = "Restart the App" + restartPreference.setOnPreferenceClickListener { + val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName) + val restartIntent = Intent.makeRestartActivityTask(launchIntent!!.component) + // Required for API 34 and later + // Ref: https://developer.android.com/about/versions/14/behavior-changes-14#safer-intents + restartIntent.setPackage(context.packageName); + context.startActivity(restartIntent) + exitProcess(0) + } + + screen.addPreference(restartPreference) + + preferenceScreen = screen + } +} diff --git a/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/FirstFragment.kt b/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/FirstFragment.kt index 9379f24d..0cb96736 100644 --- a/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/FirstFragment.kt +++ b/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/FirstFragment.kt @@ -100,7 +100,11 @@ class FirstFragment : Fragment() { setContent { // In Compose world MaterialTheme { - Text("Hello from Compose!") + Text( + text = "Text in Compose", + style = MaterialTheme.typography.h6, + color = MaterialTheme.colors.secondary, + ) } } } @@ -110,6 +114,9 @@ class FirstFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + binding.btnNavigateConfiguration.setOnClickListener { + findNavController().navigate(R.id.action_FirstFragment_to_ConfigFragment) + } binding.btnCopySessionUrl.setOnClickListener(this::copySessionUrl) binding.btnStartNewSession.setOnClickListener(this::startNewSession) binding.btnTempDeviceCode.setOnClickListener(this::getTempDeviceCode) diff --git a/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/GradleTestApp.kt b/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/GradleTestApp.kt index 69a1ce5d..768e6410 100644 --- a/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/GradleTestApp.kt +++ b/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/GradleTestApp.kt @@ -48,12 +48,14 @@ import android.os.Build import android.os.Bundle import android.util.Log import androidx.core.content.ContextCompat +import androidx.preference.PreferenceManager import io.bitdrift.capture.Capture import io.bitdrift.capture.Capture.Logger.sessionUrl import io.bitdrift.capture.LogLevel import io.bitdrift.capture.events.span.Span import io.bitdrift.capture.events.span.SpanResult import io.bitdrift.capture.timber.CaptureTree +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import papa.AppLaunchType import papa.PapaEvent import papa.PapaEventListener @@ -81,7 +83,14 @@ class GradleTestApp : Application() { } private fun initLogging() { - BitdriftInit.initBitdriftCaptureInJava() + val prefs = PreferenceManager.getDefaultSharedPreferences(this) + val stringApiUrl = prefs.getString("apiUrl", null) + val apiUrl = stringApiUrl?.toHttpUrlOrNull() + if (apiUrl == null) { + Log.e("GradleTestApp", "Failed to initialize bitdrift logger due to invalid API URL: $stringApiUrl") + return + } + BitdriftInit.initBitdriftCaptureInJava(apiUrl, prefs.getString("apiKey", "")) // Timber if (BuildConfig.DEBUG) { Timber.plant(Timber.DebugTree()) diff --git a/platform/jvm/gradle-test-app/src/main/res/layout/fragment_first.xml b/platform/jvm/gradle-test-app/src/main/res/layout/fragment_first.xml index b57783af..6061c6c3 100644 --- a/platform/jvm/gradle-test-app/src/main/res/layout/fragment_first.xml +++ b/platform/jvm/gradle-test-app/src/main/res/layout/fragment_first.xml @@ -11,6 +11,14 @@ tools:context=".FirstFragment" > +