Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
e0e2f924
Unverified
Commit
e0e2f924
authored
Jul 27, 2018
by
Lucio Maciel
Committed by
GitHub
Jul 27, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1548 from RocketChat/fix/fix-uppercase-scheme
[FIX] Fix uppercase url scheme
parents
ebf24317
263b3f63
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
20 deletions
+29
-20
UrlPreviewViewHolder.kt
...t/rocket/android/chatroom/adapter/UrlPreviewViewHolder.kt
+2
-3
MessageParser.kt
...src/main/java/chat/rocket/android/helper/MessageParser.kt
+5
-15
String.kt
...c/main/java/chat/rocket/android/util/extensions/String.kt
+8
-0
View.kt
...src/main/java/chat/rocket/android/util/extensions/View.kt
+14
-2
No files found.
app/src/main/java/chat/rocket/android/chatroom/adapter/UrlPreviewViewHolder.kt
View file @
e0e2f924
package
chat.rocket.android.chatroom.adapter
import
android.net.Uri
import
android.view.View
import
androidx.core.view.isVisible
import
chat.rocket.android.chatroom.uimodel.UrlPreviewUiModel
import
chat.rocket.android.util.extensions.openTabbedUrl
import
chat.rocket.android.emoji.EmojiReactionListener
import
chat.rocket.android.util.extensions.content
import
chat.rocket.android.util.extensions.openTabbedUrl
import
kotlinx.android.synthetic.main.message_url_preview.view.*
class
UrlPreviewViewHolder
(
itemView
:
View
,
...
...
@@ -42,7 +41,7 @@ class UrlPreviewViewHolder(itemView: View,
private
val
onClickListener
=
{
view
:
View
->
if
(
data
!=
null
)
{
view
.
openTabbedUrl
(
Uri
.
parse
(
data
!!
.
rawData
.
url
)
)
view
.
openTabbedUrl
(
data
!!
.
rawData
.
url
)
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/helper/MessageParser.kt
View file @
e0e2f924
...
...
@@ -5,21 +5,19 @@ import android.content.Context
import
android.graphics.Canvas
import
android.graphics.Paint
import
android.graphics.RectF
import
android.net.Uri
import
androidx.core.content.res.ResourcesCompat
import
android.text.Spanned
import
android.text.style.ClickableSpan
import
android.text.style.ReplacementSpan
import
android.text.style.StyleSpan
import
android.util.Patterns
import
android.view.View
import
androidx.core.content.res.ResourcesCompat
import
chat.rocket.android.R
import
chat.rocket.android.server.domain.PublicSettings
import
chat.rocket.android.server.domain.useRealName
import
chat.rocket.android.util.extensions.openTabbedUrl
import
chat.rocket.android.emoji.EmojiParser
import
chat.rocket.android.emoji.EmojiRepository
import
chat.rocket.android.emoji.EmojiTypefaceSpan
import
chat.rocket.android.server.domain.PublicSettings
import
chat.rocket.android.server.domain.useRealName
import
chat.rocket.android.util.extensions.openTabbedUrl
import
chat.rocket.common.model.SimpleUser
import
chat.rocket.core.model.Message
import
org.commonmark.node.AbstractVisitor
...
...
@@ -187,7 +185,7 @@ class MessageParser @Inject constructor(
if
(!
link
.
startsWith
(
"@"
)
&&
link
!
in
consumed
)
{
builder
.
setSpan
(
object
:
ClickableSpan
()
{
override
fun
onClick
(
view
:
View
)
{
view
.
openTabbedUrl
(
getUri
(
link
)
)
view
.
openTabbedUrl
(
link
)
}
},
matcher
.
start
(
0
),
matcher
.
end
(
0
))
consumed
.
add
(
link
)
...
...
@@ -195,14 +193,6 @@ class MessageParser @Inject constructor(
}
visitChildren
(
text
)
}
private
fun
getUri
(
link
:
String
):
Uri
{
val
uri
=
Uri
.
parse
(
link
)
if
(
uri
.
scheme
==
null
)
{
return
Uri
.
parse
(
"http://$link"
)
}
return
uri
}
}
class
MentionSpan
(
...
...
app/src/main/java/chat/rocket/android/util/extensions/String.kt
View file @
e0e2f924
...
...
@@ -3,6 +3,7 @@ package chat.rocket.android.util.extensions
import
android.graphics.Color
import
android.util.Patterns
import
chat.rocket.common.model.Token
import
okhttp3.HttpUrl
import
timber.log.Timber
fun
String
.
removeTrailingSlash
():
String
{
...
...
@@ -64,4 +65,11 @@ fun String.parseColor(): Int {
fun
String
.
userId
(
userId
:
String
?):
String
?
{
return
userId
?.
let
{
this
.
replace
(
it
,
""
)
}
}
fun
String
.
lowercaseUrl
():
String
?
{
val
httpUrl
=
HttpUrl
.
parse
(
this
)
val
newScheme
=
httpUrl
?.
scheme
()
?.
toLowerCase
()
return
httpUrl
?.
newBuilder
()
?.
scheme
(
newScheme
)
?.
build
()
?.
toString
()
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/util/extensions/View.kt
View file @
e0e2f924
...
...
@@ -7,15 +7,27 @@ import android.view.View
import
chat.rocket.android.R
import
timber.log.Timber
fun
View
.
openTabbedUrl
(
url
:
Uri
)
{
fun
View
.
openTabbedUrl
(
url
:
String
)
{
with
(
this
)
{
val
uri
=
url
.
ensureScheme
()
val
tabsbuilder
=
CustomTabsIntent
.
Builder
()
tabsbuilder
.
setToolbarColor
(
ResourcesCompat
.
getColor
(
context
.
resources
,
R
.
color
.
colorPrimary
,
context
.
theme
))
val
customTabsIntent
=
tabsbuilder
.
build
()
try
{
customTabsIntent
.
launchUrl
(
context
,
ur
l
)
customTabsIntent
.
launchUrl
(
context
,
ur
i
)
}
catch
(
ex
:
Exception
)
{
Timber
.
d
(
ex
,
"Unable to launch URL"
)
}
}
}
private
fun
String
.
ensureScheme
():
Uri
?
{
// check if the URL starts with a http(s) scheme
val
url
=
if
(!
this
.
matches
(
Regex
(
"^([h|H][t|T][t|T][p|P]).*"
)))
{
"http://$this"
}
else
{
this
}
return
Uri
.
parse
(
url
.
lowercaseUrl
())
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment