use of com.cloudrail.si.interfaces.CloudStorage in project AmazeFileManager by TeamAmaze.
the class Operations method mkfile.
public static void mkfile(@NonNull final HybridFile file, final Context context, final boolean rootMode, @NonNull final ErrorCallBack errorCallBack) {
new AsyncTask<Void, Void, Void>() {
private DataUtils dataUtils = DataUtils.getInstance();
@Override
protected Void doInBackground(Void... params) {
// check whether filename is valid or not
if (!Operations.isFileNameValid(file.getName(context))) {
errorCallBack.invalidName(file);
return null;
}
if (file.exists()) {
errorCallBack.exists(file);
return null;
}
if (file.isSftp()) {
OutputStream out = file.getOutputStream(context);
try {
out.close();
errorCallBack.done(file, true);
return null;
} catch (IOException e) {
errorCallBack.done(file, false);
return null;
}
}
if (file.isSmb()) {
try {
file.getSmbFile(2000).createNewFile();
} catch (SmbException e) {
e.printStackTrace();
errorCallBack.done(file, false);
return null;
}
errorCallBack.done(file, file.exists());
return null;
} else if (file.isDropBoxFile()) {
CloudStorage cloudStorageDropbox = dataUtils.getAccount(OpenMode.DROPBOX);
try {
byte[] tempBytes = new byte[0];
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(tempBytes);
cloudStorageDropbox.upload(CloudUtil.stripPath(OpenMode.DROPBOX, file.getPath()), byteArrayInputStream, 0l, true);
errorCallBack.done(file, true);
} catch (Exception e) {
e.printStackTrace();
errorCallBack.done(file, false);
}
} else if (file.isBoxFile()) {
CloudStorage cloudStorageBox = dataUtils.getAccount(OpenMode.BOX);
try {
byte[] tempBytes = new byte[0];
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(tempBytes);
cloudStorageBox.upload(CloudUtil.stripPath(OpenMode.BOX, file.getPath()), byteArrayInputStream, 0l, true);
errorCallBack.done(file, true);
} catch (Exception e) {
e.printStackTrace();
errorCallBack.done(file, false);
}
} else if (file.isOneDriveFile()) {
CloudStorage cloudStorageOneDrive = dataUtils.getAccount(OpenMode.ONEDRIVE);
try {
byte[] tempBytes = new byte[0];
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(tempBytes);
cloudStorageOneDrive.upload(CloudUtil.stripPath(OpenMode.ONEDRIVE, file.getPath()), byteArrayInputStream, 0l, true);
errorCallBack.done(file, true);
} catch (Exception e) {
e.printStackTrace();
errorCallBack.done(file, false);
}
} else if (file.isGoogleDriveFile()) {
CloudStorage cloudStorageGdrive = dataUtils.getAccount(OpenMode.GDRIVE);
try {
byte[] tempBytes = new byte[0];
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(tempBytes);
cloudStorageGdrive.upload(CloudUtil.stripPath(OpenMode.GDRIVE, file.getPath()), byteArrayInputStream, 0l, true);
errorCallBack.done(file, true);
} catch (Exception e) {
e.printStackTrace();
errorCallBack.done(file, false);
}
} else if (file.isOtgFile()) {
// first check whether new file already exists
DocumentFile fileToCreate = OTGUtil.getDocumentFile(file.getPath(), context, false);
if (fileToCreate != null)
errorCallBack.exists(file);
DocumentFile parentDirectory = OTGUtil.getDocumentFile(file.getParent(), context, false);
if (parentDirectory.isDirectory()) {
parentDirectory.createFile(file.getName(context).substring(file.getName().lastIndexOf(".")), file.getName(context));
errorCallBack.done(file, true);
} else
errorCallBack.done(file, false);
return null;
} else {
if (file.isLocal() || file.isRoot()) {
int mode = checkFolder(new File(file.getParent()), context);
if (mode == 2) {
errorCallBack.launchSAF(file);
return null;
}
if (mode == 1 || mode == 0)
try {
FileUtil.mkfile(file.getFile(), context);
} catch (IOException e) {
}
if (!file.exists() && rootMode) {
file.setMode(OpenMode.ROOT);
if (file.exists())
errorCallBack.exists(file);
try {
RootUtils.mkFile(file.getPath());
} catch (ShellNotRunningException e) {
e.printStackTrace();
}
errorCallBack.done(file, file.exists());
return null;
}
errorCallBack.done(file, file.exists());
return null;
}
errorCallBack.done(file, file.exists());
}
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.cloudrail.si.interfaces.CloudStorage 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;
}
}
use of com.cloudrail.si.interfaces.CloudStorage in project AmazeFileManager by TeamAmaze.
the class CloudUtil method checkToken.
/**
* Asynctask checks if the item pressed on is a cloud account, and if the token that
* is saved for it is invalid or not, in which case, we'll clear off the
* saved token and authenticate the user again
* @param path the path of item in drawer
* @param mainActivity reference to main activity to fire callbacks to delete/add connection
*/
public static void checkToken(String path, final MainActivity mainActivity) {
new AsyncTask<String, Void, Boolean>() {
OpenMode serviceType;
private DataUtils dataUtils = DataUtils.getInstance();
@Override
protected Boolean doInBackground(String... params) {
boolean isTokenValid = true;
String path = params[0];
if (path.startsWith(CloudHandler.CLOUD_PREFIX_DROPBOX)) {
// dropbox account
serviceType = OpenMode.DROPBOX;
CloudStorage cloudStorageDropbox = dataUtils.getAccount(OpenMode.DROPBOX);
try {
cloudStorageDropbox.getUserLogin();
} catch (Exception e) {
e.printStackTrace();
isTokenValid = false;
}
} else if (path.startsWith(CloudHandler.CLOUD_PREFIX_ONE_DRIVE)) {
serviceType = OpenMode.ONEDRIVE;
CloudStorage cloudStorageOneDrive = dataUtils.getAccount(OpenMode.ONEDRIVE);
try {
cloudStorageOneDrive.getUserLogin();
} catch (Exception e) {
e.printStackTrace();
isTokenValid = false;
}
} else if (path.startsWith(CloudHandler.CLOUD_PREFIX_BOX)) {
serviceType = OpenMode.BOX;
CloudStorage cloudStorageBox = dataUtils.getAccount(OpenMode.BOX);
try {
cloudStorageBox.getUserLogin();
} catch (Exception e) {
e.printStackTrace();
isTokenValid = false;
}
} else if (path.startsWith(CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE)) {
serviceType = OpenMode.GDRIVE;
CloudStorage cloudStorageGDrive = dataUtils.getAccount(OpenMode.GDRIVE);
try {
cloudStorageGDrive.getUserLogin();
} catch (Exception e) {
e.printStackTrace();
isTokenValid = false;
}
}
return isTokenValid;
}
@Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
if (!aBoolean) {
// delete account and create a new one
Toast.makeText(mainActivity, mainActivity.getResources().getString(R.string.cloud_token_lost), Toast.LENGTH_LONG).show();
mainActivity.deleteConnection(serviceType);
mainActivity.addConnection(serviceType);
}
}
}.execute(path);
}
use of com.cloudrail.si.interfaces.CloudStorage in project AmazeFileManager by TeamAmaze.
the class DeleteTask method doInBackground.
protected Boolean doInBackground(ArrayList<HybridFileParcelable>... p1) {
files = p1[0];
boolean wasDeleted = true;
if (files.size() == 0)
return true;
if (files.get(0).isOtgFile()) {
for (HybridFileParcelable file : files) {
DocumentFile documentFile = OTGUtil.getDocumentFile(file.getPath(), cd, false);
wasDeleted = documentFile.delete();
}
} else if (files.get(0).isDropBoxFile()) {
CloudStorage cloudStorageDropbox = dataUtils.getAccount(OpenMode.DROPBOX);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageDropbox.delete(CloudUtil.stripPath(OpenMode.DROPBOX, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else if (files.get(0).isBoxFile()) {
CloudStorage cloudStorageBox = dataUtils.getAccount(OpenMode.BOX);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageBox.delete(CloudUtil.stripPath(OpenMode.BOX, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else if (files.get(0).isGoogleDriveFile()) {
CloudStorage cloudStorageGdrive = dataUtils.getAccount(OpenMode.GDRIVE);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageGdrive.delete(CloudUtil.stripPath(OpenMode.GDRIVE, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else if (files.get(0).isOneDriveFile()) {
CloudStorage cloudStorageOnedrive = dataUtils.getAccount(OpenMode.ONEDRIVE);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageOnedrive.delete(CloudUtil.stripPath(OpenMode.ONEDRIVE, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else {
for (HybridFileParcelable file : files) {
try {
if (file.delete(cd, rootMode)) {
wasDeleted = true;
} else {
wasDeleted = false;
break;
}
} catch (ShellNotRunningException e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
}
// delete file from media database
if (!files.get(0).isSmb()) {
try {
for (HybridFileParcelable f : files) {
delete(cd, f.getPath());
}
} catch (Exception e) {
for (HybridFileParcelable f : files) {
FileUtils.scanFile(f.getPath(), cd);
}
}
}
// delete file entry from encrypted database
for (HybridFileParcelable file : files) {
if (file.getName().endsWith(CryptUtil.CRYPT_EXTENSION)) {
CryptHandler handler = new CryptHandler(cd);
handler.clear(file.getPath());
}
}
return wasDeleted;
}
use of com.cloudrail.si.interfaces.CloudStorage in project AmazeFileManager by TeamAmaze.
the class MoveFiles method doInBackground.
@Override
protected Boolean doInBackground(ArrayList<String>... strings) {
paths = strings[0];
if (files.size() == 0)
return true;
switch(mode) {
case SMB:
for (int i = 0; i < paths.size(); i++) {
for (HybridFileParcelable f : files.get(i)) {
try {
SmbFile source = new SmbFile(f.getPath());
SmbFile dest = new SmbFile(paths.get(i) + "/" + f.getName());
source.renameTo(dest);
} catch (MalformedURLException e) {
e.printStackTrace();
return false;
} catch (SmbException e) {
e.printStackTrace();
return false;
}
}
}
break;
case FILE:
for (int i = 0; i < paths.size(); i++) {
for (HybridFileParcelable f : files.get(i)) {
File dest = new File(paths.get(i) + "/" + f.getName());
File source = new File(f.getPath());
if (!source.renameTo(dest)) {
// check if we have root
if (mainFrag.getMainActivity().isRootExplorer()) {
try {
if (!RootUtils.rename(f.getPath(), paths.get(i) + "/" + f.getName()))
return false;
} catch (ShellNotRunningException e) {
e.printStackTrace();
return false;
}
} else
return false;
}
}
}
break;
case DROPBOX:
case BOX:
case ONEDRIVE:
case GDRIVE:
for (int i = 0; i < paths.size(); i++) {
for (HybridFileParcelable baseFile : files.get(i)) {
DataUtils dataUtils = DataUtils.getInstance();
CloudStorage cloudStorage = dataUtils.getAccount(mode);
String targetPath = paths.get(i) + "/" + baseFile.getName();
if (baseFile.getMode() == mode) {
// source and target both in same filesystem, use API method
try {
cloudStorage.move(CloudUtil.stripPath(mode, baseFile.getPath()), CloudUtil.stripPath(mode, targetPath));
} catch (Exception e) {
return false;
}
} else {
// not in same filesystem, execute service
return false;
}
}
}
default:
return false;
}
return true;
}
Aggregations