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
8e8e9231
Commit
8e8e9231
authored
Jan 09, 2017
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
just refactor
parent
c50327a8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
32 deletions
+16
-32
RocketChatCache.java
app/src/main/java/chat/rocket/android/RocketChatCache.java
+9
-29
GcmRegistrationIntentService.java
...rocket/android/push/gcm/GcmRegistrationIntentService.java
+4
-2
CurrentUserObserver.java
.../rocket/android/service/observer/CurrentUserObserver.java
+3
-1
No files found.
app/src/main/java/chat/rocket/android/RocketChatCache.java
View file @
8e8e9231
...
...
@@ -12,7 +12,7 @@ public class RocketChatCache {
public
static
final
String
KEY_SELECTED_SERVER_CONFIG_ID
=
"selectedServerConfigId"
;
public
static
final
String
KEY_SELECTED_ROOM_ID
=
"selectedRoomId"
;
private
static
final
String
PUSH_ID
=
"pushId"
;
private
static
final
String
KEY_
PUSH_ID
=
"pushId"
;
/**
* get SharedPreference instance for RocketChat application cache.
...
...
@@ -21,36 +21,16 @@ public class RocketChatCache {
return
context
.
getSharedPreferences
(
"cache"
,
Context
.
MODE_PRIVATE
);
}
public
static
String
getSelectedServerConfigId
(
Context
context
)
{
return
get
(
context
).
getString
(
KEY_SELECTED_SERVER_CONFIG_ID
,
""
);
}
public
static
void
setSelectedServerConfigId
(
Context
context
,
String
serverConfigId
)
{
setString
(
get
(
context
),
KEY_SELECTED_SERVER_CONFIG_ID
,
serverConfigId
);
}
public
static
String
getSelectedRoomId
(
Context
context
)
{
return
get
(
context
).
getString
(
KEY_SELECTED_ROOM_ID
,
""
);
}
public
static
void
setSelectedRoomId
(
Context
context
,
String
roomId
)
{
setString
(
get
(
context
),
KEY_SELECTED_ROOM_ID
,
roomId
);
}
public
static
String
getPushId
(
Context
context
)
{
public
static
String
getOrCreatePushId
(
Context
context
)
{
SharedPreferences
preferences
=
get
(
context
);
String
pushId
=
null
;
if
(!
preferences
.
contains
(
PUSH_ID
))
{
if
(!
preferences
.
contains
(
KEY_PUSH_ID
))
{
// generates one and save
pushId
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
setString
(
preferences
,
PUSH_ID
,
pushId
);
String
newId
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
preferences
.
edit
()
.
putString
(
KEY_PUSH_ID
,
newId
)
.
apply
();
return
newId
;
}
return
preferences
.
getString
(
PUSH_ID
,
pushId
);
}
private
static
void
setString
(
SharedPreferences
preferences
,
String
key
,
String
value
)
{
SharedPreferences
.
Editor
editor
=
preferences
.
edit
();
editor
.
putString
(
key
,
value
);
editor
.
apply
();
return
preferences
.
getString
(
KEY_PUSH_ID
,
null
);
}
}
app/src/main/java/chat/rocket/android/push/gcm/GcmRegistrationIntentService.java
View file @
8e8e9231
...
...
@@ -52,8 +52,10 @@ public class GcmRegistrationIntentService extends IntentService {
final
User
currentUser
=
realmHelper
.
executeTransactionForRead
(
realm
->
User
.
queryCurrentUser
(
realm
).
findFirst
());
new
RaixPushHelper
(
getBaseContext
(),
serverConfig
.
getServerConfigId
()).
pushUpdate
(
RocketChatCache
.
getPushId
(
this
),
gcmToken
,
currentUser
!=
null
?
currentUser
.
getId
()
:
null
)
final
String
pushId
=
RocketChatCache
.
getOrCreatePushId
(
this
);
final
String
userId
=
currentUser
!=
null
?
currentUser
.
getId
()
:
null
;
new
RaixPushHelper
(
getBaseContext
(),
serverConfig
.
getServerConfigId
())
.
pushUpdate
(
pushId
,
gcmToken
,
userId
)
.
onSuccess
(
task
->
{
markRefreshAsDone
(
serverConfig
);
return
task
;
...
...
app/src/main/java/chat/rocket/android/service/observer/CurrentUserObserver.java
View file @
8e8e9231
...
...
@@ -63,7 +63,9 @@ public class CurrentUserObserver extends AbstractModelObserver<User> {
final
String
userId
=
user
.
getId
();
// update push info
pushHelper
.
pushSetUser
(
RocketChatCache
.
getPushId
(
context
)).
continueWith
(
new
LogcatIfError
());
pushHelper
.
pushSetUser
(
RocketChatCache
.
getOrCreatePushId
(
context
))
.
continueWith
(
new
LogcatIfError
());
// get and observe Room subscriptions.
methodCall
.
getRoomSubscriptions
().
onSuccess
(
task
->
{
...
...
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