From cbb8f256450362c5dd899bd3c0acdcc3cdf28a8d Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 17 Jun 2020 22:39:45 -0400 Subject: [PATCH] Allow extension details header to scroll --- .../details/ExtensionDetailsController.kt | 37 ++---- .../details/ExtensionDetailsHeaderAdapter.kt | 62 +++++++++++ .../layout/extension_detail_controller.xml | 105 +----------------- .../res/layout/extension_detail_header.xml | 98 ++++++++++++++++ 4 files changed, 172 insertions(+), 130 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsHeaderAdapter.kt create mode 100644 app/src/main/res/layout/extension_detail_header.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt index 8aa62b84a..e8fba01fb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt @@ -19,6 +19,7 @@ import androidx.preference.SwitchPreferenceCompat import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.DividerItemDecoration.VERTICAL import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.MergeAdapter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.EmptyPreferenceDataStore import eu.kanade.tachiyomi.data.preference.PreferencesHelper @@ -31,17 +32,14 @@ import eu.kanade.tachiyomi.source.getPreferenceKey import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction -import eu.kanade.tachiyomi.ui.browse.extension.getApplicationIcon import eu.kanade.tachiyomi.util.preference.DSL import eu.kanade.tachiyomi.util.preference.onChange import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.switchSettingsPreference import eu.kanade.tachiyomi.util.system.LocaleHelper -import eu.kanade.tachiyomi.util.view.visible import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach -import reactivecircus.flowbinding.android.view.clicks import uy.kohesive.injekt.injectLazy @SuppressLint("RestrictedApi") @@ -84,30 +82,15 @@ class ExtensionDetailsController(bundle: Bundle? = null) : val extension = presenter.extension ?: return val context = view.context - extension.getApplicationIcon(context)?.let { binding.extensionIcon.setImageDrawable(it) } - binding.extensionTitle.text = extension.name - binding.extensionVersion.text = context.getString(R.string.ext_version_info, extension.versionName) - binding.extensionLang.text = context.getString(R.string.ext_language_info, LocaleHelper.getSourceDisplayName(extension.lang, context)) - binding.extensionPkg.text = extension.pkgName - - binding.extensionUninstallButton.clicks() - .onEach { presenter.uninstallExtension() } - .launchIn(scope) - - if (extension.isObsolete) { - binding.extensionWarningBanner.visible() - binding.extensionWarningBanner.setText(R.string.obsolete_extension_message) - } - - if (extension.isUnofficial) { - binding.extensionWarningBanner.visible() - binding.extensionWarningBanner.setText(R.string.unofficial_extension_message) - } - - initPreferences(context, extension) + binding.extensionPrefsRecycler.layoutManager = LinearLayoutManager(context) + binding.extensionPrefsRecycler.adapter = MergeAdapter( + ExtensionDetailsHeaderAdapter(presenter), + initPreferencesAdapter(context, extension) + ) + binding.extensionPrefsRecycler.addItemDecoration(DividerItemDecoration(context, VERTICAL)) } - private fun initPreferences(context: Context, extension: Extension.Installed) { + private fun initPreferencesAdapter(context: Context, extension: Extension.Installed): PreferenceGroupAdapter { val themedContext = getPreferenceThemeContext() val manager = PreferenceManager(themedContext) manager.preferenceDataStore = EmptyPreferenceDataStore() @@ -181,9 +164,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) : } } - binding.extensionPrefsRecycler.layoutManager = LinearLayoutManager(context) - binding.extensionPrefsRecycler.adapter = PreferenceGroupAdapter(screen) - binding.extensionPrefsRecycler.addItemDecoration(DividerItemDecoration(context, VERTICAL)) + return PreferenceGroupAdapter(screen) } override fun onDestroyView(view: View) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsHeaderAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsHeaderAdapter.kt new file mode 100644 index 000000000..603ae78c2 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsHeaderAdapter.kt @@ -0,0 +1,62 @@ +package eu.kanade.tachiyomi.ui.browse.extension.details + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.databinding.ExtensionDetailHeaderBinding +import eu.kanade.tachiyomi.ui.browse.extension.getApplicationIcon +import eu.kanade.tachiyomi.util.system.LocaleHelper +import eu.kanade.tachiyomi.util.view.visible +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import reactivecircus.flowbinding.android.view.clicks + +class ExtensionDetailsHeaderAdapter(private val presenter: ExtensionDetailsPresenter) : + RecyclerView.Adapter() { + + private val scope = CoroutineScope(Job() + Dispatchers.Main) + private lateinit var binding: ExtensionDetailHeaderBinding + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HeaderViewHolder { + binding = ExtensionDetailHeaderBinding.inflate(LayoutInflater.from(parent.context), parent, false) + return HeaderViewHolder(binding.root) + } + + override fun getItemCount(): Int = 1 + + override fun onBindViewHolder(holder: HeaderViewHolder, position: Int) { + holder.bind() + } + + inner class HeaderViewHolder(private val view: View) : RecyclerView.ViewHolder(view) { + fun bind() { + val extension = presenter.extension ?: return + val context = view.context + + extension.getApplicationIcon(context)?.let { binding.extensionIcon.setImageDrawable(it) } + binding.extensionTitle.text = extension.name + binding.extensionVersion.text = context.getString(R.string.ext_version_info, extension.versionName) + binding.extensionLang.text = context.getString(R.string.ext_language_info, LocaleHelper.getSourceDisplayName(extension.lang, context)) + binding.extensionPkg.text = extension.pkgName + + binding.extensionUninstallButton.clicks() + .onEach { presenter.uninstallExtension() } + .launchIn(scope) + + if (extension.isObsolete) { + binding.extensionWarningBanner.visible() + binding.extensionWarningBanner.setText(R.string.obsolete_extension_message) + } + + if (extension.isUnofficial) { + binding.extensionWarningBanner.visible() + binding.extensionWarningBanner.setText(R.string.unofficial_extension_message) + } + } + } +} diff --git a/app/src/main/res/layout/extension_detail_controller.xml b/app/src/main/res/layout/extension_detail_controller.xml index bfb275204..321b78630 100644 --- a/app/src/main/res/layout/extension_detail_controller.xml +++ b/app/src/main/res/layout/extension_detail_controller.xml @@ -1,104 +1,5 @@ - - - - - - - - - - - - - - - - -