Skip to content

Commit

Permalink
Add ability to see what sizes the cache folders are
Browse files Browse the repository at this point in the history
  • Loading branch information
nonproto committed Feb 10, 2025
1 parent 7638363 commit c02cf49
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CoverCache(val context: Context) {
*/
private val renewInterval = TimeUnit.HOURS.toMillis(1)

fun getChapterCacheSize(): String {
fun getCoverCacheSize(): String {
return Formatter.formatFileSize(context, DiskUtil.getDirectorySize(cacheDir))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class NetworkHelper(val context: Context) {
private val json: Json by injectLazy()
private val mangaDexLoginHelper: MangaDexLoginHelper by injectLazy()

private val cacheDir = File(context.cacheDir, "network_cache")
val cacheDir = File(context.cacheDir, "network_cache")

private val cacheSize = 5L * 1024 * 1024 // 5 MiB

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.uuid
import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.download.DownloadProvider
import eu.kanade.tachiyomi.data.image.coil.CoilDiskCache
import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.source.SourceManager
Expand Down Expand Up @@ -64,6 +65,7 @@ import tachiyomi.core.network.PREF_DOH_NJALLA
import tachiyomi.core.network.PREF_DOH_QUAD101
import tachiyomi.core.network.PREF_DOH_QUAD9
import tachiyomi.core.network.PREF_DOH_SHECAN
import tachiyomi.core.util.storage.DiskUtil
import tachiyomi.core.util.system.setDefaultSettings
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
Expand Down Expand Up @@ -153,6 +155,21 @@ class SettingsAdvancedController : SettingsController() {

preferenceCategory {
titleRes = R.string.data_management

preference {
title = "Total cache usage"
summary =
"""
Chapter Disk Cache: ${DiskUtil.readableDiskSize(context, chapterCache.cacheDir)}
Cover Cache: ${coverCache.getCoverCacheSize()}
Online Cover Cache: ${coverCache.getOnlineCoverCacheSize()}
Image Cache: ${DiskUtil.readableDiskSize(context, CoilDiskCache.get(context).size)}
Network Cache: ${DiskUtil.readableDiskSize(context, network.cacheDir)}
"""
.trimIndent()
onClick {}
}

preference {
key = CLEAR_CACHE_KEY
titleRes = R.string.clear_chapter_cache
Expand All @@ -177,7 +194,7 @@ class SettingsAdvancedController : SettingsController() {
summary =
context.getString(
R.string.delete_old_covers_in_library_used_,
coverCache.getChapterCacheSize(),
coverCache.getCoverCacheSize(),
)

onClick {
Expand Down
42 changes: 26 additions & 16 deletions app/src/main/java/org/nekomanga/presentation/screens/FeedScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,32 @@ fun FeedScreen(
actions = {
AppBarActions(
actions =
listOf(
AppBar.Action(
title = UiText.StringResource(R.string.settings),
icon = Icons.Outlined.Tune,
onClick = { scope.launch { sheetState.show() } },
),
AppBar.MainDropdown(
incognitoMode = feedScreenState.value.incognitoMode,
incognitoModeClick = incognitoClick,
settingsClick = settingsClick,
statsClick = statsClick,
aboutClick = aboutClick,
helpClick = helpClick,
menuShowing = { visible -> mainDropdownShowing = visible },
),
)
if (
feedScreenState.value.feedScreenType != FeedScreenType.Summary
) {
listOf(
AppBar.Action(
title = UiText.StringResource(R.string.settings),
icon = Icons.Outlined.Tune,
onClick = { scope.launch { sheetState.show() } },
)
)
} else {
listOf()
} +
listOf(
AppBar.MainDropdown(
incognitoMode = feedScreenState.value.incognitoMode,
incognitoModeClick = incognitoClick,
settingsClick = settingsClick,
statsClick = statsClick,
aboutClick = aboutClick,
helpClick = helpClick,
menuShowing = { visible ->
mainDropdownShowing = visible
},
)
)
)
},
) { incomingContentPadding ->
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/kotlin/tachiyomi/core/util/storage/DiskUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.StatFs
import android.text.format.Formatter
import com.hippo.unifile.UniFile
import java.io.File
import tachiyomi.core.util.lang.Hash
Expand Down Expand Up @@ -114,5 +115,15 @@ object DiskUtil {
}
}

/** Returns real size of directory in human readable format. */
fun readableDiskSize(context: Context, file: File): String {
return Formatter.formatFileSize(context, getDirectorySize(file))
}

/** Returns real size of directory in human readable format. */
fun readableDiskSize(context: Context, bytes: Long): String {
return Formatter.formatFileSize(context, bytes)
}

const val NOMEDIA_FILE = ".nomedia"
}

0 comments on commit c02cf49

Please sign in to comment.