Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add jetpack compose #1280

Merged
merged 9 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
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'

// Architecture
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'
Expand Down Expand Up @@ -62,6 +62,10 @@ buildscript {
}
}

plugins {
id 'com.google.devtools.ksp' version '1.9.23-1.0.19' apply false
}

allprojects {
repositories {
google()
Expand Down
16 changes: 12 additions & 4 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
148 changes: 148 additions & 0 deletions common/src/main/java/org/dash/wallet/common/ui/components/MenuItem.kt
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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,
HashEngineering marked this conversation as resolved.
Show resolved Hide resolved
action: (() -> Unit)? = null
) {
HashEngineering marked this conversation as resolved.
Show resolved Hide resolved
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 = { }
)
}
13 changes: 5 additions & 8 deletions features/exploredash/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -49,10 +49,6 @@ android {
namespace 'org.dash.wallet.features.exploredash'
}

kapt {
correctErrorTypes true
}

hilt {
enableAggregatingTask = true
}
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,10 +15,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

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
Expand All @@ -30,4 +30,4 @@ class RoomConverters {
fun dateToTimestamp(date: Date?): Long? {
return date?.time
}
}
}
14 changes: 4 additions & 10 deletions integrations/coinbase/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -44,10 +44,6 @@ android {
namespace 'org.dash.wallet.integrations.coinbase'
}

kapt {
correctErrorTypes true
}

hilt {
enableAggregatingTask = true
}
Expand All @@ -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"
Expand All @@ -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'
Expand Down
10 changes: 3 additions & 7 deletions integrations/crowdnode/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -37,10 +37,6 @@ android {
namespace 'org.dash.wallet.integrations.crowdnode'
}

kapt {
correctErrorTypes true
}

hilt {
enableAggregatingTask = true
}
Expand All @@ -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"
Expand Down
Loading
Loading