Skip to content

Commit

Permalink
Use Initialization Scripts for spotless (#256)
Browse files Browse the repository at this point in the history
* Use Initialization Scripts for spotless

* Run spotlessApply
  • Loading branch information
fornewid authored Dec 9, 2023
1 parent 008816a commit 57eff2f
Show file tree
Hide file tree
Showing 100 changed files with 544 additions and 504 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# https://editorconfig.org/
# This configuration is used by ktlint when spotless invokes it

[*.{kt,kts}]
ij_kotlin_allow_trailing_comma=true
ij_kotlin_allow_trailing_comma_on_call_site=true
21 changes: 17 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ on:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 40
timeout-minutes: 60

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

- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
Expand All @@ -27,5 +28,17 @@ jobs:
distribution: temurin
java-version: 17

- name: Build, lint and spotless
run: ./gradlew spotlessCheck dependencyGuard lintDebug assemble --scan
- name: Check dependencyGuard
run: ./gradlew dependencyGuard

- name: Check spotless
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --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 --stacktrace
8 changes: 4 additions & 4 deletions app/src/main/java/soup/movie/analytics/EventAnalyticsImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class EventAnalyticsImpl(context: Context) : EventAnalytics {
delegate.logEvent(Event.SHARE, Bundle().apply { params() })
}

/* Common */
// Common

override fun screen(activity: Activity, screenName: String, screenClass: String?) {
logEvent(Event.SCREEN_VIEW) {
Expand All @@ -52,7 +52,7 @@ class EventAnalyticsImpl(context: Context) : EventAnalytics {
}
}

/* Main */
// Main

override fun clickMovie() {
logSelectEvent {
Expand All @@ -66,7 +66,7 @@ class EventAnalyticsImpl(context: Context) : EventAnalytics {
}
}

/* Detail */
// Detail

override fun clickPoster() {
logShareEvent {
Expand Down Expand Up @@ -101,7 +101,7 @@ class EventAnalyticsImpl(context: Context) : EventAnalytics {
}
}

/* Detail: Trailers */
// Detail: Trailers

override fun clickTrailer() {
logSelectEvent {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/soup/movie/di/ApplicationModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ApplicationModule {
@Singleton
@Provides
fun provideEventAnalytics(
@ApplicationContext context: Context
@ApplicationContext context: Context,
): EventAnalytics = EventAnalyticsImpl(context)

@Singleton
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/soup/movie/ui/main/MainNavGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fun MainNavGraph(
}
composable(
route = Screen.Detail.route + "/{movieId}",
arguments = listOf(navArgument("movieId") { nullable = false })
arguments = listOf(navArgument("movieId") { nullable = false }),
) {
val viewModel = hiltViewModel<DetailViewModel>()
DetailNavGraph(
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/soup/movie/ui/main/MainUiEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ package soup.movie.ui.main
sealed class MainUiEvent {

class ShowDetailUiEvent(
val movieId: String
val movieId: String,
) : MainUiEvent()
}
15 changes: 0 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ plugins {
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.dagger.hilt) apply false
alias(libs.plugins.spotless) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.dependencyGuard) apply false
alias(libs.plugins.firebase.crashlytics) apply false
Expand All @@ -14,20 +13,6 @@ plugins {

apply from: "$rootDir/gradle/version.gradle"

subprojects {
apply plugin: 'com.diffplug.spotless'
spotless {
kotlin {
target '**/*.kt'
targetExclude("$buildDir/**/*.kt")
targetExclude('bin/**/*.kt')

ktlint("0.41.0")
licenseHeaderFile rootProject.file('spotless/copyright.kt')
}
}
}

Object propOrDef(String propertyName, Object defaultValue) {
def properties = new Properties()
def keyFile = rootProject.file("signing/key.properties")
Expand Down
2 changes: 1 addition & 1 deletion core/ads/src/main/java/soup/movie/core/ads/NativeAd.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ fun NativeAd(adInfo: NativeAdInfo) {
modifier = Modifier.fillMaxWidth().wrapContentHeight(),
update = {
it.setNativeAd(adInfo.nativeAd)
}
},
)
}
2 changes: 1 addition & 1 deletion core/ads/src/main/java/soup/movie/core/ads/NativeAdView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class NativeAdView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = 0
defStyleRes: Int = 0,
) : FrameLayout(context, attrs, defStyleAttr, defStyleRes) {

private var nativeAd: NativeAd? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ import android.app.Activity

interface EventAnalytics {

/* Common */
// Common
fun screen(activity: Activity, screenName: String, screenClass: String?)

/* Main */
// Main
fun clickMovie()
fun clickMenuFilter()

/* Detail */
// Detail
fun clickPoster()
fun clickShare()
fun clickCgvInfo()
fun clickLotteInfo()
fun clickMegaboxInfo()

/* Detail: Trailers */
// Detail: Trailers
fun clickTrailer()
fun clickMoreTrailers()
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ private val LightMovieColors = lightMovieColors(
primaryVariant = Color(0xFF9E9E9E),
onPrimary = Color.Black,
secondary = Color(0xFF2D7AF6),
onSecondary = Color.White
)
onSecondary = Color.White,
),
)

private val DarkMovieColors = darkMovieColors(
Expand All @@ -43,7 +43,7 @@ private val DarkMovieColors = darkMovieColors(
onPrimary = Color.White,
secondary = Color(0xFF8EB5F0),
onSecondary = Color.Black,
)
),
)

private val LightElevations = Elevations(
Expand All @@ -59,7 +59,7 @@ private val DarkElevations = Elevations(
@Composable
fun MovieTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
content: @Composable () -> Unit,
) {
val colors = if (darkTheme) {
DarkMovieColors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fun calculateWindowSizeClass(activity: Activity): WindowSizeClass {
@Immutable
class WindowSizeClass private constructor(
val widthSizeClass: WindowWidthSizeClass,
val heightSizeClass: WindowHeightSizeClass
val heightSizeClass: WindowHeightSizeClass,
) {
companion object {
/**
Expand Down Expand Up @@ -115,7 +115,7 @@ class WindowSizeClass private constructor(
@Immutable
@kotlin.jvm.JvmInline
value class WindowWidthSizeClass private constructor(
private val value: Int
private val value: Int,
) : Comparable<WindowWidthSizeClass> {

override operator fun compareTo(other: WindowWidthSizeClass) = value.compareTo(other.value)
Expand Down Expand Up @@ -169,7 +169,7 @@ value class WindowWidthSizeClass private constructor(
@Immutable
@kotlin.jvm.JvmInline
value class WindowHeightSizeClass private constructor(
private val value: Int
private val value: Int,
) : Comparable<WindowHeightSizeClass> {

override operator fun compareTo(other: WindowHeightSizeClass) = value.compareTo(other.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ private fun Context.executePlayStoreForApp(pkgName: String) {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=$pkgName")
)
Uri.parse("market://details?id=$pkgName"),
),
)
} catch (e: ActivityNotFoundException) {
Logger.w(e)
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=$pkgName")
)
Uri.parse("https://play.google.com/store/apps/details?id=$pkgName"),
),
)
}
}
Expand Down Expand Up @@ -90,14 +90,14 @@ object YouTube {
} catch (e: ActivityNotFoundException) {
Logger.w(e)
ctx.startActivitySafely(
createTrailerWebIntent(youtubeId)
createTrailerWebIntent(youtubeId),
)
}
}

private fun createTrailerAppIntent(id: String): Intent = Intent(
Intent.ACTION_VIEW,
Uri.parse("vnd.youtube:$id")
Uri.parse("vnd.youtube:$id"),
).apply {
flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Intent.FLAG_ACTIVITY_NEW_TASK or
Expand All @@ -110,7 +110,7 @@ object YouTube {

private fun createTrailerWebIntent(id: String): Intent = Intent(
Intent.ACTION_VIEW,
Uri.parse("https://www.youtube.com/watch?v=$id")
Uri.parse("https://www.youtube.com/watch?v=$id"),
)

fun executeAppWithQuery(ctx: Context, movieTitle: String) {
Expand All @@ -121,14 +121,14 @@ object YouTube {
Logger.w(e)
ctx.startActivitySafely(
createSearchWebIntent(
query
)
query,
),
)
}
}

private fun createSearchAppIntent(query: String): Intent = Intent(
Intent.ACTION_SEARCH
Intent.ACTION_SEARCH,
)
.setPackage(packageName)
.putExtra("query", query).apply {
Expand All @@ -143,6 +143,6 @@ object YouTube {

private fun createSearchWebIntent(query: String): Intent = Intent(
Intent.ACTION_VIEW,
Uri.parse("https://www.youtube.com/results?search_query=$query")
Uri.parse("https://www.youtube.com/results?search_query=$query"),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class ImageUriProviderImpl(
bitmap.toCacheFile(
appContext,
folderName = CACHE_DIRECTORY_NAME,
fileName = url.substring(url.lastIndexOf('/') + 1)
)
fileName = url.substring(url.lastIndexOf('/') + 1),
),
)
}

Expand All @@ -64,8 +64,8 @@ class ImageUriProviderImpl(
bitmap.toCacheFile(
appContext,
folderName = CACHE_DIRECTORY_NAME,
fileName = "share.jpg"
)
fileName = "share.jpg",
),
)
}

Expand All @@ -79,7 +79,7 @@ class ImageUriProviderImpl(
private fun Bitmap.toCacheFile(
context: Context,
folderName: String? = null,
fileName: String
fileName: String,
): File {
val cacheDir = if (folderName.isNullOrBlank()) {
context.cacheDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ object LocalDataSourceFactory {
return LocalDataSourceImpl(
movieDb.favoriteMovieDao(),
movieDb.openDateAlarmDao(),
cacheDb.movieCacheDao()
cacheDb.movieCacheDao(),
)
}

private fun createMovieDatabase(
context: Context
context: Context,
): MovieDatabase {
return Room
.databaseBuilder(context.applicationContext, MovieDatabase::class.java, "movie.db")
.build()
}

private fun createCacheDatabase(
context: Context
context: Context,
): MovieCacheDatabase {
return Room
.databaseBuilder(context.applicationContext, MovieCacheDatabase::class.java, "moop.db")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import javax.inject.Inject
class LocalDataSourceImpl @Inject constructor(
private val favoriteMovieDao: FavoriteMovieDao,
private val openDateAlarmDao: OpenDateAlarmDao,
private val cacheDao: MovieCacheDao
private val cacheDao: MovieCacheDao,
) : LocalDataSource {

private var codeResponse: TheaterAreaGroupModel? = null
Expand Down Expand Up @@ -70,8 +70,8 @@ class LocalDataSourceImpl @Inject constructor(
MovieListEntity(
type,
movieList.lastUpdateTime,
movieList.list.map { it.toMovieEntity() }
)
movieList.list.map { it.toMovieEntity() },
),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import soup.movie.data.database.impl.entity.OpenDateAlarmEntity
@Database(
entities = [
FavoriteMovieEntity::class,
OpenDateAlarmEntity::class
OpenDateAlarmEntity::class,
],
version = 1,
exportSchema = false
exportSchema = false,
)
@TypeConverters(FavoriteMovieTypeConverters::class)
abstract class MovieDatabase : RoomDatabase() {
Expand Down
Loading

0 comments on commit 57eff2f

Please sign in to comment.