Search in sources :

Example 1 with MainFragmentViewModel

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

the class MainFragment method loadlist.

/**
 * This loads a path into the MainFragment.
 *
 * @param providedPath the path to be loaded
 * @param back if we're coming back from any directory and want the scroll to be restored
 * @param providedOpenMode the mode in which the directory should be opened
 */
public void loadlist(final String providedPath, final boolean back, final OpenMode providedOpenMode) {
    if (mainFragmentViewModel == null) {
        Log.w(getClass().getSimpleName(), "Viewmodel not available to load the data");
        return;
    }
    if (getMainActivity() != null && getMainActivity().getActionModeHelper() != null && getMainActivity().getActionModeHelper().getActionMode() != null) {
        getMainActivity().getActionModeHelper().getActionMode().finish();
    }
    mSwipeRefreshLayout.setRefreshing(true);
    if (loadFilesListTask != null && loadFilesListTask.getStatus() == AsyncTask.Status.RUNNING) {
        Log.w(getClass().getSimpleName(), "Existing load list task running, cancel current");
        loadFilesListTask.cancel(true);
    }
    OpenMode openMode = providedOpenMode;
    String actualPath = FileProperties.remapPathForApi30OrAbove(providedPath, false);
    if (!providedPath.equals(actualPath) && SDK_INT >= Q) {
        openMode = loadPathInQ(actualPath, providedPath, providedOpenMode);
    } else // OpenMode.DOCUMENT_FILE
    if (actualPath.startsWith("/") && OpenMode.DOCUMENT_FILE.equals(openMode)) {
        openMode = OpenMode.FILE;
    }
    loadFilesListTask = new LoadFilesListTask(getActivity(), actualPath, this, openMode, getBoolean(PREFERENCE_SHOW_THUMB), getBoolean(PREFERENCE_SHOW_HIDDENFILES), (data) -> {
        mSwipeRefreshLayout.setRefreshing(false);
        if (data != null && data.second != null) {
            boolean isPathLayoutGrid = DataUtils.getInstance().getListOrGridForPath(providedPath, DataUtils.LIST) == DataUtils.GRID;
            setListElements(data.second, back, providedPath, data.first, false, isPathLayoutGrid);
        } else {
            Log.w(getClass().getSimpleName(), "Load list operation cancelled");
        }
    });
    loadFilesListTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) ImageView(android.widget.ImageView) SDK_INT(android.os.Build.VERSION.SDK_INT) ShortcutManagerCompat(androidx.core.content.pm.ShortcutManagerCompat) Fragment(androidx.fragment.app.Fragment) Log(android.util.Log) CustomScrollGridLayoutManager(com.amaze.filemanager.ui.views.CustomScrollGridLayoutManager) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) DividerItemDecoration(com.amaze.filemanager.ui.views.DividerItemDecoration) GeneralDialogCreation(com.amaze.filemanager.ui.dialogs.GeneralDialogCreation) Q(android.os.Build.VERSION_CODES.Q) IntentFilter(android.content.IntentFilter) Streamer(com.amaze.filemanager.file_operations.filesystem.smbstreamer.Streamer) FileUtils(com.amaze.filemanager.filesystem.files.FileUtils) EncryptDecryptUtils(com.amaze.filemanager.filesystem.files.EncryptDecryptUtils) MainFragmentViewModel(com.amaze.filemanager.ui.fragments.data.MainFragmentViewModel) JELLY_BEAN_MR2(android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) Nullable(androidx.annotation.Nullable) ActivityResultContracts(androidx.activity.result.contract.ActivityResultContracts) R(com.amaze.filemanager.R) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) AppTheme(com.amaze.filemanager.ui.theme.AppTheme) AppConfig(com.amaze.filemanager.application.AppConfig) Environment(android.os.Environment) CustomScrollLinearLayoutManager(com.amaze.filemanager.ui.views.CustomScrollLinearLayoutManager) CloudUtil(com.amaze.filemanager.filesystem.cloud.CloudUtil) ArrayList(java.util.ArrayList) MainActivityHelper(com.amaze.filemanager.utils.MainActivityHelper) SshClientUtils(com.amaze.filemanager.filesystem.ssh.SshClientUtils) DataUtils(com.amaze.filemanager.utils.DataUtils) Toast(android.widget.Toast) Formatter(android.text.format.Formatter) DeleteTask(com.amaze.filemanager.asynchronous.asynctasks.DeleteTask) FragmentManager(androidx.fragment.app.FragmentManager) ViewModelProvider(androidx.lifecycle.ViewModelProvider) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) TextUtils(android.text.TextUtils) File(java.io.File) Utils(com.amaze.filemanager.utils.Utils) SharedPreferences(android.content.SharedPreferences) SmbFile(jcifs.smb.SmbFile) IconCompat(androidx.core.graphics.drawable.IconCompat) CryptUtil(com.amaze.filemanager.filesystem.files.CryptUtil) RingtoneManager(android.media.RingtoneManager) PreferenceManager(androidx.preference.PreferenceManager) DocumentsContract(android.provider.DocumentsContract) PREFERENCE_SHOW_GOBACK_BUTTON(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_GOBACK_BUTTON) EditText(android.widget.EditText) TabFragmentBottomDragListener(com.amaze.filemanager.ui.drag.TabFragmentBottomDragListener) RequiresApi(androidx.annotation.RequiresApi) JELLY_BEAN(android.os.Build.VERSION_CODES.JELLY_BEAN) PackageManager(android.content.pm.PackageManager) SmbException(jcifs.smb.SmbException) FileProperties(com.amaze.filemanager.filesystem.FileProperties) MainActivity(com.amaze.filemanager.ui.activities.MainActivity) AppBarLayout(com.google.android.material.appbar.AppBarLayout) SortHandler(com.amaze.filemanager.database.SortHandler) RecyclerAdapter(com.amaze.filemanager.adapters.RecyclerAdapter) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) BottomBarButtonPath(com.amaze.filemanager.utils.BottomBarButtonPath) FileHandler(com.amaze.filemanager.asynchronous.handlers.FileHandler) Tab(com.amaze.filemanager.database.models.explorer.Tab) SSH_URI_PREFIX(com.amaze.filemanager.filesystem.ssh.SshConnectionPool.SSH_URI_PREFIX) LoadFilesListTask(com.amaze.filemanager.asynchronous.asynctasks.LoadFilesListTask) OTGUtil(com.amaze.filemanager.utils.OTGUtil) AsyncTask(android.os.AsyncTask) ItemViewHolder(com.amaze.filemanager.adapters.holders.ItemViewHolder) BroadcastReceiver(android.content.BroadcastReceiver) RecyclerAdapterDragListener(com.amaze.filemanager.ui.drag.RecyclerAdapterDragListener) ViewGroup(android.view.ViewGroup) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) PREFERENCE_SHOW_HIDDENFILES(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_HIDDENFILES) List(java.util.List) TextView(android.widget.TextView) CustomFileObserver(com.amaze.filemanager.filesystem.CustomFileObserver) ActivityNotFoundException(android.content.ActivityNotFoundException) MimeTypes(com.amaze.filemanager.ui.icons.MimeTypes) UtilitiesProvider(com.amaze.filemanager.ui.provider.UtilitiesProvider) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) FastScroller(com.amaze.filemanager.ui.views.FastScroller) Context(android.content.Context) PREFERENCE_SHOW_DIVIDERS(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_DIVIDERS) KeyEvent(android.view.KeyEvent) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) UriPermission(android.content.UriPermission) HybridFile(com.amaze.filemanager.filesystem.HybridFile) HashMap(java.util.HashMap) Intent(android.content.Intent) OpenMode(com.amaze.filemanager.file_operations.filesystem.OpenMode) FragmentActivity(androidx.fragment.app.FragmentActivity) PREFERENCE_SHOW_THUMB(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_THUMB) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) FileListSorter(com.amaze.filemanager.filesystem.files.FileListSorter) ActivityResultLauncher(androidx.activity.result.ActivityResultLauncher) LayoutInflater(android.view.LayoutInflater) DialogAction(com.afollestad.materialdialogs.DialogAction) SafRootHolder(com.amaze.filemanager.filesystem.SafRootHolder) WarnableTextInputValidator(com.amaze.filemanager.ui.views.WarnableTextInputValidator) ResolveInfo(android.content.pm.ResolveInfo) Color(android.graphics.Color) ViewTreeObserver(android.view.ViewTreeObserver) Collections(java.util.Collections) Activity(android.app.Activity) Resources(android.content.res.Resources) LoadFilesListTask(com.amaze.filemanager.asynchronous.asynctasks.LoadFilesListTask) OpenMode(com.amaze.filemanager.file_operations.filesystem.OpenMode)

Example 2 with MainFragmentViewModel

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

the class MainFragment method onViewCreated.

@Override
@SuppressWarnings("PMD.NPathComplexity")
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mainFragmentViewModel = new ViewModelProvider(this).get(MainFragmentViewModel.class);
    listView = rootView.findViewById(R.id.listView);
    mToolbarContainer = getMainActivity().getAppbar().getAppbarLayout();
    fastScroller = rootView.findViewById(R.id.fastscroll);
    fastScroller.setPressedHandleColor(mainFragmentViewModel.getAccentColor());
    View.OnTouchListener onTouchListener = (view1, motionEvent) -> {
        if (adapter != null && mainFragmentViewModel.getStopAnims()) {
            stopAnimation();
            mainFragmentViewModel.setStopAnims(false);
        }
        return false;
    };
    listView.setOnTouchListener(onTouchListener);
    // listView.setOnDragListener(new MainFragmentDragListener());
    mToolbarContainer.setOnTouchListener(onTouchListener);
    mSwipeRefreshLayout = rootView.findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setOnRefreshListener(() -> loadlist((mainFragmentViewModel.getCurrentPath()), false, mainFragmentViewModel.getOpenMode()));
    // String itemsstring = res.getString(R.string.items);// TODO: 23/5/2017 use or delete
    mToolbarContainer.setBackgroundColor(MainActivity.currentTab == 1 ? mainFragmentViewModel.getPrimaryTwoColor() : mainFragmentViewModel.getPrimaryColor());
    // listView.setPadding(listView.getPaddingLeft(), paddingTop, listView.getPaddingRight(),
    // listView.getPaddingBottom());
    setHasOptionsMenu(false);
    initNoFileLayout();
    HybridFile f = new HybridFile(OpenMode.UNKNOWN, mainFragmentViewModel.getCurrentPath());
    f.generateMode(getActivity());
    getMainActivity().getAppbar().getBottomBar().setClickListener();
    if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT) && !mainFragmentViewModel.isList()) {
        listView.setBackgroundColor(Utils.getColor(getContext(), R.color.grid_background_light));
    } else {
        listView.setBackgroundDrawable(null);
    }
    listView.setHasFixedSize(true);
    if (mainFragmentViewModel.isList()) {
        mLayoutManager = new CustomScrollLinearLayoutManager(getContext());
        listView.setLayoutManager(mLayoutManager);
    } else {
        if (mainFragmentViewModel.getColumns() == -1 || mainFragmentViewModel.getColumns() == 0)
            mLayoutManagerGrid = new CustomScrollGridLayoutManager(getActivity(), 3);
        else
            mLayoutManagerGrid = new CustomScrollGridLayoutManager(getActivity(), mainFragmentViewModel.getColumns());
        setGridLayoutSpanSizeLookup(mLayoutManagerGrid);
        listView.setLayoutManager(mLayoutManagerGrid);
    }
    // use a linear layout manager
    // View footerView = getActivity().getLayoutInflater().inflate(R.layout.divider, null);// TODO:
    // 23/5/2017 use or delete
    dividerItemDecoration = new DividerItemDecoration(getActivity(), false, getBoolean(PREFERENCE_SHOW_DIVIDERS));
    listView.addItemDecoration(dividerItemDecoration);
    mSwipeRefreshLayout.setColorSchemeColors(mainFragmentViewModel.getAccentColor());
    DefaultItemAnimator animator = new DefaultItemAnimator();
    listView.setItemAnimator(animator);
    mToolbarContainer.getViewTreeObserver().addOnGlobalLayoutListener(this);
    loadViews();
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) ImageView(android.widget.ImageView) SDK_INT(android.os.Build.VERSION.SDK_INT) ShortcutManagerCompat(androidx.core.content.pm.ShortcutManagerCompat) Fragment(androidx.fragment.app.Fragment) Log(android.util.Log) CustomScrollGridLayoutManager(com.amaze.filemanager.ui.views.CustomScrollGridLayoutManager) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) DividerItemDecoration(com.amaze.filemanager.ui.views.DividerItemDecoration) GeneralDialogCreation(com.amaze.filemanager.ui.dialogs.GeneralDialogCreation) Q(android.os.Build.VERSION_CODES.Q) IntentFilter(android.content.IntentFilter) Streamer(com.amaze.filemanager.file_operations.filesystem.smbstreamer.Streamer) FileUtils(com.amaze.filemanager.filesystem.files.FileUtils) EncryptDecryptUtils(com.amaze.filemanager.filesystem.files.EncryptDecryptUtils) MainFragmentViewModel(com.amaze.filemanager.ui.fragments.data.MainFragmentViewModel) JELLY_BEAN_MR2(android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) Nullable(androidx.annotation.Nullable) ActivityResultContracts(androidx.activity.result.contract.ActivityResultContracts) R(com.amaze.filemanager.R) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) AppTheme(com.amaze.filemanager.ui.theme.AppTheme) AppConfig(com.amaze.filemanager.application.AppConfig) Environment(android.os.Environment) CustomScrollLinearLayoutManager(com.amaze.filemanager.ui.views.CustomScrollLinearLayoutManager) CloudUtil(com.amaze.filemanager.filesystem.cloud.CloudUtil) ArrayList(java.util.ArrayList) MainActivityHelper(com.amaze.filemanager.utils.MainActivityHelper) SshClientUtils(com.amaze.filemanager.filesystem.ssh.SshClientUtils) DataUtils(com.amaze.filemanager.utils.DataUtils) Toast(android.widget.Toast) Formatter(android.text.format.Formatter) DeleteTask(com.amaze.filemanager.asynchronous.asynctasks.DeleteTask) FragmentManager(androidx.fragment.app.FragmentManager) ViewModelProvider(androidx.lifecycle.ViewModelProvider) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) TextUtils(android.text.TextUtils) File(java.io.File) Utils(com.amaze.filemanager.utils.Utils) SharedPreferences(android.content.SharedPreferences) SmbFile(jcifs.smb.SmbFile) IconCompat(androidx.core.graphics.drawable.IconCompat) CryptUtil(com.amaze.filemanager.filesystem.files.CryptUtil) RingtoneManager(android.media.RingtoneManager) PreferenceManager(androidx.preference.PreferenceManager) DocumentsContract(android.provider.DocumentsContract) PREFERENCE_SHOW_GOBACK_BUTTON(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_GOBACK_BUTTON) EditText(android.widget.EditText) TabFragmentBottomDragListener(com.amaze.filemanager.ui.drag.TabFragmentBottomDragListener) RequiresApi(androidx.annotation.RequiresApi) JELLY_BEAN(android.os.Build.VERSION_CODES.JELLY_BEAN) PackageManager(android.content.pm.PackageManager) SmbException(jcifs.smb.SmbException) FileProperties(com.amaze.filemanager.filesystem.FileProperties) MainActivity(com.amaze.filemanager.ui.activities.MainActivity) AppBarLayout(com.google.android.material.appbar.AppBarLayout) SortHandler(com.amaze.filemanager.database.SortHandler) RecyclerAdapter(com.amaze.filemanager.adapters.RecyclerAdapter) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) BottomBarButtonPath(com.amaze.filemanager.utils.BottomBarButtonPath) FileHandler(com.amaze.filemanager.asynchronous.handlers.FileHandler) Tab(com.amaze.filemanager.database.models.explorer.Tab) SSH_URI_PREFIX(com.amaze.filemanager.filesystem.ssh.SshConnectionPool.SSH_URI_PREFIX) LoadFilesListTask(com.amaze.filemanager.asynchronous.asynctasks.LoadFilesListTask) OTGUtil(com.amaze.filemanager.utils.OTGUtil) AsyncTask(android.os.AsyncTask) ItemViewHolder(com.amaze.filemanager.adapters.holders.ItemViewHolder) BroadcastReceiver(android.content.BroadcastReceiver) RecyclerAdapterDragListener(com.amaze.filemanager.ui.drag.RecyclerAdapterDragListener) ViewGroup(android.view.ViewGroup) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) PREFERENCE_SHOW_HIDDENFILES(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_HIDDENFILES) List(java.util.List) TextView(android.widget.TextView) CustomFileObserver(com.amaze.filemanager.filesystem.CustomFileObserver) ActivityNotFoundException(android.content.ActivityNotFoundException) MimeTypes(com.amaze.filemanager.ui.icons.MimeTypes) UtilitiesProvider(com.amaze.filemanager.ui.provider.UtilitiesProvider) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) FastScroller(com.amaze.filemanager.ui.views.FastScroller) Context(android.content.Context) PREFERENCE_SHOW_DIVIDERS(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_DIVIDERS) KeyEvent(android.view.KeyEvent) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) UriPermission(android.content.UriPermission) HybridFile(com.amaze.filemanager.filesystem.HybridFile) HashMap(java.util.HashMap) Intent(android.content.Intent) OpenMode(com.amaze.filemanager.file_operations.filesystem.OpenMode) FragmentActivity(androidx.fragment.app.FragmentActivity) PREFERENCE_SHOW_THUMB(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_THUMB) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) FileListSorter(com.amaze.filemanager.filesystem.files.FileListSorter) ActivityResultLauncher(androidx.activity.result.ActivityResultLauncher) LayoutInflater(android.view.LayoutInflater) DialogAction(com.afollestad.materialdialogs.DialogAction) SafRootHolder(com.amaze.filemanager.filesystem.SafRootHolder) WarnableTextInputValidator(com.amaze.filemanager.ui.views.WarnableTextInputValidator) ResolveInfo(android.content.pm.ResolveInfo) Color(android.graphics.Color) ViewTreeObserver(android.view.ViewTreeObserver) Collections(java.util.Collections) Activity(android.app.Activity) Resources(android.content.res.Resources) HybridFile(com.amaze.filemanager.filesystem.HybridFile) MainFragmentViewModel(com.amaze.filemanager.ui.fragments.data.MainFragmentViewModel) CustomScrollGridLayoutManager(com.amaze.filemanager.ui.views.CustomScrollGridLayoutManager) CustomScrollLinearLayoutManager(com.amaze.filemanager.ui.views.CustomScrollLinearLayoutManager) DividerItemDecoration(com.amaze.filemanager.ui.views.DividerItemDecoration) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 3 with MainFragmentViewModel

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

the class LoadFilesListTask method doInBackground.

@Override
@Nullable
protected Pair<OpenMode, ArrayList<LayoutElementParcelable>> doInBackground(Void... p) {
    final MainFragment mainFragment = this.mainFragmentReference.get();
    final Context context = this.context.get();
    if (mainFragment == null || context == null || mainFragment.getMainFragmentViewModel() == null) {
        cancel(true);
        return null;
    }
    HybridFile hFile = null;
    if (OpenMode.UNKNOWN.equals(openmode) || OpenMode.CUSTOM.equals(openmode)) {
        hFile = new HybridFile(openmode, path);
        hFile.generateMode(mainFragment.getActivity());
        openmode = hFile.getMode();
        if (hFile.isSmb()) {
            mainFragment.getMainFragmentViewModel().setSmbPath(path);
        }
    }
    if (isCancelled())
        return null;
    mainFragment.getMainFragmentViewModel().setFolderCount(0);
    mainFragment.getMainFragmentViewModel().setFileCount(0);
    final ArrayList<LayoutElementParcelable> list;
    switch(openmode) {
        case SMB:
            if (hFile == null) {
                hFile = new HybridFile(OpenMode.SMB, path);
            }
            if (!hFile.getPath().endsWith("/")) {
                hFile.setPath(hFile.getPath() + "/");
            }
            try {
                SmbFile[] smbFile = hFile.getSmbFile(5000).listFiles();
                list = mainFragment.addToSmb(smbFile, path, showHiddenFiles);
                openmode = OpenMode.SMB;
            } catch (SmbAuthException e) {
                if (!e.getMessage().toLowerCase().contains("denied")) {
                    mainFragment.reauthenticateSmb();
                }
                e.printStackTrace();
                return null;
            } catch (SmbException | NullPointerException e) {
                Log.w(getClass().getSimpleName(), "Failed to load smb files for path: " + path, e);
                mainFragment.reauthenticateSmb();
                return null;
            }
            break;
        case SFTP:
            HybridFile sftpHFile = new HybridFile(OpenMode.SFTP, path);
            list = new ArrayList();
            sftpHFile.forEachChildrenFile(context, false, file -> {
                if (!(dataUtils.isFileHidden(file.getPath()) || file.isHidden() && !showHiddenFiles)) {
                    LayoutElementParcelable elem = createListParcelables(file);
                    if (elem != null) {
                        list.add(elem);
                    }
                }
            });
            break;
        case CUSTOM:
            switch(Integer.parseInt(path)) {
                case 0:
                    list = listImages();
                    break;
                case 1:
                    list = listVideos();
                    break;
                case 2:
                    list = listaudio();
                    break;
                case 3:
                    list = listDocs();
                    break;
                case 4:
                    list = listApks();
                    break;
                case 5:
                    list = listRecent();
                    break;
                case 6:
                    list = listRecentFiles();
                    break;
                default:
                    throw new IllegalStateException();
            }
            break;
        case OTG:
            list = new ArrayList<>();
            listOtg(path, file -> {
                LayoutElementParcelable elem = createListParcelables(file);
                if (elem != null)
                    list.add(elem);
            });
            openmode = OpenMode.OTG;
            break;
        case DOCUMENT_FILE:
            list = new ArrayList<>();
            listDocumentFiles(file -> {
                LayoutElementParcelable elem = createListParcelables(file);
                if (elem != null)
                    list.add(elem);
            });
            openmode = OpenMode.DOCUMENT_FILE;
            break;
        case DROPBOX:
        case BOX:
        case GDRIVE:
        case ONEDRIVE:
            CloudStorage cloudStorage = dataUtils.getAccount(openmode);
            list = new ArrayList<>();
            try {
                listCloud(path, cloudStorage, openmode, file -> {
                    LayoutElementParcelable elem = createListParcelables(file);
                    if (elem != null)
                        list.add(elem);
                });
            } catch (CloudPluginException e) {
                e.printStackTrace();
                AppConfig.toast(context, context.getResources().getString(R.string.failed_no_connection));
                return new Pair<>(openmode, list);
            }
            break;
        default:
            // we're neither in OTG not in SMB, load the list based on root/general filesystem
            list = new ArrayList<>();
            final OpenMode[] currentOpenMode = new OpenMode[1];
            ListFilesCommand.INSTANCE.listFiles(path, mainFragment.getMainActivity().isRootExplorer(), showHiddenFiles, mode -> {
                currentOpenMode[0] = mode;
                return null;
            }, hybridFileParcelable -> {
                LayoutElementParcelable elem = createListParcelables(hybridFileParcelable);
                if (elem != null)
                    list.add(elem);
                return null;
            });
            if (null != currentOpenMode[0]) {
                openmode = currentOpenMode[0];
            }
            break;
    }
    if (list != null && !(openmode == OpenMode.CUSTOM && ((path).equals("5") || (path).equals("6")))) {
        int t = SortHandler.getSortType(context, path);
        int sortby;
        int asc;
        if (t <= 3) {
            sortby = t;
            asc = 1;
        } else {
            asc = -1;
            sortby = t - 4;
        }
        MainFragmentViewModel viewModel = mainFragment.getMainFragmentViewModel();
        if (viewModel != null) {
            Collections.sort(list, new FileListSorter(viewModel.getDsort(), sortby, asc));
        } else {
            Log.e(TAG, "MainFragmentViewModel is null, this is a bug");
        }
    }
    return new Pair<>(openmode, list);
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) OpenMode(com.amaze.filemanager.file_operations.filesystem.OpenMode) SmbFile(jcifs.smb.SmbFile) SmbException(jcifs.smb.SmbException) CloudStorage(com.cloudrail.si.interfaces.CloudStorage) HybridFile(com.amaze.filemanager.filesystem.HybridFile) CloudPluginException(com.amaze.filemanager.file_operations.exceptions.CloudPluginException) MainFragment(com.amaze.filemanager.ui.fragments.MainFragment) SmbAuthException(jcifs.smb.SmbAuthException) MainFragmentViewModel(com.amaze.filemanager.ui.fragments.data.MainFragmentViewModel) FileListSorter(com.amaze.filemanager.filesystem.files.FileListSorter) Pair(androidx.core.util.Pair) Nullable(androidx.annotation.Nullable)

Aggregations

Context (android.content.Context)3 Nullable (androidx.annotation.Nullable)3 LayoutElementParcelable (com.amaze.filemanager.adapters.data.LayoutElementParcelable)3 OpenMode (com.amaze.filemanager.file_operations.filesystem.OpenMode)3 HybridFile (com.amaze.filemanager.filesystem.HybridFile)3 FileListSorter (com.amaze.filemanager.filesystem.files.FileListSorter)3 MainFragmentViewModel (com.amaze.filemanager.ui.fragments.data.MainFragmentViewModel)3 ArrayList (java.util.ArrayList)3 SmbException (jcifs.smb.SmbException)3 SmbFile (jcifs.smb.SmbFile)3 Activity (android.app.Activity)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 BroadcastReceiver (android.content.BroadcastReceiver)2 Intent (android.content.Intent)2 IntentFilter (android.content.IntentFilter)2 SharedPreferences (android.content.SharedPreferences)2 UriPermission (android.content.UriPermission)2 PackageManager (android.content.pm.PackageManager)2 ResolveInfo (android.content.pm.ResolveInfo)2 Resources (android.content.res.Resources)2