Skip to content

Commit

Permalink
Merge pull request #11 from shinhyo/add_theme_toggle
Browse files Browse the repository at this point in the history
feat: add theme toggle button
  • Loading branch information
shinhyo authored May 3, 2024
2 parents 0fba091 + c1b1c2b commit 2aad747
Show file tree
Hide file tree
Showing 86 changed files with 1,082 additions and 724 deletions.
24 changes: 4 additions & 20 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
# https://pinterest.github.io/ktlint/latest/rules/standard

root = true

[*.{kt, kts}]
ktlint_code_style = ktlint_official
indent_size = 4
indent_style = space
ij_kotlin_allow_trailing_comma = false
ij_kotlin_allow_trailing_comma_on_call_site = false

# enabled, disabled
ktlint_standard = enabled
ktlint_experimental = disabled
ktlint_custom-rule-set = disabled

max_line_length = off
insert_final_newline = false

# ktlint_standard_multiline-expression-wrapping = disabled
# ktlint_standard_import-ordering = disabled
# ktlint_standard_trailing-comma-on-declaration-site = disabled
[*.{kt,kts}]
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ktlint_function_naming_ignore_when_annotated_with = Composable, Test
27 changes: 6 additions & 21 deletions .github/workflows/Build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v3

- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
Expand All @@ -46,29 +46,14 @@ jobs:
key: gradle-${{ hashFiles('checksum.txt') }}

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v3

- name: Check spotless
- name: Check Spotless
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace

- name: Check lint
run: ./gradlew lintDebug --stacktrace

# - name: Build all build type and flavor permutations
# run: ./gradlew assemble --stacktrace

# - name: Run local tests
# run: ./gradlew testDebug testProdDebug --stacktrace

# - name: Upload build outputs (APKs)
# uses: actions/upload-artifact@v3
# with:
# name: build-outputs
# path: app/build/outputs

- name: Upload build reports
if: always()
uses: actions/upload-artifact@v3
with:
name: build-reports
path: app/build/reports
path: app/build/reports
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p align="center">
<a href='https://developer.android.com'><img src='http://img.shields.io/badge/platform-android-green.svg'/></a>
<a href="https://kotlinlang.org/docs/whatsnew1920.html"><img src = "https://shields.io/badge/kotlin-1.9.23-blue" /></a>
<a href="https://developer.android.com/jetpack/compose/bom"><img src = "https://img.shields.io/badge/jetpack%20compose-2024.04.00-brightgreen" /></a>
<a href="https://developer.android.com/jetpack/compose/bom"><img src = "https://img.shields.io/badge/jetpack%20compose-2024.05.00-brightgreen" /></a>
<a href="https://opensource.org/licenses/Apache-2.0"><img src="https://img.shields.io/badge/license-Apache%202.0-blue.svg"/></a>
</p>

Expand All @@ -28,14 +28,18 @@
- MVVM pattern
- Kotlin Coroutines & Flows
- Material Design 3
- [Material Theme Builder](https://material-foundation.github.io/material-theme-builder/)
- Single Activity
- StaggeredVerticalGrid
- [Gradle Version Catalog](https://docs.gradle.org/7.4/userguide/platforms.html)
- [Retrofit2](https://github.com/square/retrofit)
- [Coil-Compose](https://coil-kt.github.io/coil/compose)
- [Timber](https://github.com/JakeWharton/timber)
- [Haze](https://github.com/chrisbanes/haze)
- [sharedElement](https://developer.android.com/guide/fragments/animate#shared)

## Multi Module

```
├── app
├── core
Expand Down
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ android {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
"proguard-rules.pro",
)
signingConfig = signingConfigs.getByName("debug")
}
Expand All @@ -48,4 +48,5 @@ dependencies {
implementation(libs.androidx.startup)
implementation(libs.androidx.compose.material3)
implementation(libs.timber)
implementation(libs.coil.kt)
}
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<application
android:name=".BrBaApplication"
android:allowBackup="false"
android:enableOnBackInvokedCallback="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -22,6 +23,10 @@
<meta-data
android:name="io.github.shinhyo.brba.initializer.TimberInitializer"
android:value="androidx.startup" />

<meta-data
android:name="io.github.shinhyo.brba.initializer.CoilInitializer"
android:value="androidx.startup" />
</provider>

</application>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2024 shinhyo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.shinhyo.brba.initializer

import android.content.Context
import androidx.startup.Initializer
import coil.Coil
import coil.ImageLoader
import coil.disk.DiskCache
import coil.memory.MemoryCache

class CoilInitializer : Initializer<Unit> {

override fun create(context: Context) {
Coil.setImageLoader(
ImageLoader.Builder(context)
.memoryCache {
MemoryCache.Builder(context)
.maxSizePercent(0.25)
.build()
}
.crossfade(true)
// .logger(if (BuildConfig.DEBUG) DebugLogger() else null)
.respectCacheHeaders(false)
.diskCache {
DiskCache.Builder()
.directory(context.cacheDir.resolve("image_cache"))
.maxSizePercent(0.10)
.build()
}
.build(),
)
}

override fun dependencies(): MutableList<Class<out Initializer<*>>> = mutableListOf()
}
3 changes: 1 addition & 2 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>
<resources></resources>
3 changes: 1 addition & 2 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ dependencies {
compileOnly(libs.android.tools.common)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(libs.ksp.gradlePlugin)
compileOnly(libs.ktlint.gradlePlugin)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import com.android.build.api.dsl.ApplicationExtension
import io.github.shinhyo.brba.buildlogic.configureAndroidCompose
import io.github.shinhyo.brba.buildlogic.configureHiltAndroid
import io.github.shinhyo.brba.buildlogic.configureKotlinAndroid
import io.github.shinhyo.brba.buildlogic.configureKtlintAndroid
import io.github.shinhyo.brba.buildlogic.findVersion

with(pluginManager) {
Expand All @@ -16,4 +15,3 @@ extensions.configure<ApplicationExtension> {
configureKotlinAndroid()
configureAndroidCompose()
configureHiltAndroid()
configureKtlintAndroid()
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ androidExtension.apply {

add("implementation", findLibrary("coil.kt.compose"))

add("implementation", findLibrary("androidx.constraintlayout.compose"))
add("implementation", findLibrary("androidx.compose.material3"))
add("implementation", findLibrary("androidx.compose.material.iconsExtended"))
add("implementation", findLibrary("androidx.compose.animation"))
add("implementation", findLibrary("haze"))

add("implementation", findLibrary("androidx.navigation.compose"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import io.github.shinhyo.brba.buildlogic.androidExtension
import io.github.shinhyo.brba.buildlogic.configureHiltAndroid
import io.github.shinhyo.brba.buildlogic.configureKotlinAndroid
import io.github.shinhyo.brba.buildlogic.configureKtlintAndroid
import io.github.shinhyo.brba.buildlogic.findLibrary

with(pluginManager) {
Expand All @@ -16,4 +15,3 @@ androidExtension.apply {

configureKotlinAndroid()
configureHiltAndroid()
configureKtlintAndroid()
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ private fun Project.configureKotlin() {
allWarningsAsErrors = properties["warningsAsErrors"] as? Boolean ?: false
compilerOptions.freeCompilerArgs.addAll(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:experimentalStrongSkipping=true",
"plugin:androidx.compose.compiler.plugins.kotlin:strongSkipping=true",
)
freeCompilerArgs = freeCompilerArgs + listOf(
"-Xcontext-receivers",
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-opt-in=androidx.compose.material3.ExperimentalMaterial3Api",
"-opt-in=androidx.compose.foundation.layout.ExperimentalLayoutApi",
"-opt-in=androidx.compose.animation.ExperimentalSharedTransitionApi",
)
}
}
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ plugins {
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.hilt) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.jlleitschuh.gradle.ktlint) apply false
}

apply(from = File("gradle/projectDependencyGraph.gradle"))
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ import javax.inject.Qualifier
annotation class Dispatcher(val dispatcher: BrbaDispatcher)

enum class BrbaDispatcher {
IO, MAIN
IO,
MAIN,
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import kotlinx.coroutines.flow.onStart
sealed interface Result<out T> {
data object Loading : Result<Nothing>
data class Success<T>(val data: T) : Result<T>
data class Error(val exception: Throwable? = null) : Result<Nothing>
data class Error(val exception: Throwable) : Result<Nothing>
}

val Result<*>.succeeded
Expand All @@ -37,4 +37,4 @@ fun <T> Result<T>.successOr(fallback: T): T {
fun <T> Flow<T>.asResult(): Flow<Result<T>> = this
.map<T, Result<T>> { Success(it) }
.onStart { emit(Result.Loading) }
.catch { emit(Result.Error(it)) }
.catch { e -> emit(Result.Error(e)) }
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ abstract class RepositoryModule {
@Binds
@Singleton
abstract fun bindCharactersRepository(
repo: CharactersRepositoryImpl
repo: CharactersRepositoryImpl,
): CharactersRepository

@Binds
@Singleton
abstract fun bindDeviceRepository(
repo: DeviceRepositoryImpl
repo: DeviceRepositoryImpl,
): DeviceRepository
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ fun BrbaCharacter.asEntity() = CharacterEntity(
charId = charId,
name = name,
img = img,
nickname = nickname
nickname = nickname,
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,27 @@ import io.github.shinhyo.brba.core.model.BrbaCharacter
import io.github.shinhyo.brba.core.network.NetworkDataSource
import io.github.shinhyo.brba.core.network.model.CharacterResponse
import io.github.shinhyo.brba.core.network.model.asExternalModel
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import javax.inject.Inject

open class CharactersRepositoryImpl @Inject constructor(
private val api: NetworkDataSource,
private val dao: CharacterDao
private val dao: CharacterDao,
) : CharactersRepository {

override fun getCharacterList(): Flow<List<BrbaCharacter>> = flow { emit(api.getCharacter()) }
.map { it.map(CharacterResponse::asExternalModel) }

override fun getCharacterList(id: Long): Flow<BrbaCharacter> = flow { emit(api.getCharacter(id)) }
.map { it.first().asExternalModel() }
override fun getCharacterList(id: Long): Flow<BrbaCharacter> =
flow { emit(api.getCharacter(id)) }
.map { it.first().asExternalModel() }

override fun getDatabaseList(isAsc: Boolean): Flow<List<BrbaCharacter>> = dao.getCharacter(isAsc = isAsc)
.map { it.map(CharacterEntity::asExternalModel) }
override fun getDatabaseList(isAsc: Boolean): Flow<List<BrbaCharacter>> =
dao.getCharacter(isAsc = isAsc)
.map { it.map(CharacterEntity::asExternalModel) }

override fun getDatabaseList(id: Long): Flow<BrbaCharacter?> = dao.getCharacter(charId = id)
.map { it?.asExternalModel() }
Expand Down
Loading

0 comments on commit 2aad747

Please sign in to comment.