mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 23:13:38 +00:00
Tie up some loose ends
This commit is contained in:
parent
dbedc5039a
commit
6393ed03bd
@ -9,14 +9,16 @@ import androidx.appcompat.app.AlertDialog
|
|||||||
import kotlinx.android.synthetic.main.dialog_join_open_group.view.*
|
import kotlinx.android.synthetic.main.dialog_join_open_group.view.*
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
import org.session.libsession.messaging.open_groups.OpenGroupV2
|
import org.session.libsession.messaging.open_groups.OpenGroupV2
|
||||||
|
import org.session.libsession.utilities.OpenGroupUrlParser
|
||||||
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
|
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
|
||||||
|
import org.thoughtcrime.securesms.loki.api.OpenGroupManager
|
||||||
|
import org.thoughtcrime.securesms.loki.protocol.MultiDeviceProtocol
|
||||||
|
|
||||||
/** Shown upon tapping an open group invitation. */
|
/** Shown upon tapping an open group invitation. */
|
||||||
class JoinOpenGroupDialog(private val openGroup: OpenGroupV2) : BaseDialog() {
|
class JoinOpenGroupDialog(private val name: String, private val url: String) : BaseDialog() {
|
||||||
|
|
||||||
override fun setContentView(builder: AlertDialog.Builder) {
|
override fun setContentView(builder: AlertDialog.Builder) {
|
||||||
val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_join_open_group, null)
|
val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_join_open_group, null)
|
||||||
val name = openGroup.name
|
|
||||||
val title = resources.getString(R.string.dialog_join_open_group_title, name)
|
val title = resources.getString(R.string.dialog_join_open_group_title, name)
|
||||||
contentView.joinOpenGroupTitleTextView.text = title
|
contentView.joinOpenGroupTitleTextView.text = title
|
||||||
val explanation = resources.getString(R.string.dialog_join_open_group_explanation, name)
|
val explanation = resources.getString(R.string.dialog_join_open_group_explanation, name)
|
||||||
@ -30,6 +32,9 @@ class JoinOpenGroupDialog(private val openGroup: OpenGroupV2) : BaseDialog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun join() {
|
private fun join() {
|
||||||
// TODO: Implement
|
val openGroup = OpenGroupUrlParser.parseUrl(url)
|
||||||
|
OpenGroupManager.add(openGroup.server, openGroup.room, openGroup.serverPublicKey, requireContext())
|
||||||
|
MultiDeviceProtocol.forceSyncConfigurationNowIfNeeded(requireContext())
|
||||||
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +1,13 @@
|
|||||||
package org.thoughtcrime.securesms.conversation.v2.dialogs
|
package org.thoughtcrime.securesms.conversation.v2.dialogs
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
|
import android.net.Uri
|
||||||
import android.text.Spannable
|
import android.text.Spannable
|
||||||
import android.text.SpannableStringBuilder
|
import android.text.SpannableStringBuilder
|
||||||
import android.text.style.StyleSpan
|
import android.text.style.StyleSpan
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import kotlinx.android.synthetic.main.dialog_open_url.view.*
|
import kotlinx.android.synthetic.main.dialog_open_url.view.*
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
@ -26,6 +29,12 @@ class OpenURLDialog(private val url: String) : BaseDialog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun open() {
|
private fun open() {
|
||||||
// TODO: Implement
|
try {
|
||||||
|
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||||
|
requireContext().startActivity(intent)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Toast.makeText(context, R.string.invalid_url, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,17 +1,23 @@
|
|||||||
package org.thoughtcrime.securesms.conversation.v2.messages
|
package org.thoughtcrime.securesms.conversation.v2.messages
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.net.Uri
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewOutlineProvider
|
import android.view.ViewOutlineProvider
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import kotlinx.android.synthetic.main.view_link_preview.view.*
|
import kotlinx.android.synthetic.main.view_link_preview.view.*
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
import org.thoughtcrime.securesms.components.CornerMask
|
import org.thoughtcrime.securesms.components.CornerMask
|
||||||
|
import org.thoughtcrime.securesms.conversation.v2.dialogs.OpenURLDialog
|
||||||
import org.thoughtcrime.securesms.conversation.v2.utilities.MessageBubbleUtilities
|
import org.thoughtcrime.securesms.conversation.v2.utilities.MessageBubbleUtilities
|
||||||
|
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
||||||
import org.thoughtcrime.securesms.loki.utilities.UiModeUtilities
|
import org.thoughtcrime.securesms.loki.utilities.UiModeUtilities
|
||||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||||
@ -19,6 +25,7 @@ import org.thoughtcrime.securesms.mms.ImageSlide
|
|||||||
|
|
||||||
class LinkPreviewView : LinearLayout {
|
class LinkPreviewView : LinearLayout {
|
||||||
private val cornerMask by lazy { CornerMask(this) }
|
private val cornerMask by lazy { CornerMask(this) }
|
||||||
|
private var url: String? = null
|
||||||
|
|
||||||
// region Lifecycle
|
// region Lifecycle
|
||||||
constructor(context: Context) : super(context) { initialize() }
|
constructor(context: Context) : super(context) { initialize() }
|
||||||
@ -32,11 +39,9 @@ class LinkPreviewView : LinearLayout {
|
|||||||
|
|
||||||
// region Updating
|
// region Updating
|
||||||
fun bind(message: MmsMessageRecord, glide: GlideRequests, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean) {
|
fun bind(message: MmsMessageRecord, glide: GlideRequests, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean) {
|
||||||
mainLinkPreviewContainer.background = background
|
|
||||||
mainLinkPreviewContainer.outlineProvider = ViewOutlineProvider.BACKGROUND
|
|
||||||
mainLinkPreviewContainer.clipToOutline = true
|
|
||||||
// Thumbnail
|
|
||||||
val linkPreview = message.linkPreviews.first()
|
val linkPreview = message.linkPreviews.first()
|
||||||
|
url = linkPreview.url
|
||||||
|
// Thumbnail
|
||||||
if (linkPreview.getThumbnail().isPresent) {
|
if (linkPreview.getThumbnail().isPresent) {
|
||||||
// This internally fetches the thumbnail
|
// This internally fetches the thumbnail
|
||||||
thumbnailImageView.setImageResource(glide, ImageSlide(context, linkPreview.getThumbnail().get()), false, false)
|
thumbnailImageView.setImageResource(glide, ImageSlide(context, linkPreview.getThumbnail().get()), false, false)
|
||||||
@ -65,4 +70,12 @@ class LinkPreviewView : LinearLayout {
|
|||||||
cornerMask.mask(canvas)
|
cornerMask.mask(canvas)
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
// region Interaction
|
||||||
|
fun openURL() {
|
||||||
|
val url = this.url ?: return
|
||||||
|
val activity = context as AppCompatActivity
|
||||||
|
OpenURLDialog(url).show(activity.supportFragmentManager, "Open URL Dialog")
|
||||||
|
}
|
||||||
|
// endregion
|
||||||
}
|
}
|
@ -5,13 +5,17 @@ import android.util.AttributeSet
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import kotlinx.android.synthetic.main.view_open_group_invitation.view.*
|
import kotlinx.android.synthetic.main.view_open_group_invitation.view.*
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
|
import org.session.libsession.messaging.open_groups.OpenGroupV2
|
||||||
import org.session.libsession.messaging.utilities.UpdateMessageData
|
import org.session.libsession.messaging.utilities.UpdateMessageData
|
||||||
import org.session.libsession.utilities.OpenGroupUrlParser
|
import org.session.libsession.utilities.OpenGroupUrlParser
|
||||||
|
import org.thoughtcrime.securesms.conversation.v2.dialogs.JoinOpenGroupDialog
|
||||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||||
|
|
||||||
class OpenGroupInvitationView : LinearLayout {
|
class OpenGroupInvitationView : LinearLayout {
|
||||||
|
private var data: UpdateMessageData.Kind.OpenGroupInvitation? = null
|
||||||
|
|
||||||
constructor(context: Context): super(context) { initialize() }
|
constructor(context: Context): super(context) { initialize() }
|
||||||
constructor(context: Context, attrs: AttributeSet?): super(context, attrs) { initialize() }
|
constructor(context: Context, attrs: AttributeSet?): super(context, attrs) { initialize() }
|
||||||
@ -25,6 +29,7 @@ class OpenGroupInvitationView : LinearLayout {
|
|||||||
// FIXME: This is a really weird approach...
|
// FIXME: This is a really weird approach...
|
||||||
val umd = UpdateMessageData.fromJSON(message.body)!!
|
val umd = UpdateMessageData.fromJSON(message.body)!!
|
||||||
val data = umd.kind as UpdateMessageData.Kind.OpenGroupInvitation
|
val data = umd.kind as UpdateMessageData.Kind.OpenGroupInvitation
|
||||||
|
this.data = data
|
||||||
val iconID = if (message.isOutgoing) R.drawable.ic_globe else R.drawable.ic_plus
|
val iconID = if (message.isOutgoing) R.drawable.ic_globe else R.drawable.ic_plus
|
||||||
openGroupInvitationIconImageView.setImageResource(iconID)
|
openGroupInvitationIconImageView.setImageResource(iconID)
|
||||||
openGroupTitleTextView.text = data.groupName
|
openGroupTitleTextView.text = data.groupName
|
||||||
@ -33,4 +38,10 @@ class OpenGroupInvitationView : LinearLayout {
|
|||||||
openGroupJoinMessageTextView.setTextColor(textColor)
|
openGroupJoinMessageTextView.setTextColor(textColor)
|
||||||
openGroupURLTextView.setTextColor(textColor)
|
openGroupURLTextView.setTextColor(textColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun joinOpenGroup() {
|
||||||
|
val data = data ?: return
|
||||||
|
val activity = context as AppCompatActivity
|
||||||
|
JoinOpenGroupDialog(data.groupName, data.groupUrl).show(activity.supportFragmentManager, "Join Open Group Dialog")
|
||||||
|
}
|
||||||
}
|
}
|
@ -9,6 +9,7 @@ import android.util.TypedValue
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
@ -60,6 +61,7 @@ class VisibleMessageContentView : LinearLayout {
|
|||||||
val linkPreviewView = LinkPreviewView(context)
|
val linkPreviewView = LinkPreviewView(context)
|
||||||
linkPreviewView.bind(message, glide, isStartOfMessageCluster, isEndOfMessageCluster)
|
linkPreviewView.bind(message, glide, isStartOfMessageCluster, isEndOfMessageCluster)
|
||||||
mainContainer.addView(linkPreviewView)
|
mainContainer.addView(linkPreviewView)
|
||||||
|
onContentClick = { linkPreviewView.openURL() }
|
||||||
// Body text view is inside the link preview for layout convenience
|
// Body text view is inside the link preview for layout convenience
|
||||||
} else if (message is MmsMessageRecord && message.quote != null) {
|
} else if (message is MmsMessageRecord && message.quote != null) {
|
||||||
val quote = message.quote!!
|
val quote = message.quote!!
|
||||||
@ -102,9 +104,11 @@ class VisibleMessageContentView : LinearLayout {
|
|||||||
val openGroupInvitationView = OpenGroupInvitationView(context)
|
val openGroupInvitationView = OpenGroupInvitationView(context)
|
||||||
openGroupInvitationView.bind(message, VisibleMessageContentView.getTextColor(context, message))
|
openGroupInvitationView.bind(message, VisibleMessageContentView.getTextColor(context, message))
|
||||||
mainContainer.addView(openGroupInvitationView)
|
mainContainer.addView(openGroupInvitationView)
|
||||||
|
onContentClick = { openGroupInvitationView.joinOpenGroup() }
|
||||||
} else {
|
} else {
|
||||||
val bodyTextView = VisibleMessageContentView.getBodyTextView(context, message)
|
val bodyTextView = VisibleMessageContentView.getBodyTextView(context, message)
|
||||||
mainContainer.addView(bodyTextView)
|
mainContainer.addView(bodyTextView)
|
||||||
|
onContentClick = { openURLIfNeeded(message) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,6 +132,12 @@ class VisibleMessageContentView : LinearLayout {
|
|||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
// region Interaction
|
||||||
|
private fun openURLIfNeeded(message: MessageRecord) {
|
||||||
|
Toast.makeText(context, "Not yet implemented", Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
// endregion
|
||||||
|
|
||||||
// region Convenience
|
// region Convenience
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user