Skip to content

Commit 70a383f

Browse files
errorcodeQQerrorcodeQQ
authored andcommitted
fix: Resolve empty provider list, clean up UI clutter, and fix author
1 parent 0bfd9e9 commit 70a383f

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

CSGuard/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version = 1
22

33
cloudstream {
44
description = "Defensive CloudStream plugin that intercepts and neutralizes malicious browser-redirect ad injections from other extensions. Wraps provider Context objects so raw Intent.ACTION_VIEW calls to ad networks are silently dropped to the void."
5-
authors = listOf("CSGuard")
5+
authors = listOf("errorcodeQQ")
66
status = 1
77
tvTypes = listOf("Others")
88
requiresResources = false

CSGuard/src/main/kotlin/com/csguard/GuardSettingsDialog.kt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import android.widget.ScrollView
1111
import android.widget.Switch
1212
import android.widget.TextView
1313
import com.lagradost.cloudstream3.APIHolder
14+
import com.lagradost.cloudstream3.MainAPI
1415

1516
class GuardSettingsDialog(
1617
private val context: Context,
@@ -41,7 +42,7 @@ class GuardSettingsDialog(
4142

4243
var isGlobalStrict = current.blockAllUnknown
4344

44-
val masterRow = createRow("Global Strict Mode", "Block ALL unknown external intents across the entire app.", isGlobalStrict) { checked ->
45+
val masterRow = createRow("Global Strict Mode (Block All Unknown)", isGlobalStrict) { checked ->
4546
isGlobalStrict = checked
4647
}
4748
container.addView(masterRow)
@@ -57,7 +58,16 @@ class GuardSettingsDialog(
5758
val blockedSet = AllowlistStore.blockedProviders().toMutableSet()
5859

5960
val providers = try {
60-
APIHolder.allProviders.sortedBy { it.name }
61+
val getApisMethod = APIHolder::class.java.methods.find {
62+
it.name == "getAllProviders" || it.name == "getApis" || it.name == "apis"
63+
}
64+
val apis = if (getApisMethod != null) {
65+
getApisMethod.isAccessible = true
66+
getApisMethod.invoke(APIHolder) as? List<MainAPI> ?: emptyList()
67+
} else {
68+
APIHolder.allProviders
69+
}
70+
apis.sortedBy { it.name }
6171
} catch (_: Throwable) { emptyList() }
6272

6373
if (providers.isEmpty()) {
@@ -67,7 +77,7 @@ class GuardSettingsDialog(
6777
})
6878
} else {
6979
providers.forEach { provider ->
70-
val row = createRow(provider.name, "Plugin: ${provider.javaClass.simpleName}", blockedSet.contains(provider.name)) { checked ->
80+
val row = createRow(provider.name, blockedSet.contains(provider.name)) { checked ->
7181
if (checked) blockedSet.add(provider.name) else blockedSet.remove(provider.name)
7282
}
7383
container.addView(row)
@@ -98,7 +108,7 @@ class GuardSettingsDialog(
98108
.show()
99109
}
100110

101-
private fun createRow(title: String, subtitle: String, isChecked: Boolean, onToggle: (Boolean) -> Unit): LinearLayout {
111+
private fun createRow(title: String, isChecked: Boolean, onToggle: (Boolean) -> Unit): LinearLayout {
102112
val row = LinearLayout(context).apply {
103113
orientation = LinearLayout.HORIZONTAL
104114
gravity = Gravity.CENTER_VERTICAL
@@ -121,6 +131,7 @@ class GuardSettingsDialog(
121131
val textLayout = LinearLayout(context).apply {
122132
orientation = LinearLayout.VERTICAL
123133
layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)
134+
gravity = Gravity.CENTER_VERTICAL
124135
}
125136

126137
val titleView = TextView(context).apply {
@@ -129,16 +140,8 @@ class GuardSettingsDialog(
129140
setTextColor(Color.WHITE)
130141
typeface = Typeface.DEFAULT_BOLD
131142
}
132-
133-
val subtitleView = TextView(context).apply {
134-
text = subtitle
135-
textSize = 12f
136-
setTextColor(Color.parseColor("#888888"))
137-
setPadding(0, 4, 0, 0)
138-
}
139143

140144
textLayout.addView(titleView)
141-
textLayout.addView(subtitleView)
142145

143146
val toggle = Switch(context).apply {
144147
this.isChecked = isChecked

0 commit comments

Comments
 (0)