mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-28 09:15:12 +03:00
Add .nomedia file in each chapter download folder (#2199)
* Move .nomedia creation to directory fetch * Add .nomedia file to all chapter download directories
This commit is contained in:
parent
5ddd7d1b14
commit
b8b118bdeb
4 changed files with 19 additions and 11 deletions
|
@ -28,7 +28,9 @@ class DownloadProvider(private val context: Context) {
|
|||
* The root directory for downloads.
|
||||
*/
|
||||
private var downloadsDir = preferences.downloadsDirectory().getOrDefault().let {
|
||||
UniFile.fromUri(context, Uri.parse(it))
|
||||
val dir = UniFile.fromUri(context, Uri.parse(it))
|
||||
DiskUtil.createNoMediaFile(dir, context)
|
||||
dir
|
||||
}
|
||||
|
||||
init {
|
||||
|
|
|
@ -407,6 +407,8 @@ class Downloader(
|
|||
if (download.status == Download.DOWNLOADED) {
|
||||
tmpDir.renameTo(dirname)
|
||||
cache.addChapter(dirname, mangaDir, download.manga)
|
||||
|
||||
DiskUtil.createNoMediaFile(tmpDir, context)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||
import eu.kanade.tachiyomi.util.DiskUtil
|
||||
import eu.kanade.tachiyomi.util.getFilePicker
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
@ -45,15 +44,6 @@ class SettingsDownloadController : SettingsController() {
|
|||
.subscribeUntilDestroy { path ->
|
||||
val dir = UniFile.fromUri(context, Uri.parse(path))
|
||||
summary = dir.filePath ?: path
|
||||
|
||||
// Don't display downloaded chapters in gallery apps creating .nomedia
|
||||
if (dir != null && dir.exists()) {
|
||||
val nomedia = dir.findFile(".nomedia")
|
||||
if (nomedia == null) {
|
||||
dir.createFile(".nomedia")
|
||||
applicationContext?.let { DiskUtil.scanMedia(it, dir.uri) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
switchPreference {
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.os.Build
|
|||
import android.os.Environment
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v4.os.EnvironmentCompat
|
||||
import com.hippo.unifile.UniFile
|
||||
import java.io.File
|
||||
|
||||
object DiskUtil {
|
||||
|
@ -54,6 +55,19 @@ object DiskUtil {
|
|||
return directories
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't display downloaded chapters in gallery apps creating `.nomedia`.
|
||||
*/
|
||||
fun createNoMediaFile(dir: UniFile?, context: Context?) {
|
||||
if (dir != null && dir.exists()) {
|
||||
val nomedia = dir.findFile(".nomedia")
|
||||
if (nomedia == null) {
|
||||
dir.createFile(".nomedia")
|
||||
context?.let { scanMedia(it, dir.uri) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans the given file so that it can be shown in gallery apps, for example.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue