Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 1ffface

Browse files
kunall17niftynei
authored andcommitted
Implement Change screens in LoginActivity
1 parent 06d996e commit 1ffface

File tree

4 files changed

+269
-67
lines changed

4 files changed

+269
-67
lines changed

app/src/main/java/com/zulip/android/activities/LoginActivity.java

Lines changed: 79 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.zulip.android.BuildConfig;
2424
import com.zulip.android.R;
2525
import com.zulip.android.networking.AsyncDevGetEmails;
26+
import com.zulip.android.networking.AsyncGetBackends;
27+
import com.zulip.android.util.AnimationHelper;
2628
import com.zulip.android.util.ZLog;
2729
import com.zulip.android.ZulipApp;
2830
import com.zulip.android.networking.ZulipAsyncPushTask.AsyncTaskCompleteListener;
@@ -44,8 +46,9 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
4446
private EditText mServerEditText;
4547
private EditText mUserName;
4648
private EditText mPassword;
47-
private View mGoogleSignInButton;
49+
private EditText serverIn;
4850

51+
private View mGoogleSignInButton;
4952
@Override
5053
protected void onCreate(Bundle savedInstanceState) {
5154
super.onCreate(savedInstanceState);
@@ -66,7 +69,69 @@ protected void onCreate(Bundle savedInstanceState) {
6669
findViewById(R.id.zulip_login).setOnClickListener(this);
6770
mUserName = (EditText) findViewById(R.id.username);
6871
mPassword = (EditText) findViewById(R.id.password);
69-
if (!BuildConfig.DEBUG) findViewById(R.id.local_server_button).setVisibility(View.GONE);
72+
serverIn = (EditText) findViewById(R.id.server_url_in);
73+
findViewById(R.id.server_btn).setOnClickListener(new View.OnClickListener() {
74+
@Override
75+
public void onClick(View view) {
76+
if (!checkForError()) {
77+
return;
78+
}
79+
80+
AsyncGetBackends asyncGetBackends = new AsyncGetBackends(ZulipApp.get());
81+
asyncGetBackends.setCallback(new AsyncTaskCompleteListener() {
82+
@Override
83+
public void onTaskComplete(String result, JSONObject jsonObject) {
84+
try {
85+
JSONObject object = new JSONObject(result);
86+
if (!object.getString("result").equals("success")) {
87+
onTaskFailure("");
88+
return;
89+
}
90+
91+
if (object.getString("password").equals("true")) {
92+
findViewById(R.id.passwordAuthLayout).setVisibility(View.VISIBLE);
93+
}
94+
95+
if (object.getString("google").equals("true")) {
96+
findViewById(R.id.google_sign_in_button).setVisibility(View.VISIBLE);
97+
}
98+
99+
if (object.getString("dev").equals("true")) {
100+
findViewById(R.id.local_server_button).setVisibility(View.VISIBLE);
101+
}
102+
showLoginFields();
103+
} catch (JSONException e) {
104+
e.printStackTrace();
105+
}
106+
107+
}
108+
109+
@Override
110+
public void onTaskFailure(String result) {
111+
Toast.makeText(LoginActivity.this, "Failed to fetch Backends!", Toast.LENGTH_SHORT).show();
112+
}
113+
});
114+
asyncGetBackends.execute();
115+
}
116+
});
117+
118+
findViewById(R.id.input_another_server).setOnClickListener(new View.OnClickListener() {
119+
@Override
120+
public void onClick(View view) {
121+
AnimationHelper.hideView(findViewById(R.id.serverInput), 100);
122+
AnimationHelper.showView(findViewById(R.id.serverFieldLayout), 201);
123+
mServerEditText.setText("");
124+
mServerEditText.setEnabled(false);
125+
findViewById(R.id.passwordAuthLayout).setVisibility(View.GONE);
126+
findViewById(R.id.google_sign_in_button).setVisibility(View.GONE);
127+
findViewById(R.id.local_server_button).setVisibility(View.GONE);
128+
}
129+
});
130+
}
131+
132+
private void showLoginFields() {
133+
AnimationHelper.showView(findViewById(R.id.serverInput), 201);
134+
AnimationHelper.hideView(findViewById(R.id.serverFieldLayout), 100);
70135
}
71136

72137
@Override
@@ -98,12 +163,13 @@ protected void onStop() {
98163
super.onStop();
99164
}
100165

101-
private void saveServerURL() {
102-
String serverURL = mServerEditText.getText().toString();
166+
private boolean checkForError() {
167+
String serverURL = serverIn.getText().toString();
103168
int errorMessage = R.string.invalid_server_domain;
104169

105170
if (serverURL.isEmpty()) {
106-
mServerEditText.setError(getString(errorMessage));
171+
serverIn.setError(getString(errorMessage));
172+
return false;
107173
}
108174

109175
// add http if scheme is not included
@@ -121,11 +187,13 @@ private void saveServerURL() {
121187
if (!serverUri.getHost().startsWith("api.") && paths.isEmpty()) {
122188
serverUri = serverUri.buildUpon().appendEncodedPath("api/").build();
123189
}
124-
190+
serverIn.setText(serverUri.toString());
191+
mServerEditText.setText(serverUri.toString());
192+
mServerEditText.setEnabled(false);
125193
((ZulipApp) getApplication()).setServerURL(serverUri.toString());
194+
return true;
126195
}
127196

128-
129197
private void handleSignInResult(GoogleSignInResult result) {
130198
Log.d("Login", "handleSignInResult:" + result.isSuccess());
131199
if (result.isSuccess()) {
@@ -231,15 +299,13 @@ public void onClick(View v) {
231299
switch (v.getId()) {
232300
case R.id.google_sign_in_button:
233301
connectionProgressDialog.show();
234-
saveServerURL();
235302
Toast.makeText(this, getString(R.string.logging_into_server, ZulipApp.get().getServerURI()), Toast.LENGTH_SHORT).show();
236303
setupGoogleSignIn();
237304
break;
238305
case R.id.zulip_login:
239306
if (!isInputValid()) {
240307
return;
241308
}
242-
saveServerURL();
243309
Toast.makeText(this, getString(R.string.logging_into_server, ZulipApp.get().getServerURI()), Toast.LENGTH_SHORT).show();
244310
connectionProgressDialog.show();
245311

@@ -265,7 +331,6 @@ public void onTaskFailure(String result) {
265331
break;
266332
case R.id.local_server_button:
267333
if (!isInputValidForDevAuth()) return;
268-
saveServerURL();
269334
connectionProgressDialog.show();
270335
AsyncDevGetEmails asyncDevGetEmails = new AsyncDevGetEmails(LoginActivity.this);
271336
asyncDevGetEmails.setCallback(new AsyncTaskCompleteListener() {
@@ -294,11 +359,11 @@ private boolean isInputValidForDevAuth() {
294359
String serverString = mServerEditText.getText().toString();
295360
if (!serverString.contains("://")) serverString = "https://" + serverString;
296361

297-
if (!Patterns.WEB_URL.matcher(serverString).matches()) {
298-
mServerEditText.setError(getString(R.string.invalid_domain));
299-
isValid = false;
362+
if (!Patterns.WEB_URL.matcher(serverString).matches()) {
363+
mServerEditText.setError(getString(R.string.invalid_domain));
364+
isValid = false;
365+
}
300366
}
301-
}
302367
return isValid;
303368
}
304369
private boolean isInputValid() {

app/src/main/res/layout-v21/login.xml

Lines changed: 91 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:tools="http://schemas.android.com/tools"
44
android:layout_width="match_parent"
55
android:layout_height="match_parent"
6+
android:gravity="center_horizontal"
67
android:orientation="vertical">
78

89
<android.support.design.widget.AppBarLayout
@@ -18,42 +19,70 @@
1819

1920
</android.support.design.widget.AppBarLayout>
2021

22+
<TextView
23+
android:id="@+id/textView1"
24+
android:layout_width="wrap_content"
25+
android:layout_height="wrap_content"
26+
android:layout_marginTop="16dp"
27+
android:gravity="center|center_horizontal"
28+
android:padding="10dp"
29+
android:text="@string/login_welcome_blurb"
30+
android:textAppearance="?android:attr/textAppearanceLarge" />
31+
32+
2133
<LinearLayout
34+
android:id="@+id/serverInput"
2235
android:layout_width="match_parent"
23-
android:layout_height="match_parent"
36+
android:layout_height="wrap_content"
2437
android:gravity="center"
2538
android:orientation="vertical"
2639
android:padding="16dp">
2740

2841
<TextView
29-
android:id="@+id/textView1"
42+
android:id="@+id/info_txt"
3043
android:layout_width="wrap_content"
3144
android:layout_height="wrap_content"
3245
android:gravity="center|center_horizontal"
3346
android:padding="10dp"
34-
android:text="@string/login_welcome_blurb"
35-
android:textAppearance="?android:attr/textAppearanceLarge" />
47+
android:text="@string/enter_server"
48+
android:textAppearance="?android:attr/textAppearanceMedium" />
3649

3750
<EditText
38-
android:id="@+id/username"
51+
android:id="@+id/server_url_in"
3952
android:layout_width="match_parent"
4053
android:layout_height="wrap_content"
4154
android:ems="10"
42-
android:hint="@string/username"
43-
android:inputType="textEmailAddress"
55+
android:hint="Server URL"
56+
android:inputType="textUri"
4457
android:selectAllOnFocus="true">
4558

4659
<requestFocus />
4760
</EditText>
4861

49-
<EditText
50-
android:id="@+id/password"
62+
<Button
63+
android:id="@+id/server_btn"
64+
style="android:buttonStyle"
5165
android:layout_width="match_parent"
5266
android:layout_height="wrap_content"
53-
android:ems="10"
54-
android:hint="@string/password"
55-
android:inputType="textPassword"
56-
android:selectAllOnFocus="true" />
67+
android:layout_marginTop="20dp"
68+
android:text="@string/enter" />
69+
70+
</LinearLayout>
71+
72+
<LinearLayout
73+
android:id="@+id/serverFieldLayout"
74+
android:layout_width="match_parent"
75+
android:layout_height="wrap_content"
76+
android:gravity="center"
77+
android:orientation="vertical"
78+
android:padding="16dp"
79+
android:visibility="gone">
80+
81+
<TextView
82+
android:layout_width="wrap_content"
83+
android:layout_height="wrap_content"
84+
android:layout_marginTop="10dp"
85+
android:text="@string/auth_login" />
5786

5887
<EditText
5988
android:id="@+id/server_url"
@@ -64,20 +93,48 @@
6493
android:inputType="textUri"
6594
android:selectAllOnFocus="true" />
6695

67-
<Button
68-
android:id="@+id/zulip_login"
69-
style="android:buttonStyle"
96+
<LinearLayout
97+
android:id="@+id/passwordAuthLayout"
7098
android:layout_width="match_parent"
7199
android:layout_height="wrap_content"
72-
android:layout_marginTop="20dp"
73-
android:text="@string/login_button" />
100+
android:orientation="vertical"
101+
android:paddingBottom="8dp"
102+
android:paddingTop="8dp"
103+
android:visibility="gone">
104+
105+
<EditText
106+
android:id="@+id/username"
107+
android:layout_width="match_parent"
108+
android:layout_height="wrap_content"
109+
android:ems="10"
110+
android:hint="@string/username"
111+
android:inputType="textEmailAddress"
112+
android:selectAllOnFocus="true" />
74113

114+
<EditText
115+
android:id="@+id/password"
116+
android:layout_width="match_parent"
117+
android:layout_height="wrap_content"
118+
android:ems="10"
119+
android:hint="@string/password"
120+
android:inputType="textPassword"
121+
android:selectAllOnFocus="true" />
122+
123+
<Button
124+
android:id="@+id/zulip_login"
125+
style="android:buttonStyle"
126+
android:layout_width="match_parent"
127+
android:layout_height="wrap_content"
128+
android:text="@string/login_button" />
129+
130+
131+
</LinearLayout>
75132

76133
<com.google.android.gms.common.SignInButton
77134
android:id="@+id/google_sign_in_button"
78135
android:layout_width="match_parent"
79136
android:layout_height="wrap_content"
80-
android:layout_marginTop="28dp" />
137+
android:visibility="gone" />
81138

82139
<TextView
83140
android:id="@+id/local_server_button"
@@ -86,14 +143,25 @@
86143
android:onClick="onClick"
87144
android:paddingTop="16dp"
88145
android:text="@string/local_server"
89-
android:textColor="#ff0099cc" />
146+
android:textColor="#ff0099cc"
147+
android:visibility="gone" />
90148

91149
<TextView
92-
android:id="@+id/legal_button"
150+
android:id="@+id/input_another_server"
93151
android:layout_width="wrap_content"
94152
android:layout_height="wrap_content"
95-
android:paddingTop="8dp"
96-
android:text="@string/legal"
153+
android:onClick="onClick"
154+
android:paddingTop="16dp"
155+
android:text="@string/another_server"
97156
android:textColor="#ff0099cc" />
98157
</LinearLayout>
158+
159+
<TextView
160+
android:id="@+id/legal_button"
161+
android:layout_width="wrap_content"
162+
android:layout_height="wrap_content"
163+
android:layout_marginBottom="29dp"
164+
android:paddingTop="8dp"
165+
android:text="@string/legal"
166+
android:textColor="#ff0099cc" />
99167
</LinearLayout>

0 commit comments

Comments
 (0)