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.entity.ProductItem
|
||||||
import com.looker.droidify.service.Connection
|
import com.looker.droidify.service.Connection
|
||||||
import com.looker.droidify.service.SyncService
|
import com.looker.droidify.service.SyncService
|
||||||
|
import com.looker.droidify.ui.appsList.AppListFragment
|
||||||
import com.looker.droidify.utility.RxUtils
|
import com.looker.droidify.utility.RxUtils
|
||||||
import com.looker.droidify.utility.Utils
|
import com.looker.droidify.utility.Utils
|
||||||
import com.looker.droidify.utility.extension.android.*
|
import com.looker.droidify.utility.extension.android.*
|
||||||
@ -85,7 +86,7 @@ class TabsFragment : ScreenFragment() {
|
|||||||
|
|
||||||
private val syncConnection = Connection(SyncService::class.java, onBind = { _, _ ->
|
private val syncConnection = Connection(SyncService::class.java, onBind = { _, _ ->
|
||||||
viewPager?.let {
|
viewPager?.let {
|
||||||
val source = ProductsFragment.Source.values()[it.currentItem]
|
val source = AppListFragment.Source.values()[it.currentItem]
|
||||||
updateUpdateNotificationBlocker(source)
|
updateUpdateNotificationBlocker(source)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -96,9 +97,9 @@ class TabsFragment : ScreenFragment() {
|
|||||||
|
|
||||||
private var needSelectUpdates = false
|
private var needSelectUpdates = false
|
||||||
|
|
||||||
private val productFragments: Sequence<ProductsFragment>
|
private val productFragments: Sequence<AppListFragment>
|
||||||
get() = if (host == null) emptySequence() else
|
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?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -212,9 +213,9 @@ class TabsFragment : ScreenFragment() {
|
|||||||
viewPager = ViewPager2(content.context).apply {
|
viewPager = ViewPager2(content.context).apply {
|
||||||
id = R.id.fragment_pager
|
id = R.id.fragment_pager
|
||||||
adapter = object : FragmentStateAdapter(this@TabsFragment) {
|
adapter = object : FragmentStateAdapter(this@TabsFragment) {
|
||||||
override fun getItemCount(): Int = ProductsFragment.Source.values().size
|
override fun getItemCount(): Int = AppListFragment.Source.values().size
|
||||||
override fun createFragment(position: Int): Fragment = ProductsFragment(
|
override fun createFragment(position: Int): Fragment = AppListFragment(
|
||||||
ProductsFragment
|
AppListFragment
|
||||||
.Source.values()[position]
|
.Source.values()[position]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -225,7 +226,7 @@ class TabsFragment : ScreenFragment() {
|
|||||||
|
|
||||||
viewPager?.let {
|
viewPager?.let {
|
||||||
TabLayoutMediator(layout.tabs, it) { tab, position ->
|
TabLayoutMediator(layout.tabs, it) { tab, position ->
|
||||||
tab.text = getString(ProductsFragment.Source.values()[position].titleResId)
|
tab.text = getString(AppListFragment.Source.values()[position].titleResId)
|
||||||
}.attach()
|
}.attach()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,7 +337,7 @@ class TabsFragment : ScreenFragment() {
|
|||||||
override fun onAttachFragment(childFragment: Fragment) {
|
override fun onAttachFragment(childFragment: Fragment) {
|
||||||
super.onAttachFragment(childFragment)
|
super.onAttachFragment(childFragment)
|
||||||
|
|
||||||
if (view != null && childFragment is ProductsFragment) {
|
if (view != null && childFragment is AppListFragment) {
|
||||||
childFragment.setSearchQuery(searchQuery)
|
childFragment.setSearchQuery(searchQuery)
|
||||||
childFragment.setSection(section)
|
childFragment.setSection(section)
|
||||||
childFragment.setOrder(Preferences[Preferences.Key.SortOrder].order)
|
childFragment.setOrder(Preferences[Preferences.Key.SortOrder].order)
|
||||||
@ -365,7 +366,7 @@ class TabsFragment : ScreenFragment() {
|
|||||||
if (view != null) {
|
if (view != null) {
|
||||||
val viewPager = viewPager
|
val viewPager = viewPager
|
||||||
viewPager?.setCurrentItem(
|
viewPager?.setCurrentItem(
|
||||||
ProductsFragment.Source.UPDATES.ordinal,
|
AppListFragment.Source.UPDATES.ordinal,
|
||||||
allowSmooth && viewPager.isLaidOut
|
allowSmooth && viewPager.isLaidOut
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@ -373,8 +374,8 @@ class TabsFragment : ScreenFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateUpdateNotificationBlocker(activeSource: ProductsFragment.Source) {
|
private fun updateUpdateNotificationBlocker(activeSource: AppListFragment.Source) {
|
||||||
val blockerFragment = if (activeSource == ProductsFragment.Source.UPDATES) {
|
val blockerFragment = if (activeSource == AppListFragment.Source.UPDATES) {
|
||||||
productFragments.find { it.source == activeSource }
|
productFragments.find { it.source == activeSource }
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
@ -464,9 +465,9 @@ class TabsFragment : ScreenFragment() {
|
|||||||
positionOffsetPixels: Int
|
positionOffsetPixels: Int
|
||||||
) {
|
) {
|
||||||
val layout = layout!!
|
val layout = layout!!
|
||||||
val fromSections = ProductsFragment.Source.values()[position].sections
|
val fromSections = AppListFragment.Source.values()[position].sections
|
||||||
val toSections = if (positionOffset <= 0f) fromSections else
|
val toSections = if (positionOffset <= 0f) fromSections else
|
||||||
ProductsFragment.Source.values()[position + 1].sections
|
AppListFragment.Source.values()[position + 1].sections
|
||||||
val offset = if (fromSections != toSections) {
|
val offset = if (fromSections != toSections) {
|
||||||
if (fromSections) 1f - positionOffset else positionOffset
|
if (fromSections) 1f - positionOffset else positionOffset
|
||||||
} else {
|
} else {
|
||||||
@ -484,7 +485,7 @@ class TabsFragment : ScreenFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPageSelected(position: Int) {
|
override fun onPageSelected(position: Int) {
|
||||||
val source = ProductsFragment.Source.values()[position]
|
val source = AppListFragment.Source.values()[position]
|
||||||
updateUpdateNotificationBlocker(source)
|
updateUpdateNotificationBlocker(source)
|
||||||
sortOrderMenu!!.first.apply {
|
sortOrderMenu!!.first.apply {
|
||||||
isVisible = source.order
|
isVisible = source.order
|
||||||
@ -501,7 +502,7 @@ class TabsFragment : ScreenFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPageScrollStateChanged(state: Int) {
|
override fun onPageScrollStateChanged(state: Int) {
|
||||||
val source = ProductsFragment.Source.values()[viewPager!!.currentItem]
|
val source = AppListFragment.Source.values()[viewPager!!.currentItem]
|
||||||
layout!!.sectionChange.isEnabled =
|
layout!!.sectionChange.isEnabled =
|
||||||
state != ViewPager2.SCROLL_STATE_DRAGGING && source.sections
|
state != ViewPager2.SCROLL_STATE_DRAGGING && source.sections
|
||||||
if (state == ViewPager2.SCROLL_STATE_IDLE) {
|
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.database.Cursor
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@ -14,7 +14,8 @@ import com.looker.droidify.R
|
|||||||
import com.looker.droidify.database.CursorOwner
|
import com.looker.droidify.database.CursorOwner
|
||||||
import com.looker.droidify.database.Database
|
import com.looker.droidify.database.Database
|
||||||
import com.looker.droidify.entity.ProductItem
|
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.utility.RxUtils
|
||||||
import com.looker.droidify.widget.RecyclerFastScroller
|
import com.looker.droidify.widget.RecyclerFastScroller
|
||||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
@ -23,9 +24,9 @@ import io.reactivex.rxjava3.disposables.Disposable
|
|||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
import kotlinx.coroutines.flow.collect
|
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 {
|
companion object {
|
||||||
private const val EXTRA_SOURCE = "source"
|
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) {
|
enum class Source(val titleResId: Int, val sections: Boolean, val order: Boolean) {
|
||||||
AVAILABLE(R.string.available, true, true),
|
AVAILABLE(R.string.available, true, true),
|
||||||
INSTALLED(R.string.installed, false, false),
|
INSTALLED(R.string.installed, false, true),
|
||||||
UPDATES(R.string.updates, false, false)
|
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.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
@ -10,7 +10,7 @@ import kotlinx.coroutines.flow.StateFlow
|
|||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class ProductsViewModel : ViewModel() {
|
class AppListViewModel : ViewModel() {
|
||||||
|
|
||||||
private val _order = MutableStateFlow(ProductItem.Order.LAST_UPDATE)
|
private val _order = MutableStateFlow(ProductItem.Order.LAST_UPDATE)
|
||||||
private val _sections = MutableStateFlow<ProductItem.Section>(ProductItem.Section.All)
|
private val _sections = MutableStateFlow<ProductItem.Section>(ProductItem.Section.All)
|
Loading…
x
Reference in New Issue
Block a user