2019-06-21 02:21:48 +00:00
|
|
|
package org.thoughtcrime.securesms.loki
|
|
|
|
|
|
|
|
import android.content.Context
|
2019-06-21 04:18:38 +00:00
|
|
|
import android.os.Build
|
2019-06-21 02:21:48 +00:00
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.view.View
|
2019-06-21 04:18:38 +00:00
|
|
|
import android.widget.Button
|
2019-06-21 02:21:48 +00:00
|
|
|
import android.widget.LinearLayout
|
|
|
|
import android.widget.TextView
|
2019-06-21 04:18:38 +00:00
|
|
|
import org.thoughtcrime.securesms.R
|
|
|
|
import org.thoughtcrime.securesms.sms.IncomingTextMessage
|
2019-06-21 02:21:48 +00:00
|
|
|
|
|
|
|
class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) {
|
2019-06-21 04:18:38 +00:00
|
|
|
var message: Any? = null
|
|
|
|
set(newValue) {
|
|
|
|
field = newValue
|
|
|
|
kind = if (message is IncomingTextMessage) Kind.Incoming else Kind.Outgoing
|
|
|
|
}
|
|
|
|
var kind: Kind? = null
|
|
|
|
var delegate: FriendRequestViewDelegate? = null
|
|
|
|
|
|
|
|
// region Types
|
|
|
|
enum class Kind { Incoming, Outgoing }
|
|
|
|
// endregion
|
2019-06-21 02:21:48 +00:00
|
|
|
|
|
|
|
// region Components
|
2019-06-21 04:18:38 +00:00
|
|
|
private val topSpacer by lazy {
|
|
|
|
val result = View(context)
|
|
|
|
result.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, 12)
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
2019-06-21 02:21:48 +00:00
|
|
|
private val label by lazy {
|
|
|
|
val result = TextView(context)
|
2019-06-21 04:18:38 +00:00
|
|
|
result.setTextColor(resources.getColorWithID(R.color.core_grey_90, context.theme))
|
|
|
|
// TODO: Typeface
|
2019-06-21 02:21:48 +00:00
|
|
|
result.textAlignment = TextView.TEXT_ALIGNMENT_CENTER
|
|
|
|
result
|
|
|
|
}
|
2019-06-21 04:18:38 +00:00
|
|
|
|
|
|
|
private val buttonLinearLayout by lazy {
|
|
|
|
val result = LinearLayout(context)
|
|
|
|
result.orientation = HORIZONTAL
|
|
|
|
result
|
|
|
|
}
|
2019-06-21 02:21:48 +00:00
|
|
|
// endregion
|
|
|
|
|
|
|
|
// region Initialization
|
|
|
|
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
|
|
|
constructor(context: Context) : this(context, null)
|
|
|
|
|
|
|
|
init {
|
|
|
|
orientation = VERTICAL
|
|
|
|
addView(topSpacer)
|
|
|
|
addView(label)
|
2019-06-21 04:18:38 +00:00
|
|
|
// if (kind == Kind.Incoming) {
|
|
|
|
// Accept button
|
|
|
|
val acceptButton = Button(context)
|
|
|
|
acceptButton.text = "Accept"
|
|
|
|
acceptButton.setTextColor(resources.getColorWithID(R.color.signal_primary, context.theme))
|
|
|
|
acceptButton.setBackgroundColor(resources.getColorWithID(R.color.transparent, context.theme))
|
|
|
|
// TODO: Typeface
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
acceptButton.elevation = 0f
|
|
|
|
acceptButton.stateListAnimator = null
|
|
|
|
}
|
|
|
|
acceptButton.setOnClickListener { accept() }
|
2019-06-21 05:29:25 +00:00
|
|
|
val acceptButtonLayoutParams = LayoutParams(0, convertToPixels(50, resources))
|
|
|
|
acceptButtonLayoutParams.weight = 1f
|
|
|
|
acceptButton.layoutParams = acceptButtonLayoutParams
|
2019-06-21 04:18:38 +00:00
|
|
|
buttonLinearLayout.addView(acceptButton)
|
|
|
|
// Reject button
|
|
|
|
val rejectButton = Button(context)
|
|
|
|
rejectButton.text = "Reject"
|
|
|
|
rejectButton.setTextColor(resources.getColorWithID(R.color.red, context.theme))
|
|
|
|
rejectButton.setBackgroundColor(resources.getColorWithID(R.color.transparent, context.theme))
|
|
|
|
// TODO: Typeface
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
rejectButton.elevation = 0f
|
|
|
|
rejectButton.stateListAnimator = null
|
|
|
|
}
|
|
|
|
rejectButton.setOnClickListener { reject() }
|
2019-06-21 05:29:25 +00:00
|
|
|
val rejectButtonLayoutParams = LayoutParams(0, convertToPixels(50, resources))
|
|
|
|
rejectButtonLayoutParams.weight = 1f
|
|
|
|
rejectButton.layoutParams = rejectButtonLayoutParams
|
2019-06-21 04:18:38 +00:00
|
|
|
buttonLinearLayout.addView(rejectButton)
|
|
|
|
//
|
2019-06-21 05:29:25 +00:00
|
|
|
buttonLinearLayout.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, convertToPixels(50, resources))
|
2019-06-21 04:18:38 +00:00
|
|
|
addView(buttonLinearLayout)
|
|
|
|
// }
|
2019-06-21 05:29:25 +00:00
|
|
|
kind = Kind.Incoming // TODO: For debugging purposes
|
2019-06-21 02:21:48 +00:00
|
|
|
updateUI()
|
2019-06-21 04:18:38 +00:00
|
|
|
// TODO: Observe friend request status changes
|
2019-06-21 02:21:48 +00:00
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
// region Updating
|
|
|
|
private fun updateUI() {
|
2019-06-21 04:18:38 +00:00
|
|
|
when (kind) {
|
|
|
|
Kind.Incoming -> {
|
2019-06-21 05:29:25 +00:00
|
|
|
// val message = this.message as IncomingTextMessage
|
2019-06-21 04:18:38 +00:00
|
|
|
// buttonLinearLayout.visibility = View.GONE // TODO: Base on friend request status
|
|
|
|
val text = { // TODO: Base on friend request status
|
|
|
|
"You've received a friend request"
|
|
|
|
}()
|
|
|
|
label.text = text
|
|
|
|
}
|
|
|
|
Kind.Outgoing -> {
|
2019-06-21 05:29:25 +00:00
|
|
|
// val message = this.message as OutgoingTextMessage
|
2019-06-21 04:18:38 +00:00
|
|
|
// buttonLinearLayout.visibility = View.GONE
|
|
|
|
val text = {
|
|
|
|
"You've sent a friend request"
|
|
|
|
}()
|
|
|
|
label.text = text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
// region Interaction
|
|
|
|
private fun accept() {
|
2019-06-21 05:29:25 +00:00
|
|
|
// val message = this.message as IncomingTextMessage
|
2019-06-21 04:18:38 +00:00
|
|
|
// TODO: Update message friend request status
|
2019-06-21 05:29:25 +00:00
|
|
|
// delegate?.acceptFriendRequest(message)
|
2019-06-21 04:18:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun reject() {
|
2019-06-21 05:29:25 +00:00
|
|
|
// val message = this.message as IncomingTextMessage
|
2019-06-21 04:18:38 +00:00
|
|
|
// TODO: Update message friend request status
|
2019-06-21 05:29:25 +00:00
|
|
|
// delegate?.rejectFriendRequest(message)
|
2019-06-21 02:21:48 +00:00
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
}
|