Fix UI issue

This commit is contained in:
Niels Andriesse 2019-06-21 15:29:25 +10:00
parent f6542b9834
commit 5c4ef59c0b
2 changed files with 20 additions and 13 deletions

View File

@ -9,7 +9,6 @@ import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.sms.IncomingTextMessage import org.thoughtcrime.securesms.sms.IncomingTextMessage
import org.thoughtcrime.securesms.sms.OutgoingTextMessage
class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) { class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) {
var message: Any? = null var message: Any? = null
@ -42,7 +41,6 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
private val buttonLinearLayout by lazy { private val buttonLinearLayout by lazy {
val result = LinearLayout(context) val result = LinearLayout(context)
result.orientation = HORIZONTAL result.orientation = HORIZONTAL
result.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, 50)
result result
} }
// endregion // endregion
@ -56,9 +54,6 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
addView(topSpacer) addView(topSpacer)
addView(label) addView(label)
// if (kind == Kind.Incoming) { // if (kind == Kind.Incoming) {
//
val buttonLayoutParams = LayoutParams(0, 50)
buttonLayoutParams.weight = 1f
// Accept button // Accept button
val acceptButton = Button(context) val acceptButton = Button(context)
acceptButton.text = "Accept" acceptButton.text = "Accept"
@ -70,7 +65,9 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
acceptButton.stateListAnimator = null acceptButton.stateListAnimator = null
} }
acceptButton.setOnClickListener { accept() } acceptButton.setOnClickListener { accept() }
acceptButton.layoutParams = buttonLayoutParams val acceptButtonLayoutParams = LayoutParams(0, convertToPixels(50, resources))
acceptButtonLayoutParams.weight = 1f
acceptButton.layoutParams = acceptButtonLayoutParams
buttonLinearLayout.addView(acceptButton) buttonLinearLayout.addView(acceptButton)
// Reject button // Reject button
val rejectButton = Button(context) val rejectButton = Button(context)
@ -83,11 +80,15 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
rejectButton.stateListAnimator = null rejectButton.stateListAnimator = null
} }
rejectButton.setOnClickListener { reject() } rejectButton.setOnClickListener { reject() }
rejectButton.layoutParams = buttonLayoutParams val rejectButtonLayoutParams = LayoutParams(0, convertToPixels(50, resources))
rejectButtonLayoutParams.weight = 1f
rejectButton.layoutParams = rejectButtonLayoutParams
buttonLinearLayout.addView(rejectButton) buttonLinearLayout.addView(rejectButton)
// //
buttonLinearLayout.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, convertToPixels(50, resources))
addView(buttonLinearLayout) addView(buttonLinearLayout)
// } // }
kind = Kind.Incoming // TODO: For debugging purposes
updateUI() updateUI()
// TODO: Observe friend request status changes // TODO: Observe friend request status changes
} }
@ -97,7 +98,7 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
private fun updateUI() { private fun updateUI() {
when (kind) { when (kind) {
Kind.Incoming -> { Kind.Incoming -> {
val message = this.message as IncomingTextMessage // val message = this.message as IncomingTextMessage
// buttonLinearLayout.visibility = View.GONE // TODO: Base on friend request status // buttonLinearLayout.visibility = View.GONE // TODO: Base on friend request status
val text = { // TODO: Base on friend request status val text = { // TODO: Base on friend request status
"You've received a friend request" "You've received a friend request"
@ -105,7 +106,7 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
label.text = text label.text = text
} }
Kind.Outgoing -> { Kind.Outgoing -> {
val message = this.message as OutgoingTextMessage // val message = this.message as OutgoingTextMessage
// buttonLinearLayout.visibility = View.GONE // buttonLinearLayout.visibility = View.GONE
val text = { val text = {
"You've sent a friend request" "You've sent a friend request"
@ -118,15 +119,15 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
// region Interaction // region Interaction
private fun accept() { private fun accept() {
val message = this.message as IncomingTextMessage // val message = this.message as IncomingTextMessage
// TODO: Update message friend request status // TODO: Update message friend request status
delegate?.acceptFriendRequest(message) // delegate?.acceptFriendRequest(message)
} }
private fun reject() { private fun reject() {
val message = this.message as IncomingTextMessage // val message = this.message as IncomingTextMessage
// TODO: Update message friend request status // TODO: Update message friend request status
delegate?.rejectFriendRequest(message) // delegate?.rejectFriendRequest(message)
} }
// endregion // endregion
} }

View File

@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.loki
import android.content.res.Resources import android.content.res.Resources
import android.os.Build import android.os.Build
import android.support.annotation.ColorRes import android.support.annotation.ColorRes
import kotlin.math.roundToInt
fun Resources.getColorWithID(@ColorRes id: Int, theme: Resources.Theme?): Int { fun Resources.getColorWithID(@ColorRes id: Int, theme: Resources.Theme?): Int {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 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 { } else {
@Suppress("DEPRECATION") getColor(id) @Suppress("DEPRECATION") getColor(id)
} }
}
fun convertToPixels(points: Int, resources: Resources): Int {
val scale = resources.displayMetrics.density
return (points * scale).roundToInt()
} }