|
|
|
@ -1,16 +1,8 @@
|
|
|
|
package org.koitharu.kotatsu.settings.sources.adapter
|
|
|
|
package org.koitharu.kotatsu.settings.sources.adapter
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
|
|
|
|
import android.graphics.Color
|
|
|
|
|
|
|
|
import android.text.SpannableStringBuilder
|
|
|
|
|
|
|
|
import android.text.style.ForegroundColorSpan
|
|
|
|
|
|
|
|
import android.text.style.RelativeSizeSpan
|
|
|
|
|
|
|
|
import android.text.style.SuperscriptSpan
|
|
|
|
|
|
|
|
import android.view.View
|
|
|
|
import android.view.View
|
|
|
|
import androidx.appcompat.widget.PopupMenu
|
|
|
|
import androidx.appcompat.widget.PopupMenu
|
|
|
|
import androidx.core.content.pm.ShortcutManagerCompat
|
|
|
|
import androidx.core.content.pm.ShortcutManagerCompat
|
|
|
|
import androidx.core.text.buildSpannedString
|
|
|
|
|
|
|
|
import androidx.core.text.inSpans
|
|
|
|
|
|
|
|
import androidx.core.view.isGone
|
|
|
|
import androidx.core.view.isGone
|
|
|
|
import androidx.core.view.isVisible
|
|
|
|
import androidx.core.view.isVisible
|
|
|
|
import androidx.lifecycle.LifecycleOwner
|
|
|
|
import androidx.lifecycle.LifecycleOwner
|
|
|
|
@ -19,12 +11,12 @@ import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegate
|
|
|
|
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.model.getSummary
|
|
|
|
import org.koitharu.kotatsu.core.model.getSummary
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.core.model.getTitle
|
|
|
|
import org.koitharu.kotatsu.core.parser.favicon.faviconUri
|
|
|
|
import org.koitharu.kotatsu.core.parser.favicon.faviconUri
|
|
|
|
import org.koitharu.kotatsu.core.ui.image.FaviconDrawable
|
|
|
|
import org.koitharu.kotatsu.core.ui.image.FaviconDrawable
|
|
|
|
import org.koitharu.kotatsu.core.ui.list.OnTipCloseListener
|
|
|
|
import org.koitharu.kotatsu.core.ui.list.OnTipCloseListener
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.crossfade
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.crossfade
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.source
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.source
|
|
|
|
import org.koitharu.kotatsu.databinding.ItemSourceConfigBinding
|
|
|
|
import org.koitharu.kotatsu.databinding.ItemSourceConfigBinding
|
|
|
|
@ -51,15 +43,7 @@ fun sourceConfigItemCheckableDelegate(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bind {
|
|
|
|
bind {
|
|
|
|
binding.textViewTitle.text = if (item.isNsfw) {
|
|
|
|
binding.textViewTitle.text = item.source.getTitle(context)
|
|
|
|
buildSpannedString {
|
|
|
|
|
|
|
|
append(item.source.title)
|
|
|
|
|
|
|
|
append(' ')
|
|
|
|
|
|
|
|
appendNsfwLabel(context)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
item.source.title
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
binding.switchToggle.isChecked = item.isEnabled
|
|
|
|
binding.switchToggle.isChecked = item.isEnabled
|
|
|
|
binding.switchToggle.isEnabled = item.isAvailable
|
|
|
|
binding.switchToggle.isEnabled = item.isAvailable
|
|
|
|
binding.textViewDescription.text = item.source.getSummary(context)
|
|
|
|
binding.textViewDescription.text = item.source.getSummary(context)
|
|
|
|
@ -101,15 +85,7 @@ fun sourceConfigItemDelegate2(
|
|
|
|
binding.imageViewMenu.setOnClickListener(eventListener)
|
|
|
|
binding.imageViewMenu.setOnClickListener(eventListener)
|
|
|
|
|
|
|
|
|
|
|
|
bind {
|
|
|
|
bind {
|
|
|
|
binding.textViewTitle.text = if (item.isNsfw) {
|
|
|
|
binding.textViewTitle.text = item.source.getTitle(context)
|
|
|
|
buildSpannedString {
|
|
|
|
|
|
|
|
append(item.source.title)
|
|
|
|
|
|
|
|
append(' ')
|
|
|
|
|
|
|
|
appendNsfwLabel(context)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
item.source.title
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
binding.imageViewAdd.isGone = item.isEnabled || !item.isAvailable
|
|
|
|
binding.imageViewAdd.isGone = item.isEnabled || !item.isAvailable
|
|
|
|
binding.imageViewRemove.isVisible = item.isEnabled
|
|
|
|
binding.imageViewRemove.isVisible = item.isEnabled
|
|
|
|
binding.imageViewMenu.isVisible = item.isEnabled
|
|
|
|
binding.imageViewMenu.isVisible = item.isEnabled
|
|
|
|
@ -147,19 +123,6 @@ fun sourceConfigEmptySearchDelegate() =
|
|
|
|
R.layout.item_sources_empty,
|
|
|
|
R.layout.item_sources_empty,
|
|
|
|
) { }
|
|
|
|
) { }
|
|
|
|
|
|
|
|
|
|
|
|
fun SpannableStringBuilder.appendNsfwLabel(context: Context) = inSpans(
|
|
|
|
|
|
|
|
ForegroundColorSpan(
|
|
|
|
|
|
|
|
context.getThemeColor(
|
|
|
|
|
|
|
|
com.google.android.material.R.attr.colorError,
|
|
|
|
|
|
|
|
Color.RED,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
RelativeSizeSpan(0.74f),
|
|
|
|
|
|
|
|
SuperscriptSpan(),
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
append(context.getString(R.string.nsfw))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun showSourceMenu(
|
|
|
|
private fun showSourceMenu(
|
|
|
|
anchor: View,
|
|
|
|
anchor: View,
|
|
|
|
item: SourceConfigItem.SourceItem,
|
|
|
|
item: SourceConfigItem.SourceItem,
|
|
|
|
|