├── .gradle
├── 8.0
│ ├── gc.properties
│ ├── fileChanges
│ │ └── last-build.bin
│ ├── dependencies-accessors
│ │ ├── gc.properties
│ │ └── dependencies-accessors.lock
│ ├── checksums
│ │ └── checksums.lock
│ ├── fileHashes
│ │ ├── fileHashes.bin
│ │ ├── fileHashes.lock
│ │ └── resourceHashesCache.bin
│ └── executionHistory
│ │ ├── executionHistory.bin
│ │ └── executionHistory.lock
├── vcs-1
│ └── gc.properties
├── buildOutputCleanup
│ ├── cache.properties
│ ├── outputFiles.bin
│ └── buildOutputCleanup.lock
└── file-system.probe
├── .idea
├── .name
├── compiler.xml
├── kotlinc.xml
├── vcs.xml
├── .gitignore
├── misc.xml
└── gradle.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── template
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable
│ │ │ ├── pager_0.jpg
│ │ │ ├── pager_1.jpg
│ │ │ ├── pager_2.jpg
│ │ │ ├── ic_person.xml
│ │ │ ├── ic_round_token_24.xml
│ │ │ ├── ic_flame.xml
│ │ │ └── ic_launcher_background.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_background.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_monochrome.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_background.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_monochrome.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_background.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_monochrome.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_background.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_monochrome.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_background.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_monochrome.png
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── themes.xml
│ │ │ ├── keys.xml
│ │ │ └── colors.xml
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher_round.xml
│ │ │ └── ic_launcher.xml
│ │ ├── xml
│ │ │ ├── backup_rules.xml
│ │ │ └── data_extraction_rules.xml
│ │ └── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ └── com
│ │ │ └── composables
│ │ │ └── jetpackcomposetemplate
│ │ │ ├── SampleApplication.kt
│ │ │ ├── http
│ │ │ └── HttpClientFactory.kt
│ │ │ ├── apimodel
│ │ │ ├── Urls.kt
│ │ │ └── ApiPhoto.kt
│ │ │ ├── ui
│ │ │ ├── theme
│ │ │ │ ├── Color.kt
│ │ │ │ ├── Shape.kt
│ │ │ │ ├── Type.kt
│ │ │ │ └── Theme.kt
│ │ │ ├── LoadingScreen.kt
│ │ │ ├── TransparentSystemBars.kt
│ │ │ └── ContentCard.kt
│ │ │ ├── core
│ │ │ ├── FindActivity.kt
│ │ │ ├── AppReference.kt
│ │ │ ├── AppContentProvider.kt
│ │ │ └── AbstractViewmodel.kt
│ │ │ ├── formatLongNumber.kt
│ │ │ ├── home
│ │ │ ├── HomeScreen.kt
│ │ │ ├── HomeScreenViewModel.kt
│ │ │ └── HomeTab.kt
│ │ │ ├── LockScreenOrientation.kt
│ │ │ ├── di
│ │ │ ├── HttpClientFactory.kt
│ │ │ └── DependencyInjection.kt
│ │ │ ├── MainActivity.kt
│ │ │ ├── details
│ │ │ ├── PhotoDetailsViewModel.kt
│ │ │ └── PhotoDetailsScreen.kt
│ │ │ ├── Logging.kt
│ │ │ ├── PhotosRepository.kt
│ │ │ ├── permissions
│ │ │ └── OptionalPermission.kt
│ │ │ └── Permissions.kt
│ │ └── AndroidManifest.xml
├── .gitignore
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── local.properties
├── depedencies.gradle
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/.gradle/8.0/gc.properties:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gradle/vcs-1/gc.properties:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gradle/8.0/fileChanges/last-build.bin:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | Jetpack Compose App template
--------------------------------------------------------------------------------
/.gradle/8.0/dependencies-accessors/gc.properties:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gradle/buildOutputCleanup/cache.properties:
--------------------------------------------------------------------------------
1 | #Thu Sep 14 12:24:13 WITA 2023
2 | gradle.version=8.0
3 |
--------------------------------------------------------------------------------
/.gradle/file-system.probe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/.gradle/file-system.probe
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gradle/8.0/checksums/checksums.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/.gradle/8.0/checksums/checksums.lock
--------------------------------------------------------------------------------
/.gradle/8.0/fileHashes/fileHashes.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/.gradle/8.0/fileHashes/fileHashes.bin
--------------------------------------------------------------------------------
/.gradle/8.0/fileHashes/fileHashes.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/.gradle/8.0/fileHashes/fileHashes.lock
--------------------------------------------------------------------------------
/.gradle/buildOutputCleanup/outputFiles.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/.gradle/buildOutputCleanup/outputFiles.bin
--------------------------------------------------------------------------------
/template/src/main/res/drawable/pager_0.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/drawable/pager_0.jpg
--------------------------------------------------------------------------------
/template/src/main/res/drawable/pager_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/drawable/pager_1.jpg
--------------------------------------------------------------------------------
/template/src/main/res/drawable/pager_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/drawable/pager_2.jpg
--------------------------------------------------------------------------------
/.gradle/8.0/fileHashes/resourceHashesCache.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/.gradle/8.0/fileHashes/resourceHashesCache.bin
--------------------------------------------------------------------------------
/.gradle/8.0/executionHistory/executionHistory.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/.gradle/8.0/executionHistory/executionHistory.bin
--------------------------------------------------------------------------------
/.gradle/8.0/executionHistory/executionHistory.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/.gradle/8.0/executionHistory/executionHistory.lock
--------------------------------------------------------------------------------
/.gradle/buildOutputCleanup/buildOutputCleanup.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/.gradle/buildOutputCleanup/buildOutputCleanup.lock
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/template/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Jetpack Compose App template
3 | Viewed %s times
4 |
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-hdpi/ic_launcher_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-hdpi/ic_launcher_background.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-hdpi/ic_launcher_monochrome.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-hdpi/ic_launcher_monochrome.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-mdpi/ic_launcher_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-mdpi/ic_launcher_background.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-mdpi/ic_launcher_monochrome.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-mdpi/ic_launcher_monochrome.png
--------------------------------------------------------------------------------
/.gradle/8.0/dependencies-accessors/dependencies-accessors.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/.gradle/8.0/dependencies-accessors/dependencies-accessors.lock
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-xhdpi/ic_launcher_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-xhdpi/ic_launcher_background.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-xhdpi/ic_launcher_monochrome.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-xhdpi/ic_launcher_monochrome.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-xxhdpi/ic_launcher_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-xxhdpi/ic_launcher_background.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-xxhdpi/ic_launcher_monochrome.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-xxhdpi/ic_launcher_monochrome.png
--------------------------------------------------------------------------------
/template/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-xxxhdpi/ic_launcher_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-xxxhdpi/ic_launcher_background.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-xxxhdpi/ic_launcher_monochrome.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/composablehorizons/jetpack-compose-app-template/HEAD/template/src/main/res/mipmap-xxxhdpi/ic_launcher_monochrome.png
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/SampleApplication.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate
2 |
3 | import android.app.Application
4 |
5 | class SampleApplication : Application()
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/http/HttpClientFactory.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.http
2 |
3 | import io.ktor.client.*
4 |
5 | interface HttpClientFactory {
6 | fun createHttpClient(): HttpClient
7 | }
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Dec 11 14:06:33 WITA 2022
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/template/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/apimodel/Urls.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.apimodel
2 |
3 | import kotlinx.serialization.SerialName
4 | import kotlinx.serialization.Serializable
5 |
6 | @Serializable
7 | data class Urls(
8 | @SerialName("small") val small: String,
9 | )
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/ui/theme/Color.kt:
--------------------------------------------------------------------------------
1 | package com.composables.blaze.sample.ui.theme
2 |
3 | import androidx.compose.ui.graphics.Color
4 |
5 | val Purple200 = Color(0xFFBB86FC)
6 | val Purple500 = Color(0xFF6200EE)
7 | val Purple700 = Color(0xFF3700B3)
8 | val Teal200 = Color(0xFF03DAC5)
--------------------------------------------------------------------------------
/template/src/main/res/values/keys.xml:
--------------------------------------------------------------------------------
1 |
2 | 1287053408539311
3 | fb123
4 | 23bb563982f5d4f5198e2d02b90bbd48
5 |
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/apimodel/ApiPhoto.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.apimodel
2 |
3 | import kotlinx.serialization.Serializable
4 |
5 | @Serializable
6 | data class ApiPhoto(
7 | val id: String,
8 | val description: String?,
9 | val alt_description: String,
10 | val urls: Urls,
11 | val views: Long,
12 | )
--------------------------------------------------------------------------------
/template/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/core/FindActivity.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.core
2 |
3 | import android.app.Activity
4 | import android.content.Context
5 | import android.content.ContextWrapper
6 |
7 | fun Context.findActivity(): Activity? = when (this) {
8 | is Activity -> this
9 | is ContextWrapper -> baseContext.findActivity()
10 | else -> null
11 | }
12 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | gradlePluginPortal()
4 | google()
5 | mavenCentral()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | }
15 | rootProject.name = "Jetpack Compose App template"
16 | include ':template'
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/formatLongNumber.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate
2 |
3 | import androidx.compose.runtime.Composable
4 | import androidx.compose.runtime.remember
5 | import java.text.DecimalFormat
6 |
7 | @Composable
8 | fun formatLongNumber(number: Long): String {
9 | val formatter = remember { DecimalFormat("#,###") }
10 | return formatter.format(number)
11 | }
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/ui/theme/Shape.kt:
--------------------------------------------------------------------------------
1 | package com.composables.blaze.sample.ui.theme
2 |
3 | import androidx.compose.foundation.shape.RoundedCornerShape
4 | import androidx.compose.material3.Shapes
5 | import androidx.compose.ui.unit.dp
6 |
7 | val Shapes = Shapes(
8 | small = RoundedCornerShape(4.dp),
9 | medium = RoundedCornerShape(12.dp),
10 | large = RoundedCornerShape(0.dp)
11 | )
--------------------------------------------------------------------------------
/template/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/local.properties:
--------------------------------------------------------------------------------
1 | ## This file is automatically generated by Android Studio.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file should *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 | #
7 | # Location of the SDK. This is only used by Gradle.
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | sdk.dir=/Users/alexstyl/Library/Android/sdk
11 |
--------------------------------------------------------------------------------
/template/src/main/res/drawable/ic_person.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/core/AppReference.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.core
2 |
3 | import android.app.Application
4 |
5 | object AppReference {
6 | fun requireApplication(): Application {
7 | return requireNotNull(application) {
8 | "Tried to get application before instance was ready. Make sure that the ${AppContentProvider::class.simpleName} is not disable from your AndroidManifest.xml"
9 | }
10 | }
11 |
12 | var application: Application? = null
13 | }
--------------------------------------------------------------------------------
/template/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
16 |
17 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/ui/LoadingScreen.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.ui
2 |
3 | import androidx.compose.foundation.layout.Box
4 | import androidx.compose.foundation.layout.fillMaxSize
5 | import androidx.compose.material3.CircularProgressIndicator
6 | import androidx.compose.runtime.Composable
7 | import androidx.compose.ui.Alignment
8 | import androidx.compose.ui.Modifier
9 |
10 | @Composable
11 | fun LoadingScreen() {
12 | Box(
13 | modifier = Modifier.fillMaxSize(),
14 | contentAlignment = Alignment.Center
15 | ) {
16 | CircularProgressIndicator()
17 | }
18 | }
--------------------------------------------------------------------------------
/template/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/template/src/main/res/drawable/ic_round_token_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/home/HomeScreen.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.home
2 |
3 | import androidx.compose.runtime.Composable
4 | import com.composables.jetpackcomposetemplate.destinations.PhotoDetailsScreenDestination
5 | import com.ramcosta.composedestinations.annotation.Destination
6 | import com.ramcosta.composedestinations.annotation.RootNavGraph
7 | import com.ramcosta.composedestinations.navigation.DestinationsNavigator
8 |
9 | @Destination
10 | @RootNavGraph(start = true)
11 | @Composable
12 | fun HomeScreen(navigator: DestinationsNavigator) {
13 | HomeTab(
14 | onPhotoClick = { photo ->
15 | navigator.navigate(PhotoDetailsScreenDestination(photo.id))
16 | }
17 | )
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/template/src/main/res/drawable/ic_flame.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/LockScreenOrientation.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate
2 |
3 | import androidx.compose.runtime.Composable
4 | import androidx.compose.runtime.DisposableEffect
5 | import androidx.compose.ui.platform.LocalContext
6 | import com.composables.jetpackcomposetemplate.core.findActivity
7 |
8 | @Composable
9 | fun LockScreenOrientation(orientation: Int) {
10 | val context = LocalContext.current
11 | DisposableEffect(Unit) {
12 | val activity = context.findActivity() ?: return@DisposableEffect onDispose {}
13 | val originalOrientation = activity.requestedOrientation
14 | activity.requestedOrientation = orientation
15 | onDispose {
16 | // restore original orientation when view disappears
17 | activity.requestedOrientation = originalOrientation
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/di/HttpClientFactory.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.di
2 |
3 | import com.composables.jetpackcomposetemplate.http.HttpClientFactory
4 | import io.ktor.client.*
5 | import io.ktor.client.engine.cio.*
6 | import io.ktor.client.plugins.contentnegotiation.*
7 | import io.ktor.serialization.kotlinx.json.*
8 | import kotlinx.serialization.json.Json
9 |
10 | private val httpClient = object : HttpClientFactory {
11 | override fun createHttpClient(): HttpClient {
12 | return HttpClient(CIO) {
13 | install(ContentNegotiation) {
14 | json(Json {
15 | encodeDefaults = true
16 | ignoreUnknownKeys = true
17 | })
18 | }
19 | }
20 | }
21 | }
22 |
23 | fun httpClientFactory(): HttpClientFactory {
24 | return httpClient
25 | }
26 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate
2 |
3 | import android.os.Bundle
4 | import androidx.activity.ComponentActivity
5 | import androidx.activity.compose.setContent
6 | import androidx.core.view.WindowCompat
7 | import com.composables.blaze.sample.ui.theme.AppTheme
8 | import com.composables.jetpackcomposetemplate.PermissionRequired
9 | import com.ramcosta.composedestinations.DestinationsNavHost
10 |
11 |
12 | class MainActivity : ComponentActivity() {
13 |
14 | override fun onCreate(savedInstanceState: Bundle?) {
15 | super.onCreate(savedInstanceState)
16 | WindowCompat.setDecorFitsSystemWindows(window, false)
17 | setContent {
18 | AppTheme {
19 | PermissionRequired(
20 | onDenyClick = { finish() },
21 | guardedContent = { DestinationsNavHost(navGraph = NavGraphs.root) }
22 | )
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/ui/theme/Type.kt:
--------------------------------------------------------------------------------
1 | package com.composables.blaze.sample.ui.theme
2 |
3 | import androidx.compose.material3.Typography
4 | import androidx.compose.ui.text.TextStyle
5 | import androidx.compose.ui.text.font.FontFamily
6 | import androidx.compose.ui.text.font.FontWeight
7 | import androidx.compose.ui.unit.sp
8 |
9 | val Typography = Typography(
10 | headlineLarge = TextStyle(
11 | fontWeight = FontWeight.SemiBold,
12 | fontSize = 28.sp,
13 | letterSpacing = (-1.5).sp
14 | ),
15 | headlineMedium = TextStyle(
16 | fontWeight = FontWeight.Normal,
17 | fontSize = 20.sp,
18 | letterSpacing = 0.15.sp,
19 | ),
20 | bodyMedium = TextStyle(
21 | fontFamily = FontFamily.Default,
22 | fontWeight = FontWeight.Medium,
23 | fontSize = 16.sp
24 | ),
25 | bodySmall = TextStyle(
26 | fontFamily = FontFamily.Default,
27 | fontWeight = FontWeight.Normal,
28 | fontSize = 14.sp,
29 | ))
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/ui/TransparentSystemBars.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.ui
2 |
3 | import androidx.compose.material3.ColorScheme
4 | import androidx.compose.runtime.Composable
5 | import androidx.compose.runtime.DisposableEffect
6 | import androidx.compose.ui.graphics.Color
7 | import com.google.accompanist.systemuicontroller.rememberSystemUiController
8 |
9 | @Composable
10 | fun TransparentSystemBars(
11 | colors: ColorScheme,
12 | useDarkIcons: Boolean,
13 | ) {
14 | val systemUiController = rememberSystemUiController()
15 |
16 | val color = colors.primaryContainer
17 |
18 | DisposableEffect(systemUiController, useDarkIcons) {
19 | systemUiController.setStatusBarColor(color = Color.Transparent,
20 | darkIcons = useDarkIcons
21 | )
22 | systemUiController.setNavigationBarColor(
23 | color,
24 | darkIcons = useDarkIcons,
25 | navigationBarContrastEnforced = false
26 | )
27 |
28 | onDispose {}
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/di/DependencyInjection.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate
2 |
3 | import android.app.Application
4 | import com.composables.jetpackcomposetemplate.core.AppReference
5 | import com.composables.jetpackcomposetemplate.details.PhotoDetailsViewModel
6 | import com.composables.jetpackcomposetemplate.di.httpClientFactory
7 | import com.composables.jetpackcomposetemplate.home.HomeScreenViewModel
8 | import com.composables.jetpackcomposetemplate.home.PhotoId
9 |
10 | fun applicationContext(): Application {
11 | return AppReference.requireApplication()
12 | }
13 |
14 | fun homeScreenViewModel(): HomeScreenViewModel {
15 | return HomeScreenViewModel(photosRepository())
16 | }
17 |
18 | fun photosRepository(): PhotosRepository {
19 | val client = httpClientFactory().createHttpClient()
20 | return UnsplashPhotosRepository(client)
21 | }
22 |
23 |
24 | fun photoDetailsViewModel(photoId: PhotoId): PhotoDetailsViewModel {
25 | return PhotoDetailsViewModel(photoId = photoId, photosRepository = photosRepository())
26 | }
--------------------------------------------------------------------------------
/template/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
23 |
24 | -keepnames @kotlin.Metadata class com.composables.jetpackcomposetemplate.apimodel.**
25 | -keep class com.composables.jetpackcomposetemplate.apimodel.** { *; }
26 | -keepclassmembers class com.composables.jetpackcomposetemplate.apimodel.** { *; }
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/home/HomeScreenViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.home
2 |
3 | import androidx.lifecycle.viewModelScope
4 | import com.composables.jetpackcomposetemplate.PhotosRepository
5 | import com.composables.jetpackcomposetemplate.core.AbstractViewModel
6 | import kotlinx.coroutines.launch
7 |
8 |
9 | typealias PhotoId = String
10 |
11 | data class Photo(
12 | val url: String,
13 | val description: String,
14 | val views: Long,
15 | val id: PhotoId,
16 | )
17 |
18 | sealed interface HomeScreenState {
19 | object Loading : HomeScreenState
20 | data class Loaded(val photos: List) : HomeScreenState
21 | object Error : HomeScreenState
22 | }
23 |
24 | class HomeScreenViewModel(
25 | private val photosRepository: PhotosRepository,
26 | ) : AbstractViewModel(
27 | startWith = HomeScreenState.Loading
28 | ) {
29 |
30 | init {
31 | viewModelScope.launch {
32 | val photos = photosRepository.loadAllPhotos()
33 | if (photos == null) {
34 | emitState(HomeScreenState.Error)
35 | } else {
36 | emitState(HomeScreenState.Loaded(photos))
37 | }
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/ui/theme/Theme.kt:
--------------------------------------------------------------------------------
1 | package com.composables.blaze.sample.ui.theme
2 |
3 | import android.content.pm.ActivityInfo
4 | import androidx.compose.material3.MaterialTheme
5 | import androidx.compose.material3.lightColorScheme
6 | import androidx.compose.runtime.Composable
7 | import com.composables.jetpackcomposetemplate.LockScreenOrientation
8 | import com.composables.jetpackcomposetemplate.ui.TransparentSystemBars
9 |
10 | private val LightColorPalette = lightColorScheme(
11 | primary = Purple500,
12 | secondary = Teal200
13 | )
14 |
15 | @Composable
16 | fun AppTheme(
17 | edgeToEdge: Boolean = true,
18 | content: @Composable () -> Unit,
19 | ) {
20 | val colors = LightColorPalette
21 | if (edgeToEdge) {
22 | TransparentSystemBars(
23 | colors,
24 | // currently the sample app does not support dark theme
25 | // because of this, we want the icons to be dark (as the bars will be light)
26 | useDarkIcons = true
27 | )
28 | }
29 | LockScreenOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
30 | MaterialTheme(
31 | colorScheme = colors,
32 | typography = Typography,
33 | shapes = Shapes,
34 | content = content
35 | )
36 | }
37 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/details/PhotoDetailsViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.details
2 |
3 | import androidx.lifecycle.viewModelScope
4 | import com.composables.jetpackcomposetemplate.PhotosRepository
5 | import com.composables.jetpackcomposetemplate.core.AbstractViewModel
6 | import com.composables.jetpackcomposetemplate.home.Photo
7 | import com.composables.jetpackcomposetemplate.home.PhotoId
8 | import kotlinx.coroutines.launch
9 |
10 |
11 | sealed interface PhotoDetailsState {
12 | object Loading : PhotoDetailsState
13 | data class Loaded(val photo: Photo, val favorite: Boolean) : PhotoDetailsState
14 | object Error : PhotoDetailsState
15 | }
16 |
17 | class PhotoDetailsViewModel(
18 | private val photoId: PhotoId,
19 | private val photosRepository: PhotosRepository,
20 | ) : AbstractViewModel(PhotoDetailsState.Loading) {
21 | init {
22 | viewModelScope.launch {
23 | val photo = photosRepository.lookupPhoto(photoId)
24 | val state = if (photo == null) {
25 | PhotoDetailsState.Error
26 | } else {
27 | PhotoDetailsState.Loaded(photo, favorite = false)
28 | }
29 | emitState(state)
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/depedencies.gradle:
--------------------------------------------------------------------------------
1 | // contains all dependency versions shared in apptemplate and sample module
2 | // do not modify this file, to avoid conflicts
3 | ext {
4 | androidCompileSdk = 33
5 | androidMinSdk = 21
6 |
7 | composeUiVersion = '1.3.1'
8 | composeCompilerVersion = '1.4.2'
9 | googleServicesVersion = '4.3.15'
10 | crashlyticsPluginVersion = '2.9.2'
11 | agpVersion = '7.4.1'
12 |
13 | javaVersion = JavaVersion.VERSION_11
14 | kotlinVersion = '1.8.10'
15 | ktorVersion = '2.2.1'
16 | accompanistVersion = '0.28.0'
17 | coilVersion = '2.2.2'
18 | junitVersion = '4.13.2'
19 | facebookSdkVersion = '14.1.0'
20 | googlePlayReviewVersion = '2.0.1'
21 | datastoreVersion = '1.0.0'
22 | billingVersion = '5.1.0'
23 | firebaseBomVersion = '31.1.1'
24 | playServicesCoroutinesVersion = '1.6.4'
25 | coreVersion = '1.9.0'
26 | kotlinXSerializationVersion = '1.4.1'
27 | lifecycleVersion = '2.5.1'
28 | activityComposeVersion = '1.6.1'
29 | material3Version = '1.0.1'
30 | playServicesAuthVersion = '20.4.1'
31 |
32 | destinationsVersion = '1.7.27-beta'
33 | dokkaVersion = '1.7.20'
34 | kspVersion = '1.8.10-1.0.9'
35 |
36 | assertJVersion = '3.24.2'
37 | coroutinesVersion = "1.6.4"
38 | coreTestingVersion = "2.1.0"
39 | turbineVersion = '0.12.1'
40 | testRulesVersion = '1.5.0'
41 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/core/AppContentProvider.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.core
2 |
3 | import android.app.Application
4 | import android.content.ContentProvider
5 | import android.content.ContentValues
6 | import android.database.Cursor
7 | import android.net.Uri
8 | import com.composables.jetpackcomposetemplate.BuildConfig
9 | import com.composables.jetpackcomposetemplate.setLogging
10 |
11 | class AppContentProvider : ContentProvider() {
12 | override fun onCreate(): Boolean {
13 | setLogging(BuildConfig.DEBUG)
14 | AppReference.application = requireNotNull(context) as Application
15 | return true
16 | }
17 |
18 | override fun query(
19 | uri: Uri,
20 | projection: Array?,
21 | selection: String?,
22 | selectionArgs: Array?,
23 | sortOrder: String?,
24 | ): Cursor? {
25 | return null
26 | }
27 |
28 | override fun getType(uri: Uri): String? {
29 | return null
30 | }
31 |
32 | override fun insert(uri: Uri, values: ContentValues?): Uri? {
33 | return null
34 | }
35 |
36 | override fun delete(uri: Uri, selection: String?, selectionArgs: Array?): Int {
37 | return -1
38 | }
39 |
40 | override fun update(
41 | uri: Uri,
42 | values: ContentValues?,
43 | selection: String?,
44 | selectionArgs: Array?,
45 | ): Int {
46 | return -1
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/template/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
34 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/template/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/Logging.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate
2 |
3 | import android.annotation.SuppressLint
4 | import android.os.Build
5 | import android.util.Log
6 | import androidx.annotation.ChecksSdkIntAtLeast
7 |
8 | private const val TAG = "Composables"
9 | private var enabled = BuildConfig.DEBUG
10 |
11 | @ChecksSdkIntAtLeast(api = Build.VERSION_CODES.BASE_1_1)
12 | @SuppressLint("ObsoleteSdkInt")
13 | // checking the SDK to see if we are running on Android or not.
14 | // when running on android the SDK_INT will always be greater than BASE_1_1
15 | // running on a computer, the SDK_INT will always be 0
16 | private val isAndroid = Build.VERSION.SDK_INT >= Build.VERSION_CODES.BASE_1_1
17 |
18 | fun setLogging(enabled: Boolean) {
19 | com.composables.jetpackcomposetemplate.enabled = enabled
20 | }
21 |
22 | fun debugLn(message: () -> Any) {
23 | if (enabled) {
24 | if (isAndroid) {
25 | Log.d(TAG, message().toString())
26 | } else {
27 | println(message().toString())
28 | }
29 | }
30 | }
31 |
32 | fun errorln(ex: Throwable) {
33 | if (enabled) {
34 | if (isAndroid) {
35 | Log.e(TAG, null, ex)
36 | } else {
37 | ex.printStackTrace()
38 | }
39 | }
40 | }
41 |
42 | fun errorln(message: () -> Any) {
43 | if (enabled) {
44 | if (isAndroid) {
45 | Log.e(TAG, message().toString())
46 | } else {
47 | System.err.println(message().toString())
48 | }
49 | }
50 | }
51 |
52 |
53 | fun verboseLn(message: () -> Any) {
54 | if (enabled) {
55 | if (isAndroid) {
56 | Log.v(TAG, message().toString())
57 | } else {
58 | println(message().toString())
59 | }
60 | }
61 | }
62 |
63 | fun warnln(message: () -> Any) {
64 | if (enabled) {
65 | if (isAndroid) {
66 | Log.w(TAG, message().toString())
67 | } else {
68 | println(message().toString())
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/core/AbstractViewmodel.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.core
2 |
3 | import androidx.lifecycle.ViewModel
4 | import androidx.lifecycle.viewModelScope
5 | import com.composables.jetpackcomposetemplate.verboseLn
6 | import kotlinx.coroutines.Dispatchers
7 | import kotlinx.coroutines.channels.Channel
8 | import kotlinx.coroutines.flow.*
9 | import kotlinx.coroutines.launch
10 | import kotlinx.coroutines.withContext
11 |
12 | abstract class AbstractViewModel(
13 | startWith: State,
14 | ) : ViewModel() {
15 |
16 | private val innerState = MutableStateFlow(startWith)
17 | val state: StateFlow = innerState.asStateFlow()
18 |
19 | private val internalEvents = Channel(Channel.BUFFERED)
20 | val events = internalEvents.receiveAsFlow()
21 |
22 | private val internalUserActions = MutableSharedFlow(
23 | extraBufferCapacity = 1
24 | )
25 | private val userActions: Flow = internalUserActions.asSharedFlow()
26 |
27 | init {
28 | viewModelScope.launch {
29 | userActions.collect {
30 | processUserAction(it)
31 | }
32 | }
33 | }
34 |
35 | open suspend fun processUserAction(userAction: UserAction) {
36 |
37 | }
38 |
39 | protected suspend fun emitState(state: State) {
40 | withContext(Dispatchers.Main.immediate) {
41 | verboseLn { "${viewModelName()} ⬅️ ${simpleName(state)}" }
42 | innerState.emit(state)
43 | }
44 | }
45 |
46 | protected suspend fun emitEvent(event: Event) {
47 | withContext(Dispatchers.Main.immediate) {
48 | verboseLn { "${viewModelName()} ⚡️ ${simpleName(event)}" }
49 | internalEvents.trySend(event)
50 | }
51 | }
52 |
53 | fun pushUserAction(userAction: UserAction) {
54 | viewModelScope.launch {
55 | withContext(Dispatchers.Main.immediate) {
56 | verboseLn { "${viewModelName()} ➡️ ${simpleName(userAction)}" }
57 | internalUserActions.emit(userAction)
58 | }
59 | }
60 | }
61 |
62 | private fun simpleName(userAction: Any): String {
63 | return if (userAction.javaClass.kotlin.objectInstance != null) {
64 | userAction::class.simpleName ?: "object"
65 | } else {
66 | userAction.toString()
67 | }
68 | }
69 |
70 | private fun viewModelName(): String =
71 | this@AbstractViewModel::class.simpleName ?: "object"
72 | }
73 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/PhotosRepository.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate
2 |
3 | import com.composables.jetpackcomposetemplate.apimodel.ApiPhoto
4 | import com.composables.jetpackcomposetemplate.home.Photo
5 | import com.composables.jetpackcomposetemplate.home.PhotoId
6 | import io.ktor.client.*
7 | import io.ktor.client.call.*
8 | import io.ktor.client.request.*
9 | import kotlinx.coroutines.Dispatchers
10 | import kotlinx.coroutines.runBlocking
11 | import kotlinx.coroutines.withContext
12 |
13 | interface PhotosRepository {
14 | suspend fun loadAllPhotos(): List?
15 | suspend fun lookupPhoto(id: PhotoId): Photo?
16 | }
17 |
18 | fun main(): Unit = runBlocking {
19 | val repo = photosRepository()
20 | repo.loadAllPhotos()
21 | }
22 |
23 | class UnsplashPhotosRepository(
24 | private val client: HttpClient,
25 | ) : PhotosRepository {
26 |
27 | override suspend fun loadAllPhotos(): List? = withContext(Dispatchers.IO) {
28 | val result = kotlin.runCatching {
29 | val response = client.get(
30 | "https://api.unsplash.com/photos/random?query=landscape&count=100"
31 | ) {
32 | headers {
33 | append("Authorization", "Client-ID $UNSPLASH_API_KEY")
34 | }
35 | }
36 |
37 | response
38 | .body>()
39 | .map {
40 | Photo(
41 | url = it.urls.small,
42 | description = it.description ?: it.alt_description,
43 | id = it.id,
44 | views = it.views
45 | )
46 | }
47 | }
48 | result.getOrNull()
49 | }
50 |
51 | override suspend fun lookupPhoto(id: PhotoId): Photo? {
52 | return kotlin.runCatching {
53 | val response = client.get(
54 | "https://api.unsplash.com/photos/${id}"
55 | ) {
56 | headers {
57 | append("Authorization", "Client-ID $UNSPLASH_API_KEY")
58 | }
59 | }
60 |
61 | response
62 | .body()
63 | .let {
64 | Photo(
65 | url = it.urls.small,
66 | description = it.description ?: it.alt_description,
67 | id = it.id,
68 | views = it.views
69 | )
70 | }
71 | }.getOrNull()
72 | }
73 |
74 | private companion object {
75 | // Key for demo purposes only. Do not use this key in your own apps
76 | // Get your own key at https://unsplash.com/developers
77 | const val UNSPLASH_API_KEY = "3atFjlj2qw8x82B2LSvBkX6m_xn7BK9f8xotBBE2M4w"
78 | }
79 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Jetpack Compose App Template
2 |
3 | A pragmatic Jetpack Compose app template to build lean apps with. It contains everything you need to get you up and running build Android apps using Jetpack Compose.
4 |
5 | This template is not meant for educational purposes with best practices in mind. Instead it is meant to be a pragmatic template that you can use to build your apps with.
6 |
7 | ## Overview
8 |
9 | ### Dependency Injection
10 |
11 | There is no dependency injection framework used. Instead you will need to create your dependencies manually. Do not worry it is much simpler and faster than you think.
12 |
13 | How to inject a ViewModel:
14 |
15 | Create your factory function (see `DependencyInjection.kt`):
16 |
17 | ```kotlin
18 | fun homeScreenViewModel(): HomeScreenViewModel {
19 | return HomeScreenViewModel(photosRepository())
20 | }
21 | ```
22 |
23 | use it in your screen level `@Composable` like this:
24 |
25 | ```kotlin
26 | val homeViewModel = viewModel { homeScreenViewModel() }
27 | ```
28 |
29 | ### View Models
30 |
31 | The template comes with an opinionated subclass of AndroidX' ViewModel called `AbstractViewModel`.
32 |
33 | It setups the boilerplate you need to handle states, events and user actions in a strongly typed fashion. See `HomeScreenViewModel.kt`
34 |
35 | Here is the signature:
36 | ```kotlin
37 | abstract class AbstractViewModel(
38 | startWith: State,
39 | )
40 | ```
41 |
42 | you can use it like this:
43 |
44 | ```kotlin
45 | class HomeScreenViewModel(
46 | private val photosRepository: PhotosRepository,
47 | ) : AbstractViewModel(
48 | startWith = HomeScreenState.Loading
49 | )
50 | ```
51 |
52 | to bootstrap your `ViewModel` and start emitting states. See the `PhotoDetailsViewModel.kt` for a more complex example.
53 |
54 | ### Navigation
55 |
56 | The template uses [`Compose Destinations`](https://github.com/raamcosta/compose-destinations/) to navigate across screens.
57 |
58 | This specific library is used as it provides a simple and type-safe way to navigate across screens, and saves you so much time from writing boilerplate code.
59 |
60 | See the original repo for more information.
61 |
62 | ### Permissions
63 |
64 | Permissions are handled for you automatically. Instead of poluting your app with permissions checks, the template guards the app's content with a permission check:
65 | ```kotlin
66 | AppTheme {
67 | PermissionRequired(
68 | onDenyClick = { finish() },
69 | guardedContent = { /* Your app's content here */ }
70 | )
71 | }
72 | ```
73 |
74 | See `Permissions.kt` for more info.
75 |
76 | #### Optional permissions
77 |
78 | The template comes with an optional permissions launcher that you can use for permissions that should not block the user experience.
79 |
80 | See `OptionalPermission.kt`
81 |
82 | ## Bring your Jetpack Compose apps to life ultra-fast
83 |
84 | With professionally crafted components, screens and tools at [Composables.com](https://www.composables.com).
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/permissions/OptionalPermission.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.permissions
2 |
3 | import android.content.Context
4 | import android.content.Intent
5 | import android.content.pm.PackageManager
6 | import android.net.Uri
7 | import android.provider.Settings
8 | import androidx.activity.compose.rememberLauncherForActivityResult
9 | import androidx.activity.result.contract.ActivityResultContracts.RequestPermission
10 | import androidx.compose.material3.SnackbarDuration
11 | import androidx.compose.material3.SnackbarHostState
12 | import androidx.compose.material3.SnackbarResult
13 | import androidx.compose.runtime.Composable
14 | import androidx.compose.runtime.remember
15 | import androidx.compose.runtime.rememberCoroutineScope
16 | import androidx.compose.ui.platform.LocalContext
17 | import androidx.core.app.ActivityCompat
18 | import androidx.core.content.ContextCompat
19 | import com.composables.jetpackcomposetemplate.core.findActivity
20 | import kotlinx.coroutines.launch
21 |
22 | @Composable
23 | fun rememberRequestOptionalPermissionLauncher(
24 | permission: String,
25 | snackbarHostState: SnackbarHostState,
26 | onGranted: () -> Unit,
27 | ): RequestOptionalPermissionLauncher {
28 | val launcher = rememberLauncherForActivityResult(RequestPermission(), onResult = { isGranted ->
29 | if (isGranted) {
30 | onGranted()
31 | }
32 | })
33 | val activity = requireNotNull(LocalContext.current.findActivity()) {
34 | "You tried to use rememberRequestOptionalPermissionLauncher() from a composable that is not linked to an Activity." +
35 | " An activity is required to use permissions"
36 | }
37 | val scope = rememberCoroutineScope()
38 |
39 | return remember(snackbarHostState, activity) {
40 | RequestOptionalPermissionLauncher(
41 | onLaunch = {
42 | when {
43 | hasPermission(permission, activity) -> onGranted()
44 | ActivityCompat.shouldShowRequestPermissionRationale(activity, permission) -> {
45 | scope.launch {
46 | val result = snackbarHostState.showSnackbar(
47 | message = "Permission required",
48 | actionLabel = "Go to settings",
49 | duration = SnackbarDuration.Short
50 | )
51 | if (result == SnackbarResult.ActionPerformed) {
52 | val intent = Intent(
53 | Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
54 | Uri.fromParts("package", activity.packageName, null)
55 | )
56 | activity.startActivity(intent)
57 | }
58 | }
59 | }
60 | else -> {
61 | launcher.launch(permission)
62 | }
63 | }
64 | })
65 | }
66 | }
67 |
68 | private fun hasPermission(permission: String, appContext: Context) =
69 | ContextCompat.checkSelfPermission(
70 | appContext, permission) == PackageManager.PERMISSION_GRANTED
71 |
72 | class RequestOptionalPermissionLauncher(
73 | private val onLaunch: () -> Unit,
74 | ) {
75 | fun launch() {
76 | onLaunch()
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/home/HomeTab.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.home
2 |
3 | import androidx.compose.foundation.background
4 | import androidx.compose.foundation.layout.Arrangement
5 | import androidx.compose.foundation.layout.Box
6 | import androidx.compose.foundation.layout.Column
7 | import androidx.compose.foundation.layout.PaddingValues
8 | import androidx.compose.foundation.layout.fillMaxSize
9 | import androidx.compose.foundation.layout.fillMaxWidth
10 | import androidx.compose.foundation.layout.statusBarsPadding
11 | import androidx.compose.foundation.lazy.LazyColumn
12 | import androidx.compose.foundation.lazy.items
13 | import androidx.compose.material3.MaterialTheme
14 | import androidx.compose.material3.Text
15 | import androidx.compose.runtime.Composable
16 | import androidx.compose.runtime.collectAsState
17 | import androidx.compose.runtime.getValue
18 | import androidx.compose.ui.Alignment
19 | import androidx.compose.ui.Modifier
20 | import androidx.compose.ui.res.stringResource
21 | import androidx.compose.ui.text.style.TextOverflow
22 | import androidx.compose.ui.unit.dp
23 | import androidx.lifecycle.viewmodel.compose.viewModel
24 | import com.composables.jetpackcomposetemplate.formatLongNumber
25 | import com.composables.jetpackcomposetemplate.homeScreenViewModel
26 | import com.composables.jetpackcomposetemplate.R
27 | import com.composables.jetpackcomposetemplate.ui.ContentCard
28 | import com.composables.jetpackcomposetemplate.ui.LoadingScreen
29 |
30 | @Composable
31 | fun HomeTab(
32 | onPhotoClick: (Photo) -> Unit,
33 | ) {
34 | val homeViewModel = viewModel { homeScreenViewModel() }
35 |
36 | val state by homeViewModel.state.collectAsState()
37 |
38 | when (val currentState = state) {
39 | is HomeScreenState.Loaded -> LoadedScreen(
40 | currentState.photos,
41 | onPhotoClick = onPhotoClick
42 | )
43 |
44 | HomeScreenState.Loading -> LoadingScreen()
45 | HomeScreenState.Error -> ErrorScreen()
46 | }
47 | }
48 |
49 | @Composable
50 | private fun ErrorScreen() {
51 | Box(
52 | Modifier
53 | .fillMaxSize()
54 | .background(MaterialTheme.colorScheme.background),
55 | contentAlignment = Alignment.Center
56 | ) {
57 | Column(
58 | horizontalAlignment = Alignment.CenterHorizontally,
59 | verticalArrangement = Arrangement.spacedBy(8.dp)
60 | ) {
61 | Text(
62 | "Couldn't load photos right now",
63 | style = MaterialTheme.typography.headlineMedium
64 | )
65 | Text(
66 | "Try again in a while",
67 | style = MaterialTheme.typography.headlineLarge
68 | )
69 | }
70 | }
71 | }
72 |
73 | @Composable
74 | fun LoadedScreen(photos: List, onPhotoClick: (Photo) -> Unit) {
75 | LazyColumn(
76 | Modifier
77 | .fillMaxSize()
78 | .statusBarsPadding(),
79 | contentPadding = PaddingValues(horizontal = 16.dp, vertical = 16.dp),
80 | verticalArrangement = Arrangement.spacedBy(8.dp),
81 | ) {
82 | items(photos) { photo ->
83 | ContentCard(
84 | modifier = Modifier.fillMaxWidth(),
85 | imageUrl = photo.url,
86 | onClick = {
87 | onPhotoClick(photo)
88 | },
89 | imageContentDescription = photo.description,
90 | title = photo.description,
91 | maxLines = 3,
92 | textOverflow = TextOverflow.Ellipsis,
93 | subtitle = stringResource(R.string.views_x, formatLongNumber(photo.views))
94 | )
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/ui/ContentCard.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.ui
2 |
3 | import androidx.compose.foundation.layout.*
4 | import androidx.compose.material3.Card
5 | import androidx.compose.material3.LocalTextStyle
6 | import androidx.compose.material3.MaterialTheme
7 | import androidx.compose.material3.Text
8 | import androidx.compose.runtime.Composable
9 | import androidx.compose.runtime.CompositionLocalProvider
10 | import androidx.compose.ui.Modifier
11 | import androidx.compose.ui.draw.clip
12 | import androidx.compose.ui.layout.ContentScale
13 | import androidx.compose.ui.platform.LocalContext
14 | import androidx.compose.ui.text.font.FontWeight
15 | import androidx.compose.ui.text.style.TextOverflow
16 | import androidx.compose.ui.unit.dp
17 | import coil.compose.AsyncImage
18 | import coil.request.ImageRequest
19 |
20 | @Composable
21 | fun ContentCard(
22 | modifier: Modifier = Modifier,
23 | title: @Composable () -> Unit = {},
24 | subtitle: @Composable () -> Unit = {},
25 | text: @Composable () -> Unit,
26 | onClick: () -> Unit,
27 | enabled: Boolean = true,
28 | ) {
29 | Card(modifier = modifier, enabled = enabled, onClick = onClick) {
30 | Column(Modifier.fillMaxSize()) {
31 | Column(Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) {
32 | CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.headlineLarge) {
33 | title()
34 | }
35 | CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyLarge) {
36 | subtitle()
37 | }
38 | Spacer(Modifier.height(8.dp))
39 | CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyLarge) {
40 | text()
41 | }
42 | }
43 | }
44 | }
45 | }
46 |
47 | @Composable
48 | fun ContentCard(
49 | modifier: Modifier = Modifier,
50 | onClick: () -> Unit,
51 | enabled: Boolean = true,
52 | imageUrl: String,
53 | imageContentDescription: String?,
54 | ) {
55 | val context = LocalContext.current
56 |
57 | Card(modifier = modifier, enabled = enabled, onClick = onClick) {
58 | Column(Modifier.fillMaxWidth()) {
59 | AsyncImage(model = ImageRequest.Builder(context)
60 | .data(imageUrl)
61 | .crossfade(true)
62 | .build(),
63 | contentDescription = imageContentDescription,
64 | contentScale = ContentScale.Crop,
65 | modifier = Modifier
66 | .clip(MaterialTheme.shapes.medium)
67 | .aspectRatio(16 / 9f))
68 | }
69 | }
70 | }
71 |
72 | @Composable
73 | fun ContentCard(
74 | modifier: Modifier = Modifier,
75 | onClick: () -> Unit,
76 | enabled: Boolean = true,
77 | imageUrl: String,
78 | imageContentDescription: String?,
79 | title: String,
80 | subtitle: String,
81 | maxLines: Int = Int.MAX_VALUE,
82 | textOverflow: TextOverflow = TextOverflow.Clip
83 | ) {
84 | val context = LocalContext.current
85 |
86 | Card(modifier = modifier, enabled = enabled, onClick = onClick) {
87 | Column(Modifier.fillMaxWidth()) {
88 | AsyncImage(model = ImageRequest.Builder(context)
89 | .data(imageUrl)
90 | .crossfade(true)
91 | .build(),
92 | contentDescription = imageContentDescription,
93 | contentScale = ContentScale.Crop,
94 | modifier = Modifier
95 | .clip(MaterialTheme.shapes.medium)
96 | .aspectRatio(16 / 9f))
97 | Column(Modifier.padding(16.dp)) {
98 | Text(title,
99 | style = MaterialTheme.typography.bodyMedium,
100 | fontWeight = FontWeight.Bold,
101 | maxLines = maxLines,
102 | overflow = textOverflow
103 | )
104 | Spacer(Modifier.height(8.dp))
105 | Text(subtitle, style = MaterialTheme.typography.bodySmall)
106 | }
107 | }
108 | }
109 | }
110 |
111 |
--------------------------------------------------------------------------------
/template/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'org.jetbrains.kotlin.android'
4 | id 'org.jetbrains.kotlin.plugin.serialization' version "${kotlinVersion}"
5 | id 'com.google.devtools.ksp' version "${kspVersion}"
6 | }
7 |
8 | android {
9 | namespace 'com.composables.jetpackcomposetemplate'
10 | compileSdk androidCompileSdk
11 |
12 | defaultConfig {
13 | applicationId "com.composables.jetpackcomposetemplate"
14 | minSdk androidMinSdk
15 | targetSdk androidCompileSdk
16 | versionCode 1
17 | versionName "1.0"
18 |
19 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
20 | vectorDrawables {
21 | useSupportLibrary true
22 | }
23 | }
24 |
25 | buildTypes {
26 | release {
27 | debuggable false
28 | minifyEnabled true
29 | shrinkResources true
30 |
31 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
32 | }
33 | debug {
34 | minifyEnabled false
35 | }
36 | }
37 | compileOptions {
38 | sourceCompatibility javaVersion
39 | targetCompatibility javaVersion
40 | }
41 | kotlinOptions {
42 | jvmTarget = javaVersion.toString()
43 | freeCompilerArgs += [
44 | '-opt-in=androidx.compose.material3.ExperimentalMaterial3Api',
45 | '-opt-in=androidx.compose.animation.ExperimentalAnimationApi',
46 | '-opt-in=com.google.accompanist.permissions.ExperimentalPermissionsApi',
47 | '-opt-in=androidx.compose.ui.ExperimentalComposeUiApi',
48 | '-opt-in=com.google.accompanist.pager.ExperimentalPagerApi',
49 | ]
50 | }
51 | buildFeatures {
52 | compose true
53 | }
54 | composeOptions {
55 | kotlinCompilerExtensionVersion composeCompilerVersion
56 | }
57 |
58 | packagingOptions {
59 | resources {
60 | excludes += '/META-INF/{AL2.0,LGPL2.1}'
61 | }
62 | }
63 | }
64 |
65 | dependencies {
66 | implementation "androidx.activity:activity-compose:${activityComposeVersion}"
67 | implementation "androidx.compose.ui:ui:$composeUiVersion"
68 | implementation "androidx.compose.ui:ui-tooling-preview:$composeUiVersion"
69 | implementation "androidx.compose.material3:material3:${material3Version}"
70 | implementation "androidx.compose.material3:material3-window-size-class:1.1.0"
71 |
72 |
73 | implementation "com.google.accompanist:accompanist-permissions:${accompanistVersion}"
74 |
75 |
76 | implementation "io.github.raamcosta.compose-destinations:core:$destinationsVersion"
77 | ksp "io.github.raamcosta.compose-destinations:ksp:$destinationsVersion"
78 |
79 | implementation "com.google.accompanist:accompanist-systemuicontroller:$accompanistVersion"
80 | implementation "com.google.accompanist:accompanist-permissions:$accompanistVersion"
81 |
82 |
83 | implementation "io.ktor:ktor-client-core:$ktorVersion"
84 | implementation "io.ktor:ktor-client-cio:$ktorVersion"
85 | implementation "io.ktor:ktor-client-content-negotiation:$ktorVersion"
86 | implementation "io.ktor:ktor-serialization-kotlinx-json:$ktorVersion"
87 | implementation "io.coil-kt:coil-compose:${coilVersion}"
88 |
89 | testImplementation "junit:junit:${junitVersion}"
90 | testImplementation("org.assertj:assertj-core:${assertJVersion}")
91 | testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion"
92 | testImplementation "androidx.arch.core:core-testing:${coreTestingVersion}"
93 | testImplementation "app.cash.turbine:turbine:${turbineVersion}"
94 |
95 | androidTestImplementation "androidx.test:rules:${testRulesVersion}"
96 | androidTestImplementation "junit:junit:${junitVersion}"
97 | androidTestImplementation("org.assertj:assertj-core:${assertJVersion}")
98 | androidTestImplementation("androidx.compose.ui:ui-test-junit4:$composeUiVersion")
99 | androidTestImplementation("io.ktor:ktor-client-mock:$ktorVersion")
100 |
101 | androidTestImplementation("io.ktor:ktor-client-mock:$ktorVersion")
102 | debugImplementation "org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}"
103 | }
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/Permissions.kt:
--------------------------------------------------------------------------------
1 | @file:OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
2 |
3 | package com.composables.jetpackcomposetemplate
4 |
5 | import android.Manifest
6 | import android.app.Activity
7 | import androidx.compose.foundation.layout.Box
8 | import androidx.compose.foundation.layout.Column
9 | import androidx.compose.foundation.layout.Spacer
10 | import androidx.compose.foundation.layout.fillMaxSize
11 | import androidx.compose.foundation.layout.fillMaxWidth
12 | import androidx.compose.foundation.layout.height
13 | import androidx.compose.foundation.layout.padding
14 | import androidx.compose.foundation.layout.size
15 | import androidx.compose.foundation.layout.widthIn
16 | import androidx.compose.foundation.shape.CircleShape
17 | import androidx.compose.material.icons.Icons
18 | import androidx.compose.material.icons.rounded.LocationOn
19 | import androidx.compose.material3.ButtonDefaults
20 | import androidx.compose.material3.Icon
21 | import androidx.compose.material3.MaterialTheme
22 | import androidx.compose.material3.Scaffold
23 | import androidx.compose.material3.Surface
24 | import androidx.compose.material3.Text
25 | import androidx.compose.material3.TextButton
26 | import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
27 | import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
28 | import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
29 | import androidx.compose.runtime.Composable
30 | import androidx.compose.runtime.LaunchedEffect
31 | import androidx.compose.ui.Alignment
32 | import androidx.compose.ui.Modifier
33 | import androidx.compose.ui.platform.LocalContext
34 | import androidx.compose.ui.text.style.TextAlign
35 | import androidx.compose.ui.unit.dp
36 | import com.google.accompanist.permissions.isGranted
37 | import com.google.accompanist.permissions.rememberPermissionState
38 |
39 | @Composable
40 | fun PermissionRequired(onDenyClick: () -> Unit, guardedContent: @Composable () -> Unit) {
41 | val state = rememberPermissionState(Manifest.permission.ACCESS_FINE_LOCATION)
42 | Scaffold { padding ->
43 | when {
44 | state.status.isGranted -> guardedContent()
45 | else -> {
46 | LaunchedEffect(Unit) {
47 | state.launchPermissionRequest()
48 | }
49 | PermissionRequiredScreen(
50 | modifier = Modifier.padding(padding),
51 | onDenyClick = onDenyClick
52 | )
53 | }
54 | }
55 | }
56 | }
57 |
58 | @Composable
59 | fun PermissionRequiredScreen(modifier: Modifier, onDenyClick: () -> Unit) {
60 | Scaffold(
61 | contentColor = MaterialTheme.colorScheme.onSurface,
62 | containerColor = MaterialTheme.colorScheme.surface
63 | ) { padding ->
64 | val windowSizeClass = calculateWindowSizeClass(LocalContext.current as Activity).widthSizeClass
65 | val centered = windowSizeClass == WindowWidthSizeClass.Expanded
66 | Box(
67 | modifier = Modifier
68 | .fillMaxSize()
69 | .padding(padding),
70 | contentAlignment = Alignment.TopCenter
71 | ) {
72 | Column(
73 | modifier = Modifier
74 | .widthIn(max = 600.dp)
75 | .fillMaxSize()
76 | .padding(horizontal = 16.dp)
77 | .padding(top = 32.dp, bottom = 12.dp),
78 | horizontalAlignment = if (centered) Alignment.CenterHorizontally else Alignment.Start
79 | ) {
80 | Surface(
81 | shape = CircleShape,
82 | color = MaterialTheme.colorScheme.primary,
83 | modifier = Modifier.size(80.dp)
84 | ) {
85 | Icon(
86 | Icons.Rounded.LocationOn,
87 | contentDescription = "Icon",
88 | modifier = Modifier.padding(12.dp)
89 | )
90 | }
91 |
92 | Spacer(Modifier.height(36.dp))
93 | Text(
94 | text = "Really important permission is required",
95 | style = MaterialTheme.typography.headlineMedium
96 | )
97 | Spacer(Modifier.height(36.dp))
98 | Text(
99 | text = "Well not really. This is used for demo purposes only to show you how a request permission screen works.",
100 | textAlign = if (centered) TextAlign.Center else TextAlign.Start,
101 | )
102 |
103 | Spacer(Modifier.weight(1f))
104 | TextButton(
105 | onClick = onDenyClick, modifier = Modifier.fillMaxWidth(),
106 | colors = ButtonDefaults.textButtonColors(contentColor = MaterialTheme.colorScheme.onSurface)
107 | ) {
108 | Text("Deny")
109 | }
110 | }
111 | }
112 | }
113 | }
--------------------------------------------------------------------------------
/template/src/main/java/com/composables/jetpackcomposetemplate/details/PhotoDetailsScreen.kt:
--------------------------------------------------------------------------------
1 | package com.composables.jetpackcomposetemplate.details
2 |
3 | import android.widget.Toast
4 | import androidx.compose.foundation.background
5 | import androidx.compose.foundation.layout.Box
6 | import androidx.compose.foundation.layout.Column
7 | import androidx.compose.foundation.layout.Spacer
8 | import androidx.compose.foundation.layout.aspectRatio
9 | import androidx.compose.foundation.layout.fillMaxSize
10 | import androidx.compose.foundation.layout.fillMaxWidth
11 | import androidx.compose.foundation.layout.height
12 | import androidx.compose.foundation.layout.padding
13 | import androidx.compose.material.icons.Icons
14 | import androidx.compose.material.icons.filled.Favorite
15 | import androidx.compose.material.icons.outlined.Favorite
16 | import androidx.compose.material.icons.rounded.ArrowBack
17 | import androidx.compose.material.icons.rounded.Favorite
18 | import androidx.compose.material.icons.twotone.Favorite
19 | import androidx.compose.material3.Icon
20 | import androidx.compose.material3.IconButton
21 | import androidx.compose.material3.MaterialTheme
22 | import androidx.compose.material3.Scaffold
23 | import androidx.compose.material3.Text
24 | import androidx.compose.material3.TopAppBar
25 | import androidx.compose.runtime.Composable
26 | import androidx.compose.runtime.LaunchedEffect
27 | import androidx.compose.runtime.collectAsState
28 | import androidx.compose.runtime.getValue
29 | import androidx.compose.ui.Modifier
30 | import androidx.compose.ui.graphics.Color
31 | import androidx.compose.ui.layout.ContentScale
32 | import androidx.compose.ui.platform.LocalContext
33 | import androidx.compose.ui.res.stringResource
34 | import androidx.compose.ui.text.style.TextOverflow
35 | import androidx.compose.ui.unit.dp
36 | import androidx.lifecycle.viewmodel.compose.viewModel
37 | import coil.compose.AsyncImage
38 | import coil.request.ImageRequest
39 | import com.composables.jetpackcomposetemplate.R
40 | import com.composables.jetpackcomposetemplate.destinations.HomeScreenDestination
41 | import com.composables.jetpackcomposetemplate.destinations.PhotoDetailsScreenDestination
42 | import com.composables.jetpackcomposetemplate.formatLongNumber
43 | import com.composables.jetpackcomposetemplate.home.PhotoId
44 | import com.composables.jetpackcomposetemplate.photoDetailsViewModel
45 | import com.composables.jetpackcomposetemplate.ui.LoadingScreen
46 | import com.ramcosta.composedestinations.annotation.Destination
47 | import com.ramcosta.composedestinations.navigation.DestinationsNavigator
48 |
49 | @Composable
50 | @Destination
51 | fun PhotoDetailsScreen(
52 | photoId: PhotoId,
53 | navigator: DestinationsNavigator,
54 | ) {
55 | val viewModel = viewModel { photoDetailsViewModel(photoId) }
56 |
57 | val state by viewModel.state.collectAsState()
58 | val context = LocalContext.current
59 | Box(Modifier.fillMaxSize().background(Color.Black)) {
60 | when (val currentState = state) {
61 | is PhotoDetailsState.Loaded -> PhotoDetailsContents(
62 | state = currentState,
63 | onNavigateUpClick = { navigator.navigateUp() }
64 | )
65 |
66 | PhotoDetailsState.Loading -> LoadingScreen()
67 | PhotoDetailsState.Error -> LaunchedEffect(Unit) {
68 | Toast.makeText(context, "Could not find photo", Toast.LENGTH_SHORT).show()
69 | navigator.navigate(HomeScreenDestination) {
70 | popUpTo(PhotoDetailsScreenDestination.route) {
71 | inclusive = true
72 | }
73 | }
74 | }
75 | }
76 | }
77 | }
78 |
79 | @Composable
80 | private fun PhotoDetailsContents(state: PhotoDetailsState.Loaded, onNavigateUpClick: () -> Unit) {
81 | val imageUrl = state.photo.url
82 | val photo = state.photo
83 | val context = LocalContext.current
84 | Scaffold(
85 | topBar = {
86 | TopAppBar(title = {
87 | Text(
88 | text = photo.description,
89 | maxLines = 1,
90 | overflow = TextOverflow.Ellipsis
91 | )
92 | },
93 | actions = {
94 | IconButton(onClick = {}) {
95 | val isFavorite = state.favorite
96 | if (isFavorite) {
97 | Icon(
98 | Icons.Filled.Favorite,
99 | contentDescription = "Favorite",
100 | )
101 | } else {
102 | Icon(
103 | Icons.TwoTone.Favorite,
104 | contentDescription = "Not favorite",
105 | )
106 | }
107 | }
108 | },
109 | navigationIcon = {
110 | IconButton(onClick = onNavigateUpClick) {
111 | Icon(Icons.Rounded.ArrowBack, contentDescription = null)
112 | }
113 | })
114 | }
115 | ) { padding ->
116 | Column(Modifier.fillMaxSize().padding(padding)) {
117 | AsyncImage(
118 | model = ImageRequest.Builder(context)
119 | .data(imageUrl)
120 | .crossfade(true)
121 | .build(),
122 | contentDescription = photo.description,
123 | contentScale = ContentScale.Crop,
124 | modifier = Modifier
125 | .aspectRatio(16 / 9f)
126 | .fillMaxWidth()
127 | )
128 |
129 | Spacer(Modifier.height(16.dp))
130 | Column(Modifier.padding(horizontal = 16.dp)) {
131 | Text("Views", style = MaterialTheme.typography.bodySmall)
132 | Text(stringResource(R.string.views_x, formatLongNumber(photo.views)))
133 | Spacer(Modifier.height(24.dp))
134 | }
135 | }
136 |
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/template/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------