add tips for profiles

This commit is contained in:
Kr328 committed 2020-02-20 01:21:59 +08:00
1 parent 5f1ee513f2
commit ba8a6247f5
8 files changed
+81 -13

No files matched your search

@@ -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),
@@ -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
)
}
+9
View File
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="?attr/colorOnSurface"
android:pathData="M11,17h2v-6h-2v6zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM11,9h2L13,7h-2v2z"/>
</vector>
+1
View File
@@ -126,4 +126,5 @@
<string name="github_issues">Github Issues</string>
<string name="format_seconds">%d 秒</string>
<string name="copied">已复制</string>
<string name="tips_profile"><![CDATA[仅接受 <strong>Clash 配置文件</strong> <br />其中包含了 <strong>代理, 代理组 和 规则</strong>]]></string>
</resources>
+2
View File
@@ -159,4 +159,6 @@
<string name="email_url" translatable="false">[email protected]</string>
<string name="github_issues_url" translatable="false">https://github.com/Kr328/ClashForAndroid/issues</string>
<string name="telegram_channel_url" translatable="false">https://t.me/clash_for_android_channel</string>
<string name="tips_profile"><![CDATA[Accept Only <strong>Clash Config</strong> which contains <br /><strong>Proxies, Proxy Groups and Rules</strong>]]></string>
</resources>
@@ -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
@@ -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) {}
}
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="@android:id/icon"
android:layout_centerVertical="true"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="22.5dp"
android:layout_marginEnd="22.5dp" />
<TextView
android:id="@android:id/title"
android:layout_toEndOf="@android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:layout_marginStart="2dp"/>
</RelativeLayout>