Avoid log spam

This commit is contained in:
FooIbar authored and tarsin committed 2023-02-12 17:20:42 +08:00
1 parent e51c297a7d
commit 90ee3b749f
3 files changed
+6 -43

No files matched your search

@@ -32,7 +32,6 @@ import com.hippo.unifile.RawFile
import com.hippo.unifile.UniFile
import com.hippo.yorozuya.FileUtils
import com.hippo.yorozuya.MathUtils
import com.hippo.yorozuya.Utilities
import io.ktor.client.plugins.onDownload
import io.ktor.client.request.prepareGet
import io.ktor.client.statement.HttpResponse
@@ -103,15 +102,8 @@ class SpiderDen(private val mGalleryInfo: GalleryInfo) {
* @param extension with dot
*/
private fun fixExtension(extension: String): String {
return if (Utilities.contain(
PageLoader2.SUPPORT_IMAGE_EXTENSIONS,
extension
)
) {
extension
} else {
PageLoader2.SUPPORT_IMAGE_EXTENSIONS[0]
}
return extension.takeIf { PageLoader2.SUPPORT_IMAGE_EXTENSIONS.contains(it) }
?: PageLoader2.SUPPORT_IMAGE_EXTENSIONS[0]
}
private fun copyFromCacheToDownloadDir(index: Int): Boolean {
@@ -158,19 +150,7 @@ class SpiderDen(private val mGalleryInfo: GalleryInfo) {
}
private fun removeFromDownloadDir(index: Int): Boolean {
val dir = downloadDir ?: return false
var result = false
var i = 0
val n = PageLoader2.SUPPORT_IMAGE_EXTENSIONS.size
while (i < n) {
val filename = generateImageFilename(index, PageLoader2.SUPPORT_IMAGE_EXTENSIONS[i])
val file = dir.subFile(filename)
if (file != null) {
result = result or runCatching { file.delete() }.getOrDefault(false)
}
i++
}
return result
return downloadDir?.let { findImageFile(it, index)?.delete() } ?: false
}
fun remove(index: Int): Boolean {
@@ -290,7 +270,8 @@ class SpiderDen(private val mGalleryInfo: GalleryInfo) {
fun getExtension(index: Int): String? {
val key = EhCacheKeyFactory.getImageKey(mGid, index)
return sCache[key]?.use { it.metadata.toNioPath().readText() }
?: downloadDir?.let { findImageFile(it, index) }?.name.let { FileUtils.getExtensionFromFilename(it) }
?: downloadDir?.let { findImageFile(it, index) }
?.name.let { FileUtils.getExtensionFromFilename(it) }
}
fun getImageSource(index: Int): ByteBufferSource? {
@@ -16,21 +16,16 @@
package com.hippo.unifile;
import android.annotation.TargetApi;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.DocumentsContract;
import android.text.TextUtils;
import android.util.Log;
@TargetApi(Build.VERSION_CODES.KITKAT)
final class DocumentsContractApi19 {
private static final String TAG = DocumentsContractApi19.class.getSimpleName();
private DocumentsContractApi19() {
}
@@ -118,8 +113,6 @@ final class DocumentsContractApi19 {
return DocumentsContract.deleteDocument(context.getContentResolver(), self);
} catch (Throwable e) {
Utils.throwIfFatal(e);
// Maybe user ejects tf card
Log.e(TAG, "Failed to renameTo", e);
return false;
}
}
@@ -134,7 +127,6 @@ final class DocumentsContractApi19 {
return null != c && c.getCount() > 0;
} catch (Throwable e) {
Utils.throwIfFatal(e);
// Log.w(TAG, "Failed query: " + e);
return false;
} finally {
Utils.closeQuietly(c);
@@ -16,21 +16,16 @@
package com.hippo.unifile;
import android.annotation.TargetApi;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.DocumentsContract;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
final class DocumentsContractApi21 {
private static final String TAG = DocumentsContractApi21.class.getSimpleName();
private static final String PATH_DOCUMENT = "document";
private static final String PATH_TREE = "tree";
@@ -44,8 +39,6 @@ final class DocumentsContractApi21 {
displayName);
} catch (Throwable e) {
Utils.throwIfFatal(e);
// Maybe user ejects tf card
Log.e(TAG, "Failed to createFile: " + self, e);
return null;
}
}
@@ -92,12 +85,11 @@ final class DocumentsContractApi21 {
}
} catch (Throwable e) {
Utils.throwIfFatal(e);
Log.e(TAG, "Failed listFiles: " + self, e);
} finally {
Utils.closeQuietly(c);
}
return results.toArray(new Uri[results.size()]);
return results.toArray(new Uri[0]);
}
public static Uri renameTo(Context context, Uri self, String displayName) {
@@ -105,8 +97,6 @@ final class DocumentsContractApi21 {
return DocumentsContract.renameDocument(context.getContentResolver(), self, displayName);
} catch (Throwable e) {
Utils.throwIfFatal(e);
// Maybe user ejects tf card
Log.e(TAG, "Failed to renameTo:" + self + ", " + displayName, e);
return null;
}
}