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
b83c2e63
Commit
b83c2e63
authored
Nov 26, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement setUsername and joinDefaultChannels and so on ...
parent
f791fce4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
5 deletions
+51
-5
AbstractAuthedActivity.java
.../chat/rocket/android/activity/AbstractAuthedActivity.java
+33
-4
MethodCallHelper.java
...c/main/java/chat/rocket/android/api/MethodCallHelper.java
+12
-0
UserRegistrationDialogFragment.java
...ragment/server_config/UserRegistrationDialogFragment.java
+2
-0
UserRenderer.java
.../main/java/chat/rocket/android/renderer/UserRenderer.java
+4
-1
No files found.
app/src/main/java/chat/rocket/android/activity/AbstractAuthedActivity.java
View file @
b83c2e63
...
...
@@ -5,6 +5,7 @@ import android.os.Bundle;
import
chat.rocket.android.LaunchUtil
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.model.ddp.RoomSubscription
;
import
chat.rocket.android.realm_helper.RealmListObserver
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
chat.rocket.android.service.RocketChatService
;
...
...
@@ -36,16 +37,28 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
private
void
updateServerConfigIdIfNeeded
(
SharedPreferences
prefs
)
{
String
newServerConfigId
=
prefs
.
getString
(
RocketChatCache
.
KEY_SELECTED_SERVER_CONFIG_ID
,
null
);
if
(
serverConfigId
==
null
)
{
if
(
newServerConfigId
!=
null
)
{
if
(
newServerConfigId
!=
null
&&
assertServerConfigExists
(
newServerConfigId
,
prefs
)
)
{
updateServerConfigId
(
newServerConfigId
);
}
}
else
{
if
(!
serverConfigId
.
equals
(
newServerConfigId
))
{
if
(!
serverConfigId
.
equals
(
newServerConfigId
)
&&
assertServerConfigExists
(
newServerConfigId
,
prefs
))
{
updateServerConfigId
(
newServerConfigId
);
}
}
}
private
boolean
assertServerConfigExists
(
String
serverConfigId
,
SharedPreferences
prefs
)
{
if
(
RealmStore
.
get
(
serverConfigId
)
==
null
)
{
prefs
.
edit
()
.
remove
(
RocketChatCache
.
KEY_SELECTED_SERVER_CONFIG_ID
)
.
remove
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
)
.
apply
();
return
false
;
}
return
true
;
}
private
void
updateServerConfigId
(
String
serverConfigId
)
{
this
.
serverConfigId
=
serverConfigId
;
onServerConfigIdUpdated
();
...
...
@@ -54,16 +67,32 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
private
void
updateRoomIdIfNeeded
(
SharedPreferences
prefs
)
{
String
newRoomId
=
prefs
.
getString
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
,
null
);
if
(
roomId
==
null
)
{
if
(
newRoomId
!=
null
)
{
if
(
newRoomId
!=
null
&&
assertRoomSubscriptionExists
(
newRoomId
,
prefs
)
)
{
updateRoomId
(
newRoomId
);
}
}
else
{
if
(!
roomId
.
equals
(
newRoomId
))
{
if
(!
roomId
.
equals
(
newRoomId
)
&&
assertRoomSubscriptionExists
(
newRoomId
,
prefs
)
)
{
updateRoomId
(
newRoomId
);
}
}
}
private
boolean
assertRoomSubscriptionExists
(
String
roomId
,
SharedPreferences
prefs
)
{
if
(!
assertServerConfigExists
(
serverConfigId
,
prefs
))
{
return
false
;
}
RoomSubscription
room
=
RealmStore
.
get
(
serverConfigId
).
executeTransactionForRead
(
realm
->
realm
.
where
(
RoomSubscription
.
class
).
equalTo
(
"rid"
,
roomId
).
findFirst
());
if
(
room
==
null
)
{
prefs
.
edit
()
.
remove
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
)
.
apply
();
return
false
;
}
return
true
;
}
private
void
updateRoomId
(
String
roomId
)
{
this
.
roomId
=
roomId
;
onRoomIdUpdated
();
...
...
app/src/main/java/chat/rocket/android/api/MethodCallHelper.java
View file @
b83c2e63
...
...
@@ -119,6 +119,18 @@ public class MethodCallHelper {
));
}
/**
* set current user's name.
*/
public
Task
<
String
>
setUsername
(
final
String
username
)
{
return
call
(
"setUsername"
,
TIMEOUT_MS
,
()
->
new
JSONArray
().
put
(
username
));
}
public
Task
<
Void
>
joinDefaultChannels
()
{
return
call
(
"joinDefaultChannels"
,
TIMEOUT_MS
)
.
onSuccessTask
(
task
->
Task
.
forResult
(
null
));
}
/**
* Login with username/email and password.
*/
...
...
app/src/main/java/chat/rocket/android/fragment/server_config/UserRegistrationDialogFragment.java
View file @
b83c2e63
...
...
@@ -112,6 +112,8 @@ public class UserRegistrationDialogFragment extends DialogFragment {
MethodCallHelper
methodCallHelper
=
new
MethodCallHelper
(
serverConfigId
);
methodCallHelper
.
registerUser
(
username
,
email
,
password
,
password
)
.
onSuccessTask
(
task
->
methodCallHelper
.
loginWithEmail
(
email
,
password
))
.
onSuccessTask
(
task
->
methodCallHelper
.
setUsername
(
username
))
//TODO: should prompt!
.
onSuccessTask
(
task
->
methodCallHelper
.
joinDefaultChannels
())
.
onSuccessTask
(
task
->
{
dismiss
();
return
task
;
...
...
app/src/main/java/chat/rocket/android/renderer/UserRenderer.java
View file @
b83c2e63
...
...
@@ -5,6 +5,7 @@ import android.widget.ImageView;
import
android.widget.TextView
;
import
chat.rocket.android.R
;
import
chat.rocket.android.helper.Avatar
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.model.ddp.User
;
/**
...
...
@@ -24,7 +25,9 @@ public class UserRenderer extends AbstractRenderer<User> {
return
this
;
}
new
Avatar
(
hostname
,
object
.
getUsername
()).
into
(
imageView
);
if
(!
TextUtils
.
isEmpty
(
object
.
getUsername
()))
{
new
Avatar
(
hostname
,
object
.
getUsername
()).
into
(
imageView
);
}
return
this
;
}
...
...
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