From 816d60b6ce910b83cacd76ba0e21048daa397b8d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 13 Jun 2024 17:42:22 +0200 Subject: [PATCH] Move rageshake configuration from resource file to Kotlin RageshakeConfig --- .idea/dictionaries/shared.xml | 1 + .../android/appconfig/RageshakeConfig.kt | 22 ++++++++++++++ .../impl/reporter/DefaultBugReporter.kt | 4 +-- .../reporter/DefaultBugReporterUrlProvider.kt | 6 ++-- .../impl/src/main/res/values/strings.xml | 29 ------------------- .../DefaultBugReporterUrlProviderTest.kt | 6 ++-- 6 files changed, 30 insertions(+), 38 deletions(-) create mode 100644 appconfig/src/main/kotlin/io/element/android/appconfig/RageshakeConfig.kt delete mode 100644 features/rageshake/impl/src/main/res/values/strings.xml diff --git a/.idea/dictionaries/shared.xml b/.idea/dictionaries/shared.xml index 01db2cef83..e7bc929689 100644 --- a/.idea/dictionaries/shared.xml +++ b/.idea/dictionaries/shared.xml @@ -13,6 +13,7 @@ onboarding placeables posthog + rageshake securebackup showkase snackbar diff --git a/appconfig/src/main/kotlin/io/element/android/appconfig/RageshakeConfig.kt b/appconfig/src/main/kotlin/io/element/android/appconfig/RageshakeConfig.kt new file mode 100644 index 0000000000..c44f64e43d --- /dev/null +++ b/appconfig/src/main/kotlin/io/element/android/appconfig/RageshakeConfig.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.appconfig + +object RageshakeConfig { + const val BUG_REPORT_URL = "https://riot.im/bugreports/submit" + const val BUG_REPORT_APP_NAME = "element-x-android" +} diff --git a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporter.kt b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporter.kt index b4e8a2effb..930f12d343 100755 --- a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporter.kt +++ b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporter.kt @@ -22,11 +22,11 @@ import androidx.core.net.toFile import androidx.core.net.toUri import com.squareup.anvil.annotations.ContributesBinding import io.element.android.appconfig.ApplicationConfig +import io.element.android.appconfig.RageshakeConfig import io.element.android.features.rageshake.api.crash.CrashDataStore import io.element.android.features.rageshake.api.reporter.BugReporter import io.element.android.features.rageshake.api.reporter.BugReporterListener import io.element.android.features.rageshake.api.screenshot.ScreenshotHolder -import io.element.android.features.rageshake.impl.R import io.element.android.libraries.androidutils.file.compressFile import io.element.android.libraries.androidutils.file.safeDelete import io.element.android.libraries.core.coroutine.CoroutineDispatchers @@ -139,7 +139,7 @@ class DefaultBugReporter @Inject constructor( // build the multi part request val builder = BugReporterMultipartBody.Builder() .addFormDataPart("text", bugDescription) - .addFormDataPart("app", context.getString(R.string.bug_report_app_name)) + .addFormDataPart("app", RageshakeConfig.BUG_REPORT_APP_NAME) .addFormDataPart("user_agent", userAgentProvider.provide()) .addFormDataPart("user_id", userId?.toString() ?: "undefined") .addFormDataPart("can_contact", canContact.toString()) diff --git a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporterUrlProvider.kt b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporterUrlProvider.kt index 5907a9a1c9..ff54a6a200 100644 --- a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporterUrlProvider.kt +++ b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporterUrlProvider.kt @@ -17,18 +17,16 @@ package io.element.android.features.rageshake.impl.reporter import com.squareup.anvil.annotations.ContributesBinding -import io.element.android.features.rageshake.impl.R +import io.element.android.appconfig.RageshakeConfig import io.element.android.libraries.di.AppScope -import io.element.android.services.toolbox.api.strings.StringProvider import okhttp3.HttpUrl import okhttp3.HttpUrl.Companion.toHttpUrl import javax.inject.Inject @ContributesBinding(AppScope::class) class DefaultBugReporterUrlProvider @Inject constructor( - private val stringProvider: StringProvider ) : BugReporterUrlProvider { override fun provide(): HttpUrl { - return stringProvider.getString(R.string.bug_report_url).toHttpUrl() + return RageshakeConfig.BUG_REPORT_URL.toHttpUrl() } } diff --git a/features/rageshake/impl/src/main/res/values/strings.xml b/features/rageshake/impl/src/main/res/values/strings.xml deleted file mode 100644 index dc1069570b..0000000000 --- a/features/rageshake/impl/src/main/res/values/strings.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - https://riot.im/bugreports/submit - - element-x-android - - - diff --git a/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporterUrlProviderTest.kt b/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporterUrlProviderTest.kt index a5c36df185..dae0b16bcc 100644 --- a/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporterUrlProviderTest.kt +++ b/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporterUrlProviderTest.kt @@ -17,15 +17,15 @@ package io.element.android.features.rageshake.impl.reporter import com.google.common.truth.Truth.assertThat -import io.element.android.services.toolbox.test.strings.FakeStringProvider +import io.element.android.appconfig.RageshakeConfig import okhttp3.HttpUrl.Companion.toHttpUrl import org.junit.Test class DefaultBugReporterUrlProviderTest { @Test fun `test DefaultBugReporterUrlProvider`() { - val sut = DefaultBugReporterUrlProvider(FakeStringProvider("https://example.org")) + val sut = DefaultBugReporterUrlProvider() val result = sut.provide() - assertThat(result).isEqualTo("https://example.org".toHttpUrl()) + assertThat(result).isEqualTo(RageshakeConfig.BUG_REPORT_URL.toHttpUrl()) } }