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.Bundle
|
||||
import android.os.Process
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.webkit.WebView
|
||||
import android.widget.FrameLayout
|
||||
|
|
@ -125,7 +126,7 @@ class BaseApplication : Application(), IApp {
|
|||
iconView.setImageResource(data.icon!!.res)
|
||||
val iconLayoutParams = iconView.layoutParams as FrameLayout.LayoutParams
|
||||
run {
|
||||
iconLayoutParams.height = 24f.pxToDp()
|
||||
iconLayoutParams.height = 24f.dpToPx()
|
||||
iconLayoutParams.width = iconLayoutParams.height
|
||||
}
|
||||
iconView.layoutParams = iconLayoutParams
|
||||
|
|
@ -135,7 +136,7 @@ class BaseApplication : Application(), IApp {
|
|||
ImageUtil.load(iconView, ImageUtil.LOAD_TYPE_AVATAR, data.icon!!.url)
|
||||
val avatarLayoutParams = iconView.layoutParams as FrameLayout.LayoutParams
|
||||
run {
|
||||
avatarLayoutParams.height = 40f.pxToDp()
|
||||
avatarLayoutParams.height = 24f.dpToPx()
|
||||
avatarLayoutParams.width = avatarLayoutParams.height
|
||||
}
|
||||
iconView.layoutParams = avatarLayoutParams
|
||||
|
|
@ -145,7 +146,15 @@ class BaseApplication : Application(), IApp {
|
|||
}
|
||||
|
||||
override fun onActivityResumed(activity: Activity) {
|
||||
activity.window.decorView.post { checkClipBoard(activity) }
|
||||
}
|
||||
|
||||
private fun checkClipBoard(activity: Activity) {
|
||||
val clipBoardText = clipBoard
|
||||
Log.i(
|
||||
TAG,
|
||||
"checkClipBoard: ${activity.clipBoardManager.hasPrimaryClip()} $clipBoardText $clipBoardHash ${getClipBoardHash()}"
|
||||
)
|
||||
if (clipBoardHash != getClipBoardHash() && clipBoardText != null) {
|
||||
@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&%_./-~-]*)?"
|
||||
|
|
@ -164,11 +173,13 @@ class BaseApplication : Application(), IApp {
|
|||
.setSubtitle(activity.getString(R.string.text_loading))
|
||||
.setUrl(url))
|
||||
} else if (isThreadUrl(uri)) {
|
||||
updatePreviewView(activity, previewView, PreviewInfo()
|
||||
updatePreviewView(
|
||||
activity, previewView, PreviewInfo()
|
||||
.setIconRes(R.drawable.ic_round_mode_comment)
|
||||
.setTitle(url)
|
||||
.setSubtitle(activity.getString(R.string.text_loading))
|
||||
.setUrl(url))
|
||||
.setUrl(url)
|
||||
)
|
||||
}
|
||||
getPreviewInfo(activity, url, object : CommonCallback<PreviewInfo> {
|
||||
override fun onSuccess(data: PreviewInfo) {
|
||||
|
|
@ -176,23 +187,27 @@ class BaseApplication : Application(), IApp {
|
|||
}
|
||||
|
||||
override fun onFailure(code: Int, error: String) {
|
||||
updatePreviewView(activity, previewView, PreviewInfo()
|
||||
updatePreviewView(
|
||||
activity, previewView, PreviewInfo()
|
||||
.setUrl(url)
|
||||
.setTitle(url)
|
||||
.setSubtitle(activity.getString(R.string.subtitle_link))
|
||||
.setIconRes(R.drawable.ic_link))
|
||||
.setIconRes(R.drawable.ic_link)
|
||||
)
|
||||
}
|
||||
})
|
||||
DialogUtil.build(activity)
|
||||
.setTitle(R.string.title_dialog_clip_board_tieba_url)
|
||||
.setPositiveButton(R.string.button_yes) { _, _ ->
|
||||
startActivity(Intent("com.huanchengfly.tieba.post.ACTION_JUMP", uri)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.addCategory(Intent.CATEGORY_DEFAULT))
|
||||
}
|
||||
.setView(previewView)
|
||||
.setNegativeButton(R.string.button_no, null)
|
||||
.show()
|
||||
.setTitle(R.string.title_dialog_clip_board_tieba_url)
|
||||
.setPositiveButton(R.string.button_yes) { _, _ ->
|
||||
startActivity(
|
||||
Intent("com.huanchengfly.tieba.post.ACTION_JUMP", uri)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.addCategory(Intent.CATEGORY_DEFAULT)
|
||||
)
|
||||
}
|
||||
.setView(previewView)
|
||||
.setNegativeButton(R.string.button_no, null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import android.content.ClipboardManager
|
|||
import android.content.Context
|
||||
import android.os.Build
|
||||
|
||||
private val Context.clipBoardManager
|
||||
val Context.clipBoardManager
|
||||
get() = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
|
||||
fun Context.getClipBoardHtmlText(): String? {
|
||||
|
|
@ -16,7 +16,7 @@ fun Context.getClipBoardHtmlText(): String? {
|
|||
fun Context.getClipBoardText(): String? {
|
||||
val data = clipBoardManager.primaryClip ?: return null
|
||||
val item = data.getItemAt(0)
|
||||
return item?.coerceToText(this)?.toString()
|
||||
return item?.text?.toString()
|
||||
}
|
||||
|
||||
fun Context.getClipBoardTimestamp(): Long {
|
||||
|
|
|
|||
|
|
@ -1,67 +1,58 @@
|
|||
<?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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:visibility="gone"
|
||||
app:shadow_layout_blur="8dp"
|
||||
app:shadow_layout_color="?attr/shadow_color"
|
||||
app:shadow_layout_offsetY="4dp"
|
||||
app:shadow_layout_radius="8dp">
|
||||
app:cardCornerRadius="8dp"
|
||||
app:cardElevation="0dp"
|
||||
app:contentPaddingBottom="16dp"
|
||||
app:contentPaddingLeft="32dp"
|
||||
app:contentPaddingRight="32dp"
|
||||
app:contentPaddingTop="16dp"
|
||||
app:strokeWidth="0dp">
|
||||
|
||||
<com.huanchengfly.tieba.post.widgets.theme.TintMaterialCardView
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:cardElevation="0dp"
|
||||
app:contentPadding="16dp"
|
||||
app:strokeWidth="0dp">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<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_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toEndOf="@id/icon_holder"
|
||||
android:orientation="vertical">
|
||||
|
||||
<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
|
||||
<com.huanchengfly.tieba.post.widgets.theme.TintTextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toEndOf="@id/icon_holder"
|
||||
android:orientation="vertical">
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
app:tint="@color/default_color_text" />
|
||||
|
||||
<com.huanchengfly.tieba.post.widgets.theme.TintTextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
app:tint="@color/default_color_text" />
|
||||
|
||||
<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>
|
||||
<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>
|
||||
Loading…
Reference in New Issue