Fix directories manage screen
This commit is contained in:
@@ -9,9 +9,11 @@ data class DirectoryModel(
|
||||
val title: String?,
|
||||
@StringRes val titleRes: Int,
|
||||
val file: File?,
|
||||
val isRemovable: Boolean,
|
||||
val isChecked: Boolean,
|
||||
val isAvailable: Boolean,
|
||||
) : ListModel {
|
||||
|
||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||
return other is DirectoryModel && other.file == file && other.title == title && other.titleRes == titleRes
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ class MangaDirectorySelectViewModel @Inject constructor(
|
||||
file = dir,
|
||||
isChecked = dir == defaultValue,
|
||||
isAvailable = true,
|
||||
isRemovable = false,
|
||||
)
|
||||
}
|
||||
this += DirectoryModel(
|
||||
@@ -72,6 +73,7 @@ class MangaDirectorySelectViewModel @Inject constructor(
|
||||
file = null,
|
||||
isChecked = false,
|
||||
isAvailable = true,
|
||||
isRemovable = false,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,16 @@ fun directoryConfigAD(
|
||||
bind {
|
||||
binding.textViewTitle.text = item.title ?: getString(item.titleRes)
|
||||
binding.textViewSubtitle.textAndVisible = item.file?.absolutePath
|
||||
binding.imageViewRemove.isVisible = item.isChecked
|
||||
binding.textViewTitle.drawableStart = if (item.isAvailable) {
|
||||
null
|
||||
binding.imageViewRemove.isVisible = item.isRemovable
|
||||
binding.imageViewRemove.isEnabled = !item.isChecked
|
||||
binding.textViewTitle.drawableStart = if (!item.isAvailable) {
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_alert_outline)?.apply {
|
||||
setTint(ContextCompat.getColor(context, R.color.warning))
|
||||
}
|
||||
} else if (item.isChecked) {
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_download)
|
||||
} else {
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_alert_outline)
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,16 +59,18 @@ class MangaDirectoriesViewModel @Inject constructor(
|
||||
val prevJob = loadingJob
|
||||
loadingJob = launchJob(Dispatchers.Default) {
|
||||
prevJob?.cancelAndJoin()
|
||||
val downloadDir = storageManager.getDefaultWriteableDir()
|
||||
val applicationDirs = storageManager.getApplicationStorageDirs()
|
||||
val customDirs = settings.userSpecifiedMangaDirectories
|
||||
val customDirs = settings.userSpecifiedMangaDirectories - applicationDirs
|
||||
items.value = buildList(applicationDirs.size + customDirs.size) {
|
||||
applicationDirs.mapTo(this) { dir ->
|
||||
DirectoryModel(
|
||||
title = storageManager.getDirectoryDisplayName(dir, isFullPath = false),
|
||||
titleRes = 0,
|
||||
file = dir,
|
||||
isChecked = false,
|
||||
isChecked = dir == downloadDir,
|
||||
isAvailable = dir.canRead() && dir.canWrite(),
|
||||
isRemovable = false,
|
||||
)
|
||||
}
|
||||
customDirs.mapTo(this) { dir ->
|
||||
@@ -76,8 +78,9 @@ class MangaDirectoriesViewModel @Inject constructor(
|
||||
title = storageManager.getDirectoryDisplayName(dir, isFullPath = false),
|
||||
titleRes = 0,
|
||||
file = dir,
|
||||
isChecked = true,
|
||||
isChecked = dir == downloadDir,
|
||||
isAvailable = dir.canRead() && dir.canWrite(),
|
||||
isRemovable = true,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
android:gravity="center_vertical"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?attr/textAppearanceTitleSmall"
|
||||
app:drawableTint="@color/warning"
|
||||
tools:drawableStart="@drawable/ic_alert_outline"
|
||||
tools:text="@tools:sample/lorem[3]" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user