Fix image extension
This commit is contained in:
7 files changed
+87
-4
No files matched your search
@@ -157,6 +157,13 @@ public class ArchiveGalleryProvider extends GalleryProvider2 {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getImageFilenameWithExtension(int index) {
|
||||
// TODO
|
||||
return Integer.toString(index);
|
||||
}
|
||||
|
||||
private class ArchiveTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -125,8 +125,33 @@ public class DirGalleryProvider extends GalleryProvider2 implements Runnable {
|
||||
@NonNull
|
||||
@Override
|
||||
public String getImageFilename(int index) {
|
||||
// TODO
|
||||
return Integer.toString(index);
|
||||
UniFile[] fileList = mFileList.get();
|
||||
if (null == fileList || index < 0 || index >= fileList.length) {
|
||||
return Integer.toString(index);
|
||||
}
|
||||
UniFile src = fileList[index];
|
||||
String name = src.getName();
|
||||
if (name == null) {
|
||||
return Integer.toString(index);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getImageFilenameWithExtension(int index) {
|
||||
UniFile[] fileList = mFileList.get();
|
||||
if (null == fileList || index < 0 || index >= fileList.length) {
|
||||
return Integer.toString(index);
|
||||
}
|
||||
UniFile src = fileList[index];
|
||||
String extension = FileUtils.getExtensionFromFilename(src.getName());
|
||||
String name = src.getName();
|
||||
if (name == null) {
|
||||
return Integer.toString(index);
|
||||
}
|
||||
name = null != extension ? name + "." + extension : name;
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -77,6 +77,18 @@ public class EhGalleryProvider extends GalleryProvider2 implements SpiderQueen.O
|
||||
return String.format(Locale.US, "%d-%s-%08d", mGalleryInfo.gid, mGalleryInfo.token, index + 1);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getImageFilenameWithExtension(int index) {
|
||||
if (null != mSpiderQueen) {
|
||||
String extension = mSpiderQueen.getExtension(index);
|
||||
if (extension != null) {
|
||||
return String.format(Locale.US, "%d-%s-%08d.%s", mGalleryInfo.gid, mGalleryInfo.token, index + 1, extension);
|
||||
}
|
||||
}
|
||||
return String.format(Locale.US, "%d-%s-%08d", mGalleryInfo.gid, mGalleryInfo.token, index + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(int index, @NonNull UniFile file) {
|
||||
if (null != mSpiderQueen) {
|
||||
|
||||
@@ -45,6 +45,12 @@ public abstract class GalleryProvider2 extends GalleryProvider {
|
||||
@NonNull
|
||||
public abstract String getImageFilename(int index);
|
||||
|
||||
/**
|
||||
* @return with extension
|
||||
*/
|
||||
@NonNull
|
||||
public abstract String getImageFilenameWithExtension(int index);
|
||||
|
||||
public abstract boolean save(int index, @NonNull UniFile file);
|
||||
|
||||
/**
|
||||
|
||||
@@ -629,6 +629,39 @@ public final class SpiderQueen implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public String getExtension(int index) {
|
||||
int state = getPageState(index);
|
||||
if (STATE_FINISHED != state) {
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStreamPipe pipe = mSpiderDen.openInputStreamPipe(index);
|
||||
if (null == pipe) {
|
||||
return null;
|
||||
}
|
||||
|
||||
OutputStream os = null;
|
||||
try {
|
||||
pipe.obtain();
|
||||
|
||||
// Get dst file
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeStream(pipe.open(), null, options);
|
||||
pipe.close();
|
||||
|
||||
return MimeTypeMap.getSingleton().getExtensionFromMimeType(options.outMimeType);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
} finally {
|
||||
pipe.close();
|
||||
pipe.release();
|
||||
IOUtils.closeQuietly(os);
|
||||
}
|
||||
}
|
||||
|
||||
public int getStartPage() {
|
||||
SpiderInfo spiderInfo = readSpiderInfoFromLocal();
|
||||
if (spiderInfo != null) {
|
||||
|
||||
@@ -785,7 +785,7 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
|
||||
return;
|
||||
}
|
||||
|
||||
String filename = mGalleryProvider.getImageFilename(page);
|
||||
String filename = mGalleryProvider.getImageFilenameWithExtension(page);
|
||||
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
|
||||
MimeTypeMap.getFileExtensionFromUrl(filename));
|
||||
if (TextUtils.isEmpty(mimeType)) {
|
||||
|
||||
Reference in new issue
Block a user