mirror of
https://github.com/rebelonion/Dantotsu.git
synced 2026-01-29 23:51:02 +00:00
feat: nomedia file
This commit is contained in:
@@ -319,6 +319,19 @@ class DownloadsManager(private val context: Context) {
|
|||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addNoMedia(context: Context) {
|
||||||
|
val baseDirectory = getBaseDirectory(context) ?: return
|
||||||
|
if (baseDirectory.findFile(".nomedia") == null) {
|
||||||
|
baseDirectory.createFile("application/octet-stream", ".nomedia")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getBaseDirectory(context: Context): DocumentFile? {
|
||||||
|
val baseDirectory = Uri.parse(PrefManager.getVal<String>(PrefName.DownloadsDir))
|
||||||
|
if (baseDirectory == Uri.EMPTY) return null
|
||||||
|
return DocumentFile.fromTreeUri(context, baseDirectory)
|
||||||
|
}
|
||||||
|
|
||||||
private fun DocumentFile.findOrCreateFolder(
|
private fun DocumentFile.findOrCreateFolder(
|
||||||
name: String, overwrite: Boolean
|
name: String, overwrite: Boolean
|
||||||
): DocumentFile? {
|
): DocumentFile? {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import ani.dantotsu.R
|
import ani.dantotsu.R
|
||||||
|
import ani.dantotsu.download.DownloadsManager
|
||||||
import ani.dantotsu.settings.saving.PrefManager
|
import ani.dantotsu.settings.saving.PrefManager
|
||||||
import ani.dantotsu.settings.saving.PrefName
|
import ani.dantotsu.settings.saving.PrefName
|
||||||
import ani.dantotsu.toast
|
import ani.dantotsu.toast
|
||||||
@@ -110,6 +111,7 @@ class LauncherWrapper(
|
|||||||
|
|
||||||
if (StoragePermissions.hasDirAccess(activity, uri)) {
|
if (StoragePermissions.hasDirAccess(activity, uri)) {
|
||||||
PrefManager.setVal(PrefName.DownloadsDir, uri.toString())
|
PrefManager.setVal(PrefName.DownloadsDir, uri.toString())
|
||||||
|
DownloadsManager.addNoMedia(activity)
|
||||||
complete(true)
|
complete(true)
|
||||||
} else {
|
} else {
|
||||||
toast(activity.getString(R.string.dir_error))
|
toast(activity.getString(R.string.dir_error))
|
||||||
|
|||||||
Reference in New Issue
Block a user