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
2b2f7499
Commit
2b2f7499
authored
Feb 13, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LoginActivity
parent
2334c8a6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
160 additions
and
63 deletions
+160
-63
LoginActivity.java
...main/java/chat/rocket/android/activity/LoginActivity.java
+34
-52
LoginContract.java
...main/java/chat/rocket/android/activity/LoginContract.java
+17
-0
LoginPresenter.java
...ain/java/chat/rocket/android/activity/LoginPresenter.java
+61
-0
RealmSessionRepository.java
...ersistence/realm/repositories/RealmSessionRepository.java
+9
-11
SessionInteractor.java
.../java/chat/rocket/core/interactors/SessionInteractor.java
+37
-0
Session.java
...t-core/src/main/java/chat/rocket/core/models/Session.java
+2
-0
No files found.
app/src/main/java/chat/rocket/android/activity/LoginActivity.java
View file @
2b2f7499
...
@@ -8,20 +8,17 @@ import android.support.v4.app.Fragment;
...
@@ -8,20 +8,17 @@ import android.support.v4.app.Fragment;
import
chat.rocket.android.R
;
import
chat.rocket.android.R
;
import
chat.rocket.android.fragment.server_config.LoginFragment
;
import
chat.rocket.android.fragment.server_config.LoginFragment
;
import
chat.rocket.android.fragment.server_config.RetryLoginFragment
;
import
chat.rocket.android.fragment.server_config.RetryLoginFragment
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.core.interactors.SessionInteractor
;
import
chat.rocket.persistence.realm.models.internal.RealmSession
;
import
chat.rocket.persistence.realm.RealmObjectObserver
;
import
chat.rocket.persistence.realm.RealmStore
;
import
chat.rocket.android.service.ConnectivityManager
;
import
chat.rocket.android.service.ConnectivityManager
;
import
chat.rocket.persistence.realm.repositories.RealmSessionRepository
;
/**
/**
* Activity for Login, Sign-up, and Retry connecting...
* Activity for Login, Sign-up, and Retry connecting...
*/
*/
public
class
LoginActivity
extends
AbstractFragmentActivity
{
public
class
LoginActivity
extends
AbstractFragmentActivity
implements
LoginContract
.
View
{
public
static
final
String
KEY_HOSTNAME
=
"hostname"
;
public
static
final
String
KEY_HOSTNAME
=
"hostname"
;
private
String
hostname
;
private
LoginContract
.
Presenter
presenter
;
private
RealmObjectObserver
<
RealmSession
>
sessionObserver
;
@Override
@Override
protected
int
getLayoutContainerForFragment
()
{
protected
int
getLayoutContainerForFragment
()
{
...
@@ -32,69 +29,38 @@ public class LoginActivity extends AbstractFragmentActivity {
...
@@ -32,69 +29,38 @@ public class LoginActivity extends AbstractFragmentActivity {
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
String
hostname
=
null
;
Intent
intent
=
getIntent
();
Intent
intent
=
getIntent
();
if
(
intent
==
null
||
intent
.
getExtras
()
==
null
)
{
if
(
intent
!=
null
&&
intent
.
getExtras
()
!=
null
)
{
finish
();
hostname
=
intent
.
getStringExtra
(
KEY_HOSTNAME
);
return
;
}
}
hostname
=
intent
.
getStringExtra
(
KEY_HOSTNAME
);
presenter
=
new
LoginPresenter
(
if
(
TextUtils
.
isEmpty
(
hostname
))
{
hostname
,
finish
();
new
SessionInteractor
(
new
RealmSessionRepository
(
hostname
)),
return
;
ConnectivityManager
.
getInstance
(
getApplicationContext
())
}
);
sessionObserver
=
RealmStore
.
get
(
hostname
)
.
createObjectObserver
(
RealmSession:
:
queryDefaultSession
)
.
setOnUpdateListener
(
this
::
onRenderServerConfigSession
);
setContentView
(
R
.
layout
.
simple_screen
);
showFragment
(
new
LoginFragment
());
}
}
@Override
@Override
protected
void
onResume
()
{
protected
void
onResume
()
{
super
.
onResume
();
super
.
onResume
();
ConnectivityManager
.
getInstance
(
getApplicationContext
()).
keepAliveServer
();
presenter
.
bindView
(
this
);
sessionObserver
.
sub
();
}
}
@Override
@Override
protected
void
onDestroy
()
{
protected
void
onDestroy
()
{
sessionObserver
.
unsub
();
presenter
.
release
();
super
.
onDestroy
();
super
.
onDestroy
();
}
}
private
void
onRenderServerConfigSession
(
RealmSession
session
)
{
private
void
showFragment
(
Fragment
fragment
,
String
hostname
)
{
if
(
session
==
null
)
{
setContentView
(
R
.
layout
.
simple_screen
);
return
;
injectHostnameArgTo
(
fragment
,
hostname
);
}
final
String
token
=
session
.
getToken
();
if
(!
TextUtils
.
isEmpty
(
token
))
{
if
(
TextUtils
.
isEmpty
(
session
.
getError
()))
{
finish
();
overridePendingTransition
(
android
.
R
.
anim
.
fade_in
,
android
.
R
.
anim
.
fade_out
);
}
else
{
showFragment
(
new
RetryLoginFragment
());
}
return
;
}
}
@Override
protected
void
showFragment
(
Fragment
fragment
)
{
injectHostnameArgTo
(
fragment
);
super
.
showFragment
(
fragment
);
super
.
showFragment
(
fragment
);
}
}
@Override
private
void
injectHostnameArgTo
(
Fragment
fragment
,
String
hostname
)
{
protected
void
showFragmentWithBackStack
(
Fragment
fragment
)
{
injectHostnameArgTo
(
fragment
);
super
.
showFragmentWithBackStack
(
fragment
);
}
private
void
injectHostnameArgTo
(
Fragment
fragment
)
{
Bundle
args
=
fragment
.
getArguments
();
Bundle
args
=
fragment
.
getArguments
();
if
(
args
==
null
)
{
if
(
args
==
null
)
{
args
=
new
Bundle
();
args
=
new
Bundle
();
...
@@ -107,4 +73,20 @@ public class LoginActivity extends AbstractFragmentActivity {
...
@@ -107,4 +73,20 @@ public class LoginActivity extends AbstractFragmentActivity {
protected
void
onBackPressedNotHandled
()
{
protected
void
onBackPressedNotHandled
()
{
moveTaskToBack
(
true
);
moveTaskToBack
(
true
);
}
}
@Override
public
void
showLogin
(
String
hostname
)
{
showFragment
(
new
LoginFragment
(),
hostname
);
}
@Override
public
void
showRetryLogin
(
String
hostname
)
{
showFragment
(
new
RetryLoginFragment
(),
hostname
);
}
@Override
public
void
close
()
{
finish
();
overridePendingTransition
(
android
.
R
.
anim
.
fade_in
,
android
.
R
.
anim
.
fade_out
);
}
}
}
app/src/main/java/chat/rocket/android/activity/LoginContract.java
0 → 100644
View file @
2b2f7499
package
chat
.
rocket
.
android
.
activity
;
import
chat.rocket.android.shared.BaseContract
;
public
interface
LoginContract
{
interface
View
extends
BaseContract
.
View
{
void
showLogin
(
String
hostname
);
void
showRetryLogin
(
String
hostname
);
void
close
();
}
interface
Presenter
extends
BaseContract
.
Presenter
<
View
>
{
}
}
app/src/main/java/chat/rocket/android/activity/LoginPresenter.java
0 → 100644
View file @
2b2f7499
package
chat
.
rocket
.
android
.
activity
;
import
android.support.annotation.NonNull
;
import
chat.rocket.android.BackgroundLooper
;
import
chat.rocket.android.service.ConnectivityManagerApi
;
import
chat.rocket.android.shared.BasePresenter
;
import
chat.rocket.core.interactors.SessionInteractor
;
import
rx.Subscription
;
import
rx.android.schedulers.AndroidSchedulers
;
public
class
LoginPresenter
extends
BasePresenter
<
LoginContract
.
View
>
implements
LoginContract
.
Presenter
{
private
final
String
hostname
;
private
final
SessionInteractor
sessionInteractor
;
private
final
ConnectivityManagerApi
connectivityManagerApi
;
public
LoginPresenter
(
String
hostname
,
SessionInteractor
sessionInteractor
,
ConnectivityManagerApi
connectivityManagerApi
)
{
this
.
hostname
=
hostname
;
this
.
sessionInteractor
=
sessionInteractor
;
this
.
connectivityManagerApi
=
connectivityManagerApi
;
}
@Override
public
void
bindView
(
@NonNull
LoginContract
.
View
view
)
{
super
.
bindView
(
view
);
connectivityManagerApi
.
keepAliveServer
();
if
(
hostname
==
null
||
hostname
.
length
()
==
0
)
{
view
.
close
();
return
;
}
loadDefaultSession
();
}
private
void
loadDefaultSession
()
{
final
Subscription
subscription
=
sessionInteractor
.
getSessionState
()
.
distinctUntilChanged
()
.
subscribeOn
(
AndroidSchedulers
.
from
(
BackgroundLooper
.
get
()))
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
state
->
{
switch
(
state
)
{
case
UNAVAILABLE:
view
.
showLogin
(
hostname
);
break
;
case
INVALID:
view
.
showRetryLogin
(
hostname
);
break
;
case
VALID:
view
.
close
();
}
});
addSubscription
(
subscription
);
}
}
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmSessionRepository.java
View file @
2b2f7499
...
@@ -28,21 +28,19 @@ public class RealmSessionRepository extends RealmRepository implements SessionRe
...
@@ -28,21 +28,19 @@ public class RealmSessionRepository extends RealmRepository implements SessionRe
return
Observable
.
just
(
null
);
return
Observable
.
just
(
null
);
}
}
final
RealmSession
realmSession
=
return
realm
.
where
(
RealmSession
.
class
)
realm
.
where
(
RealmSession
.
class
).
equalTo
(
RealmSession
.
ID
,
RealmSession
.
DEFAULT_ID
)
.
equalTo
(
RealmSession
.
ID
,
RealmSession
.
DEFAULT_ID
)
.
findFirst
();
.
findAll
()
if
(
realmSession
==
null
)
{
realm
.
close
();
return
Observable
.
just
(
null
);
}
return
realmSession
.<
RealmSession
>
asObservable
()
.<
RealmSession
>
asObservable
()
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
looper
))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
looper
))
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
.
filter
(
it
->
it
!=
null
&&
it
.
isLoaded
()
&&
it
.
isValid
())
.
filter
(
it
->
it
!=
null
&&
it
.
isLoaded
()
&&
it
.
isValid
())
.
map
(
RealmSession:
:
asSession
);
.
map
(
realmSessions
->
{
if
(
realmSessions
.
size
()
==
0
)
{
return
null
;
}
return
realmSessions
.
get
(
0
).
asSession
();
});
});
});
}
}
}
}
rocket-chat-core/src/main/java/chat/rocket/core/interactors/SessionInteractor.java
0 → 100644
View file @
2b2f7499
package
chat
.
rocket
.
core
.
interactors
;
import
chat.rocket.core.models.Session
;
import
chat.rocket.core.repositories.SessionRepository
;
import
rx.Observable
;
public
class
SessionInteractor
{
private
final
SessionRepository
sessionRepository
;
public
SessionInteractor
(
SessionRepository
sessionRepository
)
{
this
.
sessionRepository
=
sessionRepository
;
}
public
Observable
<
Session
.
State
>
getSessionState
()
{
return
sessionRepository
.
getDefault
()
.
map
(
this
::
getStateFrom
);
}
private
Session
.
State
getStateFrom
(
Session
session
)
{
if
(
session
==
null
)
{
return
Session
.
State
.
UNAVAILABLE
;
}
final
String
token
=
session
.
getToken
();
if
(
token
==
null
||
token
.
length
()
==
0
)
{
return
Session
.
State
.
UNAVAILABLE
;
}
final
String
error
=
session
.
getError
();
if
(
error
==
null
||
error
.
length
()
==
0
)
{
return
Session
.
State
.
VALID
;
}
return
Session
.
State
.
INVALID
;
}
}
rocket-chat-core/src/main/java/chat/rocket/core/models/Session.java
View file @
2b2f7499
...
@@ -7,6 +7,8 @@ import javax.annotation.Nullable;
...
@@ -7,6 +7,8 @@ import javax.annotation.Nullable;
@AutoValue
@AutoValue
public
abstract
class
Session
{
public
abstract
class
Session
{
public
enum
State
{
UNAVAILABLE
,
INVALID
,
VALID
}
public
abstract
int
getSessionId
();
public
abstract
int
getSessionId
();
@Nullable
@Nullable
...
...
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