mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 00:37:47 +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 network.loki.messenger.R
|
||||
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.loki.api.OpenGroupManager
|
||||
import org.thoughtcrime.securesms.loki.protocol.MultiDeviceProtocol
|
||||
|
||||
/** 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) {
|
||||
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)
|
||||
contentView.joinOpenGroupTitleTextView.text = title
|
||||
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() {
|
||||
// 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
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.Typeface
|
||||
import android.net.Uri
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.style.StyleSpan
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import kotlinx.android.synthetic.main.dialog_open_url.view.*
|
||||
import network.loki.messenger.R
|
||||
@ -26,6 +29,12 @@ class OpenURLDialog(private val url: String) : BaseDialog() {
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewOutlineProvider
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import kotlinx.android.synthetic.main.view_link_preview.view.*
|
||||
import network.loki.messenger.R
|
||||
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.database.model.MessageRecord
|
||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
||||
import org.thoughtcrime.securesms.loki.utilities.UiModeUtilities
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||
@ -19,6 +25,7 @@ import org.thoughtcrime.securesms.mms.ImageSlide
|
||||
|
||||
class LinkPreviewView : LinearLayout {
|
||||
private val cornerMask by lazy { CornerMask(this) }
|
||||
private var url: String? = null
|
||||
|
||||
// region Lifecycle
|
||||
constructor(context: Context) : super(context) { initialize() }
|
||||
@ -32,11 +39,9 @@ class LinkPreviewView : LinearLayout {
|
||||
|
||||
// region Updating
|
||||
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()
|
||||
url = linkPreview.url
|
||||
// Thumbnail
|
||||
if (linkPreview.getThumbnail().isPresent) {
|
||||
// This internally fetches the thumbnail
|
||||
thumbnailImageView.setImageResource(glide, ImageSlide(context, linkPreview.getThumbnail().get()), false, false)
|
||||
@ -65,4 +70,12 @@ class LinkPreviewView : LinearLayout {
|
||||
cornerMask.mask(canvas)
|
||||
}
|
||||
// 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.widget.LinearLayout
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import kotlinx.android.synthetic.main.view_open_group_invitation.view.*
|
||||
import network.loki.messenger.R
|
||||
import org.session.libsession.messaging.open_groups.OpenGroupV2
|
||||
import org.session.libsession.messaging.utilities.UpdateMessageData
|
||||
import org.session.libsession.utilities.OpenGroupUrlParser
|
||||
import org.thoughtcrime.securesms.conversation.v2.dialogs.JoinOpenGroupDialog
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
|
||||
class OpenGroupInvitationView : LinearLayout {
|
||||
private var data: UpdateMessageData.Kind.OpenGroupInvitation? = null
|
||||
|
||||
constructor(context: Context): super(context) { initialize() }
|
||||
constructor(context: Context, attrs: AttributeSet?): super(context, attrs) { initialize() }
|
||||
@ -25,6 +29,7 @@ class OpenGroupInvitationView : LinearLayout {
|
||||
// FIXME: This is a really weird approach...
|
||||
val umd = UpdateMessageData.fromJSON(message.body)!!
|
||||
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
|
||||
openGroupInvitationIconImageView.setImageResource(iconID)
|
||||
openGroupTitleTextView.text = data.groupName
|
||||
@ -33,4 +38,10 @@ class OpenGroupInvitationView : LinearLayout {
|
||||
openGroupJoinMessageTextView.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.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
@ -60,6 +61,7 @@ class VisibleMessageContentView : LinearLayout {
|
||||
val linkPreviewView = LinkPreviewView(context)
|
||||
linkPreviewView.bind(message, glide, isStartOfMessageCluster, isEndOfMessageCluster)
|
||||
mainContainer.addView(linkPreviewView)
|
||||
onContentClick = { linkPreviewView.openURL() }
|
||||
// Body text view is inside the link preview for layout convenience
|
||||
} else if (message is MmsMessageRecord && message.quote != null) {
|
||||
val quote = message.quote!!
|
||||
@ -102,9 +104,11 @@ class VisibleMessageContentView : LinearLayout {
|
||||
val openGroupInvitationView = OpenGroupInvitationView(context)
|
||||
openGroupInvitationView.bind(message, VisibleMessageContentView.getTextColor(context, message))
|
||||
mainContainer.addView(openGroupInvitationView)
|
||||
onContentClick = { openGroupInvitationView.joinOpenGroup() }
|
||||
} else {
|
||||
val bodyTextView = VisibleMessageContentView.getBodyTextView(context, message)
|
||||
mainContainer.addView(bodyTextView)
|
||||
onContentClick = { openURLIfNeeded(message) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,6 +132,12 @@ class VisibleMessageContentView : LinearLayout {
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region Interaction
|
||||
private fun openURLIfNeeded(message: MessageRecord) {
|
||||
Toast.makeText(context, "Not yet implemented", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region Convenience
|
||||
companion object {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user