feat: nomedia file
This commit is contained in:
parent
7ca44480a9
commit
a8ff4fdc26
2 changed files with 15 additions and 0 deletions
|
@ -319,6 +319,19 @@ class DownloadsManager(private val context: Context) {
|
|||
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(
|
||||
name: String, overwrite: Boolean
|
||||
): DocumentFile? {
|
||||
|
|
|
@ -13,6 +13,7 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import ani.dantotsu.R
|
||||
import ani.dantotsu.download.DownloadsManager
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.toast
|
||||
|
@ -110,6 +111,7 @@ class LauncherWrapper(
|
|||
|
||||
if (StoragePermissions.hasDirAccess(activity, uri)) {
|
||||
PrefManager.setVal(PrefName.DownloadsDir, uri.toString())
|
||||
DownloadsManager.addNoMedia(activity)
|
||||
complete(true)
|
||||
} else {
|
||||
toast(activity.getString(R.string.dir_error))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue