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);
}
}
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()));
}
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);
}
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());
}
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);
}
}
Aggregations