24
24
import androidx .activity .result .contract .ActivityResultContracts ;
25
25
import androidx .annotation .NonNull ;
26
26
import androidx .annotation .Nullable ;
27
+ import androidx .annotation .VisibleForTesting ;
27
28
import androidx .appcompat .widget .AppCompatTextView ;
28
29
import androidx .fragment .app .FragmentManager ;
29
30
import androidx .recyclerview .widget .GridLayoutManager ;
32
33
import androidx .recyclerview .widget .RecyclerView .ItemAnimator ;
33
34
import androidx .recyclerview .widget .RecyclerView .OnItemTouchListener ;
34
35
import androidx .recyclerview .widget .SimpleItemAnimator ;
35
- import butterknife .BindView ;
36
- import butterknife .ButterKnife ;
37
- import butterknife .OnClick ;
38
36
import com .google .android .material .floatingactionbutton .FloatingActionButton ;
39
37
import fr .free .nrw .commons .CommonsApplication ;
40
38
import fr .free .nrw .commons .Media ;
41
39
import fr .free .nrw .commons .R ;
42
40
import fr .free .nrw .commons .Utils ;
43
41
import fr .free .nrw .commons .auth .SessionManager ;
42
+ import fr .free .nrw .commons .databinding .FragmentContributionsListBinding ;
44
43
import fr .free .nrw .commons .di .CommonsDaggerSupportFragment ;
45
44
import fr .free .nrw .commons .media .MediaClient ;
46
45
import fr .free .nrw .commons .profile .ProfileActivity ;
@@ -66,61 +65,43 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
66
65
67
66
private static final String RV_STATE = "rv_scroll_state" ;
68
67
69
- @ BindView (R .id .contributionsList )
70
- RecyclerView rvContributionsList ;
71
- @ BindView (R .id .loadingContributionsProgressBar )
72
- ProgressBar progressBar ;
73
- @ BindView (R .id .fab_plus )
74
- FloatingActionButton fabPlus ;
75
- @ BindView (R .id .fab_camera )
76
- FloatingActionButton fabCamera ;
77
- @ BindView (R .id .fab_gallery )
78
- FloatingActionButton fabGallery ;
79
- @ BindView (R .id .noContributionsYet )
80
- TextView noContributionsYet ;
81
- @ BindView (R .id .fab_layout )
82
- LinearLayout fab_layout ;
83
- @ BindView (R .id .fab_custom_gallery )
84
- FloatingActionButton fabCustomGallery ;
85
-
86
68
@ Inject
87
69
SystemThemeUtils systemThemeUtils ;
88
- @ BindView (R .id .tv_contributions_of_user )
89
- AppCompatTextView tvContributionsOfUser ;
90
-
91
70
@ Inject
92
71
ContributionController controller ;
93
72
@ Inject
94
73
MediaClient mediaClient ;
95
-
96
74
@ Named (NAMED_LANGUAGE_WIKI_PEDIA_WIKI_SITE )
97
75
@ Inject
98
76
WikiSite languageWikipediaSite ;
99
-
100
77
@ Inject
101
78
ContributionsListPresenter contributionsListPresenter ;
102
-
103
79
@ Inject
104
80
SessionManager sessionManager ;
105
81
82
+ private FragmentContributionsListBinding binding ;
106
83
private Animation fab_close ;
107
84
private Animation fab_open ;
108
85
private Animation rotate_forward ;
109
86
private Animation rotate_backward ;
110
-
111
-
112
87
private boolean isFabOpen ;
113
88
114
- private ContributionsListAdapter adapter ;
89
+ @ VisibleForTesting
90
+ protected RecyclerView rvContributionsList ;
91
+
92
+ @ VisibleForTesting
93
+ protected ContributionsListAdapter adapter ;
115
94
116
95
@ Nullable
117
- private Callback callback ;
96
+ @ VisibleForTesting
97
+ protected Callback callback ;
118
98
119
99
private final int SPAN_COUNT_LANDSCAPE = 3 ;
120
100
private final int SPAN_COUNT_PORTRAIT = 1 ;
121
101
122
102
private int contributionsSize ;
123
- String userName ;
103
+ private String userName ;
104
+
124
105
private ActivityResultLauncher <String []> inAppCameraLocationPermissionLauncher = registerForActivityResult (new ActivityResultContracts .RequestMultiplePermissions (), new ActivityResultCallback <Map <String , Boolean >>() {
125
106
@ Override
126
107
public void onActivityResult (Map <String , Boolean > result ) {
@@ -162,21 +143,32 @@ public void onCreate(
162
143
public View onCreateView (
163
144
final LayoutInflater inflater , @ Nullable final ViewGroup container ,
164
145
@ Nullable final Bundle savedInstanceState ) {
165
- final View view = inflater .inflate (R .layout .fragment_contributions_list , container , false );
166
- ButterKnife .bind (this , view );
146
+ binding = FragmentContributionsListBinding .inflate (
147
+ inflater , container , false
148
+ );
149
+ rvContributionsList = binding .contributionsList ;
150
+
167
151
contributionsListPresenter .onAttachView (this );
152
+ binding .fabCustomGallery .setOnClickListener (v -> launchCustomSelector ());
168
153
169
154
if (Objects .equals (sessionManager .getUserName (), userName )) {
170
- tvContributionsOfUser .setVisibility (GONE );
171
- fab_layout .setVisibility (VISIBLE );
155
+ binding . tvContributionsOfUser .setVisibility (GONE );
156
+ binding . fabLayout .setVisibility (VISIBLE );
172
157
} else {
173
- tvContributionsOfUser .setVisibility (VISIBLE );
174
- tvContributionsOfUser .setText (getString (R .string .contributions_of_user , userName ));
175
- fab_layout .setVisibility (GONE );
158
+ binding . tvContributionsOfUser .setVisibility (VISIBLE );
159
+ binding . tvContributionsOfUser .setText (getString (R .string .contributions_of_user , userName ));
160
+ binding . fabLayout .setVisibility (GONE );
176
161
}
177
162
178
163
initAdapter ();
179
- return view ;
164
+
165
+ return binding .getRoot ();
166
+ }
167
+
168
+ @ Override
169
+ public void onDestroyView () {
170
+ binding = null ;
171
+ super .onDestroyView ();
180
172
}
181
173
182
174
@ Override
@@ -309,7 +301,7 @@ private int getSpanCount(final int orientation) {
309
301
public void onConfigurationChanged (final Configuration newConfig ) {
310
302
super .onConfigurationChanged (newConfig );
311
303
// check orientation
312
- fab_layout .setOrientation (newConfig .orientation == Configuration .ORIENTATION_LANDSCAPE ?
304
+ binding . fabLayout .setOrientation (newConfig .orientation == Configuration .ORIENTATION_LANDSCAPE ?
313
305
LinearLayout .HORIZONTAL : LinearLayout .VERTICAL );
314
306
rvContributionsList
315
307
.setLayoutManager (
@@ -324,12 +316,12 @@ private void initializeAnimations() {
324
316
}
325
317
326
318
private void setListeners () {
327
- fabPlus .setOnClickListener (view -> animateFAB (isFabOpen ));
328
- fabCamera .setOnClickListener (view -> {
319
+ binding . fabPlus .setOnClickListener (view -> animateFAB (isFabOpen ));
320
+ binding . fabCamera .setOnClickListener (view -> {
329
321
controller .initiateCameraPick (getActivity (), inAppCameraLocationPermissionLauncher );
330
322
animateFAB (isFabOpen );
331
323
});
332
- fabGallery .setOnClickListener (view -> {
324
+ binding . fabGallery .setOnClickListener (view -> {
333
325
controller .initiateGalleryPick (getActivity (), true );
334
326
animateFAB (isFabOpen );
335
327
});
@@ -338,8 +330,7 @@ private void setListeners() {
338
330
/**
339
331
* Launch Custom Selector.
340
332
*/
341
- @ OnClick (R .id .fab_custom_gallery )
342
- void launchCustomSelector () {
333
+ protected void launchCustomSelector () {
343
334
controller .initiateCustomGalleryPickWithPermission (getActivity ());
344
335
animateFAB (isFabOpen );
345
336
}
@@ -350,23 +341,23 @@ public void scrollToTop() {
350
341
351
342
private void animateFAB (final boolean isFabOpen ) {
352
343
this .isFabOpen = !isFabOpen ;
353
- if (fabPlus .isShown ()) {
344
+ if (binding . fabPlus .isShown ()) {
354
345
if (isFabOpen ) {
355
- fabPlus .startAnimation (rotate_backward );
356
- fabCamera .startAnimation (fab_close );
357
- fabGallery .startAnimation (fab_close );
358
- fabCustomGallery .startAnimation (fab_close );
359
- fabCamera .hide ();
360
- fabGallery .hide ();
361
- fabCustomGallery .hide ();
346
+ binding . fabPlus .startAnimation (rotate_backward );
347
+ binding . fabCamera .startAnimation (fab_close );
348
+ binding . fabGallery .startAnimation (fab_close );
349
+ binding . fabCustomGallery .startAnimation (fab_close );
350
+ binding . fabCamera .hide ();
351
+ binding . fabGallery .hide ();
352
+ binding . fabCustomGallery .hide ();
362
353
} else {
363
- fabPlus .startAnimation (rotate_forward );
364
- fabCamera .startAnimation (fab_open );
365
- fabGallery .startAnimation (fab_open );
366
- fabCustomGallery .startAnimation (fab_open );
367
- fabCamera .show ();
368
- fabGallery .show ();
369
- fabCustomGallery .show ();
354
+ binding . fabPlus .startAnimation (rotate_forward );
355
+ binding . fabCamera .startAnimation (fab_open );
356
+ binding . fabGallery .startAnimation (fab_open );
357
+ binding . fabCustomGallery .startAnimation (fab_open );
358
+ binding . fabCamera .show ();
359
+ binding . fabGallery .show ();
360
+ binding . fabCustomGallery .show ();
370
361
}
371
362
this .isFabOpen = !isFabOpen ;
372
363
}
@@ -377,7 +368,7 @@ private void animateFAB(final boolean isFabOpen) {
377
368
*/
378
369
@ Override
379
370
public void showWelcomeTip (final boolean shouldShow ) {
380
- noContributionsYet .setVisibility (shouldShow ? VISIBLE : GONE );
371
+ binding . noContributionsYet .setVisibility (shouldShow ? VISIBLE : GONE );
381
372
}
382
373
383
374
/**
@@ -387,12 +378,12 @@ public void showWelcomeTip(final boolean shouldShow) {
387
378
*/
388
379
@ Override
389
380
public void showProgress (final boolean shouldShow ) {
390
- progressBar .setVisibility (shouldShow ? VISIBLE : GONE );
381
+ binding . loadingContributionsProgressBar .setVisibility (shouldShow ? VISIBLE : GONE );
391
382
}
392
383
393
384
@ Override
394
385
public void showNoContributionsUI (final boolean shouldShow ) {
395
- noContributionsYet .setVisibility (shouldShow ? VISIBLE : GONE );
386
+ binding . noContributionsYet .setVisibility (shouldShow ? VISIBLE : GONE );
396
387
}
397
388
398
389
@ Override
0 commit comments