Skip to content

Commit

Permalink
Finished refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kon3gor committed Apr 1, 2023
1 parent 87f14b2 commit 3408ec0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class NodesAdapter (
&& oldItem.foregroundColor == newItem.foregroundColor
&& oldItem.getOtpElement() == newItem.getOtpElement()
&& oldItem.containsAttachment() == newItem.containsAttachment()
&& oldItem.tags == newItem.tags
} else if (oldItem is Group && newItem is Group) {
typeContentTheSame = oldItem.numberOfChildEntries == newItem.numberOfChildEntries
&& oldItem.notes == newItem.notes
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/kunzisoft/keepass/database/element/Tags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ class Tags: Parcelable {
return mTags.joinToString(DELIMITER.toString())
}

override fun equals(other: Any?): Boolean {
return when (other) {
!is Tags -> false
else -> mTags == other.toList()
}
}

override fun hashCode(): Int {
return mTags.hashCode()
}

companion object CREATOR : Parcelable.Creator<Tags> {
const val DELIMITER= ','
const val DELIMITER1= ';'
Expand Down
31 changes: 17 additions & 14 deletions app/src/main/java/com/kunzisoft/keepass/view/TagsListView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class TagsListView @JvmOverloads constructor(
return
}
field = value
expandBtn?.setColorFilter(value!!)
}
var bgColor: Int? = null
set(value) {
Expand All @@ -49,17 +50,17 @@ class TagsListView @JvmOverloads constructor(
drawAllTagsAndMeasure()
}

init {
inflate(context, R.layout.tags_list_view, this)
initialize()
}

private var flow: Flow? = null
private var expandBtn: View? = null
private var expandBtn: AppCompatImageView? = null
private var hiddenViews: MutableList<View> = mutableListOf()
private var currentState: State = State.IDLE
private var animationHelper: AnimationHelper? = null

init {
inflate(context, R.layout.tags_list_view, this)
initialize()
}

private fun initialize() {
viewTreeObserver.addOnGlobalLayoutListener(InitialMeasuringObserver())
flow = findViewById(R.id.flow)
Expand Down Expand Up @@ -120,8 +121,10 @@ class TagsListView @JvmOverloads constructor(
}
hiddenViews[ind].animate().setListener(object : StubAnimatorListener() {
override fun onAnimationEnd(p0: Animator?) {
if (isGone) return
hiddenViews[ind].isGone = !isGone
if (!isGone) {
hiddenViews[ind].isGone = !isGone
}
requestLayout()
}
}).alpha(alpha).start()
}
Expand Down Expand Up @@ -182,10 +185,8 @@ class TagsListView @JvmOverloads constructor(
when (currentState) {
State.MEASURING_EXPANDED -> {
expandedHeight = measuredHeight
post {
currentState = currentState.next()
toggleHiddenViews(false)
}
currentState = currentState.next()
toggleHiddenViews(false)
}
State.MEASURING_COLLAPSED -> {
currentState = currentState.next()
Expand Down Expand Up @@ -224,6 +225,8 @@ class TagsListView @JvmOverloads constructor(

private val VERTICAL_PADDING = 2.dp.intPx
private val HORIZONTAL_PADDING = 5.dp.intPx
private const val TAG_TEXT_SIZE = 13f
private val TAG_STROKE = 1.2f.dp.intPx

private fun TagsListView.createTagView(tag: String): View {
val view = AppCompatTextView(context)
Expand Down Expand Up @@ -251,7 +254,7 @@ private fun TagsListView.styleTagView(view: AppCompatTextView): View {
}

view.setPadding(HORIZONTAL_PADDING, VERTICAL_PADDING, HORIZONTAL_PADDING, VERTICAL_PADDING)
view.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13f)
view.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAG_TEXT_SIZE)

return view
}
Expand All @@ -263,7 +266,7 @@ private fun TagsListView.createTagBg(): Drawable? {
) as? GradientDrawable

bgColor?.let {
bg?.setStroke(1.2f.dp.intPx, it)
bg?.setStroke(TAG_STROKE, it)
}

return bg
Expand Down

0 comments on commit 3408ec0

Please sign in to comment.