Search in sources :

Example 1 with SearchWorkerFragment

use of com.amaze.filemanager.ui.fragments.SearchWorkerFragment in project AmazeFileManager by TeamAmaze.

the class MainActivityHelper method search.

/**
 * Creates a fragment which will handle the search AsyncTask {@link SearchWorkerFragment}
 *
 * @param query the text query entered the by user
 */
public void search(SharedPreferences sharedPrefs, String query) {
    TabFragment tabFragment = mainActivity.getTabFragment();
    if (tabFragment == null) {
        Log.w(getClass().getSimpleName(), "Failed to search: tab fragment not available");
        return;
    }
    final MainFragment ma = (MainFragment) tabFragment.getCurrentTabFragment();
    if (ma == null || ma.getMainFragmentViewModel() == null) {
        Log.w(getClass().getSimpleName(), "Failed to search: main fragment not available");
        return;
    }
    final String fpath = ma.getCurrentPath();
    /*SearchTask task = new SearchTask(ma.searchHelper, ma, query);
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, fpath);*/
    // ma.searchTask = task;
    SEARCH_TEXT = query;
    FragmentManager fm = mainActivity.getSupportFragmentManager();
    SearchWorkerFragment fragment = (SearchWorkerFragment) fm.findFragmentByTag(MainActivity.TAG_ASYNC_HELPER);
    if (fragment != null) {
        if (fragment.searchAsyncTask.getStatus() == AsyncTask.Status.RUNNING) {
            fragment.searchAsyncTask.cancel(true);
        }
        fm.beginTransaction().remove(fragment).commit();
    }
    addSearchFragment(fm, new SearchWorkerFragment(), fpath, query, ma.getMainFragmentViewModel().getOpenMode(), mainActivity.isRootExplorer(), sharedPrefs.getBoolean(SearchWorkerFragment.KEY_REGEX, false), sharedPrefs.getBoolean(SearchWorkerFragment.KEY_REGEX_MATCHES, false));
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) MainFragment(com.amaze.filemanager.ui.fragments.MainFragment) TabFragment(com.amaze.filemanager.ui.fragments.TabFragment) SearchWorkerFragment(com.amaze.filemanager.ui.fragments.SearchWorkerFragment)

Aggregations

FragmentManager (androidx.fragment.app.FragmentManager)1 MainFragment (com.amaze.filemanager.ui.fragments.MainFragment)1 SearchWorkerFragment (com.amaze.filemanager.ui.fragments.SearchWorkerFragment)1 TabFragment (com.amaze.filemanager.ui.fragments.TabFragment)1