diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/View.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/View.kt index 5dd9c0464..ddb3a0c0f 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/View.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/View.kt @@ -8,6 +8,7 @@ import android.view.ViewGroup import android.view.ViewParent import android.view.inputmethod.InputMethodManager import android.widget.Checkable +import android.widget.CompoundButton import androidx.core.view.children import androidx.recyclerview.widget.RecyclerView import androidx.viewpager2.widget.ViewPager2 diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt b/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt index 9d7f65b22..04fecfa35 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt @@ -68,6 +68,14 @@ class MangaSourcesRepository @Inject constructor( } } + suspend fun setSourcesEnabledExclusive(sources: Set) { + db.withTransaction { + for (s in remoteSources) { + dao.setEnabled(s.name, s in sources) + } + } + } + suspend fun setSourcesEnabled(sources: Iterable, isEnabled: Boolean) { db.withTransaction { for (s in sources) { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/ExploreFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/ExploreFragment.kt index 144d9b490..94864079d 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/ExploreFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/ExploreFragment.kt @@ -28,13 +28,13 @@ import org.koitharu.kotatsu.core.ui.widgets.TipView import org.koitharu.kotatsu.core.util.ext.addMenuProvider import org.koitharu.kotatsu.core.util.ext.observe import org.koitharu.kotatsu.core.util.ext.observeEvent -import org.koitharu.kotatsu.core.util.ext.scaleUpActivityOptionsOf import org.koitharu.kotatsu.databinding.FragmentExploreBinding import org.koitharu.kotatsu.details.ui.DetailsActivity import org.koitharu.kotatsu.download.ui.list.DownloadsActivity import org.koitharu.kotatsu.explore.ui.adapter.ExploreAdapter import org.koitharu.kotatsu.explore.ui.adapter.ExploreListEventListener import org.koitharu.kotatsu.explore.ui.model.MangaSourceItem +import org.koitharu.kotatsu.list.ui.adapter.TypedListSpacingDecoration import org.koitharu.kotatsu.list.ui.model.ListHeader import org.koitharu.kotatsu.list.ui.model.TipModel import org.koitharu.kotatsu.parsers.model.Manga @@ -57,7 +57,6 @@ class ExploreFragment : private val viewModel by viewModels() private var exploreAdapter: ExploreAdapter? = null - private var paddingHorizontal = 0 override val recyclerView: RecyclerView get() = requireViewBinding().recyclerView @@ -75,8 +74,7 @@ class ExploreFragment : adapter = exploreAdapter setHasFixedSize(true) SpanSizeResolver(this, resources.getDimensionPixelSize(R.dimen.explore_grid_width)).attach() - val spacing = resources.getDimensionPixelOffset(R.dimen.list_spacing) - paddingHorizontal = spacing + addItemDecoration(TypedListSpacingDecoration(context)) } addMenuProvider(ExploreMenuProvider(binding.root.context, viewModel)) viewModel.content.observe(viewLifecycleOwner) { @@ -97,8 +95,9 @@ class ExploreFragment : } override fun onWindowInsetsChanged(insets: Insets) { - requireViewBinding().recyclerView.updatePadding( - bottom = insets.bottom, + val rv = requireViewBinding().recyclerView + rv.updatePadding( + bottom = insets.bottom + rv.paddingTop, ) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/MangaListFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/MangaListFragment.kt index cb2d98121..e48d25fc5 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/MangaListFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/MangaListFragment.kt @@ -204,10 +204,11 @@ abstract class MangaListFragment : } override fun onWindowInsetsChanged(insets: Insets) { - requireViewBinding().recyclerView.updatePadding( - bottom = insets.bottom, + val rv = requireViewBinding().recyclerView + rv.updatePadding( + bottom = insets.bottom + rv.paddingTop, ) - requireViewBinding().recyclerView.fastScroller.updateLayoutParams { + rv.fastScroller.updateLayoutParams { bottomMargin = insets.bottom } if (activity is MainActivity) { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/adapter/TypedListSpacingDecoration.kt b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/adapter/TypedListSpacingDecoration.kt index a34ed2d07..dd06e62ef 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/adapter/TypedListSpacingDecoration.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/adapter/TypedListSpacingDecoration.kt @@ -29,7 +29,10 @@ class TypedListSpacingDecoration( ListItemType.FILTER_TAG -> outRect.set(0) ListItemType.HEADER -> outRect.set(spacingList, 0, spacingList, 0) - ListItemType.MANGA_LIST -> outRect.set(spacingList) + + ListItemType.EXPLORE_SOURCE_LIST, + ListItemType.MANGA_LIST -> outRect.set(spacingList, 0, spacingList, 0) + ListItemType.DOWNLOAD, ListItemType.MANGA_LIST_DETAILED -> outRect.set(spacingList) @@ -43,7 +46,6 @@ class TypedListSpacingDecoration( ListItemType.STATE_EMPTY, ListItemType.EXPLORE_BUTTONS, ListItemType.EXPLORE_SOURCE_GRID, - ListItemType.EXPLORE_SOURCE_LIST, ListItemType.EXPLORE_SUGGESTION, ListItemType.MANGA_NESTED_GROUP, null -> outRect.set(0) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/multi/MultiSearchViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/multi/MultiSearchViewModel.kt index f9252b55c..d6dfe6c26 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/multi/MultiSearchViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/multi/MultiSearchViewModel.kt @@ -107,6 +107,9 @@ class MultiSearchViewModel @Inject constructor( @CheckResult private fun searchImpl(q: String): Flow> = channelFlow { val sources = sourcesRepository.getEnabledSources() + if (sources.isEmpty()) { + return@channelFlow + } val semaphore = Semaphore(MAX_PARALLELISM) for (source in sources) { launch { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/onboard/OnboardViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/onboard/OnboardViewModel.kt index e8f413216..529cd1392 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/onboard/OnboardViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/onboard/OnboardViewModel.kt @@ -1,6 +1,5 @@ package org.koitharu.kotatsu.settings.onboard -import androidx.annotation.WorkerThread import androidx.core.os.LocaleListCompat import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers @@ -10,9 +9,11 @@ import org.koitharu.kotatsu.core.ui.BaseViewModel import org.koitharu.kotatsu.core.util.ext.map import org.koitharu.kotatsu.core.util.ext.mapToSet import org.koitharu.kotatsu.explore.data.MangaSourcesRepository +import org.koitharu.kotatsu.parsers.model.MangaSource import org.koitharu.kotatsu.parsers.util.mapNotNullToSet import org.koitharu.kotatsu.parsers.util.toTitleCase import org.koitharu.kotatsu.settings.onboard.model.SourceLocale +import java.util.EnumSet import java.util.Locale import javax.inject.Inject @@ -43,8 +44,7 @@ class OnboardViewModel @Inject constructor( repository.getEnabledSources().mapNotNullToSet { x -> x.locale }, ) } - rebuildList() - repository.assimilateNewSources() + commit() } } @@ -58,15 +58,16 @@ class OnboardViewModel @Inject constructor( val prevJob = updateJob updateJob = launchJob(Dispatchers.Default) { prevJob.join() - val sources = allSources.filter { x -> x.locale == key } - repository.setSourcesEnabled(sources, isChecked) - rebuildList() + commit() } } } - @WorkerThread - private fun rebuildList() { + private suspend fun commit() { + val enabledSources = allSources.filterTo(EnumSet.noneOf(MangaSource::class.java)) { x -> + x.locale in selectedLocales + } + repository.setSourcesEnabledExclusive(enabledSources) list.value = locales.map { (key, srcs) -> val locale = if (key != null) { Locale(key) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/onboard/adapter/SourceLocaleAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/onboard/adapter/SourceLocaleAD.kt index 3d5dfae35..f5ae32b15 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/onboard/adapter/SourceLocaleAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/onboard/adapter/SourceLocaleAD.kt @@ -1,5 +1,6 @@ package org.koitharu.kotatsu.settings.onboard.adapter +import android.widget.CompoundButton import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.util.ext.setChecked @@ -13,13 +14,16 @@ fun sourceLocaleAD( { inflater, parent -> ItemSourceLocaleBinding.inflate(inflater, parent, false) }, ) { - binding.switchToggle.setOnCheckedChangeListener { _, isChecked -> + val checkedChangeListener = CompoundButton.OnCheckedChangeListener { _, isChecked -> listener.onItemCheckedChanged(item, isChecked) } + binding.switchToggle.setOnCheckedChangeListener(checkedChangeListener) bind { payloads -> binding.textViewTitle.text = item.title ?: getString(R.string.different_languages) binding.textViewDescription.textAndVisible = item.summary + binding.switchToggle.setOnCheckedChangeListener(null) binding.switchToggle.setChecked(item.isChecked, payloads.isNotEmpty()) + binding.switchToggle.setOnCheckedChangeListener(checkedChangeListener) } } diff --git a/app/src/main/res/layout/fragment_explore.xml b/app/src/main/res/layout/fragment_explore.xml index 6267e23f6..acf916849 100644 --- a/app/src/main/res/layout/fragment_explore.xml +++ b/app/src/main/res/layout/fragment_explore.xml @@ -7,9 +7,6 @@ android:layout_height="match_parent" android:clipToPadding="false" android:orientation="vertical" - android:paddingLeft="@dimen/list_spacing" - android:paddingTop="@dimen/grid_spacing_outer" - android:paddingRight="@dimen/list_spacing" - android:paddingBottom="@dimen/grid_spacing_outer" + android:padding="@dimen/list_spacing" android:scrollbars="vertical" tools:listitem="@layout/item_explore_source_list" /> diff --git a/app/src/main/res/layout/item_explore_buttons.xml b/app/src/main/res/layout/item_explore_buttons.xml index e55b90d35..576c90ad8 100644 --- a/app/src/main/res/layout/item_explore_buttons.xml +++ b/app/src/main/res/layout/item_explore_buttons.xml @@ -4,8 +4,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingHorizontal="8dp" - android:paddingVertical="4dp"> + android:paddingHorizontal="@dimen/list_spacing" + android:paddingBottom="@dimen/list_spacing"> - + android:clipChildren="false"> + android:textAppearance="?attr/textAppearanceBodyLarge" + app:layout_constraintBottom_toBottomOf="@id/imageView_icon" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toEndOf="@+id/imageView_icon" + app:layout_constraintTop_toTopOf="@+id/imageView_icon" + tools:text="@tools:sample/lorem" /> - +