Add: Other apps by developer block to AppSheet

This commit is contained in:
machiav3lli 2022-10-11 03:03:14 +02:00
parent 9272e7e748
commit fbf289a189
3 changed files with 30 additions and 0 deletions

View File

@ -69,6 +69,7 @@ import com.machiav3lli.fdroid.screen.MessageDialog
import com.machiav3lli.fdroid.service.Connection import com.machiav3lli.fdroid.service.Connection
import com.machiav3lli.fdroid.service.DownloadService import com.machiav3lli.fdroid.service.DownloadService
import com.machiav3lli.fdroid.ui.activities.MainActivityX import com.machiav3lli.fdroid.ui.activities.MainActivityX
import com.machiav3lli.fdroid.ui.compose.ProductsHorizontalRecycler
import com.machiav3lli.fdroid.ui.compose.components.ExpandableBlock import com.machiav3lli.fdroid.ui.compose.components.ExpandableBlock
import com.machiav3lli.fdroid.ui.compose.components.ScreenshotList import com.machiav3lli.fdroid.ui.compose.components.ScreenshotList
import com.machiav3lli.fdroid.ui.compose.components.SwitchPreference import com.machiav3lli.fdroid.ui.compose.components.SwitchPreference
@ -352,6 +353,7 @@ class AppSheetX() : FullscreenBottomSheetDialogFragment(), Callbacks {
var screenshotPage by remember { mutableStateOf(0) } var screenshotPage by remember { mutableStateOf(0) }
val installed by viewModel.installedItem.observeAsState() val installed by viewModel.installedItem.observeAsState()
val products by viewModel.products.observeAsState() val products by viewModel.products.observeAsState()
val authorProducts by viewModel.authorProducts.observeAsState()
val repos by viewModel.repositories.observeAsState() val repos by viewModel.repositories.observeAsState()
val downloadState by viewModel.downloadState.observeAsState(null) val downloadState by viewModel.downloadState.observeAsState(null)
val mainAction by viewModel.mainAction.observeAsState(if (installed == null) ActionState.Install else ActionState.Launch) val mainAction by viewModel.mainAction.observeAsState(if (installed == null) ActionState.Install else ActionState.Launch)
@ -585,6 +587,26 @@ class AppSheetX() : FullscreenBottomSheetDialogFragment(), Callbacks {
} }
} }
} }
if (!authorProducts.isNullOrEmpty()) {
item {
ExpandableBlock(
heading = stringResource(
id = R.string.other_apps_by,
product.author.name
),
positive = true,
preExpanded = false
) {
ProductsHorizontalRecycler(
productsList = authorProducts,
repositories = repos?.associateBy { repo -> repo.id }
?: emptyMap()
) { item ->
mainActivityX.navigateProduct(item.packageName, item.developer)
}
}
}
}
if (product.antiFeatures.isNotEmpty()) { if (product.antiFeatures.isNotEmpty()) {
item { item {
ExpandableBlock( ExpandableBlock(

View File

@ -32,6 +32,7 @@ class AppViewModelX(val db: DatabaseX, val packageName: String, developer: Strin
val mainAction: MutableLiveData<ActionState> = MutableLiveData() val mainAction: MutableLiveData<ActionState> = MutableLiveData()
val actions: MediatorLiveData<Set<ActionState>> = MediatorLiveData() val actions: MediatorLiveData<Set<ActionState>> = MediatorLiveData()
val extras: MediatorLiveData<Extras> = MediatorLiveData() val extras: MediatorLiveData<Extras> = MediatorLiveData()
val authorProducts: MediatorLiveData<List<Product>> = MediatorLiveData()
init { init {
products.addSource(db.productDao.getLive(packageName)) { products.setValue(it.filterNotNull()) } products.addSource(db.productDao.getLive(packageName)) { products.setValue(it.filterNotNull()) }
@ -39,6 +40,12 @@ class AppViewModelX(val db: DatabaseX, val packageName: String, developer: Strin
installedItem.addSource(db.installedDao.getLive(packageName), installedItem::setValue) installedItem.addSource(db.installedDao.getLive(packageName), installedItem::setValue)
extras.addSource(db.extrasDao.getLive(packageName), extras::setValue) extras.addSource(db.extrasDao.getLive(packageName), extras::setValue)
actions.addSource(extras) { updateActions() } actions.addSource(extras) { updateActions() }
authorProducts.addSource(db.productDao.getAuthorPackages(developer)) { prods ->
if (developer.isNotEmpty()) authorProducts.value = prods
.filter { it.packageName != packageName }
.groupBy { it.packageName }
.map { it.value.maxByOrNull(Product::added)!! }
}
} }
fun updateActions() { fun updateActions() {

View File

@ -227,4 +227,5 @@
<string name="date_added">Date added</string> <string name="date_added">Date added</string>
<string name="date_updated">Date updated</string> <string name="date_updated">Date updated</string>
<string name="target_sdk">targetSDK</string> <string name="target_sdk">targetSDK</string>
<string name="other_apps_by">Other apps by %s</string>
</resources> </resources>