Compare commits
2 Commits
806e56e20b
...
fb9ceecabd
Author | SHA1 | Date | |
---|---|---|---|
fb9ceecabd | |||
61b9fd30e0 |
@ -52,6 +52,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.acra.ktx.sendSilentlyWithAcra
|
||||
import org.kodein.di.DI
|
||||
import org.kodein.di.DIAware
|
||||
import org.kodein.di.android.x.closestDI
|
||||
@ -103,7 +104,12 @@ class ArticleFragment : Fragment(), DIAware {
|
||||
try {
|
||||
binding = FragmentArticleBinding.inflate(inflater, container, false)
|
||||
|
||||
try {
|
||||
url = item.getLinkDecoded()
|
||||
} catch (e: Exception) {
|
||||
e.sendSilentlyWithAcra()
|
||||
}
|
||||
|
||||
contentText = item.content
|
||||
contentTitle = item.title.getHtmlDecoded()
|
||||
contentImage = item.getThumbnail(repository.baseUrl)
|
||||
@ -157,7 +163,7 @@ class ArticleFragment : Fragment(), DIAware {
|
||||
)
|
||||
} catch (e: InflateException) {
|
||||
e.sendSilentlyWithAcraWithName("webview not available")
|
||||
if (context != null) {
|
||||
try {
|
||||
AlertDialog.Builder(requireContext())
|
||||
.setMessage(requireContext().getString(R.string.webview_dialog_issue_message))
|
||||
.setTitle(requireContext().getString(R.string.webview_dialog_issue_title))
|
||||
@ -169,6 +175,8 @@ class ArticleFragment : Fragment(), DIAware {
|
||||
}
|
||||
.create()
|
||||
.show()
|
||||
} catch (e: IllegalStateException) {
|
||||
e.sendSilentlyWithAcraWithName("Context required is null")
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,7 +226,7 @@ class ArticleFragment : Fragment(), DIAware {
|
||||
R.id.share_action -> requireActivity().shareLink(url, contentTitle)
|
||||
R.id.open_action -> requireActivity().openItemUrlInBrowserAsNewTask(this@ArticleFragment.item)
|
||||
R.id.unread_action ->
|
||||
if (context != null) {
|
||||
try {
|
||||
if (this@ArticleFragment.item.unread) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
repository.markAsRead(this@ArticleFragment.item)
|
||||
@ -240,6 +248,8 @@ class ArticleFragment : Fragment(), DIAware {
|
||||
Toast.LENGTH_LONG,
|
||||
).show()
|
||||
}
|
||||
} catch (e: IllegalStateException) {
|
||||
e.sendSilentlyWithAcraWithName("Context required is null")
|
||||
}
|
||||
|
||||
else -> Unit
|
||||
@ -389,7 +399,7 @@ class ArticleFragment : Fragment(), DIAware {
|
||||
}
|
||||
|
||||
private fun htmlToWebview() {
|
||||
if (context != null) {
|
||||
try {
|
||||
val attrs: IntArray = intArrayOf(android.R.attr.fontFamily)
|
||||
val a: TypedArray = requireContext().obtainStyledAttributes(resId, attrs)
|
||||
|
||||
@ -534,6 +544,8 @@ class ArticleFragment : Fragment(), DIAware {
|
||||
"utf-8",
|
||||
null,
|
||||
)
|
||||
} catch (e: IllegalStateException) {
|
||||
e.sendSilentlyWithAcraWithName("Context required is null")
|
||||
}
|
||||
}
|
||||
|
||||
@ -549,10 +561,10 @@ class ArticleFragment : Fragment(), DIAware {
|
||||
|
||||
private fun openInBrowserAfterFailing() {
|
||||
binding.progressBar.visibility = View.GONE
|
||||
if (context != null) {
|
||||
try {
|
||||
requireContext().openItemUrlInBrowserAsNewTask(this@ArticleFragment.item)
|
||||
} else {
|
||||
Exception("openInBrowserAfterFailing context is null").sendSilentlyWithAcraWithName("openInBrowserAfterFailing > $context")
|
||||
} catch (e: IllegalStateException) {
|
||||
e.sendSilentlyWithAcraWithName("Context required is null")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package bou.amine.apps.readerforselfossv2.model
|
||||
|
||||
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
||||
import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded
|
||||
import bou.amine.apps.readerforselfossv2.utils.isEmptyOrNullOrNullString
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||
@ -10,7 +11,12 @@ import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.encoding.encodeCollection
|
||||
import kotlinx.serialization.json.*
|
||||
import kotlinx.serialization.json.JsonArray
|
||||
import kotlinx.serialization.json.JsonDecoder
|
||||
import kotlinx.serialization.json.boolean
|
||||
import kotlinx.serialization.json.booleanOrNull
|
||||
import kotlinx.serialization.json.int
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
class SelfossModel {
|
||||
@Serializable
|
||||
@ -134,6 +140,10 @@ class SelfossModel {
|
||||
stringUrl = "http:$stringUrl"
|
||||
}
|
||||
|
||||
if (stringUrl.isEmptyOrNullOrNullString()) {
|
||||
throw Exception("Link ${link} was translated to ${stringUrl}, but was empty. Handle this.")
|
||||
}
|
||||
|
||||
return stringUrl
|
||||
}
|
||||
|
||||
@ -176,7 +186,10 @@ class SelfossModel {
|
||||
encoder: Encoder,
|
||||
value: List<String>,
|
||||
) {
|
||||
encoder.encodeCollection(PrimitiveSerialDescriptor("tags", PrimitiveKind.STRING), value.size) { this.toString() }
|
||||
encoder.encodeCollection(
|
||||
PrimitiveSerialDescriptor("tags", PrimitiveKind.STRING),
|
||||
value.size
|
||||
) { this.toString() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,7 +204,10 @@ class SelfossModel {
|
||||
}
|
||||
|
||||
override val descriptor: SerialDescriptor
|
||||
get() = PrimitiveSerialDescriptor("BooleanOrIntForSomeSelfossVersions", PrimitiveKind.BOOLEAN)
|
||||
get() = PrimitiveSerialDescriptor(
|
||||
"BooleanOrIntForSomeSelfossVersions",
|
||||
PrimitiveKind.BOOLEAN
|
||||
)
|
||||
|
||||
override fun serialize(
|
||||
encoder: Encoder,
|
||||
|
Loading…
x
Reference in New Issue
Block a user