From ca1380e2b10aaa5048e1da3e5a83f2254a5390d6 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Tue, 22 Aug 2023 16:17:18 +0300 Subject: [PATCH] Refactor application class --- app/build.gradle | 4 +- .../org/koitharu/kotatsu/HiltTestRunner.kt | 0 .../org/koitharu/kotatsu/Instrumentation.kt | 0 .../org/koitharu/kotatsu/SampleData.kt | 0 .../kotatsu/core/db/MangaDatabaseTest.kt | 0 .../kotatsu/core/os/AppShortcutManagerTest.kt | 0 .../settings/backup/AppBackupAgentTest.kt | 0 .../kotatsu/tracker/domain/TrackerTest.kt | 0 .../kotlin/org/koitharu/kotatsu/KotatsuApp.kt | 45 +++++++++++++++++++ .../core/network/CurlLoggingInterceptor.kt | 0 .../kotatsu/core/parser/DummyParser.kt | 0 .../kotatsu/core/util/ext/DebugExt.kt | 0 .../{KotatsuApp.kt => core/BaseApp.kt} | 42 ++--------------- .../anilist/data/AniListAuthenticator.kt | 5 +-- .../scrobbling/mal/data/MALAuthenticator.kt | 5 +-- .../shikimori/data/ShikimoriAuthenticator.kt | 5 +-- .../kotlin/org/koitharu/kotatsu/KotatsuApp.kt | 7 +++ .../core/network/CurlLoggingInterceptor.kt | 0 .../kotatsu/core/parser/DummyParser.kt | 0 .../koitharu/kotatsu/core/util/ext/Debug.kt | 0 .../kotatsu/core/backup/JsonSerializerTest.kt | 0 .../kotatsu/core/github/VersionIdTest.kt | 0 .../kotatsu/reader/domain/ChapterPagesTest.kt | 0 .../kotatsu/util/CompositeMutexTest.kt | 0 24 files changed, 64 insertions(+), 49 deletions(-) rename app/src/androidTest/{java => kotlin}/org/koitharu/kotatsu/HiltTestRunner.kt (100%) rename app/src/androidTest/{java => kotlin}/org/koitharu/kotatsu/Instrumentation.kt (100%) rename app/src/androidTest/{java => kotlin}/org/koitharu/kotatsu/SampleData.kt (100%) rename app/src/androidTest/{java => kotlin}/org/koitharu/kotatsu/core/db/MangaDatabaseTest.kt (100%) rename app/src/androidTest/{java => kotlin}/org/koitharu/kotatsu/core/os/AppShortcutManagerTest.kt (100%) rename app/src/androidTest/{java => kotlin}/org/koitharu/kotatsu/settings/backup/AppBackupAgentTest.kt (100%) rename app/src/androidTest/{java => kotlin}/org/koitharu/kotatsu/tracker/domain/TrackerTest.kt (100%) create mode 100644 app/src/debug/kotlin/org/koitharu/kotatsu/KotatsuApp.kt rename app/src/debug/{java => kotlin}/org/koitharu/kotatsu/core/network/CurlLoggingInterceptor.kt (100%) rename app/src/debug/{java => kotlin}/org/koitharu/kotatsu/core/parser/DummyParser.kt (100%) rename app/src/debug/{java => kotlin}/org/koitharu/kotatsu/core/util/ext/DebugExt.kt (100%) rename app/src/main/kotlin/org/koitharu/kotatsu/{KotatsuApp.kt => core/BaseApp.kt} (75%) create mode 100644 app/src/release/kotlin/org/koitharu/kotatsu/KotatsuApp.kt rename app/src/release/{java => kotlin}/org/koitharu/kotatsu/core/network/CurlLoggingInterceptor.kt (100%) rename app/src/release/{java => kotlin}/org/koitharu/kotatsu/core/parser/DummyParser.kt (100%) rename app/src/release/{java => kotlin}/org/koitharu/kotatsu/core/util/ext/Debug.kt (100%) rename app/src/test/{java => kotlin}/org/koitharu/kotatsu/core/backup/JsonSerializerTest.kt (100%) rename app/src/test/{java => kotlin}/org/koitharu/kotatsu/core/github/VersionIdTest.kt (100%) rename app/src/test/{java => kotlin}/org/koitharu/kotatsu/reader/domain/ChapterPagesTest.kt (100%) rename app/src/test/{java => kotlin}/org/koitharu/kotatsu/util/CompositeMutexTest.kt (100%) diff --git a/app/build.gradle b/app/build.gradle index c1c1bc179..943f21eeb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,8 +16,8 @@ android { applicationId 'org.koitharu.kotatsu' minSdk = 21 targetSdk = 34 - versionCode = 571 - versionName = '6.0-a2' + versionCode = 572 + versionName = '6.0-a3' generatedDensities = [] testInstrumentationRunner "org.koitharu.kotatsu.HiltTestRunner" ksp { diff --git a/app/src/androidTest/java/org/koitharu/kotatsu/HiltTestRunner.kt b/app/src/androidTest/kotlin/org/koitharu/kotatsu/HiltTestRunner.kt similarity index 100% rename from app/src/androidTest/java/org/koitharu/kotatsu/HiltTestRunner.kt rename to app/src/androidTest/kotlin/org/koitharu/kotatsu/HiltTestRunner.kt diff --git a/app/src/androidTest/java/org/koitharu/kotatsu/Instrumentation.kt b/app/src/androidTest/kotlin/org/koitharu/kotatsu/Instrumentation.kt similarity index 100% rename from app/src/androidTest/java/org/koitharu/kotatsu/Instrumentation.kt rename to app/src/androidTest/kotlin/org/koitharu/kotatsu/Instrumentation.kt diff --git a/app/src/androidTest/java/org/koitharu/kotatsu/SampleData.kt b/app/src/androidTest/kotlin/org/koitharu/kotatsu/SampleData.kt similarity index 100% rename from app/src/androidTest/java/org/koitharu/kotatsu/SampleData.kt rename to app/src/androidTest/kotlin/org/koitharu/kotatsu/SampleData.kt diff --git a/app/src/androidTest/java/org/koitharu/kotatsu/core/db/MangaDatabaseTest.kt b/app/src/androidTest/kotlin/org/koitharu/kotatsu/core/db/MangaDatabaseTest.kt similarity index 100% rename from app/src/androidTest/java/org/koitharu/kotatsu/core/db/MangaDatabaseTest.kt rename to app/src/androidTest/kotlin/org/koitharu/kotatsu/core/db/MangaDatabaseTest.kt diff --git a/app/src/androidTest/java/org/koitharu/kotatsu/core/os/AppShortcutManagerTest.kt b/app/src/androidTest/kotlin/org/koitharu/kotatsu/core/os/AppShortcutManagerTest.kt similarity index 100% rename from app/src/androidTest/java/org/koitharu/kotatsu/core/os/AppShortcutManagerTest.kt rename to app/src/androidTest/kotlin/org/koitharu/kotatsu/core/os/AppShortcutManagerTest.kt diff --git a/app/src/androidTest/java/org/koitharu/kotatsu/settings/backup/AppBackupAgentTest.kt b/app/src/androidTest/kotlin/org/koitharu/kotatsu/settings/backup/AppBackupAgentTest.kt similarity index 100% rename from app/src/androidTest/java/org/koitharu/kotatsu/settings/backup/AppBackupAgentTest.kt rename to app/src/androidTest/kotlin/org/koitharu/kotatsu/settings/backup/AppBackupAgentTest.kt diff --git a/app/src/androidTest/java/org/koitharu/kotatsu/tracker/domain/TrackerTest.kt b/app/src/androidTest/kotlin/org/koitharu/kotatsu/tracker/domain/TrackerTest.kt similarity index 100% rename from app/src/androidTest/java/org/koitharu/kotatsu/tracker/domain/TrackerTest.kt rename to app/src/androidTest/kotlin/org/koitharu/kotatsu/tracker/domain/TrackerTest.kt diff --git a/app/src/debug/kotlin/org/koitharu/kotatsu/KotatsuApp.kt b/app/src/debug/kotlin/org/koitharu/kotatsu/KotatsuApp.kt new file mode 100644 index 000000000..69b456c85 --- /dev/null +++ b/app/src/debug/kotlin/org/koitharu/kotatsu/KotatsuApp.kt @@ -0,0 +1,45 @@ +package org.koitharu.kotatsu + +import android.content.Context +import android.os.StrictMode +import androidx.fragment.app.strictmode.FragmentStrictMode +import org.koitharu.kotatsu.core.BaseApp +import org.koitharu.kotatsu.local.data.LocalMangaRepository +import org.koitharu.kotatsu.local.data.PagesCache +import org.koitharu.kotatsu.parsers.MangaLoaderContext +import org.koitharu.kotatsu.reader.domain.PageLoader + +class KotatsuApp : BaseApp() { + + override fun attachBaseContext(base: Context?) { + super.attachBaseContext(base) + enableStrictMode() + } + + private fun enableStrictMode() { + StrictMode.setThreadPolicy( + StrictMode.ThreadPolicy.Builder() + .detectAll() + .penaltyLog() + .build(), + ) + StrictMode.setVmPolicy( + StrictMode.VmPolicy.Builder() + .detectAll() + .setClassInstanceLimit(LocalMangaRepository::class.java, 1) + .setClassInstanceLimit(PagesCache::class.java, 1) + .setClassInstanceLimit(MangaLoaderContext::class.java, 1) + .setClassInstanceLimit(PageLoader::class.java, 1) + .penaltyLog() + .build(), + ) + FragmentStrictMode.defaultPolicy = FragmentStrictMode.Policy.Builder() + .penaltyDeath() + .detectFragmentReuse() + // .detectWrongFragmentContainer() FIXME: migrate to ViewPager2 + .detectRetainInstanceUsage() + .detectSetUserVisibleHint() + .detectFragmentTagUsage() + .build() + } +} diff --git a/app/src/debug/java/org/koitharu/kotatsu/core/network/CurlLoggingInterceptor.kt b/app/src/debug/kotlin/org/koitharu/kotatsu/core/network/CurlLoggingInterceptor.kt similarity index 100% rename from app/src/debug/java/org/koitharu/kotatsu/core/network/CurlLoggingInterceptor.kt rename to app/src/debug/kotlin/org/koitharu/kotatsu/core/network/CurlLoggingInterceptor.kt diff --git a/app/src/debug/java/org/koitharu/kotatsu/core/parser/DummyParser.kt b/app/src/debug/kotlin/org/koitharu/kotatsu/core/parser/DummyParser.kt similarity index 100% rename from app/src/debug/java/org/koitharu/kotatsu/core/parser/DummyParser.kt rename to app/src/debug/kotlin/org/koitharu/kotatsu/core/parser/DummyParser.kt diff --git a/app/src/debug/java/org/koitharu/kotatsu/core/util/ext/DebugExt.kt b/app/src/debug/kotlin/org/koitharu/kotatsu/core/util/ext/DebugExt.kt similarity index 100% rename from app/src/debug/java/org/koitharu/kotatsu/core/util/ext/DebugExt.kt rename to app/src/debug/kotlin/org/koitharu/kotatsu/core/util/ext/DebugExt.kt diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/KotatsuApp.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/BaseApp.kt similarity index 75% rename from app/src/main/kotlin/org/koitharu/kotatsu/KotatsuApp.kt rename to app/src/main/kotlin/org/koitharu/kotatsu/core/BaseApp.kt index f636b4417..008038107 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/KotatsuApp.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/BaseApp.kt @@ -1,11 +1,9 @@ -package org.koitharu.kotatsu +package org.koitharu.kotatsu.core import android.app.Application import android.content.Context -import android.os.StrictMode import androidx.annotation.WorkerThread import androidx.appcompat.app.AppCompatDelegate -import androidx.fragment.app.strictmode.FragmentStrictMode import androidx.hilt.work.HiltWorkerFactory import androidx.room.InvalidationTracker import androidx.work.Configuration @@ -20,21 +18,19 @@ import org.acra.config.httpSender import org.acra.data.StringFormat import org.acra.ktx.initAcra import org.acra.sender.HttpSender +import org.koitharu.kotatsu.BuildConfig +import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.db.MangaDatabase import org.koitharu.kotatsu.core.os.AppValidator import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.util.WorkServiceStopHelper import org.koitharu.kotatsu.core.util.ext.processLifecycleScope -import org.koitharu.kotatsu.local.data.LocalMangaRepository -import org.koitharu.kotatsu.local.data.PagesCache -import org.koitharu.kotatsu.parsers.MangaLoaderContext -import org.koitharu.kotatsu.reader.domain.PageLoader import org.koitharu.kotatsu.settings.work.WorkScheduleManager import javax.inject.Inject import javax.inject.Provider @HiltAndroidApp -class KotatsuApp : Application(), Configuration.Provider { +open class BaseApp : Application(), Configuration.Provider { @Inject lateinit var databaseObservers: Set<@JvmSuppressWildcards InvalidationTracker.Observer> @@ -63,9 +59,6 @@ class KotatsuApp : Application(), Configuration.Provider { override fun onCreate() { super.onCreate() ACRA.errorReporter.putCustomData("isOriginalApp", appValidator.isOriginalApp.toString()) - if (BuildConfig.DEBUG) { - enableStrictMode() - } AppCompatDelegate.setDefaultNightMode(settings.theme) AppCompatDelegate.setApplicationLocales(settings.appLocales) setupActivityLifecycleCallbacks() @@ -136,31 +129,4 @@ class KotatsuApp : Application(), Configuration.Provider { registerActivityLifecycleCallbacks(it) } } - - private fun enableStrictMode() { - StrictMode.setThreadPolicy( - StrictMode.ThreadPolicy.Builder() - .detectAll() - .penaltyLog() - .build(), - ) - StrictMode.setVmPolicy( - StrictMode.VmPolicy.Builder() - .detectAll() - .setClassInstanceLimit(LocalMangaRepository::class.java, 1) - .setClassInstanceLimit(PagesCache::class.java, 1) - .setClassInstanceLimit(MangaLoaderContext::class.java, 1) - .setClassInstanceLimit(PageLoader::class.java, 1) - .penaltyLog() - .build(), - ) - FragmentStrictMode.defaultPolicy = FragmentStrictMode.Policy.Builder() - .penaltyDeath() - .detectFragmentReuse() - // .detectWrongFragmentContainer() FIXME: migrate to ViewPager2 - .detectRetainInstanceUsage() - .detectSetUserVisibleHint() - .detectFragmentTagUsage() - .build() - } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/anilist/data/AniListAuthenticator.kt b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/anilist/data/AniListAuthenticator.kt index 57f9fc517..4def5e1d6 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/anilist/data/AniListAuthenticator.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/anilist/data/AniListAuthenticator.kt @@ -7,6 +7,7 @@ import okhttp3.Response import okhttp3.Route import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.core.network.CommonHeaders +import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.scrobbling.common.data.ScrobblerStorage import org.koitharu.kotatsu.scrobbling.common.domain.model.ScrobblerService import org.koitharu.kotatsu.scrobbling.common.domain.model.ScrobblerType @@ -49,8 +50,6 @@ class AniListAuthenticator @Inject constructor( runBlocking { repository.authorize(null) } return storage.accessToken }.onFailure { - if (BuildConfig.DEBUG) { - it.printStackTrace() - } + it.printStackTraceDebug() }.getOrNull() } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/mal/data/MALAuthenticator.kt b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/mal/data/MALAuthenticator.kt index 0e43a2e6b..5a343bf9b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/mal/data/MALAuthenticator.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/mal/data/MALAuthenticator.kt @@ -7,6 +7,7 @@ import okhttp3.Response import okhttp3.Route import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.core.network.CommonHeaders +import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.scrobbling.common.data.ScrobblerStorage import org.koitharu.kotatsu.scrobbling.common.domain.model.ScrobblerService import org.koitharu.kotatsu.scrobbling.common.domain.model.ScrobblerType @@ -49,9 +50,7 @@ class MALAuthenticator @Inject constructor( runBlocking { repository.authorize(null) } return storage.accessToken }.onFailure { - if (BuildConfig.DEBUG) { - it.printStackTrace() - } + it.printStackTraceDebug() }.getOrNull() } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/shikimori/data/ShikimoriAuthenticator.kt b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/shikimori/data/ShikimoriAuthenticator.kt index 52b3f9550..d67dd81d8 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/shikimori/data/ShikimoriAuthenticator.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/shikimori/data/ShikimoriAuthenticator.kt @@ -7,6 +7,7 @@ import okhttp3.Response import okhttp3.Route import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.core.network.CommonHeaders +import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.scrobbling.common.data.ScrobblerStorage import org.koitharu.kotatsu.scrobbling.common.domain.model.ScrobblerService import org.koitharu.kotatsu.scrobbling.common.domain.model.ScrobblerType @@ -49,8 +50,6 @@ class ShikimoriAuthenticator @Inject constructor( runBlocking { repository.authorize(null) } return storage.accessToken }.onFailure { - if (BuildConfig.DEBUG) { - it.printStackTrace() - } + it.printStackTraceDebug() }.getOrNull() } diff --git a/app/src/release/kotlin/org/koitharu/kotatsu/KotatsuApp.kt b/app/src/release/kotlin/org/koitharu/kotatsu/KotatsuApp.kt new file mode 100644 index 000000000..d862b196f --- /dev/null +++ b/app/src/release/kotlin/org/koitharu/kotatsu/KotatsuApp.kt @@ -0,0 +1,7 @@ +package org.koitharu.kotatsu + +import org.koitharu.kotatsu.core.BaseApp + +class KotatsuApp : BaseApp() { + +} diff --git a/app/src/release/java/org/koitharu/kotatsu/core/network/CurlLoggingInterceptor.kt b/app/src/release/kotlin/org/koitharu/kotatsu/core/network/CurlLoggingInterceptor.kt similarity index 100% rename from app/src/release/java/org/koitharu/kotatsu/core/network/CurlLoggingInterceptor.kt rename to app/src/release/kotlin/org/koitharu/kotatsu/core/network/CurlLoggingInterceptor.kt diff --git a/app/src/release/java/org/koitharu/kotatsu/core/parser/DummyParser.kt b/app/src/release/kotlin/org/koitharu/kotatsu/core/parser/DummyParser.kt similarity index 100% rename from app/src/release/java/org/koitharu/kotatsu/core/parser/DummyParser.kt rename to app/src/release/kotlin/org/koitharu/kotatsu/core/parser/DummyParser.kt diff --git a/app/src/release/java/org/koitharu/kotatsu/core/util/ext/Debug.kt b/app/src/release/kotlin/org/koitharu/kotatsu/core/util/ext/Debug.kt similarity index 100% rename from app/src/release/java/org/koitharu/kotatsu/core/util/ext/Debug.kt rename to app/src/release/kotlin/org/koitharu/kotatsu/core/util/ext/Debug.kt diff --git a/app/src/test/java/org/koitharu/kotatsu/core/backup/JsonSerializerTest.kt b/app/src/test/kotlin/org/koitharu/kotatsu/core/backup/JsonSerializerTest.kt similarity index 100% rename from app/src/test/java/org/koitharu/kotatsu/core/backup/JsonSerializerTest.kt rename to app/src/test/kotlin/org/koitharu/kotatsu/core/backup/JsonSerializerTest.kt diff --git a/app/src/test/java/org/koitharu/kotatsu/core/github/VersionIdTest.kt b/app/src/test/kotlin/org/koitharu/kotatsu/core/github/VersionIdTest.kt similarity index 100% rename from app/src/test/java/org/koitharu/kotatsu/core/github/VersionIdTest.kt rename to app/src/test/kotlin/org/koitharu/kotatsu/core/github/VersionIdTest.kt diff --git a/app/src/test/java/org/koitharu/kotatsu/reader/domain/ChapterPagesTest.kt b/app/src/test/kotlin/org/koitharu/kotatsu/reader/domain/ChapterPagesTest.kt similarity index 100% rename from app/src/test/java/org/koitharu/kotatsu/reader/domain/ChapterPagesTest.kt rename to app/src/test/kotlin/org/koitharu/kotatsu/reader/domain/ChapterPagesTest.kt diff --git a/app/src/test/java/org/koitharu/kotatsu/util/CompositeMutexTest.kt b/app/src/test/kotlin/org/koitharu/kotatsu/util/CompositeMutexTest.kt similarity index 100% rename from app/src/test/java/org/koitharu/kotatsu/util/CompositeMutexTest.kt rename to app/src/test/kotlin/org/koitharu/kotatsu/util/CompositeMutexTest.kt