Revert changes not related to the gradle upgrade

This commit is contained in:
davidoskky 2023-09-16 14:09:29 +02:00
parent 20aab0ea62
commit 2b82be61d0
11 changed files with 80 additions and 136 deletions

View File

@ -5,7 +5,6 @@ import android.content.res.ColorStateList
import android.os.Bundle import android.os.Bundle
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import bou.amine.apps.readerforselfossv2.android.adapters.SourcesListAdapter import bou.amine.apps.readerforselfossv2.android.adapters.SourcesListAdapter
import bou.amine.apps.readerforselfossv2.android.databinding.ActivitySourcesBinding import bou.amine.apps.readerforselfossv2.android.databinding.ActivitySourcesBinding
@ -37,10 +36,8 @@ class SourcesActivity : AppCompatActivity(), DIAware {
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)
binding.fab.rippleColor = ContextCompat.getColor(this, R.color.colorAccentDark) binding.fab.rippleColor = resources.getColor(R.color.colorAccentDark)
binding.fab.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.colorAccent))
binding.fab.backgroundTintList =
ColorStateList.valueOf(ContextCompat.getColor(this, R.color.colorAccent))
} }
override fun onStop() { override fun onStop() {

View File

@ -6,7 +6,6 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView.ScaleType import android.widget.ImageView.ScaleType
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.R
import bou.amine.apps.readerforselfossv2.android.databinding.CardItemBinding import bou.amine.apps.readerforselfossv2.android.databinding.CardItemBinding
@ -61,7 +60,7 @@ class ItemCardAdapter(
binding.title.setOnTouchListener(LinkOnTouchListener()) binding.title.setOnTouchListener(LinkOnTouchListener())
binding.title.setLinkTextColor(ContextCompat.getColor(c, R.color.colorAccent)) binding.title.setLinkTextColor(c.resources.getColor(R.color.colorAccent))
binding.sourceTitleAndDate.text = itm.sourceAuthorAndDate() binding.sourceTitleAndDate.text = itm.sourceAuthorAndDate()

View File

@ -4,7 +4,6 @@ import android.app.Activity
import android.content.Context import android.content.Context
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.R
import bou.amine.apps.readerforselfossv2.android.databinding.ListItemBinding import bou.amine.apps.readerforselfossv2.android.databinding.ListItemBinding
@ -45,8 +44,7 @@ class ItemListAdapter(
binding.title.setOnTouchListener(LinkOnTouchListener()) binding.title.setOnTouchListener(LinkOnTouchListener())
binding.title.setLinkTextColor(ContextCompat.getColor(c, R.color.colorAccent)) binding.title.setLinkTextColor(c.resources.getColor(R.color.colorAccent))
binding.sourceTitleAndDate.text = itm.sourceAuthorAndDate() binding.sourceTitleAndDate.text = itm.sourceAuthorAndDate()

View File

@ -10,21 +10,13 @@ import android.graphics.drawable.ColorDrawable
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.util.TypedValue import android.util.TypedValue
import android.view.GestureDetector import android.view.*
import android.view.InflateException
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse import android.webkit.WebResourceResponse
import android.webkit.WebSettings import android.webkit.WebSettings
import android.webkit.WebView import android.webkit.WebView
import android.webkit.WebViewClient import android.webkit.WebViewClient
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.core.widget.NestedScrollView import androidx.core.widget.NestedScrollView
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import bou.amine.apps.readerforselfossv2.android.ImageActivity import bou.amine.apps.readerforselfossv2.android.ImageActivity
@ -43,7 +35,6 @@ import bou.amine.apps.readerforselfossv2.model.SelfossModel
import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.repository.Repository
import bou.amine.apps.readerforselfossv2.rest.MercuryApi import bou.amine.apps.readerforselfossv2.rest.MercuryApi
import bou.amine.apps.readerforselfossv2.service.AppSettingsService import bou.amine.apps.readerforselfossv2.service.AppSettingsService
import bou.amine.apps.readerforselfossv2.utils.ImageMimeType
import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded
import bou.amine.apps.readerforselfossv2.utils.getImages import bou.amine.apps.readerforselfossv2.utils.getImages
import bou.amine.apps.readerforselfossv2.utils.getThumbnail import bou.amine.apps.readerforselfossv2.utils.getThumbnail
@ -63,7 +54,7 @@ import org.kodein.di.instance
import java.net.MalformedURLException import java.net.MalformedURLException
import java.net.SocketTimeoutException import java.net.SocketTimeoutException
import java.net.URL import java.net.URL
import java.util.Locale import java.util.*
import java.util.concurrent.ExecutionException import java.util.concurrent.ExecutionException
@ -125,15 +116,9 @@ class ArticleFragment : Fragment(), DIAware {
fab = binding.fab fab = binding.fab
fab.backgroundTintList = fab.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.colorAccent))
ColorStateList.valueOf(
ContextCompat.getColor(
requireContext(),
R.color.colorAccent
)
)
fab.rippleColor = ContextCompat.getColor(requireContext(), R.color.colorAccentDark) fab.rippleColor = resources.getColor(R.color.colorAccentDark)
val floatingToolbar: FloatingToolbar = handleFloatingToolbar() val floatingToolbar: FloatingToolbar = handleFloatingToolbar()
@ -218,8 +203,7 @@ class ArticleFragment : Fragment(), DIAware {
} }
floatingToolbar.attachFab(fab) floatingToolbar.attachFab(fab)
floatingToolbar.background = floatingToolbar.background = ColorDrawable(resources.getColor(R.color.colorAccent))
ColorDrawable(ContextCompat.getColor(requireContext(), R.color.colorAccent))
floatingToolbar.setClickListener( floatingToolbar.setClickListener(
object : FloatingToolbar.ItemClickListener { object : FloatingToolbar.ItemClickListener {
@ -304,7 +288,7 @@ class ArticleFragment : Fragment(), DIAware {
contentText = data.content.orEmpty() contentText = data.content.orEmpty()
htmlToWebview() htmlToWebview()
handleLeadImage(data.lead_image_url) handleLeadImage(data?.lead_image_url)
binding.nestedScrollView.scrollTo(0, 0) binding.nestedScrollView.scrollTo(0, 0)
binding.progressBar.visibility = View.GONE binding.progressBar.visibility = View.GONE
@ -329,19 +313,11 @@ class ArticleFragment : Fragment(), DIAware {
private fun handleImageLoading() { private fun handleImageLoading() {
binding.webcontent.webViewClient = object : WebViewClient() { binding.webcontent.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading( @Deprecated("Deprecated in Java")
view: WebView?, override fun shouldOverrideUrlLoading(view: WebView?, url: String): Boolean {
request: WebResourceRequest? return if (context != null && url.isUrlValid() && binding.webcontent.hitTestResult.type != WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
): Boolean {
val url = request?.url?.toString()
return if (context != null && url != null && url.isUrlValid() && binding.webcontent.hitTestResult.type != WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
try { try {
requireContext().startActivity( requireContext().startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
Intent(
Intent.ACTION_VIEW,
Uri.parse(url)
)
)
} catch (e: ActivityNotFoundException) { } catch (e: ActivityNotFoundException) {
e.sendSilentlyWithAcraWithName("activityNotFound > $url") e.sendSilentlyWithAcraWithName("activityNotFound > $url")
} }
@ -351,42 +327,50 @@ class ArticleFragment : Fragment(), DIAware {
} }
} }
override fun shouldInterceptRequest( @Deprecated("Deprecated in Java")
view: WebView, override fun shouldInterceptRequest(view: WebView, url: String): WebResourceResponse? {
request: WebResourceRequest
): WebResourceResponse? {
val url = request.url.toString()
val glideOptions = RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.ALL) val glideOptions = RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.ALL)
if (url.lowercase(Locale.US).contains(".jpg") || url.lowercase(Locale.US)
val supportedExtensions = ImageMimeType.values().map { it.extension } .contains(".jpeg")
) {
val matchingExtension = supportedExtensions.find {
url.lowercase(Locale.US).contains(it)
}
matchingExtension?.let {
try { try {
val image = Glide.with(view) val image =
.asBitmap() Glide.with(view).asBitmap().apply(glideOptions).load(url).submit().get()
.apply(glideOptions) return WebResourceResponse(
.load(url) IMAGE_JPG,
.submit() "UTF-8",
.get() getBitmapInputStream(image, Bitmap.CompressFormat.JPEG)
)
val mimeType = ImageMimeType.findMimeTypeByExtension(it) } catch (e: ExecutionException) {
if (mimeType != null) { // Do nothing
return WebResourceResponse( }
mimeType, } else if (url.lowercase(Locale.US).contains(".png")) {
"UTF-8", try {
getBitmapInputStream(image, Bitmap.CompressFormat.WEBP) 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) {
// Do nothing
}
} 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)
)
} catch (e: ExecutionException) { } catch (e: ExecutionException) {
// Do nothing // Do nothing
} }
} }
return super.shouldInterceptRequest(view, request) return super.shouldInterceptRequest(view, url)
} }
} }
} }
@ -398,23 +382,13 @@ class ArticleFragment : Fragment(), DIAware {
binding.webcontent.settings.standardFontFamily = a.getString(0) binding.webcontent.settings.standardFontFamily = a.getString(0)
a.recycle()
binding.webcontent.visibility = View.VISIBLE binding.webcontent.visibility = View.VISIBLE
val colorOnSurface = TypedValue() val colorOnSurface = TypedValue()
requireContext().theme.resolveAttribute( requireContext().theme.resolveAttribute(R.attr.colorOnSurface, colorOnSurface, true)
com.google.android.material.R.attr.colorOnSurface,
colorOnSurface,
true
)
val colorSurface = TypedValue() val colorSurface = TypedValue()
requireContext().theme.resolveAttribute( requireContext().theme.resolveAttribute(R.attr.colorSurface, colorSurface, true)
com.google.android.material.R.attr.colorSurface,
colorSurface,
true
)
binding.webcontent.settings.useWideViewPort = true binding.webcontent.settings.useWideViewPort = true
binding.webcontent.settings.loadWithOverviewMode = true binding.webcontent.settings.loadWithOverviewMode = true
@ -483,7 +457,7 @@ class ArticleFragment : Fragment(), DIAware {
| color: ${ | color: ${
String.format( String.format(
"#%06X", "#%06X",
0xFFFFFF and ContextCompat.getColor(requireContext(), R.color.colorAccent) 0xFFFFFF and resources.getColor(R.color.colorAccent)
) )
} !important; } !important;
| } | }

View File

@ -12,7 +12,6 @@ import android.view.View
import android.view.View.GONE import android.view.View.GONE
import android.view.View.VISIBLE import android.view.View.VISIBLE
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.content.ContextCompat
import bou.amine.apps.readerforselfossv2.android.HomeActivity import bou.amine.apps.readerforselfossv2.android.HomeActivity
import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.R
import bou.amine.apps.readerforselfossv2.android.databinding.FilterFragmentBinding import bou.amine.apps.readerforselfossv2.android.databinding.FilterFragmentBinding
@ -21,7 +20,7 @@ import bou.amine.apps.readerforselfossv2.repository.Repository
import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded
import bou.amine.apps.readerforselfossv2.utils.getIcon import bou.amine.apps.readerforselfossv2.utils.getIcon
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.CustomViewTarget import com.bumptech.glide.request.target.ViewTarget
import com.bumptech.glide.request.transition.Transition import com.bumptech.glide.request.transition.Transition
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.chip.Chip import com.google.android.material.chip.Chip
@ -89,7 +88,7 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
Glide.with(context) Glide.with(context)
.load(source.getIcon(repository.baseUrl)) .load(source.getIcon(repository.baseUrl))
.into(object : CustomViewTarget<Chip, Drawable>(c) { .into(object : ViewTarget<Chip?, Drawable?>(c) {
override fun onResourceReady( override fun onResourceReady(
resource: Drawable, resource: Drawable,
transition: Transition<in Drawable?>? transition: Transition<in Drawable?>?
@ -101,13 +100,6 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
} }
} }
override fun onLoadFailed(errorDrawable: Drawable?) {
c.chipIcon = errorDrawable
}
override fun onResourceCleared(placeholder: Drawable?) {
c.chipIcon = placeholder
}
}) })
c.text = source.title.getHtmlDecoded() c.text = source.title.getHtmlDecoded()
@ -164,7 +156,7 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
Color.parseColor(tag.color) Color.parseColor(tag.color)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
e.sendSilentlyWithAcraWithName("color issue " + tag.color) e.sendSilentlyWithAcraWithName("color issue " + tag.color)
ContextCompat.getColor(context, R.color.colorPrimary) resources.getColor(R.color.colorPrimary)
} }
gd.setColor(gdColor) gd.setColor(gdColor)
gd.shape = GradientDrawable.RECTANGLE gd.shape = GradientDrawable.RECTANGLE

View File

@ -71,25 +71,23 @@ class SettingsActivity : AppCompatActivity(),
} }
override fun onPreferenceStartFragment( override fun onPreferenceStartFragment(
caller: PreferenceFragmentCompat, caller: PreferenceFragmentCompat,
pref: Preference pref: Preference
): Boolean { ): Boolean {
val fragmentClassName = pref.fragment ?: return false
// Instantiate the new Fragment // Instantiate the new Fragment
val args = pref.extras val args = pref.extras
val fragment = supportFragmentManager.fragmentFactory.instantiate( val fragment = supportFragmentManager.fragmentFactory.instantiate(
classLoader, classLoader,
fragmentClassName pref.fragment.toString()
).apply { ).apply {
arguments = args arguments = args
setTargetFragment(caller, 0)
} }
// Replace the existing Fragment with the new Fragment // Replace the existing Fragment with the new Fragment
supportFragmentManager.beginTransaction() supportFragmentManager.beginTransaction()
.replace(R.id.settings, fragment) .replace(R.id.settings, fragment)
.addToBackStack(null) .addToBackStack(null)
.commit() .commit()
title = pref.title title = pref.title
supportActionBar?.title = title supportActionBar?.title = title
return true return true

View File

@ -95,7 +95,6 @@ class LinkOnTouchListener : View.OnTouchListener {
if (link.isNotEmpty()) { if (link.isNotEmpty()) {
if (action == MotionEvent.ACTION_UP) { if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget) link[0].onClick(widget)
widget.performClick()
} }
ret = true ret = true
} }

View File

@ -19,7 +19,7 @@ kotlin.code.style=official
android.useAndroidX=true android.useAndroidX=true
#android.nonTransitiveRClass=true #android.nonTransitiveRClass=true
android.enableJetifier=true android.enableJetifier=true
android.nonTransitiveRClass=true android.nonTransitiveRClass=false
#MPP #MPP
kotlin.mpp.enableCInteropCommonization=true kotlin.mpp.enableCInteropCommonization=true
org.gradle.parallel=true org.gradle.parallel=true

View File

@ -1,19 +1,13 @@
package bou.amine.apps.readerforselfossv2.utils package bou.amine.apps.readerforselfossv2.utils
import android.net.Uri import android.net.Uri
import android.os.Build
import android.text.Html import android.text.Html
import bou.amine.apps.readerforselfossv2.model.SelfossModel import bou.amine.apps.readerforselfossv2.model.SelfossModel
import org.jsoup.Jsoup import org.jsoup.Jsoup
import java.util.* import java.util.*
actual fun String.getHtmlDecoded(): String { actual fun String.getHtmlDecoded(): String {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { return Html.fromHtml(this).toString()
Html.fromHtml(this, Html.FROM_HTML_MODE_COMPACT).toString()
} else {
@Suppress("DEPRECATION")
Html.fromHtml(this).toString()
}
} }
actual fun SelfossModel.Item.getIcon(baseUrl: String): String { actual fun SelfossModel.Item.getIcon(baseUrl: String): String {
@ -25,10 +19,19 @@ actual fun SelfossModel.Item.getThumbnail(baseUrl: String): String {
} }
actual fun SelfossModel.Item.getImages(): ArrayList<String> { actual fun SelfossModel.Item.getImages(): ArrayList<String> {
val doc = Jsoup.parse(content) val allImages = ArrayList<String>()
val images = doc.getElementsByTag("img")
return ArrayList(images.map { it.attr("src") }) for ( image in Jsoup.parse(content).getElementsByTag("img")) {
val url = image.attr("src")
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)
}
}
return allImages
} }
actual fun SelfossModel.Source.getIcon(baseUrl: String): String { actual fun SelfossModel.Source.getIcon(baseUrl: String): String {

View File

@ -17,7 +17,7 @@ fun SOURCE.toView(): SelfossModel.SourceDetail =
this.id.toInt(), this.id.toInt(),
this.title, this.title,
null, null,
this.tags.split(","), this.tags?.split(","),
this.spout, this.spout,
this.error, this.error,
this.icon, this.icon,

View File

@ -8,20 +8,4 @@ enum class ItemType(val position: Int, val type: String) {
companion object { companion object {
fun fromInt(value: Int) = values().first { it.position == value } fun fromInt(value: Int) = values().first { it.position == value }
} }
}
enum class ImageMimeType(val extension: String, val mimeType: String) {
JPG(".jpg", "image/jpeg"),
JPEG(".jpeg", "image/jpeg"),
PNG(".png", "image/png"),
WEBP(".webp", "image/webp"),
GIF(".gif", "image/gif"),
SVG(".svg", "image/svg+xml"),
BMP(".bmp", "image/bmp"),
TIFF(".tiff", "image/tiff"),
TIF(".tif", "image/tiff");
companion object {
fun findMimeTypeByExtension(ext: String) = values().find { it.extension == ext }?.mimeType
}
} }