From 1bb975c5846b32f2e07fcbf952e19c16b95c4c1e Mon Sep 17 00:00:00 2001 From: davidoskky Date: Thu, 9 Dec 2021 20:17:16 +0100 Subject: [PATCH] Substitute some deprecated functions (#386) * Deprecated color filter * Various deprecated functions --- .../amine/bou/readerforselfoss/AddSourceActivity.kt | 6 +++--- .../java/apps/amine/bou/readerforselfoss/MyApp.kt | 4 ++-- .../amine/bou/readerforselfoss/ReaderActivity.kt | 2 +- .../readerforselfoss/api/selfoss/SelfossModels.kt | 12 +++++++----- .../readerforselfoss/fragments/ArticleFragment.kt | 7 ++++--- .../amine/bou/readerforselfoss/utils/AppUtils.kt | 2 +- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt index ad2bb5d..0517f2e 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt @@ -52,19 +52,19 @@ class AddSourceActivity : AppCompatActivity() { scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value) val drawable = binding.nameInput.background - drawable.setColorFilter(appColors.colorAccent, PorterDuff.Mode.SRC_ATOP) + drawable.setTint(appColors.colorAccent) // TODO: clean binding.nameInput.background = drawable val drawable1 = binding.sourceUri.background - drawable1.setColorFilter(appColors.colorAccent, PorterDuff.Mode.SRC_ATOP) + drawable1.setTint(appColors.colorAccent) binding.sourceUri.background = drawable1 val drawable2 = binding.tags.background - drawable2.setColorFilter(appColors.colorAccent, PorterDuff.Mode.SRC_ATOP) + drawable2.setTint(appColors.colorAccent) binding.tags.background = drawable2 diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt index d44d688..2808320 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt @@ -61,14 +61,14 @@ class MyApp : MultiDexApplication() { private fun initDrawerImageLoader() { DrawerImageLoader.init(object : AbstractDrawerImageLoader() { override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) { - Glide.with(imageView?.context) + Glide.with(imageView.context) .loadMaybeBasicAuth(config, uri.toString()) .apply(RequestOptions.fitCenterTransform().placeholder(placeholder)) .into(imageView) } override fun cancel(imageView: ImageView) { - Glide.with(imageView?.context).clear(imageView) + Glide.with(imageView.context).clear(imageView) } override fun placeholder(ctx: Context, tag: String?): Drawable { diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt index 6a23c55..24b08e9 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt @@ -127,7 +127,7 @@ class ReaderActivity : AppCompatActivity() { notifyAdapter() binding.pager.setPageTransformer(true, DepthPageTransformer()) - (binding.indicator as CircleIndicator).setViewPager(binding.pager) + binding.indicator.setViewPager(binding.pager) binding.pager.addOnPageChangeListener( object : ViewPager.SimpleOnPageChangeListener() { diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossModels.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossModels.kt index 8e0d919..0988cc0 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossModels.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossModels.kt @@ -14,6 +14,8 @@ import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.request.RequestOptions import com.google.gson.annotations.SerializedName +import java.util.* +import kotlin.collections.ArrayList private fun constructUrl(config: Config?, path: String, file: String?): String { return if (file.isEmptyOrNullOrNullString()) { @@ -155,14 +157,14 @@ data class Item( } fun getImages() : ArrayList { - var allImages = ArrayList() + val allImages = ArrayList() for ( image in Jsoup.parse(content).getElementsByTag("img")) { val url = image.attr("src") - if (url.toLowerCase().contains(".jpg") || - url.toLowerCase().contains(".jpeg") || - url.toLowerCase().contains(".png") || - url.toLowerCase().contains(".webp")) + if (url.lowercase(Locale.US).contains(".jpg") || + url.lowercase(Locale.US).contains(".jpeg") || + url.lowercase(Locale.US).contains(".png") || + url.lowercase(Locale.US).contains(".webp")) { allImages.add(url) } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt index 8ea66b3..debb7d6 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt @@ -48,6 +48,7 @@ import retrofit2.Callback import retrofit2.Response import java.net.MalformedURLException import java.net.URL +import java.util.* import java.util.concurrent.ExecutionException import kotlin.collections.ArrayList @@ -430,19 +431,19 @@ class ArticleFragment : Fragment() { override fun shouldInterceptRequest(view: WebView?, url: String): WebResourceResponse? { val glideOptions = RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.ALL) - if (url.toLowerCase().contains(".jpg") || url.toLowerCase().contains(".jpeg")) { + if (url.lowercase(Locale.US).contains(".jpg") || url.lowercase(Locale.US).contains(".jpeg")) { try { val image = Glide.with(view).asBitmap().apply(glideOptions).load(url).submit().get() return WebResourceResponse("image/jpg", "UTF-8", getBitmapInputStream(image, Bitmap.CompressFormat.JPEG)) }catch ( e : ExecutionException) {} } - else if (url.toLowerCase().contains(".png")) { + else if (url.lowercase(Locale.US).contains(".png")) { try { val image = Glide.with(view).asBitmap().apply(glideOptions).load(url).submit().get() return WebResourceResponse("image/jpg", "UTF-8", getBitmapInputStream(image, Bitmap.CompressFormat.PNG)) }catch ( e : ExecutionException) {} } - else if (url.toLowerCase().contains(".webp")) { + else if (url.lowercase(Locale.US).contains(".webp")) { try { val image = Glide.with(view).asBitmap().apply(glideOptions).load(url).submit().get() return WebResourceResponse("image/jpg", "UTF-8", getBitmapInputStream(image, Bitmap.CompressFormat.WEBP)) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/AppUtils.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/AppUtils.kt index 35e5a72..f206294 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/AppUtils.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/AppUtils.kt @@ -13,7 +13,7 @@ fun String.longHash(): Long { val chars = this.toCharArray() for (i in 0 until l) { - h = 31 * h + chars[i].toLong() + h = 31 * h + chars[i].code.toLong() } return h }