Improve local manga directories config screen
parent
d0ed1fb85f
commit
0d5229b112
@ -1,38 +1,66 @@
|
|||||||
package org.koitharu.kotatsu.settings.storage.directories
|
package org.koitharu.kotatsu.settings.storage.directories
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.text.bold
|
||||||
|
import androidx.core.text.buildSpannedString
|
||||||
|
import androidx.core.text.color
|
||||||
|
import androidx.core.view.isGone
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.core.util.ext.drawableStart
|
import org.koitharu.kotatsu.core.util.FileSize
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
||||||
import org.koitharu.kotatsu.core.util.ext.setTooltipCompat
|
import org.koitharu.kotatsu.core.util.ext.setTooltipCompat
|
||||||
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
||||||
import org.koitharu.kotatsu.databinding.ItemStorageConfigBinding
|
import org.koitharu.kotatsu.databinding.ItemStorageConfig2Binding
|
||||||
import org.koitharu.kotatsu.settings.storage.DirectoryModel
|
|
||||||
|
|
||||||
fun directoryConfigAD(
|
fun directoryConfigAD(
|
||||||
clickListener: OnListItemClickListener<DirectoryModel>,
|
clickListener: OnListItemClickListener<DirectoryConfigModel>,
|
||||||
) = adapterDelegateViewBinding<DirectoryModel, DirectoryModel, ItemStorageConfigBinding>(
|
) = adapterDelegateViewBinding<DirectoryConfigModel, DirectoryConfigModel, ItemStorageConfig2Binding>(
|
||||||
{ layoutInflater, parent -> ItemStorageConfigBinding.inflate(layoutInflater, parent, false) },
|
{ layoutInflater, parent -> ItemStorageConfig2Binding.inflate(layoutInflater, parent, false) },
|
||||||
) {
|
) {
|
||||||
|
|
||||||
binding.buttonRemove.setOnClickListener { v -> clickListener.onItemClick(item, v) }
|
binding.buttonRemove.setOnClickListener { v -> clickListener.onItemClick(item, v) }
|
||||||
binding.buttonRemove.setTooltipCompat(binding.buttonRemove.contentDescription)
|
binding.buttonRemove.setTooltipCompat(binding.buttonRemove.contentDescription)
|
||||||
|
|
||||||
bind {
|
bind {
|
||||||
binding.textViewTitle.text = item.title ?: getString(item.titleRes)
|
binding.textViewTitle.text = item.title
|
||||||
binding.textViewSubtitle.textAndVisible = item.file?.absolutePath
|
binding.textViewSubtitle.text = item.path.absolutePath
|
||||||
binding.buttonRemove.isVisible = item.isRemovable
|
binding.buttonRemove.isGone = item.isAppPrivate
|
||||||
binding.buttonRemove.isEnabled = !item.isChecked
|
binding.buttonRemove.isEnabled = !item.isDefault
|
||||||
binding.textViewTitle.drawableStart = if (!item.isAvailable) {
|
binding.spacer.visibility = if (item.isAppPrivate) {
|
||||||
ContextCompat.getDrawable(context, R.drawable.ic_alert_outline)?.apply {
|
View.INVISIBLE
|
||||||
setTint(ContextCompat.getColor(context, R.color.warning))
|
} else {
|
||||||
}
|
View.GONE
|
||||||
} else if (item.isChecked) {
|
}
|
||||||
ContextCompat.getDrawable(context, R.drawable.ic_download)
|
binding.textViewInfo.textAndVisible = buildSpannedString {
|
||||||
} else {
|
if (item.isDefault) {
|
||||||
null
|
bold {
|
||||||
}
|
append(getString(R.string.download_default_directory))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (!item.isAccessible) {
|
||||||
|
if (isNotEmpty()) appendLine()
|
||||||
|
color(
|
||||||
|
context.getThemeColor(
|
||||||
|
androidx.appcompat.R.attr.colorError,
|
||||||
|
ContextCompat.getColor(context, R.color.common_red),
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
append(getString(R.string.no_write_permission_to_file))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.isAppPrivate) {
|
||||||
|
if (isNotEmpty()) appendLine()
|
||||||
|
append(getString(R.string.private_app_directory_warning))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
binding.indicatorSize.max = FileSize.BYTES.convert(item.available, FileSize.KILOBYTES).toInt()
|
||||||
|
binding.indicatorSize.progress = FileSize.BYTES.convert(item.size, FileSize.KILOBYTES).toInt()
|
||||||
|
binding.textViewSize.text = context.getString(
|
||||||
|
R.string.available_pattern,
|
||||||
|
FileSize.BYTES.format(context, item.available),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,22 @@
|
|||||||
|
package org.koitharu.kotatsu.settings.storage.directories
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.DiffUtil.ItemCallback
|
||||||
|
|
||||||
|
class DirectoryConfigDiffCallback : ItemCallback<DirectoryConfigModel>() {
|
||||||
|
|
||||||
|
override fun areItemsTheSame(oldItem: DirectoryConfigModel, newItem: DirectoryConfigModel): Boolean {
|
||||||
|
return oldItem.path == newItem.path
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areContentsTheSame(oldItem: DirectoryConfigModel, newItem: DirectoryConfigModel): Boolean {
|
||||||
|
return oldItem == newItem
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getChangePayload(oldItem: DirectoryConfigModel, newItem: DirectoryConfigModel): Any? {
|
||||||
|
return if (oldItem.isDefault != newItem.isDefault) {
|
||||||
|
Unit
|
||||||
|
} else {
|
||||||
|
super.getChangePayload(oldItem, newItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
package org.koitharu.kotatsu.settings.storage.directories
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
data class DirectoryConfigModel(
|
||||||
|
val title: String,
|
||||||
|
val path: File,
|
||||||
|
val isDefault: Boolean,
|
||||||
|
val isAppPrivate: Boolean,
|
||||||
|
val isAccessible: Boolean,
|
||||||
|
val size: Long,
|
||||||
|
val available: Long,
|
||||||
|
) : ListModel {
|
||||||
|
|
||||||
|
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||||
|
return other is DirectoryConfigModel && path == other.path
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,57 +1,60 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_height="match_parent">
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
|
||||||
android:id="@+id/appbar"
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:layout_width="match_parent"
|
android:id="@+id/appbar"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:fitsSystemWindows="true">
|
android:layout_height="wrap_content"
|
||||||
|
android:fitsSystemWindows="true">
|
||||||
<com.google.android.material.appbar.MaterialToolbar
|
|
||||||
android:id="@id/toolbar"
|
<com.google.android.material.appbar.MaterialToolbar
|
||||||
android:layout_width="match_parent"
|
android:id="@id/toolbar"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_width="match_parent"
|
||||||
app:layout_scrollFlags="noScroll">
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
app:layout_scrollFlags="noScroll">
|
||||||
</com.google.android.material.appbar.MaterialToolbar>
|
|
||||||
|
</com.google.android.material.appbar.MaterialToolbar>
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
|
||||||
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/recyclerView"
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:layout_width="match_parent"
|
android:id="@+id/recyclerView"
|
||||||
android:layout_height="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:clipToPadding="false"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:clipToPadding="false"
|
||||||
android:scrollbars="vertical"
|
android:orientation="vertical"
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
android:paddingBottom="@dimen/list_spacing_large"
|
||||||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
|
android:scrollbars="vertical"
|
||||||
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
<com.google.android.material.progressindicator.LinearProgressIndicator
|
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
|
||||||
android:id="@+id/progressBar"
|
tools:listitem="@layout/item_storage_config2" />
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
<com.google.android.material.progressindicator.LinearProgressIndicator
|
||||||
android:indeterminate="true"
|
android:id="@+id/progressBar"
|
||||||
android:visibility="gone"
|
android:layout_width="match_parent"
|
||||||
app:layout_anchor="@id/appbar"
|
android:layout_height="wrap_content"
|
||||||
app:layout_anchorGravity="bottom" />
|
android:indeterminate="true"
|
||||||
|
android:visibility="gone"
|
||||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
app:layout_anchor="@id/appbar"
|
||||||
android:id="@+id/fab_add"
|
app:layout_anchorGravity="bottom" />
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||||
android:layout_margin="16dp"
|
android:id="@+id/fab_add"
|
||||||
android:contentDescription="@string/pick_custom_directory"
|
android:layout_width="wrap_content"
|
||||||
android:text="@string/add"
|
android:layout_height="wrap_content"
|
||||||
app:fabSize="normal"
|
android:layout_margin="16dp"
|
||||||
app:icon="@drawable/ic_add"
|
android:contentDescription="@string/pick_custom_directory"
|
||||||
app:layout_anchor="@id/recyclerView"
|
android:text="@string/add"
|
||||||
app:layout_anchorGravity="bottom|end"
|
app:fabSize="normal"
|
||||||
app:layout_behavior="org.koitharu.kotatsu.core.ui.util.ShrinkOnScrollBehavior"
|
app:icon="@drawable/ic_add"
|
||||||
app:layout_dodgeInsetEdges="bottom" />
|
app:layout_anchor="@id/recyclerView"
|
||||||
|
app:layout_anchorGravity="bottom|end"
|
||||||
|
app:layout_behavior="org.koitharu.kotatsu.core.ui.util.ShrinkOnScrollBehavior"
|
||||||
|
app:layout_dodgeInsetEdges="bottom" />
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
|||||||
@ -0,0 +1,93 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:layout_margin="@dimen/screen_padding">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingBottom="@dimen/margin_small">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView_title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="@dimen/screen_padding"
|
||||||
|
android:layout_marginTop="@dimen/screen_padding"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAppearance="?attr/textAppearanceTitleMedium"
|
||||||
|
tools:text="@tools:sample/lorem[3]" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView_subtitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="@dimen/screen_padding"
|
||||||
|
android:layout_marginTop="@dimen/margin_small"
|
||||||
|
android:textAppearance="?attr/textAppearanceBodyMedium"
|
||||||
|
tools:text="@tools:sample/lorem[5]" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="@dimen/screen_padding"
|
||||||
|
android:layout_marginTop="@dimen/screen_padding"
|
||||||
|
android:baselineAligned="false"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView_size"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="@dimen/margin_small"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAppearance="?attr/textAppearanceBodyMedium"
|
||||||
|
android:textColor="?android:textColorSecondary"
|
||||||
|
tools:text="250MB / 10GB" />
|
||||||
|
|
||||||
|
<com.google.android.material.progressindicator.LinearProgressIndicator
|
||||||
|
android:id="@+id/indicator_size"
|
||||||
|
android:layout_width="160dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:trackCornerRadius="5dp"
|
||||||
|
app:trackThickness="10dp"
|
||||||
|
tools:progress="40" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView_info"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="@dimen/screen_padding"
|
||||||
|
android:layout_marginTop="@dimen/margin_small"
|
||||||
|
android:textAppearance="?attr/textAppearanceBodySmall"
|
||||||
|
android:textColor="?android:textColorSecondary"
|
||||||
|
tools:text="Content will be removed within application" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button_remove"
|
||||||
|
style="?buttonBarButtonStyle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="end"
|
||||||
|
android:layout_marginEnd="@dimen/margin_small"
|
||||||
|
android:text="@string/remove" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/spacer"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/margin_small"
|
||||||
|
tools:visibility="gone" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
Loading…
Reference in New Issue