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