Search in sources :

Example 1 with GoogleDrive

use of com.cloudrail.si.services.GoogleDrive 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 GoogleDrive

use of com.cloudrail.si.services.GoogleDrive in project cloudrail-si-android-sdk by CloudRail.

the class Services method initGoogleDrive.

private void initGoogleDrive() {
    googledrive.set(new GoogleDrive(context, "[Client ID]", "", "com.cloudrail.fileviewer:/oauth2redirect", ""));
    ((GoogleDrive) googledrive.get()).useAdvancedAuthentication();
}
Also used : GoogleDrive(com.cloudrail.si.services.GoogleDrive)

Example 3 with GoogleDrive

use of com.cloudrail.si.services.GoogleDrive in project AmazeFileManager by TeamAmaze.

the class MainActivity method onLoadFinished.

@Override
public void onLoadFinished(Loader<Cursor> loader, final Cursor data) {
    if (data == null) {
        Toast.makeText(this, getResources().getString(R.string.cloud_error_failed_restart), Toast.LENGTH_LONG).show();
        return;
    }
    cloudSyncTask = new AsyncTask<Void, Void, Boolean>() {

        @Override
        protected Boolean doInBackground(Void... params) {
            boolean hasUpdatedDrawer = false;
            if (data.getCount() > 0 && data.moveToFirst()) {
                do {
                    switch(data.getInt(0)) {
                        case 1:
                            try {
                                CloudRail.setAppKey(data.getString(1));
                            } catch (Exception e) {
                                // any other exception due to network conditions or other error
                                e.printStackTrace();
                                AppConfig.toast(MainActivity.this, getResources().getString(R.string.failed_cloud_api_key));
                                return false;
                            }
                            break;
                        case 2:
                            // DRIVE
                            try {
                                CloudEntry cloudEntryGdrive = null;
                                CloudEntry savedCloudEntryGdrive;
                                GoogleDrive cloudStorageDrive = new GoogleDrive(getApplicationContext(), data.getString(1), "", CLOUD_AUTHENTICATOR_REDIRECT_URI, data.getString(2));
                                cloudStorageDrive.useAdvancedAuthentication();
                                if ((savedCloudEntryGdrive = cloudHandler.findEntry(OpenMode.GDRIVE)) != null) {
                                    try {
                                        cloudStorageDrive.loadAsString(savedCloudEntryGdrive.getPersistData());
                                    } catch (ParseException e) {
                                        e.printStackTrace();
                                        // we need to update the persist string as existing one is been compromised
                                        cloudStorageDrive.login();
                                        cloudEntryGdrive = new CloudEntry(OpenMode.GDRIVE, cloudStorageDrive.saveAsString());
                                        cloudHandler.updateEntry(OpenMode.GDRIVE, cloudEntryGdrive);
                                    }
                                } else {
                                    cloudStorageDrive.login();
                                    cloudEntryGdrive = new CloudEntry(OpenMode.GDRIVE, cloudStorageDrive.saveAsString());
                                    cloudHandler.addEntry(cloudEntryGdrive);
                                }
                                dataUtils.addAccount(cloudStorageDrive);
                                hasUpdatedDrawer = true;
                            } catch (CloudPluginException e) {
                                e.printStackTrace();
                                AppConfig.toast(MainActivity.this, getResources().getString(R.string.cloud_error_plugin));
                                deleteConnection(OpenMode.GDRIVE);
                                return false;
                            } catch (AuthenticationException e) {
                                e.printStackTrace();
                                AppConfig.toast(MainActivity.this, getResources().getString(R.string.cloud_fail_authenticate));
                                deleteConnection(OpenMode.GDRIVE);
                                return false;
                            } catch (Exception e) {
                                // any other exception due to network conditions or other error
                                e.printStackTrace();
                                AppConfig.toast(MainActivity.this, getResources().getString(R.string.failed_cloud_new_connection));
                                deleteConnection(OpenMode.GDRIVE);
                                return false;
                            }
                            break;
                        case 3:
                            // DROPBOX
                            try {
                                CloudEntry cloudEntryDropbox = null;
                                CloudEntry savedCloudEntryDropbox;
                                CloudStorage cloudStorageDropbox = new Dropbox(getApplicationContext(), data.getString(1), data.getString(2));
                                if ((savedCloudEntryDropbox = cloudHandler.findEntry(OpenMode.DROPBOX)) != null) {
                                    // we already have the entry and saved state, get it
                                    try {
                                        cloudStorageDropbox.loadAsString(savedCloudEntryDropbox.getPersistData());
                                    } catch (ParseException e) {
                                        e.printStackTrace();
                                        // we need to persist data again
                                        cloudStorageDropbox.login();
                                        cloudEntryDropbox = new CloudEntry(OpenMode.DROPBOX, cloudStorageDropbox.saveAsString());
                                        cloudHandler.updateEntry(OpenMode.DROPBOX, cloudEntryDropbox);
                                    }
                                } else {
                                    cloudStorageDropbox.login();
                                    cloudEntryDropbox = new CloudEntry(OpenMode.DROPBOX, cloudStorageDropbox.saveAsString());
                                    cloudHandler.addEntry(cloudEntryDropbox);
                                }
                                dataUtils.addAccount(cloudStorageDropbox);
                                hasUpdatedDrawer = true;
                            } catch (CloudPluginException e) {
                                e.printStackTrace();
                                AppConfig.toast(MainActivity.this, getResources().getString(R.string.cloud_error_plugin));
                                deleteConnection(OpenMode.DROPBOX);
                                return false;
                            } catch (AuthenticationException e) {
                                e.printStackTrace();
                                AppConfig.toast(MainActivity.this, getResources().getString(R.string.cloud_fail_authenticate));
                                deleteConnection(OpenMode.DROPBOX);
                                return false;
                            } catch (Exception e) {
                                // any other exception due to network conditions or other error
                                e.printStackTrace();
                                AppConfig.toast(MainActivity.this, getResources().getString(R.string.failed_cloud_new_connection));
                                deleteConnection(OpenMode.DROPBOX);
                                return false;
                            }
                            break;
                        case 4:
                            // BOX
                            try {
                                CloudEntry cloudEntryBox = null;
                                CloudEntry savedCloudEntryBox;
                                CloudStorage cloudStorageBox = new Box(getApplicationContext(), data.getString(1), data.getString(2));
                                if ((savedCloudEntryBox = cloudHandler.findEntry(OpenMode.BOX)) != null) {
                                    // we already have the entry and saved state, get it
                                    try {
                                        cloudStorageBox.loadAsString(savedCloudEntryBox.getPersistData());
                                    } catch (ParseException e) {
                                        e.printStackTrace();
                                        // we need to persist data again
                                        cloudStorageBox.login();
                                        cloudEntryBox = new CloudEntry(OpenMode.BOX, cloudStorageBox.saveAsString());
                                        cloudHandler.updateEntry(OpenMode.BOX, cloudEntryBox);
                                    }
                                } else {
                                    cloudStorageBox.login();
                                    cloudEntryBox = new CloudEntry(OpenMode.BOX, cloudStorageBox.saveAsString());
                                    cloudHandler.addEntry(cloudEntryBox);
                                }
                                dataUtils.addAccount(cloudStorageBox);
                                hasUpdatedDrawer = true;
                            } catch (CloudPluginException e) {
                                e.printStackTrace();
                                AppConfig.toast(MainActivity.this, getResources().getString(R.string.cloud_error_plugin));
                                deleteConnection(OpenMode.BOX);
                                return false;
                            } catch (AuthenticationException e) {
                                e.printStackTrace();
                                AppConfig.toast(MainActivity.this, getResources().getString(R.string.cloud_fail_authenticate));
                                deleteConnection(OpenMode.BOX);
                                return false;
                            } catch (Exception e) {
                                // any other exception due to network conditions or other error
                                e.printStackTrace();
                                AppConfig.toast(MainActivity.this, getResources().getString(R.string.failed_cloud_new_connection));
                                deleteConnection(OpenMode.BOX);
                                return false;
                            }
                            break;
                        case 5:
                            // ONEDRIVE
                            try {
                                CloudEntry cloudEntryOnedrive = null;
                                CloudEntry savedCloudEntryOnedrive;
                                CloudStorage cloudStorageOnedrive = new OneDrive(getApplicationContext(), data.getString(1), data.getString(2));
                                if ((savedCloudEntryOnedrive = cloudHandler.findEntry(OpenMode.ONEDRIVE)) != null) {
                                    // we already have the entry and saved state, get it
                                    try {
                                        cloudStorageOnedrive.loadAsString(savedCloudEntryOnedrive.getPersistData());
                                    } catch (ParseException e) {
                                        e.printStackTrace();
                                        // we need to persist data again
                                        cloudStorageOnedrive.login();
                                        cloudEntryOnedrive = new CloudEntry(OpenMode.ONEDRIVE, cloudStorageOnedrive.saveAsString());
                                        cloudHandler.updateEntry(OpenMode.ONEDRIVE, cloudEntryOnedrive);
                                    }
                                } else {
                                    cloudStorageOnedrive.login();
                                    cloudEntryOnedrive = new CloudEntry(OpenMode.ONEDRIVE, cloudStorageOnedrive.saveAsString());
                                    cloudHandler.addEntry(cloudEntryOnedrive);
                                }
                                dataUtils.addAccount(cloudStorageOnedrive);
                                hasUpdatedDrawer = true;
                            } catch (CloudPluginException e) {
                                e.printStackTrace();
                                AppConfig.toast(MainActivity.this, getResources().getString(R.string.cloud_error_plugin));
                                deleteConnection(OpenMode.ONEDRIVE);
                                return false;
                            } catch (AuthenticationException e) {
                                e.printStackTrace();
                                AppConfig.toast(MainActivity.this, getResources().getString(R.string.cloud_fail_authenticate));
                                deleteConnection(OpenMode.ONEDRIVE);
                                return false;
                            } catch (Exception e) {
                                // any other exception due to network conditions or other error
                                e.printStackTrace();
                                AppConfig.toast(MainActivity.this, getResources().getString(R.string.failed_cloud_new_connection));
                                deleteConnection(OpenMode.ONEDRIVE);
                                return false;
                            }
                            break;
                        default:
                            Toast.makeText(MainActivity.this, getResources().getString(R.string.cloud_error_failed_restart), Toast.LENGTH_LONG).show();
                            return false;
                    }
                } while (data.moveToNext());
            }
            return hasUpdatedDrawer;
        }

        @Override
        protected void onPostExecute(Boolean refreshDrawer) {
            super.onPostExecute(refreshDrawer);
            if (refreshDrawer) {
                drawer.refreshDrawer();
            }
        }
    }.execute();
}
Also used : AuthenticationException(com.cloudrail.si.exceptions.AuthenticationException) AsyncTask(android.os.AsyncTask) GoogleDrive(com.cloudrail.si.services.GoogleDrive) CloudEntry(com.amaze.filemanager.database.models.CloudEntry) Box(com.cloudrail.si.services.Box) ParseException(com.cloudrail.si.exceptions.ParseException) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException) AuthenticationException(com.cloudrail.si.exceptions.AuthenticationException) CloudStorage(com.cloudrail.si.interfaces.CloudStorage) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException) OneDrive(com.cloudrail.si.services.OneDrive) ParseException(com.cloudrail.si.exceptions.ParseException) Dropbox(com.cloudrail.si.services.Dropbox)

Aggregations

GoogleDrive (com.cloudrail.si.services.GoogleDrive)3 CloudStorage (com.cloudrail.si.interfaces.CloudStorage)2 Box (com.cloudrail.si.services.Box)2 Dropbox (com.cloudrail.si.services.Dropbox)2 OneDrive (com.cloudrail.si.services.OneDrive)2 Intent (android.content.Intent)1 AsyncTask (android.os.AsyncTask)1 DrawableRes (android.support.annotation.DrawableRes)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)1 PreferencesActivity (com.amaze.filemanager.activities.PreferencesActivity)1 CloudEntry (com.amaze.filemanager.database.models.CloudEntry)1 CloudPluginException (com.amaze.filemanager.exceptions.CloudPluginException)1 HybridFile (com.amaze.filemanager.filesystem.HybridFile)1 AppsListFragment (com.amaze.filemanager.fragments.AppsListFragment)1 FTPServerFragment (com.amaze.filemanager.fragments.FTPServerFragment)1 BookSorter (com.amaze.filemanager.utils.BookSorter)1 AuthenticationException (com.cloudrail.si.exceptions.AuthenticationException)1