Add: Installed to ProductListItem

This commit is contained in:
machiav3lli 2022-05-13 09:57:16 +02:00
parent 3d4ff47a32
commit 099b1bdf28
6 changed files with 15 additions and 2 deletions

View File

@ -19,6 +19,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.looker.droidify.R
import com.looker.droidify.database.entity.Installed
import com.looker.droidify.database.entity.Product
import com.looker.droidify.database.entity.Repository
import com.looker.droidify.entity.ProductItem
@ -34,6 +35,7 @@ fun ProductsVerticalRecycler(
onUserClick: (ProductItem) -> Unit = {},
onFavouriteClick: (ProductItem) -> Unit = {},
onInstallClick: (ProductItem) -> Unit = {}
getInstalled: (ProductItem) -> Installed? = {null},
) {
VerticalItemList(list = productsList, modifier = modifier) {
it.toItem().let { item ->
@ -43,6 +45,7 @@ fun ProductsVerticalRecycler(
onUserClick,
onFavouriteClick,
onInstallClick
getInstalled.invoke(item),
)
}
}

View File

@ -30,6 +30,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.looker.droidify.R
import com.looker.droidify.database.entity.Installed
import com.looker.droidify.database.entity.Repository
import com.looker.droidify.entity.ProductItem
import com.looker.droidify.network.CoilDownloader
@ -43,6 +44,7 @@ fun ProductsListItem(
onUserClick: (ProductItem) -> Unit = {},
onFavouriteClick: (ProductItem) -> Unit = {},
onInstallClick: (ProductItem) -> Unit = {}
installed: Installed? = null,
) {
val product by remember(item) { mutableStateOf(item) }
val imageData by remember(product, repo) {
@ -63,6 +65,7 @@ fun ProductsListItem(
expandedContent = {
ExpandedItemContent(
item = product,
installed = installed,
onFavourite = onFavouriteClick,
onInstallClicked = onInstallClick
)
@ -123,6 +126,7 @@ fun ProductsListItem(
fun ExpandedItemContent(
modifier: Modifier = Modifier,
item: ProductItem,
installed: Installed? = null,
favourite: Boolean = false,
onFavourite: (ProductItem) -> Unit = {},
onInstallClicked: (ProductItem) -> Unit = {}

View File

@ -71,6 +71,7 @@ class ExploreFragment : MainNavFragmentX() {
private fun ExplorePage() {
val products by viewModel.primaryProducts.observeAsState(null)
val categories by viewModel.categories.observeAsState(emptyList())
val installedList by viewModel.installed.observeAsState(null)
val searchQuery by viewModel.searchQuery.observeAsState("")
AppTheme(
@ -134,6 +135,7 @@ class ExploreFragment : MainNavFragmentX() {
onFavouriteClick = {},
onInstallClick = {
mainActivityX.syncConnection.binder?.installApps(listOf(it))
getInstalled = { installedList?.get(it.packageName) },
}
)
}

View File

@ -90,6 +90,7 @@ class InstalledFragment : MainNavFragmentX() {
private fun InstalledPage() {
val primaryList by viewModel.primaryProducts.observeAsState(null)
val secondaryList by viewModel.secondaryProducts.observeAsState(null)
val installedList by viewModel.installed.observeAsState(null)
val searchQuery by viewModel.searchQuery.observeAsState("")
AppTheme(
@ -224,6 +225,7 @@ class InstalledFragment : MainNavFragmentX() {
onFavouriteClick = {},
onInstallClick = {
mainActivityX.syncConnection.binder?.installApps(listOf(it))
getInstalled = { installedList?.get(it.packageName) },
}
)
}

View File

@ -82,6 +82,7 @@ class LatestFragment : MainNavFragmentX() {
private fun LatestPage() {
val primaryList by viewModel.primaryProducts.observeAsState(null)
val secondaryList by viewModel.secondaryProducts.observeAsState(null)
val installedList by viewModel.installed.observeAsState(null)
val searchQuery by viewModel.searchQuery.observeAsState("")
AppTheme(
@ -162,6 +163,7 @@ class LatestFragment : MainNavFragmentX() {
onFavouriteClick = {},
onInstallClick = {
mainActivityX.syncConnection.binder?.installApps(listOf(it))
getInstalled = { installedList?.get(it.packageName) },
}
)
}

View File

@ -78,7 +78,7 @@ class MainNavFragmentViewModelX(
val repositories = MediatorLiveData<List<Repository>>()
val categories = MediatorLiveData<List<String>>()
val installed = MediatorLiveData<List<Installed>>()
val installed = MediatorLiveData<Map<String, Installed>>()
init {
primaryProducts.addSource(
@ -125,7 +125,7 @@ class MainNavFragmentViewModelX(
}
}
}
installed.postValue(it)
installed.postValue(it.associateBy { it.packageName })
}
}