Skip to content

Commit 27cc410

Browse files
Fixes #3784 (#3787)
* Added empty constructor in ContributionsListFragment * Initialise ContributionsListFragment's callaback in onAttach
1 parent 884e348 commit 27cc410

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ void onAuthCookieAcquired() {
223223

224224
private void initFragments() {
225225
if (null == contributionsListFragment) {
226-
contributionsListFragment = new ContributionsListFragment(this);
226+
contributionsListFragment = new ContributionsListFragment();
227227
}
228228

229229
if (shouldShowMediaDetailsFragment) {

app/src/main/java/fr/free/nrw/commons/contributions/ContributionsListFragment.java

+22-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static android.view.View.GONE;
44
import static android.view.View.VISIBLE;
55

6+
import android.content.Context;
67
import android.content.res.Configuration;
78
import android.os.Bundle;
89
import android.os.Parcelable;
@@ -71,14 +72,11 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
7172

7273
private ContributionsListAdapter adapter;
7374

74-
private final Callback callback;
75+
private Callback callback;
7576

7677
private final int SPAN_COUNT_LANDSCAPE = 3;
7778
private final int SPAN_COUNT_PORTRAIT = 1;
7879

79-
ContributionsListFragment(final Callback callback) {
80-
this.callback = callback;
81-
}
8280

8381
public View onCreateView(
8482
final LayoutInflater inflater, @Nullable final ViewGroup container,
@@ -90,6 +88,20 @@ public View onCreateView(
9088
return view;
9189
}
9290

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+
93105
private void initAdapter() {
94106
adapter = new ContributionsListAdapter(this, mediaClient);
95107
}
@@ -203,7 +215,9 @@ public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
203215

204216
@Override
205217
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+
}
207221
}
208222

209223
@Override
@@ -213,7 +227,9 @@ public void deleteUpload(final Contribution contribution) {
213227

214228
@Override
215229
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+
}
217233
}
218234

219235
public Media getMediaAtPosition(final int i) {

0 commit comments

Comments
 (0)