Skip to content

Commit

Permalink
Remove brittle and unnecessary file extension check for user style
Browse files Browse the repository at this point in the history
Intent to initiate content open already specifies text/* content type,
and Android 11 no longer returns file names as URIs.
  • Loading branch information
itkach committed Dec 28, 2021
1 parent 647f9a7 commit d84b375
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/itkach/aard2/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v4.provider.DocumentFile;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
Expand Down Expand Up @@ -69,19 +70,13 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
Uri dataUri = data == null ? null : data.getData();
Log.d(TAG, String.format("req code %s, result code: %s, data: %s", requestCode, resultCode, dataUri));
if (resultCode == Activity.RESULT_OK && dataUri != null) {
String path = dataUri.getPath().toLowerCase();
if (!(path.endsWith(".css") || path.endsWith(".txt"))) {
Log.d(TAG, "Doesn't appear to be a css: " + dataUri);
Toast.makeText(getActivity(), R.string.msg_file_not_css,
Toast.LENGTH_LONG).show();
return;
}
try {
InputStream is = getActivity().getContentResolver().openInputStream(dataUri);
DocumentFile documentFile = DocumentFile.fromSingleUri(getContext(), dataUri);
String fileName = documentFile.getName();
Application app = (Application)getActivity().getApplication();
String userCss = app.readTextFile(is, 256 * 1024);
List<String> pathSegments = dataUri.getPathSegments();
String fileName = pathSegments.get(pathSegments.size() - 1);
Log.d(TAG, fileName);
Log.d(TAG, userCss);
int lastIndexOfDot = fileName.lastIndexOf(".");
Expand Down

0 comments on commit d84b375

Please sign in to comment.