@@ -99,6 +99,24 @@ public void onSuccess(String s) {
9999 AppUtils .fetchDefaultObjects ();
100100 startActivity (new Intent (MainActivity .this , HomeActivity .class ));
101101 finish ();
102+ } else {
103+ AppUtils .fetchSampleUsers (new CometChat .CallbackListener <List <User >>() {
104+ @ Override
105+ public void onSuccess (List <User > users ) {
106+ if (!users .isEmpty ()) {
107+ setUsers (users );
108+ } else {
109+ stateLayout .setVisibility (View .VISIBLE );
110+ progressBar .setVisibility (View .GONE );
111+ stateMessage .setText (R .string .no_sample_users_available );
112+ }
113+ }
114+
115+ @ Override
116+ public void onError (CometChatException e ) {
117+ setUsers (AppUtils .processSampleUserList (AppUtils .loadJSONFromAsset (MainActivity .this )));
118+ }
119+ });
102120 }
103121 }
104122
@@ -109,23 +127,6 @@ public void onError(CometChatException e) {
109127 });
110128
111129
112- AppUtils .fetchSampleUsers (new CometChat .CallbackListener <List <User >>() {
113- @ Override
114- public void onSuccess (List <User > users ) {
115- if (!users .isEmpty ()) {
116- setUsers (users );
117- } else {
118- stateLayout .setVisibility (View .VISIBLE );
119- progressBar .setVisibility (View .GONE );
120- stateMessage .setText (R .string .no_sample_users_available );
121- }
122- }
123-
124- @ Override
125- public void onError (CometChatException e ) {
126- setUsers (AppUtils .processSampleUserList (AppUtils .loadJSONFromAsset (MainActivity .this )));
127- }
128- });
129130 findViewById (R .id .login ).setOnClickListener (view -> startActivity (new Intent (MainActivity .this , LoginActivity .class )));
130131
131132 user1 .setOnClickListener (view -> {
@@ -159,23 +160,27 @@ private void setUsers(List<User> users) {
159160 gridLayoutContainer .setVisibility (View .VISIBLE );
160161 for (int i = 0 ; i < users .size (); i ++) {
161162 if (i == 0 ) {
163+ if (isDestroyed () || isFinishing ()) break ;
162164 user1Name .setText (users .get (i ).getName ());
163- Glide .with (this ).load (users .get (i ).getAvatar ()).error (R .drawable .ironman ).into (user1Avatar );
165+ Glide .with (getApplicationContext () ).load (users .get (i ).getAvatar ()).error (R .drawable .ironman ).into (user1Avatar );
164166 user1 .setTag (users .get (i ).getUid ());
165167 user1 .setVisibility (View .VISIBLE );
166168 } else if (i == 1 ) {
169+ if (isDestroyed () || isFinishing ()) break ;
167170 user2Name .setText (users .get (i ).getName ());
168- Glide .with (this ).load (users .get (i ).getAvatar ()).error (R .drawable .captainamerica ).into (user2Avatar );
171+ Glide .with (getApplicationContext () ).load (users .get (i ).getAvatar ()).error (R .drawable .captainamerica ).into (user2Avatar );
169172 user2 .setTag (users .get (i ).getUid ());
170173 user2 .setVisibility (View .VISIBLE );
171174 } else if (i == 2 ) {
175+ if (isDestroyed () || isFinishing ()) break ;
172176 user3Name .setText (users .get (i ).getName ());
173- Glide .with (this ).load (users .get (i ).getAvatar ()).error (R .drawable .spiderman ).into (user3Avatar );
177+ Glide .with (getApplicationContext () ).load (users .get (i ).getAvatar ()).error (R .drawable .spiderman ).into (user3Avatar );
174178 user3 .setTag (users .get (i ).getUid ());
175179 user3 .setVisibility (View .VISIBLE );
176180 } else if (i == 3 ) {
181+ if (isDestroyed () || isFinishing ()) break ;
177182 user4Name .setText (users .get (i ).getName ());
178- Glide .with (this ).load (users .get (i ).getAvatar ()).error (R .drawable .wolverine ).into (user4Avatar );
183+ Glide .with (getApplicationContext () ).load (users .get (i ).getAvatar ()).error (R .drawable .wolverine ).into (user4Avatar );
179184 user4 .setTag (users .get (i ).getUid ());
180185 user4 .setVisibility (View .VISIBLE );
181186 }
0 commit comments