Update/Remove: Use ComposeView in MainNav fragments / Remove Recyclers&FastAdapters.

This commit is contained in:
machiav3lli 2022-02-17 23:19:22 +01:00
parent 0733b80c56
commit b994df4ede
6 changed files with 48 additions and 212 deletions

View File

@ -8,18 +8,11 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.looker.droidify.database.entity.Product
import com.looker.droidify.database.entity.Repository
import com.looker.droidify.databinding.FragmentExploreXBinding
import com.looker.droidify.ui.items.VAppItem
import com.looker.droidify.utility.PRODUCT_ASYNC_DIFFER_CONFIG
import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.IAdapter
import com.mikepenz.fastadapter.paged.PagedModelAdapter
// TODO add chips bar to navigate categories
class ExploreFragment : MainNavFragmentX() {
private lateinit var binding: FragmentExploreXBinding
private lateinit var appsItemAdapter: PagedModelAdapter<Product, VAppItem>
private var appsFastAdapter: FastAdapter<VAppItem>? = null
override val primarySource = Source.AVAILABLE
override val secondarySource = Source.AVAILABLE
@ -38,31 +31,9 @@ class ExploreFragment : MainNavFragmentX() {
}
override fun setupAdapters() {
appsItemAdapter = PagedModelAdapter<Product, VAppItem>(PRODUCT_ASYNC_DIFFER_CONFIG) {
VAppItem(it.item, repositories[it.repository_id])
}
appsFastAdapter = FastAdapter.with(appsItemAdapter)
appsFastAdapter?.setHasStableIds(true)
appsFastAdapter?.onClickListener =
{ _: View?, _: IAdapter<VAppItem>?, item: VAppItem?, _: Int? ->
item?.item?.let {
AppSheetX(it.packageName)
.showNow(parentFragmentManager, "Product ${it.packageName}")
}
false
}
binding.recyclerView.apply {
layoutManager = LinearLayoutManager(requireContext())
setHasFixedSize(true)
adapter = appsFastAdapter
}
}
override fun setupLayout() {
viewModel.primaryProducts.observe(viewLifecycleOwner) {
appsItemAdapter.submitList(it)
appsFastAdapter?.notifyDataSetChanged()
}
viewModel.repositories.observe(viewLifecycleOwner) {
repositories = it.associateBy { repo -> repo.id }
}

View File

@ -4,26 +4,14 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.looker.droidify.database.entity.Product
import com.looker.droidify.database.entity.Repository
import com.looker.droidify.databinding.FragmentInstalledXBinding
import com.looker.droidify.ui.items.HAppItem
import com.looker.droidify.ui.items.VAppItem
import com.looker.droidify.utility.PRODUCT_ASYNC_DIFFER_CONFIG
import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.paged.PagedModelAdapter
class InstalledFragment : MainNavFragmentX() {
private lateinit var binding: FragmentInstalledXBinding
private lateinit var installedItemAdapter: PagedModelAdapter<Product, VAppItem>
private var installedFastAdapter: FastAdapter<VAppItem>? = null
private lateinit var updatedItemAdapter: PagedModelAdapter<Product, HAppItem>
private var updatedFastAdapter: FastAdapter<HAppItem>? = null
override val primarySource = Source.INSTALLED
override val secondarySource = Source.UPDATES
@ -41,39 +29,16 @@ class InstalledFragment : MainNavFragmentX() {
}
override fun setupAdapters() {
installedItemAdapter = PagedModelAdapter<Product, VAppItem>(PRODUCT_ASYNC_DIFFER_CONFIG) {
VAppItem(it.item, repositories[it.repository_id])
}
updatedItemAdapter = PagedModelAdapter<Product, HAppItem>(PRODUCT_ASYNC_DIFFER_CONFIG) {
HAppItem(it.item, repositories[it.repository_id])
}
installedFastAdapter = FastAdapter.with(installedItemAdapter)
installedFastAdapter?.setHasStableIds(true)
binding.installedRecycler.apply {
layoutManager = LinearLayoutManager(requireContext())
adapter = installedFastAdapter
}
updatedFastAdapter = FastAdapter.with(updatedItemAdapter)
updatedFastAdapter?.setHasStableIds(true)
binding.updatedRecycler.apply {
layoutManager = LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL, false)
adapter = updatedFastAdapter
}
}
override fun setupLayout() {
binding.buttonUpdated.setOnClickListener {
binding.updatedRecycler.apply {
visibility = if (visibility == View.VISIBLE) View.GONE else View.VISIBLE
}
}
viewModel.primaryProducts.observe(viewLifecycleOwner) {
installedItemAdapter.submitList(it)
}
viewModel.secondaryProducts.observe(viewLifecycleOwner) {
binding.updatedBar.visibility = if (it.isNotEmpty()) View.VISIBLE else View.GONE
updatedItemAdapter.submitList(it)
}
viewModel.repositories.observe(viewLifecycleOwner) {
repositories = it.associateBy { repo -> repo.id }

View File

@ -4,26 +4,14 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.looker.droidify.database.entity.Product
import com.looker.droidify.database.entity.Repository
import com.looker.droidify.databinding.FragmentLatestXBinding
import com.looker.droidify.ui.items.HAppItem
import com.looker.droidify.ui.items.VAppItem
import com.looker.droidify.utility.PRODUCT_ASYNC_DIFFER_CONFIG
import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.paged.PagedModelAdapter
class LatestFragment : MainNavFragmentX() {
private lateinit var binding: FragmentLatestXBinding
private lateinit var updatedItemAdapter: PagedModelAdapter<Product, VAppItem>
private var updatedFastAdapter: FastAdapter<VAppItem>? = null
private lateinit var newItemAdapter: PagedModelAdapter<Product, HAppItem>
private var newFastAdapter: FastAdapter<HAppItem>? = null
// TODO replace the source with one that get a certain amount of updated apps
override val primarySource = Source.UPDATED
override val secondarySource = Source.NEW
@ -42,33 +30,12 @@ class LatestFragment : MainNavFragmentX() {
}
override fun setupAdapters() {
updatedItemAdapter = PagedModelAdapter<Product, VAppItem>(PRODUCT_ASYNC_DIFFER_CONFIG) {
VAppItem(it.item, repositories[it.repository_id])
}
newItemAdapter = PagedModelAdapter<Product, HAppItem>(PRODUCT_ASYNC_DIFFER_CONFIG) {
// TODO filter for only new apps and add placeholder
HAppItem(it.item, repositories[it.repository_id])
}
updatedFastAdapter = FastAdapter.with(updatedItemAdapter)
updatedFastAdapter?.setHasStableIds(true)
binding.updatedRecycler.apply {
layoutManager = LinearLayoutManager(requireContext())
adapter = updatedFastAdapter
}
newFastAdapter = FastAdapter.with(newItemAdapter)
newFastAdapter?.setHasStableIds(true)
binding.newRecycler.apply {
layoutManager = LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL, false)
adapter = newFastAdapter
}
}
override fun setupLayout() {
viewModel.primaryProducts.observe(viewLifecycleOwner) {
updatedItemAdapter.submitList(it)
}
viewModel.secondaryProducts.observe(viewLifecycleOwner) {
newItemAdapter.submitList(it)
}
viewModel.repositories.observe(viewLifecycleOwner) {
repositories = it.associateBy { repo -> repo.id }

View File

@ -15,8 +15,7 @@
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
@ -26,21 +25,18 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:id="@+id/scrollLayout"
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:clipToPadding="false">
android:nestedScrollingEnabled="true"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
<androidx.compose.ui.platform.ComposeView
android:id="@+id/primaryComposeRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
tools:listitem="@layout/item_app_vertical_x" />
</androidx.core.widget.NestedScrollView>
android:layout_height="0dp"
android:layout_weight="1" />
</androidx.appcompat.widget.LinearLayoutCompat>
</com.google.android.material.circularreveal.CircularRevealFrameLayout>
</layout>

View File

@ -16,22 +16,22 @@
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<layout 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">
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingHorizontal="8dp">
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/updatedBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/shape_margin_medium"
app:layout_constraintBottom_toTopOf="@id/modeBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@ -47,7 +47,7 @@
android:text="@string/updates"
android:textAlignment="viewStart"
android:textColor="?colorControlNormal"
app:layout_constraintBottom_toTopOf="@id/updatedRecycler"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/buttonUpdateAll"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent"
@ -61,37 +61,26 @@
android:layout_marginEnd="4dp"
android:text="@string/update_all"
app:chipIcon="@drawable/ic_download"
app:layout_constraintBottom_toTopOf="@id/updatedRecycler"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/buttonUpdated"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/updatedRecycler"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:orientation="horizontal"
android:scrollbars="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/buttonUpdated"
tools:listitem="@layout/item_app_horiz_x" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.compose.ui.platform.ComposeView
android:id="@+id/secondaryComposeRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/modeBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/shape_margin_medium"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="horizontal"
android:paddingHorizontal="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/updatedBar">
android:paddingHorizontal="4dp">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/buttonBlocklist"
@ -118,25 +107,11 @@
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/scrollLayout"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="top"
android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/modeBar">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/installedRecycler"
<androidx.compose.ui.platform.ComposeView
android:id="@+id/primaryComposeRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
tools:listitem="@layout/item_app_vertical_x" />
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
android:layout_height="0dp"
android:layout_weight="1" />
</androidx.appcompat.widget.LinearLayoutCompat>
</layout>

View File

@ -16,26 +16,16 @@
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<layout 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">
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingHorizontal="8dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/updatedBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/modeBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
android:orientation="vertical">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/textNew"
@ -43,37 +33,21 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="12dp"
android:layout_marginVertical="14dp"
android:text="@string/new_applications"
app:layout_constraintBottom_toTopOf="@id/newRecycler"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:text="@string/new_applications" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/newRecycler"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:orientation="horizontal"
android:scrollbars="none"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textNew"
tools:listitem="@layout/item_app_horiz_x" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.compose.ui.platform.ComposeView
android:id="@+id/secondaryComposeRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/modeBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/shape_margin_medium"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="horizontal"
android:paddingHorizontal="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/updatedBar">
android:orientation="horizontal">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/textLatest"
@ -100,25 +74,13 @@
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/scrollLayout"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="top"
android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/modeBar">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/updatedRecycler"
<androidx.compose.ui.platform.ComposeView
android:id="@+id/primaryComposeRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
tools:listitem="@layout/item_app_vertical_x" />
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
android:layout_height="0dp"
android:layout_weight="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/modeBar" />
</androidx.appcompat.widget.LinearLayoutCompat>
</layout>