From b7000aa58b3fb9f157ddf6f77f5c2d6a5faed72f Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 17 Jun 2021 15:20:19 +1000 Subject: [PATCH] Tweak UI --- .../conversation/v2/ConversationActivityV2.kt | 2 +- .../conversation/v2/input_bar/InputBarButton.kt | 7 +++++-- .../v2/input_bar/InputBarRecordingView.kt | 17 +++++++++++++++++ .../res/layout/view_input_bar_recording.xml | 1 + 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index a8d853a76f..3892d444ad 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -72,7 +72,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe private val screenWidth by lazy { Resources.getSystem().displayMetrics.widthPixels } - private val gifButton by lazy { InputBarButton(this, R.drawable.ic_gif_white_24dp, hasOpaqueBackground = true) } + private val gifButton by lazy { InputBarButton(this, R.drawable.ic_gif_white_24dp, hasOpaqueBackground = true, isGIFButton = true) } private val documentButton by lazy { InputBarButton(this, R.drawable.ic_document_small_dark, hasOpaqueBackground = true) } private val libraryButton by lazy { InputBarButton(this, R.drawable.ic_baseline_photo_library_24, hasOpaqueBackground = true) } private val cameraButton by lazy { InputBarButton(this, R.drawable.ic_baseline_photo_camera_24, hasOpaqueBackground = true) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarButton.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarButton.kt index bcb753b416..7a76efc473 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarButton.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarButton.kt @@ -28,6 +28,7 @@ class InputBarButton : RelativeLayout { private val gestureHandler = Handler(Looper.getMainLooper()) private var isSendButton = false private var hasOpaqueBackground = false + private var isGIFButton = false @DrawableRes private var iconID = 0 private var longPressCallback: Runnable? = null private var onDownTimestamp = 0L @@ -71,7 +72,7 @@ class InputBarButton : RelativeLayout { private val imageView by lazy { val result = ImageView(context) - val size = toPx(16, resources) + val size = if (isGIFButton) toPx(24, resources) else toPx(16, resources) result.layoutParams = LayoutParams(size, size) result.scaleType = ImageView.ScaleType.CENTER_INSIDE result.setImageResource(iconID) @@ -84,10 +85,12 @@ class InputBarButton : RelativeLayout { constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { throw IllegalAccessException("Use InputBarButton(context:iconID:) instead.") } constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { throw IllegalAccessException("Use InputBarButton(context:iconID:) instead.") } - constructor(context: Context, @DrawableRes iconID: Int, isSendButton: Boolean = false, hasOpaqueBackground: Boolean = false) : super(context) { + constructor(context: Context, @DrawableRes iconID: Int, isSendButton: Boolean = false, + hasOpaqueBackground: Boolean = false, isGIFButton: Boolean = false) : super(context) { this.isSendButton = isSendButton this.iconID = iconID this.hasOpaqueBackground = hasOpaqueBackground + this.isGIFButton = isGIFButton val size = resources.getDimension(R.dimen.input_bar_button_expanded_size).toInt() val layoutParams = LayoutParams(size, size) this.layoutParams = layoutParams diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarRecordingView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarRecordingView.kt index 371bac3ae3..bf830992bb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarRecordingView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarRecordingView.kt @@ -4,7 +4,10 @@ import android.animation.FloatEvaluator import android.animation.IntEvaluator import android.animation.ValueAnimator import android.content.Context +import android.os.Handler +import android.os.Looper import android.util.AttributeSet +import android.util.Log import android.view.LayoutInflater import android.widget.RelativeLayout import androidx.core.content.res.ResourcesCompat @@ -14,8 +17,13 @@ import network.loki.messenger.R import org.thoughtcrime.securesms.loki.utilities.animateSizeChange import org.thoughtcrime.securesms.loki.utilities.disableClipping import org.thoughtcrime.securesms.loki.utilities.toPx +import org.thoughtcrime.securesms.util.DateUtils +import java.util.* +import kotlin.math.roundToLong class InputBarRecordingView : RelativeLayout { + private var startTimestamp = 0L + private val snHandler = Handler(Looper.getMainLooper()) constructor(context: Context) : super(context) { initialize() } constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { initialize() } @@ -27,6 +35,7 @@ class InputBarRecordingView : RelativeLayout { } fun show() { + startTimestamp = Date().time isVisible = true alpha = 0.0f val animation = ValueAnimator.ofObject(FloatEvaluator(), 0.0f, 1.0f) @@ -38,6 +47,7 @@ class InputBarRecordingView : RelativeLayout { animateDotView() pulse() animateLockViewUp() + updateTimer() } private fun animateDotView() { @@ -79,6 +89,13 @@ class InputBarRecordingView : RelativeLayout { animation.start() } + private fun updateTimer() { + Log.d("Test", "${Date().time - startTimestamp}") + val duration = (Date().time - startTimestamp) / 1000L + recordingViewDurationTextView.text = DateUtils.formatElapsedTime(duration) + snHandler.postDelayed({ updateTimer() }, 500) + } + fun lock() { val fadeOutAnimation = ValueAnimator.ofObject(FloatEvaluator(), 1.0f, 0.0f) fadeOutAnimation.duration = 250L diff --git a/app/src/main/res/layout/view_input_bar_recording.xml b/app/src/main/res/layout/view_input_bar_recording.xml index f36b6ab734..7a6d86cb26 100644 --- a/app/src/main/res/layout/view_input_bar_recording.xml +++ b/app/src/main/res/layout/view_input_bar_recording.xml @@ -38,6 +38,7 @@ android:backgroundTint="@color/destructive" />