From 99f0380182b698355b59d41853510baa1cb5b00e Mon Sep 17 00:00:00 2001 From: HashEngineering Date: Tue, 23 Apr 2024 07:27:20 -0700 Subject: [PATCH] feat: add jetpack compose (#1280) * feat: install jetpack compose * fix: ksp error * fix: various fixes * fix: various fixes * tests: fix test * fix: remove Compose ZenLedger menu item * fix: handle intent after setting up the result launcher --------- Co-authored-by: Andrei Ashikhmin --- build.gradle | 12 +- common/build.gradle | 16 +- .../wallet/common/ui/components/MenuItem.kt | 148 ++++++++++++++++++ .../main}/res/drawable/ic_menu_row_arrow.xml | 0 features/exploredash/build.gradle | 13 +- .../features/exploredash/ExploreDatabase.kt | 2 +- .../exploredash/utils}/RoomConverters.kt | 8 +- integrations/coinbase/build.gradle | 14 +- integrations/crowdnode/build.gradle | 10 +- integrations/uphold/build.gradle | 8 +- wallet/build.gradle | 19 +-- wallet/res/layout/fragment_tools.xml | 4 + .../schildbach/wallet/database/AppDatabase.kt | 2 +- .../database/BlockchainStateRoomConverters.kt | 4 +- .../wallet/livedata/EncryptWalletLiveData.kt | 6 + .../wallet/ui/LockScreenActivity.kt | 2 + .../wallet/ui/OnboardingActivity.kt | 1 + .../ui/RestoreWalletFromSeedActivity.kt | 1 + .../de/schildbach/wallet/ui/SetPinActivity.kt | 1 + .../wallet/ui/WalletUriHandlerActivity.kt | 40 ++--- .../ui/backup/RestoreFromFileActivity.kt | 1 + .../wallet/ui/more/ToolsFragment.kt | 1 + 22 files changed, 237 insertions(+), 76 deletions(-) create mode 100644 common/src/main/java/org/dash/wallet/common/ui/components/MenuItem.kt rename {wallet => common/src/main}/res/drawable/ic_menu_row_arrow.xml (100%) rename {common/src/main/java/org/dash/wallet/common/data => features/exploredash/src/main/java/org/dash/wallet/features/exploredash/utils}/RoomConverters.kt (89%) diff --git a/build.gradle b/build.gradle index 433b2a3cb5..ba0719bda9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,15 @@ buildscript { ext { - kotlin_version = '1.8.22' + kotlin_version = '1.9.23' coroutinesVersion = '1.6.4' ok_http_version = '4.9.1' dashjVersion = '20.0.4' - hiltVersion = '2.45' + hiltVersion = '2.51' + hiltCompilerVersion = '1.2.0' hiltWorkVersion = '1.0.0' workRuntimeVersion='2.7.1' firebaseVersion = '32.1.1' - roomVersion = '2.4.3' + roomVersion = '2.5.2' jetpackVersion = '1.8.0' appCompatVersion = '1.4.2' @@ -16,7 +17,6 @@ buildscript { lifecycleVersion = '2.5.1' navigationVersion = '2.6.0' datastoreVersion = "1.0.0" - hiltVersion = '2.45' hiltWorkVersion = '1.0.0' serializationVersion = '1.0.1' preferenceVersion = '1.2.0' @@ -62,6 +62,10 @@ buildscript { } } +plugins { + id 'com.google.devtools.ksp' version '1.9.23-1.0.19' apply false +} + allprojects { repositories { google() diff --git a/common/build.gradle b/common/build.gradle index 96e41c43e5..aea172fb5f 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-kapt' +apply plugin: 'com.google.devtools.ksp' apply plugin: 'kotlin-parcelize' apply plugin: 'dagger.hilt.android.plugin' @@ -36,6 +36,10 @@ android { buildFeatures { viewBinding true + compose = true + } + composeOptions { + kotlinCompilerExtensionVersion = "1.5.11" } tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { kotlinOptions { @@ -76,9 +80,13 @@ dependencies { implementation "androidx.room:room-ktx:$roomVersion" implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion" - // UI + implementation(platform("androidx.compose:compose-bom:2023.03.00")) + implementation("androidx.compose.ui:ui") + implementation("androidx.compose.ui:ui-tooling-preview") + implementation("androidx.compose.material3:material3") + implementation "com.github.bumptech.glide:glide:$glideVersion" - kapt "com.github.bumptech.glide:compiler:$glideVersion" + ksp "com.github.bumptech.glide:compiler:$glideVersion" implementation "io.coil-kt:coil:$coilVersion" implementation "com.google.android.material:material:$materialVersion" implementation "androidx.browser:browser:$browserVersion" @@ -89,7 +97,7 @@ dependencies { // DI implementation "com.google.dagger:hilt-android:$hiltVersion" - kapt "com.google.dagger:hilt-compiler:$hiltVersion" + ksp "com.google.dagger:hilt-compiler:$hiltVersion" testImplementation "junit:junit:$junitVersion" testImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoVersion" diff --git a/common/src/main/java/org/dash/wallet/common/ui/components/MenuItem.kt b/common/src/main/java/org/dash/wallet/common/ui/components/MenuItem.kt new file mode 100644 index 0000000000..3df31e41c2 --- /dev/null +++ b/common/src/main/java/org/dash/wallet/common/ui/components/MenuItem.kt @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2024 Dash Core Group + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.dash.wallet.common.ui.components + +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import org.dash.wallet.common.R + +@Composable +fun MenuItem( + title: String, + subtitle: String? = null, + details: String? = null, + icon: Int? = null, // Assuming you use resource IDs for icons + showInfo: Boolean = false, + showChevron: Boolean = false, + isToggled: (() -> Boolean)? = null, // Change to a lambda that returns a Boolean + onToggleChanged: ((Boolean) -> Unit)? = null, + action: (() -> Unit)? = null +) { + var toggleState by remember { mutableStateOf(isToggled?.invoke() ?: false) } + + Row( + modifier = Modifier + .fillMaxWidth() + .padding(10.dp) + .background(Color.White, RoundedCornerShape(8.dp)) + .clickable { action?.invoke() } + .padding(10.dp), + verticalAlignment = Alignment.CenterVertically + ) { + icon?.let { + Image( + painter = painterResource(id = it), + contentDescription = null, + modifier = Modifier.size(34.dp) + ) + } + + Column( + modifier = Modifier + .weight(1f) + .padding(start = 8.dp) + ) { + Row(verticalAlignment = Alignment.CenterVertically) { + Text( + text = title, + fontWeight = FontWeight.Medium, + fontSize = 14.sp, + color = Color.Black, + modifier = Modifier.weight(1f) + ) + + if (showInfo) { + Icon( + painter = painterResource(id = android.R.drawable.ic_dialog_info), + contentDescription = "Info", + tint = Color.Gray, + modifier = Modifier.size(18.dp) + ) + } + } + + subtitle?.let { + Text( + text = it, + fontSize = 12.sp, + color = Color.DarkGray, + modifier = Modifier.padding(top = 2.dp) + ) + } + + details?.let { + Text( + text = it, + fontSize = 12.sp, + color = Color.DarkGray, + modifier = Modifier.padding(top = 2.dp) + ) + } + } + + isToggled?.let { + Switch( + checked = toggleState, + onCheckedChange = { newState -> + toggleState = newState + onToggleChanged?.invoke(newState) + }, + modifier = Modifier.size(60.dp) + ) + } + + if (showChevron) { + Icon( + painter = painterResource(id = R.drawable.ic_menu_row_arrow), + contentDescription = "Chevron", + tint = Color.Gray, + modifier = Modifier.padding(end = 10.dp) + ) + } + } +} + +@Preview(showBackground = true) +@Composable +fun PreviewMenuItem() { + MenuItem( + title = "Title", + subtitle = "Easily stake Dash and earn passive income with a few simple steps", + icon = R.drawable.ic_dash_blue_filled, + showInfo = true, + isToggled = { true }, + onToggleChanged = { } + ) +} diff --git a/wallet/res/drawable/ic_menu_row_arrow.xml b/common/src/main/res/drawable/ic_menu_row_arrow.xml similarity index 100% rename from wallet/res/drawable/ic_menu_row_arrow.xml rename to common/src/main/res/drawable/ic_menu_row_arrow.xml diff --git a/features/exploredash/build.gradle b/features/exploredash/build.gradle index 1fe8fff41b..2a3ce40bba 100644 --- a/features/exploredash/build.gradle +++ b/features/exploredash/build.gradle @@ -1,7 +1,7 @@ plugins { id 'com.android.library' id 'kotlin-android' - id 'kotlin-kapt' + id 'com.google.devtools.ksp' id 'androidx.navigation.safeargs.kotlin' id 'dagger.hilt.android.plugin' id 'kotlin-parcelize' @@ -49,10 +49,6 @@ android { namespace 'org.dash.wallet.features.exploredash' } -kapt { - correctErrorTypes true -} - hilt { enableAggregatingTask = true } @@ -77,11 +73,13 @@ dependencies { // Database implementation "androidx.room:room-ktx:$roomVersion" implementation "androidx.room:room-paging:$roomVersion" + implementation "androidx.room:room-runtime:$roomVersion" + ksp "androidx.room:room-compiler:$roomVersion" // DI implementation "com.google.dagger:hilt-android:$hiltVersion" - kapt "com.google.dagger:hilt-compiler:$hiltVersion" - kapt 'androidx.hilt:hilt-compiler:1.0.0' + ksp "com.google.dagger:hilt-compiler:$hiltVersion" + ksp "androidx.hilt:hilt-compiler:$hiltCompilerVersion" implementation "androidx.hilt:hilt-work:$hiltWorkVersion" // UI @@ -119,7 +117,6 @@ dependencies { testImplementation "androidx.arch.core:core-testing:$coreTestingVersion" testImplementation "org.robolectric:robolectric:4.9.2" testImplementation "androidx.room:room-testing:$roomVersion" - kapt "androidx.room:room-compiler:$roomVersion" androidTestImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoVersion" androidTestImplementation "org.mockito:mockito-android:4.6.1" diff --git a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ExploreDatabase.kt b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ExploreDatabase.kt index e4300a6a10..a5d2c0c8db 100644 --- a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ExploreDatabase.kt +++ b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ExploreDatabase.kt @@ -26,7 +26,6 @@ import androidx.room.RoomDatabase import androidx.room.TypeConverters import androidx.sqlite.db.SupportSQLiteDatabase import kotlinx.coroutines.suspendCancellableCoroutine -import org.dash.wallet.common.data.RoomConverters import org.dash.wallet.features.exploredash.data.explore.AtmDao import org.dash.wallet.features.exploredash.data.explore.MerchantDao import org.dash.wallet.features.exploredash.data.explore.model.Atm @@ -35,6 +34,7 @@ import org.dash.wallet.features.exploredash.data.explore.model.Merchant import org.dash.wallet.features.exploredash.data.explore.model.MerchantFTS import org.dash.wallet.features.exploredash.repository.ExploreRepository import org.dash.wallet.features.exploredash.utils.ExploreConfig +import org.dash.wallet.features.exploredash.utils.RoomConverters import org.slf4j.LoggerFactory import java.io.File import kotlin.coroutines.resume diff --git a/common/src/main/java/org/dash/wallet/common/data/RoomConverters.kt b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/utils/RoomConverters.kt similarity index 89% rename from common/src/main/java/org/dash/wallet/common/data/RoomConverters.kt rename to features/exploredash/src/main/java/org/dash/wallet/features/exploredash/utils/RoomConverters.kt index 1bde713c63..7f36362a38 100644 --- a/common/src/main/java/org/dash/wallet/common/data/RoomConverters.kt +++ b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/utils/RoomConverters.kt @@ -1,5 +1,5 @@ /* - * Copyright 2022 Dash Core Group. + * Copyright 2024 Dash Core Group. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package org.dash.wallet.common.data +package org.dash.wallet.features.exploredash.utils import androidx.room.TypeConverter -import java.util.* +import java.util.Date class RoomConverters { @TypeConverter @@ -30,4 +30,4 @@ class RoomConverters { fun dateToTimestamp(date: Date?): Long? { return date?.time } -} \ No newline at end of file +} diff --git a/integrations/coinbase/build.gradle b/integrations/coinbase/build.gradle index cf369040b0..5b7f5afe21 100644 --- a/integrations/coinbase/build.gradle +++ b/integrations/coinbase/build.gradle @@ -1,7 +1,7 @@ plugins { id 'com.android.library' id 'kotlin-android' - id 'kotlin-kapt' + id 'com.google.devtools.ksp' id 'androidx.navigation.safeargs.kotlin' id 'dagger.hilt.android.plugin' id 'kotlin-parcelize' @@ -44,10 +44,6 @@ android { namespace 'org.dash.wallet.integrations.coinbase' } -kapt { - correctErrorTypes true -} - hilt { enableAggregatingTask = true } @@ -68,8 +64,8 @@ dependencies { // DI implementation "com.google.dagger:hilt-android:$hiltVersion" - kapt "com.google.dagger:hilt-android-compiler:$hiltVersion" - kapt "androidx.hilt:hilt-compiler:1.0.0" + ksp "com.google.dagger:hilt-android-compiler:$hiltVersion" + ksp "androidx.hilt:hilt-compiler:$hiltCompilerVersion" // UI implementation "com.google.android.material:material:$materialVersion" @@ -85,12 +81,10 @@ dependencies { // Tests testImplementation 'junit:junit:4.13.2' - testImplementation "org.mockito:mockito-core:4.0.0" - testImplementation 'org.mockito:mockito-inline:3.8.0' testImplementation "io.mockk:mockk:1.9.3" - implementation 'org.hamcrest:hamcrest:2.2' testImplementation "androidx.test:core-ktx:1.4.0" testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion" + testImplementation 'org.hamcrest:hamcrest:2.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/integrations/crowdnode/build.gradle b/integrations/crowdnode/build.gradle index bf76e00910..f61244b6d3 100644 --- a/integrations/crowdnode/build.gradle +++ b/integrations/crowdnode/build.gradle @@ -1,7 +1,7 @@ plugins { id 'com.android.library' id 'kotlin-android' - id 'kotlin-kapt' + id 'com.google.devtools.ksp' id 'androidx.navigation.safeargs.kotlin' id 'dagger.hilt.android.plugin' id 'kotlin-parcelize' @@ -37,10 +37,6 @@ android { namespace 'org.dash.wallet.integrations.crowdnode' } -kapt { - correctErrorTypes true -} - hilt { enableAggregatingTask = true } @@ -65,8 +61,8 @@ dependencies { implementation "com.google.dagger:hilt-android:$hiltVersion" implementation "androidx.hilt:hilt-work:$hiltWorkVersion" implementation "androidx.work:work-runtime-ktx:$workRuntimeVersion" - kapt "com.google.dagger:hilt-android-compiler:$hiltVersion" - kapt "androidx.hilt:hilt-compiler:1.0.0" + ksp "com.google.dagger:hilt-android-compiler:$hiltVersion" + ksp "androidx.hilt:hilt-compiler:$hiltCompilerVersion" // UI implementation "com.google.android.material:material:$materialVersion" diff --git a/integrations/uphold/build.gradle b/integrations/uphold/build.gradle index 1b49112a85..b2cd751bf8 100644 --- a/integrations/uphold/build.gradle +++ b/integrations/uphold/build.gradle @@ -1,7 +1,7 @@ plugins { id 'com.android.library' id 'kotlin-android' - id 'kotlin-kapt' + id 'com.google.devtools.ksp' id 'dagger.hilt.android.plugin' id 'org.jlleitschuh.gradle.ktlint' } @@ -37,10 +37,6 @@ android { namespace 'org.dash.wallet.integrations.uphold' } -kapt { - correctErrorTypes true -} - hilt { enableAggregatingTask = true } @@ -65,7 +61,7 @@ dependencies { // DI implementation "com.google.dagger:hilt-android:$hiltVersion" - kapt "com.google.dagger:hilt-compiler:$hiltVersion" + ksp "com.google.dagger:hilt-compiler:$hiltVersion" // JWT implementation 'io.jsonwebtoken:jjwt-api:0.11.5' diff --git a/wallet/build.gradle b/wallet/build.gradle index 042ce9eb94..666a43f5c9 100644 --- a/wallet/build.gradle +++ b/wallet/build.gradle @@ -3,7 +3,7 @@ plugins { id 'project-report' id 'kotlin-android' id 'kotlin-parcelize' - id 'kotlin-kapt' + id 'com.google.devtools.ksp' id 'dagger.hilt.android.plugin' id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' id 'androidx.navigation.safeargs.kotlin' @@ -46,6 +46,7 @@ dependencies { implementation 'androidx.legacy:legacy-support-core-utils:1.0.0' implementation "androidx.work:work-runtime-ktx:$workRuntimeVersion" implementation "androidx.biometric:biometric:1.1.0" + implementation("androidx.activity:activity-compose:1.7.2") implementation "org.dashj:dashj-core:$dashjVersion" implementation "org.dashj.android:dashj-bls-android:1.0.0" @@ -81,7 +82,7 @@ dependencies { implementation 'com.google.android.flexbox:flexbox:3.0.0' implementation "androidx.constraintlayout:constraintlayout:$constrainLayoutVersion" implementation "com.github.bumptech.glide:glide:$glideVersion" - kapt "com.github.bumptech.glide:compiler:$glideVersion" + ksp "com.github.bumptech.glide:compiler:$glideVersion" implementation 'com.github.MikeOrtiz:TouchImageView:3.0.3' implementation "io.coil-kt:coil:$coilVersion" @@ -92,7 +93,7 @@ dependencies { // Database implementation "androidx.room:room-ktx:$roomVersion" implementation "androidx.room:room-runtime:$roomVersion" - kapt "androidx.room:room-compiler:$roomVersion" + ksp "androidx.room:room-compiler:$roomVersion" // Prefs implementation "androidx.preference:preference-ktx:$preferenceVersion" @@ -132,9 +133,9 @@ dependencies { // DI implementation "com.google.dagger:hilt-android:$hiltVersion" - kapt "com.google.dagger:hilt-compiler:$hiltVersion" + ksp "com.google.dagger:hilt-compiler:$hiltVersion" implementation "androidx.hilt:hilt-work:$hiltWorkVersion" - kapt 'androidx.hilt:hilt-compiler:1.0.0' + ksp "androidx.hilt:hilt-compiler:$hiltCompilerVersion" // Unit tests testImplementation "junit:junit:$junitVersion" @@ -164,10 +165,6 @@ ext { archivesBaseName = 'dash-wallet' } -kapt { - correctErrorTypes true -} - hilt { enableAggregatingTask = true } @@ -346,6 +343,10 @@ android { } buildFeatures { viewBinding true + compose true + } + composeOptions { + kotlinCompilerExtensionVersion = "1.5.11" } lint { abortOnError false diff --git a/wallet/res/layout/fragment_tools.xml b/wallet/res/layout/fragment_tools.xml index 07dda06b11..c0176f1ae3 100644 --- a/wallet/res/layout/fragment_tools.xml +++ b/wallet/res/layout/fragment_tools.xml @@ -201,4 +201,8 @@ + \ No newline at end of file diff --git a/wallet/src/de/schildbach/wallet/database/AppDatabase.kt b/wallet/src/de/schildbach/wallet/database/AppDatabase.kt index d2d3a7fb71..9f8e380dc3 100644 --- a/wallet/src/de/schildbach/wallet/database/AppDatabase.kt +++ b/wallet/src/de/schildbach/wallet/database/AppDatabase.kt @@ -21,7 +21,6 @@ import androidx.room.Database import androidx.room.RoomDatabase import androidx.room.TypeConverters import de.schildbach.wallet.database.dao.* -import org.dash.wallet.common.data.RoomConverters import org.dash.wallet.common.data.entity.AddressMetadata import org.dash.wallet.common.data.entity.BlockchainState import org.dash.wallet.common.data.entity.ExchangeRate @@ -29,6 +28,7 @@ import org.dash.wallet.common.data.entity.IconBitmap import org.dash.wallet.common.data.entity.TransactionMetadata import org.dash.wallet.features.exploredash.data.dashdirect.GiftCardDao import org.dash.wallet.common.data.entity.GiftCard +import org.dash.wallet.features.exploredash.utils.RoomConverters @Database( entities = diff --git a/wallet/src/de/schildbach/wallet/database/BlockchainStateRoomConverters.kt b/wallet/src/de/schildbach/wallet/database/BlockchainStateRoomConverters.kt index 73808d1d8d..0cee5aa35e 100644 --- a/wallet/src/de/schildbach/wallet/database/BlockchainStateRoomConverters.kt +++ b/wallet/src/de/schildbach/wallet/database/BlockchainStateRoomConverters.kt @@ -26,7 +26,7 @@ import java.util.* class BlockchainStateRoomConverters { @TypeConverter - fun fromImpedimentsEnumSet(value: String?): Set { + fun fromImpedimentsEnumSet(value: String?): MutableSet { val impedimentSet = EnumSet.noneOf(BlockchainState.Impediment::class.java) if (value == null || value.isEmpty()) { return impedimentSet @@ -39,7 +39,7 @@ class BlockchainStateRoomConverters { } @TypeConverter - fun toImpedimentsString(impediments: Set): String { + fun toImpedimentsString(impediments: MutableSet): String { val sb = StringBuilder() impediments.forEach { if (sb.isNotEmpty()) { diff --git a/wallet/src/de/schildbach/wallet/livedata/EncryptWalletLiveData.kt b/wallet/src/de/schildbach/wallet/livedata/EncryptWalletLiveData.kt index 67ff9635c8..3327311f08 100644 --- a/wallet/src/de/schildbach/wallet/livedata/EncryptWalletLiveData.kt +++ b/wallet/src/de/schildbach/wallet/livedata/EncryptWalletLiveData.kt @@ -74,10 +74,12 @@ class EncryptWalletLiveData( @SuppressLint("StaticFieldLeak") internal inner class EncryptWalletTask : AsyncTask>() { + @Deprecated("Deprecated in Java") override fun onPreExecute() { value = Resource.loading(null) } + @Deprecated("Deprecated in Java") override fun doInBackground(vararg args: Any): Resource { val initialize = args[0] as Boolean val wallet = walletApplication.wallet!! @@ -111,6 +113,7 @@ class EncryptWalletLiveData( } } + @Deprecated("Deprecated in Java") override fun onPostExecute(result: Resource) { value = result encryptWalletTask = null @@ -120,10 +123,12 @@ class EncryptWalletLiveData( @SuppressLint("StaticFieldLeak") internal inner class DecryptWalletTask : AsyncTask>() { + @Deprecated("Deprecated in Java") override fun onPreExecute() { value = Resource.loading(null) } + @Deprecated("Deprecated in Java") override fun doInBackground(vararg args: String): Resource { val password = args[0] val wallet = walletApplication.wallet!! @@ -137,6 +142,7 @@ class EncryptWalletLiveData( } } + @Deprecated("Deprecated in Java") override fun onPostExecute(result: Resource) { value = result decryptWalletTask = null diff --git a/wallet/src/de/schildbach/wallet/ui/LockScreenActivity.kt b/wallet/src/de/schildbach/wallet/ui/LockScreenActivity.kt index eeacf08663..5f6f433884 100644 --- a/wallet/src/de/schildbach/wallet/ui/LockScreenActivity.kt +++ b/wallet/src/de/schildbach/wallet/ui/LockScreenActivity.kt @@ -28,6 +28,7 @@ import android.view.View import android.view.ViewConfiguration import android.view.animation.AnimationUtils import android.view.inputmethod.InputMethodManager +import androidx.activity.OnBackPressedCallback import androidx.activity.viewModels import androidx.appcompat.app.AlertDialog import androidx.constraintlayout.widget.ConstraintLayout @@ -476,6 +477,7 @@ open class LockScreenActivity : SecureActivity() { } } + @Deprecated("Deprecated in Java") override fun onBackPressed() { if (!lockScreenDisplayed) { super.onBackPressed() diff --git a/wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt b/wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt index f97647dcc7..77cdbf9a03 100644 --- a/wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt +++ b/wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt @@ -293,6 +293,7 @@ class OnboardingActivity : RestoreFromFileActivity() { overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out) } + @Deprecated("Deprecated in Java") override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) diff --git a/wallet/src/de/schildbach/wallet/ui/RestoreWalletFromSeedActivity.kt b/wallet/src/de/schildbach/wallet/ui/RestoreWalletFromSeedActivity.kt index 14b2ea8d44..d15f44ce55 100644 --- a/wallet/src/de/schildbach/wallet/ui/RestoreWalletFromSeedActivity.kt +++ b/wallet/src/de/schildbach/wallet/ui/RestoreWalletFromSeedActivity.kt @@ -176,6 +176,7 @@ class RestoreWalletFromSeedActivity : RestoreFromFileActivity() { ).show(this) } + @Deprecated("Deprecated in Java") override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == SET_PIN_REQUEST_CODE && resultCode == Activity.RESULT_OK) { diff --git a/wallet/src/de/schildbach/wallet/ui/SetPinActivity.kt b/wallet/src/de/schildbach/wallet/ui/SetPinActivity.kt index 480c5048cb..2d54a82d92 100644 --- a/wallet/src/de/schildbach/wallet/ui/SetPinActivity.kt +++ b/wallet/src/de/schildbach/wallet/ui/SetPinActivity.kt @@ -512,6 +512,7 @@ class SetPinActivity : InteractionAwareActivity() { return super.onOptionsItemSelected(item) } + @Deprecated("Deprecated in Java") override fun onBackPressed() { when { pin.size > 0 -> setState(state) diff --git a/wallet/src/de/schildbach/wallet/ui/WalletUriHandlerActivity.kt b/wallet/src/de/schildbach/wallet/ui/WalletUriHandlerActivity.kt index 105eaef167..bb6cc825b0 100644 --- a/wallet/src/de/schildbach/wallet/ui/WalletUriHandlerActivity.kt +++ b/wallet/src/de/schildbach/wallet/ui/WalletUriHandlerActivity.kt @@ -17,8 +17,11 @@ package de.schildbach.wallet.ui +import android.app.Activity import android.content.Intent import android.os.Bundle +import androidx.activity.result.ActivityResultLauncher +import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.localbroadcastmanager.content.LocalBroadcastManager import de.schildbach.wallet.Constants @@ -27,6 +30,7 @@ import de.schildbach.wallet.data.PaymentIntent import de.schildbach.wallet.integration.android.BitcoinIntegration import de.schildbach.wallet.ui.buy_sell.IntegrationOverviewFragment import de.schildbach.wallet.ui.main.WalletActivity +import de.schildbach.wallet.ui.send.SendCoinsActivity import de.schildbach.wallet.ui.send.SendCoinsActivity.Companion.sendFromWalletUri import de.schildbach.wallet.ui.util.InputParser.WalletUriParser import de.schildbach.wallet.ui.util.WalletUri @@ -49,10 +53,22 @@ class WalletUriHandlerActivity : AppCompatActivity() { } private var wallet: Wallet? = null + private lateinit var walletUriResultLauncher: ActivityResultLauncher override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) wallet = (application as WalletApplication).wallet + walletUriResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + var resultIntent: Intent? = null + if (result.resultCode == Activity.RESULT_OK) { + val data = result.data + val requestData = intent.data + val transactionHash = BitcoinIntegration.transactionHashFromResult(data) + resultIntent = WalletUri.createPaymentResult(requestData, transactionHash) + } + setResult(result.resultCode, resultIntent) + finish() + } handleIntent(intent) } @@ -90,9 +106,10 @@ class WalletUriHandlerActivity : AppCompatActivity() { } else { object : WalletUriParser(intentUri) { override fun handlePaymentIntent(paymentIntent: PaymentIntent, forceInstantSend: Boolean) { - sendFromWalletUri( - this@WalletUriHandlerActivity, REQUEST_CODE_SEND_FROM_WALLET_URI, paymentIntent - ) + val intent = Intent(this@WalletUriHandlerActivity, SendCoinsActivity::class.java) + intent.action = SendCoinsActivity.ACTION_SEND_FROM_WALLET_URI + intent.putExtra(SendCoinsActivity.INTENT_EXTRA_PAYMENT_INTENT, paymentIntent) + walletUriResultLauncher.launch(intent) } override fun handleMasterPublicKeyRequest(sender: String) { @@ -140,23 +157,6 @@ class WalletUriHandlerActivity : AppCompatActivity() { confirmationAlertDialogBuilder.buildAlertDialog().show() } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - - if (requestCode == REQUEST_CODE_SEND_FROM_WALLET_URI) { - var result: Intent? = null - - if (resultCode == RESULT_OK) { - val requestData = intent.data - val transactionHash = BitcoinIntegration.transactionHashFromResult(data) - result = WalletUri.createPaymentResult(requestData, transactionHash) - } - - setResult(resultCode, result) - finish() - } - } - private val negativeButtonClickListener = { this@WalletUriHandlerActivity.setResult(RESULT_CANCELED) finish() diff --git a/wallet/src/de/schildbach/wallet/ui/backup/RestoreFromFileActivity.kt b/wallet/src/de/schildbach/wallet/ui/backup/RestoreFromFileActivity.kt index 70a6bfec55..8a7280a5e8 100644 --- a/wallet/src/de/schildbach/wallet/ui/backup/RestoreFromFileActivity.kt +++ b/wallet/src/de/schildbach/wallet/ui/backup/RestoreFromFileActivity.kt @@ -110,6 +110,7 @@ open class RestoreFromFileActivity : SecureActivity(), AbstractPINDialogFragment viewModel.restoreWallet(walletBuffer, password) } + @Deprecated("Deprecated in Java") override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == SET_PIN_REQUEST_CODE && resultCode == Activity.RESULT_OK) { diff --git a/wallet/src/de/schildbach/wallet/ui/more/ToolsFragment.kt b/wallet/src/de/schildbach/wallet/ui/more/ToolsFragment.kt index 548124fa75..70e1c08058 100644 --- a/wallet/src/de/schildbach/wallet/ui/more/ToolsFragment.kt +++ b/wallet/src/de/schildbach/wallet/ui/more/ToolsFragment.kt @@ -44,6 +44,7 @@ import kotlinx.coroutines.launch import org.dash.wallet.common.services.analytics.AnalyticsConstants import org.dash.wallet.common.services.analytics.AnalyticsService import org.dash.wallet.common.ui.BaseAlertDialogBuilder +import org.dash.wallet.common.ui.components.MenuItem import org.dash.wallet.common.ui.dialogs.AdaptiveDialog import org.dash.wallet.common.ui.viewBinding import org.dash.wallet.common.util.Qr