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
2b88395e
Commit
2b88395e
authored
Dec 11, 2017
by
Lucio Maciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Signup support
parent
69989fb6
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
195 additions
and
27 deletions
+195
-27
AuthenticationModule.kt
.../rocket/android/authentication/di/AuthenticationModule.kt
+7
-0
SignupFragmentModule.kt
.../rocket/android/authentication/di/SignupFragmentModule.kt
+14
-0
SignupFragmentProvider.kt
...ocket/android/authentication/di/SignupFragmentProvider.kt
+11
-0
AuthTokenRepository.kt
...oid/authentication/infraestructure/AuthTokenRepository.kt
+16
-0
AuthenticationNavigator.kt
...id/authentication/presentation/AuthenticationNavigator.kt
+4
-4
LoginPresenter.kt
...ket/android/authentication/presentation/LoginPresenter.kt
+6
-18
SignupPresenter.kt
...et/android/authentication/presentation/SignupPresenter.kt
+59
-0
SignupView.kt
.../rocket/android/authentication/presentation/SignupView.kt
+7
-0
SignupFragment.kt
...a/chat/rocket/android/authentication/ui/SignupFragment.kt
+60
-2
ActivityBuilder.kt
...java/chat/rocket/android/dagger/module/ActivityBuilder.kt
+4
-2
Extensions.kt
app/src/main/java/chat/rocket/android/util/Extensions.kt
+7
-1
No files found.
app/src/main/java/chat/rocket/android/authentication/di/AuthenticationModule.kt
View file @
2b88395e
package
chat.rocket.android.authentication.di
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.authentication.ui.AuthenticationActivity
import
chat.rocket.android.dagger.scope.PerActivity
...
...
@@ -12,4 +13,10 @@ class AuthenticationModule {
@Provides
@PerActivity
fun
provideAuthenticationNavigator
(
activity
:
AuthenticationActivity
)
=
AuthenticationNavigator
(
activity
)
@Provides
@PerActivity
fun
provideAuthTokenRepository
():
AuthTokenRepository
{
return
AuthTokenRepository
()
}
}
app/src/main/java/chat/rocket/android/authentication/di/SignupFragmentModule.kt
0 → 100644
View file @
2b88395e
package
chat.rocket.android.authentication.di
import
chat.rocket.android.authentication.presentation.SignupView
import
chat.rocket.android.authentication.ui.SignupFragment
import
dagger.Module
import
dagger.Provides
@Module
class
SignupFragmentModule
{
@Provides
fun
signupView
(
frag
:
SignupFragment
):
SignupView
{
return
frag
}
}
app/src/main/java/chat/rocket/android/authentication/di/SignupFragmentProvider.kt
0 → 100644
View file @
2b88395e
package
chat.rocket.android.authentication.di
import
chat.rocket.android.authentication.ui.SignupFragment
import
dagger.Module
import
dagger.android.ContributesAndroidInjector
@Module
abstract
class
SignupFragmentProvider
{
@ContributesAndroidInjector
(
modules
=
arrayOf
(
SignupFragmentModule
::
class
))
abstract
fun
provideSignupFragment
():
SignupFragment
}
app/src/main/java/chat/rocket/android/authentication/infraestructure/AuthTokenRepository.kt
0 → 100644
View file @
2b88395e
package
chat.rocket.android.authentication.infraestructure
import
chat.rocket.common.model.Token
import
chat.rocket.core.TokenRepository
class
AuthTokenRepository
:
TokenRepository
{
var
savedToken
:
Token
?
=
null
override
fun
get
():
Token
?
{
return
savedToken
}
override
fun
save
(
token
:
Token
)
{
savedToken
=
token
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt
View file @
2b88395e
...
...
@@ -5,7 +5,7 @@ import chat.rocket.android.R
import
chat.rocket.android.app.MainActivity
import
chat.rocket.android.authentication.ui.AuthenticationActivity
import
chat.rocket.android.authentication.ui.LoginFragment
import
chat.rocket.android.authentication.ui.Sign
U
pFragment
import
chat.rocket.android.authentication.ui.Sign
u
pFragment
import
chat.rocket.android.util.addFragmentBackStack
class
AuthenticationNavigator
(
internal
val
activity
:
AuthenticationActivity
)
{
...
...
@@ -18,7 +18,7 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity) {
}
}
fun
toChat
Room
()
{
fun
toChat
List
()
{
val
chatRoom
=
Intent
(
activity
,
MainActivity
::
class
.
java
).
apply
{
//TODO any parameter to pass
}
...
...
@@ -26,9 +26,9 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity) {
activity
.
finish
()
}
fun
toSignUp
()
{
fun
toSignUp
(
server
:
String
)
{
activity
.
addFragmentBackStack
(
"signupFragment"
,
R
.
id
.
fragment_container
)
{
Sign
UpFragment
.
newInstance
(
)
Sign
upFragment
.
newInstance
(
server
)
}
}
}
app/src/main/java/chat/rocket/android/authentication/presentation/LoginPresenter.kt
View file @
2b88395e
package
chat.rocket.android.authentication.presentation
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.model.Token
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.TokenRepository
import
chat.rocket.core.internal.rest.login
import
kotlinx.coroutines.experimental.Job
import
kotlinx.coroutines.experimental.android.UI
...
...
@@ -16,18 +15,18 @@ import javax.inject.Inject
class
LoginPresenter
@Inject
constructor
(
private
val
view
:
LoginView
,
private
val
navigator
:
AuthenticationNavigator
,
private
val
okHttpClient
:
OkHttpClient
,
private
val
logger
:
PlatformLogger
)
{
private
val
logger
:
PlatformLogger
,
private
val
repository
:
AuthTokenRepository
)
{
var
job
:
Job
?
=
null
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
httpClient
=
okHttpClient
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
websocketUrl
=
navigator
.
currentServer
!!
tokenRepository
=
SimpleTokenProvider
()
tokenRepository
=
repository
platformLogger
=
logger
}
fun
authenticate
(
username
:
String
,
password
:
String
)
{
// TODO - validate input
...
...
@@ -37,7 +36,7 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
val
token
=
client
.
login
(
username
,
password
)
view
.
hideProgress
()
navigator
.
toChat
Room
()
navigator
.
toChat
List
()
}
catch
(
ex
:
RocketChatException
)
{
view
.
hideProgress
()
view
.
onLoginError
(
ex
.
message
)
...
...
@@ -53,17 +52,6 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
}
fun
signup
()
{
navigator
.
toSignUp
()
}
}
class
SimpleTokenProvider
:
TokenRepository
{
var
savedToken
:
Token
?
=
null
override
fun
get
():
Token
?
{
return
savedToken
}
override
fun
save
(
token
:
Token
)
{
savedToken
=
token
navigator
.
toSignUp
(
navigator
.
currentServer
!!
)
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/presentation/SignupPresenter.kt
0 → 100644
View file @
2b88395e
package
chat.rocket.android.authentication.presentation
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.login
import
chat.rocket.core.internal.rest.signup
import
kotlinx.coroutines.experimental.Job
import
kotlinx.coroutines.experimental.android.UI
import
kotlinx.coroutines.experimental.launch
import
okhttp3.HttpUrl
import
okhttp3.OkHttpClient
import
timber.log.Timber
import
javax.inject.Inject
class
SignupPresenter
@Inject
constructor
(
private
val
view
:
SignupView
,
private
val
navigator
:
AuthenticationNavigator
,
private
val
okHttpClient
:
OkHttpClient
,
private
val
logger
:
PlatformLogger
,
private
val
repository
:
AuthTokenRepository
)
{
var
job
:
Job
?
=
null
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
httpClient
=
okHttpClient
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
websocketUrl
=
navigator
.
currentServer
!!
tokenRepository
=
repository
platformLogger
=
logger
}
fun
signup
(
email
:
String
,
name
:
String
,
username
:
String
,
password
:
String
)
{
// TODO - validate input
job
=
launch
(
UI
)
{
view
.
showProgress
()
try
{
val
user
=
client
.
signup
(
email
,
name
,
username
,
password
)
Timber
.
d
(
"Created user: $user"
)
val
token
=
client
.
login
(
username
,
password
)
Timber
.
d
(
"Logged in: $token"
)
view
.
hideProgress
()
navigator
.
toChatList
()
}
catch
(
ex
:
RocketChatException
)
{
view
.
hideProgress
()
view
.
onSignupError
(
ex
.
message
)
}
}
}
fun
unbind
()
{
job
?.
let
{
it
.
cancel
()
}.
also
{
null
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/presentation/SignupView.kt
0 → 100644
View file @
2b88395e
package
chat.rocket.android.authentication.presentation
interface
SignupView
{
fun
showProgress
()
fun
hideProgress
()
fun
onSignupError
(
message
:
String
?
=
"Unknown error"
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/ui/Sign
U
pFragment.kt
→
app/src/main/java/chat/rocket/android/authentication/ui/Sign
u
pFragment.kt
View file @
2b88395e
package
chat.rocket.android.authentication.ui
import
DrawableHelper
import
android.app.ProgressDialog
import
android.os.Build
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.view.*
import
android.widget.Toast
import
chat.rocket.android.R
import
chat.rocket.android.app.KeyboardHelper
import
chat.rocket.android.authentication.presentation.SignupPresenter
import
chat.rocket.android.authentication.presentation.SignupView
import
chat.rocket.android.util.content
import
dagger.android.support.AndroidSupportInjection
import
kotlinx.android.synthetic.main.fragment_authentication_sign_up.*
import
javax.inject.Inject
class
Sign
UpFragment
:
Fragment
()
{
class
Sign
upFragment
:
Fragment
(),
SignupView
{
companion
object
{
fun
newInstance
()
=
SignUpFragment
()
private
const
val
SERVER_URL
=
"server_url"
fun
newInstance
(
url
:
String
)
=
SignupFragment
().
apply
{
arguments
=
Bundle
(
1
).
apply
{
putString
(
SERVER_URL
,
url
)
}
}
}
@Inject
lateinit
var
presenter
:
SignupPresenter
var
progress
:
ProgressDialog
?
=
null
lateinit
var
serverUrl
:
String
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
AndroidSupportInjection
.
inject
(
this
)
super
.
onCreate
(
savedInstanceState
)
// TODO - research a better way to initialize parameters on fragments.
serverUrl
=
arguments
?.
getString
(
SERVER_URL
)
?:
"https://open.rocket.chat"
}
override
fun
onDestroy
()
{
presenter
.
unbind
()
super
.
onDestroy
()
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
=
inflater
.
inflate
(
R
.
layout
.
fragment_authentication_sign_up
,
container
,
false
)
...
...
@@ -27,6 +58,15 @@ class SignUpFragment : Fragment() {
}
setupGlobalLayoutListener
()
button_sign_up
.
setOnClickListener
{
val
email
=
text_email
.
content
val
name
=
text_name
.
content
val
username
=
text_username
.
content
val
password
=
text_password
.
content
presenter
.
signup
(
email
,
name
,
username
,
password
)
}
}
override
fun
onDestroyView
()
{
...
...
@@ -59,4 +99,22 @@ class SignUpFragment : Fragment() {
text_new_user_agreement
.
visibility
=
View
.
VISIBLE
}
}
override
fun
showProgress
()
{
// TODO - change for a proper progress indicator
progress
=
ProgressDialog
.
show
(
activity
,
"Authenticating"
,
"Registering user"
)
}
override
fun
hideProgress
()
{
progress
?.
apply
{
cancel
()
}
progress
=
null
}
override
fun
onSignupError
(
message
:
String
?)
{
// TODO - show a proper error message
Toast
.
makeText
(
activity
,
message
,
Toast
.
LENGTH_LONG
).
show
()
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/dagger/module/ActivityBuilder.kt
View file @
2b88395e
package
chat.rocket.android.dagger.module
import
chat.rocket.android.app.MainActivity
import
chat.rocket.android.authentication.di.LoginFragmentProvider
import
chat.rocket.android.authentication.di.AuthenticationModule
import
chat.rocket.android.authentication.di.LoginFragmentProvider
import
chat.rocket.android.authentication.di.ServerFragmentProvider
import
chat.rocket.android.authentication.di.SignupFragmentProvider
import
chat.rocket.android.authentication.ui.AuthenticationActivity
import
chat.rocket.android.dagger.scope.PerActivity
import
dagger.Module
...
...
@@ -16,7 +17,8 @@ abstract class ActivityBuilder {
@ContributesAndroidInjector
(
modules
=
arrayOf
(
AuthenticationModule
::
class
,
LoginFragmentProvider
::
class
,
ServerFragmentProvider
::
class
ServerFragmentProvider
::
class
,
SignupFragmentProvider
::
class
))
abstract
fun
bindAuthenticationActivity
():
AuthenticationActivity
...
...
app/src/main/java/chat/rocket/android/util/Extensions.kt
View file @
2b88395e
package
chat.rocket.android.util
import
android.widget.TextView
fun
String
.
ifEmpty
(
value
:
String
):
String
{
if
(
isEmpty
())
{
return
value
}
return
this
}
\ No newline at end of file
}
var
TextView
.
content
:
String
get
()
=
this
.
text
.
toString
()
set
(
value
)
{
this
.
text
=
value
}
\ 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