From 5c4ef59c0b662ffff4528ff4762a9b2aec2752c3 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 21 Jun 2019 15:29:25 +1000 Subject: [PATCH] Fix UI issue --- .../securesms/loki/FriendRequestView.kt | 27 ++++++++++--------- .../securesms/loki/GeneralUtilities.kt | 6 +++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/org/thoughtcrime/securesms/loki/FriendRequestView.kt b/src/org/thoughtcrime/securesms/loki/FriendRequestView.kt index b5510941b5..9b4fc4cab5 100644 --- a/src/org/thoughtcrime/securesms/loki/FriendRequestView.kt +++ b/src/org/thoughtcrime/securesms/loki/FriendRequestView.kt @@ -9,7 +9,6 @@ import android.widget.LinearLayout import android.widget.TextView import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.sms.IncomingTextMessage -import org.thoughtcrime.securesms.sms.OutgoingTextMessage class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) { var message: Any? = null @@ -42,7 +41,6 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In private val buttonLinearLayout by lazy { val result = LinearLayout(context) result.orientation = HORIZONTAL - result.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, 50) result } // endregion @@ -56,9 +54,6 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In addView(topSpacer) addView(label) // if (kind == Kind.Incoming) { - // - val buttonLayoutParams = LayoutParams(0, 50) - buttonLayoutParams.weight = 1f // Accept button val acceptButton = Button(context) acceptButton.text = "Accept" @@ -70,7 +65,9 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In acceptButton.stateListAnimator = null } acceptButton.setOnClickListener { accept() } - acceptButton.layoutParams = buttonLayoutParams + val acceptButtonLayoutParams = LayoutParams(0, convertToPixels(50, resources)) + acceptButtonLayoutParams.weight = 1f + acceptButton.layoutParams = acceptButtonLayoutParams buttonLinearLayout.addView(acceptButton) // Reject button val rejectButton = Button(context) @@ -83,11 +80,15 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In rejectButton.stateListAnimator = null } rejectButton.setOnClickListener { reject() } - rejectButton.layoutParams = buttonLayoutParams + val rejectButtonLayoutParams = LayoutParams(0, convertToPixels(50, resources)) + rejectButtonLayoutParams.weight = 1f + rejectButton.layoutParams = rejectButtonLayoutParams buttonLinearLayout.addView(rejectButton) // + buttonLinearLayout.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, convertToPixels(50, resources)) addView(buttonLinearLayout) // } + kind = Kind.Incoming // TODO: For debugging purposes updateUI() // TODO: Observe friend request status changes } @@ -97,7 +98,7 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In private fun updateUI() { when (kind) { Kind.Incoming -> { - val message = this.message as IncomingTextMessage +// val message = this.message as IncomingTextMessage // buttonLinearLayout.visibility = View.GONE // TODO: Base on friend request status val text = { // TODO: Base on friend request status "You've received a friend request" @@ -105,7 +106,7 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In label.text = text } Kind.Outgoing -> { - val message = this.message as OutgoingTextMessage +// val message = this.message as OutgoingTextMessage // buttonLinearLayout.visibility = View.GONE val text = { "You've sent a friend request" @@ -118,15 +119,15 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In // region Interaction private fun accept() { - val message = this.message as IncomingTextMessage +// val message = this.message as IncomingTextMessage // TODO: Update message friend request status - delegate?.acceptFriendRequest(message) +// delegate?.acceptFriendRequest(message) } private fun reject() { - val message = this.message as IncomingTextMessage +// val message = this.message as IncomingTextMessage // TODO: Update message friend request status - delegate?.rejectFriendRequest(message) +// delegate?.rejectFriendRequest(message) } // endregion } \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/GeneralUtilities.kt b/src/org/thoughtcrime/securesms/loki/GeneralUtilities.kt index b3347351fc..4407738596 100644 --- a/src/org/thoughtcrime/securesms/loki/GeneralUtilities.kt +++ b/src/org/thoughtcrime/securesms/loki/GeneralUtilities.kt @@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.loki import android.content.res.Resources import android.os.Build import android.support.annotation.ColorRes +import kotlin.math.roundToInt fun Resources.getColorWithID(@ColorRes id: Int, theme: Resources.Theme?): Int { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @@ -10,4 +11,9 @@ fun Resources.getColorWithID(@ColorRes id: Int, theme: Resources.Theme?): Int { } else { @Suppress("DEPRECATION") getColor(id) } +} + +fun convertToPixels(points: Int, resources: Resources): Int { + val scale = resources.displayMetrics.density + return (points * scale).roundToInt() } \ No newline at end of file