
Android application development with Kotlin
US$ 19.95
The publisher has enabled DRM protection, which means that you need to use the BookFusion iOS, Android or Web app to read this eBook. This eBook cannot be used outside of the BookFusion platform.
Description
Contents
Reviews
Language
English
ISBN
9789389423501
Cover Page
Title Page
Copyright Page
Dedication
About the Author
Acknowledgement
Preface
Errata
Table of Contents
1. Getting Started with Kotin for Android
Structure
How does the Kotlin code look like?
How does Kotlin build process work with Android?
Configure Kotlin in Android Studio
Downloading and installing Java
Downloading and installing Android Studio
Installing Kotlin plugin
Updating build.gradle
Add classpath into the project’s build.gradle
Add Koltin as a library
Create a new project
Setting up Android emulator
Display “Hello Kotlin”
Understanding the basics of Android
Activity
Activity lifecycle
Intent
Implicit Intent
Explicit Intent
Building Intent
AndroidManifest.xml
Fragment
Context
Trying out Kotlin
Wrapping up
2. Kotlin Fundamentals
Structure
Understanding basic types
Numbers
String
Booleans
Understanding variables
Type inference
Understanding the scope of the variable
Naming a variable
Functions in Kotlin
Functions and parameters
Functions and return type
Named arguments
Default arguments
Why Java does not support default arguments?
Functions as an expression
Variable arguments
Beyond arguments and return types
Local function
Extension function
Infix function
Top-level functions
Playing with String
Standard extension properties and functions
String template
String comparison
Comparing value
Comparing reference
Using .equals() function
Escaped string
Controlling program flow
Decision making
If, else-if, else
‘when’ expression
‘when’ as switch case
‘when’ with objects
Perform iteratively
Using for loop
The great while loop
Jumping off the branches
Handling errors and exceptions
Checked exception
Playing around functions
Useful extension function
Managing files
Scoping functions
Using ‘with’ and ‘run’ functions
Using ‘apply’ and ‘also’ function
Using ‘let’ function
Returning multiple values from the function
Pair<A, B>
Triple<A, B, C>
Destructuring declaration
Being late or lazy
lateinit
lazy
Type aliases
Type casting
Smart casting
Safe casting
Classes
Creating a class
Properties
Types of constructors
Implicit primary constructor
Primary constructor
Secondary constructor
Private constructor
Interfaces
Defining an interface
Implementing an interface
Inheritance
Visibility modifiers
Data classes
equals()/hashCode()
toString()
componentN()
copy()
Nested and inner classes
Accessing outer class inside the nested and inner class
Initialising nested and inner class
Enum classes
Sealed classes
Defining sealed class
Using sealed class
Wrapping up
Pop quiz
Answers
3. Go to the Depth of Kotlin
Structure
Kotlin’s type of system
Null safety
Safe call operator
Elvis operator (?:)
Non-null assertion (!!)
Any, Nothing, and Unit
Any
Nothing
Unit
Delegated properties
lazy
observable and vetoable
vetoable
Binding property from the map
Writing custom delegated property
Lambdas
Lambdas and functional interfaces
Higher-order functions
Using lambdas as the callback
Passing function as a parameter
Passing function lambda style
Higher order function as an extension function
Returning a function
Using callable reference
Inline function
What’s going on behind the scene of the inline function
Collections in Kotlin
List
Functional initializers
List and operator overloading
Reversing a List
Sorting Collections
Sorting List
Sorting a Map
Sorting a Set
Sequence vs Iterable
When Sequences needs to be used
Taking advantage of Generics
Why Generics?
Generic and type safety
Generics and constraints
Generics and variance
Covariance
Contravariance
Use site variance or type projection
DSL – Type-safe builders
Learn how to create DSL
Bijou yet significant Kotlin features
Import alias
Naming companion object
Changing class name
Wrapping up
Pop quiz
Answers
4. Design Patterns in Kotlin
Structure
Objective
Builder pattern
Singleton pattern
Decorator pattern
Facade pattern
Observer pattern
Chain of responsibility pattern
Wrapping up
5. Analyzing and Architecting a Meal Recipe App
Structure
Understand the requirements for a meal recipe app
User story mapping
Developing user interface
Creating layouts
ConstraintLayout
Creating layout using DSL
Theming and styling
Styles
Themes
Creating activities and fragments
Architecture component
Navigation components
Preparing navigation graph
Displaying fragments on MainActivity
Creating data repository
Reading input stream
Converting raw data into application data
Creating ViewModel with the help of generics
What are generics?
Refactor view model factory using generics
Troubleshoot your dry run
Extension function and generics
Get rid of findViewById()
Data classes
Data level classes
Presentation level classes
Dependency injection
Comparison between various DI frameworks
Using Koin
Setting up Koin
Declaring modules
Starting Koin
Injecting your dependencies
Wrapping up
6. Making Network Calls Using Coroutines
Structure
What is coroutine?
Using coroutine
Creating coroutine
Understanding the scope
Creating a Job
Canceling a Job
Managing asynchronous coroutine
Suspending a function
Measuring coroutine’s performance
sumWithoutAsync
sumWithAsync
Beyond coroutine Job – A Flow
Emit and collect a Flow
Inside Flow
Canceling a Flow
Operators in Flow
map operator
filter operator
Behaviour The behavior of Flow is sequential
Optimize the Flow using the buffer
Managing multiple flows
The zip operator
The combine operator
Operator combine without extension function
combine vs combineTransform
Exception handling in Flow
catch as an operator
Declarative catch
Connect application to the remote server
Setting up dependency
Refactoring repository layer
Retrofit, Coroutine, and Flow
Inside Repository
Inside ViewModel
Inside View
Wrapping up
7. Kotlin-ize Remaining of Your App
Structure
Error handling approaches
Handling exception inside the repository
Refactor emitting the response
Show error to the user
Approach 1: Using a sealed class
Approach 2: Using multiple observer and LiveData
Write utility using extension function
The simplest way to show and hide any view
Formatting string using an extension function
Checking internet connectivity using an extension function
Extension function and InputStream
Extension function and higher-order function
Implicit intent and extension function
Using KTX and Splitties
Convert build.gradle from Groovy to Kotlin DSL
Why one would ditch Groovy?
Pros of using Kotlin DSL
Cons of using Kotlin DSL
Step 1: Updating the Gradle distribution version
Step 2: Getting rid of all single quotes (‘)
Step 3: Changing Groovy function calls
Step 4: Updating settings.gradle
Step 5: Updating project level build.gradle
Step 6: Updating app-level build.gradle
Wrapping up
8. Testing the Kotlin Code
Structure
Application testing approach
Why I should care about tests?
Quality of code
Makes refactoring easy
Find bugs during development
Great cost saver
Enforce good structural code
Testing Pyramid
Small tests
Medium tests
Large tests
Writing unit tests using JUnit5
Features of JUnit5
Rich set of annotations
DisplayName
Grouped assertions
Asserting exceptions
Configure JUnit5 for Android app
Unit test your repository layer
Unit test suspend function
Using inner classes to group your test cases
Unit testing ViewModel and LiveData
Best practices to follow while writing test cases
Verify one scenario at a time
Make your test readable
Divide and rule
Find a good balance between unit and integration test
Fixed and shared test data
Wrapping up
9. Make Your App Production Ready
Structure
Package restructuring
Writing safe code in Kotlin
Use val over var
Use data class as POJO
Return immutable type
The static code analysis tool
Advantages of static code analysis tool
Early and frequent checks
Increases robustness of your code
Reports and modelling diagrams
detekt vs ktlint
Fine tune default config
Enabling code commenting
Exception handling
Some small yet significant improvements
Changes we did as per detekt recommendation
Removing wildcard imports
Adding missing documentation
Parameter list wrapping
Dokka as documentation engine
Dokka report
Analytics using Firebase
Wrapping up
10. Kotlin Everywhere
Structure
Kotlin ecosystem
Kotlin – Jack of all trades
Kotlin for the standalone app
Why TornadoFX
Kotlin for server-side development
Kotlin for JavaScript
Kotlin for iOS using Kotlin multiplatform
What part of the code will be shared across Android and iOS?
What tools do we need?
Create an Android application
Creating a shared module
Writing common implementation
Writing Android implementation
Writing iOS implementation
Integrating shared code in Android
Integrating shared code with iOS
Generating iOS framework from SharedCode module
Keeping SharedCode up to date
Some useful learning resources
Libraries
Websites and blogs
Wrapping up
The book hasn't received reviews yet.