Skip to content

Commit

Permalink
Fix KtLint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shubertm committed Nov 4, 2024
1 parent 00c875d commit 88070d8
Show file tree
Hide file tree
Showing 58 changed files with 2,541 additions and 2,051 deletions.
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
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") }
}
}
97 changes: 55 additions & 42 deletions app/src/main/java/dev/arkbuilders/arkmemo/graphics/SVG.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dev.arkbuilders.arkmemo.graphics

import android.graphics.Paint
import android.util.Log
import android.graphics.Path as AndroidDrawPath
import android.util.Xml
import dev.arkbuilders.arkmemo.ui.viewmodels.DrawPath
import dev.arkbuilders.arkmemo.utils.getColorCode
Expand All @@ -11,6 +10,7 @@ import org.xmlpull.v1.XmlPullParser
import java.nio.file.Path
import kotlin.io.path.reader
import kotlin.io.path.writer
import android.graphics.Path as AndroidDrawPath

class SVG {
private var strokeColor = Color.BLACK.value
Expand All @@ -21,14 +21,15 @@ class SVG {
private val paths = ArrayDeque<DrawPath>()

private val paint
get() = Paint().also {
it.color = strokeColor.getColorCode()
it.style = Paint.Style.STROKE
it.strokeWidth = strokeSize.getStrokeSize()
it.strokeCap = Paint.Cap.ROUND
it.strokeJoin = Paint.Join.ROUND
it.isAntiAlias = true
}
get() =
Paint().also {
it.color = strokeColor.getColorCode()
it.style = Paint.Style.STROKE
it.strokeWidth = strokeSize.getStrokeSize()
it.strokeCap = Paint.Cap.ROUND
it.strokeJoin = Paint.Join.ROUND
it.isAntiAlias = true
}

fun addCommand(command: SVGCommand) {
commands.addLast(command)
Expand Down Expand Up @@ -61,13 +62,14 @@ class SVG {

fun getPaths(): Collection<DrawPath> = paths

fun copy(): SVG = SVG().apply {
strokeColor = this@SVG.strokeColor
fill = this@SVG.fill
viewBox = this@SVG.viewBox
commands.addAll(this@SVG.commands)
paths.addAll(this@SVG.paths)
}
fun copy(): SVG =
SVG().apply {
strokeColor = this@SVG.strokeColor
fill = this@SVG.fill
viewBox = this@SVG.viewBox
commands.addAll(this@SVG.commands)
paths.addAll(this@SVG.paths)
}

private fun createCanvasPaths() {
if (commands.isNotEmpty()) {
Expand All @@ -90,10 +92,15 @@ class SVG {
path.lineTo(command.x, command.y)
}
}
paths.addLast(DrawPath(path, paint.apply {
color = strokeColor.getColorCode()
strokeWidth = strokeSize.getStrokeSize()
}))
paths.addLast(
DrawPath(
path,
paint.apply {
color = strokeColor.getColorCode()
strokeWidth = strokeSize.getStrokeSize()
},
),
)
}
}
}
Expand All @@ -116,9 +123,10 @@ class SVG {
XmlPullParser.START_TAG -> {
when (tag) {
SVG_TAG -> {
viewBox = ViewBox.fromString(
getAttributeValue("", Attributes.VIEW_BOX)
)
viewBox =
ViewBox.fromString(
getAttributeValue("", Attributes.VIEW_BOX),
)
}
PATH_TAG -> {
pathCount += 1
Expand Down Expand Up @@ -149,10 +157,12 @@ class SVG {
if (commandElements.size > 4) {
strokeSize = commandElements[4].toInt()
}
commands.addLast(SVGCommand.MoveTo.fromString(command).apply {
paintColor = strokeColor
brushSizeId = strokeSize
})
commands.addLast(
SVGCommand.MoveTo.fromString(command).apply {
paintColor = strokeColor
brushSizeId = strokeSize
},
)
}
SVGCommand.AbsLineTo.CODE -> {
if (commandElements.size > 3) {
Expand All @@ -161,10 +171,12 @@ class SVG {
if (commandElements.size > 4) {
strokeSize = commandElements[4].toInt()
}
commands.addLast(SVGCommand.MoveTo.fromString(command).apply {
paintColor = strokeColor
brushSizeId = strokeSize
})
commands.addLast(
SVGCommand.MoveTo.fromString(command).apply {
paintColor = strokeColor
brushSizeId = strokeSize
},
)
}
SVGCommand.AbsQuadTo.CODE -> {
if (commandElements.size > 5) {
Expand All @@ -173,10 +185,12 @@ class SVG {
if (commandElements.size > 6) {
strokeSize = commandElements[6].toInt()
}
commands.addLast(SVGCommand.AbsQuadTo.fromString(command).apply {
paintColor = strokeColor
brushSizeId = strokeSize
})
commands.addLast(
SVGCommand.AbsQuadTo.fromString(command).apply {
paintColor = strokeColor
brushSizeId = strokeSize
},
)
}
else -> {}
}
Expand Down Expand Up @@ -208,7 +222,7 @@ data class ViewBox(
val x: Float = 0f,
val y: Float = 0f,
val width: Float = 100f,
val height: Float = 100f
val height: Float = 100f,
) {
override fun toString(): String = "$x $y $width $height"

Expand All @@ -219,20 +233,19 @@ data class ViewBox(
viewBox[0].toFloat(),
viewBox[1].toFloat(),
viewBox[2].toFloat(),
viewBox[3].toFloat()
viewBox[3].toFloat(),
)
}
}
}

sealed class SVGCommand {

var paintColor = Color.BLACK.value
var brushSizeId = Size.TINY.id

class MoveTo(
val x: Float,
val y: Float
val y: Float,
) : SVGCommand() {
override fun toString(): String = "$CODE $x $y $paintColor $brushSizeId"

Expand All @@ -255,7 +268,7 @@ sealed class SVGCommand {

class AbsLineTo(
val x: Float,
val y: Float
val y: Float,
) : SVGCommand() {
override fun toString(): String = "$CODE $x $y $paintColor $brushSizeId"

Expand All @@ -280,7 +293,7 @@ sealed class SVGCommand {
val x1: Float,
val y1: Float,
val x2: Float,
val y2: Float
val y2: Float,
) : SVGCommand() {
override fun toString(): String = "$CODE $x1 $y1 $x2 $y2 $paintColor $brushSizeId"

Expand All @@ -307,4 +320,4 @@ sealed class SVGCommand {
private const val COMMA = ","
private const val XML_NS_URI = "http://www.w3.org/2000/svg"
private const val SVG_TAG = "svg"
private const val PATH_TAG = "path"
private const val PATH_TAG = "path"
5 changes: 2 additions & 3 deletions app/src/main/java/dev/arkbuilders/arkmemo/graphics/Size.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.arkbuilders.arkmemo.graphics

enum class Size(val id: Int, val value: Float) {

TINY(0, 5f),

SMALL(1, 10f),
Expand All @@ -10,5 +9,5 @@ enum class Size(val id: Int, val value: Float) {

LARGE(3, 20f),

HUGE(4, 25f)
}
HUGE(4, 25f),
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,73 +9,77 @@ import java.nio.file.Path
import javax.inject.Inject
import kotlin.io.path.createTempFile

class ArkAudioRecorderImpl @Inject constructor(
@ApplicationContext private val context: Context
): ArkAudioRecorder {
class ArkAudioRecorderImpl
@Inject
constructor(
@ApplicationContext private val context: Context,
) : ArkAudioRecorder {
private val tag = "ArkAudioRecorderImpl"

private val TAG = "ArkAudioRecorderImpl"
private var recorder: MediaRecorder? = null
private val tempFile = createTempFile().toFile()

private var recorder: MediaRecorder? = null
private val tempFile = createTempFile().toFile()
override fun init() {
recorder =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
MediaRecorder(context)
} else {
MediaRecorder()
}
recorder?.apply {
setAudioSource(MediaRecorder.AudioSource.MIC)
setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP)
setOutputFile(tempFile)
setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB)
prepare()
}
}

override fun init() {
recorder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
MediaRecorder(context)
else MediaRecorder()
recorder?.apply {
setAudioSource(MediaRecorder.AudioSource.MIC)
setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP)
setOutputFile(tempFile)
setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB)
prepare()
override fun start() {
recorder?.start()
}
}

override fun start() {
recorder?.start()
}
override fun pause() {
recorder?.pause()
}

override fun pause() {
recorder?.pause()
}
override fun resume() {
recorder?.resume()
}

override fun resume() {
recorder?.resume()
}
override fun reset() {
recorder?.reset()
}

override fun reset() {
recorder?.reset()
}
override fun stop() {
recorder?.let {
try {
it.stop()
} catch (e: RuntimeException) {
Log.e(tag, "stop exception: " + e.message)
}

override fun stop() {
recorder?.let {
try {
it.stop()
} catch (e: RuntimeException) {
Log.e(TAG, "stop exception: " + e.message)
it.release()
}

it.release()
recorder = null
}
recorder = null
}

override fun maxAmplitude(): Int {
return try {
recorder?.maxAmplitude ?: 0
} catch (e: Exception) {
0
override fun maxAmplitude(): Int {
return try {
recorder?.maxAmplitude ?: 0
} catch (e: Exception) {
0
}
}
}

override fun getRecording(): Path = tempFile.toPath()
override fun getRecording(): Path = tempFile.toPath()

override suspend fun deleteTempFile(): Boolean {
return try {
tempFile.delete()
} catch (e: Exception) {
Log.e(TAG, "deleteTempFile exception: " + e.message)
false
override suspend fun deleteTempFile(): Boolean {
return try {
tempFile.delete()
} catch (e: Exception) {
Log.e(tag, "deleteTempFile exception: " + e.message)
false
}
}
}
}
Loading

0 comments on commit 88070d8

Please sign in to comment.