diff --git a/.github/workflows/dependabot.yml b/.github/dependabot.yml similarity index 100% rename from .github/workflows/dependabot.yml rename to .github/dependabot.yml diff --git a/.gitignore b/.gitignore index cf226dd935..f6e1ef5b8b 100644 --- a/.gitignore +++ b/.gitignore @@ -82,3 +82,4 @@ lint/generated/ lint/outputs/ lint/tmp/ # lint/reports/ +/.idea/deploymentTargetDropDown.xml diff --git a/.idea/copyright/NewVector.xml b/.idea/copyright/NewVector.xml new file mode 100644 index 0000000000..72a4f2e779 --- /dev/null +++ b/.idea/copyright/NewVector.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000000..0875fcecb1 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/README.md b/README.md index 82cc63ea3b..caa8fff8ef 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,25 @@ Proof Of Concept to run a Matrix client on Android devices using the Matrix Rust Sdk and Jetpack compose. The plan is [here](https://github.com/vector-im/element-x-android-poc/issues/1)! + + +### Modules + +This Android project is a multi modules project. + +- `app` module is the Android application module. Other modules are libraries; +- `features` modules contain some UI and can be seen as screen of the application; +- `libraries` modules contain classes that can be useful for other modules to work. + +A few details about some modules: + +- `libraries-core` module contains utility classes; +- `libraries-designsystem` module contains Composables which can be used across the app (theme, etc.); +- `libraries-elementresources` module contains resource from Element Android (mainly strings); +- `libraries-matrix` module contains wrappers around the Matrix Rust SDK. + +Here is the current module dependency graph: + + + + diff --git a/anvilannotations/build.gradle.kts b/anvilannotations/build.gradle.kts index 80b108d11f..d7974f5643 100644 --- a/anvilannotations/build.gradle.kts +++ b/anvilannotations/build.gradle.kts @@ -1,7 +1,25 @@ +/* + * Copyright (c) 2022 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. + */ + +// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed +@Suppress("DSL_SCOPE_VIOLATION") plugins { alias(libs.plugins.kotlin.jvm) } dependencies { api(libs.inject) -} \ No newline at end of file +} diff --git a/anvilannotations/src/main/java/io/element/android/x/anvilannotations/ContributesViewModel.kt b/anvilannotations/src/main/java/io/element/android/x/anvilannotations/ContributesViewModel.kt index e8fdc272c9..0695e93263 100644 --- a/anvilannotations/src/main/java/io/element/android/x/anvilannotations/ContributesViewModel.kt +++ b/anvilannotations/src/main/java/io/element/android/x/anvilannotations/ContributesViewModel.kt @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022 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.x.anvilannotations import kotlin.reflect.KClass @@ -14,4 +30,4 @@ import kotlin.reflect.KClass @Target(AnnotationTarget.CLASS) annotation class ContributesViewModel( val scope: KClass<*>, -) \ No newline at end of file +) diff --git a/anvilcodegen/build.gradle.kts b/anvilcodegen/build.gradle.kts index d915eb3711..da817a5edb 100644 --- a/anvilcodegen/build.gradle.kts +++ b/anvilcodegen/build.gradle.kts @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2022 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. + */ + +// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed +@Suppress("DSL_SCOPE_VIOLATION") plugins { alias(libs.plugins.kotlin.jvm) alias(libs.plugins.kapt) @@ -7,8 +25,8 @@ dependencies { implementation(project(":anvilannotations")) api(libs.anvil.compiler.api) implementation(libs.anvil.compiler.utils) - implementation("com.squareup:kotlinpoet:1.10.2") + implementation("com.squareup:kotlinpoet:1.12.0") implementation(libs.dagger) compileOnly("com.google.auto.service:auto-service-annotations:1.0.1") kapt("com.google.auto.service:auto-service:1.0.1") -} \ No newline at end of file +} diff --git a/anvilcodegen/src/main/java/io/element/android/x/anvilcodegen/ContributesViewModelCodeGenerator.kt b/anvilcodegen/src/main/java/io/element/android/x/anvilcodegen/ContributesViewModelCodeGenerator.kt index a72d10ab84..e84d6cdd5f 100644 --- a/anvilcodegen/src/main/java/io/element/android/x/anvilcodegen/ContributesViewModelCodeGenerator.kt +++ b/anvilcodegen/src/main/java/io/element/android/x/anvilcodegen/ContributesViewModelCodeGenerator.kt @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022 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. + */ + @file:OptIn(ExperimentalAnvilApi::class) package io.element.android.x.anvilcodegen @@ -31,10 +47,10 @@ import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import dagger.multibindings.IntoMap import io.element.android.x.anvilannotations.ContributesViewModel +import java.io.File import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.KtFile -import java.io.File /** * This is an anvil plugin that allows ViewModels to use [ContributesViewModel] alone and let this plugin automatically @@ -69,7 +85,12 @@ class ContributesViewModelCodeGenerator : CodeGenerator { .returns(assistedViewModelFactoryFqName.asClassName(module).parameterizedBy(STAR, STAR)) .addAnnotation(Binds::class) .addAnnotation(IntoMap::class) - .addAnnotation(AnnotationSpec.Companion.builder(viewModelKeyFqName.asClassName(module)).addMember("%T::class", vmClass.asClassName()).build()) + .addAnnotation( + AnnotationSpec.Companion + .builder(viewModelKeyFqName.asClassName(module)) + .addMember("%T::class", vmClass.asClassName()) + .build() + ) .build(), ) .build(), diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0c4d93816c..d3ce5a7a78 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2022 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. + */ + +// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed +@Suppress("DSL_SCOPE_VIOLATION") plugins { id("io.element.android-compose-application") alias(libs.plugins.kotlin.android) @@ -136,12 +154,16 @@ knit { dependencies { implementation(project(":libraries:designsystem")) implementation(project(":libraries:matrix")) + implementation(project(":libraries:matrixui")) implementation(project(":libraries:core")) implementation(project(":libraries:architecture")) implementation(project(":features:onboarding")) implementation(project(":features:login")) + implementation(project(":features:logout")) implementation(project(":features:roomlist")) implementation(project(":features:messages")) + implementation(project(":features:rageshake")) + implementation(project(":features:preferences")) implementation(project(":libraries:di")) implementation(project(":anvilannotations")) anvil(project(":anvilcodegen")) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d32f0dca75..61a03241a1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,4 +1,20 @@ + + @@ -32,8 +48,6 @@ android:exported="false" tools:node="remove" /> - - diff --git a/app/src/main/java/io/element/android/x/ElementRootModule.kt b/app/src/main/java/io/element/android/x/ElementRootModule.kt index ea6e1e7f31..ab59ae72fe 100644 --- a/app/src/main/java/io/element/android/x/ElementRootModule.kt +++ b/app/src/main/java/io/element/android/x/ElementRootModule.kt @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022 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.x import com.airbnb.android.showkase.annotation.ShowkaseRoot diff --git a/app/src/main/java/io/element/android/x/ElementXApplication.kt b/app/src/main/java/io/element/android/x/ElementXApplication.kt index cc97438f31..f13ba5d070 100644 --- a/app/src/main/java/io/element/android/x/ElementXApplication.kt +++ b/app/src/main/java/io/element/android/x/ElementXApplication.kt @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022 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.x import android.app.Application @@ -9,8 +25,10 @@ import io.element.android.x.di.AppComponent import io.element.android.x.di.DaggerAppComponent import io.element.android.x.di.SessionComponentsOwner import io.element.android.x.initializer.CoilInitializer +import io.element.android.x.initializer.CrashInitializer import io.element.android.x.initializer.MatrixInitializer import io.element.android.x.initializer.MavericksInitializer +import io.element.android.x.initializer.TimberInitializer class ElementXApplication : Application(), DaggerComponentOwner { @@ -25,6 +43,8 @@ class ElementXApplication : Application(), DaggerComponentOwner { appComponent = DaggerAppComponent.factory().create(applicationContext) sessionComponentsOwner = bindings().sessionComponentsOwner() AppInitializer.getInstance(this).apply { + initializeComponent(CrashInitializer::class.java) + initializeComponent(TimberInitializer::class.java) initializeComponent(MatrixInitializer::class.java) initializeComponent(CoilInitializer::class.java) initializeComponent(MavericksInitializer::class.java) diff --git a/app/src/main/java/io/element/android/x/MainActivity.kt b/app/src/main/java/io/element/android/x/MainActivity.kt index 0baf53fafd..33eac75262 100644 --- a/app/src/main/java/io/element/android/x/MainActivity.kt +++ b/app/src/main/java/io/element/android/x/MainActivity.kt @@ -1,13 +1,23 @@ -@file:OptIn( - ExperimentalAnimationApi::class, - ExperimentalMaterialNavigationApi::class -) +/* + * Copyright (c) 2022 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.x import android.os.Bundle import androidx.activity.compose.setContent -import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface @@ -15,7 +25,6 @@ import androidx.compose.ui.Modifier import androidx.core.view.WindowCompat import com.bumble.appyx.core.integration.NodeHost import com.bumble.appyx.core.integrationpoint.NodeComponentActivity -import com.google.accompanist.navigation.material.ExperimentalMaterialNavigationApi import io.element.android.x.architecture.bindings import io.element.android.x.core.di.DaggerComponentOwner import io.element.android.x.designsystem.ElementXTheme diff --git a/app/src/main/java/io/element/android/x/MainViewModel.kt b/app/src/main/java/io/element/android/x/MainViewModel.kt deleted file mode 100644 index 0c498f3ab6..0000000000 --- a/app/src/main/java/io/element/android/x/MainViewModel.kt +++ /dev/null @@ -1,53 +0,0 @@ -package io.element.android.x - -import com.airbnb.mvrx.MavericksState -import com.airbnb.mvrx.MavericksViewModel -import com.airbnb.mvrx.MavericksViewModelFactory -import dagger.assisted.Assisted -import dagger.assisted.AssistedInject -import io.element.android.x.anvilannotations.ContributesViewModel -import io.element.android.x.architecture.viewmodel.daggerMavericksViewModelFactory -import io.element.android.x.di.AppScope -import io.element.android.x.di.SessionComponentsOwner -import io.element.android.x.matrix.Matrix -import kotlinx.coroutines.flow.first -import kotlinx.coroutines.launch - -data class MainState(val fake: Boolean = false) : MavericksState - -@ContributesViewModel(AppScope::class) -class MainViewModel @AssistedInject constructor( - private val matrix: Matrix, - private val sessionComponentsOwner: SessionComponentsOwner, - @Assisted initialState: MainState -) : MavericksViewModel(initialState) { - - companion object : - MavericksViewModelFactory by daggerMavericksViewModelFactory() - - suspend fun isLoggedIn(): Boolean { - return matrix.isLoggedIn().first() - } - - fun startSyncIfLogged() { - viewModelScope.launch { - if (!isLoggedIn()) return@launch - } - } - - fun stopSyncIfLogged() { - viewModelScope.launch { - if (!isLoggedIn()) return@launch - } - } - - suspend fun restoreSession() { - val matrixClient = matrix.restoreSession() - if (matrixClient == null) { - throw IllegalStateException("Couldn't restore session...") - } else { - sessionComponentsOwner.create(matrixClient) - matrixClient.startSync() - } - } -} diff --git a/app/src/main/java/io/element/android/x/di/AppBindings.kt b/app/src/main/java/io/element/android/x/di/AppBindings.kt index 73ae3bf846..f330346e80 100644 --- a/app/src/main/java/io/element/android/x/di/AppBindings.kt +++ b/app/src/main/java/io/element/android/x/di/AppBindings.kt @@ -1,14 +1,30 @@ +/* + * Copyright (c) 2022 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.x.di import com.squareup.anvil.annotations.ContributesTo import io.element.android.x.matrix.Matrix -import io.element.android.x.node.LoggedInFlowNode -import io.element.android.x.node.RootFlowNode +import io.element.android.x.matrix.ui.MatrixUi import kotlinx.coroutines.CoroutineScope @ContributesTo(AppScope::class) interface AppBindings { fun coroutineScope(): CoroutineScope fun matrix(): Matrix + fun matrixUi(): MatrixUi fun sessionComponentsOwner(): SessionComponentsOwner } diff --git a/app/src/main/java/io/element/android/x/di/AppComponent.kt b/app/src/main/java/io/element/android/x/di/AppComponent.kt index fb6e924672..3320a88218 100644 --- a/app/src/main/java/io/element/android/x/di/AppComponent.kt +++ b/app/src/main/java/io/element/android/x/di/AppComponent.kt @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022 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.x.di import android.content.Context diff --git a/app/src/main/java/io/element/android/x/di/AppModule.kt b/app/src/main/java/io/element/android/x/di/AppModule.kt index 681365aa9f..b8e703c775 100644 --- a/app/src/main/java/io/element/android/x/di/AppModule.kt +++ b/app/src/main/java/io/element/android/x/di/AppModule.kt @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022 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.x.di import com.squareup.anvil.annotations.ContributesTo @@ -17,4 +33,4 @@ object AppModule { fun providesAppCoroutineScope(): CoroutineScope { return MainScope() + CoroutineName("ElementX Scope") } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/element/android/x/di/SessionComponent.kt b/app/src/main/java/io/element/android/x/di/SessionComponent.kt index fd9ffb5078..15fd19a9d8 100644 --- a/app/src/main/java/io/element/android/x/di/SessionComponent.kt +++ b/app/src/main/java/io/element/android/x/di/SessionComponent.kt @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022 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.x.di import com.squareup.anvil.annotations.ContributesTo diff --git a/app/src/main/java/io/element/android/x/di/SessionComponentsOwner.kt b/app/src/main/java/io/element/android/x/di/SessionComponentsOwner.kt index f289573821..13b886e0a4 100644 --- a/app/src/main/java/io/element/android/x/di/SessionComponentsOwner.kt +++ b/app/src/main/java/io/element/android/x/di/SessionComponentsOwner.kt @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022 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.x.di import android.content.Context @@ -42,5 +58,4 @@ class SessionComponentsOwner @Inject constructor(@ApplicationContext private val activeSessionComponent = null } } - } diff --git a/app/src/main/java/io/element/android/x/initializer/CoilInitializer.kt b/app/src/main/java/io/element/android/x/initializer/CoilInitializer.kt index 9594328881..43d44ba867 100644 --- a/app/src/main/java/io/element/android/x/initializer/CoilInitializer.kt +++ b/app/src/main/java/io/element/android/x/initializer/CoilInitializer.kt @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022 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.x.initializer import android.content.Context @@ -19,22 +35,19 @@ class CoilInitializer : Initializer { private class ElementImageLoaderFactory( private val context: Context -) : - ImageLoaderFactory { +) : ImageLoaderFactory { override fun newImageLoader(): ImageLoader { return ImageLoader .Builder(context) .components { val appBindings = context.bindings() - val matrix = appBindings.matrix() + val matrixUi = appBindings.matrixUi() val matrixClientProvider = { appBindings .sessionComponentsOwner().activeSessionComponent?.matrixClient() } - matrix.registerCoilComponents(this, matrixClientProvider) + matrixUi.registerCoilComponents(this, matrixClientProvider) } .build() } - - } diff --git a/app/src/main/java/io/element/android/x/initializer/CrashInitializer.kt b/app/src/main/java/io/element/android/x/initializer/CrashInitializer.kt new file mode 100644 index 0000000000..df3dcacdbb --- /dev/null +++ b/app/src/main/java/io/element/android/x/initializer/CrashInitializer.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 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.x.initializer + +import android.content.Context +import androidx.startup.Initializer +import io.element.android.x.features.rageshake.crash.VectorUncaughtExceptionHandler + +class CrashInitializer : Initializer { + + override fun create(context: Context) { + VectorUncaughtExceptionHandler(context).activate() + } + + override fun dependencies(): List>> = emptyList() +} diff --git a/app/src/main/java/io/element/android/x/initializer/MatrixInitializer.kt b/app/src/main/java/io/element/android/x/initializer/MatrixInitializer.kt index 30bf700297..f071893d19 100644 --- a/app/src/main/java/io/element/android/x/initializer/MatrixInitializer.kt +++ b/app/src/main/java/io/element/android/x/initializer/MatrixInitializer.kt @@ -1,11 +1,26 @@ +/* + * Copyright (c) 2022 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.x.initializer import android.content.Context import androidx.startup.Initializer -import com.airbnb.mvrx.Mavericks +import io.element.android.x.BuildConfig import io.element.android.x.matrix.tracing.TracingConfigurations import io.element.android.x.matrix.tracing.setupTracing -import io.element.android.x.sdk.matrix.BuildConfig class MatrixInitializer : Initializer { @@ -19,5 +34,4 @@ class MatrixInitializer : Initializer { override fun dependencies(): List>> = listOf(TimberInitializer::class.java) - } diff --git a/app/src/main/java/io/element/android/x/initializer/MavericksInitializer.kt b/app/src/main/java/io/element/android/x/initializer/MavericksInitializer.kt index ff51aa1d60..f7d48b66c1 100644 --- a/app/src/main/java/io/element/android/x/initializer/MavericksInitializer.kt +++ b/app/src/main/java/io/element/android/x/initializer/MavericksInitializer.kt @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022 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.x.initializer import android.content.Context @@ -11,6 +27,4 @@ class MavericksInitializer : Initializer { } override fun dependencies(): List>> = listOf() - - -} \ No newline at end of file +} diff --git a/app/src/main/java/io/element/android/x/initializer/TimberInitializer.kt b/app/src/main/java/io/element/android/x/initializer/TimberInitializer.kt index ebb101cc59..10b7e17ffd 100644 --- a/app/src/main/java/io/element/android/x/initializer/TimberInitializer.kt +++ b/app/src/main/java/io/element/android/x/initializer/TimberInitializer.kt @@ -1,13 +1,34 @@ +/* + * Copyright (c) 2022 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.x.initializer import android.content.Context import androidx.startup.Initializer +import io.element.android.x.BuildConfig +import io.element.android.x.features.rageshake.logs.VectorFileLogger import timber.log.Timber class TimberInitializer : Initializer { override fun create(context: Context) { - Timber.plant(Timber.DebugTree()) + if (BuildConfig.DEBUG) { + Timber.plant(Timber.DebugTree()) + } + Timber.plant(VectorFileLogger(context)) } override fun dependencies(): List>> = emptyList() diff --git a/app/src/main/java/io/element/android/x/node/RootFlowNode.kt b/app/src/main/java/io/element/android/x/node/RootFlowNode.kt index a19e0f5a53..376f88cdb2 100644 --- a/app/src/main/java/io/element/android/x/node/RootFlowNode.kt +++ b/app/src/main/java/io/element/android/x/node/RootFlowNode.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -31,6 +32,9 @@ import io.element.android.x.BuildConfig import io.element.android.x.component.ShowkaseButton import io.element.android.x.core.di.DaggerComponentOwner import io.element.android.x.di.SessionComponentsOwner +import io.element.android.x.features.rageshake.bugreport.BugReportScreen +import io.element.android.x.features.rageshake.crash.ui.CrashDetectionScreen +import io.element.android.x.features.rageshake.detection.RageshakeDetectionScreen import io.element.android.x.getBrowserIntent import io.element.android.x.matrix.Matrix import io.element.android.x.matrix.core.SessionId @@ -118,6 +122,28 @@ class RootFlowNode( onCloseClicked = { isShowkaseButtonVisible = false }, onClick = { startActivity(context, Showkase.getBrowserIntent(context), null) } ) + + /* + var isBugReportVisible by rememberSaveable { + mutableStateOf(false) + } + RageshakeDetectionScreen( + onOpenBugReport = { + isBugReportVisible = true + } + ) + CrashDetectionScreen( + onOpenBugReport = { + isBugReportVisible = true + } + ) + if (isBugReportVisible) { + // TODO Improve the navigation, when pressing back here, it closes the app. + BugReportScreen( + onDone = { isBugReportVisible = false } + ) + } + */ } } diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index f8c6127d32..bd16b87387 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,4 +1,20 @@ + + #FFBB86FC #FF6200EE @@ -7,4 +23,4 @@ #FF018786 #FF000000 #FFFFFFFF - \ No newline at end of file + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6b30d8d9d4..120af4c3da 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,19 @@ + + - \ No newline at end of file + diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index bb56da5868..e75bc2cc4d 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -1,5 +1,21 @@ + +