2016-03-19 17:48:55 +01:00
|
|
|
package eu.kanade.tachiyomi
|
|
|
|
|
|
|
|
|
|
import android.app.Application
|
2016-10-15 11:12:16 +02:00
|
|
|
import android.content.Context
|
2016-12-13 20:47:46 +01:00
|
|
|
import android.content.res.Configuration
|
2019-04-14 05:47:57 +02:00
|
|
|
import android.os.Environment
|
2016-10-15 11:12:16 +02:00
|
|
|
import android.support.multidex.MultiDex
|
2019-04-14 05:47:57 +02:00
|
|
|
import com.elvishew.xlog.LogConfiguration
|
|
|
|
|
import com.elvishew.xlog.LogLevel
|
|
|
|
|
import com.elvishew.xlog.XLog
|
|
|
|
|
import com.elvishew.xlog.printer.AndroidPrinter
|
|
|
|
|
import com.elvishew.xlog.printer.Printer
|
|
|
|
|
import com.elvishew.xlog.printer.file.FilePrinter
|
|
|
|
|
import com.elvishew.xlog.printer.file.clean.FileLastModifiedCleanStrategy
|
|
|
|
|
import com.elvishew.xlog.printer.file.naming.DateFileNameGenerator
|
2016-11-06 18:44:14 +01:00
|
|
|
import com.evernote.android.job.JobManager
|
2017-08-24 23:11:43 +02:00
|
|
|
import com.github.ajalt.reprint.core.Reprint
|
2019-04-14 05:47:57 +02:00
|
|
|
import com.kizitonwose.time.days
|
2017-04-04 17:42:17 +02:00
|
|
|
import eu.kanade.tachiyomi.data.backup.BackupCreatorJob
|
2016-11-06 18:44:14 +01:00
|
|
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
2017-10-10 14:15:41 +02:00
|
|
|
import eu.kanade.tachiyomi.data.notification.Notifications
|
2019-04-14 05:47:57 +02:00
|
|
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
|
|
|
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
2017-12-11 20:01:28 +01:00
|
|
|
import eu.kanade.tachiyomi.data.updater.UpdaterJob
|
2016-12-13 20:47:46 +01:00
|
|
|
import eu.kanade.tachiyomi.util.LocaleHelper
|
2019-04-14 05:47:57 +02:00
|
|
|
import exh.log.CrashlyticsPrinter
|
2019-04-14 16:46:06 +02:00
|
|
|
import exh.log.EHLogLevel
|
2017-08-25 23:31:38 +02:00
|
|
|
import io.realm.Realm
|
|
|
|
|
import io.realm.RealmConfiguration
|
2019-04-14 05:47:57 +02:00
|
|
|
import kotlinx.coroutines.GlobalScope
|
|
|
|
|
import kotlinx.coroutines.launch
|
2016-03-19 17:48:55 +01:00
|
|
|
import timber.log.Timber
|
2016-06-14 15:13:48 +02:00
|
|
|
import uy.kohesive.injekt.Injekt
|
2016-06-15 17:58:28 +02:00
|
|
|
import uy.kohesive.injekt.api.InjektScope
|
2019-04-14 05:47:57 +02:00
|
|
|
import uy.kohesive.injekt.api.get
|
2016-06-15 17:58:28 +02:00
|
|
|
import uy.kohesive.injekt.registry.default.DefaultRegistrar
|
2017-08-25 23:31:38 +02:00
|
|
|
import java.io.File
|
|
|
|
|
import kotlin.concurrent.thread
|
2016-03-19 17:48:55 +01:00
|
|
|
|
|
|
|
|
open class App : Application() {
|
|
|
|
|
|
|
|
|
|
override fun onCreate() {
|
|
|
|
|
super.onCreate()
|
2018-01-09 12:27:45 +01:00
|
|
|
if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
|
|
|
|
|
|
2016-06-15 17:58:28 +02:00
|
|
|
Injekt = InjektScope(DefaultRegistrar())
|
2016-06-14 15:13:48 +02:00
|
|
|
Injekt.importModule(AppModule(this))
|
2016-06-15 17:58:28 +02:00
|
|
|
|
2016-11-06 18:44:14 +01:00
|
|
|
setupJobManager()
|
2017-10-10 14:15:41 +02:00
|
|
|
setupNotificationChannels()
|
2019-04-14 05:47:57 +02:00
|
|
|
GlobalScope.launch { deleteOldMetadataRealm() } // Delete old metadata DB (EH)
|
2017-08-24 23:11:43 +02:00
|
|
|
Reprint.initialize(this) //Setup fingerprint (EH)
|
2019-04-14 05:47:57 +02:00
|
|
|
setupExhLogging() // EXH logging
|
2016-12-13 20:47:46 +01:00
|
|
|
|
2016-12-26 16:56:19 +01:00
|
|
|
LocaleHelper.updateConfiguration(this, resources.configuration)
|
2016-03-19 17:48:55 +01:00
|
|
|
}
|
|
|
|
|
|
2016-10-15 11:12:16 +02:00
|
|
|
override fun attachBaseContext(base: Context) {
|
|
|
|
|
super.attachBaseContext(base)
|
2019-04-13 15:10:44 +02:00
|
|
|
MultiDex.install(this)
|
2016-10-15 11:12:16 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-13 20:47:46 +01:00
|
|
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
|
|
|
|
super.onConfigurationChanged(newConfig)
|
2016-12-26 16:56:19 +01:00
|
|
|
LocaleHelper.updateConfiguration(this, newConfig, true)
|
2016-12-13 20:47:46 +01:00
|
|
|
}
|
|
|
|
|
|
2016-11-06 18:44:14 +01:00
|
|
|
protected open fun setupJobManager() {
|
2019-03-14 21:44:20 +01:00
|
|
|
try {
|
|
|
|
|
JobManager.create(this).addJobCreator { tag ->
|
|
|
|
|
when (tag) {
|
|
|
|
|
LibraryUpdateJob.TAG -> LibraryUpdateJob()
|
|
|
|
|
UpdaterJob.TAG -> UpdaterJob()
|
|
|
|
|
BackupCreatorJob.TAG -> BackupCreatorJob()
|
|
|
|
|
else -> null
|
|
|
|
|
}
|
2016-11-06 18:44:14 +01:00
|
|
|
}
|
2019-03-14 21:44:20 +01:00
|
|
|
} catch (e: Exception) {
|
|
|
|
|
Timber.w("Can't initialize job manager")
|
2016-11-06 18:44:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 14:15:41 +02:00
|
|
|
protected open fun setupNotificationChannels() {
|
|
|
|
|
Notifications.createChannels(this)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-24 03:03:49 +01:00
|
|
|
// EXH
|
2019-04-14 05:47:57 +02:00
|
|
|
private fun deleteOldMetadataRealm() {
|
2017-08-25 23:31:38 +02:00
|
|
|
Realm.init(this)
|
|
|
|
|
val config = RealmConfiguration.Builder()
|
|
|
|
|
.name("gallery-metadata.realm")
|
2018-04-16 15:53:18 +02:00
|
|
|
.schemaVersion(3)
|
2017-08-26 09:40:59 +02:00
|
|
|
.deleteRealmIfMigrationNeeded()
|
2017-08-25 23:31:38 +02:00
|
|
|
.build()
|
2019-04-14 05:47:57 +02:00
|
|
|
Realm.deleteRealm(config)
|
2017-08-25 23:31:38 +02:00
|
|
|
|
|
|
|
|
//Delete old paper db files
|
|
|
|
|
listOf(
|
|
|
|
|
File(filesDir, "gallery-ex"),
|
|
|
|
|
File(filesDir, "gallery-perveden"),
|
|
|
|
|
File(filesDir, "gallery-nhentai")
|
|
|
|
|
).forEach {
|
|
|
|
|
if(it.exists()) {
|
|
|
|
|
thread {
|
|
|
|
|
it.deleteRecursively()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-14 05:47:57 +02:00
|
|
|
|
|
|
|
|
// EXH
|
|
|
|
|
private fun setupExhLogging() {
|
2019-04-14 16:46:06 +02:00
|
|
|
val logLevel = if(BuildConfig.DEBUG || EHLogLevel.shouldLog(EHLogLevel.EXTRA)) {
|
2019-04-14 05:47:57 +02:00
|
|
|
LogLevel.ALL
|
|
|
|
|
} else {
|
|
|
|
|
LogLevel.WARN
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val logConfig = LogConfiguration.Builder()
|
|
|
|
|
.logLevel(logLevel)
|
|
|
|
|
.t()
|
|
|
|
|
.st(2)
|
|
|
|
|
.nb()
|
|
|
|
|
.build()
|
|
|
|
|
|
|
|
|
|
val printers = mutableListOf<Printer>(AndroidPrinter())
|
|
|
|
|
|
|
|
|
|
val logFolder = File(Environment.getExternalStorageDirectory().absolutePath + File.separator +
|
|
|
|
|
getString(R.string.app_name), "logs")
|
|
|
|
|
|
|
|
|
|
printers += FilePrinter
|
|
|
|
|
.Builder(logFolder.absolutePath)
|
|
|
|
|
.fileNameGenerator(DateFileNameGenerator())
|
|
|
|
|
.cleanStrategy(FileLastModifiedCleanStrategy(7.days.inMilliseconds.longValue))
|
|
|
|
|
.build()
|
|
|
|
|
|
|
|
|
|
// Install Crashlytics in prod
|
|
|
|
|
if(!BuildConfig.DEBUG) {
|
|
|
|
|
printers += CrashlyticsPrinter(LogLevel.ERROR)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XLog.init(
|
|
|
|
|
logConfig,
|
|
|
|
|
*printers.toTypedArray()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
XLog.d("Application booting...")
|
|
|
|
|
}
|
2016-03-19 17:48:55 +01:00
|
|
|
}
|