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
5e11a6bd
Commit
5e11a6bd
authored
Nov 20, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement logic to show the status of current user in Sidebar.
parent
a994849c
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
114 additions
and
4 deletions
+114
-4
MainActivity.java
.../main/java/chat/rocket/android/activity/MainActivity.java
+7
-0
MethodCallHelper.java
...c/main/java/chat/rocket/android/api/MethodCallHelper.java
+0
-1
SidebarMainFragment.java
.../rocket/android/fragment/sidebar/SidebarMainFragment.java
+32
-0
User.java
app/src/main/java/chat/rocket/android/model/ddp/User.java
+5
-0
UserRenderer.java
.../main/java/chat/rocket/android/renderer/UserRenderer.java
+67
-0
fragment_sidebar_main.xml
app/src/main/res/layout/fragment_sidebar_main.xml
+3
-3
No files found.
app/src/main/java/chat/rocket/android/activity/MainActivity.java
View file @
5e11a6bd
...
...
@@ -59,10 +59,17 @@ public class MainActivity extends AbstractAuthedActivity {
@Override
protected
void
onServerConfigIdUpdated
()
{
super
.
onServerConfigIdUpdated
();
updateSidebarMainFragment
();
showServerConfigActivityIfNeeded
();
}
private
void
updateSidebarMainFragment
()
{
getSupportFragmentManager
().
beginTransaction
()
.
replace
(
R
.
id
.
sidebar_fragment_container
,
SidebarMainFragment
.
create
(
serverConfigId
))
.
commit
();
}
private
void
showServerConfigActivityIfNeeded
()
{
if
(
serverConfigId
==
null
)
{
return
;
}
...
...
app/src/main/java/chat/rocket/android/api/MethodCallHelper.java
View file @
5e11a6bd
...
...
@@ -20,7 +20,6 @@ import org.json.JSONObject;
/**
* Utility class for creating/handling MethodCall or RPC.
*
* TODO: separate method into several manager classes (SubscriptionManager, MessageManager, ...).
*/
public
class
MethodCallHelper
{
...
...
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainFragment.java
View file @
5e11a6bd
...
...
@@ -3,16 +3,22 @@ package chat.rocket.android.fragment.sidebar;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.widget.CompoundButton
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
chat.rocket.android.R
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.fragment.AbstractFragment
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.layouthelper.chatroom.RoomListManager
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.model.ddp.RoomSubscription
;
import
chat.rocket.android.model.ddp.User
;
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.RealmStore
;
import
chat.rocket.android.renderer.UserRenderer
;
import
com.jakewharton.rxbinding.view.RxView
;
import
com.jakewharton.rxbinding.widget.RxCompoundButton
;
...
...
@@ -20,11 +26,16 @@ public class SidebarMainFragment extends AbstractFragment {
private
String
serverConfigId
;
private
RoomListManager
roomListManager
;
private
String
hostname
;
private
RealmListObserver
<
RoomSubscription
>
roomsObserver
;
private
RealmObjectObserver
<
User
>
currentUserObserver
;
public
SidebarMainFragment
()
{
}
/**
* create SidebarMainFragment with serverConfigId.
*/
public
static
SidebarMainFragment
create
(
String
serverConfigId
)
{
Bundle
args
=
new
Bundle
();
args
.
putString
(
"serverConfigId"
,
serverConfigId
);
...
...
@@ -40,11 +51,21 @@ public class SidebarMainFragment extends AbstractFragment {
Bundle
args
=
getArguments
();
serverConfigId
=
args
==
null
?
null
:
args
.
getString
(
"serverConfigId"
);
if
(!
TextUtils
.
isEmpty
(
serverConfigId
))
{
ServerConfig
config
=
RealmStore
.
getDefault
().
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"serverConfigId"
,
serverConfigId
).
findFirst
());
if
(
config
!=
null
)
{
hostname
=
config
.
getHostname
();
}
RealmHelper
realmHelper
=
RealmStore
.
get
(
serverConfigId
);
if
(
realmHelper
!=
null
)
{
roomsObserver
=
realmHelper
.
createListObserver
(
realm
->
realm
.
where
(
RoomSubscription
.
class
).
findAll
())
.
setOnUpdateListener
(
list
->
roomListManager
.
setRooms
(
list
));
currentUserObserver
=
realmHelper
.
createObjectObserver
(
realm
->
realm
.
where
(
User
.
class
).
isNotEmpty
(
"emails"
))
.
setOnUpdateListener
(
this
::
updateCurrentUser
);
}
}
}
...
...
@@ -86,15 +107,26 @@ public class SidebarMainFragment extends AbstractFragment {
.
subscribe
(
RxView
.
visibility
(
rootView
.
findViewById
(
R
.
id
.
user_action_outer_container
)));
}
private
void
updateCurrentUser
(
User
user
)
{
if
(
user
!=
null
&&
!
TextUtils
.
isEmpty
(
hostname
))
{
new
UserRenderer
(
getContext
(),
user
)
.
avatarInto
((
ImageView
)
rootView
.
findViewById
(
R
.
id
.
current_user_avatar
),
hostname
)
.
usernameInto
((
TextView
)
rootView
.
findViewById
(
R
.
id
.
current_user_name
))
.
statusColorInto
((
ImageView
)
rootView
.
findViewById
(
R
.
id
.
current_user_status
));
}
}
@Override
public
void
onResume
()
{
super
.
onResume
();
if
(
roomsObserver
!=
null
)
{
roomsObserver
.
sub
();
currentUserObserver
.
sub
();
}
}
@Override
public
void
onPause
()
{
if
(
roomsObserver
!=
null
)
{
currentUserObserver
.
unsub
();
roomsObserver
.
unsub
();
}
super
.
onPause
();
...
...
app/src/main/java/chat/rocket/android/model/ddp/User.java
View file @
5e11a6bd
...
...
@@ -10,6 +10,11 @@ import io.realm.annotations.PrimaryKey;
@SuppressWarnings
({
"PMD.ShortClassName"
,
"PMD.ShortVariable"
,
"PMD.MethodNamingConventions"
,
"PMD.VariableNamingConventions"
})
public
class
User
extends
RealmObject
{
public
static
final
String
STATUS_ONLINE
=
"online"
;
public
static
final
String
STATUS_BUSY
=
"busy"
;
public
static
final
String
STATUS_AWAY
=
"away"
;
public
static
final
String
STATUS_OFFLINE
=
"offline"
;
@PrimaryKey
private
String
_id
;
private
String
username
;
private
String
status
;
...
...
app/src/main/java/chat/rocket/android/renderer/UserRenderer.java
0 → 100644
View file @
5e11a6bd
package
chat
.
rocket
.
android
.
renderer
;
import
android.content.Context
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
chat.rocket.android.R
;
import
chat.rocket.android.helper.Avatar
;
import
chat.rocket.android.model.ddp.User
;
/**
* Renderer for User model.
*/
public
class
UserRenderer
extends
AbstractRenderer
<
User
>
{
public
UserRenderer
(
Context
context
,
User
user
)
{
super
(
context
,
user
);
}
/**
* show Avatar image.
*/
public
UserRenderer
avatarInto
(
ImageView
imageView
,
String
hostname
)
{
if
(!
shouldHandle
(
imageView
))
{
return
this
;
}
new
Avatar
(
hostname
,
object
.
getUsername
()).
into
(
imageView
);
return
this
;
}
/**
* show Username in textView.
*/
public
UserRenderer
usernameInto
(
TextView
textView
)
{
if
(!
shouldHandle
(
textView
))
{
return
this
;
}
textView
.
setText
(
object
.
getUsername
());
return
this
;
}
/**
* show user's status color into imageView.
*/
public
UserRenderer
statusColorInto
(
ImageView
imageView
)
{
if
(!
shouldHandle
(
imageView
))
{
return
this
;
}
String
status
=
object
.
getStatus
();
if
(
User
.
STATUS_ONLINE
.
equals
(
status
))
{
imageView
.
setImageResource
(
R
.
drawable
.
userstatus_online
);
}
else
if
(
User
.
STATUS_AWAY
.
equals
(
status
))
{
imageView
.
setImageResource
(
R
.
drawable
.
userstatus_away
);
}
else
if
(
User
.
STATUS_BUSY
.
equals
(
status
))
{
imageView
.
setImageResource
(
R
.
drawable
.
userstatus_busy
);
}
else
if
(
User
.
STATUS_OFFLINE
.
equals
(
status
))
{
imageView
.
setImageResource
(
R
.
drawable
.
userstatus_offline
);
}
else
{
// unknown status is rendered as "offline" status.
imageView
.
setImageResource
(
R
.
drawable
.
userstatus_offline
);
}
return
this
;
}
}
app/src/main/res/layout/fragment_sidebar_main.xml
View file @
5e11a6bd
...
...
@@ -21,7 +21,7 @@
>
<ImageView
android:id=
"@+id/
img_user
status"
android:id=
"@+id/
current_user_
status"
android:layout_width=
"8dp"
android:layout_height=
"8dp"
android:src=
"@drawable/userstatus_online"
...
...
@@ -33,7 +33,7 @@
/>
<ImageView
android:id=
"@+id/
img_my
_avatar"
android:id=
"@+id/
current_user
_avatar"
android:layout_width=
"48dp"
android:layout_height=
"48dp"
/>
...
...
@@ -47,7 +47,7 @@
>
<TextView
android:id=
"@+id/
txt_account_info
"
android:id=
"@+id/
current_user_name
"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_vertical"
...
...
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