Skip to content

Commit

Permalink
[enhancement] Fix Lint warnings including: * Unused namespaces in XML…
Browse files Browse the repository at this point in the history
… * Add task configuration avoidance by using register when define a gradle task * Update protected visibility in final class to private as they are effectively the same * Add private modifier for variables where needed * Upgrade kotlin version & kotlin gradle plugin to 1.8.20 * Naming issues and others

[lint] Execute ktlintCheck prior to every git commit to scan for lint errors
  • Loading branch information
tuancoltech committed Oct 31, 2023
1 parent daaca01 commit 5496970
Show file tree
Hide file tree
Showing 29 changed files with 134 additions and 165 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
root = true


# noinspection EditorConfigKeyCorrectness
[*]

indent_style = space
Expand Down
19 changes: 19 additions & 0 deletions app/app-scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
echo "*********************************************************"
echo "Running git pre-commit hook, ktlintCheck in progress..."
echo "*********************************************************"

./gradlew ktlintCheck

status=$?

if [ "$status" = 0 ] ; then
echo "Static analysis found no problems."
exit 0
else
echo "*********************************************************"
echo 1>&2 "ktlintCheck found violations it could not fix."
echo "Run ./gradlew ktlintFormat to fix formatting related issues..."
echo "*********************************************************"
exit 1
fi
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ dependencies {
implementation 'com.airbnb.android:lottie:6.1.0'
}

task installGitHook(type: Copy) {
tasks.register('installGitHook', Copy) {
def suffix = "linux"
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
suffix = "windows"
Expand All @@ -197,3 +197,5 @@ task installGitHook(type: Copy) {
rename("pre-commit-$suffix", 'pre-commit')
fileMode 0775
}

build.dependsOn installGitHook
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ import javax.inject.Singleton

@Singleton
class PermissionsHelper @Inject constructor(private val appContext: Context) {
val permissionResultFlow = MutableSharedFlow<Boolean>()
private val permissionResultFlow = MutableSharedFlow<Boolean>()
private var writePermLauncher: ActivityResultLauncher<String>? = null
private var writePermUsingSettingsLauncher: ActivityResultLauncher<String>? =
null
private var writePermLauncher_R: ActivityResultLauncher<String>? = null
private var writePermLauncherR: ActivityResultLauncher<String>? = null

fun registerActivity(activity: AppCompatActivity) {
writePermLauncher = buildWritePermLauncher(activity)
writePermUsingSettingsLauncher =
buildWritePermsUsingSettingsLauncher(activity)
writePermLauncher_R = buildWritePermLauncher_R(activity)
writePermLauncherR = buildWritePermLauncherR(activity)
}

fun isWritePermissionGranted(): Boolean {
Expand All @@ -56,7 +56,7 @@ class PermissionsHelper @Inject constructor(private val appContext: Context) {
) {
val packageUri = "package:" + BuildConfig.APPLICATION_ID
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
writePermLauncher_R!!.launch(packageUri)
writePermLauncherR!!.launch(packageUri)
} else {
val rationale =
fragment?.shouldShowRequestPermissionRationale(
Expand Down Expand Up @@ -120,7 +120,7 @@ class PermissionsHelper @Inject constructor(private val appContext: Context) {
}
}

private fun buildWritePermLauncher_R(
private fun buildWritePermLauncherR(
activity: AppCompatActivity
) =
activity.registerForActivityResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import kotlinx.coroutines.withContext
import dev.arkbuilders.arklib.data.stats.StatsEvent
import dev.arkbuilders.arklib.user.tags.Tag

class AggregatedStatsStorage(val shards: List<StatsStorage>) : StatsStorage {
class AggregatedStatsStorage(private val shards: List<StatsStorage>) : StatsStorage {

override suspend fun init() = withContext(Dispatchers.IO) {
shards.map { launch { it.init() } }.joinAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PlainStatsStorage(
private val index: RootIndex,
private val preferences: Preferences,
private val tagStorage: RootTagsStorage,
private val statsFlow: SharedFlow<StatsEvent>
statsFlow: SharedFlow<StatsEvent>
) : StatsStorage {

private val root = index.path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class StatsStorageRepo(
}
}

suspend fun provide(
private suspend fun provide(
root: RootIndex,
tagsStorage: RootTagsStorage
): PlainStatsStorage =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private const val FLUSH_INTERVAL = 10_000L

abstract class StatsCategoryStorage<out T>(
val root: Path,
val scope: CoroutineScope
private val scope: CoroutineScope
) {
abstract val fileName: String
private val flushFlow = MutableSharedFlow<Unit>().also { flow ->
Expand All @@ -36,7 +36,7 @@ abstract class StatsCategoryStorage<out T>(
abstract fun provideData(): T
protected abstract fun flush()

fun locateStorage() = root.arkFolder().arkStats().resolve(fileName)
fun locateStorage(): Path? = root.arkFolder().arkStats().resolve(fileName)

protected fun requestFlush() = scope.launch {
flushFlow.emit(Unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import kotlin.io.path.writeText

class TagLabeledNStorage(
val index: ResourceIndex,
val tagsStorage: TagStorage,
private val tagsStorage: TagStorage,
root: Path,
scope: CoroutineScope
) : StatsCategoryStorage<Map<Tag, Int>>(root, scope) {
Expand All @@ -26,7 +26,7 @@ class TagLabeledNStorage(

override suspend fun init() {
val storage = locateStorage()
if (storage.exists()) {
if (storage?.exists() == true) {
val json = Json.decodeFromStream<JsonTagLabeledN>(storage.inputStream())
tagLabeledAmount.putAll(json.data)
} else {
Expand Down Expand Up @@ -64,7 +64,7 @@ class TagLabeledNStorage(

override fun flush() {
val data = Json.encodeToString(JsonTagLabeledN(tagLabeledAmount))
locateStorage().writeText(data)
locateStorage()?.writeText(data)
Timber.i("flushed with $tagLabeledAmount")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TagLabeledTSStorage(

override fun flush() {
val data = Json.encodeToString(JsonTagLabeledTS(tagLabeledTS))
locateStorage().writeText(data)
locateStorage()?.writeText(data)
Timber.i("flushed with $tagLabeledTS")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TagQueriedNStorage(

override fun flush() {
val data = Json.encodeToString(JsonTagQueriedN(tagQueriedN))
locateStorage().writeText(data)
locateStorage()?.writeText(data)
Timber.i("flushed with $tagQueriedN")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ class TagQueriedTSStorage(

override suspend fun init() {
val storage = locateStorage()
if (storage.notExists()) return
val json = Json.decodeFromStream<JsonTagQueriedTS>(storage.inputStream())
tagQueriedTS.putAll(json.data)
if (storage?.notExists() == true) return
val json = storage?.let {
Json.decodeFromStream<JsonTagQueriedTS>(it.inputStream())
}
json?.let { tagQueriedTS.putAll(it.data) }
Timber.i("initialized with $tagQueriedTS")
}

Expand All @@ -43,7 +45,7 @@ class TagQueriedTSStorage(

override fun flush() {
val data = Json.encodeToString(JsonTagQueriedTS(tagQueriedTS))
locateStorage().writeText(data)
locateStorage()?.writeText(data)
Timber.i("flushed with $tagQueriedTS")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RootPickerDialogFragment : ArkFilePickerFragment() {
@Inject
lateinit var foldersRepo: FoldersRepo

var rootNotFavorite = false
private var rootNotFavorite = false

override fun onAttach(context: Context) {
App.instance.appComponent.inject(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sealed class TagsSortSideEffect {
}

class TagsSortViewModel(
private val selectorNotEdit: Boolean,
selectorNotEdit: Boolean,
private val preferences: Preferences
) : ViewModel(), ContainerHost<TagsSortState, TagsSortSideEffect> {
override val container: Container<TagsSortState, TagsSortSideEffect> =
Expand Down
Loading

0 comments on commit 5496970

Please sign in to comment.