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
1880ace4
Commit
1880ace4
authored
Dec 19, 2016
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into feature/unread-mode
parents
4cd1a173
f91a845d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
111 additions
and
6 deletions
+111
-6
MainActivity.java
.../main/java/chat/rocket/android/activity/MainActivity.java
+1
-1
RoomFragment.java
...a/chat/rocket/android/fragment/chatroom/RoomFragment.java
+8
-0
MessageType.java
...hat/rocket/android/layouthelper/chatroom/MessageType.java
+12
-4
Linkify.java
.../main/java/chat/rocket/android/widget/helper/Linkify.java
+1
-1
MarkDown.java
...main/java/chat/rocket/android/widget/helper/MarkDown.java
+87
-0
RocketChatMessageLayout.java
...ocket/android/widget/message/RocketChatMessageLayout.java
+2
-0
No files found.
app/src/main/java/chat/rocket/android/activity/MainActivity.java
View file @
1880ace4
...
@@ -164,7 +164,7 @@ public class MainActivity extends AbstractAuthedActivity {
...
@@ -164,7 +164,7 @@ public class MainActivity extends AbstractAuthedActivity {
protected
void
onRoomIdUpdated
()
{
protected
void
onRoomIdUpdated
()
{
super
.
onRoomIdUpdated
();
super
.
onRoomIdUpdated
();
if
(
roomId
!=
null
)
{
if
(
roomId
!=
null
&&
RoomFragment
.
canCreate
(
RealmStore
.
get
(
serverConfigId
))
)
{
showFragment
(
RoomFragment
.
create
(
serverConfigId
,
roomId
));
showFragment
(
RoomFragment
.
create
(
serverConfigId
,
roomId
));
closeSidebarIfNeeded
();
closeSidebarIfNeeded
();
}
else
{
}
else
{
...
...
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomFragment.java
View file @
1880ace4
...
@@ -67,6 +67,14 @@ public class RoomFragment extends AbstractChatRoomFragment
...
@@ -67,6 +67,14 @@ public class RoomFragment extends AbstractChatRoomFragment
public
RoomFragment
()
{
public
RoomFragment
()
{
}
}
public
static
boolean
canCreate
(
RealmHelper
realmHelper
)
{
User
currentUser
=
realmHelper
.
executeTransactionForRead
(
realm
->
User
.
queryCurrentUser
(
realm
).
findFirst
());
Session
session
=
realmHelper
.
executeTransactionForRead
(
realm
->
Session
.
queryDefaultSession
(
realm
).
findFirst
());
return
currentUser
!=
null
&&
session
!=
null
;
}
/**
/**
* create fragment with roomId.
* create fragment with roomId.
*/
*/
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/MessageType.java
View file @
1880ace4
...
@@ -13,21 +13,21 @@ public enum MessageType {
...
@@ -13,21 +13,21 @@ public enum MessageType {
@Override
@Override
public
String
getString
(
Context
context
,
Message
message
)
{
public
String
getString
(
Context
context
,
Message
message
)
{
return
context
.
getString
(
R
.
string
.
message_room_name_changed
,
return
context
.
getString
(
R
.
string
.
message_room_name_changed
,
message
.
getMessage
(),
message
.
getUser
().
getUsername
(
));
message
.
getMessage
(),
getUsername
(
message
));
}
}
},
},
USER_ADDED
(
"au"
)
{
USER_ADDED
(
"au"
)
{
@Override
@Override
public
String
getString
(
Context
context
,
Message
message
)
{
public
String
getString
(
Context
context
,
Message
message
)
{
return
context
.
getString
(
R
.
string
.
message_user_added_by
,
return
context
.
getString
(
R
.
string
.
message_user_added_by
,
message
.
getMessage
(),
message
.
getUser
().
getUsername
(
));
message
.
getMessage
(),
getUsername
(
message
));
}
}
},
},
USER_REMOVED
(
"ru"
)
{
USER_REMOVED
(
"ru"
)
{
@Override
@Override
public
String
getString
(
Context
context
,
Message
message
)
{
public
String
getString
(
Context
context
,
Message
message
)
{
return
context
.
getString
(
R
.
string
.
message_user_removed_by
,
return
context
.
getString
(
R
.
string
.
message_user_removed_by
,
message
.
getMessage
(),
message
.
getUser
().
getUsername
(
));
message
.
getMessage
(),
getUsername
(
message
));
}
}
},
},
USER_JOINED
(
"uj"
)
{
USER_JOINED
(
"uj"
)
{
...
@@ -45,7 +45,7 @@ public enum MessageType {
...
@@ -45,7 +45,7 @@ public enum MessageType {
WELCOME
(
"wm"
)
{
WELCOME
(
"wm"
)
{
@Override
@Override
public
String
getString
(
Context
context
,
Message
message
)
{
public
String
getString
(
Context
context
,
Message
message
)
{
return
context
.
getString
(
R
.
string
.
message_welcome
,
message
.
getUser
().
getUsername
(
));
return
context
.
getString
(
R
.
string
.
message_welcome
,
getUsername
(
message
));
}
}
},
},
MESSAGE_REMOVED
(
"rm"
)
{
MESSAGE_REMOVED
(
"rm"
)
{
...
@@ -77,4 +77,12 @@ public enum MessageType {
...
@@ -77,4 +77,12 @@ public enum MessageType {
public
String
getString
(
Context
context
,
Message
message
)
{
public
String
getString
(
Context
context
,
Message
message
)
{
return
""
;
return
""
;
}
}
private
static
String
getUsername
(
Message
message
)
{
if
(
message
!=
null
&&
message
.
getUser
()
!=
null
)
{
return
message
.
getUser
().
getUsername
();
}
else
{
return
""
;
}
}
}
}
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/helper/Linkify.java
View file @
1880ace4
...
@@ -28,7 +28,7 @@ public class Linkify {
...
@@ -28,7 +28,7 @@ public class Linkify {
public
static
void
markup
(
TextView
textview
)
{
public
static
void
markup
(
TextView
textview
)
{
textview
.
setMovementMethod
(
LinkMovementMethodCompat
.
getInstance
());
textview
.
setMovementMethod
(
LinkMovementMethodCompat
.
getInstance
());
final
CharSequence
text
=
textview
.
getText
()
.
toString
()
;
final
CharSequence
text
=
textview
.
getText
();
textview
.
setText
(
markupInner
(
text
));
textview
.
setText
(
markupInner
(
text
));
}
}
...
...
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/helper/MarkDown.java
0 → 100644
View file @
1880ace4
package
chat
.
rocket
.
android
.
widget
.
helper
;
import
android.graphics.Typeface
;
import
android.text.SpannableString
;
import
android.text.Spanned
;
import
android.text.style.AbsoluteSizeSpan
;
import
android.text.style.StrikethroughSpan
;
import
android.text.style.StyleSpan
;
import
android.widget.TextView
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* supports only bold, italic, strike.
*/
public
class
MarkDown
{
/**
* transform MarkDown text into Spans.
*/
public
static
void
apply
(
TextView
textView
)
{
SpannableString
text
=
new
SpannableString
(
textView
.
getText
());
bold
(
text
);
italic
(
text
);
strike
(
text
);
textView
.
setText
(
text
);
}
private
static
void
bold
(
SpannableString
inputText
)
{
Pattern
boldPattern
=
Pattern
.
compile
(
"(^|>|[ >_~`])(\\*{1,2})[^\\*\\r\\n]+(\\*{1,2})([<_~`]|\\B|\\b|$)"
,
Pattern
.
MULTILINE
);
Matcher
matcher
=
boldPattern
.
matcher
(
inputText
);
while
(
matcher
.
find
())
{
setSpan
(
new
StyleSpan
(
Typeface
.
BOLD
),
inputText
,
matcher
.
start
()
+
matcher
.
group
(
1
).
length
(),
matcher
.
end
()
-
matcher
.
group
(
4
).
length
(),
matcher
.
group
(
2
).
length
(),
matcher
.
group
(
3
).
length
());
}
}
private
static
void
italic
(
SpannableString
inputText
)
{
Pattern
italicPattern
=
Pattern
.
compile
(
"(^|>|[ >*~`])(\\_)[^\\_\\r\\n]+(\\_)([<*~`]|\\B|\\b|$)"
,
Pattern
.
MULTILINE
);
Matcher
matcher
=
italicPattern
.
matcher
(
inputText
);
while
(
matcher
.
find
())
{
setSpan
(
new
StyleSpan
(
Typeface
.
ITALIC
),
inputText
,
matcher
.
start
()
+
matcher
.
group
(
1
).
length
(),
matcher
.
end
()
-
matcher
.
group
(
4
).
length
(),
matcher
.
group
(
2
).
length
(),
matcher
.
group
(
3
).
length
());
}
}
private
static
void
strike
(
SpannableString
inputText
)
{
Pattern
strikePattern
=
Pattern
.
compile
(
"(^|>|[ >_*`])(\\~{1,2})[^~\\r\\n]+(\\~{1,2})([<_*`]|\\B|\\b|$)"
,
Pattern
.
MULTILINE
);
Matcher
matcher
=
strikePattern
.
matcher
(
inputText
);
while
(
matcher
.
find
())
{
setSpan
(
new
StrikethroughSpan
(),
inputText
,
matcher
.
start
()
+
matcher
.
group
(
1
).
length
(),
matcher
.
end
()
-
matcher
.
group
(
4
).
length
(),
matcher
.
group
(
2
).
length
(),
matcher
.
group
(
3
).
length
());
}
}
private
static
void
setSpan
(
Object
span
,
SpannableString
inputText
,
int
start
,
int
end
,
int
markStartLen
,
int
markEndLen
)
{
if
(
markStartLen
>
0
)
{
inputText
.
setSpan
(
new
AbsoluteSizeSpan
(
0
),
start
,
start
+
markStartLen
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
inputText
.
setSpan
(
span
,
start
+
markStartLen
,
end
-
markEndLen
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
if
(
markEndLen
>
0
)
{
inputText
.
setSpan
(
new
AbsoluteSizeSpan
(
0
),
end
-
markEndLen
,
end
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
}
}
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/RocketChatMessageLayout.java
View file @
1880ace4
...
@@ -13,6 +13,7 @@ import com.emojione.Emojione;
...
@@ -13,6 +13,7 @@ import com.emojione.Emojione;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.helper.InlineHightlighter
;
import
chat.rocket.android.widget.helper.InlineHightlighter
;
import
chat.rocket.android.widget.helper.Linkify
;
import
chat.rocket.android.widget.helper.Linkify
;
import
chat.rocket.android.widget.helper.MarkDown
;
/**
/**
*/
*/
...
@@ -77,6 +78,7 @@ public class RocketChatMessageLayout extends LinearLayout {
...
@@ -77,6 +78,7 @@ public class RocketChatMessageLayout extends LinearLayout {
TextView
textView
=
(
TextView
)
inflater
.
inflate
(
R
.
layout
.
message_body
,
this
,
false
);
TextView
textView
=
(
TextView
)
inflater
.
inflate
(
R
.
layout
.
message_body
,
this
,
false
);
textView
.
setText
(
Emojione
.
shortnameToUnicode
(
text
,
false
));
textView
.
setText
(
Emojione
.
shortnameToUnicode
(
text
,
false
));
MarkDown
.
apply
(
textView
);
Linkify
.
markup
(
textView
);
Linkify
.
markup
(
textView
);
InlineHightlighter
.
highlight
(
textView
);
InlineHightlighter
.
highlight
(
textView
);
...
...
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