Skip to content

Commit 889501e

Browse files
Merge pull request #2498 from hussainmohd-a/main
lint-fix
2 parents e97c2c5 + 19cd552 commit 889501e

26 files changed

+173
-89
lines changed

app/src/full/java/com/celzero/bravedns/adapter/AppWiseDomainsAdapter.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class AppWiseDomainsAdapter(
5353
AppDomainRulesBottomSheet.OnBottomSheetDialogFragmentDismiss {
5454

5555
private var maxValue: Int = 0
56-
private var minPercentage: Int = 100
56+
private var minPercentage: Int = INITIAL_MIN_PERCENTAGE
5757

5858
companion object {
5959
private val DIFF_CALLBACK =
@@ -71,6 +71,8 @@ class AppWiseDomainsAdapter(
7171
}
7272

7373
private const val TAG = "AppWiseDomainsAdapter"
74+
private const val INITIAL_MIN_PERCENTAGE = 100
75+
private const val PERCENTAGE_MULTIPLIER = 100
7476
}
7577

7678
private lateinit var adapter: AppWiseDomainsAdapter
@@ -99,15 +101,15 @@ class AppWiseDomainsAdapter(
99101
}
100102

101103
private fun calculatePercentage(c: Double): Int {
102-
val value = (log2(c) * 100).toInt()
104+
val value = (log2(c) * PERCENTAGE_MULTIPLIER).toInt()
103105
// maxValue will be based on the count returned by db query (order by count desc)
104106
if (value > maxValue) {
105107
maxValue = value
106108
}
107109
return if (maxValue == 0) {
108110
0
109111
} else {
110-
val percentage = (value * 100 / maxValue)
112+
val percentage = (value * PERCENTAGE_MULTIPLIER / maxValue)
111113
// minPercentage is used to show the progress bar when the percentage is 0
112114
if (percentage < minPercentage && percentage != 0) {
113115
minPercentage = percentage
@@ -282,7 +284,7 @@ class AppWiseDomainsAdapter(
282284
override fun notifyDataset(position: Int) {
283285
// Fix: IndexOutOfBoundsException - validate position before notifying
284286
try {
285-
if (position >= 0 && position < itemCount) {
287+
if (position in 0..<itemCount) {
286288
notifyItemChanged(position)
287289
} else {
288290
// Position is invalid, refresh the entire dataset instead

app/src/full/java/com/celzero/bravedns/adapter/AppWiseIpsAdapter.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class AppWiseIpsAdapter(val context: Context, val lifecycleOwner: LifecycleOwner
4242
AppIpRulesBottomSheet.OnBottomSheetDialogFragmentDismiss {
4343

4444
private var maxValue: Int = 0
45-
private var minPercentage: Int = 100
45+
private var minPercentage: Int = INITIAL_MIN_PERCENTAGE
4646

4747
companion object {
4848
private val DIFF_CALLBACK =
@@ -52,6 +52,8 @@ class AppWiseIpsAdapter(val context: Context, val lifecycleOwner: LifecycleOwner
5252
override fun areContentsTheSame(old: AppConnection, new: AppConnection) = old == new
5353
}
5454
private const val TAG = "AppWiseIpsAdapter"
55+
private const val INITIAL_MIN_PERCENTAGE = 100
56+
private const val PERCENTAGE_MULTIPLIER = 100
5557
}
5658

5759
private lateinit var adapter: AppWiseIpsAdapter
@@ -70,15 +72,15 @@ class AppWiseIpsAdapter(val context: Context, val lifecycleOwner: LifecycleOwner
7072
}
7173

7274
private fun calculatePercentage(c: Double): Int {
73-
val value = (log2(c) * 100).toInt()
75+
val value = (log2(c) * PERCENTAGE_MULTIPLIER).toInt()
7476
// maxValue will be based on the count returned by db query (order by count desc)
7577
if (value > maxValue) {
7678
maxValue = value
7779
}
7880
return if (maxValue == 0) {
7981
0
8082
} else {
81-
val percentage = (value * 100 / maxValue)
83+
val percentage = (value * PERCENTAGE_MULTIPLIER / maxValue)
8284
// minPercentage is used to show the progress bar when the percentage is 0
8385
if (percentage < minPercentage && percentage != 0) {
8486
minPercentage = percentage

app/src/full/java/com/celzero/bravedns/adapter/BubbleAllowedAppsAdapter.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ class BubbleAllowedAppsAdapter(
3838
return oldItem == newItem
3939
}
4040
}
41+
42+
// Time constants for allowed app duration calculation
43+
private const val ALLOWED_DURATION_MINUTES = 15
44+
private const val MILLIS_PER_MINUTE = 60
45+
private const val MILLIS_PER_SECOND = 1000
46+
private const val SINGLE_MINUTE = 1L
4147
}
4248

4349
inner class ViewHolder(private val binding: ItemAllowedAppBinding) :
@@ -52,11 +58,11 @@ class BubbleAllowedAppsAdapter(
5258

5359
// Calculate time remaining
5460
val now = System.currentTimeMillis()
55-
val expiresAt = app.allowedAt + (15 * 60 * 1000) // 15 minutes
56-
val remaining = (expiresAt - now) / 1000 / 60 // minutes
61+
val expiresAt = app.allowedAt + (ALLOWED_DURATION_MINUTES * MILLIS_PER_MINUTE * MILLIS_PER_SECOND) // 15 minutes
62+
val remaining = (expiresAt - now) / MILLIS_PER_SECOND / MILLIS_PER_MINUTE // minutes
5763

5864
binding.allowedTimeRemaining.text = if (remaining > 0) {
59-
"$remaining min${if (remaining != 1L) "s" else ""} remaining"
65+
"$remaining min${if (remaining != SINGLE_MINUTE) "s" else ""} remaining"
6066
} else {
6167
"Expired"
6268
}

app/src/full/java/com/celzero/bravedns/adapter/ConnectionTrackerAdapter.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class ConnectionTrackerAdapter(private val context: Context) :
7676
private const val MAX_TIME_TCP = 135 // seconds
7777
private const val MAX_TIME_UDP = 135 // seconds
7878
private const val NO_USER_ID = 0
79+
private const val RTT_SHORT_THRESHOLD_MS = 20 // milliseconds
7980
private const val TAG = "ConnTrackAdapter"
8081
}
8182

@@ -393,7 +394,7 @@ class ConnectionTrackerAdapter(private val context: Context) :
393394
}
394395

395396
private fun isRoundTripShorter(rtt: Long, blocked: Boolean): Boolean {
396-
return rtt in 1..20 && !blocked
397+
return rtt in 1..RTT_SHORT_THRESHOLD_MS && !blocked
397398
}
398399

399400
private fun containsRelayProxy(rpid: String): Boolean {

app/src/full/java/com/celzero/bravedns/adapter/DnsLogAdapter.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class DnsLogAdapter(val context: Context, val loadFavIcon: Boolean, val isRethin
5858

5959
companion object {
6060
private const val TAG = "DnsLogAdapter"
61+
private const val RTT_SHORT_THRESHOLD_MS = 10 // milliseconds
62+
6163
private val DIFF_CALLBACK =
6264
object : DiffUtil.ItemCallback<DnsLog>() {
6365

@@ -266,7 +268,7 @@ class DnsLogAdapter(val context: Context, val loadFavIcon: Boolean, val isRethin
266268
}
267269

268270
private fun isRoundTripShorter(rtt: Long, blocked: Boolean): Boolean {
269-
return rtt in 1..10 && !blocked
271+
return rtt in 1..RTT_SHORT_THRESHOLD_MS && !blocked
270272
}
271273

272274
private fun containsRelayProxy(rpid: String): Boolean {

app/src/full/java/com/celzero/bravedns/adapter/FirewallAppListAdapter.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class FirewallAppListAdapter(
6666
// private val userAppColor: Int by lazy { UIUtils.fetchColor(context, R.attr.primaryTextColor) }
6767

6868
companion object {
69+
private const val ALPHA_FULL = 1f
70+
private const val ALPHA_DISABLED = 0.4f
71+
6972
private val DIFF_CALLBACK =
7073
object : DiffUtil.ItemCallback<AppInfo>() {
7174
override fun areItemsTheSame(
@@ -128,11 +131,11 @@ class FirewallAppListAdapter(
128131
getIcon(context, appInfo.packageName, appInfo.appName), b.firewallAppIconIv)
129132
// set the alpha based on internet permission
130133
if (appInfo.hasInternetPermission(packageManager)) {
131-
b.firewallAppLabelTv.alpha = 1f
132-
b.firewallAppIconIv.alpha = 1f
134+
b.firewallAppLabelTv.alpha = ALPHA_FULL
135+
b.firewallAppIconIv.alpha = ALPHA_FULL
133136
} else {
134-
b.firewallAppLabelTv.alpha = 0.4f
135-
b.firewallAppIconIv.alpha = 0.4f
137+
b.firewallAppLabelTv.alpha = ALPHA_DISABLED
138+
b.firewallAppIconIv.alpha = ALPHA_DISABLED
136139
}
137140
if (appInfo.packageName == context.packageName) {
138141
b.firewallAppToggleWifi.visibility = View.GONE
@@ -147,8 +150,8 @@ class FirewallAppListAdapter(
147150
// strike through the app name if the app is tombstoned
148151
if (appInfo.tombstoneTs > 0) {
149152
b.firewallAppLabelTv.paint.isStrikeThruText = true
150-
b.firewallAppLabelTv.alpha = 0.4f
151-
b.firewallAppIconIv.alpha = 0.4f
153+
b.firewallAppLabelTv.alpha = ALPHA_DISABLED
154+
b.firewallAppIconIv.alpha = ALPHA_DISABLED
152155
} else {
153156
b.firewallAppLabelTv.paint.isStrikeThruText = false
154157
}
@@ -496,7 +499,7 @@ class FirewallAppListAdapter(
496499

497500
override fun getSectionName(position: Int): String {
498501
// Check if position is valid to prevent IndexOutOfBoundsException
499-
if (position < 0 || position >= itemCount) {
502+
if (position !in 0..<itemCount) {
500503
return ""
501504
}
502505

app/src/full/java/com/celzero/bravedns/adapter/RethinkLogAdapter.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class RethinkLogAdapter(private val context: Context) :
7373
private const val MAX_BYTES = 500000 // 500 KB
7474
private const val MAX_TIME_TCP = 135 // seconds
7575
private const val MAX_TIME_UDP = 135 // seconds
76+
private const val RTT_SHORT_THRESHOLD_MS = 20 // milliseconds
7677

7778
const val DNS_IP_TEMPLATE_V4 = "10.111.222.3"
7879
const val DNS_IP_TEMPLATE_V6 = "fd66:f83a:c650::3"
@@ -370,7 +371,7 @@ class RethinkLogAdapter(private val context: Context) :
370371
}
371372

372373
private fun isRoundTripShorter(rtt: Long, blocked: Boolean): Boolean {
373-
return rtt in 1..20 && !blocked
374+
return rtt in 1..RTT_SHORT_THRESHOLD_MS && !blocked
374375
}
375376

376377
private fun containsRelayProxy(rpid: String): Boolean {

app/src/full/java/com/celzero/bravedns/adapter/SummaryStatisticsAdapter.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class SummaryStatisticsAdapter(
7474
private var timeCategory = SummaryStatisticsViewModel.TimeCategory.ONE_HOUR
7575

7676
companion object {
77+
private const val PERCENTAGE_MULTIPLIER = 100
78+
7779
private val DIFF_CALLBACK =
7880
object : DiffUtil.ItemCallback<AppConnection>() {
7981
// Fix: Compare by unique identifiers instead of object equality
@@ -123,15 +125,15 @@ class SummaryStatisticsAdapter(
123125
}
124126

125127
private fun calculatePercentage(c: Double): Int {
126-
val value = (log2(c) * 100).toInt()
128+
val value = (log2(c) * PERCENTAGE_MULTIPLIER).toInt()
127129
// maxValue will be based on the count returned by the database query (order by count desc)
128130
if (value > maxValue) {
129131
maxValue = value
130132
}
131133
return if (maxValue == 0) {
132134
0
133135
} else {
134-
(value * 100 / maxValue)
136+
(value * PERCENTAGE_MULTIPLIER / maxValue)
135137
}
136138
}
137139

app/src/full/java/com/celzero/bravedns/adapter/WgHopAdapter.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class WgHopAdapter(
4949

5050
companion object {
5151
private const val TAG = "HopAdapter"
52+
private const val HOP_TEST_DELAY_MS = 2000L // 2 seconds
5253
}
5354

5455
private var isAttached = false
@@ -310,7 +311,7 @@ class WgHopAdapter(
310311
}
311312
}
312313
}
313-
delay(2000)
314+
delay(HOP_TEST_DELAY_MS)
314315
if (isChecked) {
315316
val hopTestRes = VpnController.testHop(src, hop)
316317
if (!hopTestRes.first) {

app/src/full/java/com/celzero/bravedns/adapter/WgIncludeAppsAdapter.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class WgIncludeAppsAdapter(
5858
private val packageManager: PackageManager = context.packageManager
5959

6060
companion object {
61+
private const val ALPHA_FULL = 1f
62+
private const val ALPHA_DISABLED = 0.4f
6163

6264
private val DIFF_CALLBACK =
6365
object : DiffUtil.ItemCallback<ProxyApplicationMapping>() {
@@ -173,11 +175,11 @@ class WgIncludeAppsAdapter(
173175
displayIcon(iconDrawable)
174176
// set the alpha based on internet permission
175177
if (hasInternetPerm) {
176-
b.wgIncludeAppListApkLabelTv.alpha = 1f
177-
b.wgIncludeAppListApkIconIv.alpha = 1f
178+
b.wgIncludeAppListApkLabelTv.alpha = ALPHA_FULL
179+
b.wgIncludeAppListApkIconIv.alpha = ALPHA_FULL
178180
} else {
179-
b.wgIncludeAppListApkLabelTv.alpha = 0.4f
180-
b.wgIncludeAppListApkIconIv.alpha = 0.4f
181+
b.wgIncludeAppListApkLabelTv.alpha = ALPHA_DISABLED
182+
b.wgIncludeAppListApkIconIv.alpha = ALPHA_DISABLED
181183
}
182184
setupClickListeners(mapping, isIncluded)
183185
}

0 commit comments

Comments
 (0)