3
3
import static android .view .View .GONE ;
4
4
import static android .view .View .VISIBLE ;
5
5
6
+ import android .content .Context ;
6
7
import android .content .res .Configuration ;
7
8
import android .os .Bundle ;
8
9
import android .os .Parcelable ;
@@ -71,14 +72,11 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
71
72
72
73
private ContributionsListAdapter adapter ;
73
74
74
- private final Callback callback ;
75
+ private Callback callback ;
75
76
76
77
private final int SPAN_COUNT_LANDSCAPE = 3 ;
77
78
private final int SPAN_COUNT_PORTRAIT = 1 ;
78
79
79
- ContributionsListFragment (final Callback callback ) {
80
- this .callback = callback ;
81
- }
82
80
83
81
public View onCreateView (
84
82
final LayoutInflater inflater , @ Nullable final ViewGroup container ,
@@ -90,6 +88,20 @@ public View onCreateView(
90
88
return view ;
91
89
}
92
90
91
+ @ Override
92
+ public void onAttach (Context context ) {
93
+ super .onAttach (context );
94
+ if (getParentFragment () != null && getParentFragment () instanceof ContributionsFragment ) {
95
+ callback = ((ContributionsFragment ) getParentFragment ());
96
+ }
97
+ }
98
+
99
+ @ Override
100
+ public void onDetach () {
101
+ super .onDetach ();
102
+ callback = null ;//To avoid possible memory leak
103
+ }
104
+
93
105
private void initAdapter () {
94
106
adapter = new ContributionsListAdapter (this , mediaClient );
95
107
}
@@ -203,7 +215,9 @@ public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
203
215
204
216
@ Override
205
217
public void retryUpload (final Contribution contribution ) {
206
- callback .retryUpload (contribution );
218
+ if (null != callback ) {//Just being safe, ideally they won't be called when detached
219
+ callback .retryUpload (contribution );
220
+ }
207
221
}
208
222
209
223
@ Override
@@ -213,7 +227,9 @@ public void deleteUpload(final Contribution contribution) {
213
227
214
228
@ Override
215
229
public void openMediaDetail (final int position ) {
216
- callback .showDetail (position );
230
+ if (null != callback ) {//Just being safe, ideally they won't be called when detached
231
+ callback .showDetail (position );
232
+ }
217
233
}
218
234
219
235
public Media getMediaAtPosition (final int i ) {
0 commit comments