Search in sources :

Example 6 with RequestFile

use of forpdateam.ru.forpda.api.RequestFile in project ForPDA by RadiationX.

the class FilePickHelper method onActivityResult.

public static List<RequestFile> onActivityResult(Context context, Intent data) {
    List<RequestFile> files = new ArrayList<>();
    RequestFile tempFile;
    Log.d(LOG_TAG, "onActivityResult " + data);
    if (data.getData() == null) {
        if (data.getClipData() != null) {
            for (int i = 0; i < data.getClipData().getItemCount(); i++) {
                tempFile = createFile(context, data.getClipData().getItemAt(i).getUri());
                if (tempFile != null)
                    files.add(tempFile);
            }
        }
    } else {
        tempFile = createFile(context, data.getData());
        if (tempFile != null)
            files.add(tempFile);
    }
    return files;
}
Also used : ArrayList(java.util.ArrayList) RequestFile(forpdateam.ru.forpda.api.RequestFile)

Example 7 with RequestFile

use of forpdateam.ru.forpda.api.RequestFile in project ForPDA by RadiationX.

the class NotesFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (data == null) {
            // Display an error
            return;
        }
        if (requestCode == REQUEST_PICK_FILE) {
            List<RequestFile> files = FilePickHelper.onActivityResult(getContext(), data);
            RequestFile file = files.get(0);
            if (file.getFileName().matches("[\\s\\S]*?\\.json$")) {
                BufferedReader r = new BufferedReader(new InputStreamReader(file.getFileStream()));
                StringBuilder total = new StringBuilder();
                String line;
                try {
                    while ((line = r.readLine()) != null) {
                        total.append(line).append('\n');
                    }
                    r.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    Toast.makeText(getContext(), "Ошибка при чтении файла", Toast.LENGTH_SHORT).show();
                }
                importNotes(total.toString());
            } else {
                Toast.makeText(getContext(), "Файл имеет неправильное расширение", Toast.LENGTH_SHORT).show();
            }
        } else if (requestCode == REQUEST_SAVE_FILE) {
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) RequestFile(forpdateam.ru.forpda.api.RequestFile) IOException(java.io.IOException)

Aggregations

RequestFile (forpdateam.ru.forpda.api.RequestFile)7 AttachmentItem (forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)4 NetworkRequest (forpdateam.ru.forpda.api.NetworkRequest)3 NetworkResponse (forpdateam.ru.forpda.api.NetworkResponse)3 ArrayList (java.util.ArrayList)3 Matcher (java.util.regex.Matcher)3 InputStream (java.io.InputStream)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 MessageDigest (java.security.MessageDigest)1 HashMap (java.util.HashMap)1 JSONObject (org.json.JSONObject)1