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
492e3d0e
Commit
492e3d0e
authored
Dec 08, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement opened rooms caching
parent
eefec932
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
277 additions
and
240 deletions
+277
-240
RocketChatCache.java
app/src/main/java/chat/rocket/android/RocketChatCache.java
+277
-240
No files found.
app/src/main/java/chat/rocket/android/RocketChatCache.java
View file @
492e3d0e
...
...
@@ -34,6 +34,7 @@ public class RocketChatCache {
private
static
final
String
KEY_SELECTED_ROOM_ID
=
"KEY_SELECTED_ROOM_ID"
;
private
static
final
String
KEY_PUSH_ID
=
"KEY_PUSH_ID"
;
private
static
final
String
KEY_HOSTNAME_LIST
=
"KEY_HOSTNAME_LIST"
;
private
static
final
String
KEY_OPENED_ROOMS
=
"KEY_OPENED_ROOMS"
;
private
Context
context
;
...
...
@@ -41,6 +42,38 @@ public class RocketChatCache {
this
.
context
=
context
.
getApplicationContext
();
}
public
void
addOpenedRoom
(
@NonNull
String
roomId
,
long
lastSeen
)
{
JSONObject
openedRooms
=
getOpenedRooms
();
try
{
JSONObject
room
=
new
JSONObject
().
put
(
"rid"
,
roomId
).
put
(
"ls"
,
lastSeen
);
openedRooms
.
put
(
roomId
,
room
);
}
catch
(
JSONException
e
)
{
RCLog
.
e
(
e
);
}
setString
(
KEY_OPENED_ROOMS
,
openedRooms
.
toString
());
}
public
void
removeOpenedRoom
(
@NonNull
String
roomId
)
{
JSONObject
openedRooms
=
getOpenedRooms
();
if
(
openedRooms
.
has
(
roomId
))
{
openedRooms
.
remove
(
roomId
);
}
}
public
@NonNull
JSONObject
getOpenedRooms
()
{
String
openedRooms
=
getString
(
KEY_OPENED_ROOMS
,
""
);
if
(
openedRooms
.
isEmpty
())
{
return
new
JSONObject
();
}
try
{
return
new
JSONObject
(
openedRooms
);
}
catch
(
JSONException
e
)
{
RCLog
.
e
(
e
);
}
return
new
JSONObject
();
}
public
String
getSelectedServerHostname
()
{
return
getString
(
KEY_SELECTED_SERVER_HOSTNAME
,
null
);
}
...
...
@@ -65,7 +98,8 @@ public class RocketChatCache {
}
}
public
@NonNull
String
getHostSiteName
(
@NonNull
String
host
)
{
public
@NonNull
String
getHostSiteName
(
@NonNull
String
host
)
{
if
(
host
.
startsWith
(
"http"
))
{
HttpUrl
url
=
HttpUrl
.
parse
(
host
);
if
(
url
!=
null
)
{
...
...
@@ -84,7 +118,8 @@ public class RocketChatCache {
return
""
;
}
private
@Nullable
String
getHostSiteNamesJson
()
{
private
@Nullable
String
getHostSiteNamesJson
()
{
return
getString
(
KEY_SELECTED_SITE_NAME
,
null
);
}
...
...
@@ -104,7 +139,8 @@ public class RocketChatCache {
}
}
public
@Nullable
String
getSiteUrlFor
(
String
hostname
)
{
public
@Nullable
String
getSiteUrlFor
(
String
hostname
)
{
try
{
String
selectedServerHostname
=
getSelectedServerHostname
();
if
(
getLoginHostnamesJson
()
==
null
||
getLoginHostnamesJson
().
isEmpty
())
{
...
...
@@ -118,7 +154,8 @@ public class RocketChatCache {
return
null
;
}
private
@Nullable
String
getLoginHostnamesJson
()
{
private
@Nullable
String
getLoginHostnamesJson
()
{
return
getString
(
KEY_SELECTED_SITE_URL
,
null
);
}
...
...
@@ -150,7 +187,7 @@ public class RocketChatCache {
try
{
JSONObject
jsonObj
=
new
JSONObject
(
json
);
List
<
Pair
<
String
,
Pair
<
String
,
String
>>>
serverList
=
new
ArrayList
<>();
for
(
Iterator
<
String
>
iter
=
jsonObj
.
keys
();
iter
.
hasNext
();
)
{
for
(
Iterator
<
String
>
iter
=
jsonObj
.
keys
();
iter
.
hasNext
();
)
{
String
hostname
=
iter
.
next
();
JSONObject
serverInfoJson
=
jsonObj
.
getJSONObject
(
hostname
);
serverList
.
add
(
new
Pair
<>(
hostname
,
new
Pair
<>(
...
...
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