use of com.hippo.unifile.UniFile in project EhViewer by seven332.
the class EhApplication method onCreate.
@SuppressLint("StaticFieldLeak")
@Override
public void onCreate() {
instance = this;
Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
try {
// Always save crash file if onCreate() is not done
if (!initialized || Settings.getSaveCrashLog()) {
Crash.saveCrashLog(instance, e);
}
} catch (Throwable ignored) {
}
if (handler != null) {
handler.uncaughtException(t, e);
}
});
super.onCreate();
GetText.initialize(this);
StatusCodeException.initialize(this);
Settings.initialize(this);
ReadableTime.initialize(this);
Html.initialize(this);
AppConfig.initialize(this);
SpiderDen.initialize(this);
EhDB.initialize(this);
EhEngine.initialize();
BitmapUtils.initialize(this);
Image.initialize(this);
A7Zip.loadLibrary(A7ZipExtractLite.LIBRARY, libname -> ReLinker.loadLibrary(EhApplication.this, libname));
if (EhDB.needMerge()) {
EhDB.mergeOldDB(this);
}
if (Settings.getEnableAnalytics()) {
Analytics.start(this);
}
// Do io tasks in new thread
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
// Check no media file
try {
UniFile downloadLocation = Settings.getDownloadLocation();
if (Settings.getMediaScan()) {
CommonOperations.removeNoMediaFile(downloadLocation);
} else {
CommonOperations.ensureNoMediaFile(downloadLocation);
}
} catch (Throwable t) {
ExceptionUtils.throwIfFatal(t);
}
// Clear temp files
try {
clearTempDir();
} catch (Throwable t) {
ExceptionUtils.throwIfFatal(t);
}
return null;
}
}.executeOnExecutor(IoThreadPoolExecutor.getInstance());
// Check app update
update();
// Update version code
try {
PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
Settings.putVersionCode(pi.versionCode);
} catch (PackageManager.NameNotFoundException e) {
// Ignore
}
mIdGenerator.setNextId(Settings.getInt(KEY_GLOBAL_STUFF_NEXT_ID, 0));
if (DEBUG_PRINT_NATIVE_MEMORY || DEBUG_PRINT_IMAGE_COUNT) {
debugPrint();
}
initialized = true;
}
use of com.hippo.unifile.UniFile in project EhViewer by seven332.
the class SpiderDen method findImageFile.
@Nullable
private static UniFile findImageFile(UniFile dir, int index) {
for (String extension : GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS) {
String filename = generateImageFilename(index, extension);
UniFile file = dir.findFile(filename);
if (file != null) {
return file;
}
}
return null;
}
use of com.hippo.unifile.UniFile in project EhViewer by seven332.
the class SpiderQueen method writeSpiderInfoToLocal.
private synchronized void writeSpiderInfoToLocal(@NonNull SpiderInfo spiderInfo) {
// Write to download dir
UniFile downloadDir = mSpiderDen.getDownloadDir();
if (downloadDir != null) {
UniFile file = downloadDir.createFile(SPIDER_INFO_FILENAME);
try {
spiderInfo.write(file.openOutputStream());
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
// Ignore
}
}
// Read from cache
OutputStreamPipe pipe = mSpiderInfoCache.getOutputStreamPipe(Long.toString(mGalleryInfo.gid));
try {
pipe.obtain();
spiderInfo.write(pipe.open());
} catch (IOException e) {
// Ignore
} finally {
pipe.close();
pipe.release();
}
}
use of com.hippo.unifile.UniFile in project EhViewer by seven332.
the class MainActivity method saveImageToTempFile.
private File saveImageToTempFile(UniFile file) {
if (null == file) {
return null;
}
Bitmap bitmap = null;
try {
bitmap = BitmapUtils.decodeStream(new UniFileInputStreamPipe(file), -1, -1, 500 * 500, false, false, null);
} catch (OutOfMemoryError e) {
// Ignore
}
if (null == bitmap) {
return null;
}
File temp = AppConfig.createTempFile();
if (null == temp) {
return null;
}
OutputStream os = null;
try {
os = new FileOutputStream(temp);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, os);
return temp;
} catch (IOException e) {
return null;
} finally {
IOUtils.closeQuietly(os);
}
}
use of com.hippo.unifile.UniFile in project EhViewer by seven332.
the class MainActivity method checkDownloadLocation.
private void checkDownloadLocation() {
UniFile uniFile = Settings.getDownloadLocation();
// null == uniFile for first start
if (null == uniFile || uniFile.ensureDir()) {
return;
}
new AlertDialog.Builder(this).setTitle(R.string.waring).setMessage(R.string.invalid_download_location).setPositiveButton(R.string.get_it, null).show();
}
Aggregations