Add: Empty constructor to SortFilterSheet

This commit is contained in:
machiav3lli 2022-09-26 01:17:44 +02:00
parent eca0dd3ea4
commit b303db06c0
5 changed files with 26 additions and 16 deletions

View File

@ -238,8 +238,8 @@ class MainActivityX : AppCompatActivity() {
.showNow(supportFragmentManager, "Product $packageName") .showNow(supportFragmentManager, "Product $packageName")
} }
internal fun navigateSortFilter(navPage: NavItem) { internal fun navigateSortFilter(navPage: String) {
SortFilterSheet(navPage) SortFilterSheet(navPage)
.showNow(supportFragmentManager, "Latest Page") .showNow(supportFragmentManager, "Sort/Filter Page of: $navPage")
} }
} }

View File

@ -32,6 +32,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.google.accompanist.flowlayout.FlowRow import com.google.accompanist.flowlayout.FlowRow
import com.google.accompanist.flowlayout.MainAxisAlignment import com.google.accompanist.flowlayout.MainAxisAlignment
import com.machiav3lli.fdroid.EXTRA_PAGE_ROUTE
import com.machiav3lli.fdroid.MainApplication import com.machiav3lli.fdroid.MainApplication
import com.machiav3lli.fdroid.R import com.machiav3lli.fdroid.R
import com.machiav3lli.fdroid.content.Preferences import com.machiav3lli.fdroid.content.Preferences
@ -42,7 +43,16 @@ import com.machiav3lli.fdroid.ui.compose.theme.AppTheme
import com.machiav3lli.fdroid.ui.navigation.NavItem import com.machiav3lli.fdroid.ui.navigation.NavItem
import com.machiav3lli.fdroid.utility.isDarkTheme import com.machiav3lli.fdroid.utility.isDarkTheme
class SortFilterSheet(val navPage: NavItem) : FullscreenBottomSheetDialogFragment() { class SortFilterSheet() : FullscreenBottomSheetDialogFragment() {
constructor(pageRoute: String = NavItem.Explore.destination) : this() {
arguments = Bundle().apply {
putString(EXTRA_PAGE_ROUTE, pageRoute)
}
}
private val pageRoute: String
get() = requireArguments().getString(EXTRA_PAGE_ROUTE, NavItem.Explore.destination)
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
@ -59,7 +69,7 @@ class SortFilterSheet(val navPage: NavItem) : FullscreenBottomSheetDialogFragmen
else -> isDarkTheme else -> isDarkTheme
} }
) { ) {
SortFilterPage(navPage) SortFilterPage(pageRoute)
} }
} }
} }
@ -73,7 +83,7 @@ class SortFilterSheet(val navPage: NavItem) : FullscreenBottomSheetDialogFragmen
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class) @OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
@Composable @Composable
fun SortFilterPage(navPage: NavItem) { fun SortFilterPage(navPage: String) {
val nestedScrollConnection = rememberNestedScrollInteropConnection() val nestedScrollConnection = rememberNestedScrollInteropConnection()
val dbHandler = ((context as AppCompatActivity).application as MainApplication).db val dbHandler = ((context as AppCompatActivity).application as MainApplication).db
val repos by dbHandler.repositoryDao.allLive.observeAsState(emptyList()) val repos by dbHandler.repositoryDao.allLive.observeAsState(emptyList())
@ -81,23 +91,23 @@ class SortFilterSheet(val navPage: NavItem) : FullscreenBottomSheetDialogFragmen
val activeRepos by remember(repos) { mutableStateOf(repos.filter { it.enabled }) } val activeRepos by remember(repos) { mutableStateOf(repos.filter { it.enabled }) }
val sortKey = when (navPage) { val sortKey = when (navPage) {
NavItem.Latest -> Preferences.Key.SortOrderLatest NavItem.Latest.destination -> Preferences.Key.SortOrderLatest
NavItem.Installed -> Preferences.Key.SortOrderInstalled NavItem.Installed.destination -> Preferences.Key.SortOrderInstalled
else -> Preferences.Key.SortOrderExplore // NavItem.Explore else -> Preferences.Key.SortOrderExplore // NavItem.Explore
} }
val sortAscendingKey = when (navPage) { val sortAscendingKey = when (navPage) {
NavItem.Latest -> Preferences.Key.SortOrderAscendingLatest NavItem.Latest.destination -> Preferences.Key.SortOrderAscendingLatest
NavItem.Installed -> Preferences.Key.SortOrderAscendingInstalled NavItem.Installed.destination -> Preferences.Key.SortOrderAscendingInstalled
else -> Preferences.Key.SortOrderAscendingExplore // NavItem.Explore else -> Preferences.Key.SortOrderAscendingExplore // NavItem.Explore
} }
val reposFilterKey = when (navPage) { val reposFilterKey = when (navPage) {
NavItem.Latest -> Preferences.Key.ReposFilterLatest NavItem.Latest.destination -> Preferences.Key.ReposFilterLatest
NavItem.Installed -> Preferences.Key.ReposFilterInstalled NavItem.Installed.destination -> Preferences.Key.ReposFilterInstalled
else -> Preferences.Key.ReposFilterExplore // NavItem.Explore else -> Preferences.Key.ReposFilterExplore // NavItem.Explore
} }
val categoriesFilterKey = when (navPage) { val categoriesFilterKey = when (navPage) {
NavItem.Latest -> Preferences.Key.CategoriesFilterLatest NavItem.Latest.destination -> Preferences.Key.CategoriesFilterLatest
NavItem.Installed -> Preferences.Key.CategoriesFilterInstalled NavItem.Installed.destination -> Preferences.Key.CategoriesFilterInstalled
else -> Preferences.Key.CategoriesFilterExplore // NavItem.Explore else -> Preferences.Key.CategoriesFilterExplore // NavItem.Explore
} }

View File

@ -93,7 +93,7 @@ fun ExplorePage(viewModel: MainNavFragmentViewModelX) {
labelColor = MaterialTheme.colorScheme.onSurface, labelColor = MaterialTheme.colorScheme.onSurface,
), ),
onClick = { onClick = {
mainActivityX.navigateSortFilter(NavItem.Explore) mainActivityX.navigateSortFilter(NavItem.Explore.destination)
}, },
icon = { icon = {
Icon( Icon(

View File

@ -160,7 +160,7 @@ fun InstalledPage(viewModel: MainNavFragmentViewModelX) {
labelColor = MaterialTheme.colorScheme.onSurface, labelColor = MaterialTheme.colorScheme.onSurface,
), ),
onClick = { onClick = {
mainActivityX.navigateSortFilter(NavItem.Installed) mainActivityX.navigateSortFilter(NavItem.Installed.destination)
}, },
icon = { icon = {
Icon( Icon(

View File

@ -101,7 +101,7 @@ fun LatestPage(viewModel: MainNavFragmentViewModelX) {
labelColor = MaterialTheme.colorScheme.onSurface, labelColor = MaterialTheme.colorScheme.onSurface,
), ),
onClick = { onClick = {
mainActivityX.navigateSortFilter(NavItem.Latest) mainActivityX.navigateSortFilter(NavItem.Latest.destination)
}, },
icon = { icon = {
Icon( Icon(