Commit 4f0d0677 authored by Geoffrey Métais's avatar Geoffrey Métais

Instanciate adapters sooner to prevent NPE

parent 45e2545a
......@@ -72,16 +72,16 @@ import java.util.Random;
public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefreshLayout.OnRefreshListener, ViewPager.OnPageChangeListener, Medialibrary.ArtistsAddedCb, Medialibrary.ArtistsModifiedCb, Medialibrary.AlbumsAddedCb, Medialibrary.AlbumsModifiedCb, MediaAddedCb, MediaUpdatedCb, TabLayout.OnTabSelectedListener {
public final static String TAG = "VLC/AudioBrowserFragment";
private AudioBrowserAdapter mArtistsAdapter;
private AudioBrowserAdapter mAlbumsAdapter;
private AudioBrowserAdapter mSongsAdapter;
private AudioBrowserAdapter mGenresAdapter;
private AudioBrowserAdapter mPlaylistAdapter;
private final AudioBrowserAdapter mSongsAdapter = new AudioBrowserAdapter(getActivity(), MediaLibraryItem.TYPE_MEDIA, this, true);
private final AudioBrowserAdapter mArtistsAdapter = new AudioBrowserAdapter(getActivity(), MediaLibraryItem.TYPE_ARTIST, this, true);
private final AudioBrowserAdapter mAlbumsAdapter = new AudioBrowserAdapter(getActivity(), MediaLibraryItem.TYPE_ALBUM, this, true);
private final AudioBrowserAdapter mGenresAdapter = new AudioBrowserAdapter(getActivity(), MediaLibraryItem.TYPE_GENRE, this, true);
private final AudioBrowserAdapter mPlaylistAdapter = new AudioBrowserAdapter(getActivity(), MediaLibraryItem.TYPE_PLAYLIST, this, true);
private ViewPager mViewPager;
private TabLayout mTabLayout;
private TextView mEmptyView;
private ContextMenuRecyclerView[] mLists;
private final ContextMenuRecyclerView[] mLists = new ContextMenuRecyclerView[MODE_TOTAL];
private FastScroller mFastScroller;
public static final int REFRESH = 101;
......@@ -100,6 +100,12 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
public final static String TAG_ITEM = "ML_ITEM";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAdapters = new AudioBrowserAdapter[]{mArtistsAdapter, mAlbumsAdapter, mSongsAdapter, mGenresAdapter, mPlaylistAdapter};
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.audio_browser, container, false);
......@@ -119,13 +125,6 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mSongsAdapter = new AudioBrowserAdapter(getActivity(), MediaLibraryItem.TYPE_MEDIA, this, true);
mArtistsAdapter = new AudioBrowserAdapter(getActivity(), MediaLibraryItem.TYPE_ARTIST, this, true);
mAlbumsAdapter = new AudioBrowserAdapter(getActivity(), MediaLibraryItem.TYPE_ALBUM, this, true);
mGenresAdapter = new AudioBrowserAdapter(getActivity(), MediaLibraryItem.TYPE_GENRE, this, true);
mPlaylistAdapter = new AudioBrowserAdapter(getActivity(), MediaLibraryItem.TYPE_PLAYLIST, this, true);
mAdapters = new AudioBrowserAdapter[]{mArtistsAdapter, mAlbumsAdapter, mSongsAdapter, mGenresAdapter, mPlaylistAdapter};
mLists = new ContextMenuRecyclerView[MODE_TOTAL];
for (int i = 0; i < MODE_TOTAL; i++)
mLists[i] = (ContextMenuRecyclerView) mViewPager.getChildAt(i);
......
......@@ -75,7 +75,6 @@ import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.VLCInstance;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class VideoGridFragment extends SortableFragment<VideoListAdapter> implements MediaUpdatedCb, SwipeRefreshLayout.OnRefreshListener, MediaAddedCb, Filterable, IEventsHandler {
......@@ -98,6 +97,7 @@ public class VideoGridFragment extends SortableFragment<VideoListAdapter> implem
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAdapter = new VideoListAdapter(this);
if (savedInstanceState != null)
setGroup(savedInstanceState.getString(KEY_GROUP));
......@@ -146,7 +146,6 @@ public class VideoGridFragment extends SortableFragment<VideoListAdapter> implem
super.onActivityCreated(savedInstanceState);
mSwipeRefreshLayout.setOnRefreshListener(this);
mDividerItemDecoration = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
mAdapter = new VideoListAdapter(this);
if (mAdapter.isListMode())
mGridView.addItemDecoration(mDividerItemDecoration);
if (savedInstanceState != null) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment