gt:                 startFolder = new File("/"); // root
context: package com.alpha.music.ui.fragments.mainactivity.folders;
  
  
  import android.app.Dialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.media.MediaScannerConnection;
  import android.os.Bundle;
  import android.os.Environment;
  import android.support.annotation.NonNull;
  import android.support.annotation.Nullable;
  import android.support.design.widget.AppBarLayout;
  import android.support.design.widget.CoordinatorLayout;
  import android.support.design.widget.Snackbar;
  import android.support.v4.app.LoaderManager;
  import android.support.v4.content.Loader;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.support.v7.widget.Toolbar;
  import android.text.Html;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.webkit.MimeTypeMap;
  import android.widget.PopupMenu;
  import android.widget.Toast;
  
  import com.afollestad.materialcab.MaterialCab;
  import com.afollestad.materialdialogs.DialogAction;
  import com.afollestad.materialdialogs.MaterialDialog;
  import com.alpha.music.adapter.SongFileAdapter;
  import com.alpha.music.helper.MusicPlayerRemote;
  import com.alpha.music.helper.menu.SongsMenuHelper;
  import com.alpha.music.interfaces.CabHolder;
  import com.alpha.music.model.Song;
  import com.alpha.music.ui.activities.MainActivity;
  import com.alpha.music.util.AlphaMusicColorUtil;
  import com.alpha.music.util.PreferenceUtil;
  import com.kabouzeid.appthemehelper.ThemeStore;
  import com.kabouzeid.appthemehelper.common.ATHToolbarActivity;
  import com.kabouzeid.appthemehelper.util.ToolbarContentTintHelper;
  import com.alpha.music.R;
  import com.alpha.music.helper.menu.SongMenuHelper;
  import com.alpha.music.interfaces.LoaderIds;
  import com.alpha.music.misc.DialogAsyncTask;
  import com.alpha.music.misc.UpdateToastMediaScannerCompletionListener;
  import com.alpha.music.misc.WrappedAsyncTaskLoader;
  import com.alpha.music.ui.fragments.mainactivity.AbsMainActivityFragment;
  import com.alpha.music.util.FileUtil;
  import com.alpha.music.util.ViewUtil;
  import com.alpha.music.views.BreadCrumbLayout;
  import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;
  
  import java.io.File;
  import java.io.FileFilter;
  import java.io.IOException;
  import java.lang.ref.WeakReference;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.LinkedList;
  import java.util.List;
  
  import butterknife.BindView;
  import butterknife.ButterKnife;
  import butterknife.Unbinder;
  /**
   * @author Mohit Arora
   */
  public class FoldersFragment extends AbsMainActivityFragment implements MainActivity.MainActivityFragmentCallbacks, CabHolder, BreadCrumbLayout.SelectionCallback, SongFileAdapter.Callbacks, AppBarLayout.OnOffsetChangedListener, LoaderManager.LoaderCallbacks<List<File>> {
      public static final String TAG = FoldersFragment.class.getSimpleName();
  
      private static final int LOADER_ID = LoaderIds.FOLDERS_FRAGMENT;
  
      protected static final String PATH = "path";
      protected static final String CRUMBS = "crumbs";
  
      private Unbinder unbinder;
  
      @BindView(R.id.coordinator_layout)
      CoordinatorLayout coordinatorLayout;
      @BindView(R.id.container)
      View container;
      @BindView(android.R.id.empty)
      View empty;
      @BindView(R.id.toolbar)
      Toolbar toolbar;
      @BindView(R.id.bread_crumbs)
      BreadCrumbLayout breadCrumbs;
      @BindView(R.id.appbar)
      AppBarLayout appbar;
      @BindView(R.id.recycler_view)
      FastScrollRecyclerView recyclerView;
  
      private SongFileAdapter adapter;
      private MaterialCab cab;
  
      public FoldersFragment() {
      }
  
      public static FoldersFragment newInstance(Context context) {
          return newInstance(PreferenceUtil.getInstance(context).getStartDirectory());
      }
  
      public static FoldersFragment newInstance(File directory) {
          FoldersFragment frag = new FoldersFragment();
          Bundle b = new Bundle();
          b.putSerializable(PATH, directory);
          frag.setArguments(b);
          return frag;
      }
  
      public void setCrumb(BreadCrumbLayout.Crumb crumb, boolean addToHistory) {
          if (crumb == null) return;
          saveScrollPosition();
          breadCrumbs.setActiveOrAdd(crumb, false);
          if (addToHistory) {
              breadCrumbs.addHistory(crumb);
          }
          getLoaderManager().restartLoader(LOADER_ID, null, this);
      }
  
      private void saveScrollPosition() {
          BreadCrumbLayout.Crumb crumb = getActiveCrumb();
          if (crumb != null) {
              crumb.setScrollPosition(((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition());
          }
      }
  
      @Nullable
      private BreadCrumbLayout.Crumb getActiveCrumb() {
          return breadCrumbs != null && breadCrumbs.size() > 0 ? breadCrumbs.getCrumb(breadCrumbs.getActiveIndex()) : null;
      }
  
      @Override
      public void onSaveInstanceState(Bundle outState) {
          super.onSaveInstanceState(outState);
          outState.putParcelable(CRUMBS, breadCrumbs.getStateWrapper());
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
          if (savedInstanceState == null) {
              setCrumb(new BreadCrumbLayout.Crumb(tryGetCanonicalFile((File) getArguments().getSerializable(PATH))), true);
          } else {
              breadCrumbs.restoreFromStateWrapper((BreadCrumbLayout.SavedStateWrapper) savedInstanceState.getParcelable(CRUMBS));
              getLoaderManager().initLoader(LOADER_ID, null, this);
          }
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_folder, container, false);
          unbinder = ButterKnife.bind(this, view);
          return view;
      }
  
      @Override
      public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
          setStatusbarColorAuto(view);
          getMainActivity().setNavigationbarColorAuto();
          getMainActivity().setTaskDescriptionColorAuto();
  
          setUpAppbarColor();
          setUpToolbar();
          setUpBreadCrumbs();
          setUpRecyclerView();
          setUpAdapter();
      }
  
      private void setUpAppbarColor() {
          int primaryColor = ThemeStore.primaryColor(getActivity());
          appbar.setBackgroundColor(primaryColor);
          toolbar.setBackgroundColor(primaryColor);
          breadCrumbs.setBackgroundColor(primaryColor);
          breadCrumbs.setActivatedContentColor(ToolbarContentTintHelper.toolbarTitleColor(getActivity(), primaryColor));
          breadCrumbs.setDeactivatedContentColor(ToolbarContentTintHelper.toolbarSubtitleColor(getActivity(), primaryColor));
      }
  
      private void setUpToolbar() {
          toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
          getActivity().setTitle(R.string.app_name);
          getMainActivity().setSupportActionBar(toolbar);
      }
  
      private void setUpBreadCrumbs() {
          breadCrumbs.setCallback(this);
      }
  
      private void setUpRecyclerView() {
          ViewUtil.setUpFastScrollRecyclerViewColor(getActivity(), recyclerView, ThemeStore.accentColor(getActivity()));
  
          recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
  
          appbar.addOnOffsetChangedListener(this);
      }
  
      private void setUpAdapter() {
          adapter = new SongFileAdapter(getMainActivity(), new LinkedList<File>(), R.layout.item_list, this, this);
          adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
              @Override
              public void onChanged() {
                  super.onChanged();
                  checkIsEmpty();
              }
          });
          recyclerView.setAdapter(adapter);
          checkIsEmpty();
      }
  
      @Override
      public void onPause() {
          super.onPause();
          saveScrollPosition();
      }
  
      @Override
      public void onDestroyView() {
          appbar.removeOnOffsetChangedListener(this);
          unbinder.unbind();
          super.onDestroyView();
      }
  
      @Override
      public boolean handleBackPress() {
          if (cab != null && cab.isActive()) {
              cab.finish();
              return true;
          }
          if (breadCrumbs.popHistory()) {
              setCrumb(breadCrumbs.lastHistory(), false);
              return true;
          }
          return false;
      }
  
      @NonNull
      @Override
      public MaterialCab openCab(int menuRes, MaterialCab.Callback callback) {
          if (cab != null && cab.isActive()) cab.finish();
          cab = new MaterialCab(getMainActivity(), R.id.cab_stub)
                  .setMenu(menuRes)
                  .setCloseDrawableRes(R.drawable.ic_close_white_24dp)
                  .setBackgroundColor(AlphaMusicColorUtil.shiftBackgroundColorForLightText(ThemeStore.primaryColor(getActivity())))
                  .start(callback);
          return cab;
      }
  
      @Override
      public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
          super.onCreateOptionsMenu(menu, inflater);
          inflater.inflate(R.menu.menu_folders, menu);
          ToolbarContentTintHelper.handleOnCreateOptionsMenu(getActivity(), toolbar, menu, ATHToolbarActivity.getToolbarBackgroundColor(toolbar));
      }
  
      @Override
      public void onPrepareOptionsMenu(Menu menu) {
          super.onPrepareOptionsMenu(menu);
          ToolbarContentTintHelper.handleOnPrepareOptionsMenu(getActivity(), toolbar);
      }
  
      @Override
      public boolean onOptionsItemSelected(@NonNull MenuItem item) {
          switch (item.getItemId()) {
              case R.id.action_go_to_start_directory:
                  setCrumb(new BreadCrumbLayout.Crumb(tryGetCanonicalFile(PreferenceUtil.getInstance(getActivity()).getStartDirectory())), true);
                  return true;
          }
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      public void onCrumbSelection(BreadCrumbLayout.Crumb crumb, int index) {
          setCrumb(crumb, true);
      }
  
      public static File getDefaultStartDirectory() {
          File musicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
          File startFolder;
          if (musicDir.exists() && musicDir.isDirectory()) {
              startFolder = musicDir;
          } else {
              File externalStorage = Environment.getExternalStorageDirectory();
              if (externalStorage.exists() && externalStorage.isDirectory()) {
                  startFolder = externalStorage;
              } else {
  