gt:       if (path != null && path.length() != 0) {
context: /*
   * Copyright (C) 2014-2020 Arpit Khurana <arpitkh96@gmail.com>, Vishal Nehra <vishalmeham2@gmail.com>,
   * Emmanuel Messulam<emmanuelbendavid@gmail.com>, Raymond Lai <airwave209gt at gmail.com> and Contributors.
   *
   * This file is part of Amaze File Manager.
   *
   * Amaze File Manager is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  
  package com.amaze.filemanager.ui.fragments;
  
  import static com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants.PREFERENCE_CURRENT_TAB;
  import static com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SAVED_PATHS;
  import static com.amaze.filemanager.utils.PreferenceUtils.DEFAULT_CURRENT_TAB;
  import static com.amaze.filemanager.utils.PreferenceUtils.DEFAULT_SAVED_PATHS;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import com.amaze.filemanager.R;
  import com.amaze.filemanager.database.TabHandler;
  import com.amaze.filemanager.database.models.explorer.Tab;
  import com.amaze.filemanager.file_operations.filesystem.OpenMode;
  import com.amaze.filemanager.ui.ColorCircleDrawable;
  import com.amaze.filemanager.ui.activities.MainActivity;
  import com.amaze.filemanager.ui.colors.UserColorPreferences;
  import com.amaze.filemanager.ui.drag.TabFragmentSideDragListener;
  import com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants;
  import com.amaze.filemanager.ui.views.DisablableViewPager;
  import com.amaze.filemanager.ui.views.Indicator;
  import com.amaze.filemanager.utils.DataUtils;
  import com.amaze.filemanager.utils.MainActivityHelper;
  import com.amaze.filemanager.utils.Utils;
  
  import android.animation.ArgbEvaluator;
  import android.content.SharedPreferences;
  import android.graphics.Color;
  import android.graphics.drawable.ColorDrawable;
  import android.os.Build;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.animation.DecelerateInterpolator;
  import android.widget.ImageView;
  
  import androidx.annotation.ColorInt;
  import androidx.annotation.NonNull;
  import androidx.constraintlayout.widget.ConstraintLayout;
  import androidx.fragment.app.Fragment;
  import androidx.fragment.app.FragmentManager;
  import androidx.fragment.app.FragmentStatePagerAdapter;
  import androidx.preference.PreferenceManager;
  import androidx.viewpager.widget.ViewPager;
  
  public class TabFragment extends Fragment implements ViewPager.OnPageChangeListener {
    private static final String TAG = TabFragment.class.getSimpleName();
  
    private static final String KEY_PATH = "path";
    private static final String KEY_POSITION = "pos";
  
    private static final String KEY_FRAGMENT_0 = "tab0";
    private static final String KEY_FRAGMENT_1 = "tab1";
  
    private boolean savePaths;
    private FragmentManager fragmentManager;
  
    private final List<Fragment> fragments = new ArrayList<>();
    private ScreenSlidePagerAdapter sectionsPagerAdapter;
    private DisablableViewPager viewPager;
    private SharedPreferences sharedPrefs;
    private String path;
  
    /** ink indicators for viewpager only for Lollipop+ */
    private Indicator indicator;
  
    /** views for circlular drawables below android lollipop */
    private ImageView circleDrawable1, circleDrawable2;
  
    /** color drawable for action bar background */
    private final ColorDrawable colorDrawable = new ColorDrawable();
  
    /** colors relative to current visible tab */
    private @ColorInt int startColor, endColor;
  
    private ViewGroup rootView;
  
    private final ArgbEvaluator evaluator = new ArgbEvaluator();
    private ConstraintLayout dragPlaceholder;
  
    @Override
    public View onCreateView(
        LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      rootView = (ViewGroup) inflater.inflate(R.layout.tabfragment, container, false);
  
      fragmentManager = requireActivity().getSupportFragmentManager();
      dragPlaceholder = rootView.findViewById(R.id.drag_placeholder);
  
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        indicator = requireActivity().findViewById(R.id.indicator);
      } else {
        circleDrawable1 = requireActivity().findViewById(R.id.tab_indicator1);
        circleDrawable2 = requireActivity().findViewById(R.id.tab_indicator2);
      }
  
      sharedPrefs = PreferenceManager.getDefaultSharedPreferences(requireActivity());
      savePaths = sharedPrefs.getBoolean(PREFERENCE_SAVED_PATHS, DEFAULT_SAVED_PATHS);
  
      viewPager = rootView.findViewById(R.id.pager);
  
      if (getArguments() != null) {
        path = getArguments().getString(KEY_PATH);
      }
  
      requireMainActivity().supportInvalidateOptionsMenu();
      viewPager.addOnPageChangeListener(this);
  
      sectionsPagerAdapter = new ScreenSlidePagerAdapter(fragmentManager);
      if (savedInstanceState == null) {
        int lastOpenTab = sharedPrefs.getInt(PREFERENCE_CURRENT_TAB, DEFAULT_CURRENT_TAB);
        MainActivity.currentTab = lastOpenTab;
  
        refactorDrawerStorages(true);
  
        viewPager.setAdapter(sectionsPagerAdapter);
  
        try {
          viewPager.setCurrentItem(lastOpenTab, true);
          if (circleDrawable1 != null && circleDrawable2 != null) {
            updateIndicator(viewPager.getCurrentItem());
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      } else {
        fragments.clear();
        try {
          fragments.add(0, fragmentManager.getFragment(savedInstanceState, KEY_FRAGMENT_0));
          fragments.add(1, fragmentManager.getFragment(savedInstanceState, KEY_FRAGMENT_1));
        } catch (Exception e) {
          e.printStackTrace();
        }
  
        sectionsPagerAdapter = new ScreenSlidePagerAdapter(fragmentManager);
  
        viewPager.setAdapter(sectionsPagerAdapter);
        int pos1 = savedInstanceState.getInt(KEY_POSITION, 0);
        MainActivity.currentTab = pos1;
        viewPager.setCurrentItem(pos1);
        sectionsPagerAdapter.notifyDataSetChanged();
      }
  
      if (indicator != null) indicator.setViewPager(viewPager);
  
      UserColorPreferences userColorPreferences = requireMainActivity().getCurrentColorPreference();
  
      // color of viewpager when current tab is 0
      startColor = userColorPreferences.getPrimaryFirstTab();
      // color of viewpager when current tab is 1
      endColor = userColorPreferences.getPrimarySecondTab();
  
      /*
       TODO
      //update the views as there is any change in {@link MainActivity#currentTab}
      //probably due to config change
      colorDrawable.setColor(Color.parseColor(MainActivity.currentTab==1 ?
              ThemedActivity.skinTwo : ThemedActivity.skin));
      mainActivity.updateViews(colorDrawable);
      */
  
      return rootView;
    }
  
    @Override
    public void onDestroyView() {
      indicator = null; // Free the strong reference
      sharedPrefs.edit().putInt(PREFERENCE_CURRENT_TAB, MainActivity.currentTab).apply();
      super.onDestroyView();
    }
  
    public void updatePaths(int pos) {
      // Getting old path from database before clearing
      TabHandler tabHandler = TabHandler.getInstance();
  
      int i = 1;
      for (Fragment fragment : fragments) {
        if (fragment instanceof MainFragment) {
          MainFragment mainFragment = (MainFragment) fragment;
          if (mainFragment.getMainFragmentViewModel() != null
              && i - 1 == MainActivity.currentTab
              && i == pos) {
            updateBottomBar(mainFragment);
            requireMainActivity()
                .getDrawer()
                .selectCorrectDrawerItemForPath(mainFragment.getCurrentPath());
            if (mainFragment.getMainFragmentViewModel().getOpenMode() == OpenMode.FILE) {
              tabHandler.update(
                  new Tab(
                      i,
                      mainFragment.getCurrentPath(),
                      mainFragment.getMainFragmentViewModel().getHome()));
            } else {
              tabHandler.update(
                  new Tab(
                      i,
                      mainFragment.getMainFragmentViewModel().getHome(),
                      mainFragment.getMainFragmentViewModel().getHome()));
            }
          }
          i++;
        }
      }
    }
  
    @Override
    public void onSaveInstanceState(@NonNull Bundle outState) {
      super.onSaveInstanceState(outState);
  
      if (sharedPrefs != null) {
        sharedPrefs.edit().putInt(PREFERENCE_CURRENT_TAB, MainActivity.currentTab).apply();
      }
  
      if (fragments.size() != 0) {
        if (fragmentManager == null) {
          return;
        }
  
        fragmentManager.executePendingTransactions();
        fragmentManager.putFragment(outState, KEY_FRAGMENT_0, fragments.get(0));
        fragmentManager.putFragment(outState, KEY_FRAGMENT_1, fragments.get(1));
        outState.putInt(KEY_POSITION, viewPager.getCurrentItem());
      }
    }
  
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
      final MainFragment mainFragment = requireMainActivity().getCurrentMainFragment();
      if (mainFragment == null
          || mainFragment.getMainFragmentViewModel() == null
          || mainFragment.getMainActivity().getListItemSelected()) {
        return; // we do not want to update toolbar colors when ActionMode is activated
      }
  
      // during the config change
      @ColorInt int color = (int) evaluator.evaluate(position + positionOffset, startColor, endColor);
  
      colorDrawable.setColor(color);
      requireMainActivity().updateViews(colorDrawable);
    }
  
    @Override
    public void onPageSelected(int p1) {
      requireMainActivity()
          .getAppbar()
          .getAppbarLayout()
          .animate()
          .translationY(0)
          .setInterpolator(new DecelerateInterpolator(2))
          .start();
  
      MainActivity.currentTab = p1;
  
      if (sharedPrefs != null) {
        sharedPrefs.edit().putInt(PREFERENCE_CURRENT_TAB, MainActivity.currentTab).apply();
      }
  
      Fragment fragment = fragments.get(p1);
      if (fragment instanceof MainFragment) {
        MainFragment ma = (MainFragment) fragment;
        if (ma.getCurrentPath() != null) {
          requireMainActivity().getDrawer().selectCorrectDrawerItemForPath(ma.getCurrentPath());
          updateBottomBar(ma);
        }
      }
  
      if (circleDrawable1 != null && circleDrawable2 != null) updateIndicator(p1);
    }
  
    @Override
    public void onPageScrollStateChanged(int state) {
      // nothing to do
    }
  
    public void setPagingEnabled(boolean isPaging) {
      viewPager.setPagingEnabled(isPaging);
    }
  
    public void setCurrentItem(int index) {
      viewPager.setCurrentItem(index);
    }
  
    private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
      public ScreenSlidePagerAdapter(FragmentManager fm) {
        super(fm);
      }
  
      @Override
      public int getItemPosition(@NonNull Object object) {
        int index = fragments.indexOf(object);
        if (index == -1) return POSITION_NONE;
        else return index;
      }
  
      public int getCount() {
        return fragments.size();
      }
  
      @NonNull
      @Override
      public Fragment getItem(int position) {
        Fragment f;
        f = fragments.get(position);
        return f;
      }
    }
  
    private void addNewTab(int num, String path) {
      addTab(new Tab(num, path, path), "");
    }
  
    /**
     * Fetches new storage paths from drawer and apply to tabs This method will just create tabs in UI
     * change paths in database. Calls should implement updating each tab's list for new paths.
     *
     * @param addTab whether new tabs should be added to ui or just change values in database
     */
    public void refactorDrawerStorages(boolean addTab) {
      TabHandler tabHandler = TabHandler.getInstance();
      Tab tab1 = tabHandler.findTab(1);
      Tab tab2 = tabHandler.findTab(2);
      Tab[] tabs = tabHandler.getAllTabs();
      String firstTabPath = requireMainActivity().getDrawer().getFirstPath();
      String secondTabPath = requireMainActivity().getDrawer().getSecondPath();
  
      if (tabs == null || tabs.length < 1 || tab1 == null || tab2 == null) {
        // creating tabs in db for the first time, probably the first launch of
        // app, or something got corrupted
        String currentFirstTab = Utils.isNullOrEmpty(firstTabPath) ? "/" : firstTabPath;
        String currentSecondTab = Utils.isNullOrEmpty(secondTabPath) ? firstTabPath : secondTabPath;
        if (addTab) {
          addNewTab(1, currentSecondTab);
          addNewTab(2, currentFirstTab);
        }
        tabHandler.addTab(new Tab(1, currentSecondTab, currentSecondTab)).blockingAwait();
        tabHandler.addTab(new Tab(2, currentFirstTab, currentFirstTab)).blockingAwait();
  
        if (currentFirstTab.equalsIgnoreCase("/")) {
          sharedPrefs.edit().putBoolean(PreferencesConstants.PREFERENCE_ROOTMODE, true).apply();
        }
      } else {
  