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
5b1ce1b6
Unverified
Commit
5b1ce1b6
authored
Apr 10, 2018
by
Rafael Kellermann Streit
Committed by
GitHub
Apr 10, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1068 from RocketChat/feature/attachment-fields
[NEW] Feature/attachment fields
parents
032a72a0
98c859dd
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
224 additions
and
16 deletions
+224
-16
RocketChatApplication.kt
...ain/java/chat/rocket/android/app/RocketChatApplication.kt
+1
-1
SharedPreferencesTokenRepository.kt
...ation/infraestructure/SharedPreferencesTokenRepository.kt
+1
-1
AuthorAttachmentViewHolder.kt
...et/android/chatroom/adapter/AuthorAttachmentViewHolder.kt
+52
-0
ChatRoomAdapter.kt
...a/chat/rocket/android/chatroom/adapter/ChatRoomAdapter.kt
+6
-0
AuthorAttachmentViewModel.kt
...t/android/chatroom/viewmodel/AuthorAttachmentViewModel.kt
+24
-0
BaseAttachmentViewModel.kt
...ket/android/chatroom/viewmodel/BaseAttachmentViewModel.kt
+5
-0
BaseFileAttachmentViewModel.kt
...android/chatroom/viewmodel/BaseFileAttachmentViewModel.kt
+1
-2
BaseViewModel.kt
...a/chat/rocket/android/chatroom/viewmodel/BaseViewModel.kt
+2
-1
ViewModelMapper.kt
...chat/rocket/android/chatroom/viewmodel/ViewModelMapper.kt
+50
-4
AppModule.kt
.../main/java/chat/rocket/android/dagger/module/AppModule.kt
+2
-3
SharedPreferencesAccountsRepository.kt
...er/infraestructure/SharedPreferencesAccountsRepository.kt
+1
-1
CharSequence.kt
.../java/chat/rocket/android/util/extensions/CharSequence.kt
+8
-0
OauthWebViewActivity.kt
...t/rocket/android/webview/oauth/ui/OauthWebViewActivity.kt
+1
-1
quote_vertical_bar.xml
app/src/main/res/drawable/quote_vertical_bar.xml
+1
-1
item_author_attachment.xml
app/src/main/res/layout/item_author_attachment.xml
+66
-0
colors.xml
app/src/main/res/values/colors.xml
+2
-0
dependencies.gradle
dependencies.gradle
+1
-1
No files found.
app/src/main/java/chat/rocket/android/app/RocketChatApplication.kt
View file @
5b1ce1b6
...
...
@@ -6,7 +6,7 @@ import android.app.Service
import
android.content.BroadcastReceiver
import
android.content.Context
import
android.content.SharedPreferences
import
androidx.content.edit
import
androidx.co
re.co
ntent.edit
import
chat.rocket.android.BuildConfig
import
chat.rocket.android.app.migration.RealmMigration
import
chat.rocket.android.app.migration.RocketChatLibraryModule
...
...
app/src/main/java/chat/rocket/android/authentication/infraestructure/SharedPreferencesTokenRepository.kt
View file @
5b1ce1b6
package
chat.rocket.android.authentication.infraestructure
import
android.content.SharedPreferences
import
androidx.content.edit
import
androidx.co
re.co
ntent.edit
import
chat.rocket.android.authentication.domain.model.TokenModel
import
chat.rocket.android.server.domain.TokenRepository
import
chat.rocket.common.model.Token
...
...
app/src/main/java/chat/rocket/android/chatroom/adapter/AuthorAttachmentViewHolder.kt
0 → 100644
View file @
5b1ce1b6
package
chat.rocket.android.chatroom.adapter
import
android.content.Intent
import
android.net.Uri
import
android.view.View
import
androidx.core.view.isGone
import
androidx.core.view.isVisible
import
chat.rocket.android.chatroom.viewmodel.AuthorAttachmentViewModel
import
chat.rocket.android.util.extensions.content
import
chat.rocket.android.widget.emoji.EmojiReactionListener
import
chat.rocket.common.util.ifNull
import
kotlinx.android.synthetic.main.item_author_attachment.view.*
class
AuthorAttachmentViewHolder
(
itemView
:
View
,
listener
:
ActionsListener
,
reactionListener
:
EmojiReactionListener
?
=
null
)
:
BaseViewHolder
<
AuthorAttachmentViewModel
>(
itemView
,
listener
,
reactionListener
)
{
init
{
with
(
itemView
)
{
setupActionMenu
(
author_attachment_container
)
setupActionMenu
(
text_fields
)
setupActionMenu
(
text_author_name
)
}
}
override
fun
bindViews
(
data
:
AuthorAttachmentViewModel
)
{
with
(
itemView
)
{
data
.
icon
?.
let
{
icon
->
author_icon
.
isVisible
=
true
author_icon
.
setImageURI
(
icon
)
}.
ifNull
{
author_icon
.
isGone
=
true
}
author_icon
.
setImageURI
(
data
.
icon
)
text_author_name
.
content
=
data
.
name
data
.
fields
?.
let
{
fields
->
text_fields
.
content
=
fields
text_fields
.
isVisible
=
true
}.
ifNull
{
text_fields
.
isGone
=
true
}
text_author_name
.
setOnClickListener
{
it
.
context
.
startActivity
(
Intent
(
Intent
.
ACTION_VIEW
,
Uri
.
parse
(
data
.
attachmentUrl
)))
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/adapter/ChatRoomAdapter.kt
View file @
5b1ce1b6
...
...
@@ -53,6 +53,10 @@ class ChatRoomAdapter(
val
view
=
parent
.
inflate
(
R
.
layout
.
item_message_attachment
)
MessageAttachmentViewHolder
(
view
,
actionsListener
,
reactionListener
)
}
BaseViewModel
.
ViewType
.
AUTHOR_ATTACHMENT
->
{
val
view
=
parent
.
inflate
(
R
.
layout
.
item_author_attachment
)
AuthorAttachmentViewHolder
(
view
,
actionsListener
,
reactionListener
)
}
else
->
{
throw
InvalidParameterException
(
"TODO - implement for ${viewType.toViewType()}"
)
}
...
...
@@ -92,6 +96,7 @@ class ChatRoomAdapter(
is
VideoAttachmentViewHolder
->
holder
.
bind
(
dataSet
[
position
]
as
VideoAttachmentViewModel
)
is
UrlPreviewViewHolder
->
holder
.
bind
(
dataSet
[
position
]
as
UrlPreviewViewModel
)
is
MessageAttachmentViewHolder
->
holder
.
bind
(
dataSet
[
position
]
as
MessageAttachmentViewModel
)
is
AuthorAttachmentViewHolder
->
holder
.
bind
(
dataSet
[
position
]
as
AuthorAttachmentViewModel
)
}
}
...
...
@@ -100,6 +105,7 @@ class ChatRoomAdapter(
return
when
(
model
)
{
is
MessageViewModel
->
model
.
messageId
.
hashCode
().
toLong
()
is
BaseFileAttachmentViewModel
->
model
.
id
is
AuthorAttachmentViewModel
->
model
.
id
else
->
return
position
.
toLong
()
}
}
...
...
app/src/main/java/chat/rocket/android/chatroom/viewmodel/AuthorAttachmentViewModel.kt
0 → 100644
View file @
5b1ce1b6
package
chat.rocket.android.chatroom.viewmodel
import
chat.rocket.android.R
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.attachment.AuthorAttachment
data class
AuthorAttachmentViewModel
(
override
val
attachmentUrl
:
String
,
val
id
:
Long
,
val
name
:
CharSequence
?,
val
icon
:
String
?,
val
fields
:
CharSequence
?,
override
val
message
:
Message
,
override
val
rawData
:
AuthorAttachment
,
override
val
messageId
:
String
,
override
var
reactions
:
List
<
ReactionViewModel
>,
override
var
nextDownStreamMessage
:
BaseViewModel
<*>?
=
null
,
override
var
preview
:
Message
?
=
null
)
:
BaseAttachmentViewModel
<
AuthorAttachment
>
{
override
val
viewType
:
Int
get
()
=
BaseViewModel
.
ViewType
.
AUTHOR_ATTACHMENT
.
viewType
override
val
layoutId
:
Int
get
()
=
R
.
layout
.
item_author_attachment
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/viewmodel/BaseAttachmentViewModel.kt
0 → 100644
View file @
5b1ce1b6
package
chat.rocket.android.chatroom.viewmodel
interface
BaseAttachmentViewModel
<
out
T
>
:
BaseViewModel
<
T
>
{
val
attachmentUrl
:
String
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/viewmodel/BaseFileAttachmentViewModel.kt
View file @
5b1ce1b6
package
chat.rocket.android.chatroom.viewmodel
interface
BaseFileAttachmentViewModel
<
out
T
>
:
BaseViewModel
<
T
>
{
val
attachmentUrl
:
String
interface
BaseFileAttachmentViewModel
<
out
T
>
:
BaseAttachmentViewModel
<
T
>
{
val
attachmentTitle
:
CharSequence
val
id
:
Long
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/viewmodel/BaseViewModel.kt
View file @
5b1ce1b6
...
...
@@ -20,7 +20,8 @@ interface BaseViewModel<out T> {
IMAGE_ATTACHMENT
(
3
),
VIDEO_ATTACHMENT
(
4
),
AUDIO_ATTACHMENT
(
5
),
MESSAGE_ATTACHMENT
(
6
)
MESSAGE_ATTACHMENT
(
6
),
AUTHOR_ATTACHMENT
(
7
)
}
}
...
...
app/src/main/java/chat/rocket/android/chatroom/viewmodel/ViewModelMapper.kt
View file @
5b1ce1b6
...
...
@@ -4,14 +4,20 @@ import DateTimeHelper
import
android.content.Context
import
android.graphics.Color
import
android.graphics.Typeface
import
android.support.v4.content.ContextCompat
import
android.text.SpannableStringBuilder
import
android.text.style.ForegroundColorSpan
import
android.text.style.StyleSpan
import
androidx.core.text.bold
import
androidx.core.text.buildSpannedString
import
androidx.core.text.color
import
androidx.core.text.scale
import
chat.rocket.android.R
import
chat.rocket.android.helper.MessageParser
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.server.domain.*
import
chat.rocket.android.util.extensions.avatarUrl
import
chat.rocket.android.util.extensions.isNotNullNorEmpty
import
chat.rocket.android.widget.emoji.EmojiParser
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.MessageType
...
...
@@ -39,6 +45,7 @@ class ViewModelMapper @Inject constructor(private val context: Context,
private
val
baseUrl
=
settings
.
baseUrl
()
private
val
token
=
tokenRepository
.
get
(
currentServer
)
private
val
currentUsername
:
String
?
=
localRepository
.
get
(
LocalRepository
.
CURRENT_USERNAME_KEY
)
private
val
secundaryTextColor
=
ContextCompat
.
getColor
(
context
,
R
.
color
.
colorSecondaryText
)
suspend
fun
map
(
message
:
Message
):
List
<
BaseViewModel
<*
>>
{
return
translate
(
message
)
...
...
@@ -98,10 +105,39 @@ class ViewModelMapper @Inject constructor(private val context: Context,
return
when
(
attachment
)
{
is
FileAttachment
->
mapFileAttachment
(
message
,
attachment
)
is
MessageAttachment
->
mapMessageAttachment
(
message
,
attachment
)
is
AuthorAttachment
->
mapAuthorAttachment
(
message
,
attachment
)
else
->
null
}
}
private
suspend
fun
mapAuthorAttachment
(
message
:
Message
,
attachment
:
AuthorAttachment
):
AuthorAttachmentViewModel
{
return
with
(
attachment
)
{
val
content
=
stripMessageQuotes
(
message
)
val
fieldsText
=
fields
?.
let
{
buildSpannedString
{
it
.
forEachIndexed
{
index
,
field
->
bold
{
append
(
field
.
title
)
}
append
(
"\n"
)
if
(
field
.
value
.
isNotEmpty
())
{
append
(
field
.
value
)
}
if
(
index
!=
it
.
size
-
1
)
{
// it is not the last one, append a new line
append
(
"\n\n"
)
}
}
}
}
val
id
=
attachmentId
(
message
,
attachment
)
AuthorAttachmentViewModel
(
attachmentUrl
=
url
,
id
=
id
,
name
=
authorName
,
icon
=
authorIcon
,
fields
=
fieldsText
,
message
=
message
,
rawData
=
attachment
,
messageId
=
message
.
id
,
reactions
=
getReactions
(
message
),
preview
=
message
.
copy
(
message
=
content
.
message
))
}
}
private
suspend
fun
mapMessageAttachment
(
message
:
Message
,
attachment
:
MessageAttachment
):
MessageAttachmentViewModel
{
val
attachmentAuthor
=
attachment
.
author
val
time
=
attachment
.
timestamp
?.
let
{
getTime
(
it
)
}
...
...
@@ -136,7 +172,7 @@ class ViewModelMapper @Inject constructor(private val context: Context,
}
}
private
fun
attachmentId
(
message
:
Message
,
attachment
:
File
Attachment
):
Long
{
private
fun
attachmentId
(
message
:
Message
,
attachment
:
Attachment
):
Long
{
return
"${message.id}_${attachment.url}"
.
hashCode
().
toLong
()
}
...
...
@@ -218,11 +254,21 @@ class ViewModelMapper @Inject constructor(private val context: Context,
}
private
fun
getSenderName
(
message
:
Message
):
CharSequence
{
if
(!
message
.
senderAlias
.
isNullOrEmpty
())
{
return
message
.
senderAlias
!!
val
username
=
message
.
sender
?.
username
message
.
senderAlias
.
isNotNullNorEmpty
{
alias
->
return
buildSpannedString
{
append
(
alias
)
username
?.
let
{
append
(
" "
)
scale
(
0.8f
)
{
color
(
secundaryTextColor
)
{
append
(
"@$username"
)
}
}
}
}
}
val
username
=
message
.
sender
?.
username
val
realName
=
message
.
sender
?.
name
val
senderName
=
if
(
settings
.
useRealName
())
realName
else
username
return
senderName
?:
username
.
toString
()
...
...
app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt
View file @
5b1ce1b6
...
...
@@ -5,7 +5,7 @@ import android.app.NotificationManager
import
android.arch.persistence.room.Room
import
android.content.Context
import
android.content.SharedPreferences
import
androidx.content.systemService
import
androidx.co
re.co
ntent.systemService
import
chat.rocket.android.BuildConfig
import
chat.rocket.android.R
import
chat.rocket.android.app.RocketChatDatabase
...
...
@@ -261,8 +261,7 @@ class AppModule {
SharedPreferencesAccountsRepository
(
preferences
,
moshi
)
@Provides
fun
provideNotificationManager
(
context
:
Context
):
NotificationManager
=
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
fun
provideNotificationManager
(
context
:
Context
):
NotificationManager
=
context
.
systemService
()
@Provides
@Singleton
...
...
app/src/main/java/chat/rocket/android/server/infraestructure/SharedPreferencesAccountsRepository.kt
View file @
5b1ce1b6
package
chat.rocket.android.server.infraestructure
import
android.content.SharedPreferences
import
androidx.content.edit
import
androidx.co
re.co
ntent.edit
import
chat.rocket.android.server.domain.AccountsRepository
import
chat.rocket.android.server.domain.model.Account
import
com.squareup.moshi.Moshi
...
...
app/src/main/java/chat/rocket/android/util/extensions/CharSequence.kt
0 → 100644
View file @
5b1ce1b6
package
chat.rocket.android.util.extensions
inline
fun
CharSequence
?.
isNotNullNorEmpty
(
block
:
(
CharSequence
)
->
Unit
)
{
if
(
this
!=
null
&&
this
.
isNotEmpty
())
{
block
(
this
)
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/webview/oauth/ui/OauthWebViewActivity.kt
View file @
5b1ce1b6
...
...
@@ -8,7 +8,7 @@ import android.os.Bundle
import
android.support.v7.app.AppCompatActivity
import
android.webkit.WebView
import
android.webkit.WebViewClient
import
androidx.net.toUri
import
androidx.
core.
net.toUri
import
chat.rocket.android.R
import
chat.rocket.android.util.extensions.decodeUrl
import
chat.rocket.android.util.extensions.toJsonObject
...
...
app/src/main/res/drawable/quote_vertical_bar.xml
View file @
5b1ce1b6
...
...
@@ -2,7 +2,7 @@
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:shape=
"rectangle"
>
<solid
android:color=
"@color/
colorPrimary
"
/>
<solid
android:color=
"@color/
quoteBar
"
/>
<size
android:width=
"4dp"
android:height=
"4dp"
/>
...
...
app/src/main/res/layout/item_author_attachment.xml
0 → 100644
View file @
5b1ce1b6
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/author_attachment_container"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:background=
"?android:attr/selectableItemBackground"
android:clickable=
"true"
android:focusable=
"true"
android:paddingBottom=
"@dimen/message_item_top_and_bottom_padding"
android:paddingEnd=
"@dimen/screen_edge_left_and_right_padding"
android:paddingStart=
"@dimen/screen_edge_left_and_right_padding"
android:paddingTop=
"@dimen/message_item_top_and_bottom_padding"
>
<View
android:id=
"@+id/quote_bar"
android:layout_width=
"4dp"
android:layout_height=
"0dp"
android:layout_marginStart=
"56dp"
android:background=
"@drawable/quote_vertical_bar"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintBottom_toTopOf=
"@+id/recycler_view_reactions"
/>
<com.facebook.drawee.view.SimpleDraweeView
android:id=
"@+id/author_icon"
android:layout_width=
"8dp"
android:layout_height=
"8dp"
android:layout_marginTop=
"6dp"
android:layout_marginStart=
"8dp"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintStart_toStartOf=
"@id/quote_bar"
tools:src=
"@tools:sample/avatars"
/>
<TextView
android:id=
"@+id/text_author_name"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"4dp"
android:textColor=
"@color/colorAccent"
android:textAppearance=
"@style/TextAppearance.AppCompat.Body2"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintStart_toEndOf=
"@id/author_icon"
app:layout_constraintEnd_toEndOf=
"parent"
tools:text=
"#5571 - User profile from SSO must not have password change option"
/>
<TextView
android:id=
"@+id/text_fields"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:visibility=
"gone"
android:layout_marginTop=
"4dp"
app:layout_constraintTop_toBottomOf=
"@id/text_author_name"
app:layout_constraintStart_toStartOf=
"@id/text_author_name"
app:layout_constraintEnd_toEndOf=
"parent"
tools:visibility=
"visible"
/>
<include
layout=
"@layout/layout_reactions"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
app:layout_constraintStart_toStartOf=
"@id/quote_bar"
app:layout_constraintTop_toBottomOf=
"@id/text_fields"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
app/src/main/res/values/colors.xml
View file @
5b1ce1b6
...
...
@@ -39,6 +39,8 @@
<color
name=
"colorEmojiIcon"
>
#FF767676
</color>
<color
name=
"quoteBar"
>
#A0A0A0
</color>
<!-- Suggestions -->
<color
name=
"suggestion_background_color"
>
@android:color/white
</color>
...
...
dependencies.gradle
View file @
5b1ce1b6
...
...
@@ -11,7 +11,7 @@ ext {
// Main dependencies
support
:
'27.1.0'
,
constraintLayout
:
'1.0.2'
,
androidKtx
:
'0.
2
'
,
androidKtx
:
'0.
3
'
,
dagger
:
'2.14.1'
,
exoPlayer
:
'2.6.0'
,
playServices
:
'11.8.0'
,
...
...
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