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
8eaf1c4b
Commit
8eaf1c4b
authored
Jan 29, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Logout and clear all data related to the current server
parent
f09e71c4
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
96 additions
and
12 deletions
+96
-12
SharedPreferencesMultiServerTokenRepository.kt
...estructure/SharedPreferencesMultiServerTokenRepository.kt
+5
-3
ChatRoomsPresenter.kt
...cket/android/chatrooms/presentation/ChatRoomsPresenter.kt
+29
-0
ChatRoomsView.kt
...at/rocket/android/chatrooms/presentation/ChatRoomsView.kt
+5
-0
ChatRoomsFragment.kt
...ava/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt
+18
-0
LocalRepository.kt
...ava/chat/rocket/android/infrastructure/LocalRepository.kt
+7
-1
SharedPrefsLocalRepository.kt
...cket/android/infrastructure/SharedPrefsLocalRepository.kt
+10
-0
CurrentServerRepository.kt
...t/rocket/android/server/domain/CurrentServerRepository.kt
+1
-0
GetCurrentServerInteractor.kt
...ocket/android/server/domain/GetCurrentServerInteractor.kt
+4
-0
MultiServerTokenRepository.kt
...ocket/android/server/domain/MultiServerTokenRepository.kt
+2
-0
SharedPreferencesSettingsRepository.kt
...er/infraestructure/SharedPreferencesSettingsRepository.kt
+1
-4
SharedPrefsCurrentServerRepository.kt
...ver/infraestructure/SharedPrefsCurrentServerRepository.kt
+4
-0
chatrooms_menu.xml
app/src/main/res/menu/chatrooms_menu.xml
+6
-2
strings.xml
app/src/main/res/values-pt-rBR/strings.xml
+2
-1
strings.xml
app/src/main/res/values/strings.xml
+2
-1
No files found.
app/src/main/java/chat/rocket/android/authentication/infraestructure/SharedPreferencesMultiServerTokenRepository.kt
View file @
8eaf1c4b
...
...
@@ -3,6 +3,7 @@ package chat.rocket.android.authentication.infraestructure
import
chat.rocket.android.authentication.domain.model.TokenModel
import
chat.rocket.android.dagger.scope.PerActivity
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.infrastructure.LocalRepository.Companion.TOKEN_KEY
import
chat.rocket.android.server.domain.MultiServerTokenRepository
import
com.squareup.moshi.Moshi
...
...
@@ -28,6 +29,7 @@ class SharedPreferencesMultiServerTokenRepository(private val repository: LocalR
repository
.
save
(
"$TOKEN_KEY$server"
,
adapter
.
toJson
(
token
))
}
override
fun
clear
(
server
:
String
)
{
repository
.
clear
(
"$TOKEN_KEY$server"
)
}
}
\ No newline at end of file
const
val
TOKEN_KEY
=
"token_"
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatrooms/presentation/ChatRoomsPresenter.kt
View file @
8eaf1c4b
package
chat.rocket.android.chatrooms.presentation
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.server.domain.GetChatRoomsInteractor
import
chat.rocket.android.server.domain.GetCurrentServerInteractor
import
chat.rocket.android.server.domain.SaveChatRoomsInteractor
...
...
@@ -10,6 +11,8 @@ import chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.model.Subscription
import
chat.rocket.core.internal.realtime.*
import
chat.rocket.core.internal.rest.chatRooms
import
chat.rocket.core.internal.rest.logout
import
chat.rocket.core.internal.rest.unregisterPushToken
import
chat.rocket.core.model.ChatRoom
import
chat.rocket.core.model.Room
import
kotlinx.coroutines.experimental.*
...
...
@@ -22,6 +25,7 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView,
private
val
serverInteractor
:
GetCurrentServerInteractor
,
private
val
getChatRoomsInteractor
:
GetChatRoomsInteractor
,
private
val
saveChatRoomsInteractor
:
SaveChatRoomsInteractor
,
private
val
localRepository
:
LocalRepository
,
factory
:
RocketChatClientFactory
)
{
private
val
client
:
RocketChatClient
=
factory
.
create
(
serverInteractor
.
get
()
!!
)
private
val
currentServer
=
serverInteractor
.
get
()
!!
...
...
@@ -245,4 +249,29 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView,
fun
disconnect
()
{
client
.
disconnect
()
}
fun
logout
()
{
launchUI
(
strategy
)
{
try
{
clearTokens
()
client
.
logout
()
//TODO: Add the code to unsubscribe to all subscriptions.
client
.
disconnect
()
view
.
onLogOut
()
}
catch
(
e
:
Exception
)
{
Timber
.
e
(
e
)
view
.
showMessage
(
e
.
message
!!
)
}
}
}
private
suspend
fun
clearTokens
()
{
serverInteractor
.
clear
()
val
pushToken
=
localRepository
.
get
(
LocalRepository
.
KEY_PUSH_TOKEN
)
if
(
pushToken
!=
null
)
{
client
.
unregisterPushToken
(
pushToken
)
localRepository
.
clear
(
LocalRepository
.
KEY_PUSH_TOKEN
)
}
localRepository
.
clearAllFromServer
(
currentServer
)
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatrooms/presentation/ChatRoomsView.kt
View file @
8eaf1c4b
...
...
@@ -12,4 +12,9 @@ interface ChatRoomsView : LoadingView, MessageView {
* @param dataSet The data set to show.
*/
suspend
fun
updateChatRooms
(
newDataSet
:
List
<
ChatRoom
>)
/**
* User has successfully logged out from the current server.
*/
fun
onLogOut
()
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt
View file @
8eaf1c4b
package
chat.rocket.android.chatrooms.ui
import
android.content.Intent
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.support.v7.app.AppCompatActivity
...
...
@@ -10,6 +11,7 @@ import android.support.v7.widget.SearchView
import
android.view.*
import
android.widget.Toast
import
chat.rocket.android.R
import
chat.rocket.android.authentication.ui.AuthenticationActivity
import
chat.rocket.android.chatrooms.presentation.ChatRoomsPresenter
import
chat.rocket.android.chatrooms.presentation.ChatRoomsView
import
chat.rocket.android.util.setVisibility
...
...
@@ -90,6 +92,13 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
})
}
override
fun
onOptionsItemSelected
(
item
:
MenuItem
?):
Boolean
{
when
(
item
?.
itemId
)
{
R
.
id
.
action_logout
->
presenter
.
logout
()
}
return
true
}
override
suspend
fun
updateChatRooms
(
newDataSet
:
List
<
ChatRoom
>)
{
activity
.
apply
{
launch
(
UI
)
{
...
...
@@ -112,6 +121,15 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
override
fun
showGenericErrorMessage
()
=
showMessage
(
getString
(
R
.
string
.
msg_generic_error
))
override
fun
onLogOut
()
{
activity
?.
apply
{
finish
()
val
intent
=
Intent
(
this
,
AuthenticationActivity
::
class
.
java
)
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_CLEAR_TASK
or
Intent
.
FLAG_ACTIVITY_NEW_TASK
)
startActivity
(
intent
)
}
}
private
fun
queryChatRoomsByName
(
name
:
String
?):
Boolean
{
presenter
.
chatRoomsByName
(
name
?:
""
)
return
true
...
...
app/src/main/java/chat/rocket/android/infrastructure/LocalRepository.kt
View file @
8eaf1c4b
...
...
@@ -3,10 +3,16 @@ package chat.rocket.android.infrastructure
interface
LocalRepository
{
companion
object
{
val
KEY_PUSH_TOKEN
=
"KEY_PUSH_TOKEN"
const
val
KEY_PUSH_TOKEN
=
"KEY_PUSH_TOKEN"
const
val
TOKEN_KEY
=
"token_"
const
val
SETTINGS_KEY
=
"settings_"
}
fun
save
(
key
:
String
,
value
:
String
?)
fun
get
(
key
:
String
):
String
?
fun
clear
(
key
:
String
)
fun
clearAllFromServer
(
server
:
String
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/infrastructure/SharedPrefsLocalRepository.kt
View file @
8eaf1c4b
...
...
@@ -11,4 +11,14 @@ class SharedPrefsLocalRepository(private val preferences: SharedPreferences) : L
override
fun
get
(
key
:
String
):
String
?
{
return
preferences
.
getString
(
key
,
null
)
}
override
fun
clear
(
key
:
String
)
{
preferences
.
edit
().
remove
(
key
).
apply
()
}
override
fun
clearAllFromServer
(
server
:
String
)
{
clear
(
LocalRepository
.
KEY_PUSH_TOKEN
)
clear
(
LocalRepository
.
TOKEN_KEY
+
server
)
clear
(
LocalRepository
.
SETTINGS_KEY
+
server
)
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/domain/CurrentServerRepository.kt
View file @
8eaf1c4b
...
...
@@ -3,4 +3,5 @@ package chat.rocket.android.server.domain
interface
CurrentServerRepository
{
fun
save
(
url
:
String
)
fun
get
():
String
?
fun
clear
()
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/domain/GetCurrentServerInteractor.kt
View file @
8eaf1c4b
...
...
@@ -4,4 +4,8 @@ import javax.inject.Inject
class
GetCurrentServerInteractor
@Inject
constructor
(
private
val
repository
:
CurrentServerRepository
)
{
fun
get
():
String
?
=
repository
.
get
()
fun
clear
()
{
repository
.
clear
()
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/domain/MultiServerTokenRepository.kt
View file @
8eaf1c4b
...
...
@@ -6,4 +6,6 @@ interface MultiServerTokenRepository {
fun
get
(
server
:
String
):
TokenModel
?
fun
save
(
server
:
String
,
token
:
TokenModel
)
fun
clear
(
server
:
String
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/infraestructure/SharedPreferencesSettingsRepository.kt
View file @
8eaf1c4b
package
chat.rocket.android.server.infraestructure
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.infrastructure.LocalRepository.Companion.SETTINGS_KEY
import
chat.rocket.android.server.domain.SettingsRepository
import
chat.rocket.core.internal.SettingsAdapter
import
chat.rocket.core.model.Value
...
...
@@ -21,8 +22,4 @@ class SharedPreferencesSettingsRepository(private val localRespository: LocalRep
return
null
}
companion
object
{
private
const
val
SETTINGS_KEY
=
"settings_"
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/infraestructure/SharedPrefsCurrentServerRepository.kt
View file @
8eaf1c4b
...
...
@@ -16,4 +16,8 @@ class SharedPrefsCurrentServerRepository(private val preferences: SharedPreferen
companion
object
{
private
const
val
CURRENT_SERVER_KEY
=
"current_server"
}
override
fun
clear
()
{
preferences
.
edit
().
remove
(
CURRENT_SERVER_KEY
).
apply
()
}
}
\ No newline at end of file
app/src/main/res/menu/chatrooms_menu.xml
View file @
8eaf1c4b
...
...
@@ -4,7 +4,11 @@
<item
android:id=
"@+id/action_search"
android:icon=
"@drawable/ic_search_white_24px"
android:title=
"@string/search"
android:title=
"@string/
action_
search"
app:actionViewClass=
"android.support.v7.widget.SearchView"
app:showAsAction=
"always|collapseActionView"
/>
app:showAsAction=
"ifRoom|collapseActionView"
/>
<item
android:id=
"@+id/action_logout"
android:title=
"@string/action_logout"
app:showAsAction=
"never"
/>
</menu>
\ No newline at end of file
app/src/main/res/values-pt-rBR/strings.xml
View file @
8eaf1c4b
...
...
@@ -11,7 +11,8 @@
<string
name=
"action_send"
>
Enviar
</string>
<string
name=
"action_terms_of_service"
>
Termos de Serviço
</string>
<string
name=
"action_privacy_policy"
>
Política de Privacidade
</string>
<string
name=
"search"
>
Pesquisar
</string>
<string
name=
"action_search"
>
Pesquisar
</string>
<string
name=
"action_logout"
>
Sair
</string>
<!-- Regular information messages -->
<string
name=
"msg_no_internet_connection"
>
Sem conexão à internet
</string>
...
...
app/src/main/res/values/strings.xml
View file @
8eaf1c4b
...
...
@@ -12,7 +12,8 @@
<string
name=
"action_send"
>
Send
</string>
<string
name=
"action_terms_of_service"
>
Terms of Service
</string>
<string
name=
"action_privacy_policy"
>
Privacy Policy
</string>
<string
name=
"search"
>
Search
</string>
<string
name=
"action_search"
>
Search
</string>
<string
name=
"action_logout"
>
Log Out
</string>
<!-- Regular information messages -->
<string
name=
"msg_no_internet_connection"
>
No internet connection
</string>
...
...
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