use of com.amaze.filemanager.filesystem.HybridFile in project AmazeFileManager by TeamAmaze.
the class MainFragment method goBack.
public void goBack() {
if (openMode == OpenMode.CUSTOM) {
loadlist(home, false, OpenMode.FILE);
return;
}
HybridFile currentFile = new HybridFile(openMode, CURRENT_PATH);
if (!results) {
if (!mRetainSearchTask) {
// normal case
if (selection) {
adapter.toggleChecked(false);
} else {
if (openMode == OpenMode.SMB) {
try {
if (!smbPath.equals(CURRENT_PATH)) {
String path = (new SmbFile(CURRENT_PATH).getParent());
loadlist((path), true, openMode);
} else
loadlist(home, false, OpenMode.FILE);
} catch (MalformedURLException e) {
e.printStackTrace();
}
} else if (openMode == OpenMode.SFTP) {
if (!CURRENT_PATH.substring("ssh://".length()).contains("/"))
loadlist(home, false, OpenMode.FILE);
else
loadlist(currentFile.getParent(getContext()), true, openMode);
} else if (CURRENT_PATH.equals("/") || CURRENT_PATH.equals(home) || CURRENT_PATH.equals(OTGUtil.PREFIX_OTG + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_BOX + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_DROPBOX + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/"))
getMainActivity().exit();
else if (FileUtils.canGoBack(getContext(), currentFile)) {
loadlist(currentFile.getParent(getContext()), true, openMode);
} else
getMainActivity().exit();
}
} else {
if (MainActivityHelper.SEARCH_TEXT != null) {
// starting the search query again :O
getMainActivity().mainFragment = (MainFragment) getMainActivity().getTabFragment().getCurrentTabFragment();
FragmentManager fm = getMainActivity().getSupportFragmentManager();
// getting parent path to resume search from there
String parentPath = new HybridFile(openMode, CURRENT_PATH).getParent(getActivity());
// don't fuckin' remove this line, we need to change
// the path back to parent on back press
CURRENT_PATH = parentPath;
MainActivityHelper.addSearchFragment(fm, new SearchWorkerFragment(), parentPath, MainActivityHelper.SEARCH_TEXT, openMode, getMainActivity().isRootExplorer(), sharedPref.getBoolean(SearchWorkerFragment.KEY_REGEX, false), sharedPref.getBoolean(SearchWorkerFragment.KEY_REGEX_MATCHES, false));
} else
loadlist(CURRENT_PATH, true, OpenMode.UNKNOWN);
mRetainSearchTask = false;
}
} else {
// to go back after search list have been popped
FragmentManager fm = getActivity().getSupportFragmentManager();
SearchWorkerFragment fragment = (SearchWorkerFragment) fm.findFragmentByTag(MainActivity.TAG_ASYNC_HELPER);
if (fragment != null) {
if (fragment.mSearchAsyncTask.getStatus() == AsyncTask.Status.RUNNING) {
fragment.mSearchAsyncTask.cancel(true);
}
}
loadlist(new File(CURRENT_PATH).getPath(), true, OpenMode.UNKNOWN);
results = false;
}
}
use of com.amaze.filemanager.filesystem.HybridFile in project AmazeFileManager by TeamAmaze.
the class MainFragment method onActivityCreated.
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(false);
// getMainActivity() = (MainActivity) getActivity();
initNoFileLayout();
getSortModes();
this.setRetainInstance(false);
HybridFile f = new HybridFile(OpenMode.UNKNOWN, CURRENT_PATH);
f.generateMode(getActivity());
getMainActivity().getAppbar().getBottomBar().setClickListener();
if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT) && !IS_LIST) {
listView.setBackgroundColor(Utils.getColor(getContext(), R.color.grid_background_light));
} else {
listView.setBackgroundDrawable(null);
}
listView.setHasFixedSize(true);
columns = Integer.parseInt(sharedPref.getString(PREFERENCE_GRID_COLUMNS, "-1"));
if (IS_LIST) {
mLayoutManager = new LinearLayoutManager(getContext());
listView.setLayoutManager(mLayoutManager);
} else {
if (columns == -1 || columns == 0)
mLayoutManagerGrid = new GridLayoutManager(getActivity(), 3);
else
mLayoutManagerGrid = new GridLayoutManager(getActivity(), columns);
setGridLayoutSpanSizeLookup(mLayoutManagerGrid);
listView.setLayoutManager(mLayoutManagerGrid);
}
// use a linear layout manager
// View footerView = getActivity().getLayoutInflater().inflate(R.layout.divider, null);// TODO: 23/5/2017 use or delete
dividerItemDecoration = new DividerItemDecoration(getActivity(), false, getBoolean(PREFERENCE_SHOW_DIVIDERS));
listView.addItemDecoration(dividerItemDecoration);
mSwipeRefreshLayout.setColorSchemeColors(accentColor);
DefaultItemAnimator animator = new DefaultItemAnimator();
listView.setItemAnimator(animator);
mToolbarContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if ((columns == 0 || columns == -1)) {
int screen_width = listView.getWidth();
int dptopx = Utils.dpToPx(getContext(), 115);
columns = screen_width / dptopx;
if (columns == 0 || columns == -1)
columns = 3;
if (!IS_LIST)
mLayoutManagerGrid.setSpanCount(columns);
}
if (savedInstanceState != null && !IS_LIST)
onSavedInstanceState(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
mToolbarContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
mToolbarContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
});
if (savedInstanceState == null) {
loadlist(CURRENT_PATH, false, openMode);
} else {
if (IS_LIST)
onSavedInstanceState(savedInstanceState);
}
}
use of com.amaze.filemanager.filesystem.HybridFile in project AmazeFileManager by TeamAmaze.
the class MainFragment method hide.
public void hide(String path) {
dataUtils.addHiddenFile(path);
if (new File(path).isDirectory()) {
File f1 = new File(path + "/" + ".nomedia");
if (!f1.exists()) {
try {
getMainActivity().mainActivityHelper.mkFile(new HybridFile(OpenMode.FILE, f1.getPath()), this);
} catch (Exception e) {
e.printStackTrace();
}
}
FileUtils.scanFile(path, getActivity());
}
}
use of com.amaze.filemanager.filesystem.HybridFile in project AmazeFileManager by TeamAmaze.
the class Drawer method onDrawerClosed.
public void onDrawerClosed() {
if (pending_fragmentTransaction != null) {
pending_fragmentTransaction.commit();
pending_fragmentTransaction = null;
}
if (pendingPath != null) {
HybridFile hFile = new HybridFile(OpenMode.UNKNOWN, pendingPath);
hFile.generateMode(mainActivity);
if (hFile.isSimpleFile()) {
FileUtils.openFile(new File(pendingPath), mainActivity, mainActivity.getPrefs());
pendingPath = null;
return;
}
MainFragment mainFrag = mainActivity.getCurrentMainFragment();
if (mainFrag != null) {
mainFrag.loadlist(pendingPath, false, OpenMode.UNKNOWN);
} else {
mainActivity.goToMain(pendingPath);
return;
}
pendingPath = null;
}
mainActivity.supportInvalidateOptionsMenu();
}
use of com.amaze.filemanager.filesystem.HybridFile in project AmazeFileManager by TeamAmaze.
the class CryptUtil method encrypt.
/**
* Wrapper around handling encryption in directory tree
* @param context
* @param sourceFile the source file to encrypt
* @param targetDirectory the target directory in which we're going to encrypt
*/
private void encrypt(final Context context, HybridFileParcelable sourceFile, HybridFile targetDirectory) throws GeneralSecurityException, IOException {
if (sourceFile.isDirectory()) {
// succeed #CRYPT_EXTENSION at end of directory/file name
final HybridFile hFile = new HybridFile(targetDirectory.getMode(), targetDirectory.getPath(), sourceFile.getName() + CRYPT_EXTENSION, sourceFile.isDirectory());
FileUtil.mkdirs(context, hFile);
sourceFile.forEachChildrenFile(context, sourceFile.isRoot(), file -> {
try {
encrypt(context, file, hFile);
} catch (IOException | GeneralSecurityException e) {
// throw unchecked exception, no throws needed
throw new IllegalStateException(e);
}
});
} else {
if (sourceFile.getName().endsWith(CRYPT_EXTENSION)) {
failedOps.add(sourceFile);
return;
}
BufferedInputStream inputStream = new BufferedInputStream(sourceFile.getInputStream(context), GenericCopyUtil.DEFAULT_BUFFER_SIZE);
// succeed #CRYPT_EXTENSION at end of directory/file name
HybridFile targetFile = new HybridFile(targetDirectory.getMode(), targetDirectory.getPath(), sourceFile.getName() + CRYPT_EXTENSION, sourceFile.isDirectory());
progressHandler.setFileName(sourceFile.getName());
BufferedOutputStream outputStream = new BufferedOutputStream(targetFile.getOutputStream(context), GenericCopyUtil.DEFAULT_BUFFER_SIZE);
if (progressHandler.getCancelled())
return;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
aesEncrypt(inputStream, outputStream);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
rsaEncrypt(context, inputStream, outputStream);
}
}
}
Aggregations