Suggest tags on search
parent
445ff89392
commit
3802bc146f
@ -0,0 +1,78 @@
|
|||||||
|
package org.koitharu.kotatsu.search.ui
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.graphics.Insets
|
||||||
|
import androidx.core.view.updateLayoutParams
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.fragment.app.commit
|
||||||
|
import org.koin.androidx.viewmodel.ext.android.getViewModel
|
||||||
|
import org.koin.core.parameter.parametersOf
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
|
import org.koitharu.kotatsu.core.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.databinding.ActivitySearchGlobalBinding
|
||||||
|
import org.koitharu.kotatsu.list.ui.filter.FilterState
|
||||||
|
import org.koitharu.kotatsu.remotelist.ui.RemoteListFragment
|
||||||
|
import org.koitharu.kotatsu.remotelist.ui.RemoteListViewModel
|
||||||
|
|
||||||
|
class MangaListActivity : BaseActivity<ActivitySearchGlobalBinding>() {
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(ActivitySearchGlobalBinding.inflate(layoutInflater))
|
||||||
|
val tag = intent.getParcelableExtra<MangaTag>(EXTRA_TAG) ?: run {
|
||||||
|
finishAfterTransition()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
val fm = supportFragmentManager
|
||||||
|
if (fm.findFragmentById(R.id.container) == null) {
|
||||||
|
fm.commit {
|
||||||
|
val fragment = RemoteListFragment.newInstance(tag.source)
|
||||||
|
replace(R.id.container, fragment)
|
||||||
|
runOnCommit(ApplyFilterRunnable(fragment, tag))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onWindowInsetsChanged(insets: Insets) {
|
||||||
|
with(binding.toolbar) {
|
||||||
|
updatePadding(
|
||||||
|
left = insets.left,
|
||||||
|
right = insets.right
|
||||||
|
)
|
||||||
|
updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||||
|
topMargin = insets.top
|
||||||
|
}
|
||||||
|
}
|
||||||
|
binding.container.updatePadding(
|
||||||
|
bottom = insets.bottom
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ApplyFilterRunnable(
|
||||||
|
private val fragment: Fragment,
|
||||||
|
private val tag: MangaTag,
|
||||||
|
) : Runnable {
|
||||||
|
|
||||||
|
override fun run() {
|
||||||
|
val viewModel = fragment.getViewModel<RemoteListViewModel> {
|
||||||
|
parametersOf(tag.source)
|
||||||
|
}
|
||||||
|
viewModel.applyFilter(FilterState(viewModel.filter.sortOrder, setOf(tag)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
private const val EXTRA_TAG = "tag"
|
||||||
|
|
||||||
|
fun newIntent(context: Context, tag: MangaTag) =
|
||||||
|
Intent(context, MangaListActivity::class.java)
|
||||||
|
.putExtra(EXTRA_TAG, tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
package org.koitharu.kotatsu.search.ui.suggestion.adapter
|
||||||
|
|
||||||
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegate
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.widgets.ChipsView
|
||||||
|
import org.koitharu.kotatsu.core.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.search.ui.suggestion.SearchSuggestionListener
|
||||||
|
import org.koitharu.kotatsu.search.ui.suggestion.model.SearchSuggestionItem
|
||||||
|
|
||||||
|
fun searchSuggestionTagsAD(
|
||||||
|
listener: SearchSuggestionListener,
|
||||||
|
) = adapterDelegate<SearchSuggestionItem.Tags, SearchSuggestionItem>(R.layout.item_search_suggestion_tags) {
|
||||||
|
|
||||||
|
val chipGroup = itemView as ChipsView
|
||||||
|
|
||||||
|
chipGroup.onChipClickListener = ChipsView.OnChipClickListener { _, data ->
|
||||||
|
listener.onTagClick(data as? MangaTag ?: return@OnChipClickListener)
|
||||||
|
}
|
||||||
|
|
||||||
|
bind {
|
||||||
|
chipGroup.setChips(item.tags)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,21 +1,26 @@
|
|||||||
package org.koitharu.kotatsu.search.ui.suggestion.model
|
package org.koitharu.kotatsu.search.ui.suggestion.model
|
||||||
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import org.koitharu.kotatsu.base.ui.widgets.ChipsView
|
||||||
import org.koitharu.kotatsu.core.model.Manga
|
import org.koitharu.kotatsu.core.model.Manga
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
|
|
||||||
sealed class SearchSuggestionItem {
|
sealed interface SearchSuggestionItem {
|
||||||
|
|
||||||
data class MangaItem(
|
data class MangaItem(
|
||||||
val manga: Manga,
|
val manga: Manga,
|
||||||
) : SearchSuggestionItem()
|
) : SearchSuggestionItem
|
||||||
|
|
||||||
data class RecentQuery(
|
data class RecentQuery(
|
||||||
val query: String,
|
val query: String,
|
||||||
) : SearchSuggestionItem()
|
) : SearchSuggestionItem
|
||||||
|
|
||||||
data class Header(
|
data class Header(
|
||||||
val source: MangaSource,
|
val source: MangaSource,
|
||||||
val isChecked: MutableStateFlow<Boolean>,
|
val isChecked: MutableStateFlow<Boolean>,
|
||||||
) : SearchSuggestionItem()
|
) : SearchSuggestionItem
|
||||||
|
|
||||||
|
data class Tags(
|
||||||
|
val tags: List<ChipsView.ChipModel>,
|
||||||
|
) : SearchSuggestionItem
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<org.koitharu.kotatsu.base.ui.widgets.ChipsView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingStart="?listPreferredItemPaddingStart"
|
||||||
|
android:paddingEnd="?listPreferredItemPaddingEnd"
|
||||||
|
android:paddingVertical="4dp"
|
||||||
|
app:chipSpacingHorizontal="6dp"
|
||||||
|
app:chipSpacingVertical="6dp" />
|
||||||
Loading…
Reference in New Issue