1
1
package fr .free .nrw .commons .theme ;
2
2
3
+ import static fr .free .nrw .commons .di .NetworkingModule .NAMED_COMMONS_WIKI_SITE ;
4
+
3
5
import android .accounts .Account ;
4
6
import android .accounts .AccountManager ;
5
7
import android .app .ActivityManager ;
8
+ import android .app .ProgressDialog ;
6
9
import android .content .ActivityNotFoundException ;
7
10
import android .content .Context ;
8
11
import android .content .Intent ;
22
25
import android .widget .TextView ;
23
26
import android .widget .Toast ;
24
27
28
+ import fr .free .nrw .commons .auth .LogoutClient ;
29
+ import io .reactivex .android .schedulers .AndroidSchedulers ;
30
+ import io .reactivex .disposables .CompositeDisposable ;
31
+ import io .reactivex .schedulers .Schedulers ;
25
32
import javax .inject .Inject ;
26
33
import javax .inject .Named ;
27
34
40
47
import fr .free .nrw .commons .logging .CommonsLogSender ;
41
48
import fr .free .nrw .commons .review .ReviewActivity ;
42
49
import fr .free .nrw .commons .settings .SettingsActivity ;
50
+ import org .wikipedia .dataclient .Service ;
51
+ import org .wikipedia .dataclient .WikiSite ;
43
52
import timber .log .Timber ;
44
53
45
54
public abstract class NavigationBaseActivity extends BaseActivity
@@ -61,6 +70,15 @@ public abstract class NavigationBaseActivity extends BaseActivity
61
70
62
71
private ActionBarDrawerToggle toggle ;
63
72
73
+ @ Inject
74
+ LogoutClient logoutClient ;
75
+
76
+
77
+ private CompositeDisposable disposable = new CompositeDisposable ();
78
+ private Service service ;
79
+
80
+ private ProgressDialog progressDialog ;
81
+
64
82
public void initDrawer () {
65
83
navigationView .setNavigationItemSelectedListener (this );
66
84
@@ -201,9 +219,7 @@ public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
201
219
.setMessage (R .string .logout_verification )
202
220
.setCancelable (false )
203
221
.setPositiveButton (R .string .yes , (dialog , which ) -> {
204
- BaseLogoutListener logoutListener = new BaseLogoutListener ();
205
- CommonsApplication app = (CommonsApplication ) getApplication ();
206
- app .clearApplicationData (this , logoutListener );
222
+ handleLogout ();
207
223
})
208
224
.setNegativeButton (R .string .no , (dialog , which ) -> dialog .cancel ())
209
225
.show ();
@@ -227,6 +243,36 @@ public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
227
243
}
228
244
}
229
245
246
+ /**
247
+ * Ask the logout client to post the logout api
248
+ */
249
+ private void handleLogout () {
250
+ if (null == progressDialog ) {
251
+ progressDialog = new ProgressDialog (this );
252
+ progressDialog .setMessage (getString (R .string .please_wait ));
253
+ }
254
+
255
+ progressDialog .show ();
256
+
257
+ disposable .add (logoutClient .postLogout ()
258
+ .subscribeOn (Schedulers .io ())
259
+ .observeOn (AndroidSchedulers .mainThread ())
260
+ .subscribe (mwQueryResponse -> {
261
+ BaseLogoutListener logoutListener = new BaseLogoutListener ();
262
+ CommonsApplication app = (CommonsApplication ) getApplication ();
263
+ app .clearApplicationData (this , logoutListener );
264
+ progressDialog .cancel ();
265
+ },
266
+ t -> {
267
+ progressDialog .cancel ();
268
+ Toast .makeText (NavigationBaseActivity .this ,
269
+ t .getLocalizedMessage (), Toast .LENGTH_SHORT ).show ();
270
+ Timber .e (t , "Something went wrong with post logout api: %s" , t
271
+ .getLocalizedMessage ());
272
+ }
273
+ ));
274
+ }
275
+
230
276
private class BaseLogoutListener implements CommonsApplication .LogoutListener {
231
277
@ Override
232
278
public void onLogoutComplete () {
@@ -294,4 +340,13 @@ public void onBackPressed() {
294
340
super .onBackPressed ();
295
341
}
296
342
}
343
+
344
+ @ Override
345
+ protected void onStop () {
346
+ super .onStop ();
347
+ disposable .clear ();
348
+ if (progressDialog != null && progressDialog .isShowing ()) {
349
+ progressDialog .cancel ();
350
+ }
351
+ }
297
352
}
0 commit comments