kopia lustrzana https://github.com/ryukoposting/Signal-Android
Allow separate specification of status and toolbar active/inactive coloring.
rodzic
e6cc49368e
commit
6854632fec
|
@ -82,6 +82,7 @@ import org.thoughtcrime.securesms.util.CommunicationActions
|
||||||
import org.thoughtcrime.securesms.util.ContextUtil
|
import org.thoughtcrime.securesms.util.ContextUtil
|
||||||
import org.thoughtcrime.securesms.util.ExpirationUtil
|
import org.thoughtcrime.securesms.util.ExpirationUtil
|
||||||
import org.thoughtcrime.securesms.util.FeatureFlags
|
import org.thoughtcrime.securesms.util.FeatureFlags
|
||||||
|
import org.thoughtcrime.securesms.util.Material3OnScrollHelper
|
||||||
import org.thoughtcrime.securesms.util.ViewUtil
|
import org.thoughtcrime.securesms.util.ViewUtil
|
||||||
import org.thoughtcrime.securesms.util.navigation.safeNavigate
|
import org.thoughtcrime.securesms.util.navigation.safeNavigate
|
||||||
import org.thoughtcrime.securesms.util.views.SimpleProgressDialog
|
import org.thoughtcrime.securesms.util.views.SimpleProgressDialog
|
||||||
|
@ -191,6 +192,15 @@ class ConversationSettingsFragment : DSLSettingsFragment(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getMaterial3OnScrollHelper(toolbar: Toolbar?): Material3OnScrollHelper {
|
||||||
|
return object : Material3OnScrollHelper(requireActivity(), toolbar!!) {
|
||||||
|
override val inactiveColorSet = ColorSet(
|
||||||
|
toolbarColorRes = R.color.transparent,
|
||||||
|
statusBarColorRes = R.color.signal_colorBackground
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun bindAdapter(adapter: DSLSettingsAdapter) {
|
override fun bindAdapter(adapter: DSLSettingsAdapter) {
|
||||||
val args = ConversationSettingsFragmentArgs.fromBundle(requireArguments())
|
val args = ConversationSettingsFragmentArgs.fromBundle(requireArguments())
|
||||||
|
|
||||||
|
|
|
@ -2223,13 +2223,13 @@ public class ConversationParentFragment extends Fragment
|
||||||
|
|
||||||
material3OnScrollHelper = new Material3OnScrollHelper(requireActivity(), Collections.singletonList(toolbarBackground), Collections.emptyList()) {
|
material3OnScrollHelper = new Material3OnScrollHelper(requireActivity(), Collections.singletonList(toolbarBackground), Collections.emptyList()) {
|
||||||
@Override
|
@Override
|
||||||
public int getActiveColorRes() {
|
public @NonNull ColorSet getActiveColorSet() {
|
||||||
return getActiveToolbarColor(wallpaper.getDrawable() != null);
|
return new ColorSet(getActiveToolbarColor(wallpaper.getDrawable() != null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInactiveColorRes() {
|
public @NonNull ColorSet getInactiveColorSet() {
|
||||||
return getInactiveToolbarColor(wallpaper.getDrawable() != null);
|
return new ColorSet(getInactiveToolbarColor(wallpaper.getDrawable() != null));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.animation.ValueAnimator
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
|
import androidx.annotation.ColorRes
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.animation.ArgbEvaluatorCompat
|
import com.google.android.material.animation.ArgbEvaluatorCompat
|
||||||
|
@ -21,8 +22,18 @@ open class Material3OnScrollHelper(
|
||||||
private val viewStubs: List<Stub<out View>> = emptyList()
|
private val viewStubs: List<Stub<out View>> = emptyList()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
open val activeColorRes: Int = R.color.signal_colorSurface2
|
/**
|
||||||
open val inactiveColorRes: Int = R.color.signal_colorBackground
|
* 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
open val activeColorSet: ColorSet = ColorSet(R.color.signal_colorSurface2)
|
||||||
|
open val inactiveColorSet: ColorSet = ColorSet(R.color.signal_colorBackground)
|
||||||
|
|
||||||
constructor(activity: Activity, view: View) : this(activity, listOf(view), emptyList())
|
constructor(activity: Activity, view: View) : this(activity, listOf(view), emptyList())
|
||||||
|
|
||||||
|
@ -44,7 +55,9 @@ open class Material3OnScrollHelper(
|
||||||
}
|
}
|
||||||
|
|
||||||
animator?.cancel()
|
animator?.cancel()
|
||||||
setColor(ContextCompat.getColor(activity, if (active == true) activeColorRes else inactiveColorRes))
|
val colorSet = if (active == true) activeColorSet else inactiveColorSet
|
||||||
|
setToolbarColor(ContextCompat.getColor(activity, colorSet.toolbarColorRes))
|
||||||
|
setStatusBarColor(ContextCompat.getColor(activity, colorSet.statusBarColorRes))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateActiveState(isActive: Boolean) {
|
private fun updateActiveState(isActive: Boolean) {
|
||||||
|
@ -61,29 +74,39 @@ open class Material3OnScrollHelper(
|
||||||
if (animator?.isRunning == true) {
|
if (animator?.isRunning == true) {
|
||||||
animator?.reverse()
|
animator?.reverse()
|
||||||
} else {
|
} else {
|
||||||
val startColor = ContextCompat.getColor(activity, if (isActive) inactiveColorRes else activeColorRes)
|
val startColorSet = if (isActive) inactiveColorSet else activeColorSet
|
||||||
val endColor = ContextCompat.getColor(activity, if (isActive) activeColorRes else inactiveColorRes)
|
val endColorSet = if (isActive) activeColorSet else inactiveColorSet
|
||||||
|
|
||||||
if (hadActiveState) {
|
if (hadActiveState) {
|
||||||
animator = ValueAnimator.ofObject(ArgbEvaluatorCompat(), startColor, endColor).apply {
|
val startToolbarColor = ContextCompat.getColor(activity, startColorSet.toolbarColorRes)
|
||||||
|
val endToolbarColor = ContextCompat.getColor(activity, endColorSet.toolbarColorRes)
|
||||||
|
val startStatusBarColor = ContextCompat.getColor(activity, startColorSet.statusBarColorRes)
|
||||||
|
val endStatusBarColor = ContextCompat.getColor(activity, endColorSet.statusBarColorRes)
|
||||||
|
|
||||||
|
animator = ValueAnimator.ofFloat(0f, 1f).apply {
|
||||||
duration = 200
|
duration = 200
|
||||||
addUpdateListener { animator ->
|
addUpdateListener {
|
||||||
setColor(animator.animatedValue as Int)
|
setToolbarColor(ArgbEvaluatorCompat.getInstance().evaluate(it.animatedFraction, startToolbarColor, endToolbarColor))
|
||||||
|
setStatusBarColor(ArgbEvaluatorCompat.getInstance().evaluate(it.animatedFraction, startStatusBarColor, endStatusBarColor))
|
||||||
}
|
}
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
setColorImmediate()
|
setColorImmediate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setColor(@ColorInt color: Int) {
|
private fun setToolbarColor(@ColorInt color: Int) {
|
||||||
WindowUtil.setStatusBarColor(activity.window, color)
|
|
||||||
views.forEach { it.setBackgroundColor(color) }
|
views.forEach { it.setBackgroundColor(color) }
|
||||||
viewStubs.filter { it.resolved() }.forEach { it.get().setBackgroundColor(color) }
|
viewStubs.filter { it.resolved() }.forEach { it.get().setBackgroundColor(color) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setStatusBarColor(@ColorInt color: Int) {
|
||||||
|
WindowUtil.setStatusBarColor(activity.window, color)
|
||||||
|
}
|
||||||
|
|
||||||
private inner class OnScrollListener : RecyclerView.OnScrollListener() {
|
private inner class OnScrollListener : RecyclerView.OnScrollListener() {
|
||||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||||
updateActiveState(recyclerView.canScrollVertically(-1))
|
updateActiveState(recyclerView.canScrollVertically(-1))
|
||||||
|
|
Ładowanie…
Reference in New Issue