Skip to content

Commit

Permalink
Update file utils
Browse files Browse the repository at this point in the history
  • Loading branch information
billthefarmer committed Jan 24, 2018
1 parent d59d5d9 commit 36c3a52
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 85 deletions.
91 changes: 7 additions & 84 deletions src/main/java/org/billthefarmer/editor/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ private void readFile(Uri uri)
if (uri.getScheme().equalsIgnoreCase(CONTENT))
uri = resolveContent(uri);

// Read using ContentResolver
// Read into default file
if (uri.getScheme().equalsIgnoreCase(CONTENT))
{
file = getDefaultFile();
Expand All @@ -1156,11 +1156,6 @@ private void readFile(Uri uri)

String title = defaultUri.getLastPathSegment();
setTitle(title);

textView.setText(R.string.loading);

ReadUriTask read = new ReadUriTask();
read.execute(uri);
}

// Read file
Expand All @@ -1171,12 +1166,12 @@ private void readFile(Uri uri)

String title = uri.getLastPathSegment();
setTitle(title);
}

textView.setText(R.string.loading);
textView.setText(R.string.loading);

ReadFileTask read = new ReadFileTask();
read.execute(file);
}
ReadTask read = new ReadTask();
read.execute(uri);

dirty = false;
modified = file.lastModified();
Expand Down Expand Up @@ -1355,8 +1350,8 @@ public boolean onQueryTextSubmit (String query)
}
}

// ReadUriTask
private class ReadUriTask
// ReadTask
private class ReadTask
extends AsyncTask<Uri, Void, String>
{
// doInBackground
Expand Down Expand Up @@ -1429,76 +1424,4 @@ public void run()
invalidateOptionsMenu();
}
}

// ReadFileTask
private class ReadFileTask
extends AsyncTask<File, Void, String>
{
// doInBackground
@Override
protected String doInBackground(File... params)
{
StringBuilder stringBuilder = new StringBuilder();
try
{
FileReader fileReader = new FileReader(params[0]);
BufferedReader reader = new BufferedReader(fileReader);

String line;
while ((line = reader.readLine()) != null)
{
stringBuilder.append(line);
stringBuilder.append(System.getProperty("line.separator"));
}

fileReader.close();
}

catch (Exception e) {}

return stringBuilder.toString();
}

// onPostExecute
@Override
protected void onPostExecute(String result)
{
if (textView != null)
textView.setText(result);

if (toAppend != null)
{
textView.append(toAppend);
toAppend = null;
dirty = true;
}

else
dirty = false;

// Check for saved position
if (pathMap.containsKey(path))
{
textView.postDelayed(new Runnable()
{
// run
@Override
public void run()
{
scrollView.smoothScrollTo(0, pathMap.get(path));
}
}, POSN_DELAY);
}

// Set read only
textView.setRawInputType(InputType.TYPE_NULL);
textView.clearFocus();

// Update boolean
edit = false;

// Update menu
invalidateOptionsMenu();
}
}
}
21 changes: 20 additions & 1 deletion src/main/java/org/billthefarmer/editor/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public static String getPath(final Context context, final Uri uri)
{

if (BuildConfig.DEBUG)
Log.d(TAG + " File -",
Log.d(TAG + " File",
"Authority: " + uri.getAuthority() +
", Fragment: " + uri.getFragment() +
", Port: " + uri.getPort() +
Expand Down Expand Up @@ -427,6 +427,25 @@ else if ("audio".equals(type))
// MediaStore (and general)
else if ("content".equalsIgnoreCase(uri.getScheme()))
{
if (BuildConfig.DEBUG)
{
Cursor cursor = null;
try
{
cursor = context.getContentResolver()
.query(uri, null, null, null, null);
if (cursor != null && cursor.moveToFirst())
DatabaseUtils.dumpCursor(cursor);
}

catch (Exception e) {}

finally
{
if (cursor != null)
cursor.close();
}
}

// Return the remote address
if (isGooglePhotosUri(uri))
Expand Down

0 comments on commit 36c3a52

Please sign in to comment.