mirror of
https://github.com/MetaCubeX/ClashMetaForAndroid.git
synced 2024-11-16 14:52:18 +08:00
chore: support double multiple grid
This commit is contained in:
parent
e8b9603bdd
commit
1eb561c784
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -32,9 +32,13 @@
|
|||
<item
|
||||
android:id="@+id/single"
|
||||
android:title="@string/single" />
|
||||
<item
|
||||
android:id="@+id/doubles"
|
||||
android:title="@string/doubles" />
|
||||
<item
|
||||
android:id="@+id/multiple"
|
||||
android:title="@string/multiple" />
|
||||
|
||||
</group>
|
||||
</menu>
|
||||
</item>
|
||||
|
|
|
@ -185,6 +185,7 @@
|
|||
<string name="no_profile_selected">プロファイルが選択されていません</string>
|
||||
<string name="layout">レイアウト</string>
|
||||
<string name="single">シングルカラム</string>
|
||||
<string name="doubles">ダブルカラム</string>
|
||||
<string name="multiple">マルチカラム</string>
|
||||
<string name="not_selectable">選択不可</string>
|
||||
<string name="providers">プロバイダー</string>
|
||||
|
|
|
@ -185,6 +185,7 @@
|
|||
<string name="no_profile_selected">구성 파일이 선택되지 않았습니다.</string>
|
||||
<string name="layout">레이아웃</string>
|
||||
<string name="single">단일</string>
|
||||
<string name="doubles">더블</string>
|
||||
<string name="multiple">복합</string>
|
||||
<string name="not_selectable">선택 불가</string>
|
||||
<string name="providers">외부 리소스</string>
|
||||
|
|
|
@ -134,6 +134,7 @@
|
|||
<string name="sort">排序</string>
|
||||
<string name="layout">佈局</string>
|
||||
<string name="single">單列</string>
|
||||
<string name="doubles">雙列</string>
|
||||
<string name="multiple">多列</string>
|
||||
<string name="not_selectable">不可選擇</string>
|
||||
<string name="providers">外部資源</string>
|
||||
|
|
|
@ -134,6 +134,7 @@
|
|||
<string name="sort">排序</string>
|
||||
<string name="layout">佈局</string>
|
||||
<string name="single">單欄</string>
|
||||
<string name="doubles">雙欄</string>
|
||||
<string name="multiple">多欄</string>
|
||||
<string name="not_selectable">不可選擇</string>
|
||||
<string name="providers">提供者</string>
|
||||
|
|
|
@ -135,6 +135,7 @@
|
|||
<string name="sort">排序</string>
|
||||
<string name="layout">布局</string>
|
||||
<string name="single">单列</string>
|
||||
<string name="doubles">双列</string>
|
||||
<string name="multiple">多列</string>
|
||||
<string name="not_selectable">不可选择</string>
|
||||
<string name="providers">外部资源</string>
|
||||
|
|
|
@ -64,10 +64,10 @@
|
|||
<dimen name="main_top_banner_height">90dp</dimen>
|
||||
|
||||
<!-- Proxy Design -->
|
||||
<dimen name="proxy_layout_padding">5dp</dimen>
|
||||
<dimen name="proxy_content_padding">15dp</dimen>
|
||||
<dimen name="proxy_text_margin">10dp</dimen>
|
||||
<dimen name="proxy_text_size">12sp</dimen>
|
||||
<dimen name="proxy_layout_padding">3dp</dimen>
|
||||
<dimen name="proxy_content_padding">6dp</dimen>
|
||||
<dimen name="proxy_text_margin">5dp</dimen>
|
||||
<dimen name="proxy_text_size">11sp</dimen>
|
||||
<dimen name="proxy_card_radius">5dp</dimen>
|
||||
<dimen name="proxy_card_offset">0dp</dimen>
|
||||
|
||||
|
|
|
@ -233,6 +233,7 @@
|
|||
|
||||
<string name="layout">Layout</string>
|
||||
<string name="single">Single</string>
|
||||
<string name="doubles">Double</string>
|
||||
<string name="multiple">Multiple</string>
|
||||
<string name="not_selectable">Not Selectable</string>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user