3
3
import android .annotation .SuppressLint ;
4
4
import android .app .AlertDialog ;
5
5
import android .content .Intent ;
6
+ import android .os .Build .VERSION ;
7
+ import android .os .Build .VERSION_CODES ;
6
8
import android .os .Bundle ;
7
9
import android .view .LayoutInflater ;
8
10
import android .view .Menu ;
9
11
import android .view .MenuInflater ;
10
12
import android .view .MenuItem ;
11
13
import android .view .View ;
12
14
import android .widget .ImageView ;
15
+ import android .widget .Switch ;
13
16
import android .widget .TextView ;
14
17
import androidx .annotation .Nullable ;
15
18
import androidx .core .view .GravityCompat ;
21
24
import butterknife .BindView ;
22
25
import butterknife .ButterKnife ;
23
26
import com .google .android .material .tabs .TabLayout ;
27
+ import fr .free .nrw .commons .CommonsApplication ;
24
28
import fr .free .nrw .commons .R ;
25
29
import fr .free .nrw .commons .auth .SessionManager ;
26
30
import fr .free .nrw .commons .location .LocationServiceManager ;
33
37
import fr .free .nrw .commons .theme .NavigationBaseActivity ;
34
38
import fr .free .nrw .commons .upload .UploadService ;
35
39
import fr .free .nrw .commons .utils .ViewUtil ;
40
+ import fr .free .nrw .commons .utils .ViewUtilWrapper ;
36
41
import io .reactivex .android .schedulers .AndroidSchedulers ;
37
42
import io .reactivex .schedulers .Schedulers ;
38
43
import java .util .List ;
@@ -56,6 +61,8 @@ public class MainActivity extends NavigationBaseActivity implements FragmentMana
56
61
NotificationController notificationController ;
57
62
@ Inject
58
63
QuizChecker quizChecker ;
64
+ @ Inject
65
+ ViewUtilWrapper viewUtilWrapper ;
59
66
60
67
61
68
public ContributionsActivityPagerAdapter contributionsActivityPagerAdapter ;
@@ -70,6 +77,7 @@ public class MainActivity extends NavigationBaseActivity implements FragmentMana
70
77
private TextView notificationCount ;
71
78
private NearbyParentFragment nearbyParentFragment ;
72
79
80
+ @ Override
73
81
public void onCreate (Bundle savedInstanceState ) {
74
82
super .onCreate (savedInstanceState );
75
83
setContentView (R .layout .activity_contributions );
@@ -280,9 +288,25 @@ public boolean onCreateOptionsMenu(Menu menu) {
280
288
this .menu = menu ;
281
289
updateMenuItem ();
282
290
setNotificationCount ();
291
+
292
+ updateLimitedConnectionToggle (menu );
293
+
283
294
return true ;
284
295
}
285
296
297
+ private void updateLimitedConnectionToggle (Menu menu ) {
298
+ MenuItem checkable = menu .findItem (R .id .toggle_limited_connection_mode );
299
+ boolean isEnabled = defaultKvStore
300
+ .getBoolean (CommonsApplication .IS_LIMITED_CONNECTION_MODE_ENABLED , false );
301
+
302
+ checkable .setChecked (isEnabled );
303
+ final Switch switchToggleLimitedConnectionMode = checkable .getActionView ()
304
+ .findViewById (R .id .switch_toggle_limited_connection_mode );
305
+ switchToggleLimitedConnectionMode .setChecked (isEnabled );
306
+ switchToggleLimitedConnectionMode .setOnCheckedChangeListener (
307
+ (buttonView , isChecked ) -> toggleLimitedConnectionMode ());
308
+ }
309
+
286
310
@ SuppressLint ("CheckResult" )
287
311
private void setNotificationCount () {
288
312
compositeDisposable .add (notificationController .getNotifications (false )
@@ -339,6 +363,27 @@ public boolean onOptionsItemSelected(MenuItem item) {
339
363
}
340
364
}
341
365
366
+ private void toggleLimitedConnectionMode () {
367
+ defaultKvStore .putBoolean (CommonsApplication .IS_LIMITED_CONNECTION_MODE_ENABLED ,
368
+ !defaultKvStore
369
+ .getBoolean (CommonsApplication .IS_LIMITED_CONNECTION_MODE_ENABLED , false ));
370
+ if (defaultKvStore
371
+ .getBoolean (CommonsApplication .IS_LIMITED_CONNECTION_MODE_ENABLED , false )) {
372
+ viewUtilWrapper
373
+ .showShortToast (getBaseContext (), getString (R .string .limited_connection_enabled ));
374
+ } else {
375
+ Intent intent = new Intent (this , UploadService .class );
376
+ intent .setAction (UploadService .PROCESS_PENDING_LIMITED_CONNECTION_MODE_UPLOADS );
377
+ if (VERSION .SDK_INT >= VERSION_CODES .O ) {
378
+ startForegroundService (intent );
379
+ } else {
380
+ startService (intent );
381
+ }
382
+ viewUtilWrapper
383
+ .showShortToast (getBaseContext (), getString (R .string .limited_connection_disabled ));
384
+ }
385
+ }
386
+
342
387
public class ContributionsActivityPagerAdapter extends FragmentPagerAdapter {
343
388
FragmentManager fragmentManager ;
344
389
0 commit comments