Add manga sources to search suggestion
parent
dd8cb8dfd0
commit
7d41318d15
@ -0,0 +1,41 @@
|
|||||||
|
package org.koitharu.kotatsu.search.ui.suggestion
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
|
import android.view.MenuItem
|
||||||
|
import androidx.core.view.MenuProvider
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
|
class SearchSuggestionMenuProvider(
|
||||||
|
private val context: Context,
|
||||||
|
private val viewModel: SearchSuggestionViewModel,
|
||||||
|
) : MenuProvider {
|
||||||
|
|
||||||
|
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
|
||||||
|
menuInflater.inflate(R.menu.opt_search_suggestion, menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
|
||||||
|
return when (menuItem.itemId) {
|
||||||
|
R.id.action_clear -> {
|
||||||
|
clearSearchHistory()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun clearSearchHistory() {
|
||||||
|
MaterialAlertDialogBuilder(context, materialR.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered)
|
||||||
|
.setTitle(R.string.clear_search_history)
|
||||||
|
.setIcon(R.drawable.ic_clear_all)
|
||||||
|
.setMessage(R.string.text_clear_search_history_prompt)
|
||||||
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.setPositiveButton(R.string.clear) { _, _ ->
|
||||||
|
viewModel.clearSearchHistory()
|
||||||
|
}.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,29 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.search.ui.suggestion.adapter
|
|
||||||
|
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
|
||||||
import org.koitharu.kotatsu.R
|
|
||||||
import org.koitharu.kotatsu.databinding.ItemSearchSuggestionHeaderBinding
|
|
||||||
import org.koitharu.kotatsu.search.ui.suggestion.SearchSuggestionListener
|
|
||||||
import org.koitharu.kotatsu.search.ui.suggestion.model.SearchSuggestionItem
|
|
||||||
|
|
||||||
fun searchSuggestionHeaderAD(
|
|
||||||
listener: SearchSuggestionListener,
|
|
||||||
) = adapterDelegateViewBinding<SearchSuggestionItem.Header, SearchSuggestionItem, ItemSearchSuggestionHeaderBinding>(
|
|
||||||
{ inflater, parent -> ItemSearchSuggestionHeaderBinding.inflate(inflater, parent, false) }
|
|
||||||
) {
|
|
||||||
|
|
||||||
binding.switchLocal.setOnCheckedChangeListener { _, isChecked ->
|
|
||||||
item.isChecked.value = isChecked
|
|
||||||
}
|
|
||||||
binding.buttonClear.setOnClickListener {
|
|
||||||
listener.onClearSearchHistory()
|
|
||||||
}
|
|
||||||
|
|
||||||
bind {
|
|
||||||
binding.switchLocal.text = getString(
|
|
||||||
R.string.search_only_on_s,
|
|
||||||
item.source.title,
|
|
||||||
)
|
|
||||||
binding.switchLocal.isChecked = item.isChecked.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
package org.koitharu.kotatsu.search.ui.suggestion.adapter
|
||||||
|
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import coil.ImageLoader
|
||||||
|
import coil.request.Disposable
|
||||||
|
import coil.request.ImageRequest
|
||||||
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
|
import org.koitharu.kotatsu.databinding.ItemSearchSuggestionSourceBinding
|
||||||
|
import org.koitharu.kotatsu.search.ui.suggestion.SearchSuggestionListener
|
||||||
|
import org.koitharu.kotatsu.search.ui.suggestion.model.SearchSuggestionItem
|
||||||
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
|
import org.koitharu.kotatsu.utils.image.FaviconFallbackDrawable
|
||||||
|
|
||||||
|
fun searchSuggestionSourceAD(
|
||||||
|
coil: ImageLoader,
|
||||||
|
lifecycleOwner: LifecycleOwner,
|
||||||
|
listener: SearchSuggestionListener,
|
||||||
|
) = adapterDelegateViewBinding<SearchSuggestionItem.Source, SearchSuggestionItem, ItemSearchSuggestionSourceBinding>(
|
||||||
|
{ inflater, parent -> ItemSearchSuggestionSourceBinding.inflate(inflater, parent, false) }
|
||||||
|
) {
|
||||||
|
|
||||||
|
var imageRequest: Disposable? = null
|
||||||
|
|
||||||
|
binding.switchLocal.setOnCheckedChangeListener { _, isChecked ->
|
||||||
|
listener.onSourceToggle(item.source, isChecked)
|
||||||
|
}
|
||||||
|
binding.root.setOnClickListener {
|
||||||
|
listener.onSourceClick(item.source)
|
||||||
|
}
|
||||||
|
|
||||||
|
bind {
|
||||||
|
binding.textViewTitle.text = item.source.title
|
||||||
|
binding.switchLocal.isChecked = item.isEnabled
|
||||||
|
val fallbackIcon = FaviconFallbackDrawable(context, item.source.name)
|
||||||
|
imageRequest = ImageRequest.Builder(context)
|
||||||
|
.data(item.faviconUrl)
|
||||||
|
.fallback(fallbackIcon)
|
||||||
|
.placeholder(fallbackIcon)
|
||||||
|
.error(fallbackIcon)
|
||||||
|
.target(binding.imageViewCover)
|
||||||
|
.lifecycle(lifecycleOwner)
|
||||||
|
.enqueueWith(coil)
|
||||||
|
}
|
||||||
|
|
||||||
|
onViewRecycled {
|
||||||
|
imageRequest?.dispose()
|
||||||
|
imageRequest = null
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,28 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:minHeight="?listPreferredItemHeightSmall"
|
|
||||||
android:paddingStart="?listPreferredItemPaddingStart"
|
|
||||||
android:paddingEnd="?listPreferredItemPaddingEnd">
|
|
||||||
|
|
||||||
<com.google.android.material.materialswitch.MaterialSwitch
|
|
||||||
android:id="@+id/switch_local"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginEnd="?listPreferredItemPaddingEnd"
|
|
||||||
android:layout_weight="1"
|
|
||||||
tools:text="@string/search_only_on_s" />
|
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/button_clear"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:background="?selectableItemBackgroundBorderless"
|
|
||||||
android:padding="8dp"
|
|
||||||
android:src="@drawable/ic_clear_all" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
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="?attr/listPreferredItemHeightSmall"
|
||||||
|
android:background="?selectableItemBackground"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<com.google.android.material.imageview.ShapeableImageView
|
||||||
|
android:id="@+id/imageView_cover"
|
||||||
|
android:layout_width="32dp"
|
||||||
|
android:layout_height="32dp"
|
||||||
|
android:layout_marginStart="?listPreferredItemPaddingStart"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
app:shapeAppearance="?shapeAppearanceCornerSmall"
|
||||||
|
tools:src="@tools:sample/backgrounds/scenic" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView_title"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginEnd="@dimen/margin_small"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAppearance="?attr/textAppearanceBodyMedium"
|
||||||
|
tools:text="@tools:sample/lorem[2]" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="1dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginVertical="8dp"
|
||||||
|
android:background="?colorOutline" />
|
||||||
|
|
||||||
|
<com.google.android.material.materialswitch.MaterialSwitch
|
||||||
|
android:id="@+id/switch_local"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:paddingHorizontal="?listPreferredItemPaddingEnd" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_clear"
|
||||||
|
android:title="@string/clear_search_history"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
</menu>
|
||||||
Loading…
Reference in New Issue