mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 04:25:18 +00:00
Further build out friend request view
This commit is contained in:
parent
7c501980fa
commit
f6542b9834
@ -1,19 +1,50 @@
|
|||||||
package org.thoughtcrime.securesms.loki
|
package org.thoughtcrime.securesms.loki
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.Button
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
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) {
|
class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) {
|
||||||
|
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
|
||||||
|
|
||||||
// region Components
|
// region Components
|
||||||
|
private val topSpacer by lazy {
|
||||||
|
val result = View(context)
|
||||||
|
result.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, 12)
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
private val label by lazy {
|
private val label by lazy {
|
||||||
val result = TextView(context)
|
val result = TextView(context)
|
||||||
|
result.setTextColor(resources.getColorWithID(R.color.core_grey_90, context.theme))
|
||||||
|
// TODO: Typeface
|
||||||
result.textAlignment = TextView.TEXT_ALIGNMENT_CENTER
|
result.textAlignment = TextView.TEXT_ALIGNMENT_CENTER
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val buttonLinearLayout by lazy {
|
||||||
|
val result = LinearLayout(context)
|
||||||
|
result.orientation = HORIZONTAL
|
||||||
|
result.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, 50)
|
||||||
|
result
|
||||||
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Initialization
|
// region Initialization
|
||||||
@ -22,17 +53,80 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
orientation = VERTICAL
|
orientation = VERTICAL
|
||||||
val topSpacer = View(context)
|
|
||||||
topSpacer.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, 12)
|
|
||||||
addView(topSpacer)
|
addView(topSpacer)
|
||||||
addView(label)
|
addView(label)
|
||||||
|
// if (kind == Kind.Incoming) {
|
||||||
|
//
|
||||||
|
val buttonLayoutParams = LayoutParams(0, 50)
|
||||||
|
buttonLayoutParams.weight = 1f
|
||||||
|
// 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() }
|
||||||
|
acceptButton.layoutParams = buttonLayoutParams
|
||||||
|
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() }
|
||||||
|
rejectButton.layoutParams = buttonLayoutParams
|
||||||
|
buttonLinearLayout.addView(rejectButton)
|
||||||
|
//
|
||||||
|
addView(buttonLinearLayout)
|
||||||
|
// }
|
||||||
updateUI()
|
updateUI()
|
||||||
|
// TODO: Observe friend request status changes
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Updating
|
// region Updating
|
||||||
private fun updateUI() {
|
private fun updateUI() {
|
||||||
label.text = "You've sent a friend request"
|
when (kind) {
|
||||||
|
Kind.Incoming -> {
|
||||||
|
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"
|
||||||
|
}()
|
||||||
|
label.text = text
|
||||||
|
}
|
||||||
|
Kind.Outgoing -> {
|
||||||
|
val message = this.message as OutgoingTextMessage
|
||||||
|
// buttonLinearLayout.visibility = View.GONE
|
||||||
|
val text = {
|
||||||
|
"You've sent a friend request"
|
||||||
|
}()
|
||||||
|
label.text = text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region Interaction
|
||||||
|
private fun accept() {
|
||||||
|
val message = this.message as IncomingTextMessage
|
||||||
|
// TODO: Update message friend request status
|
||||||
|
delegate?.acceptFriendRequest(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun reject() {
|
||||||
|
val message = this.message as IncomingTextMessage
|
||||||
|
// TODO: Update message friend request status
|
||||||
|
delegate?.rejectFriendRequest(message)
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
}
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package org.thoughtcrime.securesms.loki
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.sms.IncomingTextMessage
|
||||||
|
|
||||||
|
interface FriendRequestViewDelegate {
|
||||||
|
/**
|
||||||
|
* Implementations of this method should update the thread's friend request status
|
||||||
|
* and send a friend request accepted message.
|
||||||
|
*/
|
||||||
|
fun acceptFriendRequest(friendRequest: IncomingTextMessage)
|
||||||
|
/**
|
||||||
|
* Implementations of this method should update the thread's friend request status
|
||||||
|
* and remove the pre keys associated with the contact.
|
||||||
|
*/
|
||||||
|
fun rejectFriendRequest(friendRequest: IncomingTextMessage)
|
||||||
|
}
|
13
src/org/thoughtcrime/securesms/loki/GeneralUtilities.kt
Normal file
13
src/org/thoughtcrime/securesms/loki/GeneralUtilities.kt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package org.thoughtcrime.securesms.loki
|
||||||
|
|
||||||
|
import android.content.res.Resources
|
||||||
|
import android.os.Build
|
||||||
|
import android.support.annotation.ColorRes
|
||||||
|
|
||||||
|
fun Resources.getColorWithID(@ColorRes id: Int, theme: Resources.Theme?): Int {
|
||||||
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
getColor(id, theme)
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION") getColor(id)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user