Search in sources :

Example 1 with ImageMedia

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

the class PickerModuleTest method testImageMedia.

@Test
public void testImageMedia() {
    ImageMedia imageMedia = new ImageMedia.Builder("233", "233").build();
    imageMedia.setPath("/");
    imageMedia.getThumbnailPath();
    String compressPath = imageMedia.getThumbnailPath();
    assertEquals(compressPath, "/");
    imageMedia.setCompressPath("111");
    String compressPath1 = imageMedia.getThumbnailPath();
    assertEquals(compressPath1, "/");
    imageMedia = new ImageMedia.Builder("233", "233").setThumbnailPath("999").build();
    String compressPath3 = imageMedia.getThumbnailPath();
    assertEquals(compressPath3, "233");
    assertEquals(imageMedia.getMimeType(), "image/jpeg");
    imageMedia.setImageType(ImageMedia.IMAGE_TYPE.GIF);
    assertEquals(imageMedia.getMimeType(), "image/gif");
}
Also used : ImageMedia(com.bilibili.boxing.model.entity.impl.ImageMedia) Test(org.junit.Test)

Example 2 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/boxing-impl/src/main/res/drawable-hdpi/ic_boxing_broken_image.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 3 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 4 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 5 with ImageMedia

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

the class BoxingMediaAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof CameraViewHolder) {
        CameraViewHolder viewHolder = (CameraViewHolder) holder;
        viewHolder.mCameraLayout.setOnClickListener(mOnCameraClickListener);
        viewHolder.mCameraImg.setImageResource(BoxingResHelper.getCameraRes());
    } else {
        int pos = position - mOffset;
        final BaseMedia media = mMedias.get(pos);
        final ImageViewHolder vh = (ImageViewHolder) holder;
        vh.mItemLayout.setImageRes(mDefaultRes);
        vh.mItemLayout.setTag(media);
        vh.mItemLayout.setOnClickListener(mOnMediaClickListener);
        vh.mItemLayout.setTag(R.id.media_item_check, pos);
        vh.mItemLayout.setMedia(media);
        vh.mItemChecked.setVisibility(mMultiImageMode ? View.VISIBLE : View.GONE);
        if (mMultiImageMode && media instanceof ImageMedia) {
            vh.mItemLayout.setChecked(((ImageMedia) media).isSelected());
            vh.mItemChecked.setTag(R.id.media_layout, vh.mItemLayout);
            vh.mItemChecked.setTag(media);
            vh.mItemChecked.setOnClickListener(mOnCheckListener);
        }
    }
}
Also used : ImageMedia(com.bilibili.boxing.model.entity.impl.ImageMedia) BaseMedia(com.bilibili.boxing.model.entity.BaseMedia)

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