From 1eb561c7840620d9c131275b88abc262c85dc9a7 Mon Sep 17 00:00:00 2001 From: metacubex Date: Sun, 11 Dec 2022 12:30:24 +0800 Subject: [PATCH] chore: support double multiple grid --- .../github/kr328/clash/design/ProxyDesign.kt | 4 ++-- .../kr328/clash/design/component/ProxyMenu.kt | 19 +++++++++++++------ .../design/component/ProxyPageFactory.kt | 9 +++++++-- .../kr328/clash/design/component/ProxyView.kt | 10 +++++----- .../clash/design/component/ProxyViewConfig.kt | 4 ++-- .../kr328/clash/design/store/UiStore.kt | 6 +++--- design/src/main/res/menu/menu_proxy.xml | 4 ++++ design/src/main/res/values-ja-rJP/strings.xml | 1 + design/src/main/res/values-ko-rKR/strings.xml | 1 + design/src/main/res/values-zh-rHK/strings.xml | 1 + design/src/main/res/values-zh-rTW/strings.xml | 1 + design/src/main/res/values-zh/strings.xml | 1 + design/src/main/res/values/dimens.xml | 8 ++++---- design/src/main/res/values/strings.xml | 1 + 14 files changed, 46 insertions(+), 24 deletions(-) diff --git a/design/src/main/java/com/github/kr328/clash/design/ProxyDesign.kt b/design/src/main/java/com/github/kr328/clash/design/ProxyDesign.kt index cddf6a21..8f012636 100644 --- a/design/src/main/java/com/github/kr328/clash/design/ProxyDesign.kt +++ b/design/src/main/java/com/github/kr328/clash/design/ProxyDesign.kt @@ -41,11 +41,11 @@ class ProxyDesign( private val binding = DesignProxyBinding .inflate(context.layoutInflater, context.root, false) - private val config = ProxyViewConfig(context, uiStore.proxySingleLine) + private var config = ProxyViewConfig(context, uiStore.proxyLine) private val menu: ProxyMenu by lazy { ProxyMenu(context, binding.menuView, overrideMode, uiStore, requests) { - config.singleLine = uiStore.proxySingleLine + config.proxyLine = uiStore.proxyLine } } diff --git a/design/src/main/java/com/github/kr328/clash/design/component/ProxyMenu.kt b/design/src/main/java/com/github/kr328/clash/design/component/ProxyMenu.kt index 1c785018..5d0672ad 100644 --- a/design/src/main/java/com/github/kr328/clash/design/component/ProxyMenu.kt +++ b/design/src/main/java/com/github/kr328/clash/design/component/ProxyMenu.kt @@ -35,14 +35,21 @@ class ProxyMenu( requests.trySend(ProxyDesign.Request.ReLaunch) } R.id.single -> { - uiStore.proxySingleLine = true + uiStore.proxyLine = 1 + + updateConfig() + + requests.trySend(ProxyDesign.Request.ReloadAll) + } + R.id.doubles -> { + uiStore.proxyLine = 2 updateConfig() requests.trySend(ProxyDesign.Request.ReloadAll) } R.id.multiple -> { - uiStore.proxySingleLine = false + uiStore.proxyLine = 3 updateConfig() @@ -87,10 +94,10 @@ class ProxyMenu( menu.menu.apply { findItem(R.id.not_selectable).isChecked = uiStore.proxyExcludeNotSelectable - if (uiStore.proxySingleLine) { - findItem(R.id.single).isChecked = true - } else { - findItem(R.id.multiple).isChecked = true + when (uiStore.proxyLine){ + 1 -> findItem(R.id.single).isChecked = true + 2 -> findItem(R.id.doubles).isChecked = true + 3 -> findItem(R.id.multiple).isChecked = true } when (uiStore.proxySort) { diff --git a/design/src/main/java/com/github/kr328/clash/design/component/ProxyPageFactory.kt b/design/src/main/java/com/github/kr328/clash/design/component/ProxyPageFactory.kt index 2ad7b8c4..ff9b84fb 100644 --- a/design/src/main/java/com/github/kr328/clash/design/component/ProxyPageFactory.kt +++ b/design/src/main/java/com/github/kr328/clash/design/component/ProxyPageFactory.kt @@ -32,10 +32,15 @@ class ProxyPageFactory(private val config: ProxyViewConfig) { root.addView(recyclerView) recyclerView.apply { - layoutManager = GridLayoutManager(config.context, 2).apply { + layoutManager = GridLayoutManager(config.context, 6).apply { spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() { override fun getSpanSize(position: Int): Int { - return if (config.singleLine) 2 else 1 + var grids:Int = 0 + when(config.proxyLine){ + 2 -> grids = 3 + 3 -> grids = 2 + } + return if (config.proxyLine==1) 6 else grids } } } diff --git a/design/src/main/java/com/github/kr328/clash/design/component/ProxyView.kt b/design/src/main/java/com/github/kr328/clash/design/component/ProxyView.kt index 01027ce7..1b8a807c 100644 --- a/design/src/main/java/com/github/kr328/clash/design/component/ProxyView.kt +++ b/design/src/main/java/com/github/kr328/clash/design/component/ProxyView.kt @@ -6,19 +6,19 @@ import android.graphics.Paint import android.graphics.Path import android.view.View import com.github.kr328.clash.common.compat.getDrawableCompat +import com.github.kr328.clash.design.store.UiStore class ProxyView( context: Context, config: ProxyViewConfig, ) : View(context) { - constructor(context: Context) : this(context, ProxyViewConfig(context, false)) init { background = context.getDrawableCompat(config.clickableBackground) } var state: ProxyViewState? = null - + constructor(context: Context) : this(context, ProxyViewConfig(context, 2)) override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { val state = state ?: return super.onMeasure(widthMeasureSpec, heightMeasureSpec) @@ -40,9 +40,9 @@ class ProxyView( } val textHeight = state.rect.height() - val exceptHeight = (state.config.layoutPadding * 2 + + val exceptHeight = (state.config.layoutPadding * 4 + state.config.contentPadding * 2 + - textHeight * 2 + + textHeight * 4 + state.config.textMargin).toInt() val height = when (MeasureSpec.getMode(heightMeasureSpec)) { @@ -75,7 +75,7 @@ class ProxyView( // draw background canvas.apply { - if (state.config.singleLine) { + if (state.config.proxyLine==1) { drawRect(0f, 0f, width, height, paint) } else { val path = state.path diff --git a/design/src/main/java/com/github/kr328/clash/design/component/ProxyViewConfig.kt b/design/src/main/java/com/github/kr328/clash/design/component/ProxyViewConfig.kt index 8684f3f4..eac9b045 100644 --- a/design/src/main/java/com/github/kr328/clash/design/component/ProxyViewConfig.kt +++ b/design/src/main/java/com/github/kr328/clash/design/component/ProxyViewConfig.kt @@ -7,7 +7,7 @@ import com.github.kr328.clash.design.util.getPixels import com.github.kr328.clash.design.util.resolveThemedColor import com.github.kr328.clash.design.util.resolveThemedResourceId -class ProxyViewConfig(val context: Context, var singleLine: Boolean) { +class ProxyViewConfig(val context: Context, var proxyLine: Int) { private val colorSurface = context.resolveThemedColor(R.attr.colorSurface) val clickableBackground = @@ -18,7 +18,7 @@ class ProxyViewConfig(val context: Context, var singleLine: Boolean) { val unselectedControl = context.resolveThemedColor(R.attr.colorOnSurface) val unselectedBackground: Int - get() = if (singleLine) Color.TRANSPARENT else colorSurface + get() = if (proxyLine==1) Color.TRANSPARENT else colorSurface val layoutPadding = context.getPixels(R.dimen.proxy_layout_padding).toFloat() val contentPadding = context.getPixels(R.dimen.proxy_content_padding).toFloat() diff --git a/design/src/main/java/com/github/kr328/clash/design/store/UiStore.kt b/design/src/main/java/com/github/kr328/clash/design/store/UiStore.kt index ea42814f..f0202a64 100644 --- a/design/src/main/java/com/github/kr328/clash/design/store/UiStore.kt +++ b/design/src/main/java/com/github/kr328/clash/design/store/UiStore.kt @@ -30,9 +30,9 @@ class UiStore(context: Context) { defaultValue = false, ) - var proxySingleLine: Boolean by store.boolean( - key = "proxy_single_line", - defaultValue = false + var proxyLine: Int by store.int( + key = "proxy_line", + defaultValue = 2 ) var proxySort: ProxySort by store.enum( diff --git a/design/src/main/res/menu/menu_proxy.xml b/design/src/main/res/menu/menu_proxy.xml index 77725c9e..6c5db536 100644 --- a/design/src/main/res/menu/menu_proxy.xml +++ b/design/src/main/res/menu/menu_proxy.xml @@ -32,9 +32,13 @@ + + diff --git a/design/src/main/res/values-ja-rJP/strings.xml b/design/src/main/res/values-ja-rJP/strings.xml index b2387302..ff349bd4 100644 --- a/design/src/main/res/values-ja-rJP/strings.xml +++ b/design/src/main/res/values-ja-rJP/strings.xml @@ -185,6 +185,7 @@ プロファイルが選択されていません レイアウト シングルカラム + ダブルカラム マルチカラム 選択不可 プロバイダー diff --git a/design/src/main/res/values-ko-rKR/strings.xml b/design/src/main/res/values-ko-rKR/strings.xml index 7bd21441..b5381f6f 100644 --- a/design/src/main/res/values-ko-rKR/strings.xml +++ b/design/src/main/res/values-ko-rKR/strings.xml @@ -185,6 +185,7 @@ 구성 파일이 선택되지 않았습니다. 레이아웃 단일 + 더블 복합 선택 불가 외부 리소스 diff --git a/design/src/main/res/values-zh-rHK/strings.xml b/design/src/main/res/values-zh-rHK/strings.xml index 28ab1d70..3ac6d9ee 100644 --- a/design/src/main/res/values-zh-rHK/strings.xml +++ b/design/src/main/res/values-zh-rHK/strings.xml @@ -134,6 +134,7 @@ 排序 佈局 單列 + 雙列 多列 不可選擇 外部資源 diff --git a/design/src/main/res/values-zh-rTW/strings.xml b/design/src/main/res/values-zh-rTW/strings.xml index e0ffe755..dee57003 100644 --- a/design/src/main/res/values-zh-rTW/strings.xml +++ b/design/src/main/res/values-zh-rTW/strings.xml @@ -134,6 +134,7 @@ 排序 佈局 單欄 + 雙欄 多欄 不可選擇 提供者 diff --git a/design/src/main/res/values-zh/strings.xml b/design/src/main/res/values-zh/strings.xml index 4bc2cc95..8fc03d6d 100644 --- a/design/src/main/res/values-zh/strings.xml +++ b/design/src/main/res/values-zh/strings.xml @@ -135,6 +135,7 @@ 排序 布局 单列 + 双列 多列 不可选择 外部资源 diff --git a/design/src/main/res/values/dimens.xml b/design/src/main/res/values/dimens.xml index a967936c..62c0dfc2 100644 --- a/design/src/main/res/values/dimens.xml +++ b/design/src/main/res/values/dimens.xml @@ -64,10 +64,10 @@ 90dp - 5dp - 15dp - 10dp - 12sp + 3dp + 6dp + 5dp + 11sp 5dp 0dp diff --git a/design/src/main/res/values/strings.xml b/design/src/main/res/values/strings.xml index 2fce0942..67ec395a 100644 --- a/design/src/main/res/values/strings.xml +++ b/design/src/main/res/values/strings.xml @@ -233,6 +233,7 @@ Layout Single + Double Multiple Not Selectable