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
c77a90ae
Commit
c77a90ae
authored
Dec 19, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FIX #86 render system message.
parent
9b1ba0df
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
311 additions
and
49 deletions
+311
-49
AbstractMessageViewHolder.java
...roid/layouthelper/chatroom/AbstractMessageViewHolder.java
+36
-44
MessageListAdapter.java
...ket/android/layouthelper/chatroom/MessageListAdapter.java
+37
-5
MessageNormalViewHolder.java
...ndroid/layouthelper/chatroom/MessageNormalViewHolder.java
+40
-0
MessageSystemViewHolder.java
...ndroid/layouthelper/chatroom/MessageSystemViewHolder.java
+35
-0
MessageType.java
...hat/rocket/android/layouthelper/chatroom/MessageType.java
+80
-0
list_item_normal_message.xml
app/src/main/res/layout/list_item_normal_message.xml
+0
-0
list_item_system_message.xml
app/src/main/res/layout/list_item_system_message.xml
+73
-0
system_message_strings.xml
app/src/main/res/values/system_message_strings.xml
+10
-0
No files found.
app/src/main/java/chat/rocket/android/layouthelper/chatroom/MessageViewHolder.java
→
app/src/main/java/chat/rocket/android/layouthelper/chatroom/
Abstract
MessageViewHolder.java
View file @
c77a90ae
...
...
@@ -10,41 +10,27 @@ import chat.rocket.android.helper.DateTime;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.model.SyncState
;
import
chat.rocket.android.realm_helper.RealmModelViewHolder
;
import
chat.rocket.android.renderer.MessageRenderer
;
import
chat.rocket.android.widget.message.RocketChatMessageAttachmentsLayout
;
import
chat.rocket.android.widget.message.RocketChatMessageLayout
;
import
chat.rocket.android.widget.message.RocketChatMessageUrlsLayout
;
/**
* View holder of NORMAL chat message.
*/
public
class
MessageViewHolder
extends
RealmModelViewHolder
<
PairedMessage
>
{
private
final
ImageView
avatar
;
private
final
TextView
username
;
private
final
TextView
timestamp
;
private
final
View
userAndTimeContainer
;
private
final
String
hostname
;
private
final
String
userId
;
private
final
String
token
;
private
final
RocketChatMessageLayout
body
;
private
final
RocketChatMessageUrlsLayout
urls
;
private
final
RocketChatMessageAttachmentsLayout
attachments
;
private
final
View
newDayContainer
;
private
final
TextView
newDayText
;
public
abstract
class
AbstractMessageViewHolder
extends
RealmModelViewHolder
<
PairedMessage
>
{
protected
final
ImageView
avatar
;
protected
final
TextView
username
;
protected
final
TextView
timestamp
;
protected
final
View
userAndTimeContainer
;
protected
final
String
hostname
;
protected
final
String
userId
;
protected
final
String
token
;
protected
final
View
newDayContainer
;
protected
final
TextView
newDayText
;
/**
* constructor WITH hostname.
*/
public
MessageViewHolder
(
View
itemView
,
String
hostname
,
String
userId
,
String
token
)
{
public
Abstract
MessageViewHolder
(
View
itemView
,
String
hostname
,
String
userId
,
String
token
)
{
super
(
itemView
);
avatar
=
(
ImageView
)
itemView
.
findViewById
(
R
.
id
.
user_avatar
);
username
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
username
);
timestamp
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
timestamp
);
userAndTimeContainer
=
itemView
.
findViewById
(
R
.
id
.
user_and_timestamp_container
);
body
=
(
RocketChatMessageLayout
)
itemView
.
findViewById
(
R
.
id
.
message_body
);
urls
=
(
RocketChatMessageUrlsLayout
)
itemView
.
findViewById
(
R
.
id
.
message_urls
);
attachments
=
(
RocketChatMessageAttachmentsLayout
)
itemView
.
findViewById
(
R
.
id
.
message_attachments
);
newDayContainer
=
itemView
.
findViewById
(
R
.
id
.
newday_container
);
newDayText
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
newday_text
);
this
.
hostname
=
hostname
;
...
...
@@ -55,14 +41,8 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> {
/**
* bind the view model.
*/
public
void
bind
(
PairedMessage
pairedMessage
)
{
new
MessageRenderer
(
itemView
.
getContext
(),
pairedMessage
.
target
)
.
avatarInto
(
avatar
,
hostname
)
.
usernameInto
(
username
)
.
timestampInto
(
timestamp
)
.
bodyInto
(
body
)
.
urlsInto
(
urls
)
.
attachmentsInto
(
attachments
,
hostname
,
userId
,
token
);
public
final
void
bind
(
PairedMessage
pairedMessage
)
{
bindMessage
(
pairedMessage
);
if
(
pairedMessage
.
target
!=
null
)
{
int
syncstate
=
pairedMessage
.
target
.
getSyncState
();
...
...
@@ -76,6 +56,8 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> {
renderNewDayAndSequential
(
pairedMessage
);
}
protected
abstract
void
bindMessage
(
PairedMessage
pairedMessage
);
private
void
renderNewDayAndSequential
(
PairedMessage
pairedMessage
)
{
//see Rocket.Chat:packages/rocketchat-livechat/app/client/views/message.coffee
if
(!
pairedMessage
.
hasSameDate
())
{
...
...
@@ -92,16 +74,25 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> {
}
private
void
setSequential
(
boolean
sequential
)
{
if
(
avatar
!=
null
)
{
if
(
sequential
)
{
avatar
.
setVisibility
(
View
.
INVISIBLE
);
userAndTimeContainer
.
setVisibility
(
View
.
GONE
);
}
else
{
avatar
.
setVisibility
(
View
.
VISIBLE
);
}
}
if
(
userAndTimeContainer
!=
null
)
{
if
(
sequential
)
{
userAndTimeContainer
.
setVisibility
(
View
.
GONE
);
}
else
{
userAndTimeContainer
.
setVisibility
(
View
.
VISIBLE
);
}
}
}
private
void
setNewDay
(
@Nullable
String
text
)
{
if
(
newDayContainer
!=
null
)
{
if
(
TextUtils
.
isEmpty
(
text
))
{
newDayContainer
.
setVisibility
(
View
.
GONE
);
}
else
{
...
...
@@ -109,4 +100,5 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> {
newDayContainer
.
setVisibility
(
View
.
VISIBLE
);
}
}
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/MessageListAdapter.java
View file @
c77a90ae
...
...
@@ -7,6 +7,7 @@ import java.util.ArrayList;
import
java.util.Collections
;
import
java.util.List
;
import
chat.rocket.android.R
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.layouthelper.ExtRealmModelListAdapter
;
import
chat.rocket.android.model.ddp.Message
;
...
...
@@ -14,7 +15,12 @@ import chat.rocket.android.model.ddp.Message;
* target list adapter for chat room.
*/
public
class
MessageListAdapter
extends
ExtRealmModelListAdapter
<
Message
,
PairedMessage
,
MessageViewHolder
>
{
extends
ExtRealmModelListAdapter
<
Message
,
PairedMessage
,
AbstractMessageViewHolder
>
{
private
static
final
int
VIEW_TYPE_UNKNOWN
=
0
;
private
static
final
int
VIEW_TYPE_NORMAL_MESSAGE
=
1
;
private
static
final
int
VIEW_TYPE_SYSTEM_MESSAGE
=
2
;
private
final
String
hostname
;
private
final
String
userId
;
private
final
String
token
;
...
...
@@ -53,17 +59,43 @@ public class MessageListAdapter
@Override
protected
int
getRealmModelViewType
(
PairedMessage
model
)
{
return
0
;
if
(
model
.
target
!=
null
)
{
if
(
TextUtils
.
isEmpty
(
model
.
target
.
getType
()))
{
return
VIEW_TYPE_NORMAL_MESSAGE
;
}
else
{
return
VIEW_TYPE_SYSTEM_MESSAGE
;
}
}
return
VIEW_TYPE_UNKNOWN
;
}
@Override
protected
int
getRealmModelLayout
(
int
viewType
)
{
return
R
.
layout
.
list_item_message
;
switch
(
viewType
)
{
case
VIEW_TYPE_NORMAL_MESSAGE:
return
R
.
layout
.
list_item_normal_message
;
case
VIEW_TYPE_SYSTEM_MESSAGE:
return
R
.
layout
.
list_item_system_message
;
default
:
return
R
.
layout
.
simple_screen
;
}
}
@Override
protected
MessageViewHolder
onCreateRealmModelViewHolder
(
int
viewType
,
View
itemView
)
{
return
new
MessageViewHolder
(
itemView
,
hostname
,
userId
,
token
);
protected
AbstractMessageViewHolder
onCreateRealmModelViewHolder
(
int
viewType
,
View
itemView
)
{
switch
(
viewType
)
{
case
VIEW_TYPE_NORMAL_MESSAGE:
return
new
MessageNormalViewHolder
(
itemView
,
hostname
,
userId
,
token
);
case
VIEW_TYPE_SYSTEM_MESSAGE:
return
new
MessageSystemViewHolder
(
itemView
,
hostname
,
userId
,
token
);
default
:
return
new
AbstractMessageViewHolder
(
itemView
,
hostname
,
userId
,
token
)
{
@Override
protected
void
bindMessage
(
PairedMessage
pairedMessage
)
{
}
};
}
}
@Override
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/MessageNormalViewHolder.java
0 → 100644
View file @
c77a90ae
package
chat
.
rocket
.
android
.
layouthelper
.
chatroom
;
import
android.view.View
;
import
chat.rocket.android.R
;
import
chat.rocket.android.renderer.MessageRenderer
;
import
chat.rocket.android.widget.message.RocketChatMessageAttachmentsLayout
;
import
chat.rocket.android.widget.message.RocketChatMessageLayout
;
import
chat.rocket.android.widget.message.RocketChatMessageUrlsLayout
;
/**
* View holder of NORMAL chat message.
*/
public
class
MessageNormalViewHolder
extends
AbstractMessageViewHolder
{
private
final
RocketChatMessageLayout
body
;
private
final
RocketChatMessageUrlsLayout
urls
;
private
final
RocketChatMessageAttachmentsLayout
attachments
;
/**
* constructor WITH hostname.
*/
public
MessageNormalViewHolder
(
View
itemView
,
String
hostname
,
String
userId
,
String
token
)
{
super
(
itemView
,
hostname
,
userId
,
token
);
body
=
(
RocketChatMessageLayout
)
itemView
.
findViewById
(
R
.
id
.
message_body
);
urls
=
(
RocketChatMessageUrlsLayout
)
itemView
.
findViewById
(
R
.
id
.
message_urls
);
attachments
=
(
RocketChatMessageAttachmentsLayout
)
itemView
.
findViewById
(
R
.
id
.
message_attachments
);
}
@Override
protected
void
bindMessage
(
PairedMessage
pairedMessage
)
{
new
MessageRenderer
(
itemView
.
getContext
(),
pairedMessage
.
target
)
.
avatarInto
(
avatar
,
hostname
)
.
usernameInto
(
username
)
.
timestampInto
(
timestamp
)
.
bodyInto
(
body
)
.
urlsInto
(
urls
)
.
attachmentsInto
(
attachments
,
hostname
,
userId
,
token
);
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/MessageSystemViewHolder.java
0 → 100644
View file @
c77a90ae
package
chat
.
rocket
.
android
.
layouthelper
.
chatroom
;
import
android.view.View
;
import
android.widget.TextView
;
import
chat.rocket.android.R
;
import
chat.rocket.android.renderer.MessageRenderer
;
/**
* View holder of NORMAL chat message.
*/
public
class
MessageSystemViewHolder
extends
AbstractMessageViewHolder
{
private
final
TextView
body
;
/**
* constructor WITH hostname.
*/
public
MessageSystemViewHolder
(
View
itemView
,
String
hostname
,
String
userId
,
String
token
)
{
super
(
itemView
,
hostname
,
userId
,
token
);
body
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
message_body
);
}
@Override
protected
void
bindMessage
(
PairedMessage
pairedMessage
)
{
new
MessageRenderer
(
itemView
.
getContext
(),
pairedMessage
.
target
)
.
avatarInto
(
avatar
,
hostname
)
.
usernameInto
(
username
)
.
timestampInto
(
timestamp
);
if
(
pairedMessage
.
target
!=
null
)
{
body
.
setText
(
MessageType
.
parse
(
pairedMessage
.
target
.
getType
())
.
getString
(
body
.
getContext
(),
pairedMessage
.
target
));
}
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/MessageType.java
0 → 100644
View file @
c77a90ae
package
chat
.
rocket
.
android
.
layouthelper
.
chatroom
;
import
android.content.Context
;
import
chat.rocket.android.R
;
import
chat.rocket.android.model.ddp.Message
;
/**
* message type.
*/
public
enum
MessageType
{
ROOM_NAME_CHANGED
(
"r"
)
{
@Override
public
String
getString
(
Context
context
,
Message
message
)
{
return
context
.
getString
(
R
.
string
.
message_room_name_changed
,
message
.
getMessage
(),
message
.
getUser
().
getUsername
());
}
},
USER_ADDED
(
"au"
)
{
@Override
public
String
getString
(
Context
context
,
Message
message
)
{
return
context
.
getString
(
R
.
string
.
message_user_added_by
,
message
.
getMessage
(),
message
.
getUser
().
getUsername
());
}
},
USER_REMOVED
(
"ru"
)
{
@Override
public
String
getString
(
Context
context
,
Message
message
)
{
return
context
.
getString
(
R
.
string
.
message_user_removed_by
,
message
.
getMessage
(),
message
.
getUser
().
getUsername
());
}
},
USER_JOINED
(
"uj"
)
{
@Override
public
String
getString
(
Context
context
,
Message
message
)
{
return
context
.
getString
(
R
.
string
.
message_user_joined_channel
);
}
},
USER_LEFT
(
"ul"
)
{
@Override
public
String
getString
(
Context
context
,
Message
message
)
{
return
context
.
getString
(
R
.
string
.
message_user_left
);
}
},
WELCOME
(
"wm"
)
{
@Override
public
String
getString
(
Context
context
,
Message
message
)
{
return
context
.
getString
(
R
.
string
.
message_welcome
,
message
.
getUser
().
getUsername
());
}
},
MESSAGE_REMOVED
(
"rm"
)
{
@Override
public
String
getString
(
Context
context
,
Message
message
)
{
return
context
.
getString
(
R
.
string
.
message_removed
);
}
},
UNSPECIFIED
(
""
);
//------------
private
final
String
value
;
MessageType
(
String
value
)
{
this
.
value
=
value
;
}
public
String
getValue
()
{
return
value
;
}
public
static
MessageType
parse
(
String
value
)
{
for
(
MessageType
type
:
MessageType
.
values
())
{
if
(
type
.
value
.
equals
(
value
))
return
type
;
}
return
UNSPECIFIED
;
}
public
String
getString
(
Context
context
,
Message
message
)
{
return
""
;
}
}
app/src/main/res/layout/list_item_message.xml
→
app/src/main/res/layout/list_item_
normal_
message.xml
View file @
c77a90ae
File moved
app/src/main/res/layout/list_item_system_message.xml
0 → 100644
View file @
c77a90ae
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
android:theme=
"@style/AppTheme"
>
<include
layout=
"@layout/list_item_message_newday"
/>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
>
<ImageView
android:id=
"@+id/user_avatar"
android:layout_width=
"32dp"
android:layout_height=
"32dp"
android:layout_margin=
"8dp"
tools:src=
"@drawable/ic_default_avatar"
/>
<LinearLayout
android:layout_width=
"0px"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"8dp"
android:layout_weight=
"1"
android:orientation=
"vertical"
>
<LinearLayout
android:id=
"@+id/user_and_timestamp_container"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
>
<TextView
android:id=
"@+id/username"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textStyle=
"bold"
tools:text=
"John Doe"
/>
<Space
android:layout_width=
"@dimen/margin_8"
android:layout_height=
"wrap_content"
/>
<TextView
android:id=
"@+id/timestamp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:enabled=
"false"
tools:text=
"12:34"
/>
</LinearLayout>
<TextView
android:id=
"@+id/message_body"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:textAppearance=
"@style/TextAppearance.AppCompat.Body1"
android:textStyle=
"italic"
android:enabled=
"false"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
app/src/main/res/values/system_message_strings.xml
0 → 100644
View file @
c77a90ae
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name=
"message_room_name_changed"
>
Room name changed to: %1$s by %2$s
</string>
<string
name=
"message_user_added_by"
>
User %1$s added by %2$s
</string>
<string
name=
"message_user_removed_by"
>
User %1$s removed by %2$s
</string>
<string
name=
"message_user_left"
>
Has left the channel.
</string>
<string
name=
"message_user_joined_channel"
>
Has joined the channel.
</string>
<string
name=
"message_welcome"
>
Welcome %s
</string>
<string
name=
"message_removed"
>
Message removed
</string>
</resources>
\ 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