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
97d8fa39
Commit
97d8fa39
authored
Jan 17, 2017
by
Tiago Cunha
Committed by
GitHub
Jan 17, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into fix/validate-server-with-insecure-connection
parents
c747aabc
3185bcc9
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
137 additions
and
1 deletion
+137
-1
build.gradle
app/build.gradle
+1
-1
MainActivity.java
.../main/java/chat/rocket/android/activity/MainActivity.java
+48
-0
dependencies.gradle
dependencies.gradle
+1
-0
build.gradle
rocket-chat-android-widgets/build.gradle
+1
-0
RoomToolbar.java
...src/main/java/chat/rocket/android/widget/RoomToolbar.java
+75
-0
badge_without_number.xml
...id-widgets/src/main/res/drawable/badge_without_number.xml
+6
-0
badge_styles.xml
...chat-android-widgets/src/main/res/values/badge_styles.xml
+5
-0
No files found.
app/build.gradle
View file @
97d8fa39
...
@@ -121,7 +121,7 @@ dependencies {
...
@@ -121,7 +121,7 @@ dependencies {
compile
'com.trello:rxlifecycle-android:1.0'
compile
'com.trello:rxlifecycle-android:1.0'
compile
'com.trello:rxlifecycle-components:1.0'
compile
'com.trello:rxlifecycle-components:1.0'
compile
'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
compile
rootProject
.
ext
.
textDrawable
compile
'frankiesardo:icepick:3.2.0'
compile
'frankiesardo:icepick:3.2.0'
provided
'frankiesardo:icepick-processor:3.2.0'
provided
'frankiesardo:icepick-processor:3.2.0'
...
...
app/src/main/java/chat/rocket/android/activity/MainActivity.java
View file @
97d8fa39
...
@@ -8,6 +8,7 @@ import android.support.v7.graphics.drawable.DrawerArrowDrawable;
...
@@ -8,6 +8,7 @@ import android.support.v7.graphics.drawable.DrawerArrowDrawable;
import
android.support.v7.widget.Toolbar
;
import
android.support.v7.widget.Toolbar
;
import
android.view.View
;
import
android.view.View
;
import
java.util.List
;
import
chat.rocket.android.LaunchUtil
;
import
chat.rocket.android.LaunchUtil
;
import
chat.rocket.android.R
;
import
chat.rocket.android.R
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.api.MethodCallHelper
;
...
@@ -17,11 +18,14 @@ import chat.rocket.android.fragment.sidebar.SidebarMainFragment;
...
@@ -17,11 +18,14 @@ import chat.rocket.android.fragment.sidebar.SidebarMainFragment;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.model.ddp.RoomSubscription
;
import
chat.rocket.android.model.ddp.User
;
import
chat.rocket.android.model.ddp.User
;
import
chat.rocket.android.model.internal.Session
;
import
chat.rocket.android.model.internal.Session
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmListObserver
;
import
chat.rocket.android.realm_helper.RealmObjectObserver
;
import
chat.rocket.android.realm_helper.RealmObjectObserver
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
chat.rocket.android.widget.RoomToolbar
;
import
hugo.weaving.DebugLog
;
import
hugo.weaving.DebugLog
;
/**
/**
...
@@ -30,6 +34,7 @@ import hugo.weaving.DebugLog;
...
@@ -30,6 +34,7 @@ import hugo.weaving.DebugLog;
public
class
MainActivity
extends
AbstractAuthedActivity
{
public
class
MainActivity
extends
AbstractAuthedActivity
{
private
RealmObjectObserver
<
Session
>
sessionObserver
;
private
RealmObjectObserver
<
Session
>
sessionObserver
;
private
RealmListObserver
<
RoomSubscription
>
unreadRoomSubscriptionObserver
;
private
boolean
isForeground
;
private
boolean
isForeground
;
private
StatusTicker
statusTicker
;
private
StatusTicker
statusTicker
;
...
@@ -150,6 +155,7 @@ public class MainActivity extends AbstractAuthedActivity {
...
@@ -150,6 +155,7 @@ public class MainActivity extends AbstractAuthedActivity {
protected
void
onServerConfigIdUpdated
()
{
protected
void
onServerConfigIdUpdated
()
{
super
.
onServerConfigIdUpdated
();
super
.
onServerConfigIdUpdated
();
updateSessionObserver
();
updateSessionObserver
();
updateUnreadRoomSubscriptionObserver
();
updateSidebarMainFragment
();
updateSidebarMainFragment
();
}
}
...
@@ -207,6 +213,44 @@ public class MainActivity extends AbstractAuthedActivity {
...
@@ -207,6 +213,44 @@ public class MainActivity extends AbstractAuthedActivity {
}
}
}
}
private
void
updateUnreadRoomSubscriptionObserver
()
{
if
(
unreadRoomSubscriptionObserver
!=
null
)
{
unreadRoomSubscriptionObserver
.
unsub
();
unreadRoomSubscriptionObserver
=
null
;
}
if
(
serverConfigId
==
null
)
{
return
;
}
RealmHelper
realmHelper
=
RealmStore
.
get
(
serverConfigId
);
if
(
realmHelper
==
null
)
{
return
;
}
unreadRoomSubscriptionObserver
=
realmHelper
.
createListObserver
(
realm
->
realm
.
where
(
RoomSubscription
.
class
)
.
equalTo
(
RoomSubscription
.
ALERT
,
true
)
.
equalTo
(
RoomSubscription
.
OPEN
,
true
)
.
findAll
())
.
setOnUpdateListener
(
this
::
updateRoomToolbarUnreadCount
);
unreadRoomSubscriptionObserver
.
sub
();
}
private
void
updateRoomToolbarUnreadCount
(
List
<
RoomSubscription
>
unreadRooms
)
{
RoomToolbar
toolbar
=
(
RoomToolbar
)
findViewById
(
R
.
id
.
activity_main_toolbar
);
if
(
toolbar
!=
null
)
{
//ref: Rocket.Chat:client/startup/unread.js
final
int
numUnreadChannels
=
unreadRooms
.
size
();
int
numMentionsSum
=
0
;
for
(
RoomSubscription
room
:
unreadRooms
)
{
numMentionsSum
+=
room
.
getUnread
();
}
toolbar
.
setUnreadBudge
(
numUnreadChannels
,
numMentionsSum
);
}
}
private
void
updateSidebarMainFragment
()
{
private
void
updateSidebarMainFragment
()
{
getSupportFragmentManager
().
beginTransaction
()
getSupportFragmentManager
().
beginTransaction
()
.
replace
(
R
.
id
.
sidebar_fragment_container
,
SidebarMainFragment
.
create
(
serverConfigId
))
.
replace
(
R
.
id
.
sidebar_fragment_container
,
SidebarMainFragment
.
create
(
serverConfigId
))
...
@@ -231,6 +275,10 @@ public class MainActivity extends AbstractAuthedActivity {
...
@@ -231,6 +275,10 @@ public class MainActivity extends AbstractAuthedActivity {
sessionObserver
.
unsub
();
sessionObserver
.
unsub
();
sessionObserver
=
null
;
sessionObserver
=
null
;
}
}
if
(
unreadRoomSubscriptionObserver
!=
null
)
{
unreadRoomSubscriptionObserver
.
unsub
();
unreadRoomSubscriptionObserver
=
null
;
}
super
.
onDestroy
();
super
.
onDestroy
();
}
}
...
...
dependencies.gradle
View file @
97d8fa39
...
@@ -18,6 +18,7 @@ ext {
...
@@ -18,6 +18,7 @@ ext {
okhttp3
=
'com.squareup.okhttp3:okhttp:3.4.1'
okhttp3
=
'com.squareup.okhttp3:okhttp:3.4.1'
picasso
=
'com.squareup.picasso:picasso:2.5.2'
picasso
=
'com.squareup.picasso:picasso:2.5.2'
picasso2Okhttp3Downloader
=
'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
picasso2Okhttp3Downloader
=
'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
textDrawable
=
'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
preDexLibs
=
!
"true"
.
equals
(
System
.
getenv
(
"CI"
))
preDexLibs
=
!
"true"
.
equals
(
System
.
getenv
(
"CI"
))
}
}
...
...
rocket-chat-android-widgets/build.gradle
View file @
97d8fa39
...
@@ -35,6 +35,7 @@ dependencies {
...
@@ -35,6 +35,7 @@ dependencies {
compile
rootProject
.
ext
.
supportAppCompat
compile
rootProject
.
ext
.
supportAppCompat
compile
rootProject
.
ext
.
supportDesign
compile
rootProject
.
ext
.
supportDesign
compile
'org.nibor.autolink:autolink:0.5.0'
compile
'org.nibor.autolink:autolink:0.5.0'
compile
rootProject
.
ext
.
textDrawable
compile
rootProject
.
ext
.
okhttp3
compile
rootProject
.
ext
.
okhttp3
compile
rootProject
.
ext
.
picasso
compile
rootProject
.
ext
.
picasso
compile
rootProject
.
ext
.
picasso2Okhttp3Downloader
compile
rootProject
.
ext
.
picasso2Okhttp3Downloader
...
...
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/RoomToolbar.java
View file @
97d8fa39
...
@@ -2,20 +2,29 @@ package chat.rocket.android.widget;
...
@@ -2,20 +2,29 @@ package chat.rocket.android.widget;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.res.TypedArray
;
import
android.content.res.TypedArray
;
import
android.graphics.Typeface
;
import
android.graphics.drawable.Drawable
;
import
android.graphics.drawable.Drawable
;
import
android.support.annotation.DrawableRes
;
import
android.support.annotation.DrawableRes
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.StringRes
;
import
android.support.annotation.StringRes
;
import
android.support.graphics.drawable.VectorDrawableCompat
;
import
android.support.graphics.drawable.VectorDrawableCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.support.v4.widget.TextViewCompat
;
import
android.support.v4.widget.TextViewCompat
;
import
android.support.v7.widget.AppCompatImageView
;
import
android.support.v7.widget.Toolbar
;
import
android.support.v7.widget.Toolbar
;
import
android.util.AttributeSet
;
import
android.util.AttributeSet
;
import
android.view.View
;
import
android.view.View
;
import
android.widget.ImageButton
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
com.amulyakhare.textdrawable.TextDrawable
;
import
java.lang.reflect.Field
;
public
class
RoomToolbar
extends
Toolbar
{
public
class
RoomToolbar
extends
Toolbar
{
private
TextView
titleTextView
;
private
TextView
titleTextView
;
private
ImageView
badgeImageView
;
public
RoomToolbar
(
Context
context
)
{
public
RoomToolbar
(
Context
context
)
{
super
(
context
);
super
(
context
);
...
@@ -95,4 +104,70 @@ public class RoomToolbar extends Toolbar {
...
@@ -95,4 +104,70 @@ public class RoomToolbar extends Toolbar {
titleTextView
.
setCompoundDrawablesWithIntrinsicBounds
(
drawable
,
null
,
null
,
null
);
titleTextView
.
setCompoundDrawablesWithIntrinsicBounds
(
drawable
,
null
,
null
,
null
);
}
}
public
void
setUnreadBudge
(
int
numUnreadChannels
,
int
numMentionsSum
)
{
if
(
getNavigationIcon
()
==
null
)
{
return
;
}
if
(
badgeImageView
==
null
)
{
badgeImageView
=
new
AppCompatImageView
(
getContext
());
badgeImageView
.
setScaleType
(
ImageView
.
ScaleType
.
CENTER_INSIDE
);
}
if
(
badgeImageView
.
getParent
()
!=
this
)
{
//ref: Toolbar#isChildOrHidden
addView
(
badgeImageView
,
generateDefaultLayoutParams
());
}
if
(
numUnreadChannels
>
0
)
{
if
(
numMentionsSum
>
0
)
{
badgeImageView
.
setImageDrawable
(
getBadgeDrawable
(
numMentionsSum
));
}
else
{
badgeImageView
.
setScaleType
(
ImageView
.
ScaleType
.
CENTER
);
badgeImageView
.
setImageResource
(
R
.
drawable
.
badge_without_number
);
}
badgeImageView
.
setVisibility
(
View
.
VISIBLE
);
}
else
{
badgeImageView
.
setVisibility
(
View
.
GONE
);
}
}
private
Drawable
getBadgeDrawable
(
int
number
)
{
String
icon
=
number
>
99
?
"99+"
:
Integer
.
toString
(
number
);
return
TextDrawable
.
builder
()
.
beginConfig
()
.
useFont
(
Typeface
.
SANS_SERIF
)
.
endConfig
()
.
buildRound
(
icon
,
ContextCompat
.
getColor
(
getContext
(),
R
.
color
.
badge_color
));
}
@Override
protected
void
onLayout
(
boolean
changed
,
int
left
,
int
top
,
int
right
,
int
bottom
)
{
super
.
onLayout
(
changed
,
left
,
top
,
right
,
bottom
);
if
(
badgeImageView
!=
null
&&
badgeImageView
.
getVisibility
()
!=
View
.
GONE
)
{
try
{
Field
field
=
Toolbar
.
class
.
getDeclaredField
(
"mNavButtonView"
);
field
.
setAccessible
(
true
);
ImageButton
navButtonView
=
(
ImageButton
)
field
.
get
(
this
);
int
iconLeft
=
navButtonView
.
getLeft
();
int
iconTop
=
navButtonView
.
getTop
();
int
iconRight
=
navButtonView
.
getRight
();
int
iconBottom
=
navButtonView
.
getBottom
();
// put badge image at right-top side on the NavButtonView,
// with 1/8 margin and 1/4 scale.
int
badgeLeft
=
iconLeft
+
(
iconRight
-
iconLeft
)
*
5
/
8
;
int
badgeRight
=
iconLeft
+
(
iconRight
-
iconLeft
)
*
7
/
8
;
int
badgeTop
=
iconTop
+
(
iconBottom
-
iconTop
)
/
8
;
int
badgeBottom
=
iconTop
+
(
iconBottom
-
iconTop
)
*
3
/
8
;
badgeImageView
.
layout
(
badgeLeft
,
badgeTop
,
badgeRight
,
badgeBottom
);
}
catch
(
Exception
exception
)
{
return
;
}
}
}
}
}
rocket-chat-android-widgets/src/main/res/drawable/badge_without_number.xml
0 → 100644
View file @
97d8fa39
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:shape=
"oval"
>
<solid
android:color=
"@color/badge_color"
/>
<size
android:width=
"@dimen/badge_size"
android:height=
"@dimen/badge_size"
/>
</shape>
\ No newline at end of file
rocket-chat-android-widgets/src/main/res/values/badge_styles.xml
0 → 100644
View file @
97d8fa39
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color
name=
"badge_color"
>
#FFFF0000
</color>
<dimen
name=
"badge_size"
>
8dp
</dimen>
</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