use of com.genonbeta.TrebleShot.io.DocumentFile in project TrebleShot by genonbeta.
the class FileUtils method fetchDirectories.
public static DocumentFile fetchDirectories(DocumentFile directoryFile, String path, boolean createIfNotExists) throws IOException {
DocumentFile currentDirectory = directoryFile;
String[] pathArray = path.split(File.separator);
for (String currentPath : pathArray) {
if (currentDirectory == null)
throw new IOException("Failed to create directories: " + path);
DocumentFile existingOne = currentDirectory.findFile(currentPath);
if (existingOne != null && !existingOne.isDirectory())
throw new IOException("A file exists for of directory name: " + currentPath + " ; " + path);
currentDirectory = existingOne == null && createIfNotExists ? currentDirectory.createDirectory(currentPath) : existingOne;
}
return currentDirectory;
}
use of com.genonbeta.TrebleShot.io.DocumentFile in project TrebleShot by genonbeta.
the class FileUtils method getApplicationDirectory.
public static DocumentFile getApplicationDirectory(Context context) {
String defaultPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + context.getString(R.string.text_appName);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
if (sharedPreferences.contains("storage_path")) {
try {
DocumentFile savePath = fromUri(context, Uri.parse(sharedPreferences.getString("storage_path", null)));
if (savePath != null && savePath.isDirectory() && savePath.canWrite())
return savePath;
} catch (Exception e) {
e.printStackTrace();
}
}
File defaultFolder = new File(defaultPath);
if (!defaultFolder.isDirectory())
defaultFolder.mkdirs();
return DocumentFile.fromFile(defaultFolder);
}
use of com.genonbeta.TrebleShot.io.DocumentFile in project TrebleShot by genonbeta.
the class ShareActivity method createFolderStructure.
protected void createFolderStructure(DocumentFile file, String folderName) {
DocumentFile[] files = file.listFiles();
if (files != null) {
for (DocumentFile thisFile : files) {
if (getDefaultInterrupter().interrupted())
break;
getProgressDialog().setMax(getProgressDialog().getMax() + 1);
getProgressDialog().setProgress(getProgressDialog().getMax() + 1);
if (thisFile.isDirectory()) {
createFolderStructure(thisFile, (folderName != null ? folderName + File.separator : null) + thisFile.getName());
continue;
}
try {
mFiles.add(new SelectableStream(thisFile, folderName));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
use of com.genonbeta.TrebleShot.io.DocumentFile in project TrebleShot by genonbeta.
the class HomeActivity method sendThisApplication.
private void sendThisApplication() {
new Handler(Looper.myLooper()).post(new Runnable() {
@Override
public void run() {
try {
Interrupter interrupter = new Interrupter();
PackageManager pm = getPackageManager();
Intent sendIntent = new Intent(Intent.ACTION_SEND);
PackageInfo packageInfo = pm.getPackageInfo(getApplicationInfo().packageName, 0);
String fileName = packageInfo.applicationInfo.loadLabel(pm) + "_" + packageInfo.versionName + ".apk";
DocumentFile storageDirectory = FileUtils.getApplicationDirectory(getApplicationContext());
DocumentFile codeFile = DocumentFile.fromFile(new File(getApplicationInfo().sourceDir));
DocumentFile cloneFile = storageDirectory.createFile(null, FileUtils.getUniqueFileName(storageDirectory, fileName, true));
FileUtils.copy(HomeActivity.this, codeFile, cloneFile, interrupter);
try {
sendIntent.putExtra(ShareActivity.EXTRA_FILENAME_LIST, fileName).putExtra(Intent.EXTRA_STREAM, FileUtils.getSecureUri(HomeActivity.this, cloneFile)).setType(cloneFile.getType());
startActivity(Intent.createChooser(sendIntent, getString(R.string.text_fileShareAppChoose)));
} catch (IllegalArgumentException e) {
Toast.makeText(HomeActivity.this, R.string.mesg_providerNotAllowedError, Toast.LENGTH_LONG).show();
openFolder(storageDirectory);
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
use of com.genonbeta.TrebleShot.io.DocumentFile in project TrebleShot by genonbeta.
the class FileExplorerFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_fileexplorer, container, false);
mDatabase = new AccessDatabase(getActivity());
mPathView = view.findViewById(R.id.fragment_fileexplorer_pathresolver);
mHomeButton = view.findViewById(R.id.fragment_fileexplorer_pathresolver_home);
mLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
mPathAdapter = new FilePathResolverRecyclerAdapter();
mFileListFragment = (FileListFragment) getChildFragmentManager().findFragmentById(R.id.fragment_fileexplorer_fragment_files);
mPathAdapter.setOnClickListener(new PathResolverRecyclerAdapter.OnClickListener<DocumentFile>() {
@Override
public void onClick(PathResolverRecyclerAdapter.Holder<DocumentFile> holder) {
requestPath(holder.index.object);
}
});
mHomeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
requestPath(null);
}
});
mFileListFragment.setOnPathChangedListener(new FileListFragment.OnPathChangedListener() {
@Override
public void onPathChanged(DocumentFile file) {
mPathAdapter.goTo(file);
mPathAdapter.notifyDataSetChanged();
if (mPathAdapter.getItemCount() > 0)
mPathView.smoothScrollToPosition(mPathAdapter.getItemCount() - 1);
}
});
mPathView.setHasFixedSize(true);
mPathView.setLayoutManager(mLayoutManager);
mLayoutManager.setStackFromEnd(true);
mPathView.setAdapter(mPathAdapter);
return view;
}
Aggregations