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
e893780a
Commit
e893780a
authored
Sep 22, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplified multi-server roomId selection cache on multi-server
parent
3ec4779a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
23 deletions
+37
-23
RocketChatCache.java
app/src/main/java/chat/rocket/android/RocketChatCache.java
+26
-3
AbstractAuthedActivity.java
.../chat/rocket/android/activity/AbstractAuthedActivity.java
+10
-13
MainActivity.java
.../main/java/chat/rocket/android/activity/MainActivity.java
+1
-7
No files found.
app/src/main/java/chat/rocket/android/RocketChatCache.java
View file @
e893780a
...
...
@@ -14,6 +14,7 @@ import java.util.Iterator;
import
java.util.List
;
import
java.util.UUID
;
import
chat.rocket.android.helper.Logger
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.log.RCLog
;
import
chat.rocket.core.utils.Pair
;
...
...
@@ -106,11 +107,33 @@ public class RocketChatCache {
}
public
String
getSelectedRoomId
()
{
return
getString
(
getSelectedServerHostname
()
+
KEY_SELECTED_ROOM_ID
,
null
);
try
{
JSONObject
jsonObject
=
getSelectedRoomIdJsonObject
();
return
jsonObject
.
optString
(
getSelectedServerHostname
(),
null
);
}
catch
(
JSONException
e
)
{
RCLog
.
e
(
e
);
Logger
.
report
(
e
);
}
return
null
;
}
public
void
setSelectedRoomId
(
String
roomId
)
{
setString
(
getSelectedServerHostname
()
+
KEY_SELECTED_ROOM_ID
,
roomId
);
try
{
JSONObject
jsonObject
=
getSelectedRoomIdJsonObject
();
jsonObject
.
put
(
getSelectedServerHostname
(),
roomId
);
setString
(
KEY_SELECTED_ROOM_ID
,
jsonObject
.
toString
());
}
catch
(
JSONException
e
)
{
RCLog
.
e
(
e
);
Logger
.
report
(
e
);
}
}
private
JSONObject
getSelectedRoomIdJsonObject
()
throws
JSONException
{
String
json
=
getString
(
KEY_SELECTED_ROOM_ID
,
null
);
if
(
json
==
null
)
{
return
new
JSONObject
();
}
return
new
JSONObject
(
json
);
}
public
String
getOrCreatePushId
()
{
...
...
@@ -131,7 +154,7 @@ public class RocketChatCache {
}
public
Flowable
<
Optional
<
String
>>
getSelectedRoomIdPublisher
()
{
return
getValuePublisher
(
getSelectedServerHostname
()
+
KEY_SELECTED_ROOM_ID
);
return
getValuePublisher
(
KEY_SELECTED_ROOM_ID
);
}
private
SharedPreferences
getSharedPreferences
()
{
...
...
app/src/main/java/chat/rocket/android/activity/AbstractAuthedActivity.java
View file @
e893780a
...
...
@@ -6,6 +6,9 @@ import android.support.annotation.Nullable;
import
com.hadisatrio.optional.Optional
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.util.List
;
import
chat.rocket.android.LaunchUtil
;
...
...
@@ -196,7 +199,8 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
compositeDisposable
.
add
(
rocketChatCache
.
getSelectedRoomIdPublisher
()
.
map
(
Optional:
:
get
)
.
distinctUntilChanged
()
.
map
(
this
::
convertStringToJsonObject
)
.
map
(
jsonObject
->
jsonObject
.
optString
(
rocketChatCache
.
getSelectedServerHostname
(),
null
))
.
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
...
...
@@ -206,17 +210,10 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
);
}
protected
void
subscribeToNewConfigChanges
()
{
compositeDisposable
.
add
(
rocketChatCache
.
getSelectedRoomIdPublisher
()
.
map
(
Optional:
:
get
)
.
distinctUntilChanged
()
.
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
this
::
updateRoomIdIfNeeded
,
Logger:
:
report
)
);
private
JSONObject
convertStringToJsonObject
(
String
json
)
throws
JSONException
{
if
(
json
==
null
)
{
return
new
JSONObject
();
}
return
new
JSONObject
(
json
);
}
}
app/src/main/java/chat/rocket/android/activity/MainActivity.java
View file @
e893780a
...
...
@@ -203,10 +203,8 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
if
(
sidebarFragment
==
null
)
{
sidebarFragment
=
SidebarMainFragment
.
create
(
selectedServerHostname
);
}
subscribeToNewConfigChanges
();
getSupportFragmentManager
().
beginTransaction
()
.
replace
(
R
.
id
.
sidebar_fragment_container
,
sidebarFragment
,
selectedServerHostname
)
.
addToBackStack
(
null
)
.
commit
();
getSupportFragmentManager
().
executePendingTransactions
();
}
...
...
@@ -229,11 +227,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
@Override
public
void
showRoom
(
String
hostname
,
String
roomId
)
{
Fragment
roomFragment
=
findFragmentByTag
(
roomId
);
if
(
roomFragment
==
null
)
{
roomFragment
=
RoomFragment
.
create
(
hostname
,
roomId
);
}
showFragmentWithTag
(
roomFragment
,
roomId
);
showFragment
(
RoomFragment
.
create
(
hostname
,
roomId
));
closeSidebarIfNeeded
();
KeyboardHelper
.
hideSoftKeyboard
(
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