mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-22 19:02:12 +00:00
Add: New adapters to LatestFragment
This commit is contained in:
parent
113cb9864d
commit
292b4ae9c3
@ -6,31 +6,37 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.looker.droidify.R
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.looker.droidify.database.CursorOwner
|
||||
import com.looker.droidify.databinding.FragmentLatestXBinding
|
||||
import com.looker.droidify.ui.adapters.AppListAdapter
|
||||
import com.looker.droidify.entity.ProductItem
|
||||
import com.looker.droidify.entity.Repository
|
||||
import com.looker.droidify.ui.items.HAppItem
|
||||
import com.looker.droidify.ui.items.VAppItem
|
||||
import com.looker.droidify.ui.viewmodels.MainNavFragmentViewModelX
|
||||
import com.looker.droidify.utility.RxUtils
|
||||
import com.looker.droidify.widget.RecyclerFastScroller
|
||||
import com.mikepenz.fastadapter.FastAdapter
|
||||
import com.mikepenz.fastadapter.adapters.ItemAdapter
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.core.Observable
|
||||
import io.reactivex.rxjava3.disposables.Disposable
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class LatestFragment : MainNavFragmentX(), CursorOwner.Callback {
|
||||
|
||||
override val viewModel: MainNavFragmentViewModelX by viewModels()
|
||||
private lateinit var binding: FragmentLatestXBinding
|
||||
|
||||
override val source = Source.UPDATES
|
||||
private val updatedItemAdapter = ItemAdapter<VAppItem>()
|
||||
private var updatedFastAdapter: FastAdapter<VAppItem>? = null
|
||||
private val newItemAdapter = ItemAdapter<HAppItem>()
|
||||
private var newFastAdapter: FastAdapter<HAppItem>? = null
|
||||
|
||||
override val source = Source.AVAILABLE
|
||||
|
||||
private var repositories: Map<Long, Repository> = mapOf()
|
||||
private var repositoriesDisposable: Disposable? = null
|
||||
|
||||
override fun onCreateView(
|
||||
@ -42,12 +48,22 @@ class LatestFragment : MainNavFragmentX(), CursorOwner.Callback {
|
||||
binding = FragmentLatestXBinding.inflate(inflater, container, false)
|
||||
binding.lifecycleOwner = this
|
||||
|
||||
binding.recyclerView.apply {
|
||||
id = android.R.id.list
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
updatedFastAdapter = FastAdapter.with(updatedItemAdapter)
|
||||
updatedFastAdapter?.setHasStableIds(true)
|
||||
binding.updatedRecycler.apply {
|
||||
layoutManager = LinearLayoutManager(requireContext())
|
||||
isMotionEventSplittingEnabled = false
|
||||
isVerticalScrollBarEnabled = false
|
||||
adapter = AppListAdapter { mainActivityX.navigateProduct(it.packageName) }
|
||||
adapter = updatedFastAdapter
|
||||
RecyclerFastScroller(this)
|
||||
}
|
||||
newFastAdapter = FastAdapter.with(newItemAdapter)
|
||||
newFastAdapter?.setHasStableIds(true)
|
||||
binding.newRecycler.apply {
|
||||
layoutManager = LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL, false)
|
||||
isMotionEventSplittingEnabled = false
|
||||
isVerticalScrollBarEnabled = false
|
||||
adapter = newFastAdapter
|
||||
RecyclerFastScroller(this)
|
||||
}
|
||||
return binding.root
|
||||
@ -63,7 +79,7 @@ class LatestFragment : MainNavFragmentX(), CursorOwner.Callback {
|
||||
.flatMapSingle { RxUtils.querySingle { mainActivityX.db.repositoryDao.all.mapNotNull { it.trueData } } }
|
||||
.map { list -> list.asSequence().map { Pair(it.id, it) }.toMap() }
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { (binding.recyclerView.adapter as? AppListAdapter)?.repositories = it }
|
||||
.subscribe { repositories = it }
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
@ -75,9 +91,16 @@ class LatestFragment : MainNavFragmentX(), CursorOwner.Callback {
|
||||
}
|
||||
|
||||
override fun onCursorData(request: CursorOwner.Request, cursor: Cursor?) {
|
||||
// TODO create app list out of cursor and use those on the different RecycleViews
|
||||
(binding.recyclerView.adapter as? AppListAdapter)?.apply {
|
||||
this.cursor = cursor
|
||||
// TODO get a list instead of the cursor
|
||||
// TODO use LiveData and observers instead of listeners
|
||||
val appItemList: List<ProductItem> = listOf()
|
||||
updatedItemAdapter.set(appItemList // .filter { !it.hasOneRelease }
|
||||
.map { VAppItem(it, repositories[it.repositoryId]) }
|
||||
)
|
||||
newItemAdapter.set(appItemList // .filter { it.hasOneRelease }
|
||||
.map { HAppItem(it, repositories[it.repositoryId]) }
|
||||
)
|
||||
/*
|
||||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
||||
emptyText = when {
|
||||
@ -88,6 +111,6 @@ class LatestFragment : MainNavFragmentX(), CursorOwner.Callback {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@ -44,12 +44,12 @@
|
||||
android:layout_marginHorizontal="12dp"
|
||||
android:layout_marginVertical="14dp"
|
||||
android:text="@string/new_applications"
|
||||
app:layout_constraintBottom_toTopOf="@id/updatedRecycler"
|
||||
app:layout_constraintBottom_toTopOf="@id/newRecycler"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/updatedRecycler"
|
||||
android:id="@+id/newRecycler"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
@ -112,7 +112,7 @@
|
||||
app:layout_constraintTop_toBottomOf="@id/modeBar">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:id="@+id/updatedRecycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false"
|
||||
|
Loading…
x
Reference in New Issue
Block a user