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
2b2b6798
Commit
2b2b6798
authored
Jan 09, 2017
by
Tiago Cunha
Committed by
GitHub
Jan 09, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #128 from RocketChat/improve_login
Improve login screen
parents
b228661c
4737dfbc
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
86 additions
and
22 deletions
+86
-22
LaunchUtil.java
app/src/main/java/chat/rocket/android/LaunchUtil.java
+3
-3
LoginActivity.java
...main/java/chat/rocket/android/activity/LoginActivity.java
+4
-10
MainActivity.java
.../main/java/chat/rocket/android/activity/MainActivity.java
+68
-8
LoginFragment.java
.../rocket/android/fragment/server_config/LoginFragment.java
+3
-0
fragment_login.xml
app/src/main/res/layout/fragment_login.xml
+7
-0
strings.xml
app/src/main/res/values/strings.xml
+1
-1
No files found.
app/src/main/java/chat/rocket/android/LaunchUtil.java
View file @
2b2b6798
...
...
@@ -4,7 +4,7 @@ import android.content.Context;
import
android.content.Intent
;
import
chat.rocket.android.activity.AddServerActivity
;
import
chat.rocket.android.activity.
ServerConfig
Activity
;
import
chat.rocket.android.activity.
Login
Activity
;
/**
* utility class for launching Activity.
...
...
@@ -23,8 +23,8 @@ public class LaunchUtil {
/**
* launch ServerConfigActivity with proper flags.
*/
public
static
void
show
ServerConfig
Activity
(
Context
context
,
String
serverCondigId
)
{
Intent
intent
=
new
Intent
(
context
,
ServerConfig
Activity
.
class
);
public
static
void
show
Login
Activity
(
Context
context
,
String
serverCondigId
)
{
Intent
intent
=
new
Intent
(
context
,
Login
Activity
.
class
);
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_REORDER_TO_FRONT
|
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
);
intent
.
putExtra
(
"serverConfigId"
,
serverCondigId
);
context
.
startActivity
(
intent
);
...
...
app/src/main/java/chat/rocket/android/activity/
ServerConfig
Activity.java
→
app/src/main/java/chat/rocket/android/activity/
Login
Activity.java
View file @
2b2b6798
...
...
@@ -18,9 +18,9 @@ import chat.rocket.android.realm_helper.RealmStore;
import
chat.rocket.android.service.RocketChatService
;
/**
* Activity for Login, Sign-up, and
C
onnecting...
* Activity for Login, Sign-up, and
Retry c
onnecting...
*/
public
class
ServerConfig
Activity
extends
AbstractFragmentActivity
{
public
class
Login
Activity
extends
AbstractFragmentActivity
{
private
String
serverConfigId
;
private
RealmObjectObserver
<
ServerConfig
>
serverConfigErrorObserver
;
...
...
@@ -91,17 +91,11 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
return
;
}
if
(
session
.
isTokenVerified
()
&&
TextUtils
.
isEmpty
(
session
.
getError
()))
{
finish
();
overridePendingTransition
(
android
.
R
.
anim
.
fade_in
,
android
.
R
.
anim
.
fade_out
);
return
;
}
final
String
token
=
session
.
getToken
();
if
(!
TextUtils
.
isEmpty
(
token
))
{
if
(
TextUtils
.
isEmpty
(
session
.
getError
()))
{
showFragment
(
WaitingFragment
.
create
(
getString
(
R
.
string
.
server_config_activity_authenticating
))
);
finish
();
overridePendingTransition
(
android
.
R
.
anim
.
fade_in
,
android
.
R
.
anim
.
fade_out
);
}
else
{
showFragment
(
new
RetryLoginFragment
());
}
...
...
app/src/main/java/chat/rocket/android/activity/MainActivity.java
View file @
2b2b6798
...
...
@@ -2,6 +2,7 @@ package chat.rocket.android.activity;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.support.design.widget.Snackbar
;
import
android.support.v4.widget.SlidingPaneLayout
;
import
android.support.v7.widget.Toolbar
;
import
android.view.View
;
...
...
@@ -13,6 +14,8 @@ import chat.rocket.android.fragment.chatroom.HomeFragment;
import
chat.rocket.android.fragment.chatroom.RoomFragment
;
import
chat.rocket.android.fragment.sidebar.SidebarMainFragment
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.model.ddp.User
;
import
chat.rocket.android.model.internal.Session
;
import
chat.rocket.android.realm_helper.RealmHelper
;
...
...
@@ -27,6 +30,7 @@ public class MainActivity extends AbstractAuthedActivity {
private
RealmObjectObserver
<
Session
>
sessionObserver
;
private
boolean
isForeground
;
private
StatusTicker
statusTicker
;
@Override
protected
int
getLayoutContainerForFragment
()
{
...
...
@@ -38,6 +42,7 @@ public class MainActivity extends AbstractAuthedActivity {
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_main
);
statusTicker
=
new
StatusTicker
();
setupSidebar
();
if
(
roomId
==
null
)
{
showFragment
(
new
HomeFragment
());
...
...
@@ -143,17 +148,42 @@ public class MainActivity extends AbstractAuthedActivity {
sessionObserver
=
realmHelper
.
createObjectObserver
(
realm
->
Session
.
queryDefaultSession
(
realm
)
.
isNotNull
(
Session
.
TOKEN
)
.
equalTo
(
Session
.
TOKEN_VERIFIED
,
true
)
.
isNull
(
Session
.
ERROR
))
.
setOnUpdateListener
(
session
->
{
if
(
session
==
null
&&
isForeground
)
{
LaunchUtil
.
showServerConfigActivity
(
this
,
serverConfigId
);
}
});
.
isNotNull
(
Session
.
TOKEN
))
.
setOnUpdateListener
(
this
::
onSessionChanged
);
sessionObserver
.
sub
();
}
private
void
onSessionChanged
(
@Nullable
Session
session
)
{
if
(
session
==
null
)
{
if
(
isForeground
)
{
LaunchUtil
.
showLoginActivity
(
this
,
serverConfigId
);
}
statusTicker
.
updateStatus
(
StatusTicker
.
STATUS_DISMISS
,
null
);
}
else
if
(!
TextUtils
.
isEmpty
(
session
.
getError
()))
{
statusTicker
.
updateStatus
(
StatusTicker
.
STATUS_CONNECTION_ERROR
,
Snackbar
.
make
(
findViewById
(
getLayoutContainerForFragment
()),
R
.
string
.
fragment_retry_login_error_title
,
Snackbar
.
LENGTH_INDEFINITE
)
.
setAction
(
R
.
string
.
fragment_retry_login_retry_title
,
view
->
RealmStore
.
getDefault
()
.
executeTransaction
(
realm
->
{
ServerConfig
config
=
realm
.
where
(
ServerConfig
.
class
)
.
equalTo
(
ServerConfig
.
ID
,
serverConfigId
).
findFirst
();
if
(
config
!=
null
&&
config
.
getState
()
==
ServerConfig
.
STATE_CONNECTION_ERROR
)
{
config
.
setState
(
ServerConfig
.
STATE_READY
);
}
return
null
;
}).
continueWith
(
new
LogcatIfError
())));
}
else
if
(!
session
.
isTokenVerified
())
{
statusTicker
.
updateStatus
(
StatusTicker
.
STATUS_TOKEN_LOGIN
,
Snackbar
.
make
(
findViewById
(
getLayoutContainerForFragment
()),
R
.
string
.
server_config_activity_authenticating
,
Snackbar
.
LENGTH_INDEFINITE
));
}
else
{
statusTicker
.
updateStatus
(
StatusTicker
.
STATUS_DISMISS
,
null
);
}
}
private
void
updateSidebarMainFragment
()
{
getSupportFragmentManager
().
beginTransaction
()
.
replace
(
R
.
id
.
sidebar_fragment_container
,
SidebarMainFragment
.
create
(
serverConfigId
))
...
...
@@ -185,4 +215,34 @@ public class MainActivity extends AbstractAuthedActivity {
protected
boolean
onBackPress
()
{
return
closeSidebarIfNeeded
()
||
super
.
onBackPress
();
}
//TODO: consider this class to define in layouthelper for more complicated operation.
private
static
class
StatusTicker
{
public
static
final
int
STATUS_DISMISS
=
0
;
public
static
final
int
STATUS_CONNECTION_ERROR
=
1
;
public
static
final
int
STATUS_TOKEN_LOGIN
=
2
;
private
int
status
;
private
Snackbar
snackbar
;
public
StatusTicker
()
{
status
=
STATUS_DISMISS
;
}
public
void
updateStatus
(
int
status
,
Snackbar
snackbar
)
{
if
(
status
==
this
.
status
)
{
return
;
}
this
.
status
=
status
;
if
(
this
.
snackbar
!=
null
)
{
this
.
snackbar
.
dismiss
();
}
if
(
status
!=
STATUS_DISMISS
)
{
this
.
snackbar
=
snackbar
;
if
(
this
.
snackbar
!=
null
)
{
this
.
snackbar
.
show
();
}
}
}
}
}
app/src/main/java/chat/rocket/android/fragment/server_config/LoginFragment.java
View file @
2b2b6798
...
...
@@ -42,6 +42,7 @@ public class LoginFragment extends AbstractServerConfigFragment {
final
View
btnEmail
=
rootView
.
findViewById
(
R
.
id
.
btn_login_with_email
);
final
TextView
txtUsername
=
(
TextView
)
rootView
.
findViewById
(
R
.
id
.
editor_username
);
final
TextView
txtPasswd
=
(
TextView
)
rootView
.
findViewById
(
R
.
id
.
editor_passwd
);
final
View
waitingView
=
rootView
.
findViewById
(
R
.
id
.
waiting
);
btnEmail
.
setOnClickListener
(
view
->
{
final
CharSequence
username
=
txtUsername
.
getText
();
final
CharSequence
passwd
=
txtPasswd
.
getText
();
...
...
@@ -49,6 +50,7 @@ public class LoginFragment extends AbstractServerConfigFragment {
return
;
}
view
.
setEnabled
(
false
);
waitingView
.
setVisibility
(
View
.
VISIBLE
);
new
MethodCallHelper
(
getContext
(),
serverConfigId
)
.
loginWithEmail
(
username
.
toString
(),
passwd
.
toString
())
...
...
@@ -56,6 +58,7 @@ public class LoginFragment extends AbstractServerConfigFragment {
if
(
task
.
isFaulted
())
{
showError
(
task
.
getError
().
getMessage
());
view
.
setEnabled
(
true
);
waitingView
.
setVisibility
(
View
.
GONE
);
}
return
null
;
});
...
...
app/src/main/res/layout/fragment_login.xml
View file @
2b2b6798
...
...
@@ -120,5 +120,12 @@
app:fabSize=
"normal"
app:srcCompat=
"@drawable/ic_arrow_forward_white_24dp"
/>
</FrameLayout>
<chat.rocket.android.widget.WaitingView
android:id=
"@+id/waiting"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:visibility=
"gone"
/>
</LinearLayout>
</FrameLayout>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
2b2b6798
...
...
@@ -29,7 +29,7 @@
<string
name=
"fragment_login_username_or_email"
>
Username or email
</string>
<string
name=
"fragment_login_password"
>
Password
</string>
<string
name=
"fragment_retry_login_retry_title"
>
RETRY
</string>
<string
name=
"fragment_retry_login_error_title"
>
Oops…
</string>
<string
name=
"fragment_retry_login_error_title"
>
Connection Error
</string>
<string
name=
"add_server_activity_waiting_server"
>
Connecting to server…
</string>
<string
name=
"server_config_activity_authenticating"
>
Authenticating…
</string>
<string
name=
"home_fragment_title"
>
Rocket.Chat - Home
</string>
...
...
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