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 2 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.6.1'
HashEngineering marked this conversation as resolved.
Show resolved Hide resolved
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
22 changes: 17 additions & 5 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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'

android {

defaultConfig {
compileSdk 33
compileSdk 34
minSdkVersion 24
targetSdkVersion 33
targetSdkVersion 34
vectorDrawables.useSupportLibrary = true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -36,6 +36,10 @@ android {

buildFeatures {
viewBinding true
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion "1.5.12"
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
Expand Down Expand Up @@ -77,8 +81,16 @@ dependencies {
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.material:material"
implementation "androidx.compose.ui:ui-tooling"
//implementation 'androidx.activity:activity-compose:1.8.2'
implementation "androidx.compose.material3:material3:1.2.1" // Check for the latest version
androidTestImplementation "androidx.compose.ui:ui-test-junit4"
debugImplementation "androidx.compose.ui:ui-tooling"
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 +101,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
195 changes: 195 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,195 @@
/*
* 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.rememberUpdatedState
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 MenuItemIcon(icon: Int?) {
HashEngineering marked this conversation as resolved.
Show resolved Hide resolved
// icon?.let {
// Image(
// painter = painterResource(id = it),
// contentDescription = null,
// modifier = Modifier.size(36.dp)
// )
// }
//}
//
//@Composable
//fun MenuItemTexts(title: String, subtitle: String?, details: String?) {
// Column(
// modifier = Modifier
// .weight(1f)
// .padding(start = 8.dp)
// ) {
// Text(
// text = title,
// fontWeight = FontWeight.Medium,
// fontSize = 14.sp,
// color = Color.Black,
// modifier = Modifier.weight(1f)
// )
//
// 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)
// )
// }
// }
//}

@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.LightGray, RoundedCornerShape(8.dp))
.clickable { action?.invoke() }
.padding(10.dp),
verticalAlignment = Alignment.CenterVertically
) {
icon?.let {
Image(
painter = painterResource(id = it),
contentDescription = null,
modifier = Modifier.size(36.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 = android.R.drawable.arrow_down_float),
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, // Replace 'ic_faceid' with actual resource ID
showInfo = true,
isToggled = { true },
onToggleChanged = { }
)
}
16 changes: 6 additions & 10 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 All @@ -10,9 +10,9 @@ plugins {

android {
defaultConfig {
compileSdk 33
compileSdk 34
minSdkVersion 24
targetSdkVersion 33
targetSdkVersion 34
HashEngineering marked this conversation as resolved.
Show resolved Hide resolved
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
javaCompileOptions {
Expand Down Expand Up @@ -49,10 +49,6 @@ android {
namespace 'org.dash.wallet.features.exploredash'
}

kapt {
correctErrorTypes true
}

hilt {
enableAggregatingTask = true
}
Expand Down Expand Up @@ -80,8 +76,8 @@ dependencies {

// 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 +115,7 @@ 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"
ksp "androidx.room:room-compiler:$roomVersion"

androidTestImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoVersion"
androidTestImplementation "org.mockito:mockito-android:4.6.1"
Expand Down
17 changes: 5 additions & 12 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 All @@ -10,9 +10,9 @@ plugins {
android {

defaultConfig {
compileSdk 33
compileSdk 34
minSdkVersion 24
targetSdkVersion 33
targetSdkVersion 34
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
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,10 +81,7 @@ 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"

Expand Down
Loading
Loading