Skip to content

Commit

Permalink
Set up KtLint (#71)
Browse files Browse the repository at this point in the history
* Add ktlint

* Add lint check to CI

* Use plugin for ktlint

* Fix KtLint issues

* Add post notification permission

* Fix Unsafe call to observe with Fragment instance as LifecycleOwner
  • Loading branch information
shubertm authored Nov 5, 2024
1 parent fa8f4e1 commit 6a90eca
Show file tree
Hide file tree
Showing 78 changed files with 2,676 additions and 2,130 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,41 @@ jobs:
with:
name: release-universal-apk
path: ./app/build/outputs/apk/release/app-universal-release.apk

lint:
needs: build
environment: Development
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'

- name: Run linter
run: ./gradlew lint

- uses: actions/upload-artifact@v4
with:
name: lint-results
path: ./app/build/reports/*.html

ktlint:
needs: build
environment: Development
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'

- name: Kotlin linter
run: ./gradlew ktlintCheck

7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
id 'kotlin-parcelize'
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
id 'org.jlleitschuh.gradle.ktlint'
}

android {
Expand Down Expand Up @@ -111,3 +112,9 @@ dependencies {
implementation "com.google.firebase:firebase-crashlytics"
implementation "com.google.firebase:firebase-analytics"
}

tasks.preBuild.dependsOn ktlintCheck

tasks.preBuild.dependsOn ktlintFormat

tasks.ktlintCheck.shouldRunAfter ktlintFormat
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package dev.arkbuilders.arkmemo

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import junit.framework.TestCase.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand All @@ -21,4 +19,4 @@ class ExampleInstrumentedTest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("dev.arkbuilders.arkmemo", appContext.packageName)
}
}
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<application
android:name=".App"
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/dev/arkbuilders/arkmemo/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package dev.arkbuilders.arkmemo

import android.app.Application
import dagger.hilt.android.HiltAndroidApp
import dev.arkbuilders.arklib.initArkLib
import dev.arkbuilders.arkfilepicker.folders.FoldersRepo
import dev.arkbuilders.arklib.initArkLib
import dev.arkbuilders.arkmemo.preferences.MemoPreferences
import javax.inject.Inject

@HiltAndroidApp
class App: Application() {

class App : Application() {
@Inject
lateinit var memoPreferences: MemoPreferences

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ import android.provider.Settings
import androidx.activity.result.contract.ActivityResultContract
import androidx.annotation.RequiresApi

class PermissionContract: ActivityResultContract<String, Boolean>() {

class PermissionContract : ActivityResultContract<String, Boolean>() {
@RequiresApi(Build.VERSION_CODES.R)
override fun createIntent(context: Context, input: String)
= Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, Uri.parse(input))
override fun createIntent(
context: Context,
input: String,
) = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, Uri.parse(input))

@RequiresApi(Build.VERSION_CODES.R)
override fun parseResult(resultCode: Int, intent: Intent?): Boolean {
override fun parseResult(
resultCode: Int,
intent: Intent?,
): Boolean {
return Environment.isExternalStorageManager()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import javax.inject.Singleton
@InstallIn(SingletonComponent::class)
@Module
object CoroutinesModule {

@Named(IO_DISPATCHER)
@Singleton
@Provides
fun provideDispatcher(): CoroutineDispatcher = Dispatchers.IO
}

const val IO_DISPATCHER = "iODispatcher"
const val IO_DISPATCHER = "iODispatcher"
5 changes: 2 additions & 3 deletions app/src/main/java/dev/arkbuilders/arkmemo/di/MediaModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import dev.arkbuilders.arkmemo.media.ArkMediaPlayer
import dev.arkbuilders.arkmemo.media.ArkMediaPlayerImpl
import dev.arkbuilders.arkmemo.media.ArkAudioRecorder
import dev.arkbuilders.arkmemo.media.ArkAudioRecorderImpl
import dev.arkbuilders.arkmemo.media.ArkMediaPlayer
import dev.arkbuilders.arkmemo.media.ArkMediaPlayerImpl

@Module
@InstallIn(SingletonComponent::class)
abstract class MediaModule {

@Binds
abstract fun bindArkAudioRecorder(impl: ArkAudioRecorderImpl): ArkAudioRecorder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ import dev.arkbuilders.arkmemo.preferences.MemoPreferencesImpl
abstract class PreferencesModule {
@Binds
abstract fun bindMemoPreferences(impl: MemoPreferencesImpl): MemoPreferences
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ import javax.inject.Singleton
@InstallIn(SingletonComponent::class)
@Module
object PropertiesStorageModule {

@Singleton
@Provides
@Named(STORAGE_SCOPE)
fun storageScope(
@Named(IO_DISPATCHER) dispatcher: CoroutineDispatcher
@Named(IO_DISPATCHER) dispatcher: CoroutineDispatcher,
): CoroutineScope = CoroutineScope(dispatcher)

@Singleton
@Provides
fun propertiesStorageRepo(
@Named(STORAGE_SCOPE) storageScope: CoroutineScope
@Named(STORAGE_SCOPE) storageScope: CoroutineScope,
): PropertiesStorageRepo {
return PropertiesStorageRepo(storageScope)
}

const val STORAGE_SCOPE = "storageScope"
}
}
11 changes: 5 additions & 6 deletions app/src/main/java/dev/arkbuilders/arkmemo/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import dev.arkbuilders.arklib.user.properties.PropertiesStorageRepo
import dev.arkbuilders.arkmemo.repo.graphics.GraphicNotesRepo
import dev.arkbuilders.arkmemo.repo.NotesRepo
import dev.arkbuilders.arkmemo.repo.text.TextNotesRepo
import dev.arkbuilders.arkmemo.models.GraphicNote
import dev.arkbuilders.arkmemo.models.TextNote
import dev.arkbuilders.arkmemo.models.VoiceNote
import dev.arkbuilders.arkmemo.preferences.MemoPreferences
import dev.arkbuilders.arkmemo.repo.NotesRepo
import dev.arkbuilders.arkmemo.repo.NotesRepoHelper
import dev.arkbuilders.arkmemo.repo.graphics.GraphicNotesRepo
import dev.arkbuilders.arkmemo.repo.text.TextNotesRepo
import dev.arkbuilders.arkmemo.repo.voices.VoiceNotesRepo


@InstallIn(SingletonComponent::class)
@Module
abstract class RepositoryModule {
Expand All @@ -33,7 +32,7 @@ abstract class RepositoryModule {
@Provides
fun provideNotesRepoHelper(
memoPreferences: MemoPreferences,
propertiesStorageRepo: PropertiesStorageRepo
propertiesStorageRepo: PropertiesStorageRepo,
) = NotesRepoHelper(memoPreferences, propertiesStorageRepo)
}
}
}
5 changes: 2 additions & 3 deletions app/src/main/java/dev/arkbuilders/arkmemo/graphics/Color.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.arkbuilders.arkmemo.graphics

enum class Color(val code: Int, val value: String) {

BLACK(ColorCode.black, "black"),

GRAY(ColorCode.gray, "gray"),
Expand All @@ -16,5 +15,5 @@ enum class Color(val code: Int, val value: String) {

PURPLE(ColorCode.purple, "purple"),

WHITE(ColorCode.white, "white")
}
WHITE(ColorCode.white, "white"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ internal object ColorCode {
val purple by lazy { android.graphics.Color.parseColor("#7A5AF8") }
val white by lazy { android.graphics.Color.parseColor("#FFFFFF") }
val brown by lazy { android.graphics.Color.parseColor("#B54708") }
}
}
Loading

0 comments on commit 6a90eca

Please sign in to comment.