From e854b57b085d488c1218b8fb46c276874c7cf5bf Mon Sep 17 00:00:00 2001 From: machiav3lli Date: Mon, 11 Apr 2022 01:31:45 +0200 Subject: [PATCH] Clean up --- src/main/kotlin/com/looker/droidify/Common.kt | 5 ++--- .../droidify/content/ProductPreferences.kt | 6 +++--- .../com/looker/droidify/database/DAOs.kt | 8 ++++---- .../com/looker/droidify/database/DatabaseX.kt | 2 +- .../database/entity/{Lock.kt => Ignored.kt} | 7 ++++--- .../droidify/service/DownloadService.kt | 1 + .../ui/compose/components/ProductCard.kt | 15 ++++++++------- .../ui/compose/components/ProductsListItem.kt | 19 ++++++++++--------- .../looker/droidify/ui/compose/utils/Chip.kt | 5 +++-- .../droidify/ui/fragments/BaseNavFragment.kt | 2 -- .../droidify/ui/fragments/ExploreFragment.kt | 3 --- .../ui/fragments/InstalledFragment.kt | 3 --- .../droidify/ui/fragments/LatestFragment.kt | 3 --- .../ui/fragments/PrefsRepositoriesFragment.kt | 5 +---- 14 files changed, 37 insertions(+), 47 deletions(-) rename src/main/kotlin/com/looker/droidify/database/entity/{Lock.kt => Ignored.kt} (56%) diff --git a/src/main/kotlin/com/looker/droidify/Common.kt b/src/main/kotlin/com/looker/droidify/Common.kt index 4a9d217c..bb45fba8 100644 --- a/src/main/kotlin/com/looker/droidify/Common.kt +++ b/src/main/kotlin/com/looker/droidify/Common.kt @@ -15,8 +15,8 @@ const val TABLE_CATEGORY_NAME = "category" const val TABLE_CATEGORY_TEMP_NAME = "temporary_category" const val TABLE_INSTALLED = "installed" const val TABLE_INSTALLED_NAME = "memory_installed" -const val TABLE_LOCK = "lock" -const val TABLE_LOCK_NAME = "memory_lock" +const val TABLE_IGNORED = "lock" +const val TABLE_IGNORED_NAME = "memory_lock" const val TABLE_PRODUCT = "product" const val TABLE_PRODUCT_NAME = "product" const val TABLE_PRODUCT_TEMP_NAME = "temporary_product" @@ -43,7 +43,6 @@ const val ROW_ANTIFEATURES = "antiFeatures" const val ROW_LICENSES = "licenses" const val ROW_DONATES = "donates" const val ROW_SCREENSHOTS = "screenshots" -const val ROW_VERSION = "version" const val ROW_SIGNATURE = "signature" const val ROW_ID = "_id" const val ROW_ENABLED = "enabled" diff --git a/src/main/kotlin/com/looker/droidify/content/ProductPreferences.kt b/src/main/kotlin/com/looker/droidify/content/ProductPreferences.kt index 6fe14a07..7787d1ce 100644 --- a/src/main/kotlin/com/looker/droidify/content/ProductPreferences.kt +++ b/src/main/kotlin/com/looker/droidify/content/ProductPreferences.kt @@ -3,7 +3,7 @@ package com.looker.droidify.content import android.content.Context import android.content.SharedPreferences import com.looker.droidify.database.DatabaseX -import com.looker.droidify.database.entity.Lock +import com.looker.droidify.database.entity.Ignored import com.looker.droidify.entity.ProductPreference import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -27,13 +27,13 @@ object ProductPreferences { db.lockDao.insert(*preferences.all.keys .mapNotNull { pName -> this@ProductPreferences[pName].databaseVersionCode?.let { - Lock(pName, it) + Ignored(pName, it) } } .toTypedArray() ) subject.collect { (packageName, versionCode) -> - if (versionCode != null) db.lockDao.insert(Lock(packageName, versionCode)) + if (versionCode != null) db.lockDao.insert(Ignored(packageName, versionCode)) else db.lockDao.delete(packageName) } } diff --git a/src/main/kotlin/com/looker/droidify/database/DAOs.kt b/src/main/kotlin/com/looker/droidify/database/DAOs.kt index 3ef01739..135dcc5a 100644 --- a/src/main/kotlin/com/looker/droidify/database/DAOs.kt +++ b/src/main/kotlin/com/looker/droidify/database/DAOs.kt @@ -144,7 +144,7 @@ interface ProductDao : BaseDao { builder += """SELECT $TABLE_PRODUCT.rowid AS $ROW_ID, $TABLE_PRODUCT.$ROW_REPOSITORY_ID, $TABLE_PRODUCT.$ROW_PACKAGE_NAME, $TABLE_PRODUCT.$ROW_LABEL, $TABLE_PRODUCT.$ROW_SUMMARY, $TABLE_PRODUCT.$ROW_DESCRIPTION, - (COALESCE($TABLE_LOCK.$ROW_VERSION_CODE, -1) NOT IN (0, $TABLE_PRODUCT.$ROW_VERSION_CODE) AND + (COALESCE($TABLE_IGNORED.$ROW_VERSION_CODE, -1) NOT IN (0, $TABLE_PRODUCT.$ROW_VERSION_CODE) AND $TABLE_PRODUCT.$ROW_COMPATIBLE != 0 AND $TABLE_PRODUCT.$ROW_VERSION_CODE > COALESCE($TABLE_INSTALLED.$ROW_VERSION_CODE, 0xffffffff) AND $signatureMatches) AS $ROW_CAN_UPDATE, $TABLE_PRODUCT.$ROW_ICON, @@ -173,8 +173,8 @@ interface ProductDao : BaseDao { ON $TABLE_PRODUCT.$ROW_REPOSITORY_ID = $TABLE_REPOSITORY.$ROW_ID""" // Merge the matching locks - builder += """LEFT JOIN $TABLE_LOCK_NAME AS $TABLE_LOCK - ON $TABLE_PRODUCT.$ROW_PACKAGE_NAME = $TABLE_LOCK.$ROW_PACKAGE_NAME""" + builder += """LEFT JOIN $TABLE_IGNORED_NAME AS $TABLE_IGNORED + ON $TABLE_PRODUCT.$ROW_PACKAGE_NAME = $TABLE_IGNORED.$ROW_PACKAGE_NAME""" // Merge the matching installed if (!installed && !updates) builder += "LEFT" @@ -291,7 +291,7 @@ interface InstalledDao : BaseDao { } @Dao -interface LockDao : BaseDao { +interface LockDao : BaseDao { @Query("DELETE FROM memory_lock WHERE packageName = :packageName") fun delete(packageName: String) } diff --git a/src/main/kotlin/com/looker/droidify/database/DatabaseX.kt b/src/main/kotlin/com/looker/droidify/database/DatabaseX.kt index 2bf22262..17cc408f 100644 --- a/src/main/kotlin/com/looker/droidify/database/DatabaseX.kt +++ b/src/main/kotlin/com/looker/droidify/database/DatabaseX.kt @@ -20,7 +20,7 @@ import kotlinx.coroutines.launch Category::class, CategoryTemp::class, Installed::class, - Lock::class + Ignored::class ], version = 6 ) @TypeConverters(Converters::class) diff --git a/src/main/kotlin/com/looker/droidify/database/entity/Lock.kt b/src/main/kotlin/com/looker/droidify/database/entity/Ignored.kt similarity index 56% rename from src/main/kotlin/com/looker/droidify/database/entity/Lock.kt rename to src/main/kotlin/com/looker/droidify/database/entity/Ignored.kt index 5f27889a..559827e3 100644 --- a/src/main/kotlin/com/looker/droidify/database/entity/Lock.kt +++ b/src/main/kotlin/com/looker/droidify/database/entity/Ignored.kt @@ -2,10 +2,11 @@ package com.looker.droidify.database.entity import androidx.room.Entity import androidx.room.PrimaryKey -import com.looker.droidify.TABLE_LOCK_NAME +import com.looker.droidify.TABLE_IGNORED_NAME -@Entity(tableName = TABLE_LOCK_NAME) -data class Lock( +// TODO complete renaming to Ignored +@Entity(tableName = TABLE_IGNORED_NAME) +data class Ignored( @PrimaryKey var packageName: String = "", var versionCode: Long = 0L diff --git a/src/main/kotlin/com/looker/droidify/service/DownloadService.kt b/src/main/kotlin/com/looker/droidify/service/DownloadService.kt index 0d878e02..97a9ec2d 100644 --- a/src/main/kotlin/com/looker/droidify/service/DownloadService.kt +++ b/src/main/kotlin/com/looker/droidify/service/DownloadService.kt @@ -37,6 +37,7 @@ import java.io.File import java.security.MessageDigest import kotlin.math.roundToInt +// TODO maybe replace by using WorkManager instead? class DownloadService : ConnectionService() { companion object { private const val ACTION_CANCEL = "${BuildConfig.APPLICATION_ID}.intent.action.CANCEL" diff --git a/src/main/kotlin/com/looker/droidify/ui/compose/components/ProductCard.kt b/src/main/kotlin/com/looker/droidify/ui/compose/components/ProductCard.kt index 2c5e957c..367944e4 100644 --- a/src/main/kotlin/com/looker/droidify/ui/compose/components/ProductCard.kt +++ b/src/main/kotlin/com/looker/droidify/ui/compose/components/ProductCard.kt @@ -28,12 +28,13 @@ fun ProductCard( onUserClick: (ProductItem) -> Unit = {} ) { - val imageData by remember(item, repo) { + val product by remember(item) { mutableStateOf(item) } + val imageData by remember(product, repo) { mutableStateOf( CoilDownloader.createIconUri( - item.packageName, - item.icon, - item.metadataIcon, + product.packageName, + product.icon, + product.metadataIcon, repo?.address, repo?.authentication ).toString() @@ -46,7 +47,7 @@ fun ProductCard( .requiredSize(80.dp, 116.dp) .clip(shape = RoundedCornerShape(8.dp)) .background(color = MaterialTheme.colorScheme.surface) - .clickable(onClick = { onUserClick(item) }), + .clickable(onClick = { onUserClick(product) }), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center ) { @@ -57,7 +58,7 @@ fun ProductCard( Text( modifier = Modifier.padding(4.dp, 2.dp), - text = item.name, + text = product.name, style = MaterialTheme.typography.bodySmall, overflow = TextOverflow.Ellipsis, maxLines = 1, @@ -65,7 +66,7 @@ fun ProductCard( ) Text( modifier = Modifier.padding(4.dp, 1.dp), - text = item.version, + text = product.version, style = MaterialTheme.typography.labelSmall, overflow = TextOverflow.Ellipsis, maxLines = 1, diff --git a/src/main/kotlin/com/looker/droidify/ui/compose/components/ProductsListItem.kt b/src/main/kotlin/com/looker/droidify/ui/compose/components/ProductsListItem.kt index 8ab827e9..25f49576 100644 --- a/src/main/kotlin/com/looker/droidify/ui/compose/components/ProductsListItem.kt +++ b/src/main/kotlin/com/looker/droidify/ui/compose/components/ProductsListItem.kt @@ -32,12 +32,13 @@ fun ProductsListItem( onFavouriteClick: (ProductItem) -> Unit = {}, onInstallClick: (ProductItem) -> Unit = {} ) { - val imageData by remember(item, repo) { + val product by remember(item) { mutableStateOf(item) } + val imageData by remember(product, repo) { mutableStateOf( CoilDownloader.createIconUri( - item.packageName, - item.icon, - item.metadataIcon, + product.packageName, + product.icon, + product.metadataIcon, repo?.address, repo?.authentication ).toString() @@ -46,10 +47,10 @@ fun ProductsListItem( ExpandableCard( modifier = Modifier.padding(horizontal = 8.dp, vertical = 8.dp), - onClick = { onUserClick(item) }, + onClick = { onUserClick(product) }, expandedContent = { ExpandedItemContent( - item = item, + item = product, onFavourite = onFavouriteClick, onInstallClicked = onInstallClick ) @@ -74,7 +75,7 @@ fun ProductsListItem( .fillMaxHeight(0.4f), ) { Text( - text = item.name, + text = product.name, modifier = Modifier .align(Alignment.CenterVertically) .weight(1f), @@ -84,8 +85,8 @@ fun ProductsListItem( style = MaterialTheme.typography.titleMedium ) Text( - text = item.version, modifier = Modifier.align(Alignment.CenterVertically), + text = product.version, overflow = TextOverflow.Ellipsis, maxLines = 1, style = MaterialTheme.typography.bodySmall, @@ -95,7 +96,7 @@ fun ProductsListItem( modifier = Modifier .fillMaxHeight() .fillMaxWidth(), - text = item.summary, + text = product.summary, style = MaterialTheme.typography.bodySmall, overflow = TextOverflow.Ellipsis, maxLines = 2, diff --git a/src/main/kotlin/com/looker/droidify/ui/compose/utils/Chip.kt b/src/main/kotlin/com/looker/droidify/ui/compose/utils/Chip.kt index 60c1e7e4..3de77dc4 100644 --- a/src/main/kotlin/com/looker/droidify/ui/compose/utils/Chip.kt +++ b/src/main/kotlin/com/looker/droidify/ui/compose/utils/Chip.kt @@ -27,7 +27,8 @@ fun ChipRow( ) { LazyRow( modifier = modifier, - horizontalArrangement = Arrangement.spacedBy(8.dp) + horizontalArrangement = Arrangement.spacedBy(8.dp), + contentPadding = PaddingValues(horizontal = 8.dp) ) { items(list) { Chip( @@ -38,7 +39,7 @@ fun ChipRow( Text( text = it, style = MaterialTheme.typography.labelLarge, - color = MaterialTheme.colorScheme.primary.copy(alpha = ChipDefaults.ContentOpacity) + color = chipColors.contentColor(enabled = true).value ) } } diff --git a/src/main/kotlin/com/looker/droidify/ui/fragments/BaseNavFragment.kt b/src/main/kotlin/com/looker/droidify/ui/fragments/BaseNavFragment.kt index f0edab8e..5c3cffb0 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/BaseNavFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/BaseNavFragment.kt @@ -7,10 +7,8 @@ import androidx.fragment.app.Fragment abstract class BaseNavFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - setupAdapters() setupLayout() } - abstract fun setupAdapters() abstract fun setupLayout() } \ No newline at end of file diff --git a/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt b/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt index 7dea93ee..b3ce7d39 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt @@ -48,9 +48,6 @@ class ExploreFragment : MainNavFragmentX() { return binding.root } - override fun setupAdapters() { - } - override fun setupLayout() { viewModel.repositories.observe(viewLifecycleOwner) { repositories = it.associateBy { repo -> repo.id } diff --git a/src/main/kotlin/com/looker/droidify/ui/fragments/InstalledFragment.kt b/src/main/kotlin/com/looker/droidify/ui/fragments/InstalledFragment.kt index f48366bf..5d2dca5a 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/InstalledFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/InstalledFragment.kt @@ -39,9 +39,6 @@ class InstalledFragment : MainNavFragmentX() { return binding.root } - override fun setupAdapters() { - } - override fun setupLayout() { viewModel.repositories.observe(viewLifecycleOwner) { repositories = it.associateBy { repo -> repo.id } diff --git a/src/main/kotlin/com/looker/droidify/ui/fragments/LatestFragment.kt b/src/main/kotlin/com/looker/droidify/ui/fragments/LatestFragment.kt index 69dfd125..84025299 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/LatestFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/LatestFragment.kt @@ -39,9 +39,6 @@ class LatestFragment : MainNavFragmentX() { return binding.root } - override fun setupAdapters() { - } - override fun setupLayout() { viewModel.repositories.observe(viewLifecycleOwner) { repositories = it.associateBy { repo -> repo.id } diff --git a/src/main/kotlin/com/looker/droidify/ui/fragments/PrefsRepositoriesFragment.kt b/src/main/kotlin/com/looker/droidify/ui/fragments/PrefsRepositoriesFragment.kt index cd224fa2..b9072545 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/PrefsRepositoriesFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/PrefsRepositoriesFragment.kt @@ -43,12 +43,9 @@ class PrefsRepositoriesFragment : BaseNavFragment() { return binding.root } - override fun setupAdapters() { + override fun setupLayout() { syncConnection.bind(requireContext()) binding.addRepository.setOnClickListener { viewModel.addRepository() } - } - - override fun setupLayout() { viewModel.repositories.observe(requireActivity()) { binding.reposRecycler.setContent { AppTheme(