Search in sources :

Example 1 with MainFragment

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

the class Drawer method onDrawerClosed.

public void onDrawerClosed() {
    if (pending_fragmentTransaction != null) {
        pending_fragmentTransaction.commit();
        pending_fragmentTransaction = null;
    }
    if (pendingPath != null) {
        HybridFile hFile = new HybridFile(OpenMode.UNKNOWN, pendingPath);
        hFile.generateMode(mainActivity);
        if (hFile.isSimpleFile()) {
            FileUtils.openFile(new File(pendingPath), mainActivity, mainActivity.getPrefs());
            pendingPath = null;
            return;
        }
        MainFragment mainFrag = mainActivity.getCurrentMainFragment();
        if (mainFrag != null) {
            mainFrag.loadlist(pendingPath, false, OpenMode.UNKNOWN);
        } else {
            mainActivity.goToMain(pendingPath);
            return;
        }
        pendingPath = null;
    }
    mainActivity.supportInvalidateOptionsMenu();
}
Also used : HybridFile(com.amaze.filemanager.filesystem.HybridFile) MainFragment(com.amaze.filemanager.fragments.MainFragment) HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File)

Example 2 with MainFragment

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

the class MainActivityHelper method add.

public void add(int pos) {
    final MainFragment ma = (MainFragment) ((TabFragment) mainActivity.getSupportFragmentManager().findFragmentById(R.id.content_frame)).getCurrentTabFragment();
    final String path = ma.getCurrentPath();
    switch(pos) {
        case NEW_FOLDER:
            mkdir(ma.openMode, path, ma);
            break;
        case NEW_FILE:
            mkfile(ma.openMode, path, ma);
            break;
        case NEW_CLOUD:
            BottomSheetDialogFragment fragment = new CloudSheetFragment();
            fragment.show(ma.getActivity().getSupportFragmentManager(), CloudSheetFragment.TAG_FRAGMENT);
            break;
    }
}
Also used : BottomSheetDialogFragment(android.support.design.widget.BottomSheetDialogFragment) CloudSheetFragment(com.amaze.filemanager.fragments.CloudSheetFragment) MainFragment(com.amaze.filemanager.fragments.MainFragment)

Example 3 with MainFragment

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

the class MainActivity method addConnection.

@Override
public void addConnection(boolean edit, final String name, final String path, final String encryptedPath, final String oldname, final String oldPath) {
    String[] s = new String[] { name, path };
    if (!edit) {
        if ((dataUtils.containsServer(path)) == -1) {
            dataUtils.addServer(s);
            drawer.refreshDrawer();
            AppConfig.runInBackground(() -> {
                utilsHandler.addSmb(name, encryptedPath);
            });
            // grid.addPath(name, encryptedPath, DataUtils.SMB, 1);
            MainFragment ma = getCurrentMainFragment();
            if (ma != null)
                getCurrentMainFragment().loadlist(path, false, OpenMode.UNKNOWN);
        } else {
            Snackbar.make(findViewById(R.id.navigation), getString(R.string.connection_exists), Snackbar.LENGTH_SHORT).show();
        }
    } else {
        int i = dataUtils.containsServer(new String[] { oldname, oldPath });
        if (i != -1) {
            dataUtils.removeServer(i);
            AppConfig.runInBackground(() -> {
                utilsHandler.renameSMB(oldname, oldPath, name, path);
            });
        // mainActivity.grid.removePath(oldname, oldPath, DataUtils.SMB);
        }
        dataUtils.addServer(s);
        Collections.sort(dataUtils.getServers(), new BookSorter());
        drawer.refreshDrawer();
    // mainActivity.grid.addPath(name, encryptedPath, DataUtils.SMB, 1);
    }
}
Also used : MainFragment(com.amaze.filemanager.fragments.MainFragment) BookSorter(com.amaze.filemanager.utils.BookSorter)

Example 4 with MainFragment

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

the class MainActivity method onRequestPermissionsResult.

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    if (requestCode == 77) {
        if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            drawer.refreshDrawer();
            TabFragment tabFragment = getTabFragment();
            boolean b = getBoolean(PREFERENCE_NEED_TO_SET_HOME);
            // reset home and current paths according to new storages
            if (b) {
                tabHandler.clear();
                if (drawer.getStorageCount() > 1) {
                    tabHandler.addTab(new Tab(1, drawer.getSecondPath(), "/"));
                } else {
                    tabHandler.addTab(new Tab(1, "/", "/"));
                }
                if (drawer.getFirstPath() != null) {
                    String pa = drawer.getFirstPath();
                    tabHandler.addTab(new Tab(2, pa, pa));
                } else {
                    tabHandler.addTab(new Tab(2, drawer.getSecondPath(), "/"));
                }
                if (tabFragment != null) {
                    Fragment main = tabFragment.getFragmentAtIndex(0);
                    if (main != null)
                        ((MainFragment) main).updateTabWithDb(tabHandler.findTab(1));
                    Fragment main1 = tabFragment.getFragmentAtIndex(1);
                    if (main1 != null)
                        ((MainFragment) main1).updateTabWithDb(tabHandler.findTab(2));
                }
                getPrefs().edit().putBoolean(PREFERENCE_NEED_TO_SET_HOME, false).commit();
            } else {
                // just refresh list
                if (tabFragment != null) {
                    Fragment main = tabFragment.getFragmentAtIndex(0);
                    if (main != null)
                        ((MainFragment) main).updateList();
                    Fragment main1 = tabFragment.getFragmentAtIndex(1);
                    if (main1 != null)
                        ((MainFragment) main1).updateList();
                }
            }
        } else {
            Toast.makeText(this, R.string.grantfailed, Toast.LENGTH_SHORT).show();
            requestStoragePermission();
        }
    }
}
Also used : Tab(com.amaze.filemanager.database.models.Tab) TabFragment(com.amaze.filemanager.fragments.TabFragment) Fragment(android.support.v4.app.Fragment) FTPServerFragment(com.amaze.filemanager.fragments.FTPServerFragment) CompressedExplorerFragment(com.amaze.filemanager.fragments.CompressedExplorerFragment) AppsListFragment(com.amaze.filemanager.fragments.AppsListFragment) ProcessViewerFragment(com.amaze.filemanager.fragments.ProcessViewerFragment) TabFragment(com.amaze.filemanager.fragments.TabFragment) MainFragment(com.amaze.filemanager.fragments.MainFragment) SearchWorkerFragment(com.amaze.filemanager.fragments.SearchWorkerFragment) CloudSheetFragment(com.amaze.filemanager.fragments.CloudSheetFragment)

Example 5 with MainFragment

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

the class MainActivity method onOptionsItemSelected.

// called when the user exits the action mode
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // ActionBarDrawerToggle will take care of this.
    if (drawer.onOptionsItemSelected(item))
        return true;
    // Handle action buttons
    MainFragment ma = getCurrentMainFragment();
    switch(item.getItemId()) {
        case R.id.home:
            if (ma != null)
                ma.home();
            break;
        case R.id.history:
            if (ma != null)
                GeneralDialogCreation.showHistoryDialog(dataUtils, getPrefs(), ma, getAppTheme());
            break;
        case R.id.sethome:
            if (ma == null)
                return super.onOptionsItemSelected(item);
            final MainFragment main = ma;
            if (main.openMode != OpenMode.FILE && main.openMode != OpenMode.ROOT) {
                Toast.makeText(mainActivity, R.string.not_allowed, Toast.LENGTH_SHORT).show();
                break;
            }
            final MaterialDialog dialog = GeneralDialogCreation.showBasicDialog(mainActivity, new String[] { getResources().getString(R.string.questionset), getResources().getString(R.string.setashome), getResources().getString(R.string.yes), getResources().getString(R.string.no), null });
            dialog.getActionButton(DialogAction.POSITIVE).setOnClickListener((v) -> {
                main.home = main.getCurrentPath();
                updatePaths(main.no);
                dialog.dismiss();
            });
            dialog.show();
            break;
        case R.id.exit:
            finish();
            break;
        case R.id.sort:
            Fragment fragment = getFragmentAtFrame();
            if (fragment instanceof AppsListFragment) {
                GeneralDialogCreation.showSortDialog((AppsListFragment) fragment, getAppTheme());
            }
            break;
        case R.id.sortby:
            if (ma != null)
                GeneralDialogCreation.showSortDialog(ma, getAppTheme(), getPrefs());
            break;
        case R.id.dsort:
            if (ma == null)
                return super.onOptionsItemSelected(item);
            String[] sort = getResources().getStringArray(R.array.directorysortmode);
            MaterialDialog.Builder builder = new MaterialDialog.Builder(mainActivity);
            builder.theme(getAppTheme().getMaterialDialogTheme());
            builder.title(R.string.directorysort);
            int current = Integer.parseInt(getPrefs().getString(PreferencesConstants.PREFERENCE_DIRECTORY_SORT_MODE, "0"));
            final MainFragment mainFrag = ma;
            builder.items(sort).itemsCallbackSingleChoice(current, (dialog1, view, which, text) -> {
                getPrefs().edit().putString(PreferencesConstants.PREFERENCE_DIRECTORY_SORT_MODE, "" + which).commit();
                mainFrag.getSortModes();
                mainFrag.updateList();
                dialog1.dismiss();
                return true;
            });
            builder.build().show();
            break;
        case R.id.hiddenitems:
            GeneralDialogCreation.showHiddenDialog(dataUtils, getPrefs(), ma, getAppTheme());
            break;
        case R.id.view:
            final MainFragment mainFragment = ma;
            int pathLayout = dataUtils.getListOrGridForPath(ma.getCurrentPath(), DataUtils.LIST);
            if (ma.IS_LIST) {
                if (pathLayout == DataUtils.LIST) {
                    AppConfig.runInBackground(() -> {
                        utilsHandler.removeListViewPath(mainFragment.getCurrentPath());
                    });
                }
                AppConfig.runInBackground(() -> {
                    utilsHandler.addGridView(mainFragment.getCurrentPath());
                });
                dataUtils.setPathAsGridOrList(ma.getCurrentPath(), DataUtils.GRID);
            } else {
                if (pathLayout == DataUtils.GRID) {
                    AppConfig.runInBackground(() -> {
                        utilsHandler.removeGridViewPath(mainFragment.getCurrentPath());
                    });
                }
                AppConfig.runInBackground(() -> {
                    utilsHandler.addListView(mainFragment.getCurrentPath());
                });
                dataUtils.setPathAsGridOrList(ma.getCurrentPath(), DataUtils.LIST);
            }
            ma.switchView();
            break;
        case R.id.paste:
            String path = ma.getCurrentPath();
            ArrayList<HybridFileParcelable> arrayList = new ArrayList<>(Arrays.asList(pasteHelper.paths));
            boolean move = pasteHelper.operation == PasteHelper.OPERATION_CUT;
            new PrepareCopyTask(ma, path, move, mainActivity, isRootExplorer()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList);
            pasteHelper = null;
            invalidatePasteButton(item);
            break;
        case R.id.extract:
            Fragment fragment1 = getFragmentAtFrame();
            if (fragment1 instanceof CompressedExplorerFragment) {
                mainActivityHelper.extractFile(((CompressedExplorerFragment) fragment1).compressedFile);
            }
            break;
        case R.id.search:
            getAppbar().getSearchView().revealSearchView();
            break;
    }
    return super.onOptionsItemSelected(item);
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ArrayList(java.util.ArrayList) Fragment(android.support.v4.app.Fragment) FTPServerFragment(com.amaze.filemanager.fragments.FTPServerFragment) CompressedExplorerFragment(com.amaze.filemanager.fragments.CompressedExplorerFragment) AppsListFragment(com.amaze.filemanager.fragments.AppsListFragment) ProcessViewerFragment(com.amaze.filemanager.fragments.ProcessViewerFragment) TabFragment(com.amaze.filemanager.fragments.TabFragment) MainFragment(com.amaze.filemanager.fragments.MainFragment) SearchWorkerFragment(com.amaze.filemanager.fragments.SearchWorkerFragment) CloudSheetFragment(com.amaze.filemanager.fragments.CloudSheetFragment) PrepareCopyTask(com.amaze.filemanager.asynchronous.asynctasks.PrepareCopyTask) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) MainFragment(com.amaze.filemanager.fragments.MainFragment) AppsListFragment(com.amaze.filemanager.fragments.AppsListFragment) CompressedExplorerFragment(com.amaze.filemanager.fragments.CompressedExplorerFragment)

Aggregations

MainFragment (com.amaze.filemanager.fragments.MainFragment)13 HybridFile (com.amaze.filemanager.filesystem.HybridFile)6 File (java.io.File)6 AppsListFragment (com.amaze.filemanager.fragments.AppsListFragment)5 CloudSheetFragment (com.amaze.filemanager.fragments.CloudSheetFragment)5 ProcessViewerFragment (com.amaze.filemanager.fragments.ProcessViewerFragment)5 SearchWorkerFragment (com.amaze.filemanager.fragments.SearchWorkerFragment)5 TabFragment (com.amaze.filemanager.fragments.TabFragment)5 ArrayList (java.util.ArrayList)5 Fragment (android.support.v4.app.Fragment)4 CompressedExplorerFragment (com.amaze.filemanager.fragments.CompressedExplorerFragment)4 FTPServerFragment (com.amaze.filemanager.fragments.FTPServerFragment)4 Intent (android.content.Intent)3 Uri (android.net.Uri)3 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)3 HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)3 BookSorter (com.amaze.filemanager.utils.BookSorter)3 Context (android.content.Context)2 AsyncTask (android.os.AsyncTask)2 Build (android.os.Build)2