From 0078cb88c340e7045d2187e7a3d445fcd90f8560 Mon Sep 17 00:00:00 2001 From: len Date: Mon, 21 Mar 2016 14:50:02 +0100 Subject: [PATCH] A few crashes fixed --- .../eu/kanade/tachiyomi/data/cache/CoverCache.kt | 15 +++++++-------- .../tachiyomi/data/download/DownloadService.kt | 2 +- .../ui/base/activity/BaseRxActivity.java | 2 +- .../ui/base/fragment/BaseRxFragment.java | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt index fb78a4f31..3b1f385f8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.data.cache import android.content.Context -import android.text.TextUtils import android.widget.ImageView import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy @@ -38,9 +37,9 @@ class CoverCache(private val context: Context) { * @param imageView imageView where picture should be displayed. */ @JvmOverloads - fun save(thumbnailUrl: String, headers: LazyHeaders, imageView: ImageView? = null) { + fun save(thumbnailUrl: String?, headers: LazyHeaders, imageView: ImageView? = null) { // Check if url is empty. - if (TextUtils.isEmpty(thumbnailUrl)) + if (thumbnailUrl.isNullOrEmpty()) return // Download the cover with Glide and save the file. @@ -51,7 +50,7 @@ class CoverCache(private val context: Context) { override fun onResourceReady(resource: File, anim: GlideAnimation) { try { // Copy the cover from Glide's cache to local cache. - copyToLocalCache(thumbnailUrl, resource) + copyToLocalCache(thumbnailUrl!!, resource) // Check if imageView isn't null and show picture in imageView. if (imageView != null) { @@ -93,9 +92,9 @@ class CoverCache(private val context: Context) { * @param thumbnailUrl the thumbnail url. * @return status of deletion. */ - fun deleteCoverFromCache(thumbnailUrl: String): Boolean { + fun deleteCoverFromCache(thumbnailUrl: String?): Boolean { // Check if url is empty. - if (TextUtils.isEmpty(thumbnailUrl)) + if (thumbnailUrl.isNullOrEmpty()) return false // Remove file. @@ -142,9 +141,9 @@ class CoverCache(private val context: Context) { * @param thumbnailUrl url of thumbnail. * @param headers headers included in Glide request. */ - fun loadFromNetwork(imageView: ImageView, thumbnailUrl: String, headers: LazyHeaders) { + fun loadFromNetwork(imageView: ImageView, thumbnailUrl: String?, headers: LazyHeaders) { // Check if url is empty. - if (TextUtils.isEmpty(thumbnailUrl)) + if (thumbnailUrl.isNullOrEmpty()) return val url = GlideUrl(thumbnailUrl, headers) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt index 50636a116..9add67cd7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt @@ -52,7 +52,7 @@ class DownloadService : Service() { listenNetworkChanges() } - override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { return Service.START_STICKY } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.java b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.java index 0f6a5e486..ec5a12b5b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.java @@ -62,7 +62,7 @@ public abstract class BaseRxActivity

extends BaseActivity i @Override public P createPresenter() { P presenter = superFactory.createPresenter(); - App app = (App) BaseRxActivity.this.getApplication(); + App app = (App) getApplication(); app.getComponentReflection().inject(presenter); ((BasePresenter) presenter).setContext(app.getApplicationContext()); return presenter; diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/fragment/BaseRxFragment.java b/app/src/main/java/eu/kanade/tachiyomi/ui/base/fragment/BaseRxFragment.java index 6752ce448..5a6518207 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/fragment/BaseRxFragment.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/fragment/BaseRxFragment.java @@ -60,7 +60,7 @@ public abstract class BaseRxFragment

extends BaseFragment i @Override public P createPresenter() { P presenter = superFactory.createPresenter(); - App app = (App) BaseRxFragment.this.getActivity().getApplication(); + App app = (App) getActivity().getApplication(); app.getComponentReflection().inject(presenter); ((BasePresenter) presenter).setContext(app.getApplicationContext()); return presenter;