Skip to content

Commit f34afbb

Browse files
committed
Show the exact number of app intercepted, for small N
1 parent 729afb1 commit f34afbb

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

app/src/main/java/tech/httptoolkit/android/ConnectionStatusView.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import com.google.android.material.card.MaterialCardView
1010
class ConnectionStatusView(
1111
context: Context,
1212
proxyConfig: ProxyConfig,
13-
isInterceptingAllApps: Boolean,
13+
totalAppCount: Int,
14+
interceptedAppCount: Int,
1415
changeApps: () -> Unit
1516
) : LinearLayout(context) {
1617

@@ -40,11 +41,12 @@ class ConnectionStatusView(
4041

4142
val appInterceptionStatusText = findViewById<TextView>(R.id.appInterceptionStatusText)
4243
appInterceptionStatusText.text = context.getString(
43-
if (isInterceptingAllApps)
44-
R.string.intercepting_all
45-
else
46-
R.string.intercepting_selected
47-
)
44+
when {
45+
totalAppCount == interceptedAppCount -> R.string.intercepting_all
46+
interceptedAppCount > 10 -> R.string.intercepting_selected
47+
else -> R.string.intercepting_few
48+
}
49+
, interceptedAppCount, if (interceptedAppCount != 1) "s" else "")
4850
}
4951

5052
}

app/src/main/java/tech/httptoolkit/android/MainActivity.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,20 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
249249
}
250250
MainState.CONNECTED -> {
251251
val proxyConfig = this.currentProxyConfig!!
252-
val isInterceptingAllApps = app.uninterceptedApps.isEmpty()
252+
val totalAppCount = packageManager.getInstalledPackages(PackageManager.GET_META_DATA)
253+
.map { app -> app.packageName }
254+
.toSet()
255+
.size
256+
val interceptedAppsCount = totalAppCount - app.uninterceptedApps.size
253257

254258
statusText.setText(R.string.connected_status)
255259

256260
detailContainer.addView(
257261
ConnectionStatusView(
258262
this,
259263
proxyConfig,
260-
isInterceptingAllApps,
264+
totalAppCount,
265+
interceptedAppsCount,
261266
::chooseApps
262267
)
263268
)

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@
3232
<string name="docs_button">Read the docs</string>
3333
<string name="try_again_button">Try again</string>
3434
<string name="test_button">Test interception</string>
35-
<string name="intercepting_all">Intercepting all apps</string>
36-
<string name="intercepting_selected">Intercepting selected apps</string>
3735
<string name="app_drawable">App Drawable</string>
3836
<string name="applications">Applications</string>
3937
<string name="all_applications">All applications</string>
4038
<string name="show_system">Show system</string>
4139
<string name="show_enabled">Show enabled only</string>
4240
<string name="enable_all">Enable all apps</string>
4341
<string name="disable_all">Disable all apps</string>
42+
43+
<string name="intercepting_all">Intercepting all apps</string>
44+
<string name="intercepting_selected">Intercepting selected apps</string>
45+
<string name="intercepting_few">Intercepting %s app%s</string>
4446
</resources>

0 commit comments

Comments
 (0)