chore: support double multiple grid

This commit is contained in:
metacubex 2022-12-11 12:30:24 +08:00
parent e8b9603bdd
commit 1eb561c784
14 changed files with 46 additions and 24 deletions

View File

@ -41,11 +41,11 @@ class ProxyDesign(
private val binding = DesignProxyBinding private val binding = DesignProxyBinding
.inflate(context.layoutInflater, context.root, false) .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 { private val menu: ProxyMenu by lazy {
ProxyMenu(context, binding.menuView, overrideMode, uiStore, requests) { ProxyMenu(context, binding.menuView, overrideMode, uiStore, requests) {
config.singleLine = uiStore.proxySingleLine config.proxyLine = uiStore.proxyLine
} }
} }

View File

@ -35,14 +35,21 @@ class ProxyMenu(
requests.trySend(ProxyDesign.Request.ReLaunch) requests.trySend(ProxyDesign.Request.ReLaunch)
} }
R.id.single -> { R.id.single -> {
uiStore.proxySingleLine = true uiStore.proxyLine = 1
updateConfig()
requests.trySend(ProxyDesign.Request.ReloadAll)
}
R.id.doubles -> {
uiStore.proxyLine = 2
updateConfig() updateConfig()
requests.trySend(ProxyDesign.Request.ReloadAll) requests.trySend(ProxyDesign.Request.ReloadAll)
} }
R.id.multiple -> { R.id.multiple -> {
uiStore.proxySingleLine = false uiStore.proxyLine = 3
updateConfig() updateConfig()
@ -87,10 +94,10 @@ class ProxyMenu(
menu.menu.apply { menu.menu.apply {
findItem(R.id.not_selectable).isChecked = uiStore.proxyExcludeNotSelectable findItem(R.id.not_selectable).isChecked = uiStore.proxyExcludeNotSelectable
if (uiStore.proxySingleLine) { when (uiStore.proxyLine){
findItem(R.id.single).isChecked = true 1 -> findItem(R.id.single).isChecked = true
} else { 2 -> findItem(R.id.doubles).isChecked = true
findItem(R.id.multiple).isChecked = true 3 -> findItem(R.id.multiple).isChecked = true
} }
when (uiStore.proxySort) { when (uiStore.proxySort) {

View File

@ -32,10 +32,15 @@ class ProxyPageFactory(private val config: ProxyViewConfig) {
root.addView(recyclerView) root.addView(recyclerView)
recyclerView.apply { recyclerView.apply {
layoutManager = GridLayoutManager(config.context, 2).apply { layoutManager = GridLayoutManager(config.context, 6).apply {
spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() { spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int { 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
} }
} }
} }

View File

@ -6,19 +6,19 @@ import android.graphics.Paint
import android.graphics.Path import android.graphics.Path
import android.view.View import android.view.View
import com.github.kr328.clash.common.compat.getDrawableCompat import com.github.kr328.clash.common.compat.getDrawableCompat
import com.github.kr328.clash.design.store.UiStore
class ProxyView( class ProxyView(
context: Context, context: Context,
config: ProxyViewConfig, config: ProxyViewConfig,
) : View(context) { ) : View(context) {
constructor(context: Context) : this(context, ProxyViewConfig(context, false))
init { init {
background = context.getDrawableCompat(config.clickableBackground) background = context.getDrawableCompat(config.clickableBackground)
} }
var state: ProxyViewState? = null var state: ProxyViewState? = null
constructor(context: Context) : this(context, ProxyViewConfig(context, 2))
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val state = state ?: return super.onMeasure(widthMeasureSpec, heightMeasureSpec) val state = state ?: return super.onMeasure(widthMeasureSpec, heightMeasureSpec)
@ -40,9 +40,9 @@ class ProxyView(
} }
val textHeight = state.rect.height() val textHeight = state.rect.height()
val exceptHeight = (state.config.layoutPadding * 2 + val exceptHeight = (state.config.layoutPadding * 4 +
state.config.contentPadding * 2 + state.config.contentPadding * 2 +
textHeight * 2 + textHeight * 4 +
state.config.textMargin).toInt() state.config.textMargin).toInt()
val height = when (MeasureSpec.getMode(heightMeasureSpec)) { val height = when (MeasureSpec.getMode(heightMeasureSpec)) {
@ -75,7 +75,7 @@ class ProxyView(
// draw background // draw background
canvas.apply { canvas.apply {
if (state.config.singleLine) { if (state.config.proxyLine==1) {
drawRect(0f, 0f, width, height, paint) drawRect(0f, 0f, width, height, paint)
} else { } else {
val path = state.path val path = state.path

View File

@ -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.resolveThemedColor
import com.github.kr328.clash.design.util.resolveThemedResourceId 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) private val colorSurface = context.resolveThemedColor(R.attr.colorSurface)
val clickableBackground = val clickableBackground =
@ -18,7 +18,7 @@ class ProxyViewConfig(val context: Context, var singleLine: Boolean) {
val unselectedControl = context.resolveThemedColor(R.attr.colorOnSurface) val unselectedControl = context.resolveThemedColor(R.attr.colorOnSurface)
val unselectedBackground: Int 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 layoutPadding = context.getPixels(R.dimen.proxy_layout_padding).toFloat()
val contentPadding = context.getPixels(R.dimen.proxy_content_padding).toFloat() val contentPadding = context.getPixels(R.dimen.proxy_content_padding).toFloat()

View File

@ -30,9 +30,9 @@ class UiStore(context: Context) {
defaultValue = false, defaultValue = false,
) )
var proxySingleLine: Boolean by store.boolean( var proxyLine: Int by store.int(
key = "proxy_single_line", key = "proxy_line",
defaultValue = false defaultValue = 2
) )
var proxySort: ProxySort by store.enum( var proxySort: ProxySort by store.enum(

View File

@ -32,9 +32,13 @@
<item <item
android:id="@+id/single" android:id="@+id/single"
android:title="@string/single" /> android:title="@string/single" />
<item
android:id="@+id/doubles"
android:title="@string/doubles" />
<item <item
android:id="@+id/multiple" android:id="@+id/multiple"
android:title="@string/multiple" /> android:title="@string/multiple" />
</group> </group>
</menu> </menu>
</item> </item>

View File

@ -185,6 +185,7 @@
<string name="no_profile_selected">プロファイルが選択されていません</string> <string name="no_profile_selected">プロファイルが選択されていません</string>
<string name="layout">レイアウト</string> <string name="layout">レイアウト</string>
<string name="single">シングルカラム</string> <string name="single">シングルカラム</string>
<string name="doubles">ダブルカラム</string>
<string name="multiple">マルチカラム</string> <string name="multiple">マルチカラム</string>
<string name="not_selectable">選択不可</string> <string name="not_selectable">選択不可</string>
<string name="providers">プロバイダー</string> <string name="providers">プロバイダー</string>

View File

@ -185,6 +185,7 @@
<string name="no_profile_selected">구성 파일이 선택되지 않았습니다.</string> <string name="no_profile_selected">구성 파일이 선택되지 않았습니다.</string>
<string name="layout">레이아웃</string> <string name="layout">레이아웃</string>
<string name="single">단일</string> <string name="single">단일</string>
<string name="doubles">더블</string>
<string name="multiple">복합</string> <string name="multiple">복합</string>
<string name="not_selectable">선택 불가</string> <string name="not_selectable">선택 불가</string>
<string name="providers">외부 리소스</string> <string name="providers">외부 리소스</string>

View File

@ -134,6 +134,7 @@
<string name="sort">排序</string> <string name="sort">排序</string>
<string name="layout">佈局</string> <string name="layout">佈局</string>
<string name="single">單列</string> <string name="single">單列</string>
<string name="doubles">雙列</string>
<string name="multiple">多列</string> <string name="multiple">多列</string>
<string name="not_selectable">不可選擇</string> <string name="not_selectable">不可選擇</string>
<string name="providers">外部資源</string> <string name="providers">外部資源</string>

View File

@ -134,6 +134,7 @@
<string name="sort">排序</string> <string name="sort">排序</string>
<string name="layout">佈局</string> <string name="layout">佈局</string>
<string name="single">單欄</string> <string name="single">單欄</string>
<string name="doubles">雙欄</string>
<string name="multiple">多欄</string> <string name="multiple">多欄</string>
<string name="not_selectable">不可選擇</string> <string name="not_selectable">不可選擇</string>
<string name="providers">提供者</string> <string name="providers">提供者</string>

View File

@ -135,6 +135,7 @@
<string name="sort">排序</string> <string name="sort">排序</string>
<string name="layout">布局</string> <string name="layout">布局</string>
<string name="single">单列</string> <string name="single">单列</string>
<string name="doubles">双列</string>
<string name="multiple">多列</string> <string name="multiple">多列</string>
<string name="not_selectable">不可选择</string> <string name="not_selectable">不可选择</string>
<string name="providers">外部资源</string> <string name="providers">外部资源</string>

View File

@ -64,10 +64,10 @@
<dimen name="main_top_banner_height">90dp</dimen> <dimen name="main_top_banner_height">90dp</dimen>
<!-- Proxy Design --> <!-- Proxy Design -->
<dimen name="proxy_layout_padding">5dp</dimen> <dimen name="proxy_layout_padding">3dp</dimen>
<dimen name="proxy_content_padding">15dp</dimen> <dimen name="proxy_content_padding">6dp</dimen>
<dimen name="proxy_text_margin">10dp</dimen> <dimen name="proxy_text_margin">5dp</dimen>
<dimen name="proxy_text_size">12sp</dimen> <dimen name="proxy_text_size">11sp</dimen>
<dimen name="proxy_card_radius">5dp</dimen> <dimen name="proxy_card_radius">5dp</dimen>
<dimen name="proxy_card_offset">0dp</dimen> <dimen name="proxy_card_offset">0dp</dimen>

View File

@ -233,6 +233,7 @@
<string name="layout">Layout</string> <string name="layout">Layout</string>
<string name="single">Single</string> <string name="single">Single</string>
<string name="doubles">Double</string>
<string name="multiple">Multiple</string> <string name="multiple">Multiple</string>
<string name="not_selectable">Not Selectable</string> <string name="not_selectable">Not Selectable</string>