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
cf96cd2f
Commit
cf96cd2f
authored
Sep 25, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete all offline data prior to calling the 'logout' method
parent
a02a2f2e
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
79 additions
and
44 deletions
+79
-44
RocketChatApplication.java
.../main/java/chat/rocket/android/RocketChatApplication.java
+8
-0
MainActivity.java
.../main/java/chat/rocket/android/activity/MainActivity.java
+14
-6
MainContract.java
.../main/java/chat/rocket/android/activity/MainContract.java
+1
-1
MainPresenter.java
...main/java/chat/rocket/android/activity/MainPresenter.java
+1
-1
MethodCallHelper.java
...c/main/java/chat/rocket/android/api/MethodCallHelper.java
+4
-22
SidebarMainContract.java
.../rocket/android/fragment/sidebar/SidebarMainContract.java
+4
-0
SidebarMainFragment.java
.../rocket/android/fragment/sidebar/SidebarMainFragment.java
+20
-14
SidebarMainPresenter.java
...rocket/android/fragment/sidebar/SidebarMainPresenter.java
+27
-0
No files found.
app/src/main/java/chat/rocket/android/RocketChatApplication.java
View file @
cf96cd2f
...
@@ -20,6 +20,12 @@ import chat.rocket.persistence.realm.RocketChatPersistenceRealm;
...
@@ -20,6 +20,12 @@ import chat.rocket.persistence.realm.RocketChatPersistenceRealm;
*/
*/
public
class
RocketChatApplication
extends
MultiDexApplication
{
public
class
RocketChatApplication
extends
MultiDexApplication
{
private
static
RocketChatApplication
instance
;
public
static
RocketChatApplication
getInstance
()
{
return
instance
;
}
@Override
@Override
public
void
onCreate
()
{
public
void
onCreate
()
{
super
.
onCreate
();
super
.
onCreate
();
...
@@ -37,5 +43,7 @@ public class RocketChatApplication extends MultiDexApplication {
...
@@ -37,5 +43,7 @@ public class RocketChatApplication extends MultiDexApplication {
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
AppCompatDelegate
.
setCompatVectorFromResourcesEnabled
(
true
);
AppCompatDelegate
.
setCompatVectorFromResourcesEnabled
(
true
);
}
}
instance
=
this
;
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/activity/MainActivity.java
View file @
cf96cd2f
...
@@ -252,6 +252,12 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
...
@@ -252,6 +252,12 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
R
.
string
.
server_config_activity_authenticating
,
Snackbar
.
LENGTH_INDEFINITE
));
R
.
string
.
server_config_activity_authenticating
,
Snackbar
.
LENGTH_INDEFINITE
));
}
}
public
void
showLogoutMessage
()
{
statusTicker
.
updateStatus
(
StatusTicker
.
STATUS_LOGGING_OUT
,
Snackbar
.
make
(
findViewById
(
getLayoutContainerForFragment
()),
"Logging Out..."
,
Snackbar
.
LENGTH_INDEFINITE
));
}
@Override
@Override
public
void
showConnectionOk
()
{
public
void
showConnectionOk
()
{
statusTicker
.
updateStatus
(
StatusTicker
.
STATUS_DISMISS
,
null
);
statusTicker
.
updateStatus
(
StatusTicker
.
STATUS_DISMISS
,
null
);
...
@@ -309,6 +315,11 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
...
@@ -309,6 +315,11 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
}
}
}
}
@DebugLog
public
void
hideLogoutMessage
()
{
statusTicker
.
updateStatus
(
StatusTicker
.
STATUS_DISMISS
,
null
);
}
@DebugLog
@DebugLog
public
void
onLogout
()
{
public
void
onLogout
()
{
if
(
new
RocketChatCache
(
getApplicationContext
()).
getSelectedServerHostname
()
==
null
)
{
if
(
new
RocketChatCache
(
getApplicationContext
()).
getSelectedServerHostname
()
==
null
)
{
...
@@ -319,12 +330,8 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
...
@@ -319,12 +330,8 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
}
}
@DebugLog
@DebugLog
public
void
beforeLogoutCleanup
()
{
public
void
cleanUpBeforeLogout
()
{
presenter
.
beforeLogout
();
presenter
.
beforeLogoutCleanUp
();
}
public
void
onFailedLogout
()
{
onHostnameUpdated
();
}
}
//TODO: consider this class to define in layouthelper for more complicated operation.
//TODO: consider this class to define in layouthelper for more complicated operation.
...
@@ -332,6 +339,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
...
@@ -332,6 +339,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
public
static
final
int
STATUS_DISMISS
=
0
;
public
static
final
int
STATUS_DISMISS
=
0
;
public
static
final
int
STATUS_CONNECTION_ERROR
=
1
;
public
static
final
int
STATUS_CONNECTION_ERROR
=
1
;
public
static
final
int
STATUS_TOKEN_LOGIN
=
2
;
public
static
final
int
STATUS_TOKEN_LOGIN
=
2
;
public
static
final
int
STATUS_LOGGING_OUT
=
3
;
private
int
status
;
private
int
status
;
private
Snackbar
snackbar
;
private
Snackbar
snackbar
;
...
...
app/src/main/java/chat/rocket/android/activity/MainContract.java
View file @
cf96cd2f
...
@@ -38,6 +38,6 @@ public interface MainContract {
...
@@ -38,6 +38,6 @@ public interface MainContract {
void
loadSignedInServers
(
String
hostname
);
void
loadSignedInServers
(
String
hostname
);
void
beforeLogout
();
void
beforeLogout
CleanUp
();
}
}
}
}
app/src/main/java/chat/rocket/android/activity/MainPresenter.java
View file @
cf96cd2f
...
@@ -134,7 +134,7 @@ public class MainPresenter extends BasePresenter<MainContract.View>
...
@@ -134,7 +134,7 @@ public class MainPresenter extends BasePresenter<MainContract.View>
}
}
@Override
@Override
public
void
beforeLogout
()
{
public
void
beforeLogout
CleanUp
()
{
clearSubscriptions
();
clearSubscriptions
();
}
}
...
...
app/src/main/java/chat/rocket/android/api/MethodCallHelper.java
View file @
cf96cd2f
...
@@ -7,20 +7,16 @@ import org.json.JSONArray;
...
@@ -7,20 +7,16 @@ import org.json.JSONArray;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
java.util.List
;
import
java.util.UUID
;
import
java.util.UUID
;
import
bolts.Continuation
;
import
bolts.Continuation
;
import
bolts.Task
;
import
bolts.Task
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.helper.CheckSum
;
import
chat.rocket.android.helper.CheckSum
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.service.ConnectivityManager
;
import
chat.rocket.android.service.ConnectivityManager
;
import
chat.rocket.android.service.ConnectivityManagerApi
;
import
chat.rocket.android.service.DDPClientRef
;
import
chat.rocket.android.service.DDPClientRef
;
import
chat.rocket.android_ddp.DDPClientCallback
;
import
chat.rocket.android_ddp.DDPClientCallback
;
import
chat.rocket.core.SyncState
;
import
chat.rocket.core.SyncState
;
import
chat.rocket.core.models.ServerInfo
;
import
chat.rocket.persistence.realm.RealmHelper
;
import
chat.rocket.persistence.realm.RealmHelper
;
import
chat.rocket.persistence.realm.RealmStore
;
import
chat.rocket.persistence.realm.RealmStore
;
import
chat.rocket.persistence.realm.models.ddp.RealmMessage
;
import
chat.rocket.persistence.realm.models.ddp.RealmMessage
;
...
@@ -265,24 +261,10 @@ public class MethodCallHelper {
...
@@ -265,24 +261,10 @@ public class MethodCallHelper {
*/
*/
public
Task
<
Void
>
logout
()
{
public
Task
<
Void
>
logout
()
{
return
call
(
"logout"
,
TIMEOUT_MS
).
onSuccessTask
(
task
->
{
return
call
(
"logout"
,
TIMEOUT_MS
).
onSuccessTask
(
task
->
{
Context
appContext
=
context
.
getApplicationContext
();
if
(
task
.
isFaulted
())
{
RocketChatCache
rocketChatCache
=
new
RocketChatCache
(
appContext
);
return
Task
.
forError
(
task
.
getError
());
String
currentHostname
=
rocketChatCache
.
getSelectedServerHostname
();
}
RealmHelper
currentRealmHelper
=
RealmStore
.
getOrCreate
(
currentHostname
);
return
null
;
return
currentRealmHelper
.
executeTransaction
(
realm
->
{
realm
.
deleteAll
();
ConnectivityManagerApi
connectivityManagerApi
=
ConnectivityManager
.
getInstance
(
appContext
);
connectivityManagerApi
.
removeServer
(
currentHostname
);
List
<
ServerInfo
>
serverList
=
connectivityManagerApi
.
getServerList
();
String
newHostname
=
null
;
if
(
serverList
!=
null
&&
serverList
.
size
()
>
0
)
{
newHostname
=
serverList
.
get
(
0
).
getHostname
();
}
rocketChatCache
.
removeHostname
(
currentHostname
);
rocketChatCache
.
removeSelectedRoomId
(
currentHostname
);
rocketChatCache
.
setSelectedServerHostname
(
newHostname
);
return
null
;
});
});
});
}
}
...
...
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainContract.java
View file @
cf96cd2f
...
@@ -23,6 +23,8 @@ public interface SidebarMainContract {
...
@@ -23,6 +23,8 @@ public interface SidebarMainContract {
void
filterRoomSidebarList
(
CharSequence
term
);
void
filterRoomSidebarList
(
CharSequence
term
);
void
show
(
User
user
);
void
show
(
User
user
);
void
onLogoutCleanUp
();
}
}
interface
Presenter
extends
BaseContract
.
Presenter
<
View
>
{
interface
Presenter
extends
BaseContract
.
Presenter
<
View
>
{
...
@@ -44,5 +46,7 @@ public interface SidebarMainContract {
...
@@ -44,5 +46,7 @@ public interface SidebarMainContract {
void
onUserOffline
();
void
onUserOffline
();
void
onLogout
(
Continuation
continuation
);
void
onLogout
(
Continuation
continuation
);
void
cleanUpBeforeLogout
();
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainFragment.java
View file @
cf96cd2f
...
@@ -321,26 +321,32 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
...
@@ -321,26 +321,32 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
adapter
.
setRoomListHeaders
(
roomListHeaders
);
adapter
.
setRoomListHeaders
(
roomListHeaders
);
}
}
private
void
setupLogoutButton
()
{
@Override
rootView
.
findViewById
(
R
.
id
.
btn_logout
).
setOnClickListener
(
view
->
{
public
void
onLogoutCleanUp
()
{
closeUserActionContainer
();
Activity
activity
=
getActivity
();
Activity
mainActivity
=
getActivity
();
if
(
activity
!=
null
&&
activity
instanceof
MainActivity
)
{
if
(
mainActivity
!=
null
&&
mainActivity
instanceof
MainActivity
)
{
((
MainActivity
)
activity
).
hideLogoutMessage
();
((
MainActivity
)
mainActivity
).
beforeLogoutCleanup
();
((
MainActivity
)
activity
).
onLogout
();
}
presenter
.
onLogout
(
task
->
{
presenter
.
onLogout
(
task
->
{
if
(
task
.
isFaulted
())
{
if
(
task
.
isFaulted
())
{
if
(
mainActivity
!=
null
&&
mainActivity
instanceof
MainActivity
)
{
((
MainActivity
)
mainActivity
).
onFailedLogout
();
}
return
Task
.
forError
(
task
.
getError
());
return
Task
.
forError
(
task
.
getError
());
}
}
if
(
mainActivity
!=
null
&&
mainActivity
instanceof
MainActivity
)
{
((
MainActivity
)
mainActivity
).
onLogout
();
}
return
null
;
return
null
;
});
});
}
}
private
void
setupLogoutButton
()
{
rootView
.
findViewById
(
R
.
id
.
btn_logout
).
setOnClickListener
(
view
->
{
closeUserActionContainer
();
final
Activity
activity
=
getActivity
();
if
(
activity
!=
null
&&
activity
instanceof
MainActivity
)
{
((
MainActivity
)
activity
).
showLogoutMessage
();
// Clear subscriptions.
((
MainActivity
)
activity
).
cleanUpBeforeLogout
();
}
// Clear relative data and set new hostname if any.
presenter
.
cleanUpBeforeLogout
();
});
});
}
}
...
...
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainPresenter.java
View file @
cf96cd2f
...
@@ -9,20 +9,26 @@ import java.util.List;
...
@@ -9,20 +9,26 @@ import java.util.List;
import
bolts.Continuation
;
import
bolts.Continuation
;
import
bolts.Task
;
import
bolts.Task
;
import
chat.rocket.android.BackgroundLooper
;
import
chat.rocket.android.BackgroundLooper
;
import
chat.rocket.android.RocketChatApplication
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.helper.AbsoluteUrlHelper
;
import
chat.rocket.android.helper.AbsoluteUrlHelper
;
import
chat.rocket.android.helper.LogIfError
;
import
chat.rocket.android.helper.LogIfError
;
import
chat.rocket.android.helper.Logger
;
import
chat.rocket.android.helper.Logger
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.service.ConnectivityManager
;
import
chat.rocket.android.service.ConnectivityManagerApi
;
import
chat.rocket.android.shared.BasePresenter
;
import
chat.rocket.android.shared.BasePresenter
;
import
chat.rocket.core.interactors.RoomInteractor
;
import
chat.rocket.core.interactors.RoomInteractor
;
import
chat.rocket.core.models.Room
;
import
chat.rocket.core.models.Room
;
import
chat.rocket.core.models.RoomSidebar
;
import
chat.rocket.core.models.RoomSidebar
;
import
chat.rocket.core.models.ServerInfo
;
import
chat.rocket.core.models.Spotlight
;
import
chat.rocket.core.models.Spotlight
;
import
chat.rocket.core.models.User
;
import
chat.rocket.core.models.User
;
import
chat.rocket.core.repositories.SpotlightRepository
;
import
chat.rocket.core.repositories.SpotlightRepository
;
import
chat.rocket.core.repositories.UserRepository
;
import
chat.rocket.core.repositories.UserRepository
;
import
chat.rocket.persistence.realm.RealmHelper
;
import
chat.rocket.persistence.realm.RealmStore
;
import
chat.rocket.persistence.realm.repositories.RealmSpotlightRepository
;
import
chat.rocket.persistence.realm.repositories.RealmSpotlightRepository
;
import
io.reactivex.Flowable
;
import
io.reactivex.Flowable
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
...
@@ -143,6 +149,27 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
...
@@ -143,6 +149,27 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
});
});
}
}
@Override
public
void
cleanUpBeforeLogout
()
{
String
currentHostname
=
rocketChatCache
.
getSelectedServerHostname
();
RealmHelper
realmHelper
=
RealmStore
.
getOrCreate
(
currentHostname
);
realmHelper
.
executeTransaction
(
realm
->
{
realm
.
deleteAll
();
ConnectivityManagerApi
connectivityManagerApi
=
ConnectivityManager
.
getInstance
(
RocketChatApplication
.
getInstance
());
connectivityManagerApi
.
removeServer
(
currentHostname
);
List
<
ServerInfo
>
serverList
=
connectivityManagerApi
.
getServerList
();
String
newHostname
=
null
;
if
(
serverList
!=
null
&&
serverList
.
size
()
>
0
)
{
newHostname
=
serverList
.
get
(
0
).
getHostname
();
}
rocketChatCache
.
removeHostname
(
currentHostname
);
rocketChatCache
.
removeSelectedRoomId
(
currentHostname
);
rocketChatCache
.
setSelectedServerHostname
(
newHostname
);
view
.
onLogoutCleanUp
();
return
null
;
});
}
@Override
@Override
public
void
disposeSubscriptions
()
{
public
void
disposeSubscriptions
()
{
clearSubscriptions
();
clearSubscriptions
();
...
...
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