Search in sources :

Example 6 with ImageMedia

use of com.bilibili.boxing.model.entity.impl.ImageMedia in project boxing by Bilibili.

the class ImageTask method addItem.

private void addItem(final int allCount, final List<ImageMedia> result, Cursor cursor, @NonNull final IMediaTaskCallback<ImageMedia> callback) {
    if (cursor != null && cursor.moveToFirst()) {
        do {
            String picPath = cursor.getString(cursor.getColumnIndex(Images.Media.DATA));
            if (callback.needFilter(picPath)) {
                BoxingLog.d("path:" + picPath + " has been filter");
            } else {
                String id = cursor.getString(cursor.getColumnIndex(Images.Media._ID));
                String size = cursor.getString(cursor.getColumnIndex(Images.Media.SIZE));
                String mimeType = cursor.getString(cursor.getColumnIndex(Images.Media.MIME_TYPE));
                int width = 0;
                int height = 0;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    width = cursor.getInt(cursor.getColumnIndex(Images.Media.WIDTH));
                    height = cursor.getInt(cursor.getColumnIndex(Images.Media.HEIGHT));
                }
                ImageMedia imageItem = new ImageMedia.Builder(id, picPath).setThumbnailPath(mThumbnailMap.get(id)).setSize(size).setMimeType(mimeType).setHeight(height).setWidth(width).build();
                if (!result.contains(imageItem)) {
                    result.add(imageItem);
                }
            }
        } while (!cursor.isLast() && cursor.moveToNext());
        postMedias(result, allCount, callback);
    } else {
        postMedias(result, 0, callback);
    }
    clear();
}
Also used : ImageMedia(com.bilibili.boxing.model.entity.impl.ImageMedia)

Example 7 with ImageMedia

use of com.bilibili.boxing.model.entity.impl.ImageMedia in project boxing by Bilibili.

the class PickerPresenterTest method checkSelectedMedia.

@Test
public void checkSelectedMedia() {
    List<BaseMedia> allMedias = new ArrayList<>();
    allMedias.add(new ImageMedia.Builder("1", "test1").setSelected(true).build());
    allMedias.add(new ImageMedia.Builder("2", "test2").setSelected(false).build());
    allMedias.add(new ImageMedia.Builder("3", "test3").build());
    List<BaseMedia> selectedMedias = new ArrayList<>();
    selectedMedias.add(new ImageMedia.Builder("2", "test2").setSelected(true).build());
    mPresenter.checkSelectedMedia(allMedias, selectedMedias);
    ImageMedia imageMedia0 = (ImageMedia) allMedias.get(0);
    ImageMedia imageMedia1 = (ImageMedia) allMedias.get(1);
    ImageMedia imageMedia2 = (ImageMedia) allMedias.get(2);
    Assert.assertTrue(!imageMedia0.isSelected());
    Assert.assertTrue(imageMedia1.isSelected());
    Assert.assertTrue(!imageMedia2.isSelected());
    mPresenter.checkSelectedMedia(null, null);
}
Also used : ImageMedia(com.bilibili.boxing.model.entity.impl.ImageMedia) ArrayList(java.util.ArrayList) BaseMedia(com.bilibili.boxing.model.entity.BaseMedia) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)

Example 8 with ImageMedia

use of com.bilibili.boxing.model.entity.impl.ImageMedia in project boxing by Bilibili.

the class PickerPresenterTest method loadImages.

@Test
public void loadImages() {
    Mockito.when(mPickerManager.getBoxingConfig()).thenReturn(new BoxingConfig(BoxingConfig.Mode.MULTI_IMG));
    mPresenter.loadMedias(0, "");
    Mockito.verify(mPickerManager).loadMedia(any(ContentResolver.class), ArgumentCaptor.forClass(Integer.class).capture(), ArgumentCaptor.forClass(String.class).capture(), mLoadMediaCallback.capture());
    List<ImageMedia> imageMedias = new ArrayList<>();
    imageMedias.add(new ImageMedia.Builder("1", "test1").build());
    imageMedias.add(new ImageMedia.Builder("2", "test2").build());
    imageMedias.add(new ImageMedia.Builder("3", "test3").build());
    imageMedias.add(new ImageMedia.Builder("4", "test4").build());
    mLoadMediaCallback.getValue().postMedia(imageMedias, 4);
    ArgumentCaptor<List> showVideoCaptor = ArgumentCaptor.forClass(List.class);
    Mockito.verify(mView).showMedia(showVideoCaptor.capture(), anyInt());
    System.out.print("load video count:" + showVideoCaptor.getValue().size());
    Assert.assertTrue(showVideoCaptor.getValue().size() == 4);
    Assert.assertTrue(showVideoCaptor.getValue().get(0).equals(imageMedias.get(0)));
    Assert.assertTrue(showVideoCaptor.getValue().get(1).equals(imageMedias.get(1)));
}
Also used : BoxingConfig(com.bilibili.boxing.model.config.BoxingConfig) ImageMedia(com.bilibili.boxing.model.entity.impl.ImageMedia) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ContentResolver(android.content.ContentResolver) MockContentResolver(android.test.mock.MockContentResolver) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)

Example 9 with ImageMedia

use of com.bilibili.boxing.model.entity.impl.ImageMedia in project boxing by Bilibili.

the class PickerUtilTest method testCompressTask.

@Test
public void testCompressTask() {
    ImageCompressor illegalCompressor = new ImageCompressor(new File("///"));
    ImageMedia media = new ImageMedia("123", "44");
    ImageCompressor compressor = new ImageCompressor(new File("src/main/res/"));
    ImageMedia media1 = new ImageMedia("1223", "../boxing-impl/src/main/res/drawable-hdpi/ic_camera.png");
    media1.setSize("233");
    boolean result1 = CompressTask.compress(null, null, 0);
    assertTrue(!result1);
    result1 = CompressTask.compress(null, media, 0);
    assertTrue(!result1);
    result1 = CompressTask.compress(illegalCompressor, media, 0);
    assertTrue(!result1);
    result1 = CompressTask.compress(illegalCompressor, media, 1000);
    assertTrue(!result1);
    result1 = CompressTask.compress(compressor, media1, 1000);
    assertTrue(result1);
}
Also used : ImageCompressor(com.bilibili.boxing.utils.ImageCompressor) ImageMedia(com.bilibili.boxing.model.entity.impl.ImageMedia) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)

Example 10 with ImageMedia

use of com.bilibili.boxing.model.entity.impl.ImageMedia in project boxing by Bilibili.

the class PickerModuleTest method testBaseMedia.

@Test
public void testBaseMedia() {
    BaseMedia media = new ImageMedia("233", "988");
    assertTrue(media.getId().equals("233"));
    assertTrue(media.getPath().equals("988"));
    media.setSize("99");
    assertTrue(media.getSize() == 99);
    media.setSize("&&");
    assertTrue(media.getSize() == 0);
    media.setSize("-1");
    assertTrue(media.getSize() == 0);
}
Also used : ImageMedia(com.bilibili.boxing.model.entity.impl.ImageMedia) BaseMedia(com.bilibili.boxing.model.entity.BaseMedia) Test(org.junit.Test)

Aggregations

ImageMedia (com.bilibili.boxing.model.entity.impl.ImageMedia)15 BaseMedia (com.bilibili.boxing.model.entity.BaseMedia)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 BoxingConfig (com.bilibili.boxing.model.config.BoxingConfig)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)3 Intent (android.content.Intent)2 Cursor (android.database.Cursor)2 Uri (android.net.Uri)2 BoxingCropOption (com.bilibili.boxing.model.config.BoxingCropOption)2 BoxingActivity (com.bilibili.boxing_impl.ui.BoxingActivity)2 ContentResolver (android.content.ContentResolver)1 MockContentResolver (android.test.mock.MockContentResolver)1 AlbumEntity (com.bilibili.boxing.model.entity.AlbumEntity)1 ImageCompressor (com.bilibili.boxing.utils.ImageCompressor)1 File (java.io.File)1 HashMap (java.util.HashMap)1 List (java.util.List)1