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
00278aaf
Commit
00278aaf
authored
Jan 17, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Honor use real name setting
parent
b0d03bea
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
10 deletions
+32
-10
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+9
-1
ChatRoomView.kt
...chat/rocket/android/chatroom/presentation/ChatRoomView.kt
+3
-1
ChatRoomAdapter.kt
...n/java/chat/rocket/android/chatroom/ui/ChatRoomAdapter.kt
+17
-6
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+3
-2
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
00278aaf
...
...
@@ -2,6 +2,7 @@ package chat.rocket.android.chatroom.presentation
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.server.domain.GetCurrentServerInteractor
import
chat.rocket.android.server.domain.GetSettingsInteractor
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.launchUI
import
chat.rocket.common.model.BaseRoom
...
...
@@ -11,6 +12,7 @@ import chat.rocket.core.internal.realtime.unsubscibre
import
chat.rocket.core.internal.rest.messages
import
chat.rocket.core.internal.rest.sendMessage
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Value
import
kotlinx.coroutines.experimental.CommonPool
import
kotlinx.coroutines.experimental.launch
import
timber.log.Timber
...
...
@@ -18,11 +20,17 @@ import javax.inject.Inject
class
ChatRoomPresenter
@Inject
constructor
(
private
val
view
:
ChatRoomView
,
private
val
strategy
:
CancelStrategy
,
getSettingsInteractor
:
GetSettingsInteractor
,
private
val
serverInteractor
:
GetCurrentServerInteractor
,
factory
:
RocketChatClientFactory
)
{
private
val
client
=
factory
.
create
(
serverInteractor
.
get
()
!!
)
private
val
roomMessages
=
ArrayList
<
Message
>()
private
var
subId
:
String
?
=
null
private
var
settings
:
Map
<
String
,
Value
<
Any
>>?
=
null
init
{
settings
=
getSettingsInteractor
.
get
(
serverInteractor
.
get
()
!!
)
}
fun
loadMessages
(
chatRoomId
:
String
,
chatRoomType
:
String
,
offset
:
Int
=
0
)
{
launchUI
(
strategy
)
{
...
...
@@ -32,7 +40,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
synchronized
(
roomMessages
)
{
roomMessages
.
addAll
(
messages
)
}
view
.
showMessages
(
messages
,
serverInteractor
.
get
()
!!
)
view
.
showMessages
(
messages
,
serverInteractor
.
get
()
!!
,
settings
)
}
catch
(
ex
:
Exception
)
{
ex
.
printStackTrace
()
ex
.
message
?.
let
{
...
...
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomView.kt
View file @
00278aaf
...
...
@@ -3,6 +3,7 @@ package chat.rocket.android.chatroom.presentation
import
chat.rocket.android.core.behaviours.LoadingView
import
chat.rocket.android.core.behaviours.MessageView
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Value
interface
ChatRoomView
:
LoadingView
,
MessageView
{
...
...
@@ -11,8 +12,9 @@ interface ChatRoomView : LoadingView, MessageView {
*
* @param dataSet The data set to show.
* @param serverUrl The server URL.
* @param settings The server settings.
*/
fun
showMessages
(
dataSet
:
List
<
Message
>,
serverUrl
:
String
)
fun
showMessages
(
dataSet
:
List
<
Message
>,
serverUrl
:
String
,
settings
:
Map
<
String
,
Value
<
Any
>>?
)
/**
* Send a message to a chat room.
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomAdapter.kt
View file @
00278aaf
...
...
@@ -9,17 +9,20 @@ import android.widget.ImageView
import
android.widget.TextView
import
chat.rocket.android.R
import
chat.rocket.android.helper.UrlHelper
import
chat.rocket.android.server.domain.USE_REALNAME
import
chat.rocket.android.util.inflate
import
chat.rocket.android.util.setVisibility
import
chat.rocket.android.util.textContent
import
chat.rocket.common.util.ifNull
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Value
import
com.facebook.drawee.view.SimpleDraweeView
import
kotlinx.android.synthetic.main.avatar.view.*
import
kotlinx.android.synthetic.main.item_message.view.*
class
ChatRoomAdapter
(
private
val
context
:
Context
,
private
val
serverUrl
:
String
)
:
RecyclerView
.
Adapter
<
ChatRoomAdapter
.
ViewHolder
>()
{
private
val
serverUrl
:
String
,
private
val
settings
:
Map
<
String
,
Value
<
Any
>>?)
:
RecyclerView
.
Adapter
<
ChatRoomAdapter
.
ViewHolder
>()
{
init
{
setHasStableIds
(
true
)
...
...
@@ -74,12 +77,20 @@ class ChatRoomAdapter(private val context: Context,
imageUnknownAvatar
.
setVisibility
(
true
)
}
private
fun
bindUserName
(
message
:
Message
,
textView
:
TextView
)
=
message
.
sender
?.
username
.
let
{
textView
.
textContent
=
it
.
toString
()
}.
ifNull
{
textView
.
textContent
=
context
.
getString
(
R
.
string
.
msg_unknown
)
}
private
fun
bindUserName
(
message
:
Message
,
textView
:
TextView
)
{
val
useRealName
=
settings
?.
get
(
USE_REALNAME
)
?.
value
as
Boolean
val
realName
=
message
.
sender
?.
name
val
username
=
message
.
sender
?.
username
val
senderName
=
if
(
useRealName
)
realName
else
username
senderName
.
let
{
// TODO: Fallback to username if real name happens to be null. ATM this could happen if the
// present message is a system message. We should handle that on the SDK
textView
.
textContent
=
if
(
senderName
==
null
)
username
.
toString
()
else
it
.
toString
()
}.
ifNull
{
textView
.
textContent
=
context
.
getString
(
R
.
string
.
msg_unknown
)
}
}
private
fun
bindTime
(
message
:
Message
,
textView
:
TextView
)
{
textView
.
textContent
=
DateTimeHelper
.
getTime
(
DateTimeHelper
.
getLocalDateTime
(
message
.
timestamp
))
}
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
00278aaf
...
...
@@ -17,6 +17,7 @@ import chat.rocket.android.util.inflate
import
chat.rocket.android.util.setVisibility
import
chat.rocket.android.util.textContent
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Value
import
dagger.android.support.AndroidSupportInjection
import
kotlinx.android.synthetic.main.fragment_chat_room.*
import
kotlinx.android.synthetic.main.message_composer.*
...
...
@@ -76,10 +77,10 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
super
.
onDestroyView
()
}
override
fun
showMessages
(
dataSet
:
List
<
Message
>,
serverUrl
:
String
)
{
override
fun
showMessages
(
dataSet
:
List
<
Message
>,
serverUrl
:
String
,
settings
:
Map
<
String
,
Value
<
Any
>>?
)
{
activity
?.
apply
{
if
(
recycler_view
.
adapter
==
null
)
{
adapter
=
ChatRoomAdapter
(
this
,
serverUrl
)
adapter
=
ChatRoomAdapter
(
this
,
serverUrl
,
settings
)
recycler_view
.
adapter
=
adapter
val
linearLayoutManager
=
LinearLayoutManager
(
context
,
LinearLayoutManager
.
VERTICAL
,
true
)
recycler_view
.
layoutManager
=
linearLayoutManager
...
...
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