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
e528cdf2
Commit
e528cdf2
authored
May 16, 2018
by
aniket
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
deals with all email and password cases
parent
8ed04ad5
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
123 additions
and
60 deletions
+123
-60
LoginPresenter.kt
...droid/authentication/login/presentation/LoginPresenter.kt
+5
-1
LoginView.kt
...et/android/authentication/login/presentation/LoginView.kt
+1
-1
LoginFragment.kt
...t/rocket/android/authentication/login/ui/LoginFragment.kt
+46
-20
SignupView.kt
.../android/authentication/signup/presentation/SignupView.kt
+1
-1
SignupFragment.kt
...rocket/android/authentication/signup/ui/SignupFragment.kt
+10
-30
AuthenticationActivity.kt
...ocket/android/authentication/ui/AuthenticationActivity.kt
+8
-0
MainPresenter.kt
...va/chat/rocket/android/main/presentation/MainPresenter.kt
+2
-1
MainView.kt
...in/java/chat/rocket/android/main/presentation/MainView.kt
+5
-0
MainActivity.kt
...src/main/java/chat/rocket/android/main/ui/MainActivity.kt
+45
-6
No files found.
app/src/main/java/chat/rocket/android/authentication/login/presentation/LoginPresenter.kt
View file @
e528cdf2
...
...
@@ -17,6 +17,7 @@ import chat.rocket.common.model.Token
import
chat.rocket.common.util.ifNull
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.*
import
com.google.android.gms.auth.api.credentials.Credential
import
kotlinx.coroutines.experimental.delay
import
timber.log.Timber
import
java.util.concurrent.TimeUnit
...
...
@@ -303,7 +304,10 @@ class LoginPresenter @Inject constructor(
saveAccount
(
username
)
saveToken
(
token
)
registerPushToken
()
var
loginCredentials
:
Credential
=
Credential
.
Builder
(
usernameOrEmail
)
.
setPassword
(
password
)
.
build
()
view
.
saveSmartLockCredentials
(
loginCredentials
)
navigator
.
toChatList
()
}
else
if
(
loginType
==
TYPE_LOGIN_OAUTH
)
{
navigator
.
toRegisterUsername
(
token
.
userId
,
token
.
authToken
)
...
...
app/src/main/java/chat/rocket/android/authentication/login/presentation/LoginView.kt
View file @
e528cdf2
...
...
@@ -228,5 +228,5 @@ interface LoginView : LoadingView, MessageView {
/**
* Save credentials via google smart lock
*/
fun
saveSmartLockCredentials
(
loginCredential
:
Credential
)
fun
saveSmartLockCredentials
(
loginCredential
:
Credential
?
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/login/ui/LoginFragment.kt
View file @
e528cdf2
...
...
@@ -15,10 +15,7 @@ import android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewTreeObserver
import
android.widget.Button
import
android.widget.ImageButton
import
android.widget.LinearLayout
import
android.widget.ScrollView
import
android.widget.*
import
androidx.core.view.isVisible
import
androidx.core.view.postDelayed
import
chat.rocket.android.R
...
...
@@ -38,6 +35,7 @@ import com.google.android.gms.auth.api.Auth
import
com.google.android.gms.auth.api.credentials.*
import
com.google.android.gms.common.api.CommonStatusCodes
import
com.google.android.gms.common.api.GoogleApiClient
import
com.google.android.gms.common.api.ResolvingResultCallbacks
import
com.google.android.gms.common.api.Status
import
dagger.android.support.AndroidSupportInjection
import
kotlinx.android.synthetic.main.fragment_authentication_log_in.*
...
...
@@ -48,6 +46,9 @@ internal const val REQUEST_CODE_FOR_CAS = 1
internal
const
val
REQUEST_CODE_FOR_OAUTH
=
2
internal
const
val
MULTIPLE_CREDENTIALS_READ
=
3
internal
const
val
NO_CREDENTIALS_EXIST
=
4
internal
const
val
SAVE_CREDENTIALS
=
5
var
googleApiClient
:
GoogleApiClient
?
=
null
class
LoginFragment
:
Fragment
(),
LoginView
,
GoogleApiClient
.
ConnectionCallbacks
{
@Inject
...
...
@@ -58,7 +59,6 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks
}
private
var
isGlobalLayoutListenerSetUp
=
false
private
var
deepLinkInfo
:
LoginDeepLinkInfo
?
=
null
private
var
googleApiClient
:
GoogleApiClient
?
=
null
private
var
credentialsToBeSaved
:
Credential
?
=
null
companion
object
{
...
...
@@ -72,7 +72,7 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks
}
override
fun
onConnected
(
p0
:
Bundle
?)
{
//add call to the save credentials function here just like in sign up fragment
saveSmartLockCredentials
(
credentialsToBeSaved
)
}
override
fun
onConnectionSuspended
(
p0
:
Int
)
{
...
...
@@ -132,30 +132,35 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks
var
loginCredentials
:
Credential
=
data
!!
.
getParcelableExtra
(
Credential
.
EXTRA_KEY
)
handleCredential
(
loginCredentials
)
}
else
if
(
requestCode
==
NO_CREDENTIALS_EXIST
)
{
//use the hints to autofill s
ome info in the sign up or sign in forms
//use the hints to autofill s
ign in forms to reduce the info to be filled
var
loginCredentials
:
Credential
=
data
!!
.
getParcelableExtra
(
Credential
.
EXTRA_KEY
)
//pass these info to sign up view to autofill forms
var
name
=
loginCredentials
.
name
var
email
=
loginCredentials
.
id
var
password
=
loginCredentials
.
password
text_username_or_email
.
setText
(
email
)
text_password
.
setText
(
password
)
}
else
if
(
requestCode
==
SAVE_CREDENTIALS
)
{
Toast
.
makeText
(
context
,
"Credentials saved successfully"
,
Toast
.
LENGTH_SHORT
).
show
()
}
}
else
if
(
requestCode
==
SAVE_CREDENTIALS
)
{
Log
.
e
(
"STATUS"
,
"ERROR: Cancelled by user"
)
}
else
if
(
requestCode
==
MULTIPLE_CREDENTIALS_READ
)
{
Log
.
d
(
"STATUS"
,
"failed "
)
}
//cancelled
else
if
(
resultCode
==
Activity
.
RESULT_CANCELED
)
{
//cancel button pressed by the user in case of reading from smart lock
else
if
(
resultCode
==
Activity
.
RESULT_CANCELED
)
{
//add shared preference so that the dialog is not shown always
}
//create new account to use it as login account (deal with this case carefully, many edge cases)
else
if
(
resultCode
==
CredentialsApi
.
ACTIVITY_RESULT_ADD_ACCOUNT
)
{
//save credentials in this case after user signs up as well as in that case when user signs in
// with a new account other than those saved by smart lock. Also delete and disableAutoSignIn
// need to be implemented. Refer docs.
}
//no hints for user id's exist
else
if
(
resultCode
==
CredentialsApi
.
ACTIVITY_RESULT_NO_HINTS_AVAILABLE
)
{
}
else
{
Log
.
d
(
"Status"
,
"nothing happening"
)
}
}
...
...
@@ -188,16 +193,14 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks
.
build
()
Auth
.
CredentialsApi
.
request
(
googleApiClient
,
request
).
setResultCallback
{
credentialRequestResult
->
//hideProgress()
val
status
=
credentialRequestResult
.
status
if
(
status
.
isSuccess
)
{
// Auto sign-in success
handleCredential
(
credentialRequestResult
.
credential
)
}
else
if
(
status
.
statusCode
==
CommonStatusCodes
.
RESOLUTION_REQUIRED
)
{
// Getting credential needs to show some UI, start resolution
resolveResult
(
status
,
MULTIPLE_CREDENTIALS_READ
)
}
else
if
(
status
.
statusCode
==
CommonStatusCodes
.
SIGN_IN_REQUIRED
)
{
//resolveResult(status, NO_CREDENTIALS_EXIST)
//build a dialog for possible account hints
var
hintRequest
:
HintRequest
=
HintRequest
.
Builder
()
.
setHintPickerConfig
(
CredentialPickerConfig
.
Builder
()
...
...
@@ -233,8 +236,31 @@ class LoginFragment : Fragment(), LoginView, GoogleApiClient.ConnectionCallbacks
}
private
fun
resolveResult
(
status
:
Status
,
requestCode
:
Int
)
{
//TODO surround with a try/catch block
try
{
status
.
startResolutionForResult
(
activity
,
requestCode
)
}
catch
(
e
:
IntentSender
.
SendIntentException
)
{
Log
.
e
(
"STATUS"
,
"Failed to send Credentials intent."
,
e
)
}
}
override
fun
saveSmartLockCredentials
(
loginCredential
:
Credential
?)
{
credentialsToBeSaved
=
loginCredential
if
(
credentialsToBeSaved
==
null
)
{
return
}
Auth
.
CredentialsApi
.
save
(
googleApiClient
,
credentialsToBeSaved
).
setResultCallback
(
object
:
ResolvingResultCallbacks
<
Status
>(
activity
!!
,
SAVE_CREDENTIALS
)
{
override
fun
onSuccess
(
status
:
Status
)
{
Log
.
d
(
"STATUS"
,
"save:SUCCESS:$status"
)
credentialsToBeSaved
=
null
}
override
fun
onUnresolvableFailure
(
status
:
Status
)
{
Log
.
w
(
"STATUS"
,
"save:FAILURE:$status"
)
credentialsToBeSaved
=
null
}
})
}
private
fun
tintEditTextDrawableStart
()
{
...
...
app/src/main/java/chat/rocket/android/authentication/signup/presentation/SignupView.kt
View file @
e528cdf2
...
...
@@ -29,5 +29,5 @@ interface SignupView : LoadingView, MessageView {
/**
* Save credentials via google smart lock
*/
fun
saveSmartLockCredentials
(
loginCredential
:
Credential
)
fun
saveSmartLockCredentials
(
loginCredential
:
Credential
?
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/signup/ui/SignupFragment.kt
View file @
e528cdf2
...
...
@@ -8,9 +8,13 @@ import android.os.Bundle
import
android.support.v4.app.Fragment
import
android.text.style.ClickableSpan
import
android.util.Log
import
android.view.*
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewTreeObserver
import
android.widget.Toast
import
chat.rocket.android.R
import
chat.rocket.android.authentication.login.ui.googleApiClient
import
chat.rocket.android.authentication.signup.presentation.SignupPresenter
import
chat.rocket.android.authentication.signup.presentation.SignupView
import
chat.rocket.android.helper.KeyboardHelper
...
...
@@ -18,7 +22,6 @@ import chat.rocket.android.helper.TextHelper
import
chat.rocket.android.util.extensions.*
import
com.google.android.gms.auth.api.Auth
import
com.google.android.gms.auth.api.credentials.Credential
import
com.google.android.gms.common.api.GoogleApiClient
import
com.google.android.gms.common.api.ResolvingResultCallbacks
import
com.google.android.gms.common.api.Status
import
dagger.android.support.AndroidSupportInjection
...
...
@@ -27,18 +30,10 @@ import javax.inject.Inject
internal
const
val
SAVE_CREDENTIALS
=
1
class
SignupFragment
:
Fragment
(),
SignupView
,
GoogleApiClient
.
ConnectionCallbacks
{
override
fun
onConnected
(
p0
:
Bundle
?)
{
saveCredentials
()
}
override
fun
onConnectionSuspended
(
p0
:
Int
)
{
TODO
(
"not implemented"
)
//To change body of created functions use File | Settings | File Templates.
}
class
SignupFragment
:
Fragment
(),
SignupView
{
@Inject
lateinit
var
presenter
:
SignupPresenter
private
var
googleApiClient
:
GoogleApiClient
?
=
null
private
var
credentialsToBeSaved
:
Credential
?
=
null
private
val
layoutListener
=
ViewTreeObserver
.
OnGlobalLayoutListener
{
if
(
KeyboardHelper
.
isSoftKeyboardShown
(
relative_layout
.
rootView
))
{
...
...
@@ -79,12 +74,6 @@ class SignupFragment : Fragment(), SignupView, GoogleApiClient.ConnectionCallbac
}
}
override
fun
onDestroy
()
{
super
.
onDestroy
()
googleApiClient
!!
.
stopAutoManage
(
activity
!!
)
googleApiClient
!!
.
disconnect
()
}
override
fun
onDestroyView
()
{
relative_layout
.
viewTreeObserver
.
removeOnGlobalLayoutListener
(
layoutListener
)
super
.
onDestroyView
()
...
...
@@ -122,21 +111,12 @@ class SignupFragment : Fragment(), SignupView, GoogleApiClient.ConnectionCallbac
}
}
override
fun
saveSmartLockCredentials
(
loginCredential
:
Credential
)
{
override
fun
saveSmartLockCredentials
(
loginCredential
:
Credential
?
)
{
credentialsToBeSaved
=
loginCredential
googleApiClient
=
GoogleApiClient
.
Builder
(
context
!!
)
.
enableAutoManage
(
activity
!!
,
{
Log
.
d
(
"STATUS"
,
"ERROR: connection to client failed"
)
})
.
addConnectionCallbacks
(
this
)
.
addApi
(
Auth
.
CREDENTIALS_API
)
.
build
()
}
override
fun
onStart
()
{
super
.
onStart
()
if
(
googleApiClient
!!
.
isConnected
)
{
saveCredentials
()
}
}
override
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
?)
{
if
(
requestCode
==
SAVE_CREDENTIALS
)
{
...
...
app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt
View file @
e528cdf2
...
...
@@ -43,6 +43,14 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector {
}
}
override
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
?)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
)
val
currentFragment
=
supportFragmentManager
.
findFragmentById
(
R
.
id
.
fragment_container
)
if
(
currentFragment
!=
null
){
currentFragment
.
onActivityResult
(
requestCode
,
resultCode
,
data
)
}
}
override
fun
onDestroy
()
{
job
.
cancel
()
super
.
onDestroy
()
...
...
app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt
View file @
e528cdf2
...
...
@@ -105,11 +105,12 @@ class MainPresenter @Inject constructor(
disconnect
()
removeAccountInteractor
.
remove
(
currentServer
)
tokenRepository
.
remove
(
currentServer
)
view
.
disableAutoSignIn
()
navigator
.
toNewServer
()
}
catch
(
ex
:
Exception
)
{
Timber
.
d
(
ex
,
"Error cleaning up the session..."
)
}
view
.
disableAutoSignIn
()
navigator
.
toNewServer
()
}
}
...
...
app/src/main/java/chat/rocket/android/main/presentation/MainView.kt
View file @
e528cdf2
...
...
@@ -24,4 +24,9 @@ interface MainView : MessageView, VersionCheckView {
fun
setupNavHeader
(
viewModel
:
NavHeaderViewModel
,
accounts
:
List
<
Account
>)
fun
closeServerSelection
()
/**
* callback to disable auto sign in for google smart lock when the user logs out
*/
fun
disableAutoSignIn
()
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt
View file @
e528cdf2
...
...
@@ -6,6 +6,7 @@ import android.os.Bundle
import
android.support.v4.app.Fragment
import
android.support.v7.app.AppCompatActivity
import
android.support.v7.widget.LinearLayoutManager
import
android.util.Log
import
android.view.Gravity
import
android.view.MenuItem
import
android.view.View
...
...
@@ -22,6 +23,8 @@ import chat.rocket.android.util.extensions.fadeOut
import
chat.rocket.android.util.extensions.rotateBy
import
chat.rocket.android.util.extensions.showToast
import
chat.rocket.common.model.UserStatus
import
com.google.android.gms.auth.api.Auth
import
com.google.android.gms.common.api.GoogleApiClient
import
com.google.android.gms.gcm.GoogleCloudMessaging
import
com.google.android.gms.iid.InstanceID
import
dagger.android.AndroidInjection
...
...
@@ -37,18 +40,29 @@ import kotlinx.coroutines.experimental.launch
import
timber.log.Timber
import
javax.inject.Inject
class
MainActivity
:
AppCompatActivity
(),
MainView
,
HasActivityInjector
,
HasSupportFragmentInjector
{
@Inject
lateinit
var
activityDispatchingAndroidInjector
:
DispatchingAndroidInjector
<
Activity
>
@Inject
lateinit
var
fragmentDispatchingAndroidInjector
:
DispatchingAndroidInjector
<
Fragment
>
@Inject
lateinit
var
presenter
:
MainPresenter
class
MainActivity
:
AppCompatActivity
(),
MainView
,
HasActivityInjector
,
HasSupportFragmentInjector
,
GoogleApiClient
.
ConnectionCallbacks
{
override
fun
onConnected
(
p0
:
Bundle
?)
{
}
override
fun
onConnectionSuspended
(
p0
:
Int
)
{
}
@Inject
lateinit
var
activityDispatchingAndroidInjector
:
DispatchingAndroidInjector
<
Activity
>
@Inject
lateinit
var
fragmentDispatchingAndroidInjector
:
DispatchingAndroidInjector
<
Fragment
>
@Inject
lateinit
var
presenter
:
MainPresenter
private
var
isFragmentAdded
:
Boolean
=
false
private
var
expanded
=
false
private
var
googleApiClient
:
GoogleApiClient
?
=
null
private
val
headerLayout
by
lazy
{
view_navigation
.
getHeaderView
(
0
)
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
AndroidInjection
.
inject
(
this
)
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_main
)
buildGoogleApiClient
()
launch
(
CommonPool
)
{
try
{
...
...
@@ -66,6 +80,31 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, HasSupp
setupNavigationView
()
}
private
fun
buildGoogleApiClient
()
{
googleApiClient
=
GoogleApiClient
.
Builder
(
this
)
.
enableAutoManage
(
this
,
{
Log
.
d
(
"STATUS"
,
"ERROR: connection to client failed"
)
})
.
addConnectionCallbacks
(
this
)
.
addApi
(
Auth
.
CREDENTIALS_API
)
.
build
()
}
override
fun
onStart
()
{
super
.
onStart
()
if
(
googleApiClient
!!
.
isConnected
)
{
Log
.
d
(
"STATUS"
,
"google api client connected successfully"
)
}
}
override
fun
disableAutoSignIn
()
{
if
(
googleApiClient
!!
.
isConnected
)
{
Auth
.
CredentialsApi
.
disableAutoSignIn
(
googleApiClient
)
}
else
{
Log
.
e
(
"STATUS"
,
"Failed to disable auto sign in"
)
}
}
override
fun
onResume
()
{
super
.
onResume
()
if
(!
isFragmentAdded
)
{
...
...
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