Skip to content

Commit

Permalink
Refactor: Extracting most UI state to EditingState (#126)
Browse files Browse the repository at this point in the history
#126: Miscellaneous refactoring
---------
* Fixes:
  - share
  - resize
  - SavePathDialog
  - NoBeanDefFoundException in EditModule

* Clarify Serialization in ImageDefaults

* Move all toggleCrop logic from EditScreen to EditViewModel
* Move operations logic from EditScreen to EditViewModel
* Move all state to EditingState

* Extract to EditingState:
  - isCropMode, isEyeDropperMode
  - isRotateMode, isResizeMode, isEraseMode
  - isZoomMode, isPanMode, isBlurMode
  - canUndo, canRedo

* Delete getCachedImageUri
* Extract image loading from EditViewModel file
* Remove context from shareImage

* Remove ktlint gradle plugin and add ktlintCheck to ktlint.gradle
* Run ktlintCheck after ktlintFormat
* Add ktlint gradle plugin + update AGP
* Update workflows, gradle, use JDK 17

* Update compose to 1.6.8

* Refactor packages structure
* Minor refactors
---------
Co-authored-by: Chingiz <[email protected]>
  • Loading branch information
shubertm authored Nov 13, 2024
1 parent 053cbf8 commit e8f7d18
Show file tree
Hide file tree
Showing 70 changed files with 4,031 additions and 3,234 deletions.
648 changes: 627 additions & 21 deletions .editorconfig

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ jobs:
environment: Development
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

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

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation[email protected]
uses: gradle/actions/wrapper-validation@v3

- name: Build debug APK
run: ./gradlew assembleDebug
Expand All @@ -38,17 +38,17 @@ jobs:
environment: Development
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

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

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation[email protected]
uses: gradle/actions/wrapper-validation@v3

- name: Decrypt the keystore for signing
run: |
Expand All @@ -59,7 +59,7 @@ jobs:
run: ./gradlew assembleRelease

- name: Upload release APK
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ark-retouch
path: ./app/build/outputs/apk/release/*.apk
Expand All @@ -69,18 +69,18 @@ jobs:
environment: Development
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

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

- name: Run linter
run: ./gradlew lint

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: lint-results
path: ./app/build/reports/*.html
Expand All @@ -90,14 +90,14 @@ jobs:
environment: Development
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

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

- name: Kotlin linter
run: ./gradlew ktlintCheck
run: ./gradlew ktlint -PautoCorrect=0

6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ jobs:
ACRA_URI: ${{ secrets.ACRARIUM_URI }}
BRANCH_NAME: ${{ github.ref_name }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

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

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation[email protected]
uses: gradle/actions/wrapper-validation@v3

- name: Build Release APK
run: ./gradlew assembleRelease
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
*.tab
*.tab.values.at
misc.xml

*.DS_Store
31 changes: 31 additions & 0 deletions .scripts/ktlint.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
configurations {
ktlint
}

dependencies {
ktlint "com.pinterest:ktlint:0.45.2"
}

tasks.register('ktlint', JavaExec) {
mainClass = "com.pinterest.ktlint.Main"
classpath = configurations.ktlint
args("$rootDir/**/*.kt", "!$rootDir/**/build/**")
jvmArgs "--add-opens=java.base/java.lang=ALL-UNNAMED"

if (project.hasProperty("autoCorrect") && project.property("autoCorrect") == "0") {
logger.quiet("(KTLINT): auto correction is disabled")
} else {
logger.quiet("(KTLINT): auto correction is enabled")
args "-F"
}
}

tasks.register('ktlintCheck', JavaExec) {
classpath = configurations.ktlint
mainClass = "com.pinterest.ktlint.Main"
args "src/**/*.kt", "**.kts", "!**/build/**"
}

tasks.preBuild.dependsOn ktlintCheck

tasks.ktlintCheck.dependsOn ktlint
48 changes: 20 additions & 28 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import org.apache.tools.ant.taskdefs.condition.Os

plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'org.jlleitschuh.gradle.ktlint'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.8.21'
}

apply from: "$project.rootDir/.scripts/ktlint.gradle"

android {
compileSdk 33
compileSdk 34

namespace 'dev.arkbuilders.arkretouch'

defaultConfig {
def login = System.getenv("ACRA_LOGIN") ?: ""
Expand All @@ -18,7 +19,7 @@ android {

applicationId "dev.arkbuilders.arkretouch2"
minSdk 26
targetSdk 32
targetSdk 34
versionCode 1
versionName "1.0"
setProperty("archivesBaseName", "ark-retouch")
Expand Down Expand Up @@ -69,6 +70,7 @@ android {
buildFeatures {
compose true
viewBinding true
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion "1.3.1"
Expand All @@ -82,20 +84,24 @@ android {

dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation "androidx.appcompat:appcompat:1.5.1"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0"

def composeVersion = "1.6.8"
implementation "androidx.compose.ui:ui-graphics-android:$composeVersion"
implementation "androidx.compose.ui:ui:$composeVersion"
implementation "androidx.compose.material:material:$composeVersion"
implementation "androidx.compose.ui:ui-tooling-preview:$composeVersion"

implementation 'com.jakewharton.timber:timber:5.0.1'
implementation "com.github.bumptech.glide:glide:4.16.0"
kapt "com.github.bumptech.glide:compiler:4.16.0"

implementation 'com.google.dagger:dagger:2.50'
kapt 'com.google.dagger:dagger-compiler:2.50'
def koinVersion = "3.4.3"
implementation("io.insert-koin:koin-android:$koinVersion")
implementation "io.insert-koin:koin-androidx-compose:$koinVersion"

implementation 'com.godaddy.android.colorpicker:compose-color-picker:0.7.0'

Expand All @@ -110,21 +116,7 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}

task installGitHook(type: Copy) {
def suffix = "linux"
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
suffix = "windows"
}
from new File(rootProject.rootDir, "scripts/pre-commit-$suffix")
into { new File(rootProject.rootDir, '.git/hooks') }
rename("pre-commit-$suffix", 'pre-commit')
fileMode 0775
}

tasks.preBuild.dependsOn installGitHook
tasks.preBuild.dependsOn ktlintCheck
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$composeVersion"
debugImplementation "androidx.compose.ui:ui-tooling:$composeVersion"
debugImplementation "androidx.compose.ui:ui-test-manifest:$composeVersion"
}

This file was deleted.

7 changes: 3 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="dev.arkbuilders.arkretouch">
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
Expand All @@ -17,10 +16,10 @@
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
android:theme="@style/Theme.ARKRetouch"
android:name=".presentation.App"
android:name=".App"
tools:targetApi="31">
<activity
android:name=".presentation.main.MainActivity"
android:name="dev.arkbuilders.arkretouch.presentation.main.RootActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize"
android:theme="@style/Theme.ARKRetouch">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
package dev.arkbuilders.arkretouch.presentation
package dev.arkbuilders.arkretouch

import android.app.Application
import dev.arkbuilders.arkfilepicker.folders.FoldersRepo
import dev.arkbuilders.arkretouch.di.EditModule
import dev.arkbuilders.arkretouch.di.common.CommonModule
import org.acra.config.dialog
import org.acra.config.httpSender
import org.acra.data.StringFormat
import org.acra.ktx.initAcra
import org.acra.sender.HttpSender
import dev.arkbuilders.arkretouch.BuildConfig
import dev.arkbuilders.arkretouch.R
import dev.arkbuilders.arkfilepicker.folders.FoldersRepo
import dev.arkbuilders.arkretouch.di.DIManager
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin
import org.koin.core.logger.Level
import timber.log.Timber

class App : Application() {
override fun onCreate() {
super.onCreate()
DIManager.init(this)
Timber.plant(Timber.DebugTree())
FoldersRepo.init(this)

setupKoin()

setupAcra()
}

// FIXME: Let's use Firebase crashlytics instead
private fun setupAcra() {
initAcra {
buildConfigClass = BuildConfig::class.java
reportFormat = StringFormat.JSON
Expand All @@ -35,4 +44,15 @@ class App : Application() {
}
}
}
}

private fun setupKoin() {
startKoin {
androidContext(applicationContext)
androidLogger(Level.INFO)
modules(
EditModule.create(),
CommonModule.create(),
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.arkbuilders.arkretouch.data.model

import androidx.compose.ui.graphics.Paint
import androidx.compose.ui.graphics.Path

class DrawPath(
val path: Path,
val paint: Paint
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.arkbuilders.arkretouch.data.model

import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Paint
import androidx.compose.ui.graphics.PaintingStyle
import dev.arkbuilders.arkretouch.utils.defaultPaint

data class DrawingState(
val currentPaint: Paint = defaultPaint(),
val drawPaint: Paint = defaultPaint(),
val backgroundPaint: Paint = Paint().also { it.color = Color.Transparent },
val erasePaint: Paint = Paint().apply {
shader = null
color = backgroundPaint.color
style = PaintingStyle.Stroke
blendMode = BlendMode.SrcOut
},
val blurSize: Float = 250f,
val blurIntensity: Float = 12f
)
Loading

0 comments on commit e8f7d18

Please sign in to comment.