Skip to content

Commit

Permalink
update ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
az4521 committed Apr 1, 2024
1 parent 893415f commit b3961fc
Show file tree
Hide file tree
Showing 579 changed files with 15,039 additions and 11,101 deletions.
85 changes: 47 additions & 38 deletions app/src/main/java/eu/kanade/tachiyomi/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,20 @@ import exh.log.EHLogLevel
import exh.ui.lock.LockActivityDelegate
import io.realm.Realm
import io.realm.RealmConfiguration
import java.io.File
import java.security.NoSuchAlgorithmException
import java.security.Security
import javax.net.ssl.SSLContext
import kotlin.concurrent.thread
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.conscrypt.Conscrypt
import timber.log.Timber
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.InjektScope
import uy.kohesive.injekt.registry.default.DefaultRegistrar
import java.io.File
import java.security.NoSuchAlgorithmException
import java.security.Security
import javax.net.ssl.SSLContext
import kotlin.concurrent.thread

open class App : Application(), LifecycleObserver {

override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
Expand Down Expand Up @@ -157,11 +156,12 @@ open class App : Application(), LifecycleObserver {

// EXH
private fun deleteOldMetadataRealm() {
val config = RealmConfiguration.Builder()
.name("gallery-metadata.realm")
.schemaVersion(3)
.deleteRealmIfMigrationNeeded()
.build()
val config =
RealmConfiguration.Builder()
.name("gallery-metadata.realm")
.schemaVersion(3)
.deleteRealmIfMigrationNeeded()
.build()
Realm.deleteRealm(config)

// Delete old paper db files
Expand All @@ -182,37 +182,46 @@ open class App : Application(), LifecycleObserver {
private fun setupExhLogging() {
EHLogLevel.init(this)

val logLevel = if (EHLogLevel.shouldLog(EHLogLevel.EXTRA)) {
LogLevel.ALL
} else {
LogLevel.WARN
}
val logLevel =
if (EHLogLevel.shouldLog(EHLogLevel.EXTRA)) {
LogLevel.ALL
} else {
LogLevel.WARN
}

val logConfig = LogConfiguration.Builder()
.logLevel(logLevel)
.t()
.st(2)
.nb()
.build()
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(object : DateFileNameGenerator() {
override fun generateFileName(logLevel: Int, timestamp: Long): String {
return super.generateFileName(logLevel, timestamp) + "-${BuildConfig.BUILD_TYPE}"
}
})
.cleanStrategy(FileLastModifiedCleanStrategy(7.days.inMilliseconds.longValue))
.backupStrategy(NeverBackupStrategy())
.build()
val logFolder =
File(
Environment.getExternalStorageDirectory().absolutePath + File.separator +
getString(R.string.app_name),
"logs"
)

printers +=
FilePrinter
.Builder(logFolder.absolutePath)
.fileNameGenerator(
object : DateFileNameGenerator() {
override fun generateFileName(
logLevel: Int,
timestamp: Long
): String {
return super.generateFileName(logLevel, timestamp) + "-${BuildConfig.BUILD_TYPE}"
}
}
)
.cleanStrategy(FileLastModifiedCleanStrategy(7.days.inMilliseconds.longValue))
.backupStrategy(NeverBackupStrategy())
.build()

// Install Crashlytics in prod
if (!BuildConfig.DEBUG) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/eu/kanade/tachiyomi/AppInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ package eu.kanade.tachiyomi
*/
object AppInfo {
fun getVersionCode() = BuildConfig.VERSION_CODE

fun getVersionName() = BuildConfig.VERSION_NAME
}
1 change: 0 additions & 1 deletion app/src/main/java/eu/kanade/tachiyomi/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import uy.kohesive.injekt.api.addSingletonFactory
import uy.kohesive.injekt.api.get

class AppModule(val app: Application) : InjektModule {

override fun InjektRegistrar.registerInjectables() {
addSingleton(app)

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/eu/kanade/tachiyomi/Migrations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import eu.kanade.tachiyomi.extension.ExtensionUpdateJob
import java.io.File

object Migrations {

// TODO NATIVE TACHIYOMI MIGRATIONS ARE FUCKED UP DUE TO DIFFERING VERSION NUMBERS

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ import rx.Observable
import uy.kohesive.injekt.injectLazy

abstract class AbstractBackupManager(protected val context: Context) {

internal val databaseHelper: DatabaseHelper by injectLazy()
internal val sourceManager: SourceManager by injectLazy()
internal val trackManager: TrackManager by injectLazy()
protected val preferences: PreferencesHelper by injectLazy()

abstract fun createBackup(uri: Uri, flags: Int, isJob: Boolean): String?
abstract fun createBackup(
uri: Uri,
flags: Int,
isJob: Boolean
): String?

/**
* Returns manga
*
* @return [Manga], null if not found
*/
internal fun getMangaFromDatabase(manga: Manga): Manga? =
databaseHelper.getManga(manga.url, manga.source).executeAsBlocking()
internal fun getMangaFromDatabase(manga: Manga): Manga? = databaseHelper.getManga(manga.url, manga.source).executeAsBlocking()

/**
* [Observable] that fetches chapter information
Expand All @@ -43,7 +45,12 @@ abstract class AbstractBackupManager(protected val context: Context) {
* @param chapters list of chapters in the backup
* @return [Observable] that contains manga
*/
internal open fun restoreChapterFetchObservable(source: Source, manga: Manga, chapters: List<Chapter>, throttleManager: EHentaiThrottleManager): Observable<Pair<List<Chapter>, List<Chapter>>> {
internal open fun restoreChapterFetchObservable(
source: Source,
manga: Manga,
chapters: List<Chapter>,
throttleManager: EHentaiThrottleManager
): Observable<Pair<List<Chapter>, List<Chapter>>> {
return (
if (source is EHentai) {
source.fetchChapterList(manga, throttleManager::throttle)
Expand All @@ -69,16 +76,14 @@ abstract class AbstractBackupManager(protected val context: Context) {
*
* @return [Manga] from library
*/
protected fun getFavoriteManga(): List<Manga> =
databaseHelper.getFavoriteMangas().executeAsBlocking()
protected fun getFavoriteManga(): List<Manga> = databaseHelper.getFavoriteMangas().executeAsBlocking()

/**
* Inserts manga and returns id
*
* @return id of [Manga], null if not found
*/
internal fun insertManga(manga: Manga): Long? =
databaseHelper.insertManga(manga).executeAsBlocking().insertedId()
internal fun insertManga(manga: Manga): Long? = databaseHelper.insertManga(manga).executeAsBlocking().insertedId()

/**
* Inserts list of chapters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.util.chapter.NoChaptersException
import exh.eh.EHentaiThrottleManager
import kotlinx.coroutines.Job
import rx.Observable
import uy.kohesive.injekt.injectLazy
import java.io.File
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import kotlinx.coroutines.Job
import rx.Observable
import uy.kohesive.injekt.injectLazy

abstract class AbstractBackupRestore<T : AbstractBackupManager>(protected val context: Context, protected val notifier: BackupNotifier) {

protected val db: DatabaseHelper by injectLazy()
protected val trackManager: TrackManager by injectLazy()

Expand Down Expand Up @@ -69,15 +68,20 @@ abstract class AbstractBackupRestore<T : AbstractBackupManager>(protected val co
* @param manga manga that needs updating
* @return [Observable] that contains manga
*/
internal fun chapterFetchObservable(source: Source, manga: Manga, chapters: List<Chapter>): Observable<Pair<List<Chapter>, List<Chapter>>> {
internal fun chapterFetchObservable(
source: Source,
manga: Manga,
chapters: List<Chapter>
): Observable<Pair<List<Chapter>, List<Chapter>>> {
return backupManager.restoreChapterFetchObservable(source, manga, chapters /* SY --> */, throttleManager /* SY <-- */)
// If there's any error, return empty update and continue.
.onErrorReturn {
val errorMessage = if (it is NoChaptersException) {
context.getString(R.string.no_chapters_error)
} else {
it.message
}
val errorMessage =
if (it is NoChaptersException) {
context.getString(R.string.no_chapters_error)
} else {
it.message
}
errors.add(Date() to "${manga.title} - $errorMessage")
Pair(emptyList(), emptyList())
}
Expand All @@ -89,7 +93,10 @@ abstract class AbstractBackupRestore<T : AbstractBackupManager>(protected val co
* @param tracks list containing tracks from restore file.
* @return [Observable] that contains updated track item
*/
internal fun trackingFetchObservable(manga: Manga, tracks: List<Track>): Observable<Track> {
internal fun trackingFetchObservable(
manga: Manga,
tracks: List<Track>
): Observable<Track> {
return Observable.from(tracks)
.flatMap { track ->
val service = trackManager.getService(track.sync_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ abstract class AbstractBackupRestoreValidator {
protected val sourceManager: SourceManager by injectLazy()
protected val trackManager: TrackManager by injectLazy()

abstract fun validate(context: Context, uri: Uri): Results
abstract fun validate(
context: Context,
uri: Uri
): Results

data class Results(val missingSources: List<String>, val missingTrackers: List<String>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.data.backup
import eu.kanade.tachiyomi.BuildConfig.APPLICATION_ID as ID

object BackupConst {

private const val NAME = "BackupRestoreServices"
const val EXTRA_URI = "$ID.$NAME.EXTRA_URI"
const val EXTRA_FLAGS = "$ID.$NAME.EXTRA_FLAGS"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import eu.kanade.tachiyomi.util.system.isServiceRunning
* Service for backing up library information to a JSON file.
*/
class BackupCreateService : Service() {

companion object {
// Filter options
internal const val BACKUP_CATEGORY = 0x1
Expand All @@ -38,8 +37,7 @@ class BackupCreateService : Service() {
* @param context the application context.
* @return true if the service is running, false otherwise.
*/
fun isRunning(context: Context): Boolean =
context.isServiceRunning(BackupCreateService::class.java)
fun isRunning(context: Context): Boolean = context.isServiceRunning(BackupCreateService::class.java)

/**
* Make a backup from library
Expand All @@ -48,13 +46,19 @@ class BackupCreateService : Service() {
* @param uri path of Uri
* @param flags determines what to backup
*/
fun start(context: Context, uri: Uri, flags: Int, type: Int) {
fun start(
context: Context,
uri: Uri,
flags: Int,
type: Int
) {
if (!isRunning(context)) {
val intent = Intent(context, BackupCreateService::class.java).apply {
putExtra(BackupConst.EXTRA_URI, uri)
putExtra(BackupConst.EXTRA_FLAGS, flags)
putExtra(BackupConst.EXTRA_TYPE, type)
}
val intent =
Intent(context, BackupCreateService::class.java).apply {
putExtra(BackupConst.EXTRA_URI, uri)
putExtra(BackupConst.EXTRA_FLAGS, flags)
putExtra(BackupConst.EXTRA_TYPE, type)
}
ContextCompat.startForegroundService(context, intent)
}
}
Expand Down Expand Up @@ -97,17 +101,22 @@ class BackupCreateService : Service() {
*/
override fun onBind(intent: Intent): IBinder? = null

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
override fun onStartCommand(
intent: Intent?,
flags: Int,
startId: Int
): Int {
if (intent == null) return START_NOT_STICKY

try {
val uri = intent.getParcelableExtra<Uri>(BackupConst.EXTRA_URI)!!
val backupFlags = intent.getIntExtra(BackupConst.EXTRA_FLAGS, 0)
val backupType = intent.getIntExtra(BackupConst.EXTRA_TYPE, BackupConst.BACKUP_TYPE_LEGACY)
val backupManager = when (backupType) {
BackupConst.BACKUP_TYPE_FULL -> FullBackupManager(this)
else -> LegacyBackupManager(this)
}
val backupManager =
when (backupType) {
BackupConst.BACKUP_TYPE_FULL -> FullBackupManager(this)
else -> LegacyBackupManager(this)
}

val backupFileUri = backupManager.createBackup(uri, backupFlags, false)?.toUri()
val unifile = UniFile.fromUri(this, backupFileUri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import androidx.work.WorkerParameters
import eu.kanade.tachiyomi.data.backup.full.FullBackupManager
import eu.kanade.tachiyomi.data.backup.legacy.LegacyBackupManager
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import java.util.concurrent.TimeUnit
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.util.concurrent.TimeUnit

class BackupCreatorJob(private val context: Context, workerParams: WorkerParameters) :
Worker(context, workerParams) {

override fun doWork(): Result {
val preferences = Injekt.get<PreferencesHelper>()
val backupManager = FullBackupManager(context)
Expand All @@ -35,16 +34,22 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet
companion object {
private const val TAG = "BackupCreator"

fun setupTask(context: Context, prefInterval: Int? = null) {
fun setupTask(
context: Context,
prefInterval: Int? = null
) {
val preferences = Injekt.get<PreferencesHelper>()
val interval = prefInterval ?: preferences.backupInterval().get()
if (interval > 0) {
val request = PeriodicWorkRequestBuilder<BackupCreatorJob>(
interval.toLong(), TimeUnit.HOURS,
10, TimeUnit.MINUTES
)
.addTag(TAG)
.build()
val request =
PeriodicWorkRequestBuilder<BackupCreatorJob>(
interval.toLong(),
TimeUnit.HOURS,
10,
TimeUnit.MINUTES
)
.addTag(TAG)
.build()

WorkManager.getInstance(context).enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, request)
} else {
Expand Down
Loading

0 comments on commit b3961fc

Please sign in to comment.