feat: custom GitHub Proxy (#208)

* feat: Custom GitHub Proxy

Signed-off-by: hamjin <jinham@qq.com>

* refactor: organize text layout

---------

Signed-off-by: hamjin <jinham@qq.com>
Co-authored-by: Fankesyooni <37344460+fankes@users.noreply.github.com>
This commit is contained in:
hamjin
2024-10-03 00:29:51 +08:00
committed by GitHub
parent a2bf9d24eb
commit a601739679
4 changed files with 65 additions and 3 deletions

View File

@@ -50,6 +50,9 @@ object IconRuleSourceSyncType {
/** GitHub Raw (直连) */
const val GITHUB_RAW_DIRECT = 2000
/** GitHub Raw (自定义) */
const val GITHUB_RAW_PROXY = 4000
/** 自定义地址 */
const val CUSTOM_URL = 3000
}

View File

@@ -93,6 +93,9 @@ object ConfigData {
/** 通知图标优化名单同步地址 */
val ICON_RULE_SOURCE_SYNC_CUSTOM_URL = PrefsData("_rule_source_sync_way_custom_url", "")
/** 通知图标优化名单同步镜像地址 */
val ICON_RULE_SOURCE_SYNC_PROXY_URL = PrefsData("_rule_source_sync_way_proxy_url", "")
/** 忽略 Android 版本过低提示 */
val IGNORED_ANDROID_VERSION_TO_LOW = PrefsData("_ignored_android_version_to_low", false)
@@ -363,6 +366,16 @@ object ConfigData {
putString(ICON_RULE_SOURCE_SYNC_CUSTOM_URL, value)
}
/**
* 通知图标优化名单同步镜像地址
* @return [String]
*/
var iconRuleSourceSyncProxyUrl
get() = getString(ICON_RULE_SOURCE_SYNC_PROXY_URL)
set(value) {
putString(ICON_RULE_SOURCE_SYNC_PROXY_URL, value)
}
/**
* 是否忽略 Android 版本过低提示
* @return [Boolean]

View File

@@ -110,6 +110,7 @@ object IconRuleManagerTool {
title = "同步列表"
var sourceType = ConfigData.iconRuleSourceSyncType
var customUrl = ConfigData.iconRuleSourceSyncCustomUrl
var proxyUrl = ConfigData.iconRuleSourceSyncProxyUrl
binding.sourceUrlEdit.apply {
if (customUrl.isNotBlank()) {
setText(customUrl)
@@ -117,29 +118,48 @@ object IconRuleManagerTool {
}
doOnTextChanged { text, _, _, _ -> customUrl = text.toString() }
}
binding.sourceUrlEditProxy.apply {
if (proxyUrl.isNotBlank()) {
setText(proxyUrl)
setSelection(proxyUrl.length)
}
doOnTextChanged { text, _, _, _ -> proxyUrl = text.toString() }
}
binding.sourceFromTextLin.isVisible = sourceType == IconRuleSourceSyncType.CUSTOM_URL
binding.sourceFromTextLinProxy.isVisible = sourceType == IconRuleSourceSyncType.GITHUB_RAW_PROXY
binding.sourceTravelerLin.isVisible = sourceType != IconRuleSourceSyncType.CUSTOM_URL
binding.sourceRadio0.isChecked = sourceType == IconRuleSourceSyncType.GITHUB_RAW_PROXY_1
binding.sourceRadio1.isChecked = sourceType == IconRuleSourceSyncType.GITHUB_RAW_PROXY_2
binding.sourceRadio2.isChecked = sourceType == IconRuleSourceSyncType.GITHUB_RAW_DIRECT
binding.sourceRadio3.isChecked = sourceType == IconRuleSourceSyncType.CUSTOM_URL
binding.sourceRadio3.isChecked = sourceType == IconRuleSourceSyncType.GITHUB_RAW_PROXY
binding.sourceRadio4.isChecked = sourceType == IconRuleSourceSyncType.CUSTOM_URL
binding.sourceRadio0.setOnClickListener {
binding.sourceFromTextLin.isVisible = false
binding.sourceFromTextLinProxy.isVisible = false
binding.sourceTravelerLin.isVisible = true
sourceType = IconRuleSourceSyncType.GITHUB_RAW_PROXY_1
}
binding.sourceRadio1.setOnClickListener {
binding.sourceFromTextLin.isVisible = false
binding.sourceFromTextLinProxy.isVisible = false
binding.sourceTravelerLin.isVisible = true
sourceType = IconRuleSourceSyncType.GITHUB_RAW_PROXY_2
}
binding.sourceRadio2.setOnClickListener {
binding.sourceFromTextLin.isVisible = false
binding.sourceFromTextLinProxy.isVisible = false
binding.sourceTravelerLin.isVisible = true
sourceType = IconRuleSourceSyncType.GITHUB_RAW_DIRECT
}
binding.sourceRadio3.setOnClickListener {
binding.sourceFromTextLin.isVisible = false
binding.sourceFromTextLinProxy.isVisible = true
binding.sourceTravelerLin.isVisible = true
sourceType = IconRuleSourceSyncType.GITHUB_RAW_PROXY
}
binding.sourceRadio4.setOnClickListener {
binding.sourceFromTextLin.isVisible = true
binding.sourceFromTextLinProxy.isVisible = false
binding.sourceTravelerLin.isVisible = false
sourceType = IconRuleSourceSyncType.CUSTOM_URL
}
@@ -148,7 +168,8 @@ object IconRuleManagerTool {
confirmButton {
ConfigData.iconRuleSourceSyncType = sourceType
ConfigData.iconRuleSourceSyncCustomUrl = customUrl
sync(context, sourceType, customUrl, callback)
ConfigData.iconRuleSourceSyncProxyUrl = proxyUrl
sync(context, sourceType, customUrl, proxyUrl, callback)
}
cancelButton()
neutralButton(text = "自定义规则") {
@@ -207,12 +228,14 @@ object IconRuleManagerTool {
context: Context,
sourceType: Int = ConfigData.iconRuleSourceSyncType,
customUrl: String = ConfigData.iconRuleSourceSyncCustomUrl,
proxyUrl: String = ConfigData.iconRuleSourceSyncProxyUrl,
callback: () -> Unit
) {
when (sourceType) {
IconRuleSourceSyncType.GITHUB_RAW_PROXY_1 -> onRefreshing(context, SYNC_PROXY_1_URL, callback)
IconRuleSourceSyncType.GITHUB_RAW_PROXY_2 -> onRefreshing(context, SYNC_PROXY_2_URL, callback)
IconRuleSourceSyncType.GITHUB_RAW_DIRECT -> onRefreshing(context, SYNC_DIRECT_URL, callback)
IconRuleSourceSyncType.GITHUB_RAW_PROXY -> onRefreshing(context, "$proxyUrl/$SYNC_DIRECT_URL", callback)
IconRuleSourceSyncType.CUSTOM_URL ->
if (customUrl.isNotBlank())
if (customUrl.startsWith("http://") || customUrl.startsWith("https://"))

View File

@@ -49,6 +49,13 @@
android:id="@+id/source_radio_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GitHub Proxy (自定义)"
app:buttonTint="@color/colorPrimaryAccent" />
<com.google.android.material.radiobutton.MaterialRadioButton
android:id="@+id/source_radio_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="从自定义地址获取"
app:buttonTint="@color/colorPrimaryAccent" />
</RadioGroup>
@@ -69,6 +76,22 @@
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/source_from_text_lin_proxy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:visibility="gone">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/source_url_edit_proxy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:hint="请输入 GitHub Proxy URL"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:id="@+id/source_traveler_lin"
android:layout_width="match_parent"
@@ -122,4 +145,4 @@
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>