use of com.amaze.filemanager.utils.OpenMode in project AmazeFileManager by TeamAmaze.
the class MainFragment method loadlist.
/**
* This loads a path into the MainFragment.
* @param path the path to be loaded
* @param back if we're coming back from any directory and want the scroll to be restored
* @param openMode the mode in which the directory should be opened
*/
public void loadlist(final String path, final boolean back, final OpenMode openMode) {
if (mActionMode != null)
mActionMode.finish();
mSwipeRefreshLayout.setRefreshing(true);
if (loadFilesListTask != null && loadFilesListTask.getStatus() == AsyncTask.Status.RUNNING) {
loadFilesListTask.cancel(true);
}
loadFilesListTask = new LoadFilesListTask(ma.getActivity(), path, ma, openMode, getBoolean(PREFERENCE_SHOW_THUMB), getBoolean(PREFERENCE_SHOW_HIDDENFILES), (data) -> {
if (data != null && data.second != null) {
boolean isPathLayoutGrid = dataUtils.getListOrGridForPath(path, DataUtils.LIST) == DataUtils.GRID;
setListElements(data.second, back, path, data.first, false, isPathLayoutGrid);
mSwipeRefreshLayout.setRefreshing(false);
}
});
loadFilesListTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.amaze.filemanager.utils.OpenMode in project AmazeFileManager by TeamAmaze.
the class RootHelper method getFiles.
/**
* Get files using shell, supposing the path is not a SMB/OTG/Custom (*.apk/images)
*
* @param path
* @param root whether root is available or not
* @param showHidden to show hidden files
* @param getModeCallBack callback to set the type of file
* @return TODO: Avoid parsing ls
*/
public static void getFiles(String path, boolean root, boolean showHidden, GetModeCallBack getModeCallBack, OnFileFound fileCallback) {
OpenMode mode = OpenMode.FILE;
ArrayList<HybridFileParcelable> files = new ArrayList<>();
if (root && !path.startsWith("/storage") && !path.startsWith("/sdcard")) {
try {
// we're rooted and we're trying to load file with superuser
// we're at the root directories, superuser is required!
ArrayList<String> ls;
String cpath = getCommandLineString(path);
// ls = Shell.SU.run("ls -l " + cpath);
ls = runShellCommand("ls -l " + (showHidden ? "-a " : "") + "\"" + cpath + "\"");
if (ls != null) {
for (int i = 0; i < ls.size(); i++) {
String file = ls.get(i);
if (!file.contains("Permission denied")) {
HybridFileParcelable array = FileUtils.parseName(file);
if (array != null) {
array.setMode(OpenMode.ROOT);
array.setName(array.getPath());
array.setPath(path + "/" + array.getPath());
if (array.getLink().trim().length() > 0) {
boolean isdirectory = isDirectory(array.getLink(), root, 0);
array.setDirectory(isdirectory);
} else
array.setDirectory(isDirectory(array));
files.add(array);
fileCallback.onFileFound(array);
}
}
}
mode = OpenMode.ROOT;
}
if (getModeCallBack != null)
getModeCallBack.getMode(mode);
} catch (ShellNotRunningException e) {
e.printStackTrace();
}
}
if (FileUtils.canListFiles(new File(path))) {
// we're taking a chance to load files using basic java filesystem
getFilesList(path, showHidden, fileCallback);
mode = OpenMode.FILE;
} else {
// we couldn't load files using native java filesystem callbacks
// maybe the access is not allowed due to android system restrictions, we'll see later
mode = OpenMode.FILE;
}
if (getModeCallBack != null)
getModeCallBack.getMode(mode);
}
use of com.amaze.filemanager.utils.OpenMode 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.amaze.filemanager.utils.OpenMode in project AmazeFileManager by TeamAmaze.
the class LoadFilesListTask method doInBackground.
@Override
protected Pair<OpenMode, ArrayList<LayoutElementParcelable>> doInBackground(Void... p) {
HybridFile hFile = null;
if (openmode == OpenMode.UNKNOWN) {
hFile = new HybridFile(OpenMode.UNKNOWN, path);
hFile.generateMode(ma.getActivity());
openmode = hFile.getMode();
if (hFile.isSmb()) {
ma.smbPath = path;
} else if (android.util.Patterns.EMAIL_ADDRESS.matcher(path).matches()) {
openmode = OpenMode.ROOT;
}
}
if (isCancelled())
return null;
ma.folder_count = 0;
ma.file_count = 0;
final ArrayList<LayoutElementParcelable> list;
switch(openmode) {
case SMB:
if (hFile == null) {
hFile = new HybridFile(OpenMode.SMB, path);
}
try {
SmbFile[] smbFile = hFile.getSmbFile(5000).listFiles();
list = ma.addToSmb(smbFile, path);
openmode = OpenMode.SMB;
} catch (SmbAuthException e) {
if (!e.getMessage().toLowerCase().contains("denied")) {
ma.reauthenticateSmb();
}
return null;
} catch (SmbException | NullPointerException e) {
e.printStackTrace();
return null;
}
break;
case SFTP:
HybridFile sftpHFile = new HybridFile(OpenMode.SFTP, path);
list = new ArrayList<LayoutElementParcelable>();
sftpHFile.forEachChildrenFile(c, false, file -> {
LayoutElementParcelable elem = createListParcelables(file);
if (elem != null)
list.add(elem);
});
break;
case CUSTOM:
switch(Integer.parseInt(path)) {
case 0:
list = listImages();
break;
case 1:
list = listVideos();
break;
case 2:
list = listaudio();
break;
case 3:
list = listDocs();
break;
case 4:
list = listApks();
break;
case 5:
list = listRecent();
break;
case 6:
list = listRecentFiles();
break;
default:
throw new IllegalStateException();
}
break;
case OTG:
list = new ArrayList<>();
listOtg(path, new OnFileFound() {
@Override
public void onFileFound(HybridFileParcelable file) {
LayoutElementParcelable elem = createListParcelables(file);
if (elem != null)
list.add(elem);
}
});
openmode = OpenMode.OTG;
break;
case DROPBOX:
case BOX:
case GDRIVE:
case ONEDRIVE:
CloudStorage cloudStorage = dataUtils.getAccount(openmode);
list = new ArrayList<>();
try {
listCloud(path, cloudStorage, openmode, new OnFileFound() {
@Override
public void onFileFound(HybridFileParcelable file) {
LayoutElementParcelable elem = createListParcelables(file);
if (elem != null)
list.add(elem);
}
});
} catch (CloudPluginException e) {
e.printStackTrace();
AppConfig.toast(c, c.getResources().getString(R.string.failed_no_connection));
return new Pair<>(openmode, list);
}
break;
default:
// we're neither in OTG not in SMB, load the list based on root/general filesystem
list = new ArrayList<>();
RootHelper.getFiles(path, ma.getMainActivity().isRootExplorer(), showHiddenFiles, new RootHelper.GetModeCallBack() {
@Override
public void getMode(OpenMode mode) {
openmode = mode;
}
}, new OnFileFound() {
@Override
public void onFileFound(HybridFileParcelable file) {
LayoutElementParcelable elem = createListParcelables(file);
if (elem != null)
list.add(elem);
}
});
break;
}
if (list != null && !(openmode == OpenMode.CUSTOM && ((path).equals("5") || (path).equals("6")))) {
Collections.sort(list, new FileListSorter(ma.dsort, ma.sortby, ma.asc));
}
return new Pair<>(openmode, list);
}
use of com.amaze.filemanager.utils.OpenMode in project AmazeFileManager by TeamAmaze.
the class SearchWorkerFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
String mPath = getArguments().getString(KEY_PATH);
String mInput = getArguments().getString(KEY_INPUT);
OpenMode mOpenMode = OpenMode.getOpenMode(getArguments().getInt(KEY_OPEN_MODE));
boolean mRootMode = getArguments().getBoolean(KEY_ROOT_MODE);
boolean isRegexEnabled = getArguments().getBoolean(KEY_REGEX);
boolean isMatchesEnabled = getArguments().getBoolean(KEY_REGEX_MATCHES);
mSearchAsyncTask = new SearchAsyncTask(getActivity(), mCallbacks, mInput, mOpenMode, mRootMode, isRegexEnabled, isMatchesEnabled);
mSearchAsyncTask.execute(mPath);
}
Aggregations