-
-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for select multiple request. #1130
base: main
Are you sure you want to change the base?
Changes from 11 commits
73437f8
6a9eb8d
abdb4c5
0850127
d80d386
d453d6d
7dad7ff
882d623
9e41073
5b58ed1
4a8ecdd
5ce5445
05427fe
d5461e4
c107409
137d8c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ package com.chuckerteam.chucker.internal.ui.transaction | |||||
import android.annotation.SuppressLint | ||||||
import android.content.Context | ||||||
import android.content.res.ColorStateList | ||||||
import android.util.TypedValue | ||||||
import android.view.LayoutInflater | ||||||
import android.view.ViewGroup | ||||||
import androidx.appcompat.content.res.AppCompatResources | ||||||
|
@@ -22,9 +23,13 @@ import javax.net.ssl.HttpsURLConnection | |||||
internal class TransactionAdapter internal constructor( | ||||||
context: Context, | ||||||
private val onTransactionClick: (Long) -> Unit, | ||||||
) : ListAdapter<HttpTransactionTuple, TransactionAdapter.TransactionViewHolder>( | ||||||
TransactionDiffCallback, | ||||||
private val longPress: (Long) -> Unit, | ||||||
) : ListAdapter< | ||||||
HttpTransactionTuple, | ||||||
TransactionAdapter.TransactionViewHolder>( | ||||||
TransactionDiffCallback | ||||||
) { | ||||||
private val selectedPos = mutableListOf<Int>() | ||||||
private val colorDefault: Int = ContextCompat.getColor(context, R.color.chucker_status_default) | ||||||
private val colorRequested: Int = | ||||||
ContextCompat.getColor( | ||||||
|
@@ -35,6 +40,22 @@ internal class TransactionAdapter internal constructor( | |||||
private val color500: Int = ContextCompat.getColor(context, R.color.chucker_status_500) | ||||||
private val color400: Int = ContextCompat.getColor(context, R.color.chucker_status_400) | ||||||
private val color300: Int = ContextCompat.getColor(context, R.color.chucker_status_300) | ||||||
val outValue = TypedValue() | ||||||
@Suppress("UnusedPrivateProperty") | ||||||
private val defaultColor = | ||||||
context.theme.resolveAttribute( | ||||||
android.R.attr.selectableItemBackground, | ||||||
outValue, | ||||||
true, | ||||||
) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. formatting is odd also here |
||||||
|
||||||
fun clearSelections() { | ||||||
val pos = selectedPos | ||||||
selectedPos.clear() | ||||||
pos.forEach { | ||||||
notifyItemRemoved(it) | ||||||
} | ||||||
} | ||||||
|
||||||
override fun onCreateViewHolder( | ||||||
parent: ViewGroup, | ||||||
|
@@ -63,14 +84,39 @@ internal class TransactionAdapter internal constructor( | |||||
itemView.setOnClickListener { | ||||||
transactionId?.let { | ||||||
onTransactionClick.invoke(it) | ||||||
if (selectedPos.isNotEmpty()) { | ||||||
if (selectedPos.contains(adapterPosition)) { | ||||||
selectedPos.remove(adapterPosition) | ||||||
} else { | ||||||
selectedPos.add(adapterPosition) | ||||||
} | ||||||
notifyItemChanged(adapterPosition) | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
itemView.setOnLongClickListener { | ||||||
transactionId?.let { | ||||||
longPress.invoke(it) | ||||||
if (selectedPos.contains(adapterPosition)) { | ||||||
selectedPos.remove(adapterPosition) | ||||||
} else { | ||||||
selectedPos.add(adapterPosition) | ||||||
} | ||||||
notifyItemChanged(adapterPosition) | ||||||
true | ||||||
} ?: kotlin.run { false } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
|
||||||
@SuppressLint("SetTextI18n") | ||||||
fun bind(transaction: HttpTransactionTuple) { | ||||||
transactionId = transaction.id | ||||||
|
||||||
if (selectedPos.find { it == adapterPosition } != null) { | ||||||
itemView.setBackgroundColor(color400) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not used this. <color name="chucker_status_highlighted">#FF9800</color> |
||||||
} else { | ||||||
itemView.setBackgroundResource(outValue.resourceId) | ||||||
} | ||||||
itemBinding.apply { | ||||||
displayGraphQlFields(transaction.graphQlOperationName, transaction.graphQlDetected) | ||||||
path.text = "${transaction.method} ${transaction.getFormattedPath(encode = false)}" | ||||||
|
@@ -134,6 +180,7 @@ private fun ChuckerListItemTransactionBinding.displayGraphQlFields( | |||||
graphqlPath.isVisible = graphQLDetected | ||||||
|
||||||
if (graphQLDetected) { | ||||||
graphqlPath.text = graphQlOperationName ?: root.resources.getString(R.string.chucker_graphql_operation_is_empty) | ||||||
graphqlPath.text = graphQlOperationName | ||||||
?: root.resources.getString(R.string.chucker_graphql_operation_is_empty) | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The formatting here is odd and is causing
ktlint
to fail