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
e780ec34
Commit
e780ec34
authored
Feb 22, 2017
by
Tiago Cunha
Committed by
GitHub
Feb 22, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into feature/honor-auto-load-image-flag
parents
398a1fa9
6cb7bfdf
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
200 additions
and
142 deletions
+200
-142
RocketChatCache.java
app/src/main/java/chat/rocket/android/RocketChatCache.java
+65
-12
AbstractAuthedActivity.java
.../chat/rocket/android/activity/AbstractAuthedActivity.java
+47
-38
MainActivity.java
.../main/java/chat/rocket/android/activity/MainActivity.java
+10
-51
MainContract.java
.../main/java/chat/rocket/android/activity/MainContract.java
+2
-0
MainPresenter.java
...main/java/chat/rocket/android/activity/MainPresenter.java
+40
-1
DefaultCookieProvider.java
...a/chat/rocket/android/api/rest/DefaultCookieProvider.java
+4
-6
InputHostnameFragment.java
...et/android/fragment/add_server/InputHostnameFragment.java
+1
-1
InputHostnamePresenter.java
...t/android/fragment/add_server/InputHostnamePresenter.java
+3
-7
SidebarMainFragment.java
.../rocket/android/fragment/sidebar/SidebarMainFragment.java
+5
-3
OkHttpHelper.java
...rc/main/java/chat/rocket/android/helper/OkHttpHelper.java
+3
-1
AbstractRocketChatCacheObserver.java
...oid/service/internal/AbstractRocketChatCacheObserver.java
+10
-13
GcmPushRegistrationObserver.java
...android/service/observer/GcmPushRegistrationObserver.java
+7
-7
SessionObserver.java
...chat/rocket/android/service/observer/SessionObserver.java
+3
-2
No files found.
app/src/main/java/chat/rocket/android/RocketChatCache.java
View file @
e780ec34
...
...
@@ -3,30 +3,43 @@ package chat.rocket.android;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
io.reactivex.BackpressureStrategy
;
import
io.reactivex.Flowable
;
import
java.util.UUID
;
/**
* sharedpreference-based cache.
*/
public
class
RocketChatCache
{
public
static
final
String
KEY_SELECTED_SERVER_HOSTNAME
=
"selectedServerHostname"
;
public
static
final
String
KEY_SELECTED_ROOM_ID
=
"selectedRoomId"
;
private
static
final
String
KEY_SELECTED_SERVER_HOSTNAME
=
"selectedServerHostname"
;
private
static
final
String
KEY_SELECTED_ROOM_ID
=
"selectedRoomId"
;
private
static
final
String
KEY_PUSH_ID
=
"pushId"
;
/**
* get SharedPreference instance for RocketChat application cache.
*/
public
static
SharedPreferences
get
(
Context
context
)
{
return
context
.
getSharedPreferences
(
"cache"
,
Context
.
MODE_PRIVATE
);
private
Context
context
;
public
RocketChatCache
(
Context
context
)
{
this
.
context
=
context
.
getApplicationContext
();
}
public
String
getSelectedServerHostname
()
{
return
getString
(
KEY_SELECTED_SERVER_HOSTNAME
,
null
);
}
public
static
String
getSelectedServerHostname
(
Context
context
)
{
return
get
(
context
).
getString
(
KEY_SELECTED_SERVER_HOSTNAME
,
null
);
public
void
setSelectedServerHostname
(
String
hostname
)
{
setString
(
KEY_SELECTED_SERVER_HOSTNAME
,
hostname
);
}
public
static
String
getOrCreatePushId
(
Context
context
)
{
SharedPreferences
preferences
=
get
(
context
);
public
String
getSelectedRoomId
()
{
return
getString
(
KEY_SELECTED_ROOM_ID
,
null
);
}
public
void
setSelectedRoomId
(
String
roomId
)
{
setString
(
KEY_SELECTED_ROOM_ID
,
roomId
);
}
public
String
getOrCreatePushId
()
{
SharedPreferences
preferences
=
getSharedPreferences
();
if
(!
preferences
.
contains
(
KEY_PUSH_ID
))
{
// generates one and save
String
newId
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
...
...
@@ -37,4 +50,44 @@ public class RocketChatCache {
}
return
preferences
.
getString
(
KEY_PUSH_ID
,
null
);
}
public
Flowable
<
String
>
getSelectedServerHostnamePublisher
()
{
return
getValuePublisher
(
KEY_SELECTED_SERVER_HOSTNAME
);
}
public
Flowable
<
String
>
getSelectedRoomIdPublisher
()
{
return
getValuePublisher
(
KEY_SELECTED_ROOM_ID
);
}
private
SharedPreferences
getSharedPreferences
()
{
return
context
.
getSharedPreferences
(
"cache"
,
Context
.
MODE_PRIVATE
);
}
private
SharedPreferences
.
Editor
getEditor
()
{
return
getSharedPreferences
().
edit
();
}
private
String
getString
(
String
key
,
String
defaultValue
)
{
return
getSharedPreferences
().
getString
(
key
,
defaultValue
);
}
private
void
setString
(
String
key
,
String
value
)
{
getEditor
().
putString
(
key
,
value
).
apply
();
}
private
Flowable
<
String
>
getValuePublisher
(
final
String
key
)
{
return
Flowable
.
create
(
emitter
->
{
SharedPreferences
.
OnSharedPreferenceChangeListener
listener
=
(
sharedPreferences
,
changedKey
)
->
{
if
(
key
.
equals
(
changedKey
)
&&
!
emitter
.
isCancelled
())
{
emitter
.
onNext
(
getString
(
key
,
null
));
}
};
emitter
.
setCancellable
(()
->
getSharedPreferences
()
.
unregisterOnSharedPreferenceChangeListener
(
listener
));
getSharedPreferences
().
registerOnSharedPreferenceChangeListener
(
listener
);
},
BackpressureStrategy
.
LATEST
);
}
}
app/src/main/java/chat/rocket/android/activity/AbstractAuthedActivity.java
View file @
e780ec34
package
chat
.
rocket
.
android
.
activity
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.disposables.CompositeDisposable
;
import
io.reactivex.schedulers.Schedulers
;
import
java.util.List
;
import
chat.rocket.android.LaunchUtil
;
import
chat.rocket.android.RocketChatCache
;
...
...
@@ -19,18 +22,16 @@ import icepick.State;
abstract
class
AbstractAuthedActivity
extends
AbstractFragmentActivity
{
@State
protected
String
hostname
;
@State
protected
String
roomId
;
SharedPreferences
.
OnSharedPreferenceChangeListener
preferenceChangeListener
=
(
sharedPreferences
,
key
)
->
{
if
(
RocketChatCache
.
KEY_SELECTED_SERVER_HOSTNAME
.
equals
(
key
))
{
updateHostnameIfNeeded
(
sharedPreferences
);
}
else
if
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
.
equals
(
key
))
{
updateRoomIdIfNeeded
(
sharedPreferences
);
}
};
private
RocketChatCache
rocketChatCache
;
private
CompositeDisposable
compositeDisposable
=
new
CompositeDisposable
();
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
rocketChatCache
=
new
RocketChatCache
(
this
);
if
(
savedInstanceState
==
null
)
{
handleIntent
(
getIntent
());
}
...
...
@@ -48,15 +49,11 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
}
if
(
intent
.
hasExtra
(
PushConstants
.
HOSTNAME
))
{
SharedPreferences
.
Editor
editor
=
RocketChatCache
.
get
(
this
).
edit
();
editor
.
putString
(
RocketChatCache
.
KEY_SELECTED_SERVER_HOSTNAME
,
intent
.
getStringExtra
(
PushConstants
.
HOSTNAME
));
rocketChatCache
.
setSelectedServerHostname
(
intent
.
getStringExtra
(
PushConstants
.
HOSTNAME
));
if
(
intent
.
hasExtra
(
PushConstants
.
ROOM_ID
))
{
editor
.
putString
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
,
intent
.
getStringExtra
(
PushConstants
.
ROOM_ID
));
rocketChatCache
.
setSelectedRoomId
(
intent
.
getStringExtra
(
PushConstants
.
ROOM_ID
));
}
editor
.
apply
();
}
if
(
intent
.
hasExtra
(
PushConstants
.
NOT_ID
))
{
...
...
@@ -65,13 +62,12 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
}
}
private
void
updateHostnameIfNeeded
(
SharedPreferences
prefs
)
{
String
newHostname
=
prefs
.
getString
(
RocketChatCache
.
KEY_SELECTED_SERVER_HOSTNAME
,
null
);
private
void
updateHostnameIfNeeded
(
String
newHostname
)
{
if
(
hostname
==
null
)
{
if
(
newHostname
!=
null
&&
assertServerRealmStoreExists
(
newHostname
))
{
updateHostname
(
newHostname
);
}
else
{
recoverFromHostnameError
(
prefs
);
recoverFromHostnameError
();
}
}
else
{
if
(
hostname
.
equals
(
newHostname
))
{
...
...
@@ -82,7 +78,7 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
if
(
assertServerRealmStoreExists
(
newHostname
))
{
updateHostname
(
newHostname
);
}
else
{
recoverFromHostnameError
(
prefs
);
recoverFromHostnameError
();
}
}
}
...
...
@@ -96,7 +92,7 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
onHostnameUpdated
();
}
private
void
recoverFromHostnameError
(
SharedPreferences
prefs
)
{
private
void
recoverFromHostnameError
()
{
final
List
<
ServerInfo
>
serverInfoList
=
ConnectivityManager
.
getInstance
(
getApplicationContext
()).
getServerList
();
if
(
serverInfoList
==
null
||
serverInfoList
.
size
()
==
0
)
{
...
...
@@ -106,26 +102,24 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
// just connect to the first available
final
ServerInfo
serverInfo
=
serverInfoList
.
get
(
0
);
prefs
.
edit
()
.
putString
(
RocketChatCache
.
KEY_SELECTED_SERVER_HOSTNAME
,
serverInfo
.
getHostname
())
.
remove
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
)
.
apply
();
rocketChatCache
.
setSelectedServerHostname
(
serverInfo
.
getHostname
());
rocketChatCache
.
setSelectedRoomId
(
null
);
}
private
void
updateRoomIdIfNeeded
(
SharedPreferences
prefs
)
{
String
newRoomId
=
prefs
.
getString
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
,
null
);
private
void
updateRoomIdIfNeeded
(
String
newRoomId
)
{
if
(
roomId
==
null
)
{
if
(
newRoomId
!=
null
&&
assertRoomSubscriptionExists
(
newRoomId
,
prefs
))
{
if
(
newRoomId
!=
null
&&
assertRoomSubscriptionExists
(
newRoomId
))
{
updateRoomId
(
newRoomId
);
}
}
else
{
if
(!
roomId
.
equals
(
newRoomId
)
&&
assertRoomSubscriptionExists
(
newRoomId
,
prefs
))
{
if
(!
roomId
.
equals
(
newRoomId
)
&&
assertRoomSubscriptionExists
(
newRoomId
))
{
updateRoomId
(
newRoomId
);
}
}
}
private
boolean
assertRoomSubscriptionExists
(
String
roomId
,
SharedPreferences
prefs
)
{
private
boolean
assertRoomSubscriptionExists
(
String
roomId
)
{
if
(!
assertServerRealmStoreExists
(
hostname
))
{
return
false
;
}
...
...
@@ -133,9 +127,7 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
RealmRoom
room
=
RealmStore
.
get
(
hostname
).
executeTransactionForRead
(
realm
->
realm
.
where
(
RealmRoom
.
class
).
equalTo
(
RealmRoom
.
ROOM_ID
,
roomId
).
findFirst
());
if
(
room
==
null
)
{
prefs
.
edit
()
.
remove
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
)
.
apply
();
rocketChatCache
.
setSelectedRoomId
(
null
);
return
false
;
}
return
true
;
...
...
@@ -157,16 +149,15 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
super
.
onResume
();
ConnectivityManager
.
getInstance
(
getApplicationContext
()).
keepAliveServer
();
SharedPreferences
prefs
=
RocketChatCache
.
get
(
this
);
update
HostnameIfNeeded
(
prefs
);
updateRoomIdIfNeeded
(
prefs
);
prefs
.
registerOnSharedPreferenceChangeListener
(
preferenceChangeListener
);
updateHostnameIfNeeded
(
rocketChatCache
.
getSelectedServerHostname
()
);
update
RoomIdIfNeeded
(
rocketChatCache
.
getSelectedRoomId
()
);
subscribeToConfigChanges
(
);
}
@Override
protected
void
onPause
()
{
SharedPreferences
prefs
=
RocketChatCache
.
get
(
this
);
prefs
.
unregisterOnSharedPreferenceChangeListener
(
preferenceChangeListener
);
compositeDisposable
.
clear
();
super
.
onPause
();
}
...
...
@@ -175,4 +166,22 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
protected
void
onSaveInstanceState
(
Bundle
outState
)
{
super
.
onSaveInstanceState
(
outState
);
}
private
void
subscribeToConfigChanges
()
{
compositeDisposable
.
add
(
rocketChatCache
.
getSelectedServerHostnamePublisher
()
.
distinctUntilChanged
()
.
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
this
::
updateHostnameIfNeeded
)
);
compositeDisposable
.
add
(
rocketChatCache
.
getSelectedRoomIdPublisher
()
.
distinctUntilChanged
()
.
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
this
::
updateRoomIdIfNeeded
)
);
}
}
app/src/main/java/chat/rocket/android/activity/MainActivity.java
View file @
e780ec34
...
...
@@ -14,11 +14,9 @@ import chat.rocket.android.api.MethodCallHelper;
import
chat.rocket.android.fragment.chatroom.HomeFragment
;
import
chat.rocket.android.fragment.chatroom.RoomFragment
;
import
chat.rocket.android.fragment.sidebar.SidebarMainFragment
;
import
chat.rocket.android.helper.LogIfError
;
import
chat.rocket.core.interactors.CanCreateRoomInteractor
;
import
chat.rocket.core.interactors.RoomInteractor
;
import
chat.rocket.core.interactors.SessionInteractor
;
import
chat.rocket.core.models.User
;
import
chat.rocket.android.service.ConnectivityManager
;
import
chat.rocket.android.widget.RoomToolbar
;
import
chat.rocket.persistence.realm.repositories.RealmRoomRepository
;
...
...
@@ -47,29 +45,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
statusTicker
=
new
StatusTicker
();
setupSidebar
();
if
(
roomId
==
null
)
{
showFragment
(
new
HomeFragment
());
}
if
(
shouldLaunchAddServerActivity
())
{
LaunchUtil
.
showAddServerActivity
(
this
);
}
}
@Override
protected
void
onStart
()
{
super
.
onStart
();
setUserOnlineIfServerAvailable
();
}
@Override
protected
void
onResume
()
{
super
.
onResume
();
if
(
presenter
!=
null
)
{
presenter
.
bindView
(
this
);
}
}
@Override
...
...
@@ -81,27 +56,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
super
.
onPause
();
}
@Override
protected
void
onStop
()
{
setUserAwayIfServerAvailable
();
super
.
onStop
();
}
private
void
setUserOnlineIfServerAvailable
()
{
if
(
hostname
!=
null
)
{
new
MethodCallHelper
(
this
,
hostname
).
setUserPresence
(
User
.
STATUS_ONLINE
)
.
continueWith
(
new
LogIfError
());
}
}
private
void
setUserAwayIfServerAvailable
()
{
if
(
hostname
!=
null
)
{
new
MethodCallHelper
(
this
,
hostname
).
setUserPresence
(
User
.
STATUS_AWAY
)
.
continueWith
(
new
LogIfError
());
}
}
private
void
setupSidebar
()
{
SlidingPaneLayout
pane
=
(
SlidingPaneLayout
)
findViewById
(
R
.
id
.
sliding_pane
);
if
(
pane
==
null
)
{
...
...
@@ -157,10 +111,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
return
false
;
}
private
boolean
shouldLaunchAddServerActivity
()
{
return
ConnectivityManager
.
getInstance
(
getApplicationContext
()).
getServerList
().
isEmpty
();
}
@DebugLog
@Override
protected
void
onHostnameUpdated
()
{
...
...
@@ -184,10 +134,14 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
presenter
=
new
MainPresenter
(
roomInteractor
,
createRoomInteractor
,
sessionInteractor
sessionInteractor
,
new
MethodCallHelper
(
this
,
hostname
),
ConnectivityManager
.
getInstance
(
getApplicationContext
())
);
updateSidebarMainFragment
();
presenter
.
bindView
(
this
);
}
private
void
updateSidebarMainFragment
()
{
...
...
@@ -226,6 +180,11 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
}
}
@Override
public
void
showAddServerScreen
()
{
LaunchUtil
.
showAddServerActivity
(
this
);
}
@Override
public
void
showLoginScreen
()
{
LaunchUtil
.
showLoginActivity
(
this
,
hostname
);
...
...
app/src/main/java/chat/rocket/android/activity/MainContract.java
View file @
e780ec34
...
...
@@ -12,6 +12,8 @@ public interface MainContract {
void
showUnreadCount
(
long
roomsCount
,
int
mentionsCount
);
void
showAddServerScreen
();
void
showLoginScreen
();
void
showConnectionError
();
...
...
app/src/main/java/chat/rocket/android/activity/MainPresenter.java
View file @
e780ec34
...
...
@@ -8,11 +8,15 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import
io.reactivex.disposables.Disposable
;
import
chat.rocket.android.BackgroundLooper
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.helper.LogIfError
;
import
chat.rocket.android.service.ConnectivityManagerApi
;
import
chat.rocket.android.shared.BasePresenter
;
import
chat.rocket.core.interactors.CanCreateRoomInteractor
;
import
chat.rocket.core.interactors.RoomInteractor
;
import
chat.rocket.core.interactors.SessionInteractor
;
import
chat.rocket.core.models.Session
;
import
chat.rocket.core.models.User
;
public
class
MainPresenter
extends
BasePresenter
<
MainContract
.
View
>
implements
MainContract
.
Presenter
{
...
...
@@ -20,21 +24,42 @@ public class MainPresenter extends BasePresenter<MainContract.View>
private
final
CanCreateRoomInteractor
canCreateRoomInteractor
;
private
final
RoomInteractor
roomInteractor
;
private
final
SessionInteractor
sessionInteractor
;
private
final
MethodCallHelper
methodCallHelper
;
private
final
ConnectivityManagerApi
connectivityManagerApi
;
public
MainPresenter
(
RoomInteractor
roomInteractor
,
CanCreateRoomInteractor
canCreateRoomInteractor
,
SessionInteractor
sessionInteractor
)
{
SessionInteractor
sessionInteractor
,
MethodCallHelper
methodCallHelper
,
ConnectivityManagerApi
connectivityManagerApi
)
{
this
.
roomInteractor
=
roomInteractor
;
this
.
canCreateRoomInteractor
=
canCreateRoomInteractor
;
this
.
sessionInteractor
=
sessionInteractor
;
this
.
methodCallHelper
=
methodCallHelper
;
this
.
connectivityManagerApi
=
connectivityManagerApi
;
}
@Override
public
void
bindView
(
@NonNull
MainContract
.
View
view
)
{
super
.
bindView
(
view
);
view
.
showHome
();
if
(
shouldLaunchAddServerActivity
())
{
view
.
showAddServerScreen
();
return
;
}
subscribeToUnreadCount
();
subscribeToSession
();
setUserOnline
();
}
@Override
public
void
release
()
{
setUserAway
();
super
.
release
();
}
@Override
...
...
@@ -101,4 +126,18 @@ public class MainPresenter extends BasePresenter<MainContract.View>
addSubscription
(
subscription
);
}
private
void
setUserOnline
()
{
methodCallHelper
.
setUserPresence
(
User
.
STATUS_ONLINE
)
.
continueWith
(
new
LogIfError
());
}
private
void
setUserAway
()
{
methodCallHelper
.
setUserPresence
(
User
.
STATUS_AWAY
)
.
continueWith
(
new
LogIfError
());
}
private
boolean
shouldLaunchAddServerActivity
()
{
return
connectivityManagerApi
.
getServerList
().
isEmpty
();
}
}
app/src/main/java/chat/rocket/android/api/rest/DefaultCookieProvider.java
View file @
e780ec34
package
chat
.
rocket
.
android
.
api
.
rest
;
import
android.content.Context
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.persistence.realm.models.ddp.RealmUser
;
import
chat.rocket.persistence.realm.models.internal.RealmSession
;
...
...
@@ -10,10 +8,10 @@ import chat.rocket.persistence.realm.RealmStore;
public
class
DefaultCookieProvider
implements
CookieProvider
{
private
final
Context
applicationContext
;
private
RocketChatCache
rocketChatCache
;
public
DefaultCookieProvider
(
Context
context
)
{
applicationContext
=
context
.
getApplicationContext
()
;
public
DefaultCookieProvider
(
RocketChatCache
rocketChatCache
)
{
this
.
rocketChatCache
=
rocketChatCache
;
}
@Override
...
...
@@ -46,6 +44,6 @@ public class DefaultCookieProvider implements CookieProvider {
}
private
String
getHostnameFromCache
()
{
return
RocketChatCache
.
getSelectedServerHostname
(
applicationContext
);
return
rocketChatCache
.
getSelectedServerHostname
(
);
}
}
app/src/main/java/chat/rocket/android/fragment/add_server/InputHostnameFragment.java
View file @
e780ec34
...
...
@@ -32,7 +32,7 @@ public class InputHostnameFragment extends AbstractFragment implements InputHost
final
Context
appContext
=
getContext
().
getApplicationContext
();
presenter
=
new
InputHostnamePresenter
(
RocketChatCache
.
get
(
appContext
),
new
RocketChatCache
(
appContext
),
ConnectivityManager
.
getInstance
(
appContext
));
}
...
...
app/src/main/java/chat/rocket/android/fragment/add_server/InputHostnamePresenter.java
View file @
e780ec34
package
chat
.
rocket
.
android
.
fragment
.
add_server
;
import
android.content.SharedPreferences
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.disposables.Disposable
;
import
io.reactivex.schedulers.Schedulers
;
...
...
@@ -18,10 +16,10 @@ import chat.rocket.android.shared.BasePresenter;
public
class
InputHostnamePresenter
extends
BasePresenter
<
InputHostnameContract
.
View
>
implements
InputHostnameContract
.
Presenter
{
private
final
SharedPreferences
rocketChatCache
;
private
final
RocketChatCache
rocketChatCache
;
private
final
ConnectivityManagerApi
connectivityManager
;
public
InputHostnamePresenter
(
SharedPreferences
rocketChatCache
,
public
InputHostnamePresenter
(
RocketChatCache
rocketChatCache
,
ConnectivityManagerApi
connectivityManager
)
{
this
.
rocketChatCache
=
rocketChatCache
;
this
.
connectivityManager
=
connectivityManager
;
...
...
@@ -63,9 +61,7 @@ public class InputHostnamePresenter extends BasePresenter<InputHostnameContract.
}
private
void
onServerValid
(
final
String
hostname
,
boolean
usesSecureConnection
)
{
rocketChatCache
.
edit
()
.
putString
(
RocketChatCache
.
KEY_SELECTED_SERVER_HOSTNAME
,
hostname
)
.
apply
();
rocketChatCache
.
setSelectedServerHostname
(
hostname
);
connectivityManager
.
addOrUpdateServer
(
hostname
,
hostname
,
!
usesSecureConnection
);
connectivityManager
.
keepAliveServer
();
...
...
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainFragment.java
View file @
e780ec34
...
...
@@ -47,6 +47,8 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
private
String
hostname
;
private
RocketChatCache
rocketChatCache
;
public
SidebarMainFragment
()
{
}
...
...
@@ -70,6 +72,8 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
Bundle
args
=
getArguments
();
hostname
=
args
==
null
?
null
:
args
.
getString
(
HOSTNAME
);
rocketChatCache
=
new
RocketChatCache
(
getContext
());
presenter
=
new
SidebarMainPresenter
(
hostname
,
new
RoomInteractor
(
new
RealmRoomRepository
(
hostname
)),
...
...
@@ -103,9 +107,7 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
setupVersionInfo
();
adapter
=
new
RoomListAdapter
();
adapter
.
setOnItemClickListener
(
room
->
RocketChatCache
.
get
(
getContext
()).
edit
()
.
putString
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
,
room
.
getRoomId
())
.
apply
());
adapter
.
setOnItemClickListener
(
room
->
rocketChatCache
.
setSelectedRoomId
(
room
.
getRoomId
()));
RecyclerView
recyclerView
=
(
RecyclerView
)
rootView
.
findViewById
(
R
.
id
.
room_list_container
);
recyclerView
.
setLayoutManager
(
...
...
app/src/main/java/chat/rocket/android/helper/OkHttpHelper.java
View file @
e780ec34
...
...
@@ -4,6 +4,7 @@ import android.content.Context;
import
com.facebook.stetho.okhttp3.StethoInterceptor
;
import
java.util.concurrent.TimeUnit
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.api.rest.CookieInterceptor
;
import
chat.rocket.android.api.rest.DefaultCookieProvider
;
import
okhttp3.OkHttpClient
;
...
...
@@ -20,7 +21,8 @@ public class OkHttpHelper {
if
(
httpClientForDownloadFile
==
null
)
{
httpClientForDownloadFile
=
new
OkHttpClient
.
Builder
()
.
addNetworkInterceptor
(
new
StethoInterceptor
())
.
addInterceptor
(
new
CookieInterceptor
(
new
DefaultCookieProvider
(
context
)))
.
addInterceptor
(
new
CookieInterceptor
(
new
DefaultCookieProvider
(
new
RocketChatCache
(
context
))))
.
build
();
}
return
httpClientForDownloadFile
;
...
...
app/src/main/java/chat/rocket/android/service/internal/AbstractRocketChatCacheObserver.java
View file @
e780ec34
package
chat
.
rocket
.
android
.
service
.
internal
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
io.reactivex.disposables.CompositeDisposable
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.helper.TextUtils
;
...
...
@@ -13,20 +14,14 @@ public abstract class AbstractRocketChatCacheObserver implements Registrable {
private
final
Context
context
;
private
final
RealmHelper
realmHelper
;
private
String
roomId
;
private
SharedPreferences
.
OnSharedPreferenceChangeListener
listener
=
(
prefs
,
key
)
->
{
if
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
.
equals
(
key
))
{
updateRoomIdWith
(
prefs
);
}
};
private
CompositeDisposable
compositeDisposable
=
new
CompositeDisposable
();
protected
AbstractRocketChatCacheObserver
(
Context
context
,
RealmHelper
realmHelper
)
{
this
.
context
=
context
;
this
.
realmHelper
=
realmHelper
;
}
private
void
updateRoomIdWith
(
SharedPreferences
prefs
)
{
String
roomId
=
prefs
.
getString
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
,
null
);
private
void
updateRoomIdWith
(
String
roomId
)
{
if
(!
TextUtils
.
isEmpty
(
roomId
))
{
RealmRoom
room
=
realmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
RealmRoom
.
class
).
equalTo
(
"rid"
,
roomId
).
findFirst
());
...
...
@@ -49,13 +44,15 @@ public abstract class AbstractRocketChatCacheObserver implements Registrable {
@Override
public
final
void
register
()
{
SharedPreferences
prefs
=
RocketChatCache
.
get
(
context
);
prefs
.
registerOnSharedPreferenceChangeListener
(
listener
);
updateRoomIdWith
(
prefs
);
compositeDisposable
.
add
(
new
RocketChatCache
(
context
)
.
getSelectedRoomIdPublisher
()
.
subscribe
(
this
::
updateRoomIdWith
)
);
}
@Override
public
final
void
unregister
()
{
RocketChatCache
.
get
(
context
).
unregisterOnSharedPreferenceChangeListener
(
listener
);
compositeDisposable
.
clear
(
);
}
}
app/src/main/java/chat/rocket/android/service/observer/GcmPushRegistrationObserver.java
View file @
e780ec34
...
...
@@ -73,7 +73,7 @@ public class GcmPushRegistrationObserver extends AbstractModelObserver<GcmPushRe
final
RealmUser
currentUser
=
realmHelper
.
executeTransactionForRead
(
realm
->
RealmUser
.
queryCurrentUser
(
realm
).
findFirst
());
final
String
userId
=
currentUser
!=
null
?
currentUser
.
getId
()
:
null
;
final
String
pushId
=
RocketChatCache
.
getOrCreatePushId
(
context
);
final
String
pushId
=
new
RocketChatCache
(
context
).
getOrCreatePushId
(
);
return
new
RaixPushHelper
(
realmHelper
,
ddpClientRef
)
.
pushUpdate
(
pushId
,
gcmToken
,
userId
);
...
...
app/src/main/java/chat/rocket/android/service/observer/SessionObserver.java
View file @
e780ec34
...
...
@@ -33,7 +33,8 @@ public class SessionObserver extends AbstractModelObserver<RealmSession> {
super
(
context
,
hostname
,
realmHelper
,
ddpClientRef
);
count
=
0
;
streamNotifyMessage
=
new
StreamRoomMessageManager
(
context
,
hostname
,
realmHelper
,
ddpClientRef
);
streamNotifyMessage
=
new
StreamRoomMessageManager
(
context
,
hostname
,
realmHelper
,
ddpClientRef
);
pushHelper
=
new
RaixPushHelper
(
realmHelper
,
ddpClientRef
);
}
...
...
@@ -72,7 +73,7 @@ public class SessionObserver extends AbstractModelObserver<RealmSession> {
// update push info
pushHelper
.
pushSetUser
(
RocketChatCache
.
getOrCreatePushId
(
context
))
.
pushSetUser
(
new
RocketChatCache
(
context
).
getOrCreatePushId
(
))
.
continueWith
(
new
LogIfError
());
}
...
...
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