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