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.Product
import com.looker.droidify.database.entity.Repository import com.looker.droidify.database.entity.Repository
import com.looker.droidify.databinding.FragmentExploreXBinding 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 // TODO add chips bar to navigate categories
class ExploreFragment : MainNavFragmentX() { class ExploreFragment : MainNavFragmentX() {
private lateinit var binding: FragmentExploreXBinding 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 primarySource = Source.AVAILABLE
override val secondarySource = Source.AVAILABLE override val secondarySource = Source.AVAILABLE
@ -38,31 +31,9 @@ class ExploreFragment : MainNavFragmentX() {
} }
override fun setupAdapters() { 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() { override fun setupLayout() {
viewModel.primaryProducts.observe(viewLifecycleOwner) {
appsItemAdapter.submitList(it)
appsFastAdapter?.notifyDataSetChanged()
}
viewModel.repositories.observe(viewLifecycleOwner) { viewModel.repositories.observe(viewLifecycleOwner) {
repositories = it.associateBy { repo -> repo.id } repositories = it.associateBy { repo -> repo.id }
} }

View File

@ -4,26 +4,14 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup 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.Product
import com.looker.droidify.database.entity.Repository import com.looker.droidify.database.entity.Repository
import com.looker.droidify.databinding.FragmentInstalledXBinding 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() { class InstalledFragment : MainNavFragmentX() {
private lateinit var binding: FragmentInstalledXBinding 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 primarySource = Source.INSTALLED
override val secondarySource = Source.UPDATES override val secondarySource = Source.UPDATES
@ -41,39 +29,16 @@ class InstalledFragment : MainNavFragmentX() {
} }
override fun setupAdapters() { 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() { override fun setupLayout() {
binding.buttonUpdated.setOnClickListener { binding.buttonUpdated.setOnClickListener {
binding.updatedRecycler.apply {
visibility = if (visibility == View.VISIBLE) View.GONE else View.VISIBLE
}
} }
viewModel.primaryProducts.observe(viewLifecycleOwner) { viewModel.primaryProducts.observe(viewLifecycleOwner) {
installedItemAdapter.submitList(it)
} }
viewModel.secondaryProducts.observe(viewLifecycleOwner) { viewModel.secondaryProducts.observe(viewLifecycleOwner) {
binding.updatedBar.visibility = if (it.isNotEmpty()) View.VISIBLE else View.GONE binding.updatedBar.visibility = if (it.isNotEmpty()) View.VISIBLE else View.GONE
updatedItemAdapter.submitList(it)
} }
viewModel.repositories.observe(viewLifecycleOwner) { viewModel.repositories.observe(viewLifecycleOwner) {
repositories = it.associateBy { repo -> repo.id } repositories = it.associateBy { repo -> repo.id }

View File

@ -4,26 +4,14 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup 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.Product
import com.looker.droidify.database.entity.Repository import com.looker.droidify.database.entity.Repository
import com.looker.droidify.databinding.FragmentLatestXBinding 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() { class LatestFragment : MainNavFragmentX() {
private lateinit var binding: FragmentLatestXBinding 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 // TODO replace the source with one that get a certain amount of updated apps
override val primarySource = Source.UPDATED override val primarySource = Source.UPDATED
override val secondarySource = Source.NEW override val secondarySource = Source.NEW
@ -42,33 +30,12 @@ class LatestFragment : MainNavFragmentX() {
} }
override fun setupAdapters() { 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() { override fun setupLayout() {
viewModel.primaryProducts.observe(viewLifecycleOwner) { viewModel.primaryProducts.observe(viewLifecycleOwner) {
updatedItemAdapter.submitList(it)
} }
viewModel.secondaryProducts.observe(viewLifecycleOwner) { viewModel.secondaryProducts.observe(viewLifecycleOwner) {
newItemAdapter.submitList(it)
} }
viewModel.repositories.observe(viewLifecycleOwner) { viewModel.repositories.observe(viewLifecycleOwner) {
repositories = it.associateBy { repo -> repo.id } 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 ~ 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/>. ~ along with this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:tools="http://schemas.android.com/tools">
<data> <data>
@ -26,21 +25,18 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView <androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/scrollLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="top" android:nestedScrollingEnabled="true"
android:clipToPadding="false"> android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView <androidx.compose.ui.platform.ComposeView
android:id="@+id/recyclerView" android:id="@+id/primaryComposeRecycler"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="0dp"
android:clipChildren="false" android:layout_weight="1" />
android:clipToPadding="false" </androidx.appcompat.widget.LinearLayoutCompat>
tools:listitem="@layout/item_app_vertical_x" />
</androidx.core.widget.NestedScrollView>
</com.google.android.material.circularreveal.CircularRevealFrameLayout> </com.google.android.material.circularreveal.CircularRevealFrameLayout>
</layout> </layout>

View File

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

View File

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