Skip to content
Draft
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
50 changes: 50 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
id("io.gitlab.arturbosch.detekt").version("1.23.7")
id("jacoco")
}

Expand Down Expand Up @@ -117,4 +118,53 @@
)
)
)
}

detekt {
// Version of detekt that will be used. When unspecified the latest detekt
// version found will be used. Override to stay on the same version.
toolVersion = "1.23.7"

// The directories where detekt looks for source files.
// Defaults to `files("src/main/java", "src/test/java", "src/main/kotlin", "src/test/kotlin")`.
source.setFrom("src/main/java", "src/main/kotlin")

// Builds the AST in parallel. Rules are always executed in parallel.
// Can lead to speedups in larger projects. `false` by default.
parallel = false

// Define the detekt configuration(s) you want to use.
// Defaults to the default detekt configuration.
config.setFrom("detekt.yml")

// Applies the config files on top of detekt's default config file. `false` by default.
buildUponDefaultConfig = false

// Turns on all the rules. `false` by default.
allRules = false

// Disables all default detekt rulesets and will only run detekt with custom rules
// defined in plugins passed in with `detektPlugins` configuration. `false` by default.
disableDefaultRuleSets = false

// Adds debug output during task execution. `false` by default.
debug = false

// If set to `true` the build does not fail when the
// maxIssues count was reached. Defaults to `false`.
ignoreFailures = false

// Android: Don't create tasks for the specified build flavor (e.g. "production")
ignoredFlavors = listOf("production")

// Android: Don't create tasks for the specified build variants (e.g. "productionRelease")
ignoredVariants = listOf("productionRelease")

// Specify the base path for file paths in the formatted reports.
// If not set, all file paths reported will be absolute file path.
basePath = projectDir.absolutePath

dependencies {
detektPlugins(libs.detekt.rules.compose)
}
}

Check warning on line 170 in app/build.gradle.kts

View check run for this annotation

codefactor.io / CodeFactor

app/build.gradle.kts#L170

The file app\build.gradle.kts is not ending with a new line. (detekt.NewLineAtEndOfFile)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import android.util.Log
import android.view.MotionEvent
import androidx.annotation.OptIn
import androidx.camera.core.*

Check warning on line 12 in app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt#L12

androidx.camera.core.* is a wildcard import. Replace it with fully qualified imports. (detekt.WildcardImport)
import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.camera.video.Quality
import androidx.camera.video.QualitySelector
Expand All @@ -17,7 +17,7 @@
import androidx.camera.video.Recording
import androidx.camera.video.VideoCapture
import androidx.camera.view.PreviewView
import androidx.compose.runtime.*

Check warning on line 20 in app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt#L20

androidx.compose.runtime.* is a wildcard import. Replace it with fully qualified imports. (detekt.WildcardImport)
import androidx.compose.runtime.snapshots.SnapshotStateMap
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModel
Expand All @@ -36,7 +36,7 @@
import java.util.concurrent.Executors

@Suppress("UNCHECKED_CAST")
class StoneCameraViewModel(

Check warning on line 39 in app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt#L39

Class 'StoneCameraViewModel' with '28' functions detected. Defined threshold inside classes is set to '11'. (detekt.TooManyFunctions)
context: Context,
private val registeredPlugins: List<IPlugin>
) :
Expand Down Expand Up @@ -343,8 +343,8 @@
private fun bindUseCases() {
// TODO consider a job that can be interrupted?

// These dependencies load in asynchronously, and can be destroyed & re-created at various points (e.g. rotating)

Check warning on line 346 in app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt#L346

Line detected, which is longer than the defined maximum line length in the code style. (detekt.MaxLineLength)
if (previewView == null || _cameraProvider == null || lifecycleOwner == null || _selectedCameraId == null) return

Check warning on line 347 in app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt#L347

Line detected, which is longer than the defined maximum line length in the code style. (detekt.MaxLineLength)

Check warning on line 347 in app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt#L347

This condition is too complex (4). Defined complexity threshold for conditions is set to '4'. (detekt.ComplexCondition)
else {
try {
preview.surfaceProvider = previewView!!.surfaceProvider
Expand All @@ -355,7 +355,7 @@
_cameraProvider!!.unbindAll()

// TODO move this into a plugin-level solution
// also: on more powerful devices that can support 3 use-cases, we should bind them all from day 1 for fast switching

Check warning on line 358 in app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt#L358

Line detected, which is longer than the defined maximum line length in the code style. (detekt.MaxLineLength)
if(selectedMode == "Photo") {
camera = _cameraProvider!!.bindToLifecycle(
lifecycleOwner!!,
Expand All @@ -378,9 +378,9 @@
_previewView = plugins.fold(previewView!!) { v, plugin ->
plugin.onPreviewView(this, v)
}
} catch (e: Exception) {

Check warning on line 381 in app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt#L381

The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled. (detekt.TooGenericExceptionCaught)
// Handle binding errors
e.printStackTrace()

Check warning on line 383 in app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt#L383

Do not print a stack trace. These debug statements should be removed or replaced with a logger. (detekt.PrintStackTrace)

}
}
Expand Down Expand Up @@ -432,7 +432,7 @@
// Await all work to finish
workList.awaitAll()
Log.d("Analyzer", "All plugins completed successfully")
} catch (e: Exception) {

Check warning on line 435 in app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/StoneCameraViewModel.kt#L435

The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled. (detekt.TooGenericExceptionCaught)
Log.e("Analyzer", "Error in one or more plugins", e)
} finally {
// Close the ImageProxy after all plugins are done
Expand All @@ -458,4 +458,4 @@
}
throw IllegalArgumentException("Unknown ViewModel class")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package co.stonephone.stonecamera.plugins

import android.app.Application
import android.util.Size
import androidx.camera.core.AspectRatio
import androidx.camera.core.ImageCapture
Expand All @@ -14,7 +13,6 @@
import androidx.compose.material3.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import co.stonephone.stonecamera.MyApplication
Expand Down Expand Up @@ -91,10 +89,13 @@
targetSize: Size?, // e.g. 3000×3000 for 1:1
ratio: Float? // e.g. 1.0f for 1:1, 1.333...f for 4:3, etc.
): ResolutionSelector {
val sixteenByNine = 16f / 9f

Check warning on line 92 in app/src/main/java/co/stonephone/stonecamera/plugins/AspectRatioPlugin.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/plugins/AspectRatioPlugin.kt#L92

This expression contains a magic number. Consider defining it to a well named constant. (detekt.MagicNumber)

Check warning on line 92 in app/src/main/java/co/stonephone/stonecamera/plugins/AspectRatioPlugin.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/plugins/AspectRatioPlugin.kt#L92

This expression contains a magic number. Consider defining it to a well named constant. (detekt.MagicNumber)
val fourByThree = 4f / 3f

Check warning on line 93 in app/src/main/java/co/stonephone/stonecamera/plugins/AspectRatioPlugin.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/plugins/AspectRatioPlugin.kt#L93

This expression contains a magic number. Consider defining it to a well named constant. (detekt.MagicNumber)

Check warning on line 93 in app/src/main/java/co/stonephone/stonecamera/plugins/AspectRatioPlugin.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/plugins/AspectRatioPlugin.kt#L93

This expression contains a magic number. Consider defining it to a well named constant. (detekt.MagicNumber)
val wiggleRoom = 0.01f

Check warning on line 94 in app/src/main/java/co/stonephone/stonecamera/plugins/AspectRatioPlugin.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/plugins/AspectRatioPlugin.kt#L94

This expression contains a magic number. Consider defining it to a well named constant. (detekt.MagicNumber)
val aspectRatioConst = when {
ratio == null -> null // “FULL” or unknown
kotlin.math.abs(ratio - (4f / 3f)) < 0.01f -> AspectRatio.RATIO_4_3
kotlin.math.abs(ratio - (16f / 9f)) < 0.01f -> AspectRatio.RATIO_16_9
kotlin.math.abs(ratio - (fourByThree)) < wiggleRoom -> AspectRatio.RATIO_4_3
kotlin.math.abs(ratio - (sixteenByNine)) < wiggleRoom -> AspectRatio.RATIO_16_9
else -> null // e.g. 1:1 or any custom ratio
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import co.stonephone.stonecamera.StoneCameraViewModel
import co.stonephone.stonecamera.utils.calculateImageCoverageRegion
import co.stonephone.stonecamera.utils.selectCameraForStepZoomLevel

class DebugPlugin : IPlugin {
override val id: String = "debugPlugin"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package co.stonephone.stonecamera.plugins

import android.annotation.SuppressLint
import androidx.camera.core.ImageCapture
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.*

Check warning on line 10 in app/src/main/java/co/stonephone/stonecamera/plugins/ShutterFlashPlugin.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/plugins/ShutterFlashPlugin.kt#L10

androidx.compose.runtime.* is a wildcard import. Replace it with fully qualified imports. (detekt.WildcardImport)
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import co.stonephone.stonecamera.StoneCameraViewModel
Expand All @@ -30,11 +29,11 @@
if (showShutterFlash) {
LaunchedEffect(Unit) {
// Wait for the fade-in duration
delay(20)

Check warning on line 32 in app/src/main/java/co/stonephone/stonecamera/plugins/ShutterFlashPlugin.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/plugins/ShutterFlashPlugin.kt#L32

This expression contains a magic number. Consider defining it to a well named constant. (detekt.MagicNumber)
// Trigger fade-out
isFadingOut = true
// Wait for the fade-out duration
delay(50)

Check warning on line 36 in app/src/main/java/co/stonephone/stonecamera/plugins/ShutterFlashPlugin.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/plugins/ShutterFlashPlugin.kt#L36

This expression contains a magic number. Consider defining it to a well named constant. (detekt.MagicNumber)
// Reset state
showShutterFlash = false
isFadingOut = false
Expand All @@ -43,8 +42,8 @@

AnimatedVisibility(
visible = showShutterFlash || isFadingOut,
enter = fadeIn(animationSpec = androidx.compose.animation.core.tween(20)), // Fade in over 100ms

Check warning on line 45 in app/src/main/java/co/stonephone/stonecamera/plugins/ShutterFlashPlugin.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/plugins/ShutterFlashPlugin.kt#L45

This expression contains a magic number. Consider defining it to a well named constant. (detekt.MagicNumber)
exit = fadeOut(animationSpec = androidx.compose.animation.core.tween(50)) // Fade out over 200ms

Check warning on line 46 in app/src/main/java/co/stonephone/stonecamera/plugins/ShutterFlashPlugin.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/plugins/ShutterFlashPlugin.kt#L46

This expression contains a magic number. Consider defining it to a well named constant. (detekt.MagicNumber)
) {
Box(
modifier = Modifier
Expand All @@ -55,7 +54,7 @@
}

@SuppressLint("ClickableViewAccessibility")
override fun initialize(viewModel: StoneCameraViewModel) {

Check warning on line 57 in app/src/main/java/co/stonephone/stonecamera/plugins/ShutterFlashPlugin.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/plugins/ShutterFlashPlugin.kt#L57

This empty block of code can be removed. (detekt.EmptyFunctionBlock)
}

override fun onCaptureStarted(stoneCameraViewModel: StoneCameraViewModel) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package co.stonephone.stonecamera.plugins

import android.annotation.SuppressLint
import android.graphics.Rect
import android.view.MotionEvent
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import co.stonephone.stonecamera.MyApplication
import co.stonephone.stonecamera.StoneCameraViewModel
import co.stonephone.stonecamera.ui.FocusReticle
import co.stonephone.stonecamera.utils.calculateImageCoverageRegion

class TapToFocusPlugin : IPlugin {
override val id: String = "tapToFocusPlugin"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package co.stonephone.stonecamera.plugins

import android.annotation.SuppressLint
import androidx.compose.ui.platform.LocalContext
import co.stonephone.stonecamera.StoneCameraViewModel
import co.stonephone.stonecamera.ui.ZoomBar
import androidx.compose.foundation.layout.*

Check warning on line 6 in app/src/main/java/co/stonephone/stonecamera/plugins/ZoomBarPlugin.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/plugins/ZoomBarPlugin.kt#L6

androidx.compose.foundation.layout.* is a wildcard import. Replace it with fully qualified imports. (detekt.WildcardImport)
import androidx.compose.runtime.*

Check warning on line 7 in app/src/main/java/co/stonephone/stonecamera/plugins/ZoomBarPlugin.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/plugins/ZoomBarPlugin.kt#L7

androidx.compose.runtime.* is a wildcard import. Replace it with fully qualified imports. (detekt.WildcardImport)
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier


Expand Down Expand Up @@ -46,7 +44,7 @@
}

@SuppressLint("ClickableViewAccessibility")
override fun initialize(viewModel: StoneCameraViewModel) {

Check warning on line 47 in app/src/main/java/co/stonephone/stonecamera/plugins/ZoomBarPlugin.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/plugins/ZoomBarPlugin.kt#L47

This empty block of code can be removed. (detekt.EmptyFunctionBlock)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
val pixelArraySize = characteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE)
var mp = 0.0
if (pixelArraySize != null) {
mp = (pixelArraySize.width.toDouble() * pixelArraySize.height.toDouble()) / 1_000_000.0

Check warning on line 68 in app/src/main/java/co/stonephone/stonecamera/utils/StoneCameraInfo.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/utils/StoneCameraInfo.kt#L68

This expression contains a magic number. Consider defining it to a well named constant. (detekt.MagicNumber)
}

// 3) Determine camera type by computing 35 mm-equivalent focal length
Expand All @@ -80,7 +80,7 @@
physicalSize.width * physicalSize.width +
physicalSize.height * physicalSize.height
)
val fullFrameDiagonal = 43.27f // 35mm "full frame" diagonal in mm

Check warning on line 83 in app/src/main/java/co/stonephone/stonecamera/utils/StoneCameraInfo.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/utils/StoneCameraInfo.kt#L83

This expression contains a magic number. Consider defining it to a well named constant. (detekt.MagicNumber)
val eqFocalLength = focalLengthMm * (fullFrameDiagonal / sensorDiagonalMm)
focalLength = eqFocalLength
cameraType = classifyCameraType(eqFocalLength)
Expand All @@ -105,7 +105,7 @@
cameraInfos.add(info)
}
} catch (e: CameraAccessException) {
e.printStackTrace()

Check warning on line 108 in app/src/main/java/co/stonephone/stonecamera/utils/StoneCameraInfo.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/utils/StoneCameraInfo.kt#L108

Do not print a stack trace. These debug statements should be removed or replaced with a logger. (detekt.PrintStackTrace)
}

return getRelativeZoomLevels(cameraInfos)
Expand All @@ -117,8 +117,8 @@
*/
private fun classifyCameraType(eqFocalLength: Float): String {
return when {
eqFocalLength < 18f -> "Ultrawide"

Check warning on line 120 in app/src/main/java/co/stonephone/stonecamera/utils/StoneCameraInfo.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/utils/StoneCameraInfo.kt#L120

This expression contains a magic number. Consider defining it to a well named constant. (detekt.MagicNumber)
eqFocalLength < 30f -> "Wide"

Check warning on line 121 in app/src/main/java/co/stonephone/stonecamera/utils/StoneCameraInfo.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/main/java/co/stonephone/stonecamera/utils/StoneCameraInfo.kt#L121

This expression contains a magic number. Consider defining it to a well named constant. (detekt.MagicNumber)
else -> "Telephoto"
}
}
Expand Down Expand Up @@ -157,4 +157,4 @@
}

return infos
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.junit.Test

import org.junit.Assert.*

Check warning on line 5 in app/src/test/java/co/stonephone/stonecamera/ExampleUnitTest.kt

View check run for this annotation

codefactor.io / CodeFactor

app/src/test/java/co/stonephone/stonecamera/ExampleUnitTest.kt#L5

org.junit.Assert.* is a wildcard import. Replace it with fully qualified imports. (detekt.WildcardImport)

/**
* Example local unit test, which will execute on the development machine (host).
Expand All @@ -14,4 +14,4 @@
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
}
Loading
Loading