mirror of https://github.com/Corewala/Buran
Added inline image rendering option
This commit is contained in:
parent
20623fc4aa
commit
85af5ff3a8
|
@ -94,6 +94,21 @@ class GemActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val inlineImage: (link: URI, adapterPosition: Int) -> Unit = { uri, position: Int ->
|
||||||
|
|
||||||
|
omniTerm.imageAddress(uri.toString())
|
||||||
|
omniTerm.uri.let{
|
||||||
|
model.requestInlineImage(URI.create(it.toString())){ imageUri ->
|
||||||
|
imageUri?.let{
|
||||||
|
runOnUiThread {
|
||||||
|
loadImage(position, imageUri)
|
||||||
|
loadingView(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadImage(position: Int, uri: Uri) {
|
private fun loadImage(position: Int, uri: Uri) {
|
||||||
adapter.loadImage(position, uri)
|
adapter.loadImage(position, uri)
|
||||||
}
|
}
|
||||||
|
@ -114,7 +129,7 @@ class GemActivity : AppCompatActivity() {
|
||||||
|
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
|
|
||||||
adapter = AbstractGemtextAdapter.getAdapter(onLink)
|
adapter = AbstractGemtextAdapter.getAdapter(onLink, inlineImage)
|
||||||
|
|
||||||
binding.gemtextRecycler.adapter = adapter
|
binding.gemtextRecycler.adapter = adapter
|
||||||
|
|
||||||
|
@ -274,6 +289,11 @@ class GemActivity : AppCompatActivity() {
|
||||||
)
|
)
|
||||||
adapter.inlineIcons(showInlineIcons)
|
adapter.inlineIcons(showInlineIcons)
|
||||||
|
|
||||||
|
val showInlineImages = prefs.getBoolean(
|
||||||
|
"show_inline_images",
|
||||||
|
true
|
||||||
|
)
|
||||||
|
adapter.inlineImages(showInlineImages)
|
||||||
|
|
||||||
model.invalidateDatasource()
|
model.invalidateDatasource()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,22 +5,28 @@ import androidx.recyclerview.widget.RecyclerView
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
|
|
||||||
abstract class AbstractGemtextAdapter(
|
abstract class AbstractGemtextAdapter(
|
||||||
val onLink: (link: URI, longTap: Boolean, adapterPosition: Int) -> Unit
|
val onLink: (link: URI, longTap: Boolean, adapterPosition: Int) -> Unit,
|
||||||
|
val inlineImage: (link: URI, adapterPosition: Int) -> Unit
|
||||||
): RecyclerView.Adapter<GmiViewHolder>() {
|
): RecyclerView.Adapter<GmiViewHolder>() {
|
||||||
|
|
||||||
var showInlineIcons: Boolean = false
|
var showInlineIcons: Boolean = false
|
||||||
var hideCodeBlocks: Boolean = false
|
var hideCodeBlocks: Boolean = false
|
||||||
|
var showInlineImages: Boolean = false
|
||||||
|
|
||||||
abstract fun render(lines: List<String>)
|
abstract fun render(lines: List<String>)
|
||||||
abstract fun loadImage(position: Int, cacheUri: Uri)
|
abstract fun loadImage(position: Int, cacheUri: Uri)
|
||||||
abstract fun inlineIcons(visible: Boolean)
|
abstract fun inlineIcons(visible: Boolean)
|
||||||
|
abstract fun inlineImages(visible: Boolean)
|
||||||
abstract fun hideCodeBlocks(hideCodeBlocks: Boolean)
|
abstract fun hideCodeBlocks(hideCodeBlocks: Boolean)
|
||||||
|
|
||||||
abstract fun inferTitle(): String?
|
abstract fun inferTitle(): String?
|
||||||
|
|
||||||
companion object{
|
companion object{
|
||||||
fun getAdapter(onLink: (link: URI, longTap: Boolean, adapterPosition: Int) -> Unit): AbstractGemtextAdapter {
|
fun getAdapter(
|
||||||
return GemtextAdapter(onLink)
|
onLink: (link: URI, longTap: Boolean, adapterPosition: Int) -> Unit,
|
||||||
|
inlineImage: (link: URI, adapterPosition: Int) -> Unit
|
||||||
|
): AbstractGemtextAdapter {
|
||||||
|
return GemtextAdapter(onLink, inlineImage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,8 +16,9 @@ import corewala.visible
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
|
|
||||||
class GemtextAdapter(
|
class GemtextAdapter(
|
||||||
onLink: (link: URI, longTap: Boolean, adapterPosition: Int) -> Unit)
|
onLink: (link: URI, longTap: Boolean, adapterPosition: Int) -> Unit,
|
||||||
: AbstractGemtextAdapter(onLink) {
|
inlineImage: (link: URI, adapterPosition: Int) -> Unit
|
||||||
|
): AbstractGemtextAdapter(onLink, inlineImage) {
|
||||||
|
|
||||||
private var lines = mutableListOf<String>()
|
private var lines = mutableListOf<String>()
|
||||||
private var inlineImages = HashMap<Int, Uri>()
|
private var inlineImages = HashMap<Int, Uri>()
|
||||||
|
@ -163,6 +164,7 @@ class GemtextAdapter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is GmiViewHolder.ImageLink -> {
|
is GmiViewHolder.ImageLink -> {
|
||||||
|
|
||||||
val linkParts = line.substring(2).trim().split("\\s+".toRegex(), 2)
|
val linkParts = line.substring(2).trim().split("\\s+".toRegex(), 2)
|
||||||
var linkName = linkParts[0]
|
var linkName = linkParts[0]
|
||||||
|
|
||||||
|
@ -189,7 +191,15 @@ class GemtextAdapter(
|
||||||
holder.itemView.gemtext_inline_image.visible(true)
|
holder.itemView.gemtext_inline_image.visible(true)
|
||||||
holder.itemView.gemtext_inline_image.setImageURI(inlineImages[position])
|
holder.itemView.gemtext_inline_image.setImageURI(inlineImages[position])
|
||||||
}
|
}
|
||||||
else -> holder.itemView.gemtext_inline_image.visible(false)
|
else -> {
|
||||||
|
holder.itemView.gemtext_inline_image.visible(false)
|
||||||
|
if (showInlineImages){
|
||||||
|
val uri = getUri(lines[holder.adapterPosition])
|
||||||
|
println("Inline image rendered: $uri")
|
||||||
|
inlineImage(uri, holder.adapterPosition)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
when {
|
when {
|
||||||
|
@ -248,6 +258,11 @@ class GemtextAdapter(
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun inlineImages(visible: Boolean){
|
||||||
|
this.showInlineImages = visible
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
override fun hideCodeBlocks(hideCodeBlocks: Boolean) {
|
override fun hideCodeBlocks(hideCodeBlocks: Boolean) {
|
||||||
this.hideCodeBlocks = hideCodeBlocks
|
this.hideCodeBlocks = hideCodeBlocks
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
|
|
|
@ -98,6 +98,12 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
|
||||||
useCustomTabsPreference.title = getString(R.string.web_content_switch_label)
|
useCustomTabsPreference.title = getString(R.string.web_content_switch_label)
|
||||||
webCategory.addPreference(useCustomTabsPreference)
|
webCategory.addPreference(useCustomTabsPreference)
|
||||||
|
|
||||||
|
val showInlineImages = SwitchPreferenceCompat(context)
|
||||||
|
showInlineImages.setDefaultValue(true)
|
||||||
|
showInlineImages.key = "show_inline_images"
|
||||||
|
showInlineImages.title = getString(R.string.show_inline_images)
|
||||||
|
webCategory.addPreference(showInlineImages)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildAppearanceSection(context: Context?, appCategory: PreferenceCategory) {
|
private fun buildAppearanceSection(context: Context?, appCategory: PreferenceCategory) {
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
<string name="web_content">Contenu Web</string>
|
<string name="web_content">Contenu Web</string>
|
||||||
<string name="web_content_label">Ouvrir les sites web en interne en utilisant des \'Onglets Personnalisés\', plutôt que d\'utiliser le navigateur par défaut. Cela pourrait vous aider à rester dans le Geminispace plutôt que d\'être distrait·e par le vaste web. Cela requiert un navigateur par défaut compatible.</string>
|
<string name="web_content_label">Ouvrir les sites web en interne en utilisant des \'Onglets Personnalisés\', plutôt que d\'utiliser le navigateur par défaut. Cela pourrait vous aider à rester dans le Geminispace plutôt que d\'être distrait·e par le vaste web. Cela requiert un navigateur par défaut compatible.</string>
|
||||||
<string name="web_content_switch_label">Ouvrir en interne</string>
|
<string name="web_content_switch_label">Ouvrir en interne</string>
|
||||||
|
<string name="show_inline_images">Images en ligne</string>
|
||||||
<string name="pkcs_notice">Seuls les magasins de clés client PKCS12 sont actuellement supportés</string>
|
<string name="pkcs_notice">Seuls les magasins de clés client PKCS12 sont actuellement supportés</string>
|
||||||
<string name="client_certificate">Certificat Client</string>
|
<string name="client_certificate">Certificat Client</string>
|
||||||
<string name="tap_to_select_client_certificate">Cliquez pour sélectionner un certificat client</string>
|
<string name="tap_to_select_client_certificate">Cliquez pour sélectionner un certificat client</string>
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
<string name="web_content">Web Content</string>
|
<string name="web_content">Web Content</string>
|
||||||
<string name="web_content_label">Open websites internally using \'Custom Tabs\', instead of using the default browser. This might help you stay in Geminispace instead of being distracted by the wider web. Requires compatible default browser.</string>
|
<string name="web_content_label">Open websites internally using \'Custom Tabs\', instead of using the default browser. This might help you stay in Geminispace instead of being distracted by the wider web. Requires compatible default browser.</string>
|
||||||
<string name="web_content_switch_label">Open internally</string>
|
<string name="web_content_switch_label">Open internally</string>
|
||||||
|
<string name="show_inline_images">Inline images</string>
|
||||||
<string name="pkcs_notice">Only PKCS12 client keystores are currently supported</string>
|
<string name="pkcs_notice">Only PKCS12 client keystores are currently supported</string>
|
||||||
<string name="client_certificate">Client Certificate</string>
|
<string name="client_certificate">Client Certificate</string>
|
||||||
<string name="tap_to_select_client_certificate">Tap to select client certificate</string>
|
<string name="tap_to_select_client_certificate">Tap to select client certificate</string>
|
||||||
|
|
Loading…
Reference in New Issue