Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

139 add ktlint to the project #140

Merged
merged 5 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*.{kt,kts}]
ktlint_code_style = ktlint_official
ktlint_standard_annotation = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
ktlint_standard_multiline-expression-wrapping = disabled
ktlint_standard_string-template-indent = disabled
ktlint_function_naming_ignore_when_annotated_with = Composable
ktlint_function_signature_body_expression_wrapping = default
32 changes: 17 additions & 15 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ plugins {
alias(libs.plugins.detekt)
alias(libs.plugins.ksp)
alias(libs.plugins.kover)
alias(libs.plugins.ktlint)
}

ktlint {
version.set(libs.versions.ktlint)
android.set(true)
filter {
exclude("**/generated/**")
}
}

detekt {
Expand Down Expand Up @@ -56,7 +65,6 @@ android {
project.rootProject.file("properties/urls.properties").inputStream().use {
urlProperties.load(it)
}

}
val serverUrl = if (urlsPropertiesExist) {
urlProperties.getProperty("main")
Expand Down Expand Up @@ -89,7 +97,6 @@ android {
value = "\"$metricaToken\"",
name = "METRICA_TOKEN",
)

}

val securityProperties = Properties()
Expand All @@ -100,7 +107,6 @@ android {
securityProperties.load(it)
}


signingConfigs {
create("release") {
storeFile = rootProject.file("Backgroundable.jks")
Expand Down Expand Up @@ -130,7 +136,6 @@ android {
isDebuggable = true
applicationIdSuffix = ".debug"
versionNameSuffix = ".debug"

}
}

Expand Down Expand Up @@ -208,10 +213,8 @@ protobuf {
}

dependencies {
detektPlugins(libs.detektFormatting)

implementation(libs.appcompat)
/*Compose*/
// Compose
implementation(libs.bundles.compose)
implementation(libs.activityCompose)
implementation(libs.navigationCompose)
Expand All @@ -220,27 +223,27 @@ dependencies {
implementation(libs.lifecycleRuntimeCompose)
implementation(libs.coilCompose)

/*coroutine*/
// coroutine
implementation(libs.coroutine)

/*Retrofit*/
// Retrofit
implementation(libs.retrofit)
implementation(libs.kotlinxSerialization)
implementation(libs.retrofitKotlinxSerializationConverter)

/*dagger*/
// dagger
implementation(libs.dagger)
ksp(libs.daggerCompiler)

/*room*/
// room
implementation(libs.bundles.room)
ksp(libs.roomCompiler)

/*chucker*/
// chucker
debugImplementation(libs.chucker)
releaseImplementation(libs.chuckerNoOp)

/*datastore*/
// datastore
implementation(libs.bundles.datastore)
implementation(libs.datastorePreferences)

Expand Down Expand Up @@ -282,8 +285,7 @@ class RoomSchemaArgProvider(
@get:PathSensitive(PathSensitivity.RELATIVE)
val schemaDir: File
) : CommandLineArgumentProvider {

override fun asArguments(): Iterable<String> {
return listOf("room.schemaLocation=${schemaDir.path}")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import okhttp3.OkHttpClient
import java.util.concurrent.TimeUnit

class BackgroundableApplication : Application() {

lateinit var appComponent: AppComponent
private set

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import java.lang.Float.min
import kotlin.math.sqrt

object HexagonShape : Shape {

override fun createOutline(
size: Size,
layoutDirection: LayoutDirection,
Expand All @@ -29,7 +28,10 @@ fun drawCustomHexagonPath(size: Size): Path {
}
}

private fun Path.customHexagon(radius: Float, size: Size) {
private fun Path.customHexagon(
radius: Float,
size: Size
) {
val triangleHeight = (sqrt(3.0) * radius / 2)
val centerX = size.width / 2
val centerY = size.height / 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.ui.res.stringResource
@Suppress("SpreadOperator")
sealed interface UiText {
data class DynamicString(val value: String) : UiText

class StringResource(
@StringRes val resId: Int,
vararg val args: Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import javax.inject.Inject
class AndroidDownloader @Inject constructor(
context: Context
) : Downloader {

private val downloadManager = context.getSystemService(
DownloadManager::class.java
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ fun Context.composeMail(
}
}

fun Context.toast(message: String, duration: Int = Toast.LENGTH_LONG) {
fun Context.toast(
message: String,
duration: Int = Toast.LENGTH_LONG
) {
Toast.makeText(this, message, duration).show()
}

fun Context.toast(@StringRes stringRes: Int, duration: Int = Toast.LENGTH_LONG) {
fun Context.toast(
@StringRes stringRes: Int,
duration: Int = Toast.LENGTH_LONG
) {
Toast.makeText(this, stringRes, duration).show()
}

Expand Down Expand Up @@ -77,7 +83,10 @@ fun File.getUri(context: Context): Uri {
)
}

fun Uri.setAsWallpaper(context: Context, onError: (Throwable) -> Unit) {
fun Uri.setAsWallpaper(
context: Context,
onError: (Throwable) -> Unit
) {
runCatching {
val intent = Intent(Intent.ACTION_ATTACH_DATA)
intent.setDataAndType(this, "image/*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,30 @@ internal sealed class AppScreens(val route: String) {
data object Search : AppScreens("search")

data object MediaList : AppScreens("media-list?id={id}&title={title}") {
fun createRoute(id: String, title: String): String {
fun createRoute(
id: String,
title: String
): String {
return "media-list?id=$id&title=$title"
}
}

data object MediaDetail : AppScreens("media-detail?id={id}&title={title}") {
fun createRoute(id: Int, title: String): String {
fun createRoute(
id: Int,
title: String
): String {
return "media-detail?id=$id&title=$title"
}
}

data object ColumnCountPicker : AppScreens(
"column-count-picker?items={items}?selectedItem={selectedItem}"
) {
fun createRoute(items: String, selectedItem: Int): String {
fun createRoute(
items: String,
selectedItem: Int
): String {
return "column-count-picker?items=$items?selectedItem=$selectedItem"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import javax.inject.Singleton

@Singleton
class SnackbarManager @Inject constructor() {

private val channel = Channel<SnackbarMessage>(
capacity = 5,
onBufferOverflow = BufferOverflow.DROP_OLDEST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package ir.thatsmejavad.backgroundable.core.sealeds

sealed interface AsyncJob<out T> {
data class Success<T>(val value: T) : AsyncJob<T>

data class Fail<T>(val exception: Throwable) : AsyncJob<T>

data object Loading : AsyncJob<Nothing>

data object Uninitialized : AsyncJob<Nothing>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import ir.thatsmejavad.backgroundable.R

sealed interface ImageQuality {
data object Low : ImageQuality

data object Medium : ImageQuality

data object High : ImageQuality

data object Ultra : ImageQuality

companion object {
fun toImageQuality(quality: Quality): ImageQuality {
return when (quality) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import ir.thatsmejavad.backgroundable.ListType as ProtoListType

sealed interface List {
data object ListType : List

data object GridType : List

data object StaggeredType : List

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ import ir.thatsmejavad.backgroundable.R

sealed class ResourceSize(val size: String) {
data object Original : ResourceSize("original")

data object Large2x : ResourceSize("large2x")

data object Large : ResourceSize("large")

data object Medium : ResourceSize("medium")

data object Small : ResourceSize("small")

data object Portrait : ResourceSize("portrait"), OrientationMode

data object Landscape : ResourceSize("landscape"), OrientationMode

data object Tiny : ResourceSize("tiny")

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import ir.thatsmejavad.backgroundable.ThemeType

sealed interface Theme {
data object DarkTheme : Theme

data object LightTheme : Theme

data object FollowSystem : Theme

companion object {
fun toTheme(theme: ThemeType): Theme {
return when (theme) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import ir.thatsmejavad.backgroundable.ThemeName

sealed interface ThemeColor {
data object Ao : ThemeColor

data object Skobeloff : ThemeColor

data object BlueViolet : ThemeColor

data object MiddleRed : ThemeColor

data object Crayola : ThemeColor

data object Indigo : ThemeColor

companion object {

val items = listOf(Skobeloff, Ao, BlueViolet, MiddleRed, Crayola, Indigo)

fun fromThemeColor(color: ThemeColor): ThemeName {
return when (color) {
Ao -> ThemeName.THEME_AO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ import androidx.lifecycle.ViewModel
import javax.inject.Inject
import javax.inject.Provider

@Suppress(
"ktlint:standard:parameter-list-spacing",
"ktlint:standard:indent",
)
class DaggerViewModelAssistedFactory @Inject constructor(
private val assistedFactoryMap:
Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModelAssistedFactory<*>>>,
private val viewModels: Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>,
) : ViewModelFactory {

@Suppress("UNCHECKED_CAST")
override fun <VM : ViewModel> create(modelClass: Class<VM>, handle: SavedStateHandle): VM {
override fun <VM : ViewModel> create(
modelClass: Class<VM>,
handle: SavedStateHandle
): VM {
val creator =
assistedFactoryMap[modelClass]
?: assistedFactoryMap.asIterable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel

interface ViewModelFactory {
fun <VM : ViewModel> create(modelClass: Class<VM>, handle: SavedStateHandle): VM
fun <VM : ViewModel> create(
modelClass: Class<VM>,
handle: SavedStateHandle
): VM
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ir.thatsmejavad.backgroundable.data.datasource.local
import ir.thatsmejavad.backgroundable.data.db.entity.PageKeyEntity

interface PageKeyLocalDataSource {

suspend fun insertPageKey(pageKey: PageKeyEntity)

suspend fun getPageKeyById(id: String): PageKeyEntity?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import javax.inject.Inject
class PageKeyLocalDataSourceImpl @Inject constructor(
private val pageKeyDao: PageKeyDao,
) : PageKeyLocalDataSource {

override suspend fun insertPageKey(pageKey: PageKeyEntity) {
pageKeyDao.insertPageKey(pageKey)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ir.thatsmejavad.backgroundable.data.datasource.local
import ir.thatsmejavad.backgroundable.data.db.entity.ResourceEntity

interface ResourceLocalDataSource {

suspend fun insertResources(resources: List<ResourceEntity>)

suspend fun deleteAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ import ir.thatsmejavad.backgroundable.model.Collection
import ir.thatsmejavad.backgroundable.model.PagedResponse

interface CollectionRemoteDataSource {

suspend fun getCollections(page: Int): PagedResponse<Collection>
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class CollectionRemoteMediator(
private val database: BackgroundableDatabase,
private val pageKeyLocalDataSource: PageKeyLocalDataSource,
) : RemoteMediator<Int, CollectionEntity>() {

private var pageKeyEntity: PageKeyEntity? = null

override suspend fun initialize(): InitializeAction {
Expand Down
Loading
Loading