Search in sources :

Example 11 with UniFile

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;
}
Also used : UniFile(com.hippo.unifile.UniFile) PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) SuppressLint(android.annotation.SuppressLint)

Example 12 with UniFile

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;
}
Also used : UniFile(com.hippo.unifile.UniFile) Nullable(androidx.annotation.Nullable)

Example 13 with UniFile

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();
    }
}
Also used : UniFile(com.hippo.unifile.UniFile) OutputStreamPipe(com.hippo.streampipe.OutputStreamPipe) IOException(java.io.IOException)

Example 14 with UniFile

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);
    }
}
Also used : Bitmap(android.graphics.Bitmap) UniFileInputStreamPipe(com.hippo.io.UniFileInputStreamPipe) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) UniFile(com.hippo.unifile.UniFile) File(java.io.File)

Example 15 with UniFile

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();
}
Also used : UniFile(com.hippo.unifile.UniFile) ListUrlBuilder(com.hippo.ehviewer.client.data.ListUrlBuilder)

Aggregations

UniFile (com.hippo.unifile.UniFile)23 IOException (java.io.IOException)10 File (java.io.File)6 OutputStream (java.io.OutputStream)6 Nullable (androidx.annotation.Nullable)5 Intent (android.content.Intent)4 InputStream (java.io.InputStream)4 Uri (android.net.Uri)3 UniFileInputStreamPipe (com.hippo.io.UniFileInputStreamPipe)3 InputStreamPipe (com.hippo.streampipe.InputStreamPipe)3 SuppressLint (android.annotation.SuppressLint)2 Bitmap (android.graphics.Bitmap)2 BitmapFactory (android.graphics.BitmapFactory)2 ListUrlBuilder (com.hippo.ehviewer.client.data.ListUrlBuilder)2 FileOutputStream (java.io.FileOutputStream)2 Context (android.content.Context)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 FavListUrlBuilder (com.hippo.ehviewer.client.data.FavListUrlBuilder)1 GalleryInfo (com.hippo.ehviewer.client.data.GalleryInfo)1