mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Add: Sort Order of Installed app will be same as main page (Closes #65)
Improve: Move AppsList*.kt(Products*.kt) to different package
This commit is contained in:
parent
c64a922640
commit
f110c610d6
@ -22,6 +22,7 @@ import com.looker.droidify.databinding.TabsToolbarBinding
|
||||
import com.looker.droidify.entity.ProductItem
|
||||
import com.looker.droidify.service.Connection
|
||||
import com.looker.droidify.service.SyncService
|
||||
import com.looker.droidify.ui.appsList.AppListFragment
|
||||
import com.looker.droidify.utility.RxUtils
|
||||
import com.looker.droidify.utility.Utils
|
||||
import com.looker.droidify.utility.extension.android.*
|
||||
@ -85,7 +86,7 @@ class TabsFragment : ScreenFragment() {
|
||||
|
||||
private val syncConnection = Connection(SyncService::class.java, onBind = { _, _ ->
|
||||
viewPager?.let {
|
||||
val source = ProductsFragment.Source.values()[it.currentItem]
|
||||
val source = AppListFragment.Source.values()[it.currentItem]
|
||||
updateUpdateNotificationBlocker(source)
|
||||
}
|
||||
})
|
||||
@ -96,9 +97,9 @@ class TabsFragment : ScreenFragment() {
|
||||
|
||||
private var needSelectUpdates = false
|
||||
|
||||
private val productFragments: Sequence<ProductsFragment>
|
||||
private val productFragments: Sequence<AppListFragment>
|
||||
get() = if (host == null) emptySequence() else
|
||||
childFragmentManager.fragments.asSequence().mapNotNull { it as? ProductsFragment }
|
||||
childFragmentManager.fragments.asSequence().mapNotNull { it as? AppListFragment }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -212,9 +213,9 @@ class TabsFragment : ScreenFragment() {
|
||||
viewPager = ViewPager2(content.context).apply {
|
||||
id = R.id.fragment_pager
|
||||
adapter = object : FragmentStateAdapter(this@TabsFragment) {
|
||||
override fun getItemCount(): Int = ProductsFragment.Source.values().size
|
||||
override fun createFragment(position: Int): Fragment = ProductsFragment(
|
||||
ProductsFragment
|
||||
override fun getItemCount(): Int = AppListFragment.Source.values().size
|
||||
override fun createFragment(position: Int): Fragment = AppListFragment(
|
||||
AppListFragment
|
||||
.Source.values()[position]
|
||||
)
|
||||
}
|
||||
@ -225,7 +226,7 @@ class TabsFragment : ScreenFragment() {
|
||||
|
||||
viewPager?.let {
|
||||
TabLayoutMediator(layout.tabs, it) { tab, position ->
|
||||
tab.text = getString(ProductsFragment.Source.values()[position].titleResId)
|
||||
tab.text = getString(AppListFragment.Source.values()[position].titleResId)
|
||||
}.attach()
|
||||
}
|
||||
|
||||
@ -336,7 +337,7 @@ class TabsFragment : ScreenFragment() {
|
||||
override fun onAttachFragment(childFragment: Fragment) {
|
||||
super.onAttachFragment(childFragment)
|
||||
|
||||
if (view != null && childFragment is ProductsFragment) {
|
||||
if (view != null && childFragment is AppListFragment) {
|
||||
childFragment.setSearchQuery(searchQuery)
|
||||
childFragment.setSection(section)
|
||||
childFragment.setOrder(Preferences[Preferences.Key.SortOrder].order)
|
||||
@ -365,7 +366,7 @@ class TabsFragment : ScreenFragment() {
|
||||
if (view != null) {
|
||||
val viewPager = viewPager
|
||||
viewPager?.setCurrentItem(
|
||||
ProductsFragment.Source.UPDATES.ordinal,
|
||||
AppListFragment.Source.UPDATES.ordinal,
|
||||
allowSmooth && viewPager.isLaidOut
|
||||
)
|
||||
} else {
|
||||
@ -373,8 +374,8 @@ class TabsFragment : ScreenFragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateUpdateNotificationBlocker(activeSource: ProductsFragment.Source) {
|
||||
val blockerFragment = if (activeSource == ProductsFragment.Source.UPDATES) {
|
||||
private fun updateUpdateNotificationBlocker(activeSource: AppListFragment.Source) {
|
||||
val blockerFragment = if (activeSource == AppListFragment.Source.UPDATES) {
|
||||
productFragments.find { it.source == activeSource }
|
||||
} else {
|
||||
null
|
||||
@ -464,9 +465,9 @@ class TabsFragment : ScreenFragment() {
|
||||
positionOffsetPixels: Int
|
||||
) {
|
||||
val layout = layout!!
|
||||
val fromSections = ProductsFragment.Source.values()[position].sections
|
||||
val fromSections = AppListFragment.Source.values()[position].sections
|
||||
val toSections = if (positionOffset <= 0f) fromSections else
|
||||
ProductsFragment.Source.values()[position + 1].sections
|
||||
AppListFragment.Source.values()[position + 1].sections
|
||||
val offset = if (fromSections != toSections) {
|
||||
if (fromSections) 1f - positionOffset else positionOffset
|
||||
} else {
|
||||
@ -484,7 +485,7 @@ class TabsFragment : ScreenFragment() {
|
||||
}
|
||||
|
||||
override fun onPageSelected(position: Int) {
|
||||
val source = ProductsFragment.Source.values()[position]
|
||||
val source = AppListFragment.Source.values()[position]
|
||||
updateUpdateNotificationBlocker(source)
|
||||
sortOrderMenu!!.first.apply {
|
||||
isVisible = source.order
|
||||
@ -501,7 +502,7 @@ class TabsFragment : ScreenFragment() {
|
||||
}
|
||||
|
||||
override fun onPageScrollStateChanged(state: Int) {
|
||||
val source = ProductsFragment.Source.values()[viewPager!!.currentItem]
|
||||
val source = AppListFragment.Source.values()[viewPager!!.currentItem]
|
||||
layout!!.sectionChange.isEnabled =
|
||||
state != ViewPager2.SCROLL_STATE_DRAGGING && source.sections
|
||||
if (state == ViewPager2.SCROLL_STATE_IDLE) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.looker.droidify.screen
|
||||
package com.looker.droidify.ui.appsList
|
||||
|
||||
import android.database.Cursor
|
||||
import android.os.Bundle
|
||||
@ -14,7 +14,8 @@ import com.looker.droidify.R
|
||||
import com.looker.droidify.database.CursorOwner
|
||||
import com.looker.droidify.database.Database
|
||||
import com.looker.droidify.entity.ProductItem
|
||||
import com.looker.droidify.ui.ProductsViewModel
|
||||
import com.looker.droidify.screen.BaseFragment
|
||||
import com.looker.droidify.screen.ProductsAdapter
|
||||
import com.looker.droidify.utility.RxUtils
|
||||
import com.looker.droidify.widget.RecyclerFastScroller
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
@ -23,9 +24,9 @@ import io.reactivex.rxjava3.disposables.Disposable
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import kotlinx.coroutines.flow.collect
|
||||
|
||||
class ProductsFragment() : BaseFragment(), CursorOwner.Callback {
|
||||
class AppListFragment() : BaseFragment(), CursorOwner.Callback {
|
||||
|
||||
private val viewModel: ProductsViewModel by viewModels()
|
||||
private val viewModel: AppListViewModel by viewModels()
|
||||
|
||||
companion object {
|
||||
private const val EXTRA_SOURCE = "source"
|
||||
@ -34,7 +35,7 @@ class ProductsFragment() : BaseFragment(), CursorOwner.Callback {
|
||||
|
||||
enum class Source(val titleResId: Int, val sections: Boolean, val order: Boolean) {
|
||||
AVAILABLE(R.string.available, true, true),
|
||||
INSTALLED(R.string.installed, false, false),
|
||||
INSTALLED(R.string.installed, false, true),
|
||||
UPDATES(R.string.updates, false, false)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.looker.droidify.ui
|
||||
package com.looker.droidify.ui.appsList
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
@ -10,7 +10,7 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class ProductsViewModel : ViewModel() {
|
||||
class AppListViewModel : ViewModel() {
|
||||
|
||||
private val _order = MutableStateFlow(ProductItem.Order.LAST_UPDATE)
|
||||
private val _sections = MutableStateFlow<ProductItem.Section>(ProductItem.Section.All)
|
Loading…
x
Reference in New Issue
Block a user