6
6
7
7
import android .Manifest ;
8
8
import android .annotation .SuppressLint ;
9
- import android .app .Activity ;
10
- import android .content .ComponentName ;
11
9
import android .content .Context ;
12
- import android .content .Intent ;
13
- import android .content .ServiceConnection ;
14
10
import android .os .Bundle ;
15
- import android .os .IBinder ;
16
11
import android .view .LayoutInflater ;
17
12
import android .view .Menu ;
18
13
import android .view .MenuInflater ;
19
14
import android .view .MenuItem ;
20
15
import android .view .MenuItem .OnMenuItemClickListener ;
21
16
import android .view .View ;
22
- import android .view .View .OnClickListener ;
23
17
import android .view .ViewGroup ;
24
18
import android .widget .CheckBox ;
25
19
import android .widget .LinearLayout ;
26
20
import android .widget .TextView ;
27
21
import android .widget .Toast ;
28
22
import androidx .annotation .NonNull ;
29
23
import androidx .annotation .Nullable ;
30
- import androidx .appcompat .widget .SwitchCompat ;
31
24
import androidx .fragment .app .Fragment ;
32
25
import androidx .fragment .app .FragmentManager .OnBackStackChangedListener ;
33
26
import androidx .fragment .app .FragmentTransaction ;
34
-
35
- import fr .free .nrw .commons .CommonsApplication ;
36
- import fr .free .nrw .commons .MediaDataExtractor ;
37
- import fr .free .nrw .commons .auth .SessionManager ;
38
- import fr .free .nrw .commons .notification .Notification ;
39
- import fr .free .nrw .commons .notification .NotificationController ;
40
- import fr .free .nrw .commons .theme .BaseActivity ;
41
- import fr .free .nrw .commons .upload .UploadService .ServiceCallback ;
42
- import io .reactivex .disposables .Disposable ;
43
- import java .util .List ;
44
-
45
- import javax .inject .Inject ;
46
- import javax .inject .Named ;
47
-
48
27
import butterknife .BindView ;
49
28
import butterknife .ButterKnife ;
29
+ import fr .free .nrw .commons .CommonsApplication ;
50
30
import fr .free .nrw .commons .Media ;
51
31
import fr .free .nrw .commons .R ;
32
+ import fr .free .nrw .commons .auth .SessionManager ;
52
33
import fr .free .nrw .commons .campaigns .Campaign ;
53
34
import fr .free .nrw .commons .campaigns .CampaignView ;
54
35
import fr .free .nrw .commons .campaigns .CampaignsPresenter ;
66
47
import fr .free .nrw .commons .nearby .NearbyController ;
67
48
import fr .free .nrw .commons .nearby .NearbyNotificationCardView ;
68
49
import fr .free .nrw .commons .nearby .Place ;
50
+ import fr .free .nrw .commons .notification .Notification ;
69
51
import fr .free .nrw .commons .notification .NotificationActivity ;
70
- import fr .free .nrw .commons .upload .UploadService ;
52
+ import fr .free .nrw .commons .notification .NotificationController ;
53
+ import fr .free .nrw .commons .theme .BaseActivity ;
71
54
import fr .free .nrw .commons .utils .ConfigUtils ;
72
55
import fr .free .nrw .commons .utils .DialogUtil ;
73
56
import fr .free .nrw .commons .utils .NetworkUtils ;
77
60
import io .reactivex .android .schedulers .AndroidSchedulers ;
78
61
import io .reactivex .disposables .CompositeDisposable ;
79
62
import io .reactivex .schedulers .Schedulers ;
63
+ import java .util .List ;
64
+ import javax .inject .Inject ;
65
+ import javax .inject .Named ;
80
66
import timber .log .Timber ;
81
67
82
68
public class ContributionsFragment
@@ -85,16 +71,14 @@ public class ContributionsFragment
85
71
OnBackStackChangedListener ,
86
72
LocationUpdateListener ,
87
73
MediaDetailProvider ,
88
- ICampaignsView , ContributionsContract .View , Callback , ServiceCallback {
74
+ ICampaignsView , ContributionsContract .View , Callback {
89
75
@ Inject @ Named ("default_preferences" ) JsonKvStore store ;
90
76
@ Inject NearbyController nearbyController ;
91
77
@ Inject OkHttpJsonApiClient okHttpJsonApiClient ;
92
78
@ Inject CampaignsPresenter presenter ;
93
79
@ Inject LocationServiceManager locationManager ;
94
80
@ Inject NotificationController notificationController ;
95
81
96
- private UploadService uploadService ;
97
- private boolean isUploadServiceConnected ;
98
82
private CompositeDisposable compositeDisposable = new CompositeDisposable ();
99
83
100
84
private ContributionsListFragment contributionsListFragment ;
@@ -127,33 +111,7 @@ public static ContributionsFragment newInstance() {
127
111
return fragment ;
128
112
}
129
113
130
- /**
131
- * Since we will need to use parent activity on onAuthCookieAcquired, we have to wait
132
- * fragment to be attached. Latch will be responsible for this sync.
133
- */
134
- private ServiceConnection uploadServiceConnection = new ServiceConnection () {
135
- @ Override
136
- public void onServiceConnected (ComponentName componentName , IBinder binder ) {
137
- uploadService = (UploadService ) ((UploadService .UploadServiceLocalBinder ) binder )
138
- .getService ();
139
- uploadService .setServiceCallback (ContributionsFragment .this );
140
- isUploadServiceConnected = true ;
141
- }
142
-
143
- @ Override
144
- public void onServiceDisconnected (ComponentName componentName ) {
145
- // this should never happen
146
- Timber .e (new RuntimeException ("UploadService died but the rest of the process did not!" ));
147
- isUploadServiceConnected = false ;
148
- }
149
-
150
- @ Override
151
- public void onBindingDied (final ComponentName name ) {
152
- isUploadServiceConnected = false ;
153
- }
154
- };
155
114
private boolean shouldShowMediaDetailsFragment ;
156
- private boolean isAuthCookieAcquired ;
157
115
158
116
@ Override
159
117
public void onCreate (@ Nullable Bundle savedInstanceState ) {
@@ -272,7 +230,6 @@ public void onAttach(Context context) {
272
230
until fragment life time ends.
273
231
*/
274
232
if (!isFragmentAttachedBefore && getActivity () != null ) {
275
- onAuthCookieAcquired ();
276
233
isFragmentAttachedBefore = true ;
277
234
}
278
235
}
@@ -312,19 +269,6 @@ public void onBackStackChanged() {
312
269
fetchCampaigns ();
313
270
}
314
271
315
- /**
316
- * Called when onAuthCookieAcquired is called on authenticated parent activity
317
- */
318
- void onAuthCookieAcquired () {
319
- // Since we call onAuthCookieAcquired method from onAttach, isAdded is still false. So don't use it
320
- isAuthCookieAcquired =true ;
321
- if (getActivity () != null ) { // If fragment is attached to parent activity
322
- getActivity ().bindService (getUploadServiceIntent (), uploadServiceConnection , Context .BIND_AUTO_CREATE );
323
- isUploadServiceConnected = true ;
324
- }
325
-
326
- }
327
-
328
272
private void initFragments () {
329
273
if (null == contributionsListFragment ) {
330
274
contributionsListFragment = new ContributionsListFragment ();
@@ -381,13 +325,6 @@ public void removeFragment(Fragment fragment) {
381
325
getChildFragmentManager ().executePendingTransactions ();
382
326
}
383
327
384
-
385
- public Intent getUploadServiceIntent (){
386
- Intent intent = new Intent (getActivity (), UploadService .class );
387
- intent .setAction (UploadService .ACTION_START_SERVICE );
388
- return intent ;
389
- }
390
-
391
328
@ SuppressWarnings ("ConstantConditions" )
392
329
private void setUploadCount () {
393
330
compositeDisposable .add (okHttpJsonApiClient
@@ -524,14 +461,6 @@ public void onDestroy() {
524
461
locationManager .unregisterLocationManager ();
525
462
locationManager .removeLocationListener (this );
526
463
super .onDestroy ();
527
-
528
- if (isUploadServiceConnected ) {
529
- if (getActivity () != null ) {
530
- uploadService .setServiceCallback (null );
531
- getActivity ().unbindService (uploadServiceConnection );
532
- isUploadServiceConnected = false ;
533
- }
534
- }
535
464
} catch (IllegalArgumentException | IllegalStateException exception ) {
536
465
Timber .e (exception );
537
466
}
@@ -594,7 +523,6 @@ private void fetchCampaigns() {
594
523
595
524
@ Override public void onDestroyView () {
596
525
super .onDestroyView ();
597
- isUploadServiceConnected = false ;
598
526
presenter .onDetachView ();
599
527
}
600
528
@@ -606,8 +534,9 @@ private void fetchCampaigns() {
606
534
@ Override
607
535
public void retryUpload (Contribution contribution ) {
608
536
if (NetworkUtils .isInternetConnectionEstablished (getContext ())) {
609
- if (contribution .getState () == STATE_FAILED || contribution .getState () == STATE_PAUSED || contribution .getState ()==Contribution .STATE_QUEUED_LIMITED_CONNECTION_MODE && null != uploadService ) {
610
- uploadService .queue (contribution );
537
+ if (contribution .getState () == STATE_FAILED || contribution .getState () == STATE_PAUSED || contribution .getState ()==Contribution .STATE_QUEUED_LIMITED_CONNECTION_MODE ) {
538
+ contribution .setState (Contribution .STATE_QUEUED );
539
+ contributionsPresenter .saveContribution (contribution );
611
540
Timber .d ("Restarting for %s" , contribution .toString ());
612
541
} else {
613
542
Timber .d ("Skipping re-upload for non-failed %s" , contribution .toString ());
@@ -624,7 +553,11 @@ public void retryUpload(Contribution contribution) {
624
553
*/
625
554
@ Override
626
555
public void pauseUpload (Contribution contribution ) {
627
- uploadService .pauseUpload (contribution );
556
+ //Pause the upload in the global singleton
557
+ CommonsApplication .pauseUploads .put (contribution .getPageId (), true );
558
+ //Retain the paused state in DB
559
+ contribution .setState (STATE_PAUSED );
560
+ contributionsPresenter .saveContribution (contribution );
628
561
}
629
562
630
563
/**
@@ -677,10 +610,5 @@ public void backButtonClicked() {
677
610
public MediaDetailPagerFragment getMediaDetailPagerFragment () {
678
611
return mediaDetailPagerFragment ;
679
612
}
680
-
681
- @ Override
682
- public void updateUploadCount () {
683
- setUploadCount ();
684
- }
685
613
}
686
614
0 commit comments