Skip to content

Commit

Permalink
fix #258
Browse files Browse the repository at this point in the history
  • Loading branch information
郑梓斌 committed Jun 22, 2018
1 parent f5c646a commit a9c10e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
12 changes: 11 additions & 1 deletion example/src/main/java/top/zibin/luban/example/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
case R.id.sync_files:
withRx(assetsToFiles());
List<File> list = new ArrayList<>();
list.add(new File("/data/user/0/1529400069961674"));
originPhotos.addAll(list);
withRx(list);
break;
case R.id.sync_uris:
withRx(assetsToUri());
Expand Down Expand Up @@ -143,6 +146,13 @@ public List<File> apply(@NonNull List<T> list) throws Exception {
}
})
.observeOn(AndroidSchedulers.mainThread())
.doOnError(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) {
Log.e(TAG, throwable.getMessage());
}
})
.onErrorResumeNext(Flowable.<List<File>>empty())
.subscribe(new Consumer<List<File>>() {
@Override
public void accept(@NonNull List<File> list) {
Expand Down
25 changes: 15 additions & 10 deletions library/src/main/java/top/zibin/luban/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,24 @@ && pack(jpeg, offset + 6, 2, false) == 0) {
return 0;
}

String extSuffix(InputStreamProvider input) throws IOException {
Bitmap bitmap = BitmapFactory.decodeStream(input.open(), null, new BitmapFactory.Options());
String suffix = TextUtils.isEmpty(input.getPath()) ? "" : input.getPath().substring(input.getPath().lastIndexOf("."), input.getPath().length());
String extSuffix(InputStreamProvider input) {
try {
Bitmap bitmap = BitmapFactory.decodeStream(input.open(), null, new BitmapFactory.Options());
String suffix = TextUtils.isEmpty(input.getPath()) ? "" :
input.getPath().substring(input.getPath().lastIndexOf("."), input.getPath().length());

if (bitmap.hasAlpha()) {
return PNG;
} else if (TextUtils.isEmpty(suffix)) {
return JPG;
} else if (!format.contains(suffix)) {
return JPG;
}

if (bitmap.hasAlpha()) {
return PNG;
} else if (TextUtils.isEmpty(suffix)) {
return JPG;
} else if (!format.contains(suffix)) {
return suffix;
} catch (Exception e) {
return JPG;
}

return suffix;
}

boolean needCompress(int leastCompressSize, String path) {
Expand Down

0 comments on commit a9c10e0

Please sign in to comment.