Search in sources :

Example 1 with AppsListFragment

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

the class Drawer method refreshDrawer.

public void refreshDrawer() {
    Menu menu = navView.getMenu();
    menu.clear();
    actionViewStateManager.deselectCurrentActionView();
    int order = 0;
    ArrayList<String> storageDirectories = mainActivity.getStorageDirectories();
    storage_count = 0;
    for (String file : storageDirectories) {
        File f = new File(file);
        String name;
        @DrawableRes int icon1 = R.drawable.ic_sd_storage_white_24dp;
        if ("/storage/emulated/legacy".equals(file) || "/storage/emulated/0".equals(file)) {
            name = resources.getString(R.string.storage);
        } else if ("/storage/sdcard1".equals(file)) {
            name = resources.getString(R.string.extstorage);
        } else if ("/".equals(file)) {
            name = resources.getString(R.string.rootdirectory);
            icon1 = R.drawable.ic_drawer_root_white;
        } else if (file.contains(OTGUtil.PREFIX_OTG)) {
            name = "OTG";
            icon1 = R.drawable.ic_usb_white_24dp;
        } else
            name = f.getName();
        if (!f.isDirectory() || f.canExecute()) {
            addNewItem(menu, STORAGES_GROUP, order++, name, new MenuMetadata(file), icon1, R.drawable.ic_show_chart_black_24dp);
            if (storage_count == 0)
                firstPath = file;
            else if (storage_count == 1)
                secondPath = file;
            storage_count++;
        }
    }
    dataUtils.setStorages(storageDirectories);
    if (dataUtils.getServers().size() > 0) {
        Collections.sort(dataUtils.getServers(), new BookSorter());
        synchronized (dataUtils.getServers()) {
            for (String[] file : dataUtils.getServers()) {
                addNewItem(menu, SERVERS_GROUP, order++, file[0], new MenuMetadata(file[1]), R.drawable.ic_settings_remote_white_24dp, R.drawable.ic_edit_24dp);
            }
        }
    }
    ArrayList<String[]> accountAuthenticationList = new ArrayList<>();
    if (CloudSheetFragment.isCloudProviderAvailable(mainActivity)) {
        for (CloudStorage cloudStorage : dataUtils.getAccounts()) {
            if (cloudStorage instanceof Dropbox) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_DROPBOX, new MenuMetadata(CloudHandler.CLOUD_PREFIX_DROPBOX + "/"), R.drawable.ic_dropbox_white_24dp, R.drawable.ic_edit_24dp);
                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_DROPBOX, CloudHandler.CLOUD_PREFIX_DROPBOX + "/" });
            } else if (cloudStorage instanceof Box) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_BOX, new MenuMetadata(CloudHandler.CLOUD_PREFIX_BOX + "/"), R.drawable.ic_box_white_24dp, R.drawable.ic_edit_24dp);
                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_BOX, CloudHandler.CLOUD_PREFIX_BOX + "/" });
            } else if (cloudStorage instanceof OneDrive) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_ONE_DRIVE, new MenuMetadata(CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/"), R.drawable.ic_onedrive_white_24dp, R.drawable.ic_edit_24dp);
                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_ONE_DRIVE, CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/" });
            } else if (cloudStorage instanceof GoogleDrive) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_GOOGLE_DRIVE, new MenuMetadata(CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/"), R.drawable.ic_google_drive_white_24dp, R.drawable.ic_edit_24dp);
                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_GOOGLE_DRIVE, CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/" });
            }
        }
        Collections.sort(accountAuthenticationList, new BookSorter());
    }
    if (mainActivity.getBoolean(PREFERENCE_SHOW_SIDEBAR_FOLDERS)) {
        if (dataUtils.getBooks().size() > 0) {
            Collections.sort(dataUtils.getBooks(), new BookSorter());
            synchronized (dataUtils.getBooks()) {
                for (String[] file : dataUtils.getBooks()) {
                    addNewItem(menu, FOLDERS_GROUP, order++, file[0], new MenuMetadata(file[1]), R.drawable.ic_folder_white_24dp, R.drawable.ic_edit_24dp);
                }
            }
        }
    }
    Boolean[] quickAccessPref = TinyDB.getBooleanArray(mainActivity.getPrefs(), QuickAccessPref.KEY, QuickAccessPref.DEFAULT);
    if (mainActivity.getBoolean(PREFERENCE_SHOW_SIDEBAR_QUICKACCESSES)) {
        if (quickAccessPref[0]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.quick, new MenuMetadata("5"), R.drawable.ic_star_white_24dp, null);
        }
        if (quickAccessPref[1]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.recent, new MenuMetadata("6"), R.drawable.ic_history_white_24dp, null);
        }
        if (quickAccessPref[2]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.images, new MenuMetadata("0"), R.drawable.ic_photo_library_white_24dp, null);
        }
        if (quickAccessPref[3]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.videos, new MenuMetadata("1"), R.drawable.ic_video_library_white_24dp, null);
        }
        if (quickAccessPref[4]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.audio, new MenuMetadata("2"), R.drawable.ic_library_music_white_24dp, null);
        }
        if (quickAccessPref[5]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.documents, new MenuMetadata("3"), R.drawable.ic_library_books_white_24dp, null);
        }
        if (quickAccessPref[6]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.apks, new MenuMetadata("4"), R.drawable.ic_apk_library_white_24dp, null);
        }
    }
    addNewItem(menu, LASTGROUP, order++, R.string.ftp, new MenuMetadata(() -> {
        FragmentTransaction transaction2 = mainActivity.getSupportFragmentManager().beginTransaction();
        transaction2.replace(R.id.content_frame, new FTPServerFragment());
        mainActivity.getAppbar().getAppbarLayout().animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
        pending_fragmentTransaction = transaction2;
        if (!isDrawerLocked)
            close();
        else
            onDrawerClosed();
    }), R.drawable.ic_ftp_white_24dp, null);
    addNewItem(menu, LASTGROUP, order++, R.string.apps, new MenuMetadata(() -> {
        FragmentTransaction transaction2 = mainActivity.getSupportFragmentManager().beginTransaction();
        transaction2.replace(R.id.content_frame, new AppsListFragment());
        mainActivity.getAppbar().getAppbarLayout().animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
        pending_fragmentTransaction = transaction2;
        if (!isDrawerLocked)
            close();
        else
            onDrawerClosed();
    }), R.drawable.ic_android_white_24dp, null);
    addNewItem(menu, LASTGROUP, order++, R.string.setting, new MenuMetadata(() -> {
        Intent in = new Intent(mainActivity, PreferencesActivity.class);
        mainActivity.startActivity(in);
    }), R.drawable.ic_settings_white_24dp, null);
    for (int i = 0; i < navView.getMenu().size(); i++) {
        navView.getMenu().getItem(i).setEnabled(true);
    }
    for (int group : GROUPS) {
        menu.setGroupCheckable(group, true, true);
    }
    MenuItem item = navView.getSelected();
    if (item != null) {
        item.setChecked(true);
        actionViewStateManager.selectActionView(item);
        isSomethingSelected = true;
    }
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) PreferencesActivity(com.amaze.filemanager.activities.PreferencesActivity) ArrayList(java.util.ArrayList) GoogleDrive(com.cloudrail.si.services.GoogleDrive) CloudStorage(com.cloudrail.si.interfaces.CloudStorage) OneDrive(com.cloudrail.si.services.OneDrive) FragmentTransaction(android.support.v4.app.FragmentTransaction) BookSorter(com.amaze.filemanager.utils.BookSorter) Menu(android.view.Menu) Dropbox(com.cloudrail.si.services.Dropbox) DrawableRes(android.support.annotation.DrawableRes) FTPServerFragment(com.amaze.filemanager.fragments.FTPServerFragment) Box(com.cloudrail.si.services.Box) Intent(android.content.Intent) MenuItem(android.view.MenuItem) AppsListFragment(com.amaze.filemanager.fragments.AppsListFragment) HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File)

Example 2 with AppsListFragment

use of com.amaze.filemanager.fragments.AppsListFragment 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)

Example 3 with AppsListFragment

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

the class MainActivity method onPrepareOptionsMenu.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem s = menu.findItem(R.id.view);
    MenuItem search = menu.findItem(R.id.search);
    MenuItem paste = menu.findItem(R.id.paste);
    Fragment fragment = getFragmentAtFrame();
    if (fragment instanceof TabFragment) {
        appbar.setTitle(R.string.appbar_name);
        if (getBoolean(PREFERENCE_VIEW)) {
            s.setTitle(getResources().getString(R.string.gridview));
        } else {
            s.setTitle(getResources().getString(R.string.listview));
        }
        try {
            MainFragment ma = getCurrentMainFragment();
            if (ma.IS_LIST)
                s.setTitle(R.string.gridview);
            else
                s.setTitle(R.string.listview);
            appbar.getBottomBar().updatePath(ma.getCurrentPath(), ma.results, MainActivityHelper.SEARCH_TEXT, ma.openMode, ma.folder_count, ma.file_count, ma);
        } catch (Exception e) {
        }
        appbar.getBottomBar().setClickListener();
        invalidatePasteButton(paste);
        search.setVisible(true);
        if (indicator_layout != null)
            indicator_layout.setVisibility(View.VISIBLE);
        menu.findItem(R.id.search).setVisible(true);
        menu.findItem(R.id.home).setVisible(true);
        menu.findItem(R.id.history).setVisible(true);
        menu.findItem(R.id.sethome).setVisible(true);
        menu.findItem(R.id.sort).setVisible(true);
        if (getBoolean(PREFERENCE_SHOW_HIDDENFILES))
            menu.findItem(R.id.hiddenitems).setVisible(true);
        menu.findItem(R.id.view).setVisible(true);
        menu.findItem(R.id.extract).setVisible(false);
        invalidatePasteButton(menu.findItem(R.id.paste));
        findViewById(R.id.buttonbarframe).setVisibility(View.VISIBLE);
    } else if (fragment instanceof AppsListFragment || fragment instanceof ProcessViewerFragment || fragment instanceof FTPServerFragment) {
        appBarLayout.setExpanded(true);
        menu.findItem(R.id.sethome).setVisible(false);
        if (indicator_layout != null)
            indicator_layout.setVisibility(View.GONE);
        findViewById(R.id.buttonbarframe).setVisibility(View.GONE);
        menu.findItem(R.id.search).setVisible(false);
        menu.findItem(R.id.home).setVisible(false);
        menu.findItem(R.id.history).setVisible(false);
        menu.findItem(R.id.extract).setVisible(false);
        if (fragment instanceof ProcessViewerFragment) {
            menu.findItem(R.id.sort).setVisible(false);
        } else {
            menu.findItem(R.id.dsort).setVisible(false);
            menu.findItem(R.id.sortby).setVisible(false);
        }
        menu.findItem(R.id.hiddenitems).setVisible(false);
        menu.findItem(R.id.view).setVisible(false);
        menu.findItem(R.id.paste).setVisible(false);
    } else if (fragment instanceof CompressedExplorerFragment) {
        appbar.setTitle(R.string.appbar_name);
        menu.findItem(R.id.sethome).setVisible(false);
        if (indicator_layout != null)
            indicator_layout.setVisibility(View.GONE);
        getAppbar().getBottomBar().resetClickListener();
        menu.findItem(R.id.search).setVisible(false);
        menu.findItem(R.id.home).setVisible(false);
        menu.findItem(R.id.history).setVisible(false);
        menu.findItem(R.id.sort).setVisible(false);
        menu.findItem(R.id.hiddenitems).setVisible(false);
        menu.findItem(R.id.view).setVisible(false);
        menu.findItem(R.id.paste).setVisible(false);
        menu.findItem(R.id.extract).setVisible(true);
    }
    return super.onPrepareOptionsMenu(menu);
}
Also used : MainFragment(com.amaze.filemanager.fragments.MainFragment) AppsListFragment(com.amaze.filemanager.fragments.AppsListFragment) CompressedExplorerFragment(com.amaze.filemanager.fragments.CompressedExplorerFragment) FTPServerFragment(com.amaze.filemanager.fragments.FTPServerFragment) MenuItem(android.view.MenuItem) TabFragment(com.amaze.filemanager.fragments.TabFragment) ProcessViewerFragment(com.amaze.filemanager.fragments.ProcessViewerFragment) 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) ParseException(com.cloudrail.si.exceptions.ParseException) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException) AuthenticationException(com.cloudrail.si.exceptions.AuthenticationException)

Aggregations

AppsListFragment (com.amaze.filemanager.fragments.AppsListFragment)3 FTPServerFragment (com.amaze.filemanager.fragments.FTPServerFragment)3 Fragment (android.support.v4.app.Fragment)2 MenuItem (android.view.MenuItem)2 CloudSheetFragment (com.amaze.filemanager.fragments.CloudSheetFragment)2 CompressedExplorerFragment (com.amaze.filemanager.fragments.CompressedExplorerFragment)2 MainFragment (com.amaze.filemanager.fragments.MainFragment)2 ProcessViewerFragment (com.amaze.filemanager.fragments.ProcessViewerFragment)2 SearchWorkerFragment (com.amaze.filemanager.fragments.SearchWorkerFragment)2 TabFragment (com.amaze.filemanager.fragments.TabFragment)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 DrawableRes (android.support.annotation.DrawableRes)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 Menu (android.view.Menu)1 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 PreferencesActivity (com.amaze.filemanager.activities.PreferencesActivity)1 PrepareCopyTask (com.amaze.filemanager.asynchronous.asynctasks.PrepareCopyTask)1 CloudPluginException (com.amaze.filemanager.exceptions.CloudPluginException)1