mirror of
https://git.sr.ht/~oppen/ariane
synced 2024-12-27 18:31:10 +00:00
feedback on link click, and better perforance by only caching tabs on destroy
This commit is contained in:
parent
a6b3ee45ac
commit
c1a08e1e12
4 changed files with 28 additions and 50 deletions
|
@ -38,35 +38,13 @@ class GemtextAdapter(val onLink: (link: URI) -> Unit): RecyclerView.Adapter<Gemt
|
|||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return when(viewType){
|
||||
typeText -> ViewHolder.Text(
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.gemtext_text, parent, false)
|
||||
)
|
||||
typeH1 -> ViewHolder.H1(
|
||||
LayoutInflater.from(
|
||||
parent.context
|
||||
).inflate(R.layout.gemtext_h1, parent, false)
|
||||
)
|
||||
typeH2 -> ViewHolder.H2(
|
||||
LayoutInflater.from(
|
||||
parent.context
|
||||
).inflate(R.layout.gemtext_h2, parent, false)
|
||||
)
|
||||
typeH3 -> ViewHolder.H3(
|
||||
LayoutInflater.from(
|
||||
parent.context
|
||||
).inflate(R.layout.gemtext_h3, parent, false)
|
||||
)
|
||||
typeListItem -> ViewHolder.ListItem(
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.gemtext_text, parent, false)
|
||||
)
|
||||
typeLink -> ViewHolder.Link(
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.gemtext_link, parent, false)
|
||||
)
|
||||
else -> ViewHolder.Text(
|
||||
LayoutInflater.from(
|
||||
parent.context
|
||||
).inflate(R.layout.gemtext_text, parent, false)
|
||||
)
|
||||
typeText -> ViewHolder.Text(LayoutInflater.from(parent.context).inflate(R.layout.gemtext_text, parent, false))
|
||||
typeH1 -> ViewHolder.H1(LayoutInflater.from(parent.context).inflate(R.layout.gemtext_h1, parent, false))
|
||||
typeH2 -> ViewHolder.H2(LayoutInflater.from(parent.context).inflate(R.layout.gemtext_h2, parent, false))
|
||||
typeH3 -> ViewHolder.H3(LayoutInflater.from(parent.context).inflate(R.layout.gemtext_h3, parent, false))
|
||||
typeListItem -> ViewHolder.ListItem(LayoutInflater.from(parent.context).inflate(R.layout.gemtext_text, parent, false))
|
||||
typeLink -> ViewHolder.Link(LayoutInflater.from(parent.context).inflate(R.layout.gemtext_link, parent, false))
|
||||
else -> ViewHolder.Text(LayoutInflater.from(parent.context).inflate(R.layout.gemtext_text, parent, false))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,16 +72,15 @@ class GemtextAdapter(val onLink: (link: URI) -> Unit): RecyclerView.Adapter<Gemt
|
|||
is ViewHolder.H3 -> holder.itemView.gemtext_text_textview.text = line.substring(4).trim()
|
||||
is ViewHolder.ListItem -> holder.itemView.gemtext_text_textview.text = "• ${line.substring(1)}".trim()
|
||||
is ViewHolder.Link -> {
|
||||
println("Tva: link: $line")
|
||||
val linkParts = line.substring(2).trim().split("\\s+".toRegex(), 2)
|
||||
var linkName = linkParts[0]
|
||||
if(linkParts.size > 1) {
|
||||
linkName = linkParts[1]
|
||||
}
|
||||
val displayText = linkName
|
||||
holder.itemView.gemtext_text_textview.text = displayText
|
||||
holder.itemView.gemtext_text_textview.paint.isUnderlineText = true
|
||||
holder.itemView.gemtext_link.setOnClickListener {
|
||||
holder.itemView.gemtext_text_link.text = displayText
|
||||
holder.itemView.gemtext_text_link.paint.isUnderlineText = true
|
||||
holder.itemView.gemtext_text_link.setOnClickListener {
|
||||
val uri = getUri(lines[holder.adapterPosition])
|
||||
println("User click link: $uri")
|
||||
onLink(uri)
|
||||
|
|
|
@ -79,4 +79,9 @@ class TvaActivity : AppCompatActivity() {
|
|||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
model.persistTabState()
|
||||
}
|
||||
}
|
|
@ -53,7 +53,6 @@ class TvaViewModel: ViewModel() {
|
|||
private fun renderGemini(state: TvaState.GeminiResponse) {
|
||||
if(tabs[activeTab].history.isEmpty() || tabs[activeTab].history.last() != state.uri){
|
||||
tabs[activeTab].add(state.uri)
|
||||
cache.update(tabs, activeTab)
|
||||
}
|
||||
|
||||
onState(state)
|
||||
|
@ -78,7 +77,9 @@ class TvaViewModel: ViewModel() {
|
|||
}
|
||||
|
||||
tabs[activeTab].history.removeLast()
|
||||
cache.update(tabs, activeTab)
|
||||
request(previous)
|
||||
}
|
||||
|
||||
|
||||
fun persistTabState() = cache.update(tabs, activeTab)
|
||||
}
|
|
@ -1,18 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/gemtext_link"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/gemtext_text_link"
|
||||
android:textSize="@dimen/default_text_size"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/gemtext_text_textview"
|
||||
android:textSize="@dimen/default_text_size"
|
||||
android:paddingLeft="@dimen/default_margin"
|
||||
android:paddingRight="@dimen/default_margin"
|
||||
android:textColor="#ffdede"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</RelativeLayout>
|
||||
android:focusable="true"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:paddingLeft="@dimen/default_margin"
|
||||
android:paddingRight="@dimen/default_margin"
|
||||
android:textColor="#ffdede"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
Loading…
Reference in a new issue