Allow extension details header to scroll

This commit is contained in:
arkon 2020-06-17 22:39:45 -04:00
parent 24ff7ff67c
commit cbb8f25645
4 changed files with 172 additions and 130 deletions

View File

@ -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) {

View File

@ -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<ExtensionDetailsHeaderAdapter.HeaderViewHolder>() {
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)
}
}
}
}

View File

@ -1,104 +1,5 @@
<?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"
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/extension_prefs_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/extension_warning_banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorError"
android:gravity="center"
android:padding="16dp"
android:textColor="?attr/colorOnError"
android:visibility="gone"
tools:visibility="visible" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="2dp"
android:padding="16dp">
<ImageView
android:id="@+id/extension_icon"
android:layout_width="56dp"
android:layout_height="56dp"
android:src="@mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="@id/extension_pkg"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/extension_title"
style="@style/TextAppearance.Regular.SubHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:elevation="3dp"
app:layout_constraintStart_toEndOf="@id/extension_icon"
app:layout_constraintTop_toTopOf="parent"
tools:text="Tachiyomi: Extension" />
<TextView
android:id="@+id/extension_version"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:elevation="3dp"
android:gravity="center"
app:layout_constraintStart_toStartOf="@id/extension_title"
app:layout_constraintTop_toBottomOf="@id/extension_title"
tools:text="Version: 1.0.0" />
<TextView
android:id="@+id/extension_lang"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:elevation="3dp"
android:gravity="center"
app:layout_constraintStart_toStartOf="@id/extension_title"
app:layout_constraintTop_toBottomOf="@id/extension_version"
tools:text="Language: English" />
<TextView
android:id="@+id/extension_pkg"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:elevation="3dp"
android:ellipsize="middle"
android:singleLine="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/extension_title"
app:layout_constraintTop_toBottomOf="@id/extension_lang"
tools:text="eu.kanade.tachiyomi.extension.en.myext" />
<Button
android:id="@+id/extension_uninstall_button"
style="@style/Theme.Widget.Button.FilledAccent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:text="@string/ext_uninstall"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/extension_lang" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/extension_prefs_recycler"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
android:layout_height="wrap_content" />

View File

@ -0,0 +1,98 @@
<?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="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/extension_warning_banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorError"
android:gravity="center"
android:padding="16dp"
android:textColor="?attr/colorOnError"
android:visibility="gone"
tools:visibility="visible" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="2dp"
android:padding="16dp">
<ImageView
android:id="@+id/extension_icon"
android:layout_width="56dp"
android:layout_height="56dp"
android:src="@mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="@id/extension_pkg"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/extension_title"
style="@style/TextAppearance.Regular.SubHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:elevation="3dp"
app:layout_constraintStart_toEndOf="@id/extension_icon"
app:layout_constraintTop_toTopOf="parent"
tools:text="Tachiyomi: Extension" />
<TextView
android:id="@+id/extension_version"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:elevation="3dp"
android:gravity="center"
app:layout_constraintStart_toStartOf="@id/extension_title"
app:layout_constraintTop_toBottomOf="@id/extension_title"
tools:text="Version: 1.0.0" />
<TextView
android:id="@+id/extension_lang"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:elevation="3dp"
android:gravity="center"
app:layout_constraintStart_toStartOf="@id/extension_title"
app:layout_constraintTop_toBottomOf="@id/extension_version"
tools:text="Language: English" />
<TextView
android:id="@+id/extension_pkg"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:elevation="3dp"
android:ellipsize="middle"
android:singleLine="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/extension_title"
app:layout_constraintTop_toBottomOf="@id/extension_lang"
tools:text="eu.kanade.tachiyomi.extension.en.myext" />
<Button
android:id="@+id/extension_uninstall_button"
style="@style/Theme.Widget.Button.FilledAccent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:text="@string/ext_uninstall"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/extension_lang" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>