@Override
  public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ButterKnife.bind(this, view);

    applyInsets((ViewGroup) view);

    mAdapter =
        new WallpaperAdapter(
            new WallpaperAdapter.ClickListener() {
              @Override
              public boolean onClick(View view, int index, boolean longPress) {
                if (longPress) {
                  showOptions(index);
                  return true;
                } else {
                  openViewer(view, index);
                  return false;
                }
              }
            });
    mRecyclerView.setLayoutManager(
        new StaggeredGridLayoutManager(
            Config.get().gridWidthWallpaper(), StaggeredGridLayoutManager.VERTICAL));
    mRecyclerView.setAdapter(mAdapter);

    if (savedInstanceState != null)
      mWallpapers =
          (WallpaperUtils.WallpapersHolder) savedInstanceState.getSerializable("wallpapers");
    if (getActivity() != null) load();
  }
 @Override
 public void onPause() {
   super.onPause();
   if (getActivity() != null) {
     if (mAdapter != null) WallpaperUtils.saveDb(getActivity(), mAdapter.getWallpapers());
     if (getActivity().isFinishing()) {
       Bridge.cancelAll().tag(WallpapersFragment.class.getName()).commit();
     }
   }
 }
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.wallpapers, menu);
    super.onCreateOptionsMenu(menu, inflater);
    MenuItem mSearchItem = menu.findItem(R.id.search);
    SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchItem);
    mSearchView.setQueryHint(getString(R.string.search_wallpapers));
    mSearchView.setOnQueryTextListener(this);
    mSearchView.setOnCloseListener(this);
    mSearchView.setImeOptions(EditorInfo.IME_ACTION_DONE);

    if (getActivity() != null) {
      final MainActivity act = (MainActivity) getActivity();
      TintUtils.themeSearchView(
          act.getToolbar(), mSearchView, DialogUtils.resolveColor(act, R.attr.tab_icon_color));
    }
  }
 @Override
 public void onCreate(@Nullable Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setHasOptionsMenu(true);
 }
 @Override
 public void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   outState.putSerializable("wallpapers", mWallpapers);
 }
 @Override
 public void onDestroyView() {
   super.onDestroyView();
   ButterKnife.unbind(this);
   WallpaperUtils.resetOptionCache(true);
 }