rewrite threads with Kotlin & coroutines (#2617)

* initial class setup

* handle events and filters

* handle status state changes

* code formatting

* fix status filtering

* cleanup code a bit

* implement removeAllByAccountId

* move toolbar into fragment, implement menu

* error and load state handling

* fix pull to refresh

* implement reveal button

* use requireContext() instead of context!!

* jump to detailed status

* add ViewThreadViewModelTest

* fix ktlint

* small code improvements (thx charlag)

* add testcase for toggleRevealButton

* add more state change testcases to ViewThreadViewModel
This commit is contained in:
Konrad Pozniak 2022-08-15 11:00:18 +02:00 committed by GitHub
commit 741461acde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 1446 additions and 999 deletions

View file

@ -1,72 +0,0 @@
/* Copyright 2017 Andrew Dawson
*
* This file is a part of Tusky.
*
* 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.
*
* Tusky 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 Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.drawable.Drawable
import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.adapter.ThreadAdapter
class ConversationLineItemDecoration(private val context: Context) : RecyclerView.ItemDecoration() {
private val divider: Drawable = ContextCompat.getDrawable(context, R.drawable.conversation_thread_line)!!
override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {
val dividerStart = parent.paddingStart + context.resources.getDimensionPixelSize(R.dimen.status_line_margin_start)
val dividerEnd = dividerStart + divider.intrinsicWidth
val childCount = parent.childCount
val avatarMargin = context.resources.getDimensionPixelSize(R.dimen.account_avatar_margin)
for (i in 0 until childCount) {
val child = parent.getChildAt(i)
val position = parent.getChildAdapterPosition(child)
val adapter = parent.adapter as ThreadAdapter
val current = adapter.getItem(position)
val dividerTop: Int
val dividerBottom: Int
if (current != null) {
val above = adapter.getItem(position - 1)
dividerTop = if (above != null && above.id == current.status.inReplyToId) {
child.top
} else {
child.top + avatarMargin
}
val below = adapter.getItem(position + 1)
dividerBottom = if (below != null && current.id == below.status.inReplyToId &&
adapter.detailedStatusPosition != position
) {
child.bottom
} else {
child.top + avatarMargin
}
if (parent.layoutDirection == View.LAYOUT_DIRECTION_LTR) {
divider.setBounds(dividerStart, dividerTop, dividerEnd, dividerBottom)
} else {
divider.setBounds(canvas.width - dividerEnd, dividerTop, canvas.width - dividerStart, dividerBottom)
}
divider.draw(canvas)
}
}
}
}