Search in sources :

Example 1 with UniFile

use of com.hippo.unifile.UniFile in project EhViewer by seven332.

the class CommonOperations method ensureNoMediaFile.

public static void ensureNoMediaFile(UniFile file) {
    if (null == file) {
        return;
    }
    UniFile noMedia = file.createFile(".nomedia");
    if (null == noMedia) {
        return;
    }
    InputStream is = null;
    try {
        is = noMedia.openInputStream();
    } catch (IOException e) {
    // Ignore
    } finally {
        IOUtils.closeQuietly(is);
    }
}
Also used : UniFile(com.hippo.unifile.UniFile) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 2 with UniFile

use of com.hippo.unifile.UniFile in project EhViewer by seven332.

the class GalleryActivity method saveImage.

private void saveImage(int page) {
    if (null == mGalleryProvider) {
        return;
    }
    File dir = AppConfig.getExternalImageDir();
    if (null == dir) {
        Toast.makeText(this, R.string.error_cant_save_image, Toast.LENGTH_SHORT).show();
        return;
    }
    UniFile file;
    if (null == (file = mGalleryProvider.save(page, UniFile.fromFile(dir), mGalleryProvider.getImageFilename(page)))) {
        Toast.makeText(this, R.string.error_cant_save_image, Toast.LENGTH_SHORT).show();
        return;
    }
    Toast.makeText(this, getString(R.string.image_saved, file.getUri()), Toast.LENGTH_SHORT).show();
    // Sync media store
    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, file.getUri()));
}
Also used : UniFile(com.hippo.unifile.UniFile) Intent(android.content.Intent) UniFile(com.hippo.unifile.UniFile) File(java.io.File)

Example 3 with UniFile

use of com.hippo.unifile.UniFile in project EhViewer by seven332.

the class DownloadFragment method openDirPicker.

private void openDirPicker() {
    UniFile uniFile = Settings.getDownloadLocation();
    Intent intent = new Intent(getActivity(), DirPickerActivity.class);
    if (uniFile != null) {
        intent.putExtra(DirPickerActivity.KEY_FILE_URI, uniFile.getUri());
    }
    startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE_DIR);
}
Also used : UniFile(com.hippo.unifile.UniFile) Intent(android.content.Intent)

Example 4 with UniFile

use of com.hippo.unifile.UniFile in project EhViewer by seven332.

the class DownloadManager method resetAllReadingProgress.

@SuppressLint("StaticFieldLeak")
public void resetAllReadingProgress() {
    LinkedList<DownloadInfo> list = new LinkedList<>(mAllInfoList);
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... voids) {
            GalleryInfo galleryInfo = new GalleryInfo();
            for (DownloadInfo downloadInfo : list) {
                galleryInfo.gid = downloadInfo.gid;
                galleryInfo.token = downloadInfo.token;
                galleryInfo.title = downloadInfo.title;
                galleryInfo.thumb = downloadInfo.thumb;
                galleryInfo.category = downloadInfo.category;
                galleryInfo.posted = downloadInfo.posted;
                galleryInfo.uploader = downloadInfo.uploader;
                galleryInfo.rating = downloadInfo.rating;
                UniFile downloadDir = SpiderDen.getGalleryDownloadDir(galleryInfo);
                if (downloadDir == null) {
                    continue;
                }
                UniFile file = downloadDir.findFile(".ehviewer");
                if (file == null) {
                    continue;
                }
                SpiderInfo spiderInfo = SpiderInfo.read(file);
                if (spiderInfo == null) {
                    continue;
                }
                spiderInfo.startPage = 0;
                try {
                    spiderInfo.write(file.openOutputStream());
                } catch (IOException e) {
                    Log.e(TAG, "Can't write SpiderInfo", e);
                }
            }
            return null;
        }
    }.executeOnExecutor(IoThreadPoolExecutor.getInstance());
}
Also used : UniFile(com.hippo.unifile.UniFile) DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) IOException(java.io.IOException) LinkedList(java.util.LinkedList) SpiderInfo(com.hippo.ehviewer.spider.SpiderInfo) SuppressLint(android.annotation.SuppressLint)

Example 5 with UniFile

use of com.hippo.unifile.UniFile in project EhViewer by seven332.

the class DirGalleryProvider method save.

@Override
public boolean save(int index, @NonNull UniFile file) {
    UniFile[] fileList = mFileList.get();
    if (null == fileList || index < 0 || index >= fileList.length) {
        return false;
    }
    InputStream is = null;
    OutputStream os = null;
    try {
        is = fileList[index].openInputStream();
        os = file.openOutputStream();
        IOUtils.copy(is, os);
        return true;
    } catch (IOException e) {
        return false;
    } finally {
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(os);
    }
}
Also used : UniFile(com.hippo.unifile.UniFile) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

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