Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
HBiSoft committed Aug 16, 2019
1 parent bec7cea commit e29aac1
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ class DownloadAsyncTask extends AsyncTask<Uri, Integer, String> {
private InputStream is = null;
private String extension;


DownloadAsyncTask(Uri uri, Context context, CallBackTask callback) {
this.mUri = uri;
mContext = new WeakReference<>(context);
this.callback = callback;

}

@Override
Expand Down Expand Up @@ -66,7 +64,6 @@ protected String doInBackground(Uri... params) {
File file = null;

try {

assert returnCursor != null;
int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
returnCursor.moveToFirst();
Expand All @@ -90,7 +87,6 @@ protected String doInBackground(Uri... params) {
fos.write(data, 0, count);
}
}

fos.flush();
fos.close();

Expand Down
4 changes: 2 additions & 2 deletions pickit/src/main/java/com/hbisoft/pickit/PickiT.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public void getPath(Uri uri, int APILevel){
downloadFile(uri);

}else {
returnedPath = FileUtils.getRealPathFromURI_API19(context, uri);
returnedPath = Utils.getRealPathFromURI_API19(context, uri);
pickiTCallbacks.PickiTonCompleteListener(returnedPath, false);
}

}else{
//Todo: Test API <19
returnedPath = FileUtils.getRealPathFromURI_BelowAPI19(context, uri);
returnedPath = Utils.getRealPathFromURI_BelowAPI19(context, uri);
pickiTCallbacks.PickiTonCompleteListener(returnedPath, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,38 @@

import java.io.File;

public class FileUtils {
public class Utils {

@SuppressLint("NewApi")
static String getRealPathFromURI_API19(final Context context, final Uri uri) {

final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];

// This is for checking Main Memory
if ("primary".equalsIgnoreCase(type)) {
if (split.length > 1) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
} else {
return Environment.getExternalStorageDirectory() + "/";
}
// This is for checking SD Card
} else {
return "storage" + "/" + docId.replace(":", "/");
}

}
// DownloadsProvider
else if (isDownloadsDocument(uri)) {


/*String fileName = getFilePath(context, uri);
if (fileName != null) {
return Environment.getExternalStorageDirectory().toString() + "/Download/" + fileName;
}
final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
return getDataColumn(context, contentUri, null, null);*/

String fileName = getFilePath(context, uri);
if (fileName != null) {
fileName = Environment.getExternalStorageDirectory().toString() + "/Download/" + fileName;
File file = new File(fileName);
if (file.exists())
return fileName;
}

//download directory directory-file
String id = DocumentsContract.getDocumentId(uri);
if (id.startsWith("raw:")) {
id = id.replaceFirst("raw:", "");
Expand All @@ -76,7 +58,6 @@ else if (isDownloadsDocument(uri)) {


}
// MediaProvider
else if (isMediaDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
Expand All @@ -99,16 +80,12 @@ else if (isMediaDocument(uri)) {
return getDataColumn(context, contentUri, selection, selectionArgs);
}
}
// MediaStore (and general)
else if ("content".equalsIgnoreCase(uri.getScheme())) {

// Return the remote address
if (isGooglePhotosUri(uri))
return uri.getLastPathSegment();

return getDataColumn(context, uri, null, null);
}
// File
else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
Expand Down

0 comments on commit e29aac1

Please # to comment.