Tweak About view
This commit is contained in:
@@ -36,18 +36,6 @@ class AboutSettingsFragment : BasePreferenceFragment(R.string.about) {
|
||||
openLink(getString(R.string.url_weblate), preference.title)
|
||||
true
|
||||
}
|
||||
AppSettings.KEY_FEEDBACK_4PDA -> {
|
||||
openLink(getString(R.string.url_forpda), preference.title)
|
||||
true
|
||||
}
|
||||
AppSettings.KEY_FEEDBACK_DISCORD -> {
|
||||
openLink(getString(R.string.url_discord), preference.title)
|
||||
true
|
||||
}
|
||||
AppSettings.KEY_FEEDBACK_GITHUB -> {
|
||||
openLink(getString(R.string.url_github_issues), preference.title)
|
||||
true
|
||||
}
|
||||
else -> super.onPreferenceTreeClick(preference)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.koitharu.kotatsu.settings.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.AttributeSet
|
||||
import androidx.core.content.ContextCompat.startActivity
|
||||
import androidx.core.net.toUri
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.utils.ext.setTooltip
|
||||
|
||||
class AboutLinksPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
Preference(context, attrs) {
|
||||
|
||||
init {
|
||||
layoutResource = R.layout.preference_about_links
|
||||
isSelectable = false
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
|
||||
holder.findViewById(R.id.btn_4pda).apply {
|
||||
setTooltip(contentDescription.toString())
|
||||
setOnClickListener { openLink(resources.getString(R.string.url_forpda), contentDescription.toString()) }
|
||||
}
|
||||
holder.findViewById(R.id.btn_discord).apply {
|
||||
setTooltip(contentDescription.toString())
|
||||
setOnClickListener { openLink(resources.getString(R.string.url_discord), contentDescription.toString()) }
|
||||
}
|
||||
holder.findViewById(R.id.btn_twitter).apply {
|
||||
setTooltip(contentDescription.toString())
|
||||
setOnClickListener { openLink(resources.getString(R.string.url_twitter), contentDescription.toString()) }
|
||||
}
|
||||
holder.findViewById(R.id.btn_reddit).apply {
|
||||
setTooltip(contentDescription.toString())
|
||||
setOnClickListener { openLink(resources.getString(R.string.url_reddit), contentDescription.toString()) }
|
||||
}
|
||||
holder.findViewById(R.id.btn_github).apply {
|
||||
setTooltip(contentDescription.toString())
|
||||
setOnClickListener {
|
||||
openLink(
|
||||
resources.getString(R.string.url_github_issues),
|
||||
contentDescription.toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun openLink(url: String, title: CharSequence?) {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.data = url.toUri()
|
||||
context.startActivity(
|
||||
if (title != null) {
|
||||
Intent.createChooser(intent, title)
|
||||
} else {
|
||||
intent
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import android.graphics.Rect
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.widget.TooltipCompat
|
||||
import androidx.core.view.children
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@@ -154,4 +156,12 @@ fun <T : View> ViewGroup.findViewsByType(clazz: Class<T>): Sequence<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun View.setTooltip(@StringRes stringRes: Int) {
|
||||
setTooltip(context.getString(stringRes))
|
||||
}
|
||||
|
||||
inline fun View.setTooltip(text: String) {
|
||||
TooltipCompat.setTooltipText(this, text)
|
||||
}
|
||||
Reference in New Issue
Block a user