Search in sources :

Example 6 with MainFragment

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

the class MainActivity method onNewIntent.

@Override
public void onNewIntent(Intent i) {
    intent = i;
    path = i.getStringExtra("path");
    if (path != null) {
        if (new File(path).isDirectory()) {
            MainFragment ma = getCurrentMainFragment();
            if (ma != null) {
                ma.loadlist(path, false, OpenMode.FILE);
            } else
                goToMain(path);
        } else
            FileUtils.openFile(new File(path), mainActivity, getPrefs());
    } else if (i.getStringArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS) != null) {
        ArrayList<HybridFileParcelable> failedOps = i.getParcelableArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS);
        if (failedOps != null) {
            mainActivityHelper.showFailedOperationDialog(failedOps, this);
        }
    } else if (i.getCategories() != null && i.getCategories().contains(CLOUD_AUTHENTICATOR_GDRIVE)) {
        // we used an external authenticator instead of APIs. Probably for Google Drive
        CloudRail.setAuthenticationResponse(intent);
    } else if ((openProcesses = i.getBooleanExtra(KEY_INTENT_PROCESS_VIEWER, false))) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.content_frame, new ProcessViewerFragment(), KEY_INTENT_PROCESS_VIEWER);
        // transaction.addToBackStack(null);
        drawer.setSomethingSelected(true);
        openProcesses = false;
        // title.setText(utils.getString(con, R.string.process_viewer));
        // Commit the transaction
        transaction.commitAllowingStateLoss();
        supportInvalidateOptionsMenu();
    } else if (intent.getAction() != null) {
        checkForExternalIntent(intent);
        if (SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
                if (getPrefs().getString(KEY_PREF_OTG, null) == null) {
                    getPrefs().edit().putString(KEY_PREF_OTG, VALUE_PREF_OTG_NULL).apply();
                    drawer.refreshDrawer();
                }
            } else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
                getPrefs().edit().putString(KEY_PREF_OTG, null).apply();
                drawer.refreshDrawer();
            }
        }
    }
}
Also used : MainFragment(com.amaze.filemanager.fragments.MainFragment) FragmentTransaction(android.support.v4.app.FragmentTransaction) ArrayList(java.util.ArrayList) ProcessViewerFragment(com.amaze.filemanager.fragments.ProcessViewerFragment) File(java.io.File) HybridFile(com.amaze.filemanager.filesystem.HybridFile)

Example 7 with MainFragment

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

the class FileHandler method handleMessage.

@Override
public void handleMessage(Message msg) {
    super.handleMessage(msg);
    MainFragment main = mainFragment.get();
    String path = (String) msg.obj;
    switch(msg.what) {
        case CustomFileObserver.GOBACK:
            main.goBack();
            break;
        case CustomFileObserver.NEW_ITEM:
            HybridFile fileCreated = new HybridFile(main.openMode, main.getCurrentPath() + "/" + path);
            main.getElementsList().add(fileCreated.generateLayoutElement(useThumbs));
            break;
        case CustomFileObserver.DELETED_ITEM:
            for (int i = 0; i < main.getElementsList().size(); i++) {
                File currentFile = new File(main.getElementsList().get(i).desc);
                if (currentFile.getName().equals(path)) {
                    main.getElementsList().remove(i);
                    break;
                }
            }
            break;
        default:
            // Pass along other messages from the UI
            super.handleMessage(msg);
            return;
    }
    if (listView.getVisibility() == View.VISIBLE) {
        if (main.getElementsList().size() == 0) {
            // no item left in list, recreate views
            main.reloadListElements(true, main.results, !main.IS_LIST);
        } else {
            // we already have some elements in list view, invalidate the adapter
            ((RecyclerAdapter) listView.getAdapter()).setItems(listView, main.getElementsList());
        }
    } else {
        // there was no list view, means the directory was empty
        main.loadlist(main.getCurrentPath(), true, main.openMode);
    }
    main.computeScroll();
}
Also used : HybridFile(com.amaze.filemanager.filesystem.HybridFile) MainFragment(com.amaze.filemanager.fragments.MainFragment) RecyclerAdapter(com.amaze.filemanager.adapters.RecyclerAdapter) HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File)

Example 8 with MainFragment

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

Example 9 with MainFragment

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

the class MainActivity method onCreate.

/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initialisePreferences();
    initializeInteractiveShell();
    dataUtils.registerOnDataChangedListener(this);
    CustomSshJConfig.init();
    AppConfig.setActivityContext(con);
    setContentView(R.layout.main_toolbar);
    appbar = new AppBar(this, getPrefs(), queue -> {
        if (!queue.isEmpty()) {
            mainActivityHelper.search(getPrefs(), queue);
        }
    });
    initialiseViews();
    tabHandler = new TabHandler(this);
    utilsHandler = AppConfig.getInstance().getUtilsHandler();
    cloudHandler = new CloudHandler(this);
    mainActivityHelper = new MainActivityHelper(this);
    // TODO: 7/12/2017 not init when actionIntent != null
    initialiseFab();
    if (CloudSheetFragment.isCloudProviderAvailable(this)) {
        getSupportLoaderManager().initLoader(REQUEST_CODE_CLOUD_LIST_KEYS, null, this);
    }
    path = getIntent().getStringExtra("path");
    openProcesses = getIntent().getBooleanExtra(KEY_INTENT_PROCESS_VIEWER, false);
    intent = getIntent();
    if (intent.getStringArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS) != null) {
        ArrayList<HybridFileParcelable> failedOps = intent.getParcelableArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS);
        if (failedOps != null) {
            mainActivityHelper.showFailedOperationDialog(failedOps, this);
        }
    }
    checkForExternalIntent(intent);
    if (savedInstanceState != null) {
        drawer.setSomethingSelected(savedInstanceState.getBoolean(KEY_DRAWER_SELECTED));
    }
    // setting window background color instead of each item, in order to reduce pixel overdraw
    if (getAppTheme().equals(AppTheme.LIGHT)) {
        /*if(Main.IS_LIST)
                getWindow().setBackgroundDrawableResource(android.R.color.white);
            else
                getWindow().setBackgroundDrawableResource(R.color.grid_background_light);
            */
        getWindow().setBackgroundDrawableResource(android.R.color.white);
    } else if (getAppTheme().equals(AppTheme.BLACK)) {
        getWindow().setBackgroundDrawableResource(android.R.color.black);
    } else {
        getWindow().setBackgroundDrawableResource(R.color.holo_dark_background);
    }
    /*findViewById(R.id.drawer_buttton).setOnClickListener(new ImageView.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mDrawerLayout.isOpen(mDrawerLinear)) {
                    mDrawerLayout.close(mDrawerLinear);
                } else mDrawerLayout.openDrawer(mDrawerLinear);
            }
        });*/
    drawer.setDrawerIndicatorEnabled();
    // recents header color implementation
    if (SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("Amaze", ((BitmapDrawable) getResources().getDrawable(R.mipmap.ic_launcher)).getBitmap(), getColorPreference().getColor(ColorUsage.getPrimary(MainActivity.currentTab)));
        setTaskDescription(taskDescription);
    }
    if (!getBoolean(PREFERENCE_BOOKMARKS_ADDED)) {
        utilsHandler.addCommonBookmarks();
        getPrefs().edit().putBoolean(PREFERENCE_BOOKMARKS_ADDED, true).commit();
    }
    AppConfig.runInBackground(new AppConfig.CustomAsyncCallbacks() {

        @Override
        public <E> E doInBackground() {
            dataUtils.setHiddenFiles(utilsHandler.getHiddenFilesConcurrentRadixTree());
            dataUtils.setHistory(utilsHandler.getHistoryLinkedList());
            dataUtils.setGridfiles(utilsHandler.getGridViewList());
            dataUtils.setListfiles(utilsHandler.getListViewList());
            dataUtils.setBooks(utilsHandler.getBookmarksList());
            ArrayList<String[]> servers = new ArrayList<String[]>();
            servers.addAll(utilsHandler.getSmbList());
            servers.addAll(utilsHandler.getSftpList());
            dataUtils.setServers(servers);
            return null;
        }

        @Override
        public Void onPostExecute(Object result) {
            drawer.refreshDrawer();
            if (savedInstanceState == null) {
                if (openProcesses) {
                    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                    transaction.replace(R.id.content_frame, new ProcessViewerFragment(), KEY_INTENT_PROCESS_VIEWER);
                    // transaction.addToBackStack(null);
                    drawer.setSomethingSelected(true);
                    openProcesses = false;
                    // title.setText(utils.getString(con, R.string.process_viewer));
                    // Commit the transaction
                    transaction.commit();
                    supportInvalidateOptionsMenu();
                } else if (intent.getAction() != null && intent.getAction().equals(TileService.ACTION_QS_TILE_PREFERENCES)) {
                    // tile preferences, open ftp fragment
                    FragmentTransaction transaction2 = getSupportFragmentManager().beginTransaction();
                    transaction2.replace(R.id.content_frame, new FTPServerFragment());
                    appBarLayout.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
                    drawer.setSomethingSelected(true);
                    drawer.deselectEverything();
                    transaction2.commit();
                } else {
                    if (path != null && path.length() > 0) {
                        HybridFile file = new HybridFile(OpenMode.UNKNOWN, path);
                        file.generateMode(MainActivity.this);
                        if (file.isDirectory(MainActivity.this))
                            goToMain(path);
                        else {
                            goToMain(null);
                            FileUtils.openFile(new File(path), MainActivity.this, getPrefs());
                        }
                    } else {
                        goToMain(null);
                    }
                }
            } else {
                pasteHelper = savedInstanceState.getParcelable(PASTEHELPER_BUNDLE);
                oppathe = savedInstanceState.getString(KEY_OPERATION_PATH);
                oppathe1 = savedInstanceState.getString(KEY_OPERATED_ON_PATH);
                oparrayList = savedInstanceState.getParcelableArrayList(KEY_OPERATIONS_PATH_LIST);
                operation = savedInstanceState.getInt(KEY_OPERATION);
            // mainFragment = (Main) savedInstanceState.getParcelable("main_fragment");
            }
            return null;
        }

        @Override
        public Void onPreExecute() {
            return null;
        }

        @Override
        public Void publishResult(Object... result) {
            return null;
        }

        @Override
        public <T> T[] params() {
            return null;
        }
    });
}
Also used : AppBar(com.amaze.filemanager.ui.views.appbar.AppBar) Arrays(java.util.Arrays) Bundle(android.os.Bundle) AppConfig(com.amaze.filemanager.utils.application.AppConfig) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ColorDrawable(android.graphics.drawable.ColorDrawable) SDK_INT(android.os.Build.VERSION.SDK_INT) AppTheme(com.amaze.filemanager.utils.theme.AppTheme) Handler(android.os.Handler) CryptHandler(com.amaze.filemanager.database.CryptHandler) ParseException(com.cloudrail.si.exceptions.ParseException) Shell(eu.chainfire.libsuperuser.Shell) PREFERENCE_SHOW_HIDDENFILES(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_HIDDENFILES) OnRequestPermissionsResultCallback(android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback) SshConnectionPool(com.amaze.filemanager.filesystem.ssh.SshConnectionPool) GeneralDialogCreation(com.amaze.filemanager.ui.dialogs.GeneralDialogCreation) IntentFilter(android.content.IntentFilter) Fragment(android.support.v4.app.Fragment) PREFERENCE_VIEW(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_VIEW) FABsMenu(jahirfiquitiva.libs.fabsmenu.FABsMenu) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException) SmbConnectionListener(com.amaze.filemanager.ui.dialogs.SmbConnectDialog.SmbConnectionListener) R(com.amaze.filemanager.R) Snackbar(android.support.design.widget.Snackbar) CloudStorage(com.cloudrail.si.interfaces.CloudStorage) Environment(android.os.Environment) SftpConnectDialog(com.amaze.filemanager.ui.dialogs.SftpConnectDialog) DataChangeListener(com.amaze.filemanager.utils.DataUtils.DataChangeListener) FTPServerFragment(com.amaze.filemanager.fragments.FTPServerFragment) NonNull(android.support.annotation.NonNull) CompressedExplorerFragment(com.amaze.filemanager.fragments.CompressedExplorerFragment) AppsListFragment(com.amaze.filemanager.fragments.AppsListFragment) ArrayList(java.util.ArrayList) TileService(android.service.quicksettings.TileService) RenameBookmark(com.amaze.filemanager.ui.dialogs.RenameBookmark) MainActivityHelper(com.amaze.filemanager.utils.MainActivityHelper) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) DataUtils(com.amaze.filemanager.utils.DataUtils) PreferenceUtils(com.amaze.filemanager.utils.PreferenceUtils) Menu(android.view.Menu) DeleteTask(com.amaze.filemanager.asynchronous.asynctasks.DeleteTask) ProcessViewerFragment(com.amaze.filemanager.fragments.ProcessViewerFragment) TextUtils(android.text.TextUtils) AuthenticationException(com.cloudrail.si.exceptions.AuthenticationException) File(java.io.File) Utils(com.amaze.filemanager.utils.Utils) RingtoneManager(android.media.RingtoneManager) Configuration(android.content.res.Configuration) Box(com.cloudrail.si.services.Box) LinearLayout(android.widget.LinearLayout) BookSorter(com.amaze.filemanager.utils.BookSorter) PreferencesConstants(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants) ColorUsage(com.amaze.filemanager.utils.color.ColorUsage) PackageManager(android.content.pm.PackageManager) WindowManager(android.view.WindowManager) ThemedActivity(com.amaze.filemanager.activities.superclasses.ThemedActivity) RootHelper(com.amaze.filemanager.filesystem.RootHelper) Drawer(com.amaze.filemanager.ui.views.drawer.Drawer) CopyService(com.amaze.filemanager.asynchronous.services.CopyService) ContentResolver(android.content.ContentResolver) CloudContract(com.amaze.filemanager.database.CloudContract) PasteHelper(com.amaze.filemanager.filesystem.PasteHelper) View(android.view.View) UsbManager(android.hardware.usb.UsbManager) GoogleDrive(com.cloudrail.si.services.GoogleDrive) LoaderManager(android.support.v4.app.LoaderManager) SmbConnectDialog(com.amaze.filemanager.ui.dialogs.SmbConnectDialog) TitleFAB(jahirfiquitiva.libs.fabsmenu.TitleFAB) AsyncTask(android.os.AsyncTask) OTGUtil(com.amaze.filemanager.utils.OTGUtil) CloudConnectionCallbacks(com.amaze.filemanager.fragments.CloudSheetFragment.CloudConnectionCallbacks) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) CloudRail(com.cloudrail.si.CloudRail) List(java.util.List) PrepareCopyTask(com.amaze.filemanager.asynchronous.asynctasks.PrepareCopyTask) CloudHandler(com.amaze.filemanager.database.CloudHandler) Pattern(java.util.regex.Pattern) PREFERENCE_COLORED_NAVIGATION(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_COLORED_NAVIGATION) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Tab(com.amaze.filemanager.database.models.Tab) Window(android.view.Window) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ActivityManager(android.app.ActivityManager) Context(android.content.Context) AppBarLayout(android.support.design.widget.AppBarLayout) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) TabFragment(com.amaze.filemanager.fragments.TabFragment) KeyEvent(android.view.KeyEvent) HybridFile(com.amaze.filemanager.filesystem.HybridFile) MainFragment(com.amaze.filemanager.fragments.MainFragment) FABsMenuListener(jahirfiquitiva.libs.fabsmenu.FABsMenuListener) UtilsHandler(com.amaze.filemanager.database.UtilsHandler) Intent(android.content.Intent) CursorLoader(android.support.v4.content.CursorLoader) TabHandler(com.amaze.filemanager.database.TabHandler) MenuItem(android.view.MenuItem) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) ServiceWatcherUtil(com.amaze.filemanager.utils.ServiceWatcherUtil) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) Build(android.os.Build) Cursor(android.database.Cursor) CloudEntry(com.amaze.filemanager.database.models.CloudEntry) Loader(android.support.v4.content.Loader) CustomSshJConfig(com.amaze.filemanager.filesystem.ssh.CustomSshJConfig) PREFERENCE_BOOKMARKS_ADDED(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_BOOKMARKS_ADDED) DialogAction(com.afollestad.materialdialogs.DialogAction) BookmarkCallback(com.amaze.filemanager.ui.dialogs.RenameBookmark.BookmarkCallback) OneDrive(com.cloudrail.si.services.OneDrive) Dropbox(com.cloudrail.si.services.Dropbox) MoveFiles(com.amaze.filemanager.asynchronous.asynctasks.MoveFiles) SearchWorkerFragment(com.amaze.filemanager.fragments.SearchWorkerFragment) HandlerThread(android.os.HandlerThread) PREFERENCE_NEED_TO_SET_HOME(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_NEED_TO_SET_HOME) FileUtils(com.amaze.filemanager.utils.files.FileUtils) CloudSheetFragment(com.amaze.filemanager.fragments.CloudSheetFragment) Activity(android.app.Activity) FragmentTransaction(android.support.v4.app.FragmentTransaction) OpenMode(com.amaze.filemanager.utils.OpenMode) Collections(java.util.Collections) ContentUris(android.content.ContentUris) FileUtil(com.amaze.filemanager.filesystem.FileUtil) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) PREFERENCE_NEED_TO_SET_HOME(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_NEED_TO_SET_HOME) ArrayList(java.util.ArrayList) ActivityManager(android.app.ActivityManager) MainActivityHelper(com.amaze.filemanager.utils.MainActivityHelper) FragmentTransaction(android.support.v4.app.FragmentTransaction) AppBar(com.amaze.filemanager.ui.views.appbar.AppBar) AppConfig(com.amaze.filemanager.utils.application.AppConfig) CloudHandler(com.amaze.filemanager.database.CloudHandler) FTPServerFragment(com.amaze.filemanager.fragments.FTPServerFragment) TabHandler(com.amaze.filemanager.database.TabHandler) ProcessViewerFragment(com.amaze.filemanager.fragments.ProcessViewerFragment) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File) HybridFile(com.amaze.filemanager.filesystem.HybridFile)

Example 10 with MainFragment

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

the class MainActivity method onActivityResult.

protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
    if (requestCode == Drawer.image_selector_request_code) {
        drawer.onActivityResult(requestCode, responseCode, intent);
    } else if (requestCode == 3) {
        Uri treeUri;
        if (responseCode == Activity.RESULT_OK) {
            // Get Uri from Storage Access Framework.
            treeUri = intent.getData();
            // Persist URI - this is required for verification of writability.
            if (treeUri != null)
                getPrefs().edit().putString(PreferencesConstants.PREFERENCE_URI, treeUri.toString()).commit();
        } else {
            /* DialogUtil.displayError(getActivity(), R.string.message_dialog_cannot_write_to_folder_saf, false, currentFolder);
                        ||!FileUtil.isWritableNormalOrSaf(currentFolder)*/
            return;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getContentResolver().takePersistableUriPermission(treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        }
        switch(operation) {
            case // deletion
            DataUtils.DELETE:
                new DeleteTask(null, mainActivity).execute((oparrayList));
                break;
            case // copying
            DataUtils.COPY:
                // legacy compatibility
                if (oparrayList != null && oparrayList.size() != 0) {
                    oparrayListList = new ArrayList<>();
                    oparrayListList.add(oparrayList);
                    oparrayList = null;
                    oppatheList = new ArrayList<>();
                    oppatheList.add(oppathe);
                    oppathe = "";
                }
                for (int i = 0; i < oparrayListList.size(); i++) {
                    ArrayList<HybridFileParcelable> sourceList = oparrayListList.get(i);
                    Intent intent1 = new Intent(con, CopyService.class);
                    intent1.putExtra(CopyService.TAG_COPY_SOURCES, sourceList);
                    intent1.putExtra(CopyService.TAG_COPY_TARGET, oppatheList.get(i));
                    ServiceWatcherUtil.runService(this, intent1);
                }
                break;
            case // moving
            DataUtils.MOVE:
                // legacy compatibility
                if (oparrayList != null && oparrayList.size() != 0) {
                    oparrayListList = new ArrayList<>();
                    oparrayListList.add(oparrayList);
                    oparrayList = null;
                    oppatheList = new ArrayList<>();
                    oppatheList.add(oppathe);
                    oppathe = "";
                }
                new MoveFiles(oparrayListList, getCurrentMainFragment(), getCurrentMainFragment().getActivity(), OpenMode.FILE).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, oppatheList);
                break;
            case // mkdir
            DataUtils.NEW_FOLDER:
                mainActivityHelper.mkDir(RootHelper.generateBaseFile(new File(oppathe), true), getCurrentMainFragment());
                break;
            case DataUtils.RENAME:
                MainFragment ma = getCurrentMainFragment();
                mainActivityHelper.rename(ma.openMode, (oppathe), (oppathe1), mainActivity, isRootExplorer());
                ma.updateList();
                break;
            case DataUtils.NEW_FILE:
                mainActivityHelper.mkFile(new HybridFile(OpenMode.FILE, oppathe), getCurrentMainFragment());
                break;
            case DataUtils.EXTRACT:
                mainActivityHelper.extractFile(new File(oppathe));
                break;
            case DataUtils.COMPRESS:
                mainActivityHelper.compressFiles(new File(oppathe), oparrayList);
        }
        operation = -1;
    } else if (requestCode == REQUEST_CODE_SAF && responseCode == Activity.RESULT_OK) {
        // otg access
        getPrefs().edit().putString(KEY_PREF_OTG, intent.getData().toString()).apply();
        drawer.closeIfNotLocked();
        if (drawer.isLocked())
            drawer.onDrawerClosed();
    } else if (requestCode == REQUEST_CODE_SAF && responseCode != Activity.RESULT_OK) {
        // otg access not provided
        drawer.resetPendingPath();
    }
}
Also used : HybridFile(com.amaze.filemanager.filesystem.HybridFile) MainFragment(com.amaze.filemanager.fragments.MainFragment) ArrayList(java.util.ArrayList) Intent(android.content.Intent) MoveFiles(com.amaze.filemanager.asynchronous.asynctasks.MoveFiles) Uri(android.net.Uri) CopyService(com.amaze.filemanager.asynchronous.services.CopyService) File(java.io.File) HybridFile(com.amaze.filemanager.filesystem.HybridFile) DeleteTask(com.amaze.filemanager.asynchronous.asynctasks.DeleteTask)

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