Run default Android Studio formatter on code

This commit is contained in:
arkon
2020-02-17 17:23:37 -05:00
parent a1fadce7c6
commit 3ecc883944
109 changed files with 640 additions and 585 deletions
@@ -161,7 +161,8 @@ internal class DownloadNotifier(private val context: Context) {
fun onError(error: String? = null, chapter: String? = null) {
// Create notification
with(notificationBuilder) {
setContentTitle(chapter ?: context.getString(R.string.download_notifier_downloader_title))
setContentTitle(chapter
?: context.getString(R.string.download_notifier_downloader_title))
setContentText(error ?: context.getString(R.string.download_notifier_unkown_error))
setSmallIcon(android.R.drawable.stat_sys_warning)
clearActions()
@@ -131,7 +131,8 @@ class DownloadService : Service() {
subscriptions += ReactiveNetwork.observeNetworkConnectivity(applicationContext)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ state -> onNetworkStateChanged(state)
.subscribe({ state ->
onNetworkStateChanged(state)
}, {
toast(R.string.download_queue_error)
stopSelf()
@@ -156,7 +157,9 @@ class DownloadService : Service() {
DISCONNECTED -> {
downloadManager.stopDownloads(getString(R.string.download_notifier_no_network))
}
else -> { /* Do nothing */ }
else -> {
/* Do nothing */
}
}
}
@@ -82,7 +82,8 @@ class Downloader(
/**
* Whether the downloader is running.
*/
@Volatile private var isRunning: Boolean = false
@Volatile
private var isRunning: Boolean = false
init {
launchNow {
@@ -175,7 +176,8 @@ class Downloader(
.concatMap { downloadChapter(it).subscribeOn(Schedulers.io()) }
.onBackpressureBuffer()
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ completeDownload(it)
.subscribe({
completeDownload(it)
}, { error ->
DownloadService.stop(context)
Timber.e(error)
@@ -376,10 +378,10 @@ class Downloader(
private fun getImageExtension(response: Response, file: UniFile): String {
// Read content type if available.
val mime = response.body?.contentType()?.let { ct -> "${ct.type}/${ct.subtype}" }
// Else guess from the uri.
?: context.contentResolver.getType(file.uri)
// Else read magic numbers.
?: ImageUtil.findImageType { file.openInputStream() }?.mime
// Else guess from the uri.
?: context.contentResolver.getType(file.uri)
// Else read magic numbers.
?: ImageUtil.findImageType { file.openInputStream() }?.mime
return MimeTypeMap.getSingleton().getExtensionFromMimeType(mime) ?: "jpg"
}
@@ -10,17 +10,24 @@ class Download(val source: HttpSource, val manga: Manga, val chapter: Chapter) {
var pages: List<Page>? = null
@Volatile @Transient var totalProgress: Int = 0
@Volatile
@Transient
var totalProgress: Int = 0
@Volatile @Transient var downloadedImages: Int = 0
@Volatile
@Transient
var downloadedImages: Int = 0
@Volatile @Transient var status: Int = 0
@Volatile
@Transient
var status: Int = 0
set(status) {
field = status
statusSubject?.onNext(this)
}
@Transient private var statusSubject: PublishSubject<Download>? = null
@Transient
private var statusSubject: PublishSubject<Download>? = null
fun setStatusSubject(subject: PublishSubject<Download>?) {
statusSubject = subject
@@ -34,4 +41,4 @@ class Download(val source: HttpSource, val manga: Manga, val chapter: Chapter) {
const val DOWNLOADED = 3
const val ERROR = 4
}
}
}
@@ -12,7 +12,7 @@ import java.util.concurrent.CopyOnWriteArrayList
class DownloadQueue(
private val store: DownloadStore,
private val queue: MutableList<Download> = CopyOnWriteArrayList<Download>())
: List<Download> by queue {
: List<Download> by queue {
private val statusSubject = PublishSubject.create<Download>()
@@ -42,7 +42,9 @@ class DownloadQueue(
}
fun remove(chapters: List<Chapter>) {
for (chapter in chapters) { remove(chapter) }
for (chapter in chapters) {
remove(chapter)
}
}
fun remove(manga: Manga) {
@@ -59,7 +61,7 @@ class DownloadQueue(
}
fun getActiveDownloads(): Observable<Download> =
Observable.from(this).filter { download -> download.status == Download.DOWNLOADING }
Observable.from(this).filter { download -> download.status == Download.DOWNLOADING }
fun getStatusObservable(): Observable<Download> = statusSubject.onBackpressureBuffer()