pref: 优化剪贴板链接检测
This commit is contained in:
parent
37aab60ddc
commit
14285ab63e
|
|
@ -15,6 +15,7 @@ import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Process
|
import android.os.Process
|
||||||
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
|
|
@ -125,7 +126,7 @@ class BaseApplication : Application(), IApp {
|
||||||
iconView.setImageResource(data.icon!!.res)
|
iconView.setImageResource(data.icon!!.res)
|
||||||
val iconLayoutParams = iconView.layoutParams as FrameLayout.LayoutParams
|
val iconLayoutParams = iconView.layoutParams as FrameLayout.LayoutParams
|
||||||
run {
|
run {
|
||||||
iconLayoutParams.height = 24f.pxToDp()
|
iconLayoutParams.height = 24f.dpToPx()
|
||||||
iconLayoutParams.width = iconLayoutParams.height
|
iconLayoutParams.width = iconLayoutParams.height
|
||||||
}
|
}
|
||||||
iconView.layoutParams = iconLayoutParams
|
iconView.layoutParams = iconLayoutParams
|
||||||
|
|
@ -135,7 +136,7 @@ class BaseApplication : Application(), IApp {
|
||||||
ImageUtil.load(iconView, ImageUtil.LOAD_TYPE_AVATAR, data.icon!!.url)
|
ImageUtil.load(iconView, ImageUtil.LOAD_TYPE_AVATAR, data.icon!!.url)
|
||||||
val avatarLayoutParams = iconView.layoutParams as FrameLayout.LayoutParams
|
val avatarLayoutParams = iconView.layoutParams as FrameLayout.LayoutParams
|
||||||
run {
|
run {
|
||||||
avatarLayoutParams.height = 40f.pxToDp()
|
avatarLayoutParams.height = 24f.dpToPx()
|
||||||
avatarLayoutParams.width = avatarLayoutParams.height
|
avatarLayoutParams.width = avatarLayoutParams.height
|
||||||
}
|
}
|
||||||
iconView.layoutParams = avatarLayoutParams
|
iconView.layoutParams = avatarLayoutParams
|
||||||
|
|
@ -145,7 +146,15 @@ class BaseApplication : Application(), IApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResumed(activity: Activity) {
|
override fun onActivityResumed(activity: Activity) {
|
||||||
|
activity.window.decorView.post { checkClipBoard(activity) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun checkClipBoard(activity: Activity) {
|
||||||
val clipBoardText = clipBoard
|
val clipBoardText = clipBoard
|
||||||
|
Log.i(
|
||||||
|
TAG,
|
||||||
|
"checkClipBoard: ${activity.clipBoardManager.hasPrimaryClip()} $clipBoardText $clipBoardHash ${getClipBoardHash()}"
|
||||||
|
)
|
||||||
if (clipBoardHash != getClipBoardHash() && clipBoardText != null) {
|
if (clipBoardHash != getClipBoardHash() && clipBoardText != null) {
|
||||||
@RegExp val regex =
|
@RegExp val regex =
|
||||||
"((http|https)://)(([a-zA-Z0-9._-]+\\.[a-zA-Z]{2,6})|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9&%_./-~-]*)?"
|
"((http|https)://)(([a-zA-Z0-9._-]+\\.[a-zA-Z]{2,6})|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9&%_./-~-]*)?"
|
||||||
|
|
@ -164,11 +173,13 @@ class BaseApplication : Application(), IApp {
|
||||||
.setSubtitle(activity.getString(R.string.text_loading))
|
.setSubtitle(activity.getString(R.string.text_loading))
|
||||||
.setUrl(url))
|
.setUrl(url))
|
||||||
} else if (isThreadUrl(uri)) {
|
} else if (isThreadUrl(uri)) {
|
||||||
updatePreviewView(activity, previewView, PreviewInfo()
|
updatePreviewView(
|
||||||
|
activity, previewView, PreviewInfo()
|
||||||
.setIconRes(R.drawable.ic_round_mode_comment)
|
.setIconRes(R.drawable.ic_round_mode_comment)
|
||||||
.setTitle(url)
|
.setTitle(url)
|
||||||
.setSubtitle(activity.getString(R.string.text_loading))
|
.setSubtitle(activity.getString(R.string.text_loading))
|
||||||
.setUrl(url))
|
.setUrl(url)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
getPreviewInfo(activity, url, object : CommonCallback<PreviewInfo> {
|
getPreviewInfo(activity, url, object : CommonCallback<PreviewInfo> {
|
||||||
override fun onSuccess(data: PreviewInfo) {
|
override fun onSuccess(data: PreviewInfo) {
|
||||||
|
|
@ -176,23 +187,27 @@ class BaseApplication : Application(), IApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(code: Int, error: String) {
|
override fun onFailure(code: Int, error: String) {
|
||||||
updatePreviewView(activity, previewView, PreviewInfo()
|
updatePreviewView(
|
||||||
|
activity, previewView, PreviewInfo()
|
||||||
.setUrl(url)
|
.setUrl(url)
|
||||||
.setTitle(url)
|
.setTitle(url)
|
||||||
.setSubtitle(activity.getString(R.string.subtitle_link))
|
.setSubtitle(activity.getString(R.string.subtitle_link))
|
||||||
.setIconRes(R.drawable.ic_link))
|
.setIconRes(R.drawable.ic_link)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
DialogUtil.build(activity)
|
DialogUtil.build(activity)
|
||||||
.setTitle(R.string.title_dialog_clip_board_tieba_url)
|
.setTitle(R.string.title_dialog_clip_board_tieba_url)
|
||||||
.setPositiveButton(R.string.button_yes) { _, _ ->
|
.setPositiveButton(R.string.button_yes) { _, _ ->
|
||||||
startActivity(Intent("com.huanchengfly.tieba.post.ACTION_JUMP", uri)
|
startActivity(
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
Intent("com.huanchengfly.tieba.post.ACTION_JUMP", uri)
|
||||||
.addCategory(Intent.CATEGORY_DEFAULT))
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
}
|
.addCategory(Intent.CATEGORY_DEFAULT)
|
||||||
.setView(previewView)
|
)
|
||||||
.setNegativeButton(R.string.button_no, null)
|
}
|
||||||
.show()
|
.setView(previewView)
|
||||||
|
.setNegativeButton(R.string.button_no, null)
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import android.content.ClipboardManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
|
||||||
private val Context.clipBoardManager
|
val Context.clipBoardManager
|
||||||
get() = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
get() = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||||
|
|
||||||
fun Context.getClipBoardHtmlText(): String? {
|
fun Context.getClipBoardHtmlText(): String? {
|
||||||
|
|
@ -16,7 +16,7 @@ fun Context.getClipBoardHtmlText(): String? {
|
||||||
fun Context.getClipBoardText(): String? {
|
fun Context.getClipBoardText(): String? {
|
||||||
val data = clipBoardManager.primaryClip ?: return null
|
val data = clipBoardManager.primaryClip ?: return null
|
||||||
val item = data.getItemAt(0)
|
val item = data.getItemAt(0)
|
||||||
return item?.coerceToText(this)?.toString()
|
return item?.text?.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getClipBoardTimestamp(): Long {
|
fun Context.getClipBoardTimestamp(): Long {
|
||||||
|
|
|
||||||
|
|
@ -1,67 +1,58 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<com.huanchengfly.tieba.post.widgets.ShadowLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.huanchengfly.tieba.post.widgets.theme.TintMaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="8dp"
|
app:cardCornerRadius="8dp"
|
||||||
android:layout_marginEnd="8dp"
|
app:cardElevation="0dp"
|
||||||
android:visibility="gone"
|
app:contentPaddingBottom="16dp"
|
||||||
app:shadow_layout_blur="8dp"
|
app:contentPaddingLeft="32dp"
|
||||||
app:shadow_layout_color="?attr/shadow_color"
|
app:contentPaddingRight="32dp"
|
||||||
app:shadow_layout_offsetY="4dp"
|
app:contentPaddingTop="16dp"
|
||||||
app:shadow_layout_radius="8dp">
|
app:strokeWidth="0dp">
|
||||||
|
|
||||||
<com.huanchengfly.tieba.post.widgets.theme.TintMaterialCardView
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
app:cardCornerRadius="8dp"
|
|
||||||
app:cardElevation="0dp"
|
|
||||||
app:contentPadding="16dp"
|
|
||||||
app:strokeWidth="0dp">
|
|
||||||
|
|
||||||
<RelativeLayout
|
<FrameLayout
|
||||||
|
android:id="@+id/icon_holder"
|
||||||
|
android:layout_width="56dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:minHeight="24dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/icon"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="center_vertical|start" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_toEndOf="@id/icon_holder"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<FrameLayout
|
<com.huanchengfly.tieba.post.widgets.theme.TintTextView
|
||||||
android:id="@+id/icon_holder"
|
android:id="@+id/title"
|
||||||
android:layout_width="56dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:minHeight="24dp">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/icon"
|
|
||||||
android:layout_width="24dp"
|
|
||||||
android:layout_height="24dp"
|
|
||||||
android:layout_gravity="center_vertical|start" />
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerVertical="true"
|
android:ellipsize="end"
|
||||||
android:layout_toEndOf="@id/icon_holder"
|
android:maxLines="2"
|
||||||
android:orientation="vertical">
|
android:textSize="16sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:tint="@color/default_color_text" />
|
||||||
|
|
||||||
<com.huanchengfly.tieba.post.widgets.theme.TintTextView
|
<com.huanchengfly.tieba.post.widgets.theme.TintTextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/subtitle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:ellipsize="end"
|
android:layout_marginTop="4dp"
|
||||||
android:maxLines="2"
|
android:textSize="14sp"
|
||||||
android:textSize="16sp"
|
app:tint="@color/default_color_text_secondary" />
|
||||||
android:textStyle="bold"
|
</LinearLayout>
|
||||||
app:tint="@color/default_color_text" />
|
</RelativeLayout>
|
||||||
|
</com.huanchengfly.tieba.post.widgets.theme.TintMaterialCardView>
|
||||||
<com.huanchengfly.tieba.post.widgets.theme.TintTextView
|
|
||||||
android:id="@+id/subtitle"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="4dp"
|
|
||||||
android:textSize="14sp"
|
|
||||||
app:tint="@color/default_color_text_secondary" />
|
|
||||||
</LinearLayout>
|
|
||||||
</RelativeLayout>
|
|
||||||
</com.huanchengfly.tieba.post.widgets.theme.TintMaterialCardView>
|
|
||||||
</com.huanchengfly.tieba.post.widgets.ShadowLayout>
|
|
||||||
Loading…
Reference in New Issue