From 82b85c20c851de712a31d2c244bbedd3e9235e45 Mon Sep 17 00:00:00 2001 From: sockenklaus Date: Fri, 15 Jul 2022 14:42:56 +0200 Subject: [PATCH] Jetpack Compose???? --- .idea/deploymentTargetDropDown.xml | 17 ----- app/build.gradle | 37 ++++++++-- app/src/main/AndroidManifest.xml | 5 ++ .../sockenklaus/batterytracker/AddBattery.kt | 71 +++++++++++++++++++ .../batterytracker/MainActivity.kt | 2 - .../batterytracker/ui/AddBatteryFragment.kt | 2 + .../ui/add_charge/AddChargeFragment.kt | 1 - .../batterytracker/ui/theme/Color.kt | 8 +++ .../batterytracker/ui/theme/Shape.kt | 11 +++ .../batterytracker/ui/theme/Theme.kt | 47 ++++++++++++ .../batterytracker/ui/theme/Type.kt | 28 ++++++++ app/src/main/res/layout/app_bar_main.xml | 2 +- app/src/main/res/layout/nav_header_main.xml | 7 +- app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/themes.xml | 2 +- build.gradle | 8 ++- 16 files changed, 215 insertions(+), 34 deletions(-) delete mode 100644 .idea/deploymentTargetDropDown.xml create mode 100644 app/src/main/java/com/sockenklaus/batterytracker/AddBattery.kt create mode 100644 app/src/main/java/com/sockenklaus/batterytracker/ui/theme/Color.kt create mode 100644 app/src/main/java/com/sockenklaus/batterytracker/ui/theme/Shape.kt create mode 100644 app/src/main/java/com/sockenklaus/batterytracker/ui/theme/Theme.kt create mode 100644 app/src/main/java/com/sockenklaus/batterytracker/ui/theme/Type.kt diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index d706a1f..0000000 --- a/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 08af63b..07fb30b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,6 +14,9 @@ android { versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + vectorDrawables { + useSupportLibrary true + } } buildTypes { @@ -31,28 +34,50 @@ android { } buildFeatures { viewBinding true + compose true + } + + composeOptions { + kotlinCompilerExtensionVersion '1.2.0' + } + packagingOptions { + resources { + excludes += '/META-INF/{AL2.0,LGPL2.1}' + } } } dependencies { - def room_version = "2.4.2" + implementation 'androidx.room:room-runtime:2.5.0-alpha02' + implementation "androidx.compose.ui:ui:$compose_version" + implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1' + annotationProcessor 'androidx.room:room-compiler:2.5.0-alpha02' - implementation "androidx.room:room-runtime:$room_version" - annotationProcessor "androidx.room:room-compiler:$room_version" - - implementation "androidx.room:room-rxjava3:$room_version" + implementation 'androidx.room:room-rxjava3:2.5.0-alpha02' implementation "androidx.room:room-paging:2.5.0-alpha02" + implementation 'com.google.android.material:material:1.6.1' + implementation 'androidx.core:core-ktx:1.8.0' implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.0' implementation 'androidx.navigation:navigation-fragment-ktx:2.5.0' implementation 'androidx.navigation:navigation-ui-ktx:2.5.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' + + implementation 'androidx.activity:activity-compose:1.5.0' + implementation 'androidx.compose.material:material:1.2.0-rc03' + implementation 'androidx.compose.animation:animation:1.2.0-rc03' + implementation 'androidx.compose.ui:ui-tooling:1.2.0-rc03' + implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.5.0' + implementation 'com.google.android.material:compose-theme-adapter:1.1.14' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.compose.ui:ui-test-junit4:1.2.0-rc03' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version" } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 07ecc5d..a334e98 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,6 +13,11 @@ android:supportsRtl="true" android:theme="@style/Theme.BatteryTracker" tools:targetApi="31"> + Unit +) { + val colors = if (darkTheme) { + DarkColorPalette + } else { + LightColorPalette + } + + MaterialTheme( + colors = colors, + typography = Typography, + shapes = Shapes, + content = content + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/sockenklaus/batterytracker/ui/theme/Type.kt b/app/src/main/java/com/sockenklaus/batterytracker/ui/theme/Type.kt new file mode 100644 index 0000000..6b7ed3e --- /dev/null +++ b/app/src/main/java/com/sockenklaus/batterytracker/ui/theme/Type.kt @@ -0,0 +1,28 @@ +package com.sockenklaus.batterytracker.ui.theme + +import androidx.compose.material.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + body1 = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp + ) + /* Other default text styles to override + button = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.W500, + fontSize = 14.sp + ), + caption = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 12.sp + ) + */ +) \ No newline at end of file diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml index 75bd898..3f2bd1e 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -11,7 +11,7 @@ android:layout_height="wrap_content" android:theme="@style/Theme.BatteryTracker.AppBarOverlay"> - + android:paddingBottom="@dimen/activity_vertical_margin"> + android:textAppearance="@style/TextAppearance.MaterialComponents.Headline5" + /> \ 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 540ff0c..8994e4f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -26,4 +26,5 @@ Enter declared capacity Declared Capacity Save Battery + AddBattery \ 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 933e8ee..5f930e3 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -10,7 +10,7 @@ @color/teal_700 @color/black - ?attr/colorPrimaryVariant + ?attr/colorPrimaryVariant diff --git a/build.gradle b/build.gradle index 932e4c5..d19836f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,12 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + ext { + compose_version = '1.1.0-beta01' + } +}// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id 'com.android.application' version '7.2.1' apply false id 'com.android.library' version '7.2.1' apply false - id 'org.jetbrains.kotlin.android' version '1.7.10' apply false + id 'org.jetbrains.kotlin.android' version '1.7.0' apply false } task clean(type: Delete) {