Fixes for CFv2.

- Status bar color being incorrect when entering a screen that changes it and then returning (e.g., Message Details)
- Fix crash in enter sends mode
- Fix warning about non-closed cursor
- Prevent message abandonment (via trim thread) when it's the first in an inactive thread
- Fix payment attachment button flashing on attachment keyboard open if payments disabled
- Fix reactionDelegate crash
- Fix attachment preview (file, mp3, location, etc) not getting cleared on send
This commit is contained in:
Cody Henthorne
2023-07-20 13:50:32 -04:00
committed by GitHub
parent 744f74b498
commit ec25831a37
21 changed files with 128 additions and 56 deletions

View File

@@ -8,6 +8,8 @@ import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat
import androidx.core.widget.NestedScrollView
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.animation.ArgbEvaluatorCompat
import com.google.android.material.appbar.AppBarLayout
@@ -22,32 +24,40 @@ import org.thoughtcrime.securesms.util.views.Stub
open class Material3OnScrollHelper(
private val context: Context,
private val setStatusBarColor: (Int) -> Unit,
private val getStatusBarColor: () -> Int,
private val views: List<View>,
private val viewStubs: List<Stub<out View>> = emptyList()
private val viewStubs: List<Stub<out View>> = emptyList(),
lifecycleOwner: LifecycleOwner
) {
constructor(activity: Activity, views: List<View>, viewStubs: List<Stub<out View>>) : this(activity, { WindowUtil.setStatusBarColor(activity.window, it) }, views, viewStubs)
constructor(activity: Activity, view: View, lifecycleOwner: LifecycleOwner) : this(activity = activity, views = listOf(view), lifecycleOwner = lifecycleOwner)
constructor(activity: Activity, views: List<View>) : this(activity, { WindowUtil.setStatusBarColor(activity.window, it) }, views, emptyList())
constructor(activity: Activity, view: View) : this(activity, { WindowUtil.setStatusBarColor(activity.window, it) }, listOf(view), emptyList())
/**
* A pair of colors tied to a specific state.
*/
data class ColorSet(
@ColorRes val toolbarColorRes: Int,
@ColorRes val statusBarColorRes: Int
) {
constructor(@ColorRes color: Int) : this(color, color)
}
constructor(activity: Activity, views: List<View>, viewStubs: List<Stub<out View>> = emptyList(), lifecycleOwner: LifecycleOwner) : this(
context = activity,
setStatusBarColor = { WindowUtil.setStatusBarColor(activity.window, it) },
getStatusBarColor = { WindowUtil.getStatusBarColor(activity.window) },
views = views,
viewStubs = viewStubs,
lifecycleOwner = lifecycleOwner
)
open val activeColorSet: ColorSet = ColorSet(R.color.signal_colorSurface2)
open val inactiveColorSet: ColorSet = ColorSet(R.color.signal_colorBackground)
protected var previousStatusBarColor: Int = getStatusBarColor()
private var animator: ValueAnimator? = null
private var active: Boolean? = null
init {
lifecycleOwner.lifecycle.addObserver(object : DefaultLifecycleObserver {
override fun onDestroy(owner: LifecycleOwner) {
animator?.cancel()
setStatusBarColor(previousStatusBarColor)
}
})
}
fun attach(nestedScrollView: NestedScrollView) {
nestedScrollView.setOnScrollChangeListener(
OnScrollListener().apply {
@@ -141,4 +151,14 @@ open class Material3OnScrollHelper(
updateActiveState(v.canScrollVertically(-1))
}
}
/**
* A pair of colors tied to a specific state.
*/
data class ColorSet(
@ColorRes val toolbarColorRes: Int,
@ColorRes val statusBarColorRes: Int
) {
constructor(@ColorRes color: Int) : this(color, color)
}
}

View File

@@ -82,6 +82,10 @@ public final class WindowUtil {
window.setStatusBarColor(color);
}
public static int getStatusBarColor(@NonNull Window window) {
return window.getStatusBarColor();
}
/**
* A sort of roundabout way of determining if the status bar is present by seeing if there's a
* vertical window offset.