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
4058b11c
Commit
4058b11c
authored
Dec 12, 2017
by
Lucio Maciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better organize authentication classes, use LifecycleObserver to cancel Jobs on onDestroy
parent
43391e73
Changes
37
Hide whitespace changes
Inline
Side-by-side
Showing
37 changed files
with
251 additions
and
180 deletions
+251
-180
build.gradle
app/build.gradle
+6
-0
BaseActivity.kt
app/src/main/java/chat/rocket/android/BaseActivity.kt
+0
-13
AuthenticationModule.kt
.../rocket/android/authentication/di/AuthenticationModule.kt
+6
-0
LoginFragmentModule.kt
...t/rocket/android/authentication/di/LoginFragmentModule.kt
+0
-14
SignupFragmentModule.kt
.../rocket/android/authentication/di/SignupFragmentModule.kt
+0
-14
TwoFAFragmentModule.kt
...t/rocket/android/authentication/di/TwoFAFragmentModule.kt
+0
-16
LoginFragmentModule.kt
...et/android/authentication/login/di/LoginFragmentModule.kt
+29
-0
LoginFragmentProvider.kt
.../android/authentication/login/di/LoginFragmentProvider.kt
+2
-2
LoginPresenter.kt
...droid/authentication/login/presentation/LoginPresenter.kt
+14
-22
LoginView.kt
...et/android/authentication/login/presentation/LoginView.kt
+7
-0
LoginFragment.kt
...t/rocket/android/authentication/login/ui/LoginFragment.kt
+7
-11
AuthenticationNavigator.kt
...id/authentication/presentation/AuthenticationNavigator.kt
+3
-3
LoginView.kt
...t/rocket/android/authentication/presentation/LoginView.kt
+0
-7
ServerView.kt
.../rocket/android/authentication/presentation/ServerView.kt
+0
-3
SignupView.kt
.../rocket/android/authentication/presentation/SignupView.kt
+0
-7
TwoFAView.kt
...t/rocket/android/authentication/presentation/TwoFAView.kt
+0
-3
ServerFragmentModule.kt
.../android/authentication/server/di/ServerFragmentModule.kt
+14
-0
ServerFragmentProvider.kt
...ndroid/authentication/server/di/ServerFragmentProvider.kt
+2
-2
ServerPresenter.kt
...oid/authentication/server/presentation/ServerPresenter.kt
+2
-1
ServerView.kt
.../android/authentication/server/presentation/ServerView.kt
+3
-0
ServerFragment.kt
...rocket/android/authentication/server/ui/ServerFragment.kt
+3
-3
SignupFragmentModule.kt
.../android/authentication/signup/di/SignupFragmentModule.kt
+29
-0
SignupFragmentProvider.kt
...ndroid/authentication/signup/di/SignupFragmentProvider.kt
+2
-2
SignupPresenter.kt
...oid/authentication/signup/presentation/SignupPresenter.kt
+9
-15
SignupView.kt
.../android/authentication/signup/presentation/SignupView.kt
+7
-0
SignupFragment.kt
...rocket/android/authentication/signup/ui/SignupFragment.kt
+7
-11
TwoFAFragmentModule.kt
...ndroid/authentication/twofactor/di/TwoFAFragmentModule.kt
+29
-0
TwoFAFragmentProvider.kt
...roid/authentication/twofactor/di/TwoFAFragmentProvider.kt
+2
-2
TwoFAPresenter.kt
...d/authentication/twofactor/presentation/TwoFAPresenter.kt
+9
-16
TwoFAView.kt
...ndroid/authentication/twofactor/presentation/TwoFAView.kt
+5
-0
TwoFAFragment.kt
...cket/android/authentication/twofactor/ui/TwoFAFragment.kt
+7
-12
AuthenticationActivity.kt
...ocket/android/authentication/ui/AuthenticationActivity.kt
+1
-0
LoadingView.kt
...n/java/chat/rocket/android/core/behaviours/LoadingView.kt
+6
-0
CancelStrategy.kt
...java/chat/rocket/android/core/lifecycle/CancelStrategy.kt
+19
-0
ActivityBuilder.kt
...java/chat/rocket/android/dagger/module/ActivityBuilder.kt
+4
-0
Coroutines.kt
app/src/main/java/chat/rocket/android/util/Coroutines.kt
+16
-0
dependencies.gradle
dependencies.gradle
+1
-1
No files found.
app/build.gradle
View file @
4058b11c
...
@@ -79,4 +79,10 @@ dependencies {
...
@@ -79,4 +79,10 @@ dependencies {
repositories
{
repositories
{
mavenCentral
()
mavenCentral
()
}
kotlin
{
experimental
{
coroutines
"enable"
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/BaseActivity.kt
deleted
100644 → 0
View file @
43391e73
package
chat.rocket.android
import
android.support.v4.app.Fragment
import
android.support.v7.app.AppCompatActivity
abstract
class
BaseActivity
:
AppCompatActivity
()
{
protected
fun
addFragment
(
tag
:
String
,
layoutId
:
Int
,
block
:
(
Unit
)
->
Fragment
)
{
val
fragment
=
supportFragmentManager
.
findFragmentByTag
(
tag
)
?:
block
(
Unit
)
supportFragmentManager
.
beginTransaction
().
replace
(
layoutId
,
fragment
,
tag
).
commit
()
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/di/AuthenticationModule.kt
View file @
4058b11c
...
@@ -6,6 +6,7 @@ import chat.rocket.android.authentication.ui.AuthenticationActivity
...
@@ -6,6 +6,7 @@ import chat.rocket.android.authentication.ui.AuthenticationActivity
import
chat.rocket.android.dagger.scope.PerActivity
import
chat.rocket.android.dagger.scope.PerActivity
import
dagger.Module
import
dagger.Module
import
dagger.Provides
import
dagger.Provides
import
kotlinx.coroutines.experimental.Job
@Module
@Module
class
AuthenticationModule
{
class
AuthenticationModule
{
...
@@ -19,4 +20,9 @@ class AuthenticationModule {
...
@@ -19,4 +20,9 @@ class AuthenticationModule {
fun
provideAuthTokenRepository
():
AuthTokenRepository
{
fun
provideAuthTokenRepository
():
AuthTokenRepository
{
return
AuthTokenRepository
()
return
AuthTokenRepository
()
}
}
@Provides
fun
provideJob
():
Job
{
return
Job
()
}
}
}
app/src/main/java/chat/rocket/android/authentication/di/LoginFragmentModule.kt
deleted
100644 → 0
View file @
43391e73
package
chat.rocket.android.authentication.di
import
chat.rocket.android.authentication.presentation.LoginView
import
chat.rocket.android.authentication.ui.LoginFragment
import
dagger.Module
import
dagger.Provides
@Module
class
LoginFragmentModule
{
@Provides
fun
loginView
(
frag
:
LoginFragment
):
LoginView
{
return
frag
}
}
app/src/main/java/chat/rocket/android/authentication/di/SignupFragmentModule.kt
deleted
100644 → 0
View file @
43391e73
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/TwoFAFragmentModule.kt
deleted
100644 → 0
View file @
43391e73
package
chat.rocket.android.authentication.di
import
chat.rocket.android.authentication.presentation.LoginView
import
chat.rocket.android.authentication.presentation.TwoFAView
import
chat.rocket.android.authentication.ui.LoginFragment
import
chat.rocket.android.authentication.ui.TwoFAFragment
import
dagger.Module
import
dagger.Provides
@Module
class
TwoFAFragmentModule
{
@Provides
fun
loginView
(
frag
:
TwoFAFragment
):
TwoFAView
{
return
frag
}
}
app/src/main/java/chat/rocket/android/authentication/login/di/LoginFragmentModule.kt
0 → 100644
View file @
4058b11c
package
chat.rocket.android.authentication.login.di
import
android.arch.lifecycle.LifecycleOwner
import
chat.rocket.android.authentication.login.presentation.LoginView
import
chat.rocket.android.authentication.login.ui.LoginFragment
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.dagger.scope.PerFragment
import
dagger.Module
import
dagger.Provides
import
kotlinx.coroutines.experimental.Job
@Module
@PerFragment
class
LoginFragmentModule
{
@Provides
fun
loginView
(
frag
:
LoginFragment
):
LoginView
{
return
frag
}
@Provides
fun
provideLifecycleOwner
(
frag
:
LoginFragment
):
LifecycleOwner
{
return
frag
}
@Provides
fun
provideCancelStrategy
(
owner
:
LifecycleOwner
,
jobs
:
Job
):
CancelStrategy
{
return
CancelStrategy
(
owner
,
jobs
)
}
}
app/src/main/java/chat/rocket/android/authentication/di/LoginFragmentProvider.kt
→
app/src/main/java/chat/rocket/android/authentication/
login/
di/LoginFragmentProvider.kt
View file @
4058b11c
package
chat.rocket.android.authentication.di
package
chat.rocket.android.authentication.
login.
di
import
chat.rocket.android.authentication.ui.LoginFragment
import
chat.rocket.android.authentication.
login.
ui.LoginFragment
import
dagger.Module
import
dagger.Module
import
dagger.android.ContributesAndroidInjector
import
dagger.android.ContributesAndroidInjector
...
...
app/src/main/java/chat/rocket/android/authentication/presentation/LoginPresenter.kt
→
app/src/main/java/chat/rocket/android/authentication/
login/
presentation/LoginPresenter.kt
View file @
4058b11c
package
chat.rocket.android.authentication.presentation
package
chat.rocket.android.authentication.
login.
presentation
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.common.RocketChatAuthException
import
chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.util.launchUI
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.RocketChatTwoFactorException
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.login
import
chat.rocket.core.internal.rest.login
import
kotlinx.coroutines.experimental.Job
import
kotlinx.coroutines.experimental.android.UI
import
kotlinx.coroutines.experimental.launch
import
okhttp3.HttpUrl
import
okhttp3.HttpUrl
import
okhttp3.OkHttpClient
import
okhttp3.OkHttpClient
import
javax.inject.Inject
import
javax.inject.Inject
class
LoginPresenter
@Inject
constructor
(
private
val
view
:
LoginView
,
class
LoginPresenter
@Inject
constructor
(
private
val
view
:
LoginView
,
private
val
strategy
:
CancelStrategy
,
private
val
navigator
:
AuthenticationNavigator
,
private
val
navigator
:
AuthenticationNavigator
,
private
val
okHttpClient
:
OkHttpClient
,
private
val
okHttpClient
:
OkHttpClient
,
private
val
logger
:
PlatformLogger
,
private
val
logger
:
PlatformLogger
,
private
val
repository
:
AuthTokenRepository
)
{
private
val
repository
:
AuthTokenRepository
)
{
var
job
:
Job
?
=
null
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
httpClient
=
okHttpClient
httpClient
=
okHttpClient
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
...
@@ -31,31 +31,23 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
...
@@ -31,31 +31,23 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
fun
authenticate
(
username
:
String
,
password
:
String
)
{
fun
authenticate
(
username
:
String
,
password
:
String
)
{
// TODO - validate input
// TODO - validate input
job
=
launch
(
UI
)
{
launchUI
(
strategy
)
{
view
.
show
Progress
()
view
.
show
Loading
()
try
{
try
{
val
token
=
client
.
login
(
username
,
password
)
val
token
=
client
.
login
(
username
,
password
)
view
.
hideProgress
()
navigator
.
toChatList
()
navigator
.
toChatList
()
}
catch
(
ex
:
RocketChatException
)
{
}
catch
(
ex
:
RocketChatException
)
{
view
.
hideProgress
()
when
(
ex
)
{
when
(
ex
)
{
is
RocketChat
Auth
Exception
->
is
RocketChat
TwoFactor
Exception
->
if
(
ex
.
error
?.
contentEquals
(
"totp-required"
)
==
true
)
{
navigator
.
toTwoFA
(
navigator
.
currentServer
!!
,
username
,
password
)
navigator
.
toTwoFA
(
navigator
.
currentServer
!!
,
username
,
password
)
else
->
}
view
.
onLoginError
(
ex
.
message
)
}
}
view
.
onLoginError
(
ex
.
message
)
}
finally
{
view
.
hideLoading
()
}
}
}
}
}
fun
unbind
()
{
job
?.
let
{
it
.
cancel
()
}.
also
{
null
}
}
}
fun
signup
()
{
fun
signup
()
{
...
...
app/src/main/java/chat/rocket/android/authentication/login/presentation/LoginView.kt
0 → 100644
View file @
4058b11c
package
chat.rocket.android.authentication.login.presentation
import
chat.rocket.android.core.behaviours.LoadingView
interface
LoginView
:
LoadingView
{
fun
onLoginError
(
message
:
String
?)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/ui/LoginFragment.kt
→
app/src/main/java/chat/rocket/android/authentication/
login/
ui/LoginFragment.kt
View file @
4058b11c
package
chat.rocket.android.authentication.ui
package
chat.rocket.android.authentication.
login.
ui
import
DrawableHelper
import
DrawableHelper
import
android.app.ProgressDialog
import
android.app.ProgressDialog
...
@@ -10,8 +10,8 @@ import android.widget.ScrollView
...
@@ -10,8 +10,8 @@ import android.widget.ScrollView
import
android.widget.Toast
import
android.widget.Toast
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.app.KeyboardHelper
import
chat.rocket.android.app.KeyboardHelper
import
chat.rocket.android.authentication.presentation.LoginPresenter
import
chat.rocket.android.authentication.
login.
presentation.LoginPresenter
import
chat.rocket.android.authentication.presentation.LoginView
import
chat.rocket.android.authentication.
login.
presentation.LoginView
import
dagger.android.support.AndroidSupportInjection
import
dagger.android.support.AndroidSupportInjection
import
kotlinx.android.synthetic.main.fragment_authentication_log_in.*
import
kotlinx.android.synthetic.main.fragment_authentication_log_in.*
import
javax.inject.Inject
import
javax.inject.Inject
...
@@ -42,11 +42,6 @@ class LoginFragment : Fragment(), LoginView {
...
@@ -42,11 +42,6 @@ class LoginFragment : Fragment(), LoginView {
serverUrl
=
arguments
?.
getString
(
SERVER_URL
)
?:
"https://open.rocket.chat"
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_log_in
,
container
,
false
)
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
=
inflater
.
inflate
(
R
.
layout
.
fragment_authentication_log_in
,
container
,
false
)
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
...
@@ -201,12 +196,13 @@ class LoginFragment : Fragment(), LoginView {
...
@@ -201,12 +196,13 @@ class LoginFragment : Fragment(), LoginView {
},
1500
)
},
1500
)
}
}
override
fun
show
Progress
()
{
override
fun
show
Loading
()
{
// TODO - change for a proper progress indicator
// TODO - change for a proper progress indicator
progress
=
ProgressDialog
.
show
(
activity
,
"Authenticating"
,
"Verifying user credentials"
)
progress
=
ProgressDialog
.
show
(
activity
,
"Authenticating"
,
"Verifying user credentials"
,
true
,
true
)
}
}
override
fun
hide
Progress
()
{
override
fun
hide
Loading
()
{
progress
?.
apply
{
progress
?.
apply
{
cancel
()
cancel
()
}
}
...
...
app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt
View file @
4058b11c
...
@@ -4,9 +4,9 @@ import android.content.Intent
...
@@ -4,9 +4,9 @@ import android.content.Intent
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.app.MainActivity
import
chat.rocket.android.app.MainActivity
import
chat.rocket.android.authentication.ui.AuthenticationActivity
import
chat.rocket.android.authentication.ui.AuthenticationActivity
import
chat.rocket.android.authentication.ui.LoginFragment
import
chat.rocket.android.authentication.
login.
ui.LoginFragment
import
chat.rocket.android.authentication.ui.SignupFragment
import
chat.rocket.android.authentication.
signup.
ui.SignupFragment
import
chat.rocket.android.authentication.ui.TwoFAFragment
import
chat.rocket.android.authentication.
twofactor.
ui.TwoFAFragment
import
chat.rocket.android.util.addFragmentBackStack
import
chat.rocket.android.util.addFragmentBackStack
class
AuthenticationNavigator
(
internal
val
activity
:
AuthenticationActivity
)
{
class
AuthenticationNavigator
(
internal
val
activity
:
AuthenticationActivity
)
{
...
...
app/src/main/java/chat/rocket/android/authentication/presentation/LoginView.kt
deleted
100644 → 0
View file @
43391e73
package
chat.rocket.android.authentication.presentation
interface
LoginView
{
fun
showProgress
()
fun
hideProgress
()
fun
onLoginError
(
message
:
String
?)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/presentation/ServerView.kt
deleted
100644 → 0
View file @
43391e73
package
chat.rocket.android.authentication.presentation
interface
ServerView
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/presentation/SignupView.kt
deleted
100644 → 0
View file @
43391e73
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/presentation/TwoFAView.kt
deleted
100644 → 0
View file @
43391e73
package
chat.rocket.android.authentication.presentation
interface
TwoFAView
:
LoginView
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/di/ServerFragmentModule.kt
→
app/src/main/java/chat/rocket/android/authentication/
server/
di/ServerFragmentModule.kt
View file @
4058b11c
package
chat.rocket.android.authentication.di
package
chat.rocket.android.authentication.
server.
di
import
chat.rocket.android.authentication.presentation.ServerView
import
chat.rocket.android.authentication.
server.
presentation.ServerView
import
chat.rocket.android.authentication.ui.ServerFragment
import
chat.rocket.android.authentication.
server.
ui.ServerFragment
import
dagger.Module
import
dagger.Module
import
dagger.Provides
import
dagger.Provides
...
...
app/src/main/java/chat/rocket/android/authentication/di/ServerFragmentProvider.kt
→
app/src/main/java/chat/rocket/android/authentication/
server/
di/ServerFragmentProvider.kt
View file @
4058b11c
package
chat.rocket.android.authentication.di
package
chat.rocket.android.authentication.
server.
di
import
chat.rocket.android.authentication.ui.ServerFragment
import
chat.rocket.android.authentication.
server.
ui.ServerFragment
import
dagger.Module
import
dagger.Module
import
dagger.android.ContributesAndroidInjector
import
dagger.android.ContributesAndroidInjector
...
...
app/src/main/java/chat/rocket/android/authentication/presentation/ServerPresenter.kt
→
app/src/main/java/chat/rocket/android/authentication/
server/
presentation/ServerPresenter.kt
View file @
4058b11c
package
chat.rocket.android.authentication.presentation
package
chat.rocket.android.authentication.
server.
presentation
import
chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
javax.inject.Inject
import
javax.inject.Inject
class
ServerPresenter
@Inject
constructor
(
private
val
view
:
ServerView
,
class
ServerPresenter
@Inject
constructor
(
private
val
view
:
ServerView
,
...
...
app/src/main/java/chat/rocket/android/authentication/server/presentation/ServerView.kt
0 → 100644
View file @
4058b11c
package
chat.rocket.android.authentication.server.presentation
interface
ServerView
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/ui/ServerFragment.kt
→
app/src/main/java/chat/rocket/android/authentication/
server/
ui/ServerFragment.kt
View file @
4058b11c
package
chat.rocket.android.authentication.ui
package
chat.rocket.android.authentication.
server.
ui
import
android.os.Bundle
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.support.v4.app.Fragment
...
@@ -7,8 +7,8 @@ import android.view.View
...
@@ -7,8 +7,8 @@ import android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
android.view.WindowManager
import
android.view.WindowManager
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.authentication.presentation.ServerPresenter
import
chat.rocket.android.authentication.
server.
presentation.ServerPresenter
import
chat.rocket.android.authentication.presentation.ServerView
import
chat.rocket.android.authentication.
server.
presentation.ServerView
import
chat.rocket.android.util.ifEmpty
import
chat.rocket.android.util.ifEmpty
import
dagger.android.support.AndroidSupportInjection
import
dagger.android.support.AndroidSupportInjection
import
kotlinx.android.synthetic.main.fragment_authentication_server.*
import
kotlinx.android.synthetic.main.fragment_authentication_server.*
...
...
app/src/main/java/chat/rocket/android/authentication/signup/di/SignupFragmentModule.kt
0 → 100644
View file @
4058b11c
package
chat.rocket.android.authentication.signup.di
import
android.arch.lifecycle.LifecycleOwner
import
chat.rocket.android.authentication.signup.presentation.SignupView
import
chat.rocket.android.authentication.signup.ui.SignupFragment
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.dagger.scope.PerFragment
import
dagger.Module
import
dagger.Provides
import
kotlinx.coroutines.experimental.Job
@Module
@PerFragment
class
SignupFragmentModule
{
@Provides
fun
signupView
(
frag
:
SignupFragment
):
SignupView
{
return
frag
}
@Provides
fun
provideLifecycleOwner
(
frag
:
SignupFragment
):
LifecycleOwner
{
return
frag
}
@Provides
fun
provideCancelStrategy
(
owner
:
LifecycleOwner
,
jobs
:
Job
):
CancelStrategy
{
return
CancelStrategy
(
owner
,
jobs
)
}
}
app/src/main/java/chat/rocket/android/authentication/di/SignupFragmentProvider.kt
→
app/src/main/java/chat/rocket/android/authentication/
signup/
di/SignupFragmentProvider.kt
View file @
4058b11c
package
chat.rocket.android.authentication.di
package
chat.rocket.android.authentication.
signup.
di
import
chat.rocket.android.authentication.ui.SignupFragment
import
chat.rocket.android.authentication.
signup.
ui.SignupFragment
import
dagger.Module
import
dagger.Module
import
dagger.android.ContributesAndroidInjector
import
dagger.android.ContributesAndroidInjector
...
...
app/src/main/java/chat/rocket/android/authentication/presentation/SignupPresenter.kt
→
app/src/main/java/chat/rocket/android/authentication/
signup/
presentation/SignupPresenter.kt
View file @
4058b11c
package
chat.rocket.android.authentication.presentation
package
chat.rocket.android.authentication.
signup.
presentation
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.util.launchUI
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.login
import
chat.rocket.core.internal.rest.login
import
chat.rocket.core.internal.rest.signup
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.HttpUrl
import
okhttp3.OkHttpClient
import
okhttp3.OkHttpClient
import
timber.log.Timber
import
timber.log.Timber
import
javax.inject.Inject
import
javax.inject.Inject
class
SignupPresenter
@Inject
constructor
(
private
val
view
:
SignupView
,
class
SignupPresenter
@Inject
constructor
(
private
val
view
:
SignupView
,
private
val
strategy
:
CancelStrategy
,
private
val
navigator
:
AuthenticationNavigator
,
private
val
navigator
:
AuthenticationNavigator
,
private
val
okHttpClient
:
OkHttpClient
,
private
val
okHttpClient
:
OkHttpClient
,
private
val
logger
:
PlatformLogger
,
private
val
logger
:
PlatformLogger
,
private
val
repository
:
AuthTokenRepository
)
{
private
val
repository
:
AuthTokenRepository
)
{
var
job
:
Job
?
=
null
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
httpClient
=
okHttpClient
httpClient
=
okHttpClient
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
...
@@ -32,8 +32,8 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
...
@@ -32,8 +32,8 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
fun
signup
(
email
:
String
,
name
:
String
,
username
:
String
,
password
:
String
)
{
fun
signup
(
email
:
String
,
name
:
String
,
username
:
String
,
password
:
String
)
{
// TODO - validate input
// TODO - validate input
job
=
launch
(
UI
)
{
launchUI
(
strategy
)
{
view
.
show
Progress
()
view
.
show
Loading
()
try
{
try
{
val
user
=
client
.
signup
(
email
,
name
,
username
,
password
)
val
user
=
client
.
signup
(
email
,
name
,
username
,
password
)
...
@@ -42,18 +42,12 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
...
@@ -42,18 +42,12 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
val
token
=
client
.
login
(
username
,
password
)
val
token
=
client
.
login
(
username
,
password
)
Timber
.
d
(
"Logged in: $token"
)
Timber
.
d
(
"Logged in: $token"
)
view
.
hideProgress
()
navigator
.
toChatList
()
navigator
.
toChatList
()
}
catch
(
ex
:
RocketChatException
)
{
}
catch
(
ex
:
RocketChatException
)
{
view
.
hideProgress
()
view
.
onSignupError
(
ex
.
message
)
view
.
onSignupError
(
ex
.
message
)
}
finally
{
view
.
hideLoading
()
}
}
}
}
}
}
fun
unbind
()
{
job
?.
let
{
it
.
cancel
()
}.
also
{
null
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/signup/presentation/SignupView.kt
0 → 100644
View file @
4058b11c
package
chat.rocket.android.authentication.signup.presentation
import
chat.rocket.android.core.behaviours.LoadingView
interface
SignupView
:
LoadingView
{
fun
onSignupError
(
message
:
String
?
=
"Unknown error"
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/ui/SignupFragment.kt
→
app/src/main/java/chat/rocket/android/authentication/
signup/
ui/SignupFragment.kt
View file @
4058b11c
package
chat.rocket.android.authentication.ui
package
chat.rocket.android.authentication.
signup.
ui
import
DrawableHelper
import
DrawableHelper
import
android.app.ProgressDialog
import
android.app.ProgressDialog
...
@@ -9,8 +9,8 @@ import android.view.*
...
@@ -9,8 +9,8 @@ import android.view.*
import
android.widget.Toast
import
android.widget.Toast
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.app.KeyboardHelper
import
chat.rocket.android.app.KeyboardHelper
import
chat.rocket.android.authentication.presentation.SignupPresenter
import
chat.rocket.android.authentication.
signup.
presentation.SignupPresenter
import
chat.rocket.android.authentication.presentation.SignupView
import
chat.rocket.android.authentication.
signup.
presentation.SignupView
import
chat.rocket.android.util.content
import
chat.rocket.android.util.content
import
dagger.android.support.AndroidSupportInjection
import
dagger.android.support.AndroidSupportInjection
import
kotlinx.android.synthetic.main.fragment_authentication_sign_up.*
import
kotlinx.android.synthetic.main.fragment_authentication_sign_up.*
...
@@ -41,11 +41,6 @@ class SignupFragment : Fragment(), SignupView {
...
@@ -41,11 +41,6 @@ class SignupFragment : Fragment(), SignupView {
serverUrl
=
arguments
?.
getString
(
SERVER_URL
)
?:
"https://open.rocket.chat"
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
)
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
=
inflater
.
inflate
(
R
.
layout
.
fragment_authentication_sign_up
,
container
,
false
)
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
...
@@ -100,12 +95,13 @@ class SignupFragment : Fragment(), SignupView {
...
@@ -100,12 +95,13 @@ class SignupFragment : Fragment(), SignupView {
}
}
}
}
override
fun
show
Progress
()
{
override
fun
show
Loading
()
{
// TODO - change for a proper progress indicator
// TODO - change for a proper progress indicator
progress
=
ProgressDialog
.
show
(
activity
,
"Authenticating"
,
"Registering user"
)
progress
=
ProgressDialog
.
show
(
activity
,
"Authenticating"
,
"Registering user"
,
true
,
true
)
}
}
override
fun
hide
Progress
()
{
override
fun
hide
Loading
()
{
progress
?.
apply
{
progress
?.
apply
{
cancel
()
cancel
()
}
}
...
...
app/src/main/java/chat/rocket/android/authentication/twofactor/di/TwoFAFragmentModule.kt
0 → 100644
View file @
4058b11c
package
chat.rocket.android.authentication.twofactor.di
import
android.arch.lifecycle.LifecycleOwner
import
chat.rocket.android.authentication.twofactor.presentation.TwoFAView
import
chat.rocket.android.authentication.twofactor.ui.TwoFAFragment
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.dagger.scope.PerFragment
import
dagger.Module
import
dagger.Provides
import
kotlinx.coroutines.experimental.Job
@Module
@PerFragment
class
TwoFAFragmentModule
{
@Provides
fun
loginView
(
frag
:
TwoFAFragment
):
TwoFAView
{
return
frag
}
@Provides
fun
provideLifecycleOwner
(
frag
:
TwoFAFragment
):
LifecycleOwner
{
return
frag
}
@Provides
fun
provideCancelStrategy
(
owner
:
LifecycleOwner
,
jobs
:
Job
):
CancelStrategy
{
return
CancelStrategy
(
owner
,
jobs
)
}
}
app/src/main/java/chat/rocket/android/authentication/di/TwoFAFragmentProvider.kt
→
app/src/main/java/chat/rocket/android/authentication/
twofactor/
di/TwoFAFragmentProvider.kt
View file @
4058b11c
package
chat.rocket.android.authentication.di
package
chat.rocket.android.authentication.
twofactor.
di
import
chat.rocket.android.authentication.ui.TwoFAFragment
import
chat.rocket.android.authentication.
twofactor.
ui.TwoFAFragment
import
dagger.Module
import
dagger.Module
import
dagger.android.ContributesAndroidInjector
import
dagger.android.ContributesAndroidInjector
...
...
app/src/main/java/chat/rocket/android/authentication/presentation/TwoFAPresenter.kt
→
app/src/main/java/chat/rocket/android/authentication/
twofactor/
presentation/TwoFAPresenter.kt
View file @
4058b11c
package
chat.rocket.android.authentication.presentation
package
chat.rocket.android.authentication.
twofactor.
presentation
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.util.launchUI
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.login
import
chat.rocket.core.internal.rest.login
import
kotlinx.coroutines.experimental.Job
import
kotlinx.coroutines.experimental.android.UI
import
kotlinx.coroutines.experimental.launch
import
okhttp3.HttpUrl
import
okhttp3.HttpUrl
import
okhttp3.OkHttpClient
import
okhttp3.OkHttpClient
import
javax.inject.Inject
import
javax.inject.Inject
class
TwoFAPresenter
@Inject
constructor
(
private
val
view
:
TwoFAView
,
class
TwoFAPresenter
@Inject
constructor
(
private
val
view
:
TwoFAView
,
private
val
strategy
:
CancelStrategy
,
private
val
navigator
:
AuthenticationNavigator
,
private
val
navigator
:
AuthenticationNavigator
,
private
val
okHttpClient
:
OkHttpClient
,
private
val
okHttpClient
:
OkHttpClient
,
private
val
logger
:
PlatformLogger
,
private
val
logger
:
PlatformLogger
,
private
val
repository
:
AuthTokenRepository
)
{
private
val
repository
:
AuthTokenRepository
)
{
var
job
:
Job
?
=
null
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
val
client
:
RocketChatClient
=
RocketChatClient
.
create
{
httpClient
=
okHttpClient
httpClient
=
okHttpClient
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
restUrl
=
HttpUrl
.
parse
(
navigator
.
currentServer
)
!!
...
@@ -30,25 +30,18 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
...
@@ -30,25 +30,18 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
fun
authenticate
(
username
:
String
,
password
:
String
,
pin
:
String
)
{
fun
authenticate
(
username
:
String
,
password
:
String
,
pin
:
String
)
{
// TODO - validate input
// TODO - validate input
job
=
launch
(
UI
)
{
launchUI
(
strategy
)
{
view
.
show
Progress
()
view
.
show
Loading
()
try
{
try
{
val
token
=
client
.
login
(
username
,
password
,
pin
)
val
token
=
client
.
login
(
username
,
password
,
pin
)
view
.
hideProgress
()
navigator
.
toChatList
()
navigator
.
toChatList
()
}
catch
(
ex
:
RocketChatException
)
{
}
catch
(
ex
:
RocketChatException
)
{
view
.
hideProgress
()
view
.
onLoginError
(
ex
.
message
)
view
.
onLoginError
(
ex
.
message
)
}
finally
{
view
.
hideLoading
()
}
}
}
}
}
fun
unbind
()
{
job
?.
let
{
it
.
cancel
()
}.
also
{
null
}
}
}
fun
signup
()
{
fun
signup
()
{
...
...
app/src/main/java/chat/rocket/android/authentication/twofactor/presentation/TwoFAView.kt
0 → 100644
View file @
4058b11c
package
chat.rocket.android.authentication.twofactor.presentation
import
chat.rocket.android.authentication.login.presentation.LoginView
interface
TwoFAView
:
LoginView
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/ui/TwoFAFragment.kt
→
app/src/main/java/chat/rocket/android/authentication/
twofactor/
ui/TwoFAFragment.kt
View file @
4058b11c
package
chat.rocket.android.authentication.ui
package
chat.rocket.android.authentication.
twofactor.
ui
import
DrawableHelper
import
DrawableHelper
import
android.app.ProgressDialog
import
android.app.ProgressDialog
...
@@ -11,8 +11,8 @@ import android.view.ViewGroup
...
@@ -11,8 +11,8 @@ import android.view.ViewGroup
import
android.view.WindowManager
import
android.view.WindowManager
import
android.widget.Toast
import
android.widget.Toast
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.authentication.presentation.TwoFAPresenter
import
chat.rocket.android.authentication.
twofactor.
presentation.TwoFAPresenter
import
chat.rocket.android.authentication.presentation.TwoFAView
import
chat.rocket.android.authentication.
twofactor.
presentation.TwoFAView
import
chat.rocket.android.util.content
import
chat.rocket.android.util.content
import
dagger.android.support.AndroidSupportInjection
import
dagger.android.support.AndroidSupportInjection
import
kotlinx.android.synthetic.main.fragment_authentication_two_fa.*
import
kotlinx.android.synthetic.main.fragment_authentication_two_fa.*
...
@@ -52,12 +52,6 @@ class TwoFAFragment : Fragment(), TwoFAView {
...
@@ -52,12 +52,6 @@ class TwoFAFragment : Fragment(), TwoFAView {
password
=
arguments
?.
getString
(
PASSWORD
)
?:
""
password
=
arguments
?.
getString
(
PASSWORD
)
?:
""
}
}
override
fun
onDestroy
()
{
presenter
.
unbind
()
super
.
onDestroy
()
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
=
inflater
.
inflate
(
R
.
layout
.
fragment_authentication_two_fa
,
container
,
false
)
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
=
inflater
.
inflate
(
R
.
layout
.
fragment_authentication_two_fa
,
container
,
false
)
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
...
@@ -84,12 +78,13 @@ class TwoFAFragment : Fragment(), TwoFAView {
...
@@ -84,12 +78,13 @@ class TwoFAFragment : Fragment(), TwoFAView {
}
}
}
}
override
fun
show
Progress
()
{
override
fun
show
Loading
()
{
// TODO - change for a proper progress indicator
// TODO - change for a proper progress indicator
progress
=
ProgressDialog
.
show
(
activity
,
"Authenticating"
,
"Verifying user credentials"
)
progress
=
ProgressDialog
.
show
(
activity
,
"Authenticating"
,
"Verifying user credentials"
,
true
,
true
)
}
}
override
fun
hide
Progress
()
{
override
fun
hide
Loading
()
{
progress
?.
apply
{
progress
?.
apply
{
cancel
()
cancel
()
}
}
...
...
app/src/main/java/chat/rocket/android/authentication/ui/AuthenticationActivity.kt
View file @
4058b11c
...
@@ -5,6 +5,7 @@ import android.support.v4.app.Fragment
...
@@ -5,6 +5,7 @@ import android.support.v4.app.Fragment
import
android.support.v7.app.AppCompatActivity
import
android.support.v7.app.AppCompatActivity
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.app.LayoutHelper
import
chat.rocket.android.app.LayoutHelper
import
chat.rocket.android.authentication.server.ui.ServerFragment
import
chat.rocket.android.util.addFragment
import
chat.rocket.android.util.addFragment
import
dagger.android.AndroidInjection
import
dagger.android.AndroidInjection
import
dagger.android.AndroidInjector
import
dagger.android.AndroidInjector
...
...
app/src/main/java/chat/rocket/android/core/behaviours/LoadingView.kt
0 → 100644
View file @
4058b11c
package
chat.rocket.android.core.behaviours
interface
LoadingView
{
fun
showLoading
()
fun
hideLoading
()
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/core/lifecycle/CancelStrategy.kt
0 → 100644
View file @
4058b11c
package
chat.rocket.android.core.lifecycle
import
android.arch.lifecycle.Lifecycle
import
android.arch.lifecycle.LifecycleObserver
import
android.arch.lifecycle.LifecycleOwner
import
android.arch.lifecycle.OnLifecycleEvent
import
kotlinx.coroutines.experimental.Job
import
javax.inject.Inject
class
CancelStrategy
@Inject
constructor
(
owner
:
LifecycleOwner
,
val
jobs
:
Job
)
:
LifecycleObserver
{
init
{
owner
.
lifecycle
.
addObserver
(
this
)
}
@OnLifecycleEvent
(
Lifecycle
.
Event
.
ON_DESTROY
)
fun
onDestroy
()
{
jobs
.
cancel
()
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/dagger/module/ActivityBuilder.kt
View file @
4058b11c
...
@@ -2,6 +2,10 @@ package chat.rocket.android.dagger.module
...
@@ -2,6 +2,10 @@ package chat.rocket.android.dagger.module
import
chat.rocket.android.app.MainActivity
import
chat.rocket.android.app.MainActivity
import
chat.rocket.android.authentication.di.*
import
chat.rocket.android.authentication.di.*
import
chat.rocket.android.authentication.login.di.LoginFragmentProvider
import
chat.rocket.android.authentication.server.di.ServerFragmentProvider
import
chat.rocket.android.authentication.signup.di.SignupFragmentProvider
import
chat.rocket.android.authentication.twofactor.di.TwoFAFragmentProvider
import
chat.rocket.android.authentication.ui.AuthenticationActivity
import
chat.rocket.android.authentication.ui.AuthenticationActivity
import
chat.rocket.android.dagger.scope.PerActivity
import
chat.rocket.android.dagger.scope.PerActivity
import
dagger.Module
import
dagger.Module
...
...
app/src/main/java/chat/rocket/android/util/Coroutines.kt
0 → 100644
View file @
4058b11c
package
chat.rocket.android.util
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
kotlinx.coroutines.experimental.CoroutineScope
import
kotlinx.coroutines.experimental.Job
import
kotlinx.coroutines.experimental.android.UI
import
kotlinx.coroutines.experimental.launch
/**
* Launches a coroutine on the UI context.
*
* @param strategy a CancelStrategy for canceling the coroutine job
*/
fun
launchUI
(
strategy
:
CancelStrategy
,
block
:
suspend
CoroutineScope
.()
->
Unit
):
Job
{
return
launch
(
context
=
UI
,
parent
=
strategy
.
jobs
,
block
=
block
)
}
\ No newline at end of file
dependencies.gradle
View file @
4058b11c
...
@@ -7,7 +7,7 @@ ext {
...
@@ -7,7 +7,7 @@ ext {
targetSdk
:
27
,
targetSdk
:
27
,
buildTools
:
'27.0.0'
,
buildTools
:
'27.0.0'
,
kotlin
:
'1.2.0'
,
kotlin
:
'1.2.0'
,
coroutine
:
'0.
19.3
'
,
coroutine
:
'0.
20
'
,
dokka
:
'0.9.15'
,
dokka
:
'0.9.15'
,
// Main dependencies
// Main dependencies
...
...
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