* Added empty constructor in ContributionsListFragment
* Initialise ContributionsListFragment's callaback in onAttach
This commit is contained in:
Ashish Kumar 2020-06-05 16:21:08 +05:30 committed by GitHub
parent 884e34887e
commit 27cc41069f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 7 deletions

View file

@ -223,7 +223,7 @@ public class ContributionsFragment
private void initFragments() {
if (null == contributionsListFragment) {
contributionsListFragment = new ContributionsListFragment(this);
contributionsListFragment = new ContributionsListFragment();
}
if (shouldShowMediaDetailsFragment) {

View file

@ -3,6 +3,7 @@ package fr.free.nrw.commons.contributions;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Parcelable;
@ -71,14 +72,11 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
private ContributionsListAdapter adapter;
private final Callback callback;
private Callback callback;
private final int SPAN_COUNT_LANDSCAPE = 3;
private final int SPAN_COUNT_PORTRAIT = 1;
ContributionsListFragment(final Callback callback) {
this.callback = callback;
}
public View onCreateView(
final LayoutInflater inflater, @Nullable final ViewGroup container,
@ -90,6 +88,20 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
return view;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (getParentFragment() != null && getParentFragment() instanceof ContributionsFragment) {
callback = ((ContributionsFragment) getParentFragment());
}
}
@Override
public void onDetach() {
super.onDetach();
callback = null;//To avoid possible memory leak
}
private void initAdapter() {
adapter = new ContributionsListAdapter(this, mediaClient);
}
@ -203,7 +215,9 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
@Override
public void retryUpload(final Contribution contribution) {
callback.retryUpload(contribution);
if (null != callback) {//Just being safe, ideally they won't be called when detached
callback.retryUpload(contribution);
}
}
@Override
@ -213,7 +227,9 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
@Override
public void openMediaDetail(final int position) {
callback.showDetail(position);
if (null != callback) {//Just being safe, ideally they won't be called when detached
callback.showDetail(position);
}
}
public Media getMediaAtPosition(final int i) {