Fix dependency injection and use custom models extending DB ones

This commit is contained in:
len
2016-06-14 15:17:37 +02:00
parent 658860fdff
commit 237af4b07d
53 changed files with 840 additions and 788 deletions
@@ -16,10 +16,7 @@ import eu.kanade.tachiyomi.data.source.Source
import eu.kanade.tachiyomi.data.source.SourceManager
import eu.kanade.tachiyomi.data.source.model.Page
import eu.kanade.tachiyomi.data.source.online.OnlineSource
import eu.kanade.tachiyomi.util.DiskUtils
import eu.kanade.tachiyomi.util.DynamicConcurrentMergeOperator
import eu.kanade.tachiyomi.util.UrlUtil
import eu.kanade.tachiyomi.util.saveImageTo
import eu.kanade.tachiyomi.util.*
import rx.Observable
import rx.Subscription
import rx.android.schedulers.AndroidSchedulers
@@ -27,12 +24,17 @@ import rx.schedulers.Schedulers
import rx.subjects.BehaviorSubject
import rx.subjects.PublishSubject
import timber.log.Timber
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.io.File
import java.io.FileReader
import java.util.*
import java.util.concurrent.TimeUnit
class DownloadManager(private val context: Context, private val sourceManager: SourceManager, private val preferences: PreferencesHelper) {
class DownloadManager(
private val context: Context,
private val sourceManager: SourceManager = Injekt.get(),
private val preferences: PreferencesHelper = Injekt.get()
) {
private val gson = Gson()
@@ -270,10 +272,8 @@ class DownloadManager(private val context: Context, private val sourceManager: S
}
page
}
.retryWhen {
it.zipWith(Observable.range(1, 3)) { errors, retries -> retries }
.flatMap { retries -> Observable.timer((retries * 2).toLong(), TimeUnit.SECONDS) }
}
// Retry 3 times, waiting 2, 4 and 8 seconds between attempts.
.retryWhen(RetryWithDelay(3, { (2 shl it - 1) * 1000 }))
}
// Public method to get the image from the filesystem. It does NOT provide any way to download the image
@@ -7,14 +7,13 @@ import android.os.IBinder
import android.os.PowerManager
import com.github.pwittchen.reactivenetwork.library.ConnectivityStatus
import com.github.pwittchen.reactivenetwork.library.ReactiveNetwork
import eu.kanade.tachiyomi.App
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.toast
import rx.Subscription
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import javax.inject.Inject
import uy.kohesive.injekt.injectLazy
class DownloadService : Service() {
@@ -29,8 +28,8 @@ class DownloadService : Service() {
}
}
@Inject lateinit var downloadManager: DownloadManager
@Inject lateinit var preferences: PreferencesHelper
val downloadManager: DownloadManager by injectLazy()
val preferences: PreferencesHelper by injectLazy()
private var wakeLock: PowerManager.WakeLock? = null
private var networkChangeSubscription: Subscription? = null
@@ -39,7 +38,6 @@ class DownloadService : Service() {
override fun onCreate() {
super.onCreate()
App.get(this).component.inject(this)
createWakeLock()