1
1
package fr .free .nrw .commons .delete ;
2
2
3
- import android .app .NotificationManager ;
4
- import android .app .PendingIntent ;
5
3
import android .content .Context ;
6
4
import android .content .Intent ;
7
5
import android .net .Uri ;
15
13
import javax .inject .Singleton ;
16
14
17
15
import androidx .appcompat .app .AlertDialog ;
18
- import androidx .core .app .NotificationCompat ;
19
16
import fr .free .nrw .commons .BuildConfig ;
20
- import fr .free .nrw .commons .CommonsApplication ;
21
17
import fr .free .nrw .commons .Media ;
22
- import fr .free .nrw .commons .R ;
23
18
import fr .free .nrw .commons .auth .SessionManager ;
24
19
import fr .free .nrw .commons .mwapi .MediaWikiApi ;
20
+ import fr .free .nrw .commons .notification .NotificationHelper ;
25
21
import fr .free .nrw .commons .review .ReviewActivity ;
26
22
import fr .free .nrw .commons .utils .ViewUtil ;
27
23
import io .reactivex .Single ;
28
24
import timber .log .Timber ;
29
25
30
- import static androidx .core .app .NotificationCompat .DEFAULT_ALL ;
31
- import static androidx .core .app .NotificationCompat .PRIORITY_HIGH ;
26
+ import static fr .free .nrw .commons .notification .NotificationHelper .NOTIFICATION_DELETE ;
32
27
33
28
/**
34
29
* Refactored async task to Rx
35
30
*/
36
31
@ Singleton
37
32
public class DeleteHelper {
38
- private static final int NOTIFICATION_DELETE = 1 ;
39
-
40
33
private final MediaWikiApi mwApi ;
41
34
private final SessionManager sessionManager ;
42
-
43
- private NotificationManager notificationManager ;
44
- private NotificationCompat .Builder notificationBuilder ;
35
+ private final NotificationHelper notificationHelper ;
45
36
46
37
@ Inject
47
- public DeleteHelper (MediaWikiApi mwApi , SessionManager sessionManager ) {
38
+ public DeleteHelper (MediaWikiApi mwApi ,
39
+ SessionManager sessionManager ,
40
+ NotificationHelper notificationHelper ) {
48
41
this .mwApi = mwApi ;
49
42
this .sessionManager = sessionManager ;
43
+ this .notificationHelper = notificationHelper ;
50
44
}
51
45
52
46
/**
@@ -57,9 +51,6 @@ public DeleteHelper(MediaWikiApi mwApi, SessionManager sessionManager) {
57
51
* @return
58
52
*/
59
53
public Single <Boolean > makeDeletion (Context context , Media media , String reason ) {
60
- notificationManager = (NotificationManager ) context .getSystemService (Context .NOTIFICATION_SERVICE );
61
- notificationBuilder = new NotificationCompat .Builder (context , CommonsApplication .NOTIFICATION_CHANNEL_ID_ALL )
62
- .setOnlyAlertOnce (true );
63
54
ViewUtil .showShortToast (context , "Trying to nominate " + media .getDisplayTitle () + " for deletion" );
64
55
65
56
return Single .fromCallable (() -> delete (media , reason ))
@@ -122,7 +113,7 @@ private boolean delete(Media media, String reason) {
122
113
return true ;
123
114
}
124
115
125
- public boolean showDeletionNotification (Context context , Media media , boolean result ) {
116
+ private boolean showDeletionNotification (Context context , Media media , boolean result ) {
126
117
String message ;
127
118
String title = "Nominating for Deletion" ;
128
119
@@ -134,20 +125,9 @@ public boolean showDeletionNotification(Context context, Media media, boolean re
134
125
message = "Could not request deletion." ;
135
126
}
136
127
137
- notificationBuilder .setDefaults (DEFAULT_ALL )
138
- .setContentTitle (title )
139
- .setStyle (new NotificationCompat .BigTextStyle ()
140
- .bigText (message ))
141
- .setSmallIcon (R .drawable .ic_launcher )
142
- .setProgress (0 , 0 , false )
143
- .setOngoing (false )
144
- .setPriority (PRIORITY_HIGH );
145
-
146
128
String urlForDelete = BuildConfig .COMMONS_URL + "/wiki/Commons:Deletion_requests/File:" + media .getFilename ();
147
129
Intent browserIntent = new Intent (Intent .ACTION_VIEW , Uri .parse (urlForDelete ));
148
- PendingIntent pendingIntent = PendingIntent .getActivity (context , 1 , browserIntent , PendingIntent .FLAG_UPDATE_CURRENT );
149
- notificationBuilder .setContentIntent (pendingIntent );
150
- notificationManager .notify (NOTIFICATION_DELETE , notificationBuilder .build ());
130
+ notificationHelper .showNotification (context , title , message , NOTIFICATION_DELETE , browserIntent );
151
131
return result ;
152
132
}
153
133
0 commit comments