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

Tutorial Update: Version 3.0 | 02 learn about composable functions #4

Open
wants to merge 3 commits into
base: versions/2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
36 changes: 17 additions & 19 deletions 02-learn-about-composable-functions/final/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'kotlin-android-extensions'
id 'kotlin-parcelize'
}

android {
Expand All @@ -20,6 +20,7 @@ android {

buildFeatures {
compose true
viewBinding true
}

buildTypes {
Expand All @@ -34,6 +35,9 @@ android {
targetCompatibility = JavaVersion.VERSION_1_8
}

composeOptions {
kotlinCompilerExtensionVersion "1.1.0-beta03"
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
Expand All @@ -42,18 +46,18 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
def room_version = "2.2.6"
def room_version = "2.4.2"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

// Support Libraries
implementation 'androidx.appcompat:appcompat:1.3.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.appcompat:appcompat:1.6.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation "androidx.fragment:fragment-ktx:1.3.2"
implementation "androidx.fragment:fragment-ktx:1.4.1"

// compose
implementation "androidx.compose.ui:ui:$compose"
Expand All @@ -76,28 +80,22 @@ dependencies {
implementation "androidx.room:room-ktx:$room_version"

// coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'

// hilt
implementation "com.google.dagger:hilt-android:2.33-beta"
kapt "com.google.dagger:hilt-android-compiler:2.33-beta"

implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03'
kapt 'androidx.hilt:hilt-compiler:1.0.0-beta01'
kapt 'androidx.hilt:hilt-compiler:1.0.0'

implementation 'com.google.code.gson:gson:2.8.6'
implementation "androidx.core:core-ktx:1.3.2"
implementation "androidx.core:core-ktx:1.7.0"
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += ["-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check"]
}
}
repositories {
mavenCentral()
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.raywenderlich.android.librarian">
xmlns:tools="http://schemas.android.com/tools"
package="com.raywenderlich.android.librarian">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".App"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<application
android:name=".App"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">

<!-- Main Activity -->
<activity android:name=".ui.main.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Main Activity -->
<activity
android:name=".ui.main.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".ui.readingListDetails.ReadingListDetailsActivity" />
<activity android:name=".ui.bookReviewDetails.BookReviewDetailsActivity" />
<activity android:name=".ui.addBook.AddBookActivity" />
<activity
android:name=".ui.addReview.AddBookReviewActivity"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden" />
</application>
<activity
android:name=".ui.readingListDetails.ReadingListDetailsActivity"
android:exported="false" />
<activity
android:name=".ui.bookReviewDetails.BookReviewDetailsActivity"
android:exported="false" />
<activity
android:name=".ui.addBook.AddBookActivity"
android:exported="false" />
<activity
android:name=".ui.addReview.AddBookReviewActivity"
android:exported="false"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.raywenderlich.android.librarian.ui.addBook.AddBookActivity

class AddBookContract : ActivityResultContract<Int, Boolean>() {

override fun createIntent(context: Context, input: Int?): Intent {
override fun createIntent(context: Context, input: Int): Intent {
return AddBookActivity.getIntent(context)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.Fragment
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.raywenderlich.android.librarian.R
import com.raywenderlich.android.librarian.databinding.ActivityMainBinding
import com.raywenderlich.android.librarian.databinding.ActivityMainBinding.inflate
import com.raywenderlich.android.librarian.ui.books.BooksFragment
import com.raywenderlich.android.librarian.ui.readingList.ReadingListFragment
import com.raywenderlich.android.librarian.ui.reviews.BookReviewsFragment
Expand All @@ -49,6 +51,8 @@ import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

lateinit var binding : ActivityMainBinding

private var reviewsFragment: BookReviewsFragment? = null
private var readingListFragment: ReadingListFragment? = null
private var booksFragment: BooksFragment? = null
Expand All @@ -59,6 +63,7 @@ class MainActivity : AppCompatActivity() {

super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
binding = inflate(layoutInflater)

initUi()

Expand All @@ -68,17 +73,15 @@ class MainActivity : AppCompatActivity() {
}

private fun initUi() {
val bottomNavigation = findViewById<BottomNavigationView>(R.id.bottomNavigation)

val colorDrawable = R.color.bottom_view_selector

bottomNavigation.itemTextColor =
binding.bottomNavigation.itemTextColor =
ResourcesCompat.getColorStateList(resources, colorDrawable, theme)

bottomNavigation.itemIconTintList =
binding.bottomNavigation.itemIconTintList =
ResourcesCompat.getColorStateList(resources, colorDrawable, theme)

bottomNavigation.setOnNavigationItemSelectedListener { menuItem ->
binding.bottomNavigation.setOnNavigationItemSelectedListener { menuItem ->
displayNextFragment(menuItem.itemId)
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import android.app.Activity
import android.content.Context
import android.content.Intent
import androidx.activity.result.contract.ActivityResultContract
import com.raywenderlich.android.librarian.ui.addBook.AddBookActivity
import com.raywenderlich.android.librarian.ui.addReview.AddBookReviewActivity

class AddBookReviewContract : ActivityResultContract<Int, Boolean>() {

override fun createIntent(context: Context, input: Int?): Intent {
override fun createIntent(context: Context, input: Int): Intent {
return AddBookReviewActivity.getIntent(context)
}

Expand Down
16 changes: 9 additions & 7 deletions 02-learn-about-composable-functions/final/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.5.31'

ext {
kotlin_version = '1.4.32'
compileSdkVersion = 30
kotlin_version = '1.5.31'
compileSdkVersion = 31
targetSdkVersion = compileSdkVersion
minSdkVersion = 23
}
Expand All @@ -16,9 +18,9 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:7.0.0-alpha14'
classpath 'com.android.tools.build:gradle:7.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.33-beta'
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.41'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -36,9 +38,9 @@ allprojects {
gson = '2.8.2'
retrofit = '2.9.0'
okHttp = '4.8.1'
compose = "1.0.0-beta04"
composeActivity = "1.3.0-alpha06"
composeViewModel = "1.0.0-alpha04"
compose = "1.2.0-alpha07"
composeActivity = "1.4.0"
composeViewModel = "2.5.0-alpha06"
}
}

Expand Down
17 changes: 9 additions & 8 deletions 02-learn-about-composable-functions/final/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Tue Apr 12 10:19:21 PDT 2022
org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M"
android.enableJetifier=true
android.useAndroidX=true
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Sep 04 10:01:01 CEST 2020
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-rc-1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
36 changes: 17 additions & 19 deletions 02-learn-about-composable-functions/starter/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'kotlin-android-extensions'
id 'kotlin-parcelize'
}

android {
Expand All @@ -20,6 +20,7 @@ android {

buildFeatures {
compose true
viewBinding true
}

buildTypes {
Expand All @@ -34,6 +35,9 @@ android {
targetCompatibility = JavaVersion.VERSION_1_8
}

composeOptions {
kotlinCompilerExtensionVersion "1.1.0-beta03"
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
Expand All @@ -42,18 +46,18 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
def room_version = "2.2.6"
def room_version = "2.4.2"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

// Support Libraries
implementation 'androidx.appcompat:appcompat:1.3.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.appcompat:appcompat:1.6.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation "androidx.fragment:fragment-ktx:1.3.2"
implementation "androidx.fragment:fragment-ktx:1.4.1"

// compose
implementation "androidx.compose.ui:ui:$compose"
Expand All @@ -76,28 +80,22 @@ dependencies {
implementation "androidx.room:room-ktx:$room_version"

// coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'

// hilt
implementation "com.google.dagger:hilt-android:2.33-beta"
kapt "com.google.dagger:hilt-android-compiler:2.33-beta"

implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03'
kapt 'androidx.hilt:hilt-compiler:1.0.0-beta01'
kapt 'androidx.hilt:hilt-compiler:1.0.0'

implementation 'com.google.code.gson:gson:2.8.6'
implementation "androidx.core:core-ktx:1.3.2"
implementation "androidx.core:core-ktx:1.7.0"
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += ["-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check"]
}
}
repositories {
mavenCentral()
}
Loading