1
1
package fr .free .nrw .commons .delete ;
2
2
3
- import android .accounts .Account ;
4
3
import android .content .Context ;
5
4
6
5
import org .wikipedia .util .DateUtil ;
16
15
import fr .free .nrw .commons .achievements .FeedbackResponse ;
17
16
import fr .free .nrw .commons .auth .SessionManager ;
18
17
import fr .free .nrw .commons .mwapi .OkHttpJsonApiClient ;
19
- import fr .free .nrw .commons .utils .ViewUtil ;
18
+ import fr .free .nrw .commons .utils .ViewUtilWrapper ;
20
19
import io .reactivex .Single ;
21
20
import timber .log .Timber ;
22
21
@@ -26,14 +25,21 @@ public class ReasonBuilder {
26
25
private SessionManager sessionManager ;
27
26
private OkHttpJsonApiClient okHttpJsonApiClient ;
28
27
private Context context ;
28
+ private ViewUtilWrapper viewUtilWrapper ;
29
29
30
30
@ Inject
31
31
public ReasonBuilder (Context context ,
32
32
SessionManager sessionManager ,
33
- OkHttpJsonApiClient okHttpJsonApiClient ) {
33
+ OkHttpJsonApiClient okHttpJsonApiClient ,
34
+ ViewUtilWrapper viewUtilWrapper ) {
34
35
this .context = context ;
35
36
this .sessionManager = sessionManager ;
36
37
this .okHttpJsonApiClient = okHttpJsonApiClient ;
38
+ this .viewUtilWrapper = viewUtilWrapper ;
39
+ }
40
+
41
+ public Single <String > getReason (Media media , String reason ) {
42
+ return fetchArticleNumber (media , reason );
37
43
}
38
44
39
45
private String prettyUploadedDate (Media media ) {
@@ -47,7 +53,7 @@ private String prettyUploadedDate(Media media) {
47
53
private Single <String > fetchArticleNumber (Media media , String reason ) {
48
54
if (checkAccount ()) {
49
55
return okHttpJsonApiClient
50
- .getAchievements (sessionManager .getCurrentAccount (). name )
56
+ .getAchievements (sessionManager .getUserName () )
51
57
.map (feedbackResponse -> appendArticlesUsed (feedbackResponse , media , reason ));
52
58
}
53
59
return Single .just ("" );
@@ -60,20 +66,14 @@ private String appendArticlesUsed(FeedbackResponse object, Media media, String r
60
66
return reason ;
61
67
}
62
68
63
-
64
- public Single <String > getReason (Media media , String reason ) {
65
- return fetchArticleNumber (media , reason );
66
- }
67
-
68
69
/**
69
70
* check to ensure that user is logged in
70
71
* @return
71
72
*/
72
73
private boolean checkAccount (){
73
- Account currentAccount = sessionManager .getCurrentAccount ();
74
- if (currentAccount == null ) {
74
+ if (!sessionManager .doesAccountExist ()) {
75
75
Timber .d ("Current account is null" );
76
- ViewUtil .showLongToast (context , context .getResources ().getString (R .string .user_not_logged_in ));
76
+ viewUtilWrapper .showLongToast (context , context .getResources ().getString (R .string .user_not_logged_in ));
77
77
sessionManager .forceLogin (context );
78
78
return false ;
79
79
}
0 commit comments