Skip to content

Commit

Permalink
优化 TransferConfig 的参数配置代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Hitomis committed Jun 15, 2017
1 parent 54f5f3b commit 5bf684f
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 92 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ tranferee 查看图组一那么传递 originImageList 值时,originImageList
+ [ ] 支持下拉手势关闭 transferee
+ [x] 支持扩展图片保存、收藏等相关操作
+ [ ] 优化单个图片使用 transferee 的场景
+ [ ] 优化 TransferConfig 的参数配置。将固定不变的配置项从每次的参数对象创建中分离开来
+ [x] 优化 TransferConfig 的参数配置。将固定不变的配置项从每次的参数对象创建中分离开来

# Licence
Copyright 2017 Hitomis, Inc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* <p>
* email: [email protected]
*/
public class TransferConfig {
public final class TransferConfig {
private int nowThumbnailIndex;
private int offscreenPageLimit;
private int missPlaceHolder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.widget.Toast;

import com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable;
import com.hitomi.tilibrary.transfer.TransferConfig;
import com.hitomi.tilibrary.transfer.Transferee;

import java.util.ArrayList;
Expand All @@ -31,6 +32,8 @@ public abstract class BaseActivity extends AppCompatActivity {
protected static final int WRITE_EXTERNAL_STORAGE = 101;

protected Transferee transferee;
protected TransferConfig config;

protected GridView gvImages;
protected List<String> thumbnailImageList;
protected List<String> sourceImageList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,30 @@ protected void testTransferee() {
READ_EXTERNAL_STORAGE);
} else {
images = getLatestPhotoPaths(9);
initTransfereeConfig();
if (images != null && !images.isEmpty())
gvImages.setAdapter(new GlideLocalActivity.NineGridAdapter());
}

}

private void initTransfereeConfig() {
config = TransferConfig.build()
.setSourceImageList(images)
.setMissPlaceHolder(R.mipmap.ic_empty_photo)
.setErrorPlaceHolder(R.mipmap.ic_empty_photo)
.setProgressIndicator(new ProgressBarIndicator())
.setIndexIndicator(new NumberIndexIndicator())
.setJustLoadHitImage(true)
.setImageLoader(GlideImageLoader.with(getApplicationContext()))
.create();
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == READ_EXTERNAL_STORAGE) {
images = getLatestPhotoPaths(9);
initTransfereeConfig();
if (images != null && !images.isEmpty())
gvImages.setAdapter(new GlideLocalActivity.NineGridAdapter());
} else {
Expand Down Expand Up @@ -132,17 +146,8 @@ protected void convert(ViewHolder viewHolder, String item, final int position) {
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TransferConfig config = TransferConfig.build()
.setNowThumbnailIndex(position)
.setSourceImageList(images)
.setMissPlaceHolder(R.mipmap.ic_empty_photo)
.setErrorPlaceHolder(R.mipmap.ic_empty_photo)
.setOriginImageList(wrapOriginImageViewList(images.size()))
.setProgressIndicator(new ProgressBarIndicator())
.setIndexIndicator(new NumberIndexIndicator())
.setJustLoadHitImage(true)
.setImageLoader(GlideImageLoader.with(getApplicationContext()))
.create();
config.setNowThumbnailIndex(position);
config.setOriginImageList(wrapOriginImageViewList(images.size()));

transferee.apply(config).show(new Transferee.OnTransfereeStateChangeListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ protected void initView() {

@Override
protected void testTransferee() {
config = TransferConfig.build()
.setSourceImageList(sourceImageList)
.setMissPlaceHolder(R.mipmap.ic_empty_photo)
.setProgressIndicator(new ProgressPieIndicator())
.setImageLoader(GlideImageLoader.with(getApplicationContext()))
.setOnLongClcikListener(new Transferee.OnTransfereeLongClickListener() {
@Override
public void onLongClick(ImageView imageView, int pos) {
saveImageByGlide(imageView);
}
})
.create();

gvImages.setAdapter(new NineGridAdapter());
}
Expand Down Expand Up @@ -75,20 +87,8 @@ protected void convert(ViewHolder viewHolder, String item, final int position) {
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TransferConfig config = TransferConfig.build()
.setNowThumbnailIndex(position)
.setSourceImageList(sourceImageList)
.setMissPlaceHolder(R.mipmap.ic_empty_photo)
.setOriginImageList(wrapOriginImageViewList(sourceImageList.size()))
.setProgressIndicator(new ProgressPieIndicator())
.setImageLoader(GlideImageLoader.with(getApplicationContext()))
.setOnLongClcikListener(new Transferee.OnTransfereeLongClickListener() {
@Override
public void onLongClick(ImageView imageView, int pos) {
saveImageByGlide(imageView);
}
})
.create();
config.setNowThumbnailIndex(position);
config.setOriginImageList(wrapOriginImageViewList(sourceImageList.size()));

transferee.apply(config).show(new Transferee.OnTransfereeStateChangeListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ protected void initView() {

@Override
protected void testTransferee() {
config = TransferConfig.build()
.setImageLoader(GlideImageLoader.with(getApplicationContext()))
.setMissPlaceHolder(R.mipmap.ic_empty_photo)
.setOriginImageList(imageViewList)
.setSourceImageList(imageStrList)
.setProgressIndicator(new ProgressBarIndicator())
.setJustLoadHitImage(true)
.setOnLongClcikListener(new Transferee.OnTransfereeLongClickListener() {
@Override
public void onLongClick(ImageView imageView, int pos) {
saveImageByGlide(imageView);
}
})
.create();

Glide.with(this)
.load(imageStrList.get(0))
.placeholder(R.mipmap.ic_empty_photo)
Expand All @@ -85,22 +100,8 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
private class ShowViewHDListener implements View.OnClickListener {
@Override
public void onClick(View v) {

transferee.apply(TransferConfig.build()
.setImageLoader(GlideImageLoader.with(getApplicationContext()))
.setMissPlaceHolder(R.mipmap.ic_empty_photo)
.setOriginImageList(imageViewList)
.setSourceImageList(imageStrList)
.setNowThumbnailIndex(imageViewList.indexOf(v))
.setProgressIndicator(new ProgressBarIndicator())
.setJustLoadHitImage(true)
.setOnLongClcikListener(new Transferee.OnTransfereeLongClickListener() {
@Override
public void onLongClick(ImageView imageView, int pos) {
saveImageByGlide(imageView);
}
})
.create())
config.setNowThumbnailIndex(imageViewList.indexOf(v));
transferee.apply(config)
.show(new Transferee.OnTransfereeStateChangeListener() {
@Override
public void onShow() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,34 @@ protected void testTransferee() {
READ_EXTERNAL_STORAGE);
} else {
images = getLatestPhotoPaths(9);
if (images != null && !images.isEmpty())
if (images != null && !images.isEmpty()) {
initTransfereeConfig();
gvImages.setAdapter(new UniversalLocalActivity.NineGridAdapter());
}
}
}

private void initTransfereeConfig() {
config = TransferConfig.build()
.setSourceImageList(images)
.setThumbnailImageList(images)
.setMissPlaceHolder(R.mipmap.ic_empty_photo)
.setErrorPlaceHolder(R.mipmap.ic_empty_photo)
.setProgressIndicator(new ProgressBarIndicator())
.setIndexIndicator(new NumberIndexIndicator())
.setJustLoadHitImage(true)
.setImageLoader(UniversalImageLoader.with(getApplicationContext()))
.create();
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == READ_EXTERNAL_STORAGE) {
images = getLatestPhotoPaths(9);
if (images != null && !images.isEmpty())
if (images != null && !images.isEmpty()) {
initTransfereeConfig();
gvImages.setAdapter(new UniversalLocalActivity.NineGridAdapter());
}
} else {
Toast.makeText(this, "请允许获取相册图片文件访问权限", Toast.LENGTH_SHORT).show();
}
Expand Down Expand Up @@ -132,18 +149,8 @@ private void bindTransferee(ImageView imageView, final int position) {
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TransferConfig config = TransferConfig.build()
.setNowThumbnailIndex(position)
.setSourceImageList(images)
.setThumbnailImageList(images)
.setMissPlaceHolder(R.mipmap.ic_empty_photo)
.setErrorPlaceHolder(R.mipmap.ic_empty_photo)
.setOriginImageList(wrapOriginImageViewList(images.size()))
.setProgressIndicator(new ProgressBarIndicator())
.setIndexIndicator(new NumberIndexIndicator())
.setJustLoadHitImage(true)
.setImageLoader(UniversalImageLoader.with(getApplicationContext()))
.create();
config.setNowThumbnailIndex(position);
config.setOriginImageList(wrapOriginImageViewList(images.size()));
transferee.apply(config).show();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ protected void testTransferee() {
.resetViewBeforeLoading(true)
.build();

config = TransferConfig.build()
.setSourceImageList(sourceImageList)
.setMissPlaceHolder(R.mipmap.ic_empty_photo)
.setErrorPlaceHolder(R.mipmap.ic_empty_photo)
.setProgressIndicator(new ProgressBarIndicator())
.setIndexIndicator(new NumberIndexIndicator())
.setImageLoader(UniversalImageLoader.with(getApplicationContext()))
.setJustLoadHitImage(true)
.setOnLongClcikListener(new Transferee.OnTransfereeLongClickListener() {
@Override
public void onLongClick(ImageView imageView, int pos) {
saveImageByUniversal(imageView);
}
})
.create();

gvImages.setAdapter(new UniversalNoThumActivity.NineGridAdapter());
}

Expand All @@ -83,23 +99,8 @@ protected void convert(ViewHolder viewHolder, String item, final int position) {
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TransferConfig config = TransferConfig.build()
.setNowThumbnailIndex(position)
.setSourceImageList(sourceImageList)
.setMissPlaceHolder(R.mipmap.ic_empty_photo)
.setErrorPlaceHolder(R.mipmap.ic_empty_photo)
.setOriginImageList(wrapOriginImageViewList(sourceImageList.size()))
.setProgressIndicator(new ProgressBarIndicator())
.setIndexIndicator(new NumberIndexIndicator())
.setImageLoader(UniversalImageLoader.with(getApplicationContext()))
.setJustLoadHitImage(true)
.setOnLongClcikListener(new Transferee.OnTransfereeLongClickListener() {
@Override
public void onLongClick(ImageView imageView, int pos) {
saveImageByUniversal(imageView);
}
})
.create();
config.setNowThumbnailIndex(position);
config.setOriginImageList(wrapOriginImageViewList(sourceImageList.size()));
transferee.apply(config).show();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ protected void testTransferee() {
.resetViewBeforeLoading(true)
.build();

config = TransferConfig.build()
.setSourceImageList(sourceImageList)
.setThumbnailImageList(thumbnailImageList)
.setMissPlaceHolder(R.mipmap.ic_empty_photo)
.setErrorPlaceHolder(R.mipmap.ic_empty_photo)
.setProgressIndicator(new ProgressPieIndicator())
.setIndexIndicator(new NumberIndexIndicator())
.setJustLoadHitImage(true)
.setImageLoader(UniversalImageLoader.with(getApplicationContext()))
.setOnLongClcikListener(new Transferee.OnTransfereeLongClickListener() {
@Override
public void onLongClick(ImageView imageView, int pos) {
saveImageByUniversal(imageView);
}
})
.create();

gvImages.setAdapter(new UniversalNormalActivity.NineGridAdapter());
}

Expand Down Expand Up @@ -118,24 +135,8 @@ private void bindTransferee(ImageView imageView, final int position) {
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TransferConfig config = TransferConfig.build()
.setNowThumbnailIndex(position)
.setSourceImageList(sourceImageList)
.setThumbnailImageList(thumbnailImageList)
.setMissPlaceHolder(R.mipmap.ic_empty_photo)
.setErrorPlaceHolder(R.mipmap.ic_empty_photo)
.setOriginImageList(wrapOriginImageViewList(thumbnailImageList.size()))
.setProgressIndicator(new ProgressPieIndicator())
.setIndexIndicator(new NumberIndexIndicator())
.setJustLoadHitImage(true)
.setImageLoader(UniversalImageLoader.with(getApplicationContext()))
.setOnLongClcikListener(new Transferee.OnTransfereeLongClickListener() {
@Override
public void onLongClick(ImageView imageView, int pos) {
saveImageByUniversal(imageView);
}
})
.create();
config.setNowThumbnailIndex(position);
config.setOriginImageList(wrapOriginImageViewList(thumbnailImageList.size()));
transferee.apply(config).show();
}
});
Expand Down

0 comments on commit 5bf684f

Please sign in to comment.