Skip to content

Commit

Permalink
feat: custom GitHub Proxy (#208)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
hamjin and fankes authored Oct 2, 2024
1 parent a2bf9d2 commit a601739
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/fankes/miui/notify/data/ConfigData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,36 +110,56 @@ object IconRuleManagerTool {
title = "同步列表"
var sourceType = ConfigData.iconRuleSourceSyncType
var customUrl = ConfigData.iconRuleSourceSyncCustomUrl
var proxyUrl = ConfigData.iconRuleSourceSyncProxyUrl
binding.sourceUrlEdit.apply {
if (customUrl.isNotBlank()) {
setText(customUrl)
setSelection(customUrl.length)
}
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
}
Expand All @@ -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 = "自定义规则") {
Expand Down Expand Up @@ -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://"))
Expand Down
25 changes: 24 additions & 1 deletion app/src/main/res/layout/dia_source_from.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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"
Expand Down Expand Up @@ -122,4 +145,4 @@
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

0 comments on commit a601739

Please sign in to comment.