Skip to content

Commit

Permalink
Merge pull request #1600 from RohitSurwase/main
Browse files Browse the repository at this point in the history
Set text color of app name based on its type - system, user or no-internet.
  • Loading branch information
hussainmohd-a authored Jul 16, 2024
2 parents 3d393ea + d4af5a0 commit e6fbe9a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ package com.celzero.bravedns.adapter
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -40,6 +42,7 @@ import com.celzero.bravedns.service.FirewallManager
import com.celzero.bravedns.service.FirewallManager.updateFirewallStatus
import com.celzero.bravedns.ui.activity.AppInfoActivity
import com.celzero.bravedns.ui.activity.AppInfoActivity.Companion.UID_INTENT_NAME
import com.celzero.bravedns.util.UIUtils
import com.celzero.bravedns.util.Utilities
import com.celzero.bravedns.util.Utilities.getIcon
import com.google.android.material.dialog.MaterialAlertDialogBuilder
Expand All @@ -53,6 +56,10 @@ class FirewallAppListAdapter(
private val lifecycleOwner: LifecycleOwner
) : PagingDataAdapter<AppInfo, FirewallAppListAdapter.AppListViewHolder>(DIFF_CALLBACK) {

private val packageManager: PackageManager = context.packageManager
private val systemAppColor: Int by lazy { UIUtils.fetchColor(context, R.attr.textColorAccentBad) }
private val userAppColor: Int by lazy { UIUtils.fetchColor(context, R.attr.primaryTextColor) }

companion object {
private val DIFF_CALLBACK =
object : DiffUtil.ItemCallback<AppInfo>() {
Expand Down Expand Up @@ -99,6 +106,16 @@ class FirewallAppListAdapter(
val connStatus = FirewallManager.connectionStatus(appInfo.uid)
uiCtx {
b.firewallAppLabelTv.text = appInfo.appName
if (appInfo.isSystemApp) {
b.firewallAppLabelTv.setTextColor(systemAppColor)
} else {
b.firewallAppLabelTv.setTextColor(userAppColor)
}
if (appInfo.hasInternetPermission(packageManager)) {
b.firewallAppLabelTv.alpha = 1f
} else {
b.firewallAppLabelTv.alpha = 0.6f
}
b.firewallAppToggleOther.text = getFirewallText(appStatus, connStatus)
displayIcon(
getIcon(context, appInfo.packageName, appInfo.appName),
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/celzero/bravedns/database/AppInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package com.celzero.bravedns.database

import android.Manifest
import android.content.ContentValues
import android.content.pm.PackageManager
import androidx.room.Entity
import com.celzero.bravedns.service.FirewallManager

Expand Down Expand Up @@ -95,4 +97,9 @@ class AppInfo {
this.screenOffAllowed = screenOffAllowed
this.backgroundAllowed = backgroundAllowed
}

fun hasInternetPermission(packageManager: PackageManager): Boolean {
// INTERNET permission if defined, can not be denied so this is safe to use
return packageManager.checkPermission(Manifest.permission.INTERNET, packageName) == PackageManager.PERMISSION_GRANTED
}
}

0 comments on commit e6fbe9a

Please sign in to comment.