From ba8a6247f56ecf641a81dd79e4a40a8fcba9e498 Mon Sep 17 00:00:00 2001
From: Kr328 <39107975+Kr328@users.noreply.github.com>
Date: Thu, 20 Feb 2020 01:21:59 +0800
Subject: [PATCH] add tips for profiles
---
.../github/kr328/clash/ProfileEditActivity.kt | 5 ++++
.../com/github/kr328/clash/utils/DpUtils.kt | 13 ---------
app/src/main/res/drawable/ic_info.xml | 9 +++++++
app/src/main/res/values-zh/strings.xml | 1 +
app/src/main/res/values/strings.xml | 2 ++
.../clash/design/common/CommonUiBuilder.kt | 14 ++++++++++
.../github/kr328/clash/design/common/Tips.kt | 27 +++++++++++++++++++
.../src/main/res/layout/view_setting_tip.xml | 23 ++++++++++++++++
8 files changed, 81 insertions(+), 13 deletions(-)
delete mode 100644 app/src/main/java/com/github/kr328/clash/utils/DpUtils.kt
create mode 100644 app/src/main/res/drawable/ic_info.xml
create mode 100644 design/src/main/java/com/github/kr328/clash/design/common/Tips.kt
create mode 100644 design/src/main/res/layout/view_setting_tip.xml
diff --git a/app/src/main/java/com/github/kr328/clash/ProfileEditActivity.kt b/app/src/main/java/com/github/kr328/clash/ProfileEditActivity.kt
index d0076d1..ef3c8f2 100644
--- a/app/src/main/java/com/github/kr328/clash/ProfileEditActivity.kt
+++ b/app/src/main/java/com/github/kr328/clash/ProfileEditActivity.kt
@@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
+import android.text.Html
import android.view.View
import android.webkit.MimeTypeMap
import androidx.appcompat.app.AlertDialog
@@ -68,6 +69,10 @@ class ProfileEditActivity : BaseActivity() {
setSupportActionBar(toolbar)
settings.build {
+ tips(icon = getDrawable(R.drawable.ic_info)) {
+ title = Html.fromHtml(getString(R.string.tips_profile), Html.FROM_HTML_MODE_LEGACY)
+ }
+
textInput(
title = getString(R.string.name),
icon = getDrawable(R.drawable.ic_label_outline),
diff --git a/app/src/main/java/com/github/kr328/clash/utils/DpUtils.kt b/app/src/main/java/com/github/kr328/clash/utils/DpUtils.kt
deleted file mode 100644
index 62de4d2..0000000
--- a/app/src/main/java/com/github/kr328/clash/utils/DpUtils.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.github.kr328.clash.utils
-
-import android.util.TypedValue
-import com.github.kr328.clash.core.Global
-
-val Int.dp: Float
- get() {
- return TypedValue.applyDimension(
- TypedValue.COMPLEX_UNIT_DIP,
- this.toFloat(),
- Global.application.resources.displayMetrics
- )
- }
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_info.xml b/app/src/main/res/drawable/ic_info.xml
new file mode 100644
index 0000000..f8ffdc6
--- /dev/null
+++ b/app/src/main/res/drawable/ic_info.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index 5546ad7..76b1537 100644
--- a/app/src/main/res/values-zh/strings.xml
+++ b/app/src/main/res/values-zh/strings.xml
@@ -126,4 +126,5 @@
Github Issues
%d 秒
已复制
+ Clash 配置文件
其中包含了 代理, 代理组 和 规则]]>
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b2a4f17..d168cc1 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -159,4 +159,6 @@
kr328app@outlook.com
https://github.com/Kr328/ClashForAndroid/issues
https://t.me/clash_for_android_channel
+
+ Clash Config which contains
Proxies, Proxy Groups and Rules]]>
diff --git a/design/src/main/java/com/github/kr328/clash/design/common/CommonUiBuilder.kt b/design/src/main/java/com/github/kr328/clash/design/common/CommonUiBuilder.kt
index fa8b431..f0659e1 100644
--- a/design/src/main/java/com/github/kr328/clash/design/common/CommonUiBuilder.kt
+++ b/design/src/main/java/com/github/kr328/clash/design/common/CommonUiBuilder.kt
@@ -71,6 +71,20 @@ class CommonUiBuilder(val screen: CommonUiScreen) {
screen.addElement(category)
}
+ fun tips(
+ title: String = "",
+ icon: Drawable? = null,
+ setup: Tips.() -> Unit) {
+ val tips = Tips(screen)
+
+ tips.title = title
+ tips.icon = icon
+
+ setup(tips)
+
+ screen.addElement(tips)
+ }
+
fun custom(
view: View,
setup: Custom.() -> Unit
diff --git a/design/src/main/java/com/github/kr328/clash/design/common/Tips.kt b/design/src/main/java/com/github/kr328/clash/design/common/Tips.kt
new file mode 100644
index 0000000..2d9fd52
--- /dev/null
+++ b/design/src/main/java/com/github/kr328/clash/design/common/Tips.kt
@@ -0,0 +1,27 @@
+package com.github.kr328.clash.design.common
+
+import android.graphics.drawable.Drawable
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.widget.TextView
+import com.github.kr328.clash.design.R
+
+class Tips(screen: CommonUiScreen): Base(screen) {
+ override val view: View = LayoutInflater.from(context)
+ .inflate(R.layout.view_setting_tip, screen.layout, false)
+
+ private val vIcon: View = view.findViewById(android.R.id.icon)
+ private val vTitle: TextView = view.findViewById(android.R.id.title)
+
+ var icon: Drawable?
+ get() = vIcon.background
+ set(value) { vIcon.background = value }
+
+ var title: CharSequence
+ get() = vTitle.text
+ set(value) { vTitle.text = value }
+
+ override fun saveState(bundle: Bundle) {}
+ override fun restoreState(bundle: Bundle) {}
+}
\ No newline at end of file
diff --git a/design/src/main/res/layout/view_setting_tip.xml b/design/src/main/res/layout/view_setting_tip.xml
new file mode 100644
index 0000000..cf309da
--- /dev/null
+++ b/design/src/main/res/layout/view_setting_tip.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
\ No newline at end of file