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

Commit 968cb99

Browse files
jainkuniyakunall17
authored andcommitted
Added progress dialog.
Show progress dialog while connecting to server, refreshing, logging out. Fix:#369
1 parent 0303990 commit 968cb99

File tree

6 files changed

+85
-27
lines changed

6 files changed

+85
-27
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.zulip.android.networking.response.LoginResponse;
1313
import com.zulip.android.networking.util.DefaultCallback;
1414
import com.zulip.android.util.AuthClickListener;
15+
import com.zulip.android.util.CommonProgressDialog;
1516
import com.zulip.android.util.ZLog;
1617

1718
import org.json.JSONArray;
@@ -29,7 +30,7 @@
2930
*/
3031
public class DevAuthActivity extends BaseActivity {
3132
private RecyclerView recyclerView;
32-
private ProgressDialog connectionProgressDialog;
33+
private CommonProgressDialog commonProgressDialog;
3334

3435

3536
@Override
@@ -40,8 +41,7 @@ protected void onCreate(Bundle savedInstanceState) {
4041
recyclerView = (RecyclerView) findViewById(R.id.devAuthRecyclerView);
4142
List<String> emails = new ArrayList<>();
4243
int directAdminSize = 1;
43-
connectionProgressDialog = new ProgressDialog(this);
44-
connectionProgressDialog.setMessage(getString(R.string.signing_in));
44+
commonProgressDialog = new CommonProgressDialog(this);
4545

4646
try {
4747
JSONObject jsonObject = new JSONObject(json);
@@ -62,6 +62,7 @@ protected void onCreate(Bundle savedInstanceState) {
6262
authEmailAdapter.setOnItemClickListener(new AuthClickListener() {
6363
@Override
6464
public void onItemClick(String email) {
65+
commonProgressDialog.showWithMessage(getString(R.string.signing_in));
6566
getServices()
6667
.loginDEV(email)
6768
.enqueue(new DefaultCallback<LoginResponse>() {
@@ -75,6 +76,7 @@ public void onSuccess(Call<LoginResponse> call, Response<LoginResponse> response
7576
public void onError(Call<LoginResponse> call, Response<LoginResponse> response) {
7677
// do nothing
7778
Toast.makeText(DevAuthActivity.this, R.string.login_failed, Toast.LENGTH_LONG).show();
79+
commonProgressDialog.dismiss();
7880
}
7981

8082
});
@@ -86,7 +88,7 @@ public void onError(Call<LoginResponse> call, Response<LoginResponse> response)
8688

8789
public void openHome() {
8890
// Cancel before leaving activity to avoid leaking windows
89-
connectionProgressDialog.dismiss();
91+
commonProgressDialog.dismiss();
9092
Intent i = new Intent(this, ZulipActivity.class);
9193
startActivity(i);
9294
finish();

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.zulip.android.activities;
22

3-
import android.app.ProgressDialog;
43
import android.content.Context;
54
import android.content.DialogInterface;
65
import android.content.Intent;
@@ -42,6 +41,7 @@
4241
import com.zulip.android.networking.util.DefaultCallback;
4342
import com.zulip.android.util.AnimationHelper;
4443
import com.zulip.android.util.Constants;
44+
import com.zulip.android.util.CommonProgressDialog;
4545

4646
import org.json.JSONException;
4747
import org.json.JSONObject;
@@ -65,7 +65,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener,
6565
private static final String TAG = "LoginActivity";
6666
private static final int REQUEST_CODE_RESOLVE_ERR = 9000;
6767
private static final int REQUEST_CODE_SIGN_IN = 9001;
68-
private ProgressDialog connectionProgressDialog;
68+
private CommonProgressDialog commonProgressDialog;
6969
private GoogleApiClient mGoogleApiClient;
7070
private EditText mServerEditText;
7171
private EditText mUserName;
@@ -88,9 +88,7 @@ protected void onCreate(Bundle savedInstanceState) {
8888
setSupportActionBar(toolbar);
8989

9090
// Progress bar to be displayed if the connection failure is not resolved.
91-
connectionProgressDialog = new ProgressDialog(this);
92-
connectionProgressDialog.setMessage(getString(R.string.signing_in));
93-
91+
commonProgressDialog = new CommonProgressDialog(this);
9492
mServerEditText = (EditText) findViewById(R.id.server_url);
9593
mGoogleSignInButton = findViewById(R.id.google_sign_in_button);
9694
findViewById(R.id.google_sign_in_button).setOnClickListener(this);
@@ -264,6 +262,7 @@ private boolean isUrlValid(String url) {
264262
}
265263

266264
private void showBackends(String httpScheme, String serverURL) {
265+
commonProgressDialog.showWithMessage(getString(R.string.connecting_to_server));
267266
// if server url does not end with "/", then append it
268267
if (!serverURL.endsWith("/")) {
269268
serverURL = serverURL + "/";
@@ -317,12 +316,14 @@ public void onSuccess(Call<ZulipBackendResponse> call, Response<ZulipBackendResp
317316
if (response.body().isDev()) {
318317
findViewById(R.id.local_server_button).setVisibility(View.VISIBLE);
319318
}
319+
commonProgressDialog.dismiss();
320320
showLoginFields();
321321
}
322322

323323
@Override
324324
public void onError(Call<ZulipBackendResponse> call, Response<ZulipBackendResponse> response) {
325325
Toast.makeText(LoginActivity.this, R.string.toast_login_failed_fetching_backends, Toast.LENGTH_SHORT).show();
326+
commonProgressDialog.dismiss();
326327
}
327328

328329
@Override
@@ -333,6 +334,7 @@ public void onFailure(Call<ZulipBackendResponse> call, Throwable t) {
333334
} else {
334335
Toast.makeText(LoginActivity.this, R.string.invalid_url, Toast.LENGTH_SHORT).show();
335336
}
337+
commonProgressDialog.dismiss();
336338
}
337339
});
338340

@@ -377,7 +379,7 @@ private void handleSignInResult(final GoogleSignInResult result) {
377379

378380
// if there's a problem with fetching the account, bail
379381
if (account == null) {
380-
connectionProgressDialog.dismiss();
382+
commonProgressDialog.dismiss();
381383
Toast.makeText(LoginActivity.this, R.string.google_app_login_failed, Toast.LENGTH_SHORT).show();
382384
return;
383385
}
@@ -388,26 +390,26 @@ private void handleSignInResult(final GoogleSignInResult result) {
388390

389391
@Override
390392
public void onSuccess(Call<LoginResponse> call, Response<LoginResponse> response) {
391-
connectionProgressDialog.dismiss();
393+
commonProgressDialog.dismiss();
392394
getApp().setLoggedInApiKey(response.body().getApiKey(), response.body().getEmail());
393395
openHome();
394396
}
395397

396398
@Override
397399
public void onError(Call<LoginResponse> call, Response<LoginResponse> response) {
398-
connectionProgressDialog.dismiss();
400+
commonProgressDialog.dismiss();
399401
}
400402

401403
@Override
402404
public void onFailure(Call<LoginResponse> call, Throwable t) {
403405
super.onFailure(call, t);
404-
connectionProgressDialog.dismiss();
406+
commonProgressDialog.dismiss();
405407
}
406408
});
407409

408410
} else {
409411
// something bad happened. whoops.
410-
connectionProgressDialog.dismiss();
412+
commonProgressDialog.dismiss();
411413
Toast.makeText(LoginActivity.this, R.string.google_app_login_failed, Toast.LENGTH_SHORT).show();
412414
}
413415
}
@@ -419,15 +421,15 @@ private void openLegal() {
419421

420422
public void openHome() {
421423
// Cancel before leaving activity to avoid leaking windows
422-
connectionProgressDialog.dismiss();
424+
commonProgressDialog.dismiss();
423425
Intent i = new Intent(this, ZulipActivity.class);
424426
startActivity(i);
425427
finish();
426428
}
427429

428430
@Override
429431
public void onConnectionFailed(ConnectionResult result) {
430-
if (connectionProgressDialog.isShowing()) {
432+
if (commonProgressDialog.isShowing()) {
431433
// The user clicked the sign-in button already. Start to resolve
432434
// connection errors. Wait until onConnected() to dismiss the
433435
// connection dialog.
@@ -437,11 +439,11 @@ public void onConnectionFailed(ConnectionResult result) {
437439
} catch (SendIntentException e) {
438440
Log.e(TAG, e.getMessage(), e);
439441
// Yeah, no idea what to do here.
440-
connectionProgressDialog.dismiss();
442+
commonProgressDialog.dismiss();
441443
Toast.makeText(LoginActivity.this, R.string.google_app_login_failed, Toast.LENGTH_SHORT).show();
442444
}
443445
} else {
444-
connectionProgressDialog.dismiss();
446+
commonProgressDialog.dismiss();
445447
if (!isNetworkAvailable()) {
446448
Toast.makeText(LoginActivity.this, R.string.toast_no_internet_connection, Toast.LENGTH_SHORT).show();
447449
} else {
@@ -482,14 +484,14 @@ private void allowUserToPickAccount() {
482484
public void onClick(View v) {
483485
switch (v.getId()) {
484486
case R.id.google_sign_in_button:
485-
connectionProgressDialog.show();
487+
commonProgressDialog.showWithMessage(getString(R.string.signing_in));
486488
setupGoogleSignIn();
487489
break;
488490
case R.id.zulip_login:
489491
if (!isInputValid()) {
490492
return;
491493
}
492-
connectionProgressDialog.show();
494+
commonProgressDialog.showWithMessage(getString(R.string.signing_in));
493495
String username = mUserName.getText().toString();
494496
String password = mPassword.getText().toString();
495497
getServices()
@@ -498,15 +500,15 @@ public void onClick(View v) {
498500

499501
@Override
500502
public void onSuccess(Call<LoginResponse> call, Response<LoginResponse> response) {
501-
connectionProgressDialog.dismiss();
503+
commonProgressDialog.dismiss();
502504
getApp().setLoggedInApiKey(response.body().getApiKey(), response.body().getEmail());
503505
openHome();
504506
}
505507

506508

507509
@Override
508510
public void onError(Call<LoginResponse> call, Response<LoginResponse> response) {
509-
connectionProgressDialog.dismiss();
511+
commonProgressDialog.dismiss();
510512
if (response != null && response.errorBody() != null) {
511513
try {
512514
JSONObject message = new JSONObject(response.errorBody().string());
@@ -528,7 +530,7 @@ public void onError(Call<LoginResponse> call, Response<LoginResponse> response)
528530
@Override
529531
public void onFailure(Call<LoginResponse> call, Throwable t) {
530532
super.onFailure(call, t);
531-
connectionProgressDialog.dismiss();
533+
commonProgressDialog.dismiss();
532534
if (!isNetworkAvailable()) {
533535
Toast.makeText(LoginActivity.this, R.string.toast_no_internet_connection, Toast.LENGTH_LONG).show();
534536
} else {
@@ -543,17 +545,17 @@ public void onFailure(Call<LoginResponse> call, Throwable t) {
543545
break;
544546
case R.id.local_server_button:
545547
if (!isInputValidForDevAuth()) return;
546-
connectionProgressDialog.show();
548+
commonProgressDialog.showWithMessage(getString(R.string.signing_in));
547549
AsyncDevGetEmails asyncDevGetEmails = new AsyncDevGetEmails(LoginActivity.this);
548550
asyncDevGetEmails.setCallback(new ZulipAsyncPushTask.AsyncTaskCompleteListener() {
549551
@Override
550552
public void onTaskComplete(String result, JSONObject jsonObject) {
551-
connectionProgressDialog.dismiss();
553+
commonProgressDialog.dismiss();
552554
}
553555

554556
@Override
555557
public void onTaskFailure(String result) {
556-
connectionProgressDialog.dismiss();
558+
commonProgressDialog.dismiss();
557559
}
558560
});
559561
asyncDevGetEmails.execute();

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
import com.zulip.android.networking.response.UploadResponse;
104104
import com.zulip.android.util.AnimationHelper;
105105
import com.zulip.android.util.Constants;
106+
import com.zulip.android.util.CommonProgressDialog;
106107
import com.zulip.android.util.FilePathHelper;
107108
import com.zulip.android.util.MutedTopics;
108109
import com.zulip.android.util.RemoveViewsOnScroll;
@@ -168,7 +169,7 @@ public class ZulipActivity extends BaseActivity implements
168169
private AsyncGetEvents event_poll;
169170
private Handler statusUpdateHandler;
170171
private Runnable statusUpdateRunnable;
171-
172+
public CommonProgressDialog commonProgressDialog;
172173
private int mToolbarHeightInPx;
173174
private int statusBarHeight = 0;
174175
private MessageListFragment narrowedList;
@@ -334,6 +335,7 @@ protected void onCreate(Bundle savedInstanceState) {
334335
notifications = new Notifications(this);
335336
notifications.register();
336337
setContentView(R.layout.main);
338+
commonProgressDialog = new CommonProgressDialog(this);
337339
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
338340
setSupportActionBar(toolbar);
339341
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@@ -1787,6 +1789,7 @@ private void processParams() {
17871789
Log.i(PARAMS, "Resetting the database...");
17881790
app.resetDatabase();
17891791
Log.i(PARAMS, "Database deleted successfully.");
1792+
commonProgressDialog.dismiss();
17901793
this.finish();
17911794
break;
17921795
default:
@@ -2065,6 +2068,7 @@ public void onClick(
20652068
break;
20662069
case R.id.refresh:
20672070
Log.w("menu", "Refreshed manually by user. We shouldn't need this.");
2071+
commonProgressDialog.showWithMessage(getString(R.string.refreshing));
20682072
onRefresh();
20692073
break;
20702074
case R.id.today:
@@ -2120,6 +2124,7 @@ private void setNightMode(@AppCompatDelegate.NightMode int nightMode) {
21202124
* Log the user out of the app, clearing our cache of their credentials.
21212125
*/
21222126
private void logout() {
2127+
commonProgressDialog.showWithMessage(getString(R.string.logging_out));
21232128
this.logged_in = false;
21242129
final String serverUrl = app.getServerURI();
21252130

@@ -2135,6 +2140,9 @@ public void run() {
21352140
* Switch to the login view.
21362141
*/
21372142
private void openLogin(String serverUrl) {
2143+
if (commonProgressDialog != null && commonProgressDialog.isShowing()) {
2144+
commonProgressDialog.dismiss();
2145+
}
21382146
Intent i = new Intent(this, LoginActivity.class);
21392147
i.putExtra(Constants.SERVER_URL, serverUrl);
21402148
startActivity(i);

app/src/main/java/com/zulip/android/networking/AsyncGetEvents.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ public void run() {
209209
mActivity.getPeopleAdapter().refresh();
210210
mActivity.onReadyToDisplay(true);
211211
mActivity.checkAndSetupStreamsDrawer();
212+
if (mActivity.commonProgressDialog != null && mActivity.commonProgressDialog.isShowing()) {
213+
mActivity.commonProgressDialog.dismiss();
214+
}
212215
}
213216
});
214217
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.zulip.android.util;
2+
3+
import android.app.ProgressDialog;
4+
import android.content.Context;
5+
6+
/**
7+
* Common progress dialog used in the entire app
8+
* In the later stage if we change progress style then changes should be done here only
9+
*/
10+
11+
public class CommonProgressDialog {
12+
13+
private ProgressDialog progressDialog;
14+
15+
public CommonProgressDialog(Context context) {
16+
progressDialog = new ProgressDialog(context);
17+
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
18+
}
19+
20+
public void show() {
21+
progressDialog.show();
22+
}
23+
24+
public void showWithMessage(String message){
25+
setMessage(message);
26+
show();
27+
}
28+
29+
public void dismiss() {
30+
progressDialog.dismiss();
31+
}
32+
33+
public boolean isShowing() {
34+
return progressDialog.isShowing();
35+
}
36+
37+
public void setMessage(String message) {
38+
progressDialog.setMessage(message);
39+
}
40+
}

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,7 @@
148148
<string name="default_delete_text">(deleted)</string>
149149
<string name="message_edited_tag">(EDITED)</string>
150150
<string name="progress_bar_description">Loading new messages</string>
151+
<string name="connecting_to_server">Connecting to server</string>
152+
<string name="refreshing">Refreshing</string>
153+
<string name="logging_out">Logging out</string>
151154
</resources>

0 commit comments

Comments
 (0)