diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84ccdfe3..44222da3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,10 +13,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: set up JDK 11 + - name: set up JDK 17 uses: actions/setup-java@v3 with: - java-version: '11' + java-version: '17' distribution: 'temurin' cache: gradle diff --git a/build.gradle b/build.gradle index 4b739390..9070497f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.nav_version = "2.5.3" + ext.nav_version = "2.6.0" repositories { google() mavenCentral() @@ -13,14 +13,14 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:7.4.1' + classpath 'com.android.tools.build:gradle:8.0.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files classpath 'com.google.gms:google-services:4.3.15' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0" classpath 'com.google.firebase:perf-plugin:1.4.2' - classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.5' + classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.7' // Refactor classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" diff --git a/gradle.properties b/gradle.properties index 4a3d1b2e..96d61fe5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,8 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m -org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +# org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # org.gradle.jvmargs=-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # -XX:MaxPermSize=512m #MaxPermSize is removed in JDK 17 # https://github.com/expo/expo-cli/issues/4196#issuecomment-1035850918 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8d21bd05..a495e2df 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Tue Feb 01 19:53:42 CST 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/main/build.gradle b/main/build.gradle index fff82a3c..8dcb0387 100644 --- a/main/build.gradle +++ b/main/build.gradle @@ -9,13 +9,13 @@ plugins { } android { - compileSdkVersion 32 + compileSdkVersion 33 buildToolsVersion "30.0.3" defaultConfig { applicationId "tw.firemaples.onscreenocr" minSdkVersion 21 - targetSdkVersion 32 + targetSdkVersion 33 versionCode 100 versionName "3.1.15" @@ -73,11 +73,11 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } buildFeatures { viewBinding true @@ -92,24 +92,24 @@ android { dependencies { implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs') - implementation 'androidx.core:core-ktx:1.8.0' // newer version needs API 33 (Android 13) - implementation 'androidx.appcompat:appcompat:1.5.1' // newer version needs API 33 (Android 13) - implementation 'com.google.android.material:material:1.8.0' + implementation 'androidx.core:core-ktx:1.10.1' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.9.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1' // newer version needs API 33 (Android 13) - implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1' // newer version needs API 33 (Android 13) + implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1' + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1' implementation "androidx.preference:preference-ktx:1.2.0" - implementation 'androidx.webkit:webkit:1.5.0' // newer version needs API 33 (Android 13) + implementation 'androidx.webkit:webkit:1.7.0' //noinspection GradleDynamicVersion - testImplementation 'junit:junit:4.+' + testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.0' // For using coroutines in tests // For runBlockingTest, CoroutineDispatcher etc. - testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4" + testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.0' // For InstantTaskExecutorRule testImplementation "androidx.arch.core:core-testing:2.2.0" @@ -125,13 +125,13 @@ dependencies { androidTestImplementation "androidx.navigation:navigation-testing:$nav_version" // required to avoid crash on Android 12 API 31 - implementation 'androidx.work:work-runtime-ktx:2.7.1' // newer version needs API 33 (Android 13) + implementation 'androidx.work:work-runtime-ktx:2.8.1' // Firebase - implementation platform('com.google.firebase:firebase-bom:30.5.0') + implementation platform('com.google.firebase:firebase-bom:32.2.0') implementation 'com.google.firebase:firebase-crashlytics' implementation 'com.google.firebase:firebase-analytics' - implementation 'com.google.firebase:firebase-core' + // implementation 'com.google.firebase:firebase-core' implementation 'com.google.firebase:firebase-config' implementation 'com.google.firebase:firebase-perf' @@ -155,16 +155,16 @@ dependencies { // Kotpref // core - implementation 'com.chibatching.kotpref:kotpref:2.13.1' + implementation 'com.chibatching.kotpref:kotpref:2.13.2' // optional, auto initialization module - implementation 'com.chibatching.kotpref:initializer:2.13.1' + implementation 'com.chibatching.kotpref:initializer:2.13.2' // optional, support saving enum value and ordinal - implementation 'com.chibatching.kotpref:enum-support:2.13.1' + implementation 'com.chibatching.kotpref:enum-support:2.13.2' // optional, support saving json string through Gson - implementation 'com.chibatching.kotpref:gson-support:2.13.1' - implementation 'com.google.code.gson:gson:2.9.0' + implementation 'com.chibatching.kotpref:gson-support:2.13.2' + implementation 'com.google.code.gson:gson:2.10.1' // optional, support LiveData observable preference - implementation 'com.chibatching.kotpref:livedata-support:2.13.1' + implementation 'com.chibatching.kotpref:livedata-support:2.13.2' // implementation 'androidx.lifecycle:lifecycle-livedata:2.2.0' // // experimental, preference screen build dsl // implementation 'com.chibatching.kotpref:preference-screen-dsl:2.13.1' @@ -173,14 +173,14 @@ dependencies { implementation 'com.squareup.retrofit2:retrofit:2.9.0' // Tesseract - implementation 'cz.adaptech.tesseract4android:tesseract4android:4.3.0' + implementation 'cz.adaptech.tesseract4android:tesseract4android:4.4.0' // implementation 'cz.adaptech:tesseract4android:4.1.0' // Microsoft translator implementation 'io.github.firemaples:microsoft-translator-java-api:0.8.8.1' // koral--/android-gif-drawable - implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.23' + implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.25' // // Ad network mediation - Mopub // implementation('com.mopub:mopub-sdk:+@aar') { @@ -200,7 +200,7 @@ dependencies { // implementation 'com.mopub.mediation:adcolony:4.5.0.1' // Admob - implementation 'com.google.android.gms:play-services-ads:22.0.0' + implementation 'com.google.android.gms:play-services-ads:22.2.0' // Facebook Ad network implementation 'com.google.ads.mediation:facebook:6.14.0.0' // Adcolony Ad network @@ -211,5 +211,5 @@ dependencies { implementation 'com.facebook.infer.annotation:infer-annotation:0.18.0' // TouchImageView - implementation 'com.github.MikeOrtiz:TouchImageView:3.2.1' // newer version needs API 33 (Android 13) + implementation 'com.github.MikeOrtiz:TouchImageView:3.3' // newer version needs API 33 (Android 13) } diff --git a/main/src/androidTest/java/tw/firemaples/onscreenocr/repo/OCRRepositoryTest.kt b/main/src/androidTest/java/tw/firemaples/onscreenocr/repo/OCRRepositoryTest.kt index d1c53b5b..7cc796c5 100644 --- a/main/src/androidTest/java/tw/firemaples/onscreenocr/repo/OCRRepositoryTest.kt +++ b/main/src/androidTest/java/tw/firemaples/onscreenocr/repo/OCRRepositoryTest.kt @@ -4,6 +4,7 @@ import junit.framework.TestCase import kotlinx.coroutines.flow.first import kotlinx.coroutines.runBlocking import tw.firemaples.onscreenocr.pref.AppPref +import tw.firemaples.onscreenocr.recognition.TextRecognitionProviderType class OCRRepositoryTest : TestCase() { @@ -13,18 +14,9 @@ class OCRRepositoryTest : TestCase() { super.setUp() } - public override fun tearDown() {} - - fun testGetSelectedOCRLangFlow() = runBlocking { - val lang = "zh" - repo.setSelectedOCRLanguage(lang) - - assertEquals(lang, repo.selectedOCRLangFlow.first()) - } - fun testSetSelectedOCRLanguage() = runBlocking { val lang = "zh" - repo.setSelectedOCRLanguage(lang) + repo.setSelectedOCRLanguage(lang, TextRecognitionProviderType.GoogleMLKit) assertEquals(lang, AppPref.selectedOCRLang) } diff --git a/main/src/main/java/tw/firemaples/onscreenocr/floatings/base/FloatingView.kt b/main/src/main/java/tw/firemaples/onscreenocr/floatings/base/FloatingView.kt index 84cddf02..cbfff4da 100644 --- a/main/src/main/java/tw/firemaples/onscreenocr/floatings/base/FloatingView.kt +++ b/main/src/main/java/tw/firemaples/onscreenocr/floatings/base/FloatingView.kt @@ -5,20 +5,29 @@ import android.graphics.PixelFormat import android.graphics.Point import android.os.Build import android.os.Looper -import android.view.* +import android.view.Gravity +import android.view.LayoutInflater +import android.view.OrientationEventListener +import android.view.View +import android.view.ViewGroup +import android.view.WindowManager import androidx.annotation.CallSuper import androidx.annotation.MainThread import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleRegistry -import kotlinx.coroutines.* +import java.io.Closeable +import kotlin.coroutines.CoroutineContext +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.cancel +import kotlinx.coroutines.cancelChildren import tw.firemaples.onscreenocr.utils.Logger import tw.firemaples.onscreenocr.utils.PermissionUtil import tw.firemaples.onscreenocr.utils.UIUtils import tw.firemaples.onscreenocr.wigets.BackButtonTrackerView import tw.firemaples.onscreenocr.wigets.HomeButtonWatcher -import java.io.Closeable -import kotlin.coroutines.CoroutineContext abstract class FloatingView(protected val context: Context) { @@ -230,9 +239,10 @@ abstract class FloatingView(protected val context: Context) { } protected class FloatingViewLifecycleOwner : LifecycleOwner { - private val lifecycleRegistry = LifecycleRegistry(this) + private val lifecycleRegistry: LifecycleRegistry = LifecycleRegistry(this) - override fun getLifecycle(): Lifecycle = lifecycleRegistry + override val lifecycle: Lifecycle + get() = lifecycleRegistry fun onStateChanged(state: Lifecycle.State) { lifecycleRegistry.currentState = state diff --git a/main/src/main/java/tw/firemaples/onscreenocr/repo/OCRRepository.kt b/main/src/main/java/tw/firemaples/onscreenocr/repo/OCRRepository.kt index d099bd1b..1360b69d 100644 --- a/main/src/main/java/tw/firemaples/onscreenocr/repo/OCRRepository.kt +++ b/main/src/main/java/tw/firemaples/onscreenocr/repo/OCRRepository.kt @@ -3,6 +3,8 @@ package tw.firemaples.onscreenocr.repo import android.content.Context import androidx.lifecycle.asFlow import com.chibatching.kotpref.livedata.asLiveData +import java.io.File +import java.io.IOException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow @@ -18,8 +20,6 @@ import tw.firemaples.onscreenocr.recognition.TextRecognitionProviderType import tw.firemaples.onscreenocr.recognition.TextRecognizer import tw.firemaples.onscreenocr.utils.Logger import tw.firemaples.onscreenocr.utils.Utils -import java.io.File -import java.io.IOException class OCRRepository { private val logger: Logger by lazy { Logger(OCRRepository::class) }