Search in sources :

Example 6 with DocumentFile

use of androidx.documentfile.provider.DocumentFile in project kdeconnect-android by KDE.

the class CompositeReceiveFileJob method openFile.

private void openFile(DocumentFile fileDocument) {
    String mimeType = FilesHelper.getMimeTypeFromFile(fileDocument.getName());
    Intent intent = new Intent(Intent.ACTION_VIEW);
    if (Build.VERSION.SDK_INT >= 24) {
        // Nougat and later require "content://" uris instead of "file://" uris
        File file = new File(fileDocument.getUri().getPath());
        Uri contentUri = FileProvider.getUriForFile(getDevice().getContext(), "org.kde.kdeconnect_tp.fileprovider", file);
        intent.setDataAndType(contentUri, mimeType);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
    } else {
        intent.setDataAndType(fileDocument.getUri(), mimeType);
    }
    // Open files for KDE Itinerary explicitly because Android's activity resolution sucks
    if (fileDocument.getName().endsWith(".itinerary")) {
        intent.setClassName("org.kde.itinerary", "org.kde.itinerary.Activity");
    }
    getDevice().getContext().startActivity(intent);
}
Also used : Intent(android.content.Intent) File(java.io.File) DocumentFile(androidx.documentfile.provider.DocumentFile) Uri(android.net.Uri)

Example 7 with DocumentFile

use of androidx.documentfile.provider.DocumentFile in project AntennaPod by AntennaPod.

the class LocalFeedUpdaterTest method callUpdateFeed.

/**
 * Calls the method {@link LocalFeedUpdater#updateFeed(Feed, Context)} with
 * the given local feed folder.
 *
 * @param localFeedDir assets local feed folder with media files
 */
private void callUpdateFeed(@NonNull String localFeedDir) {
    DocumentFile documentFile = new AssetsDocumentFile(localFeedDir, context.getAssets());
    try (MockedStatic<DocumentFile> dfMock = Mockito.mockStatic(DocumentFile.class)) {
        // mock external storage
        dfMock.when(() -> DocumentFile.fromTreeUri(any(), any())).thenReturn(documentFile);
        // call method to test
        Feed feed = new Feed(FEED_URL, null);
        LocalFeedUpdater.updateFeed(feed, context);
    }
}
Also used : DocumentFile(androidx.documentfile.provider.DocumentFile) AssetsDocumentFile(androidx.documentfile.provider.AssetsDocumentFile) AssetsDocumentFile(androidx.documentfile.provider.AssetsDocumentFile) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 8 with DocumentFile

use of androidx.documentfile.provider.DocumentFile in project AntennaPod by AntennaPod.

the class LocalFeedUpdaterTest method testGetImageUrl_OtherImageFilenamePng.

@Test
public void testGetImageUrl_OtherImageFilenamePng() {
    DocumentFile documentFolder = mockDocumentFolder(mockDocumentFile("audio.mp3", "audio/mp3"), mockDocumentFile("my-image.png", "image/png"));
    String imageUrl = LocalFeedUpdater.getImageUrl(context, documentFolder);
    assertThat(imageUrl, endsWith("my-image.png"));
}
Also used : DocumentFile(androidx.documentfile.provider.DocumentFile) AssetsDocumentFile(androidx.documentfile.provider.AssetsDocumentFile) Test(org.junit.Test)

Example 9 with DocumentFile

use of androidx.documentfile.provider.DocumentFile in project AntennaPod by AntennaPod.

the class LocalFeedUpdaterTest method mockDocumentFile.

/**
 * Create a DocumentFile mock object.
 */
@NonNull
private static DocumentFile mockDocumentFile(@NonNull String fileName, @NonNull String mimeType) {
    DocumentFile file = mock(DocumentFile.class);
    when(file.getName()).thenReturn(fileName);
    when(file.getUri()).thenReturn(Uri.parse("file:///path/" + fileName));
    when(file.getType()).thenReturn(mimeType);
    return file;
}
Also used : DocumentFile(androidx.documentfile.provider.DocumentFile) AssetsDocumentFile(androidx.documentfile.provider.AssetsDocumentFile) NonNull(androidx.annotation.NonNull)

Example 10 with DocumentFile

use of androidx.documentfile.provider.DocumentFile in project AntennaPod by AntennaPod.

the class LocalFeedUpdaterTest method testGetImageUrl_OtherImageFilenameJpeg.

@Test
public void testGetImageUrl_OtherImageFilenameJpeg() {
    DocumentFile documentFolder = mockDocumentFolder(mockDocumentFile("audio.mp3", "audio/mp3"), mockDocumentFile("my-image.jpeg", "image/jpeg"));
    String imageUrl = LocalFeedUpdater.getImageUrl(context, documentFolder);
    assertThat(imageUrl, endsWith("my-image.jpeg"));
}
Also used : DocumentFile(androidx.documentfile.provider.DocumentFile) AssetsDocumentFile(androidx.documentfile.provider.AssetsDocumentFile) Test(org.junit.Test)

Aggregations

DocumentFile (androidx.documentfile.provider.DocumentFile)32 Uri (android.net.Uri)12 AssetsDocumentFile (androidx.documentfile.provider.AssetsDocumentFile)10 Test (org.junit.Test)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)5 OutputStream (java.io.OutputStream)3 Intent (android.content.Intent)2 NonNull (androidx.annotation.NonNull)2 RequiresApi (androidx.annotation.RequiresApi)2 Feed (de.danoeh.antennapod.model.feed.Feed)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 FullBackupExporter (org.thoughtcrime.securesms.backup.FullBackupExporter)2 NotificationController (org.thoughtcrime.securesms.service.NotificationController)2 Instrumentation (android.app.Instrumentation)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1