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

Commit 2ae2c8f

Browse files
kunall17niftynei
authored andcommitted
Set httpScheme according to debug or production
1 parent 8ef9793 commit 2ae2c8f

File tree

1 file changed

+14
-43
lines changed

1 file changed

+14
-43
lines changed

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

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -73,45 +73,7 @@ protected void onCreate(Bundle savedInstanceState) {
7373
findViewById(R.id.server_btn).setOnClickListener(new View.OnClickListener() {
7474
@Override
7575
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();
76+
checkForError();
11577
}
11678
});
11779

@@ -163,19 +125,28 @@ protected void onStop() {
163125
super.onStop();
164126
}
165127

166-
private boolean checkForError() {
128+
private void checkForError() {
167129
String serverURL = serverIn.getText().toString();
168130
int errorMessage = R.string.invalid_server_domain;
131+
String httpScheme = (BuildConfig.DEBUG) ? "http" : "https";
169132

170133
if (serverURL.isEmpty()) {
171134
serverIn.setError(getString(errorMessage));
172-
return false;
135+
return;
173136
}
174137

175-
// add http if scheme is not included
138+
// add http or https if scheme is not included
176139
if (!serverURL.contains("://")) {
177-
serverURL = "http://" + serverURL;
140+
serverURL = httpScheme + "://" + serverURL;
141+
showBackends(httpScheme, serverURL);
142+
} else {
143+
Uri serverUri = Uri.parse(serverURL);
144+
145+
if (!BuildConfig.DEBUG && serverUri.getScheme().equals("http")) { //Production build and not https
146+
} else {
147+
}
178148
}
149+
}
179150

180151
Uri serverUri = Uri.parse(serverURL);
181152
if (serverUri.isRelative()) {

0 commit comments

Comments
 (0)