Skip to content

Commit 385d11b

Browse files
feat: add lint kotlin (#36)
1 parent b4f9eb6 commit 385d11b

31 files changed

+458
-345
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[*.{kt,kts}]
2+
ktlint_function_naming_ignore_when_annotated_with = Composable
3+
compose_allowed_forwarding_of_types = .*AccountViewModel

.github/workflows/pr-check.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jobs:
3434
- name: Grant execute permission for gradlew
3535
run: chmod +x ./gradlew
3636

37+
- name: Lint Check
38+
run: bash ./gradlew lintKotlin
39+
3740
- name: 🏗 Build APK
3841
run: bash ./gradlew assembleDebug
3942

app/build.gradle.kts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
alias(libs.plugins.kotlin.android)
44
alias(libs.plugins.kotlin.compose)
55
alias(libs.plugins.sqldelight)
6+
id("org.jmailen.kotlinter")
67
}
78

89
android {
@@ -31,7 +32,7 @@ android {
3132
isMinifyEnabled = true
3233
proguardFiles(
3334
getDefaultProguardFile("proguard-android-optimize.txt"),
34-
"proguard-rules.pro"
35+
"proguard-rules.pro",
3536
)
3637
}
3738
}
@@ -95,4 +96,16 @@ dependencies {
9596
implementation(libs.compose.qr.code)
9697
implementation(libs.accompanist)
9798
implementation(libs.opencsv)
98-
}
99+
ktlint("io.nlopez.compose.rules:ktlint:0.4.27")
100+
}
101+
102+
kotlinter {
103+
ktlintVersion = "1.5.0"
104+
ignoreFormatFailures = true
105+
ignoreLintFailures = false
106+
reporters = arrayOf("checkstyle")
107+
}
108+
109+
tasks.check {
110+
dependsOn("installKotlinterPrePushHook")
111+
}

app/src/androidTest/java/com/yogeshpaliyal/deepr/ExampleInstrumentedTest.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package com.yogeshpaliyal.deepr
22

3-
import androidx.test.platform.app.InstrumentationRegistry
43
import androidx.test.ext.junit.runners.AndroidJUnit4
5-
4+
import androidx.test.platform.app.InstrumentationRegistry
5+
import org.junit.Assert.assertEquals
66
import org.junit.Test
77
import org.junit.runner.RunWith
88

9-
import org.junit.Assert.*
10-
119
/**
1210
* Instrumented test, which will execute on an Android device.
1311
*
@@ -21,4 +19,4 @@ class ExampleInstrumentedTest {
2119
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
2220
assertEquals("com.yogeshpaliyal.deepr", appContext.packageName)
2321
}
24-
}
22+
}

app/src/main/java/com/yogeshpaliyal/deepr/DeeprApplication.kt

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,33 @@ class DeeprApplication : Application() {
1818
override fun onCreate() {
1919
super.onCreate()
2020

21-
val appModule = module {
22-
// Provide the Android-specific SqlDriver
23-
single<SqlDriver> {
24-
AndroidSqliteDriver(DeeprDB.Schema, this@DeeprApplication, "deepr.db")
25-
}
21+
val appModule =
22+
module {
23+
// Provide the Android-specific SqlDriver
24+
single<SqlDriver> {
25+
AndroidSqliteDriver(DeeprDB.Schema, this@DeeprApplication, "deepr.db")
26+
}
2627

27-
// Provide the Database instance
28-
single {
29-
DeeprDB(get())
30-
}
28+
// Provide the Database instance
29+
single {
30+
DeeprDB(get())
31+
}
3132

32-
// Provide the generated queries from the database.
33-
// Replace `accountQueries` if your table has a different name.
34-
single<DeeprQueries> {
35-
val database = get<DeeprDB>()
36-
database.deeprQueries
37-
}
33+
// Provide the generated queries from the database.
34+
// Replace `accountQueries` if your table has a different name.
35+
single<DeeprQueries> {
36+
val database = get<DeeprDB>()
37+
database.deeprQueries
38+
}
3839

39-
single { AppPreferenceDataStore(androidContext()) }
40+
single { AppPreferenceDataStore(androidContext()) }
4041

41-
single<ExportRepository> { ExportRepositoryImpl(androidContext(), get()) }
42+
single<ExportRepository> { ExportRepositoryImpl(androidContext(), get()) }
4243

43-
single<ImportRepository> { ImportRepositoryImpl(androidContext(), get()) }
44+
single<ImportRepository> { ImportRepositoryImpl(androidContext(), get()) }
4445

45-
viewModel { AccountViewModel(get(), get(), get()) }
46-
}
46+
viewModel { AccountViewModel(get(), get(), get()) }
47+
}
4748

4849
startKoin {
4950
// Provide Android context to Koin
@@ -52,4 +53,4 @@ class DeeprApplication : Application() {
5253
modules(appModule)
5354
}
5455
}
55-
}
56+
}

app/src/main/java/com/yogeshpaliyal/deepr/MainActivity.kt

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.compose.material3.Text
1010
import androidx.compose.runtime.Composable
1111
import androidx.compose.runtime.mutableStateListOf
1212
import androidx.compose.runtime.remember
13+
import androidx.compose.ui.Modifier
1314
import androidx.navigation3.runtime.NavEntry
1415
import androidx.navigation3.ui.NavDisplay
1516
import com.yogeshpaliyal.deepr.ui.screens.AboutUs
@@ -40,28 +41,35 @@ class MainActivity : ComponentActivity() {
4041
}
4142

4243
@Composable
43-
fun Dashboard(viewModel: AccountViewModel) {
44+
fun Dashboard(
45+
viewModel: AccountViewModel,
46+
modifier: Modifier = Modifier,
47+
) {
4448
val backStack = remember { mutableStateListOf<Any>(Home) }
4549

4650
NavDisplay(
4751
backStack = backStack,
52+
modifier = modifier,
4853
onBack = { backStack.removeLastOrNull() },
4954
entryProvider = { key ->
5055
when (key) {
51-
is Home -> NavEntry(key) {
52-
HomeScreen(viewModel, backStack)
53-
}
56+
is Home ->
57+
NavEntry(key) {
58+
HomeScreen(viewModel, backStack)
59+
}
5460

55-
is Settings -> NavEntry(key) {
56-
SettingsScreen(viewModel, backStack)
57-
}
61+
is Settings ->
62+
NavEntry(key) {
63+
SettingsScreen(viewModel, backStack)
64+
}
5865

59-
is AboutUs -> NavEntry(key) {
60-
AboutUsScreen(backStack)
61-
}
66+
is AboutUs ->
67+
NavEntry(key) {
68+
AboutUsScreen(backStack)
69+
}
6270

6371
else -> NavEntry(Unit) { Text("Unknown route") }
6472
}
65-
}
73+
},
6674
)
6775
}

app/src/main/java/com/yogeshpaliyal/deepr/backup/ExportRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ import com.yogeshpaliyal.deepr.util.RequestResult
44

55
interface ExportRepository {
66
suspend fun exportToCsv(): RequestResult<String>
7-
}
7+
}

app/src/main/java/com/yogeshpaliyal/deepr/backup/ExportRepositoryImpl.kt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class ExportRepositoryImpl(
2222
private val context: Context,
2323
private val deeprQueries: DeeprQueries,
2424
) : ExportRepository {
25-
2625
override suspend fun exportToCsv(): RequestResult<String> {
2726
val count = deeprQueries.countDeepr().executeAsOne()
2827
if (count == 0L) {
@@ -38,15 +37,15 @@ class ExportRepositoryImpl(
3837

3938
return withContext(Dispatchers.IO) {
4039
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
41-
42-
val contentValues = ContentValues().apply {
43-
put(MediaStore.MediaColumns.DISPLAY_NAME, fileName)
44-
put(MediaStore.MediaColumns.MIME_TYPE, "text/csv")
45-
put(
46-
MediaStore.MediaColumns.RELATIVE_PATH,
47-
"${Environment.DIRECTORY_DOWNLOADS}/Deepr"
48-
)
49-
}
40+
val contentValues =
41+
ContentValues().apply {
42+
put(MediaStore.MediaColumns.DISPLAY_NAME, fileName)
43+
put(MediaStore.MediaColumns.MIME_TYPE, "text/csv")
44+
put(
45+
MediaStore.MediaColumns.RELATIVE_PATH,
46+
"${Environment.DIRECTORY_DOWNLOADS}/Deepr",
47+
)
48+
}
5049

5150
val resolver = context.contentResolver
5251
val uri =
@@ -73,12 +72,15 @@ class ExportRepositoryImpl(
7372
FileOutputStream(file).use { outputStream ->
7473
writeCsvData(outputStream, dataToExportInCsvFormat)
7574
}
76-
RequestResult.Success("Successfully exported to ${downloadsDir}/${file.absolutePath}")
75+
RequestResult.Success("Successfully exported to $downloadsDir/${file.absolutePath}")
7776
}
7877
}
7978
}
8079

81-
private fun writeCsvData(outputStream: OutputStream, data: List<Deepr>) {
80+
private fun writeCsvData(
81+
outputStream: OutputStream,
82+
data: List<Deepr>,
83+
) {
8284
outputStream.bufferedWriter().use { writer ->
8385
// Write Header
8486
writer.write("${Constants.Header.LINK},${Constants.Header.CREATED_AT},${Constants.Header.OPENED_COUNT}\n")
@@ -89,4 +91,4 @@ class ExportRepositoryImpl(
8991
}
9092
}
9193
}
92-
}
94+
}

app/src/main/java/com/yogeshpaliyal/deepr/backup/ImportRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ import com.yogeshpaliyal.deepr.util.RequestResult
55

66
interface ImportRepository {
77
suspend fun importFromCsv(uri: Uri): RequestResult<ImportResult>
8-
}
8+
}

app/src/main/java/com/yogeshpaliyal/deepr/backup/ImportRepositoryImpl.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@ import java.io.IOException
1111

1212
class ImportRepositoryImpl(
1313
private val context: Context,
14-
private val deeprQueries: DeeprQueries
14+
private val deeprQueries: DeeprQueries,
1515
) : ImportRepository {
16-
1716
override suspend fun importFromCsv(uri: Uri): RequestResult<ImportResult> {
1817
var updatedCount = 0
1918
var skippedCount = 0
2019

2120
try {
2221
context.contentResolver.openInputStream(uri)?.use { inputStream ->
2322
inputStream.reader().use { reader ->
24-
val csvReader = CSVReaderBuilder(reader)
25-
.build()
23+
val csvReader =
24+
CSVReaderBuilder(reader)
25+
.build()
2626

2727
// verify header first
2828
val header = csvReader.readNext()
29-
if (header == null || header.size < 3 ||
29+
if (header == null ||
30+
header.size < 3 ||
3031
header[0] != Constants.Header.LINK ||
3132
header[1] != Constants.Header.CREATED_AT ||
3233
header[2] != Constants.Header.OPENED_COUNT
@@ -44,7 +45,7 @@ class ImportRepositoryImpl(
4445
deeprQueries.transaction {
4546
deeprQueries.insertDeepr(
4647
link = link,
47-
openedCount = openedCount
48+
openedCount = openedCount,
4849
)
4950
}
5051
} else {
@@ -58,7 +59,6 @@ class ImportRepositoryImpl(
5859
}
5960

6061
return RequestResult.Success(ImportResult(updatedCount, skippedCount))
61-
6262
} catch (e: IOException) {
6363
return RequestResult.Error("Error reading file: ${e.message}")
6464
} catch (e: CsvException) {
@@ -67,4 +67,4 @@ class ImportRepositoryImpl(
6767
return RequestResult.Error("An unexpected error occurred: ${e.message}")
6868
}
6969
}
70-
}
70+
}

0 commit comments

Comments
 (0)