content: package com.music.player.bhandari.m.activity;
  
  import android.content.Context;
  import android.os.Bundle;
  
  import androidx.annotation.NonNull;
  import androidx.fragment.app.Fragment;
  import androidx.recyclerview.widget.LinearLayoutManager;
  import androidx.recyclerview.widget.RecyclerView;
  
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  import com.music.player.bhandari.m.R;
  import com.music.player.bhandari.m.UIElementHelper.BottomOffsetDecoration;
  import com.music.player.bhandari.m.adapter.PlaylistLibraryAdapter;
  
  /**
   * Copyright 2017 Amit Bhandari AB
   * <p>
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * <p>
   * http://www.apache.org/licenses/LICENSE-2.0
   * <p>
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  public class FragmentPlaylistLibrary extends Fragment {
      private PlaylistLibraryAdapter playlistAdapter;
  
      public FragmentPlaylistLibrary() {
  
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
      }
  
  
      @Override
      public View onCreateView(@NonNull final LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View layout = inflater.inflate(R.layout.fragment_playlist_library, container, false);
  
          RecyclerView mRecyclerViewPlaylist = layout.findViewById(R.id.recyclerViewSystemPlaylist);
          playlistAdapter = new PlaylistLibraryAdapter(getContext());
  
          mRecyclerViewPlaylist.setAdapter(playlistAdapter);
          mRecyclerViewPlaylist.setLayoutManager(new FragmentPlaylistLibrary.WrapContentLinearLayoutManager(getContext()));
  
          float offsetPx = getResources().getDimension(R.dimen.bottom_offset_dp);
          BottomOffsetDecoration bottomOffsetDecoration = new BottomOffsetDecoration((int) offsetPx);
          mRecyclerViewPlaylist.addItemDecoration(bottomOffsetDecoration);
  
          return layout;
      }
  
      public void refreshPlaylistList() {
          if (playlistAdapter != null)
              playlistAdapter.refreshPlaylistList();
      }
  
      //for catching exception generated by recycler view which was causing abend, no other way to handle this
      class WrapContentLinearLayoutManager extends LinearLayoutManager {
          WrapContentLinearLayoutManager(Context context) {
              super(context);
          }
  
          //... constructor
          @Override
          public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
              try {
                  super.onLayoutChildren(recycler, state);
              } catch (IndexOutOfBoundsException ignored) {
              }
          }
      }
  
      @Override
      public void onDestroyView() {
          super.onDestroyView();
      }
  
  }
  
  