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
f50e924b
Commit
f50e924b
authored
Jan 11, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop-2.x' into notifications
parents
049de2ba
226e069b
Changes
21
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
411 additions
and
127 deletions
+411
-127
LoginPresenter.kt
...droid/authentication/login/presentation/LoginPresenter.kt
+71
-11
LoginFragment.kt
...t/rocket/android/authentication/login/ui/LoginFragment.kt
+55
-57
AuthenticationNavigator.kt
...id/authentication/presentation/AuthenticationNavigator.kt
+10
-21
ServerPresenter.kt
...oid/authentication/server/presentation/ServerPresenter.kt
+40
-11
SignupPresenter.kt
...oid/authentication/signup/presentation/SignupPresenter.kt
+18
-4
TwoFAPresenter.kt
...d/authentication/twofactor/presentation/TwoFAPresenter.kt
+16
-5
TwoFAFragment.kt
...cket/android/authentication/twofactor/ui/TwoFAFragment.kt
+21
-5
ChatRoomsPresenter.kt
...cket/android/chatrooms/presentation/ChatRoomsPresenter.kt
+9
-2
AppModule.kt
.../main/java/chat/rocket/android/dagger/module/AppModule.kt
+20
-7
NetworkHelper.kt
...src/main/java/chat/rocket/android/helper/NetworkHelper.kt
+2
-2
SharedPrefsLocalRepository.kt
...cket/android/infrastructure/SharedPrefsLocalRepository.kt
+1
-1
CurrentServerRepository.kt
...t/rocket/android/server/domain/CurrentServerRepository.kt
+6
-0
GetCurrentServerInteractor.kt
...ocket/android/server/domain/GetCurrentServerInteractor.kt
+7
-0
GetSettingsInteractor.kt
...hat/rocket/android/server/domain/GetSettingsInteractor.kt
+7
-0
SaveCurrentServerInteractor.kt
...cket/android/server/domain/SaveCurrentServerInteractor.kt
+7
-0
SaveSettingsInteractor.kt
...at/rocket/android/server/domain/SaveSettingsInteractor.kt
+8
-0
SettingsRepository.kt
...a/chat/rocket/android/server/domain/SettingsRepository.kt
+48
-0
MemorySettingsRepository.kt
...ndroid/server/infraestructure/MemorySettingsRepository.kt
+18
-0
RocketChatClientFactory.kt
...android/server/infraestructure/RocketChatClientFactory.kt
+29
-0
ServerEntity.kt
...hat/rocket/android/server/infraestructure/ServerEntity.kt
+1
-1
SharedPrefsCurrentServerRepository.kt
...ver/infraestructure/SharedPrefsCurrentServerRepository.kt
+17
-0
No files found.
app/src/main/java/chat/rocket/android/authentication/login/presentation/LoginPresenter.kt
View file @
f50e924b
...
...
@@ -4,9 +4,12 @@ import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.helper.NetworkHelper
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.server.domain.*
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.launchUI
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.RocketChatTwoFactorException
import
chat.rocket.common.util.ifNull
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.login
import
chat.rocket.core.internal.rest.registerPushToken
...
...
@@ -16,11 +19,67 @@ import javax.inject.Inject
class
LoginPresenter
@Inject
constructor
(
private
val
view
:
LoginView
,
private
val
strategy
:
CancelStrategy
,
private
val
navigator
:
AuthenticationNavigator
,
private
val
localRepository
:
LocalRepository
)
{
@Inject
lateinit
var
client
:
RocketChatClient
private
val
localRepository
:
LocalRepository
,
private
val
settingsInteractor
:
GetSettingsInteractor
,
private
val
serverInteractor
:
GetCurrentServerInteractor
,
factory
:
RocketChatClientFactory
)
{
// TODO - we should validate the current server when opening the app, and have a nonnull get()
private
val
client
:
RocketChatClient
=
factory
.
create
(
serverInteractor
.
get
()
!!
)
fun
setup
()
{
val
server
=
serverInteractor
.
get
()
if
(
server
==
null
)
{
navigator
.
toServerScreen
()
return
}
val
settings
=
settingsInteractor
.
get
(
server
)
if
(
settings
==
null
)
{
navigator
.
toServerScreen
()
return
}
var
hasSocial
=
false
if
(
settings
.
facebookEnabled
())
{
view
.
enableLoginByFacebook
()
hasSocial
=
true
}
if
(
settings
.
githubEnabled
())
{
view
.
enableLoginByGithub
()
hasSocial
=
true
}
if
(
settings
.
googleEnabled
())
{
view
.
enableLoginByGoogle
()
hasSocial
=
true
}
if
(
settings
.
linkedinEnabled
())
{
view
.
enableLoginByLinkedin
()
hasSocial
=
true
}
if
(
settings
.
meteorEnabled
())
{
view
.
enableLoginByMeteor
()
hasSocial
=
true
}
if
(
settings
.
twitterEnabled
())
{
view
.
enableLoginByTwitter
()
hasSocial
=
true
}
if
(
settings
.
gitlabEnabled
())
{
view
.
enableLoginByGitlab
()
hasSocial
=
true
}
view
.
showSignUpView
(
settings
.
registrationEnabled
())
view
.
showOauthView
(
hasSocial
)
}
fun
authenticate
(
usernameOrEmail
:
String
,
password
:
String
)
{
val
server
=
serverInteractor
.
get
()
when
{
server
==
null
->
{
navigator
.
toServerScreen
()
}
usernameOrEmail
.
isBlank
()
->
{
view
.
alertWrongUsernameOrEmail
()
}
...
...
@@ -37,17 +96,19 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
registerPushToken
()
navigator
.
toChatList
()
}
catch
(
exception
:
RocketChatException
)
{
if
(
exception
is
RocketChatTwoFactorException
)
{
when
(
exception
)
{
is
RocketChatTwoFactorException
->
{
navigator
.
toTwoFA
(
usernameOrEmail
,
password
)
}
else
{
val
message
=
exception
.
message
if
(
message
!=
null
)
{
view
.
showMessage
(
message
)
}
else
{
}
else
->
{
exception
.
message
?.
let
{
view
.
showMessage
(
it
)
}.
ifNull
{
view
.
showGenericErrorMessage
()
}
}
}
}
view
.
hideLoading
()
}
else
{
...
...
@@ -66,7 +127,6 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
localRepository
.
get
(
LocalRepository
.
KEY_PUSH_TOKEN
)
?.
let
{
client
.
registerPushToken
(
it
)
}
// TODO: Schedule push token registering when it comes up null
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/login/ui/LoginFragment.kt
View file @
f50e924b
...
...
@@ -7,6 +7,7 @@ import android.os.Bundle
import
android.support.v4.app.Fragment
import
android.text.style.ClickableSpan
import
android.view.*
import
android.widget.ImageButton
import
android.view.inputmethod.InputMethodManager
import
android.widget.ScrollView
import
android.widget.Toast
...
...
@@ -27,7 +28,6 @@ class LoginFragment : Fragment(), LoginView {
@Inject
lateinit
var
presenter
:
LoginPresenter
@Inject
lateinit
var
appContext
:
Context
// TODO we really need it? Check alternatives...
/*
private
val
layoutListener
=
ViewTreeObserver
.
OnGlobalLayoutListener
{
if
(
KeyboardHelper
.
isSoftKeyboardShown
(
scroll_view
.
rootView
))
{
showSignUpView
(
false
)
...
...
@@ -42,7 +42,7 @@ class LoginFragment : Fragment(), LoginView {
}
}
private
var
isGlobalLayoutListenerSetUp
=
false
*/
companion
object
{
fun
newInstance
()
=
LoginFragment
()
}
...
...
@@ -67,29 +67,28 @@ class LoginFragment : Fragment(), LoginView {
tintEditTextDrawableStart
()
}
presenter
.
setup
()
showThreeSocialMethods
()
button_log_in
.
setOnClickListener
{
presenter
.
authenticate
(
text_username_or_email
.
textContent
,
text_password
.
textContent
)
}
/*
// TODO: THIS IS A PRESENTER CONCERN - REMOVE THAT ! WE SHOULD GET THE SERVER SETTINGS!
// -------------------------------------------------------------------------------------------------------------------
showOauthView(true)
// Show the first three social account's ImageButton (REMARK: we must show at maximum *three* views)
enableLoginByFacebook()
enableLoginByGithub()
enableLoginByGoogle()
setupFabListener
()
// Just an example: if the server allow the new users registration then show the respective interface.
setupSignUpListener
()
showSignUpView(true)
// -------------------------------------------------------------------------------------------------------------------
*/
}
/*
private
fun
showThreeSocialMethods
()
{
var
count
=
0
for
(
i
in
0
..
social_accounts_container
.
childCount
)
{
val
view
=
social_accounts_container
.
getChildAt
(
i
)
as
?
ImageButton
?:
continue
if
(
view
.
isEnabled
&&
count
<
3
)
{
view
.
visibility
=
View
.
VISIBLE
count
++
}
}
}
override
fun
onDestroyView
()
{
super
.
onDestroyView
()
if
(
isGlobalLayoutListenerSetUp
)
{
...
...
@@ -97,58 +96,58 @@ class LoginFragment : Fragment(), LoginView {
isGlobalLayoutListenerSetUp
=
false
}
}
*/
override
fun
showOauthView
(
value
:
Boolean
)
{
//
if (value) {
//
social_accounts_container.setVisibility(true)
//
button_fab.setVisibility(true)
//
//
// We need to setup the layout to hide and show the oauth interface when the soft keyboard is shown
//
// (means that the user touched the text_username_or_email or text_password EditText to fill that respective fields).
//
if (!isGlobalLayoutListenerSetUp) {
//
scroll_view.viewTreeObserver.addOnGlobalLayoutListener(layoutListener)
//
isGlobalLayoutListenerSetUp = true
//
}
//
} else {
//
social_accounts_container.setVisibility(false)
//
button_fab.setVisibility(false)
//
}
if
(
value
)
{
social_accounts_container
.
setVisibility
(
true
)
button_fab
.
setVisibility
(
true
)
// We need to setup the layout to hide and show the oauth interface when the soft keyboard is shown
// (means that the user touched the text_username_or_email or text_password EditText to fill that respective fields).
if
(!
isGlobalLayoutListenerSetUp
)
{
scroll_view
.
viewTreeObserver
.
addOnGlobalLayoutListener
(
layoutListener
)
isGlobalLayoutListenerSetUp
=
true
}
}
else
{
social_accounts_container
.
setVisibility
(
false
)
button_fab
.
setVisibility
(
false
)
}
}
override
fun
setupFabListener
()
{
//
button_fab.setOnClickListener({
//
button_fab.hide()
//
showRemainingSocialAccountsView()
//
scrollToBottom()
//
})
button_fab
.
setOnClickListener
({
button_fab
.
hide
()
showRemainingSocialAccountsView
()
scrollToBottom
()
})
}
override
fun
enableLoginByFacebook
()
{
button_facebook
.
setVisibility
(
true
)
button_facebook
.
isEnabled
=
true
}
override
fun
enableLoginByGithub
()
{
button_github
.
setVisibility
(
true
)
button_github
.
isEnabled
=
true
}
override
fun
enableLoginByGoogle
()
{
button_google
.
setVisibility
(
true
)
button_google
.
isEnabled
=
true
}
override
fun
enableLoginByLinkedin
()
{
button_linkedin
.
setVisibility
(
true
)
button_linkedin
.
isEnabled
=
true
}
override
fun
enableLoginByMeteor
()
{
button_meteor
.
setVisibility
(
true
)
button_meteor
.
isEnabled
=
true
}
override
fun
enableLoginByTwitter
()
{
button_twitter
.
setVisibility
(
true
)
button_twitter
.
isEnabled
=
true
}
override
fun
enableLoginByGitlab
()
{
button_gitlab
.
setVisibility
(
true
)
button_gitlab
.
isEnabled
=
true
}
override
fun
showSignUpView
(
value
:
Boolean
)
=
text_new_to_rocket_chat
.
setVisibility
(
value
)
...
...
@@ -195,7 +194,7 @@ class LoginFragment : Fragment(), LoginView {
DrawableHelper
.
compoundDrawables
(
arrayOf
(
text_username_or_email
,
text_password
),
drawables
)
}
}
/*
private
fun
showLoginButton
(
value
:
Boolean
)
{
button_log_in
.
setVisibility
(
value
)
}
...
...
@@ -212,26 +211,26 @@ class LoginFragment : Fragment(), LoginView {
TextHelper
.
addLink
(
text_new_to_rocket_chat
,
arrayOf
(
signUp
),
arrayOf
(
signUpListener
))
}
*/
private
fun
enableUserInput
(
value
:
Boolean
)
{
button_log_in
.
isEnabled
=
value
text_username_or_email
.
isEnabled
=
value
text_password
.
isEnabled
=
value
//
if (isEditTextEmpty()) {
//
showSignUpView(value)
//
showOauthView(value)
//
}
if
(
isEditTextEmpty
())
{
showSignUpView
(
value
)
showOauthView
(
value
)
}
}
/*
// Returns true if *all* EditTexts are empty.
private
fun
isEditTextEmpty
():
Boolean
=
text_username_or_email
.
textContent
.
isBlank
()
&&
text_password
.
textContent
.
isEmpty
()
private
fun
showRemainingSocialAccountsView
()
{
social_accounts_container
.
postDelayed
({
enableLoginByLinkedin()
enableLoginByMeteor()
enableLoginByTwitter()
enableLoginByGitlab()
for
(
i
in
0
..
social_accounts_container
.
childCount
)
{
val
view
=
social_accounts_container
.
getChildAt
(
i
)
as
?
ImageButton
?:
continue
if
(
view
.
isEnabled
)
view
.
visibility
=
View
.
VISIBLE
}
},
1000
)
}
...
...
@@ -240,5 +239,4 @@ class LoginFragment : Fragment(), LoginView {
scroll_view
.
fullScroll
(
ScrollView
.
FOCUS_DOWN
)
},
1250
)
}
*/
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt
View file @
f50e924b
...
...
@@ -3,31 +3,24 @@ package chat.rocket.android.authentication.presentation
import
android.content.Context
import
android.content.Intent
import
chat.rocket.android.R
import
chat.rocket.android.chatrooms.ui.MainActivity
import
chat.rocket.android.authentication.login.ui.LoginFragment
import
chat.rocket.android.authentication.signup.ui.SignupFragment
import
chat.rocket.android.authentication.twofactor.ui.TwoFAFragment
import
chat.rocket.android.authentication.ui.AuthenticationActivity
import
chat.rocket.android.chatrooms.ui.MainActivity
import
chat.rocket.android.util.addFragmentBackStack
import
chat.rocket.android.webview.webViewIntent
class
AuthenticationNavigator
(
internal
val
activity
:
AuthenticationActivity
,
internal
val
context
:
Context
)
{
lateinit
var
server
:
String
lateinit
var
usernameOrEmail
:
String
lateinit
var
password
:
String
fun
toLogin
(
server
:
String
)
{
this
.
server
=
server
fun
toLogin
()
{
activity
.
addFragmentBackStack
(
"loginFragment"
,
R
.
id
.
fragment_container
)
{
LoginFragment
.
newInstance
()
}
}
fun
toTwoFA
(
usernameOrEmail
:
String
,
password
:
String
)
{
this
.
usernameOrEmail
=
usernameOrEmail
this
.
password
=
password
fun
toTwoFA
(
username
:
String
,
password
:
String
)
{
activity
.
addFragmentBackStack
(
"twoFAFragment"
,
R
.
id
.
fragment_container
)
{
TwoFAFragment
.
newInstance
()
TwoFAFragment
.
newInstance
(
username
,
password
)
}
}
...
...
@@ -37,16 +30,8 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity, int
}
}
fun
toTermsOfService
()
{
val
webPageUrl
=
server
+
"/terms-of-service"
// TODO Move to UrlHelper
activity
.
startActivity
(
context
.
webViewIntent
(
webPageUrl
))
activity
.
overridePendingTransition
(
R
.
anim
.
slide_up
,
R
.
anim
.
hold
)
}
fun
toPrivacyPolicy
()
{
val
webPageUrl
=
server
+
"/privacy-policy"
// TODO Move to UrlHelper
activity
.
startActivity
(
context
.
webViewIntent
(
webPageUrl
))
activity
.
overridePendingTransition
(
R
.
anim
.
slide_up
,
R
.
anim
.
hold
)
fun
toWebPage
(
url
:
String
)
{
activity
.
startActivity
(
context
.
webViewIntent
(
url
))
}
fun
toChatList
()
{
...
...
@@ -56,4 +41,8 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity, int
activity
.
startActivity
(
chatList
)
activity
.
finish
()
}
fun
toServerScreen
()
{
TODO
(
"not implemented"
)
//To change body of created functions use File | Settings | File Templates.
}
}
app/src/main/java/chat/rocket/android/authentication/server/presentation/ServerPresenter.kt
View file @
f50e924b
...
...
@@ -3,28 +3,57 @@ package chat.rocket.android.authentication.server.presentation
import
chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.helper.NetworkHelper
import
chat.rocket.android.server.domain.*
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.launchUI
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.settings
import
java.security.InvalidParameterException
import
javax.inject.Inject
class
ServerPresenter
@Inject
constructor
(
private
val
view
:
ServerView
,
private
val
strategy
:
CancelStrategy
,
private
val
navigator
:
AuthenticationNavigator
)
{
@Inject
lateinit
var
client
:
RocketChatClient
private
val
navigator
:
AuthenticationNavigator
,
private
val
serverInteractor
:
SaveCurrentServerInteractor
,
private
val
settingsInteractor
:
SaveSettingsInteractor
,
private
val
factory
:
RocketChatClientFactory
)
{
private
var
settingsFilter
=
arrayOf
(
SITE_URL
,
SITE_NAME
,
FAVICON_512
,
USE_REALNAME
,
ALLOW_ROOM_NAME_SPECIAL_CHARS
,
FAVORITE_ROOMS
,
ACCOUNT_LOGIN_FORM
,
ACCOUNT_GOOGLE
,
ACCOUNT_FACEBOOK
,
ACCOUNT_GITHUB
,
ACCOUNT_GITLAB
,
ACCOUNT_LINKEDIN
,
ACCOUNT_METEOR
,
ACCOUNT_TWITTER
,
ACCOUNT_WORDPRESS
,
LDAP_ENABLE
,
ACCOUNT_REGISTRATION
,
STORAGE_TYPE
,
HIDE_USER_JOIN
,
HIDE_USER_LEAVE
,
HIDE_TYPE_AU
,
HIDE_MUTE_UNMUTE
,
HIDE_TYPE_RU
,
ACCOUNT_CUSTOM_FIELDS
)
fun
connect
(
server
:
String
)
{
var
cli
:
RocketChatClient
?
=
null
try
{
cli
=
factory
.
create
(
server
)
}
catch
(
ex
:
InvalidParameterException
)
{
view
.
showMessage
(
ex
.
message
!!
)
}
cli
?.
let
{
client
->
launchUI
(
strategy
)
{
if
(
NetworkHelper
.
hasInternetAccess
())
{
view
.
showLoading
()
// TODO - validate server URL and get server settings and info before going to Login screen
//client.connect(server)
navigator
.
toLogin
(
server
)
try
{
val
settings
=
client
.
settings
(*
settingsFilter
)
settingsInteractor
.
save
(
server
,
settings
)
serverInteractor
.
save
(
server
)
navigator
.
toLogin
()
}
catch
(
ex
:
Exception
)
{
ex
.
printStackTrace
()
view
.
showMessage
(
ex
.
message
!!
)
}
finally
{
view
.
hideLoading
()
}
}
else
{
view
.
showNoInternetConnection
()
}
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/signup/presentation/SignupPresenter.kt
View file @
f50e924b
...
...
@@ -4,6 +4,8 @@ import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.helper.NetworkHelper
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.server.domain.GetCurrentServerInteractor
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.launchUI
import
chat.rocket.common.RocketChatException
import
chat.rocket.core.RocketChatClient
...
...
@@ -15,11 +17,18 @@ import javax.inject.Inject
class
SignupPresenter
@Inject
constructor
(
private
val
view
:
SignupView
,
private
val
strategy
:
CancelStrategy
,
private
val
navigator
:
AuthenticationNavigator
,
private
val
localRepository
:
LocalRepository
)
{
@Inject
lateinit
var
client
:
RocketChatClient
private
val
localRepository
:
LocalRepository
,
private
val
serverInteractor
:
GetCurrentServerInteractor
,
private
val
factory
:
RocketChatClientFactory
)
{
private
val
client
:
RocketChatClient
=
factory
.
create
(
serverInteractor
.
get
()
!!
)
fun
signup
(
name
:
String
,
username
:
String
,
password
:
String
,
email
:
String
)
{
val
server
=
serverInteractor
.
get
()
when
{
server
==
null
->
{
navigator
.
toServerScreen
()
}
name
.
isBlank
()
->
{
view
.
alertBlankName
()
}
...
...
@@ -33,6 +42,7 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
view
.
alertBlankEmail
()
}
else
->
{
val
client
=
factory
.
create
(
server
)
launchUI
(
strategy
)
{
if
(
NetworkHelper
.
hasInternetAccess
())
{
view
.
showLoading
()
...
...
@@ -61,11 +71,15 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
}
fun
termsOfService
()
{
navigator
.
toTermsOfService
()
serverInteractor
.
get
()
?.
let
{
navigator
.
toWebPage
(
"/terms-of-service"
)
}
}
fun
privacyPolicy
()
{
navigator
.
toPrivacyPolicy
()
serverInteractor
.
get
()
?.
let
{
navigator
.
toWebPage
(
"/privacy-policy"
)
}
}
private
suspend
fun
registerPushToken
()
{
...
...
app/src/main/java/chat/rocket/android/authentication/twofactor/presentation/TwoFAPresenter.kt
View file @
f50e924b
...
...
@@ -4,6 +4,8 @@ import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.helper.NetworkHelper
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.server.domain.GetCurrentServerInteractor
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.launchUI
import
chat.rocket.common.RocketChatAuthException
import
chat.rocket.common.RocketChatException
...
...
@@ -15,19 +17,29 @@ import javax.inject.Inject
class
TwoFAPresenter
@Inject
constructor
(
private
val
view
:
TwoFAView
,
private
val
strategy
:
CancelStrategy
,
private
val
navigator
:
AuthenticationNavigator
,
private
val
localRepository
:
LocalRepository
)
{
@Inject
lateinit
var
client
:
RocketChatClient
private
val
localRepository
:
LocalRepository
,
private
val
serverInteractor
:
GetCurrentServerInteractor
,
private
val
factory
:
RocketChatClientFactory
)
{
fun
authenticate
(
twoFactorAuthenticationCode
:
String
)
{
private
val
client
:
RocketChatClient
=
factory
.
create
(
serverInteractor
.
get
()
!!
)
// TODO: If the usernameOrEmail and password was informed by the user on the previous screen, then we should pass only the pin, like this: fun authenticate(pin: EditText)
fun
authenticate
(
usernameOrEmail
:
String
,
password
:
String
,
twoFactorAuthenticationCode
:
String
)
{
val
server
=
serverInteractor
.
get
()
if
(
twoFactorAuthenticationCode
.
isBlank
())
{
view
.
alertBlankTwoFactorAuthenticationCode
()
}
else
if
(
server
==
null
)
{
navigator
.
toServerScreen
()
}
else
{
launchUI
(
strategy
)
{
val
client
=
factory
.
create
(
server
)
if
(
NetworkHelper
.
hasInternetAccess
())
{
view
.
showLoading
()
try
{
client
.
login
(
navigator
.
usernameOrEmail
,
navigator
.
password
,
twoFactorAuthenticationCode
)
// TODO This function returns a user token so should we save it?
// The token is saved via the client TokenProvider
client
.
login
(
usernameOrEmail
,
password
,
twoFactorAuthenticationCode
)
registerPushToken
()
navigator
.
toChatList
()
}
catch
(
exception
:
RocketChatException
)
{
...
...
@@ -42,7 +54,6 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
}
}
}
view
.
hideLoading
()
}
else
{
view
.
showNoInternetConnection
()
...
...
app/src/main/java/chat/rocket/android/authentication/twofactor/ui/TwoFAFragment.kt
View file @
f50e924b
...
...
@@ -22,15 +22,29 @@ import javax.inject.Inject
class
TwoFAFragment
:
Fragment
(),
TwoFAView
{
@Inject
lateinit
var
presenter
:
TwoFAPresenter
@Inject
lateinit
var
appContext
:
Context
// TODO we really need it? Check alternatives...
lateinit
var
username
:
String
lateinit
var
password
:
String
// TODO - we could create an in memory repository to save username and password.
companion
object
{
fun
newInstance
()
=
TwoFAFragment
()
private
const
val
USERNAME
=
"username"
private
const
val
PASSWORD
=
"password"
fun
newInstance
(
username
:
String
,
password
:
String
)
=
TwoFAFragment
().
apply
{
arguments
=
Bundle
(
1
).
apply
{
putString
(
USERNAME
,
username
)
putString
(
PASSWORD
,
password
)
}
}
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
AndroidSupportInjection
.
inject
(
this
)
// TODO - research a better way to initialize parameters on fragments.
username
=
arguments
?.
getString
(
USERNAME
)
?:
""
password
=
arguments
?.
getString
(
PASSWORD
)
?:
""
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
=
inflater
.
inflate
(
R
.
layout
.
fragment_authentication_two_fa
,
container
,
false
)
...
...
@@ -51,9 +65,11 @@ class TwoFAFragment : Fragment(), TwoFAView {
}
override
fun
alertBlankTwoFactorAuthenticationCode
()
{
AnimationHelper
.
vibrateSmartPhone
(
appContext
)
activity
?.
let
{
AnimationHelper
.
vibrateSmartPhone
(
it
)
AnimationHelper
.
shakeView
(
text_two_factor_auth
)
}
}
override
fun
alertInvalidTwoFactorAuthenticationCode
()
=
showMessage
(
getString
(
R
.
string
.
msg_invalid_2fa_code
))
...
...
@@ -89,7 +105,7 @@ class TwoFAFragment : Fragment(), TwoFAView {
private
fun
setupOnClickListener
()
{
button_log_in
.
setOnClickListener
{
presenter
.
authenticate
(
text_two_factor_auth
.
textContent
)
presenter
.
authenticate
(
username
,
password
,
text_two_factor_auth
.
textContent
)
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatrooms/presentation/ChatRoomsPresenter.kt
View file @
f50e924b
package
chat.rocket.android.chatrooms.presentation
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.server.domain.GetCurrentServerInteractor
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.launchUI
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.chatRooms
import
chat.rocket.core.model.ChatRoom
import
javax.inject.Inject
class
ChatRoomsPresenter
@Inject
constructor
(
private
val
view
:
ChatRoomsView
,
private
val
strategy
:
CancelStrategy
)
{
@Inject
lateinit
var
client
:
RocketChatClient
class
ChatRoomsPresenter
@Inject
constructor
(
private
val
view
:
ChatRoomsView
,
private
val
strategy
:
CancelStrategy
,
private
val
serverInteractor
:
GetCurrentServerInteractor
,
private
val
factory
:
RocketChatClientFactory
)
{
lateinit
var
client
:
RocketChatClient
fun
chatRooms
()
{
// TODO - check for current server
client
=
factory
.
create
(
serverInteractor
.
get
()
!!
)
launchUI
(
strategy
)
{
view
.
showLoading
()
val
chatRooms
=
client
.
chatRooms
().
update
...
...
app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt
View file @
f50e924b
...
...
@@ -5,12 +5,15 @@ import android.arch.persistence.room.Room
import
android.content.Context
import
android.content.SharedPreferences
import
chat.rocket.android.BuildConfig
import
chat.rocket.android.app.RocketChatApplication
import
chat.rocket.android.app.RocketChatDatabase
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.infrastructure.SharedPreferencesRepository
import
chat.rocket.android.infrastructure.SharedPrefsLocalRepository
import
chat.rocket.android.server.domain.CurrentServerRepository
import
chat.rocket.android.server.domain.SettingsRepository
import
chat.rocket.android.server.infraestructure.MemorySettingsRepository
import
chat.rocket.android.server.infraestructure.ServerDao
import
chat.rocket.android.server.infraestructure.SharedPrefsCurrentServerRepository
import
chat.rocket.android.util.TimberLogger
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
...
...
@@ -32,7 +35,6 @@ class AppModule {
platformLogger
=
logger
// TODO remove
// TODO: From where should we get the url here?
restUrl
=
"https://open.rocket.chat"
}
}
...
...
@@ -89,14 +91,25 @@ class AppModule {
}
@Provides
@Singleton
fun
provideSharedPreferences
(
context
:
Context
):
SharedPreferences
{
fun
provideSharedPreferences
(
context
:
Application
):
SharedPreferences
{
return
context
.
getSharedPreferences
(
"rocket.chat"
,
Context
.
MODE_PRIVATE
)
}
@Provides
@Singleton
fun
provideSharedPreferencesRepository
(
preferences
:
SharedPreferences
):
LocalRepository
{
return
SharedPreferencesRepository
(
preferences
)
fun
provideSharedPreferencesRepository
(
prefs
:
SharedPreferences
):
LocalRepository
{
return
SharedPrefsLocalRepository
(
prefs
)
}
@Provides
@Singleton
fun
provideCurrentServerRepository
(
prefs
:
SharedPreferences
):
CurrentServerRepository
{
return
SharedPrefsCurrentServerRepository
(
prefs
)
}
@Provides
@Singleton
fun
provideSettingsRepository
():
SettingsRepository
{
return
MemorySettingsRepository
()
}
}
app/src/main/java/chat/rocket/android/helper/NetworkHelper.kt
View file @
f50e924b
package
chat.rocket.android.helper
import
kotlinx.coroutines.experimental.CommonPool
import
kotlinx.coroutines.experimental.
run
import
kotlinx.coroutines.experimental.
withContext
import
java.io.IOException
import
java.net.InetSocketAddress
import
java.net.Socket
...
...
@@ -15,7 +15,7 @@ object NetworkHelper {
*
* @return true if there is internet access, false otherwise.
*/
suspend
fun
hasInternetAccess
():
Boolean
=
run
(
CommonPool
)
{
suspend
fun
hasInternetAccess
():
Boolean
=
withContext
(
CommonPool
)
{
try
{
val
socket
=
Socket
()
val
inetSocketAddress
=
InetSocketAddress
(
"8.8.8.8"
,
53
)
...
...
app/src/main/java/chat/rocket/android/infrastructure/SharedPref
erences
Repository.kt
→
app/src/main/java/chat/rocket/android/infrastructure/SharedPref
sLocal
Repository.kt
View file @
f50e924b
...
...
@@ -2,7 +2,7 @@ package chat.rocket.android.infrastructure
import
android.content.SharedPreferences
class
SharedPref
erences
Repository
(
private
val
preferences
:
SharedPreferences
)
:
LocalRepository
{
class
SharedPref
sLocal
Repository
(
private
val
preferences
:
SharedPreferences
)
:
LocalRepository
{
override
fun
save
(
key
:
String
,
value
:
String
?)
{
preferences
.
edit
().
putString
(
key
,
value
).
apply
()
...
...
app/src/main/java/chat/rocket/android/server/domain/CurrentServerRepository.kt
0 → 100644
View file @
f50e924b
package
chat.rocket.android.server.domain
interface
CurrentServerRepository
{
fun
save
(
url
:
String
)
fun
get
():
String
?
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/domain/GetCurrentServerInteractor.kt
0 → 100644
View file @
f50e924b
package
chat.rocket.android.server.domain
import
javax.inject.Inject
class
GetCurrentServerInteractor
@Inject
constructor
(
private
val
repository
:
CurrentServerRepository
)
{
fun
get
():
String
?
=
repository
.
get
()
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/domain/GetSettingsInteractor.kt
0 → 100644
View file @
f50e924b
package
chat.rocket.android.server.domain
import
javax.inject.Inject
class
GetSettingsInteractor
@Inject
constructor
(
private
val
repository
:
SettingsRepository
)
{
fun
get
(
url
:
String
)
=
repository
.
get
(
url
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/domain/SaveCurrentServerInteractor.kt
0 → 100644
View file @
f50e924b
package
chat.rocket.android.server.domain
import
javax.inject.Inject
class
SaveCurrentServerInteractor
@Inject
constructor
(
private
val
repository
:
CurrentServerRepository
)
{
fun
save
(
url
:
String
)
=
repository
.
save
(
url
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/domain/SaveSettingsInteractor.kt
0 → 100644
View file @
f50e924b
package
chat.rocket.android.server.domain
import
chat.rocket.core.model.Value
import
javax.inject.Inject
class
SaveSettingsInteractor
@Inject
constructor
(
private
val
repository
:
SettingsRepository
)
{
fun
save
(
url
:
String
,
settings
:
Map
<
String
,
Value
<
Any
>>)
=
repository
.
save
(
url
,
settings
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/domain/SettingsRepository.kt
0 → 100644
View file @
f50e924b
package
chat.rocket.android.server.domain
import
chat.rocket.core.model.Value
interface
SettingsRepository
{
fun
save
(
url
:
String
,
settings
:
Map
<
String
,
Value
<
Any
>>)
fun
get
(
url
:
String
):
Map
<
String
,
Value
<
Any
>>?
}
fun
Map
<
String
,
Value
<
Any
>>.
googleEnabled
():
Boolean
=
(
this
[
ACCOUNT_GOOGLE
]
as
Value
<
Boolean
>?)
?.
value
==
true
fun
Map
<
String
,
Value
<
Any
>>.
facebookEnabled
():
Boolean
=
(
this
[
ACCOUNT_FACEBOOK
]
as
Value
<
Boolean
>?)
?.
value
==
true
fun
Map
<
String
,
Value
<
Any
>>.
githubEnabled
():
Boolean
=
(
this
[
ACCOUNT_GITHUB
]
as
Value
<
Boolean
>?)
?.
value
==
true
fun
Map
<
String
,
Value
<
Any
>>.
linkedinEnabled
():
Boolean
=
(
this
[
ACCOUNT_LINKEDIN
]
as
Value
<
Boolean
>?)
?.
value
==
true
fun
Map
<
String
,
Value
<
Any
>>.
meteorEnabled
():
Boolean
=
(
this
[
ACCOUNT_METEOR
]
as
Value
<
Boolean
>?)
?.
value
==
true
fun
Map
<
String
,
Value
<
Any
>>.
twitterEnabled
():
Boolean
=
(
this
[
ACCOUNT_TWITTER
]
as
Value
<
Boolean
>?)
?.
value
==
true
fun
Map
<
String
,
Value
<
Any
>>.
gitlabEnabled
():
Boolean
=
(
this
[
ACCOUNT_GITLAB
]
as
Value
<
Boolean
>?)
?.
value
==
true
fun
Map
<
String
,
Value
<
Any
>>.
wordpressEnabled
():
Boolean
=
(
this
[
ACCOUNT_WORDPRESS
]
as
Value
<
Boolean
>?)
?.
value
==
true
fun
Map
<
String
,
Value
<
Any
>>.
registrationEnabled
():
Boolean
{
val
value
=
this
[
ACCOUNT_REGISTRATION
]
as
Value
<
String
>?
return
value
?.
value
==
"Public"
}
const
val
ACCOUNT_FACEBOOK
=
"Accounts_OAuth_Facebook"
const
val
ACCOUNT_GITHUB
=
"Accounts_OAuth_Github"
const
val
ACCOUNT_GITLAB
=
"Accounts_OAuth_Gitlab"
const
val
ACCOUNT_GOOGLE
=
"Accounts_OAuth_Google"
const
val
ACCOUNT_LINKEDIN
=
"Accounts_OAuth_Linkedin"
const
val
ACCOUNT_METEOR
=
"Accounts_OAuth_Meteor"
const
val
ACCOUNT_TWITTER
=
"Accounts_OAuth_Twitter"
const
val
ACCOUNT_WORDPRESS
=
"Accounts_OAuth_Wordpress"
const
val
ACCOUNT_REGISTRATION
=
"Accounts_RegistrationForm"
const
val
ACCOUNT_LOGIN_FORM
=
"Accounts_ShowFormLogin"
const
val
ACCOUNT_CUSTOM_FIELDS
=
"Accounts_CustomFields"
const
val
SITE_URL
=
"Site_Url"
const
val
SITE_NAME
=
"Site_Name"
const
val
FAVICON_512
=
"Assets_favicon_512"
const
val
USE_REALNAME
=
"UI_Use_Real_Name"
const
val
ALLOW_ROOM_NAME_SPECIAL_CHARS
=
"UI_Allow_room_names_with_special_chars"
const
val
FAVORITE_ROOMS
=
"Favorite_Rooms"
const
val
LDAP_ENABLE
=
"LDAP_Enable"
const
val
STORAGE_TYPE
=
"FileUpload_Storage_Type"
const
val
HIDE_USER_JOIN
=
"Message_HideType_uj"
const
val
HIDE_USER_LEAVE
=
"Message_HideType_ul"
const
val
HIDE_TYPE_AU
=
"Message_HideType_au"
const
val
HIDE_TYPE_RU
=
"Message_HideType_ru"
const
val
HIDE_MUTE_UNMUTE
=
"Message_HideType_mute_unmute"
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/infraestructure/MemorySettingsRepository.kt
0 → 100644
View file @
f50e924b
package
chat.rocket.android.server.infraestructure
import
chat.rocket.android.server.domain.SettingsRepository
import
chat.rocket.core.model.Value
class
MemorySettingsRepository
:
SettingsRepository
{
val
cache
=
HashMap
<
String
,
Map
<
String
,
Value
<
Any
>>>()
override
fun
save
(
url
:
String
,
settings
:
Map
<
String
,
Value
<
Any
>>)
{
cache
.
put
(
url
,
settings
)
}
override
fun
get
(
url
:
String
):
Map
<
String
,
Value
<
Any
>>?
{
return
cache
[
url
]
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/infraestructure/RocketChatClientFactory.kt
0 → 100644
View file @
f50e924b
package
chat.rocket.android.server.infraestructure
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
import
okhttp3.OkHttpClient
import
javax.inject.Inject
class
RocketChatClientFactory
@Inject
constructor
(
val
okHttpClient
:
OkHttpClient
,
val
repository
:
AuthTokenRepository
,
val
logger
:
PlatformLogger
)
{
private
val
cache
=
HashMap
<
String
,
RocketChatClient
>()
fun
create
(
url
:
String
):
RocketChatClient
{
cache
[
url
]
?.
let
{
return
it
}
val
client
=
RocketChatClient
.
create
{
httpClient
=
okHttpClient
restUrl
=
url
tokenRepository
=
repository
platformLogger
=
logger
}
cache
.
put
(
url
,
client
)
return
client
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/infraestructure/ServerEntity.kt
View file @
f50e924b
...
...
@@ -4,7 +4,7 @@ import android.arch.persistence.room.Entity
import
android.arch.persistence.room.Index
import
android.arch.persistence.room.PrimaryKey
@Entity
(
tableName
=
"server"
,
indices
=
arrayOf
(
Index
(
value
=
"host"
,
unique
=
true
))
)
@Entity
(
tableName
=
"server"
,
indices
=
[(
Index
(
value
=
[
"host"
],
unique
=
true
))]
)
data class
ServerEntity
(
@PrimaryKey
(
autoGenerate
=
true
)
val
id
:
Long
,
...
...
app/src/main/java/chat/rocket/android/server/infraestructure/SharedPrefsCurrentServerRepository.kt
0 → 100644
View file @
f50e924b
package
chat.rocket.android.server.infraestructure
import
android.content.SharedPreferences
import
chat.rocket.android.server.domain.CurrentServerRepository
class
SharedPrefsCurrentServerRepository
(
private
val
preferences
:
SharedPreferences
)
:
CurrentServerRepository
{
private
val
CURRENT_SERVER
=
"current_server"
override
fun
save
(
url
:
String
)
{
preferences
.
edit
().
putString
(
CURRENT_SERVER
,
url
).
apply
()
}
override
fun
get
():
String
?
{
return
preferences
.
getString
(
CURRENT_SERVER
,
null
)
}
}
\ No newline at end of file
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