diff options
Diffstat (limited to 'app/src/main/java/foundation')
3 files changed, 22 insertions, 26 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/AppsAdapter.kt b/app/src/main/java/foundation/e/privacycentralapp/common/AppsAdapter.kt index 07cf125..ed47cff 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/common/AppsAdapter.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/common/AppsAdapter.kt @@ -32,7 +32,7 @@ class AppsAdapter( ) : RecyclerView.Adapter<AppsAdapter.ViewHolder>() { - class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + class ViewHolder(view: View, private val listener: (String) -> Unit) : RecyclerView.ViewHolder(view) { val appName: TextView = view.findViewById(R.id.title) val counts: TextView = view.findViewById(R.id.counts) val icon: ImageView = view.findViewById(R.id.icon) @@ -44,6 +44,8 @@ class AppsAdapter( item.trackersCount ) icon.setImageDrawable(item.icon) + + itemView.setOnClickListener { listener(item.packageName) } } } @@ -56,11 +58,7 @@ class AppsAdapter( override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val view = LayoutInflater.from(parent.context) .inflate(itemsLayout, parent, false) - val holder = ViewHolder(view) - holder.itemView.setOnClickListener { _ -> - listener(dataSet[holder.adapterPosition].packageName) - } - return holder + return ViewHolder(view, listener) } override fun onBindViewHolder(holder: ViewHolder, position: Int) { diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/ToggleAppsAdapter.kt b/app/src/main/java/foundation/e/privacycentralapp/common/ToggleAppsAdapter.kt index 9d62381..c41c0cf 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/common/ToggleAppsAdapter.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/common/ToggleAppsAdapter.kt @@ -33,7 +33,7 @@ class ToggleAppsAdapter( ) : RecyclerView.Adapter<ToggleAppsAdapter.ViewHolder>() { - class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + class ViewHolder(view: View, private val listener: (String) -> Unit) : RecyclerView.ViewHolder(view) { val appName: TextView = view.findViewById(R.id.title) val togglePermission: CheckBox = view.findViewById(R.id.toggle) @@ -44,6 +44,7 @@ class ToggleAppsAdapter( togglePermission.isEnabled = isEnabled itemView.findViewById<ImageView>(R.id.icon).setImageDrawable(item.first.icon) + togglePermission.setOnClickListener { listener(item.first.packageName) } } } @@ -63,11 +64,7 @@ class ToggleAppsAdapter( override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val view = LayoutInflater.from(parent.context) .inflate(itemsLayout, parent, false) - val holder = ViewHolder(view) - holder.togglePermission.setOnClickListener { - listener(dataSet[holder.adapterPosition].first.packageName) - } - return holder + return ViewHolder(view, listener) } override fun onBindViewHolder(holder: ViewHolder, position: Int) { diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/ToggleTrackersAdapter.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/ToggleTrackersAdapter.kt index 9ffdd12..b9beccf 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/ToggleTrackersAdapter.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/ToggleTrackersAdapter.kt @@ -38,7 +38,11 @@ class ToggleTrackersAdapter( var isEnabled = true - class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + class ViewHolder( + view: View, + private val onToggleSwitch: (Tracker, Boolean) -> Unit, + private val onClickTitle: (Tracker) -> Unit + ) : RecyclerView.ViewHolder(view) { val title: TextView = view.findViewById(R.id.title) val toggle: Switch = view.findViewById(R.id.toggle) @@ -59,6 +63,15 @@ class ToggleTrackersAdapter( toggle.isChecked = item.second toggle.isEnabled = isEnabled toggleOverlay.isVisible = !isEnabled + + toggle.setOnClickListener { + onToggleSwitch(item.first, toggle.isChecked) + } + toggleOverlay.setOnClickListener { + onToggleSwitch(item.first, false) + } + + title.setOnClickListener { onClickTitle(item.first) } } } @@ -73,19 +86,7 @@ class ToggleTrackersAdapter( override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val view = LayoutInflater.from(parent.context) .inflate(itemsLayout, parent, false) - val holder = ViewHolder(view) - holder.toggle.setOnClickListener { - onToggleSwitch(dataSet[holder.adapterPosition].first, holder.toggle.isChecked) - } - holder.toggleOverlay.setOnClickListener { - onToggleSwitch(dataSet[holder.adapterPosition].first, false) - } - - holder.title.setOnClickListener { - onClickTitle(dataSet[holder.adapterPosition].first) - } - - return holder + return ViewHolder(view, onToggleSwitch, onClickTitle) } override fun onBindViewHolder(holder: ViewHolder, position: Int) { |