diff options
author | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2023-12-05 08:17:03 +0000 |
---|---|---|
committer | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2023-12-05 08:17:03 +0000 |
commit | 2234842a2bf5f17b6654a66347f6d3692cf1e443 (patch) | |
tree | 8f72170bee6247db6743521675d0ac0822b2ef65 /app/src/main/java/foundation/e/advancedprivacy/common | |
parent | 0db4d25038823369f320e0cd291968e66ed51e0c (diff) | |
parent | 2e897cc8af4234abc4e3f5c3448e1fd7b2b8a1bd (diff) | |
download | advanced-privacy-2234842a2bf5f17b6654a66347f6d3692cf1e443.tar.gz |
Merge branch '1203-trackers_oriented_view' into 'main'
1203 trackers oriented view
See merge request e/os/advanced-privacy!151
Diffstat (limited to 'app/src/main/java/foundation/e/advancedprivacy/common')
-rw-r--r-- | app/src/main/java/foundation/e/advancedprivacy/common/AppsAdapter.kt | 71 | ||||
-rw-r--r-- | app/src/main/java/foundation/e/advancedprivacy/common/extensions/ViewPager2Extensions.kt | 43 |
2 files changed, 43 insertions, 71 deletions
diff --git a/app/src/main/java/foundation/e/advancedprivacy/common/AppsAdapter.kt b/app/src/main/java/foundation/e/advancedprivacy/common/AppsAdapter.kt deleted file mode 100644 index aee1890..0000000 --- a/app/src/main/java/foundation/e/advancedprivacy/common/AppsAdapter.kt +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2021 E FOUNDATION, 2022 - 2023 MURENA SAS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ - -package foundation.e.advancedprivacy.common - -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.ImageView -import android.widget.TextView -import androidx.recyclerview.widget.RecyclerView -import foundation.e.advancedprivacy.R -import foundation.e.advancedprivacy.domain.entities.AppWithCounts - -class AppsAdapter( - private val itemsLayout: Int, - private val listener: (Int) -> Unit -) : - RecyclerView.Adapter<AppsAdapter.ViewHolder>() { - - class ViewHolder(view: View, private val listener: (Int) -> 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) - fun bind(item: AppWithCounts) { - appName.text = item.label - counts.text = if (item.trackersCount > 0) itemView.context.getString( - R.string.trackers_app_trackers_counts, - item.blockedTrackersCount, - item.trackersCount, - item.leaks - ) else "" - icon.setImageDrawable(item.icon) - - itemView.setOnClickListener { listener(item.uid) } - } - } - - var dataSet: List<AppWithCounts> = emptyList() - set(value) { - field = value - notifyDataSetChanged() - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - val view = LayoutInflater.from(parent.context) - .inflate(itemsLayout, parent, false) - return ViewHolder(view, listener) - } - - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val app = dataSet[position] - holder.bind(app) - } - - override fun getItemCount(): Int = dataSet.size -} diff --git a/app/src/main/java/foundation/e/advancedprivacy/common/extensions/ViewPager2Extensions.kt b/app/src/main/java/foundation/e/advancedprivacy/common/extensions/ViewPager2Extensions.kt new file mode 100644 index 0000000..e17d692 --- /dev/null +++ b/app/src/main/java/foundation/e/advancedprivacy/common/extensions/ViewPager2Extensions.kt @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2023 MURENA SAS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ +package foundation.e.advancedprivacy.common.extensions + +import android.view.View +import androidx.recyclerview.widget.RecyclerView +import androidx.viewpager2.widget.ViewPager2 + +fun ViewPager2.findViewHolderForAdapterPosition(position: Int): RecyclerView.ViewHolder? { + return (getChildAt(0) as RecyclerView).findViewHolderForAdapterPosition(position) +} + +fun ViewPager2.updatePagerHeightForChild(itemView: View) { + itemView.post { + val wMeasureSpec = + View.MeasureSpec.makeMeasureSpec(itemView.width, View.MeasureSpec.EXACTLY) + val hMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED) + itemView.measure(wMeasureSpec, hMeasureSpec) + + if (layoutParams.height != itemView.measuredHeight) { + layoutParams = (layoutParams) + .also { lp -> + // applying Fragment Root View Height to + // the pager LayoutParams, so they match + lp.height = itemView.measuredHeight + } + } + } +} |