diff --git a/src/main/kotlin/com/looker/droidify/Common.kt b/src/main/kotlin/com/looker/droidify/Common.kt index 08d80c14..34d7811b 100644 --- a/src/main/kotlin/com/looker/droidify/Common.kt +++ b/src/main/kotlin/com/looker/droidify/Common.kt @@ -15,8 +15,6 @@ 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_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" diff --git a/src/main/kotlin/com/looker/droidify/content/ProductPreferences.kt b/src/main/kotlin/com/looker/droidify/content/ProductPreferences.kt deleted file mode 100644 index fff5e733..00000000 --- a/src/main/kotlin/com/looker/droidify/content/ProductPreferences.kt +++ /dev/null @@ -1,75 +0,0 @@ -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.Ignored -import com.looker.droidify.entity.ProductPreference -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.MutableSharedFlow -import kotlinx.coroutines.flow.asSharedFlow -import kotlinx.coroutines.launch -import java.io.ByteArrayOutputStream -import java.nio.charset.Charset - -object ProductPreferences { - private val defaultProductPreference = ProductPreference(false, 0L) - private lateinit var preferences: SharedPreferences - private val mutableSubject = MutableSharedFlow>() - private val subject = mutableSubject.asSharedFlow() - lateinit var db: DatabaseX - - fun init(context: Context) { - db = DatabaseX.getInstance(context) - preferences = context.getSharedPreferences("product_preferences", Context.MODE_PRIVATE) - CoroutineScope(Dispatchers.Default).launch { - db.lockDao.insertReplace(*preferences.all.keys - .mapNotNull { pName -> - this@ProductPreferences[pName].databaseVersionCode?.let { - Ignored(pName, it) - } - } - .toTypedArray() - ) - subject.collect { (packageName, versionCode) -> - if (versionCode != null) db.lockDao.insert(Ignored(packageName, versionCode)) - else db.lockDao.delete(packageName) - } - } - } - - private val ProductPreference.databaseVersionCode: Long? - get() = when { - ignoreUpdates -> 0L - ignoreVersionCode > 0L -> ignoreVersionCode - else -> null - } - - operator fun get(packageName: String): ProductPreference { - return if (preferences.contains(packageName)) { - try { - ProductPreference.fromJson(preferences.getString(packageName, "{}") ?: "{}") - } catch (e: Exception) { - e.printStackTrace() - defaultProductPreference - } - } else { - defaultProductPreference - } - } - - operator fun set(packageName: String, productPreference: ProductPreference) { - val oldProductPreference = this[packageName] - preferences.edit().putString(packageName, ByteArrayOutputStream() - .apply { write(productPreference.toJSON().toByteArray()) } - .toByteArray().toString(Charset.defaultCharset())).apply() - if (oldProductPreference.ignoreUpdates != productPreference.ignoreUpdates || - oldProductPreference.ignoreVersionCode != productPreference.ignoreVersionCode - ) { - CoroutineScope(Dispatchers.Default).launch { - mutableSubject.emit(Pair(packageName, productPreference.databaseVersionCode)) - } - } - } -} diff --git a/src/main/kotlin/com/looker/droidify/database/DAOs.kt b/src/main/kotlin/com/looker/droidify/database/DAOs.kt index db3d2d01..c2e862ce 100644 --- a/src/main/kotlin/com/looker/droidify/database/DAOs.kt +++ b/src/main/kotlin/com/looker/droidify/database/DAOs.kt @@ -48,7 +48,6 @@ import com.looker.droidify.TABLE_REPOSITORY import com.looker.droidify.TABLE_REPOSITORY_NAME import com.looker.droidify.database.entity.Category import com.looker.droidify.database.entity.CategoryTemp -import com.looker.droidify.database.entity.Ignored import com.looker.droidify.database.entity.Extras import com.looker.droidify.database.entity.Installed import com.looker.droidify.database.entity.Product @@ -343,12 +342,6 @@ interface InstalledDao : BaseDao { fun emptyTable() } -@Dao -interface LockDao : BaseDao { - @Query("DELETE FROM memory_lock WHERE packageName = :packageName") - fun delete(packageName: String) -} - @Dao interface ProductTempDao : BaseDao { @get:Query("SELECT * FROM temporary_product") diff --git a/src/main/kotlin/com/looker/droidify/database/entity/Ignored.kt b/src/main/kotlin/com/looker/droidify/database/entity/Ignored.kt deleted file mode 100644 index 559827e3..00000000 --- a/src/main/kotlin/com/looker/droidify/database/entity/Ignored.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.looker.droidify.database.entity - -import androidx.room.Entity -import androidx.room.PrimaryKey -import com.looker.droidify.TABLE_IGNORED_NAME - -// TODO complete renaming to Ignored -@Entity(tableName = TABLE_IGNORED_NAME) -data class Ignored( - @PrimaryKey - var packageName: String = "", - var versionCode: Long = 0L -) \ No newline at end of file diff --git a/src/main/kotlin/com/looker/droidify/entity/ProductPreference.kt b/src/main/kotlin/com/looker/droidify/entity/ProductPreference.kt deleted file mode 100644 index 9c10bd16..00000000 --- a/src/main/kotlin/com/looker/droidify/entity/ProductPreference.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.looker.droidify.entity - -import kotlinx.serialization.Serializable -import kotlinx.serialization.decodeFromString -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json - -@Serializable -data class ProductPreference(val ignoreUpdates: Boolean, val ignoreVersionCode: Long) { - fun shouldIgnoreUpdate(versionCode: Long): Boolean { - return ignoreUpdates || ignoreVersionCode == versionCode - } - - fun toJSON() = Json.encodeToString(this) - - companion object { - fun fromJson(json: String) = Json.decodeFromString(json) - } -} diff --git a/src/main/kotlin/com/looker/droidify/ui/fragments/AppSheetX.kt b/src/main/kotlin/com/looker/droidify/ui/fragments/AppSheetX.kt index ad0317dd..6cb458fa 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/AppSheetX.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/AppSheetX.kt @@ -474,10 +474,12 @@ class AppSheetX() : FullscreenBottomSheetDialogFragment(), Callbacks { positive = true, preExpanded = true ) { - links.forEach { link -> + links.forEach { item -> LinkItem( - linkType = link, - onClick = { it?.let { onUriClick(it, true) } }, + linkType = item, + onClick = { link -> + link?.let { onUriClick(it, true) } + }, onLongClick = { link -> copyLinkToClipboard( requireActivity().window.decorView.rootView, @@ -496,8 +498,8 @@ class AppSheetX() : FullscreenBottomSheetDialogFragment(), Callbacks { positive = true, preExpanded = false ) { - product.donates.forEach { - LinkItem(linkType = DonateType(it, requireContext()), + product.donates.forEach { item -> + LinkItem(linkType = DonateType(item, requireContext()), onClick = { link -> link?.let { onUriClick(it, true) } }, 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 477a8434..0d0d4ccd 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt @@ -2,7 +2,6 @@ package com.looker.droidify.ui.fragments import android.content.Intent import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -61,10 +60,6 @@ class ExploreFragment : MainNavFragmentX() { viewModel.repositories.observe(viewLifecycleOwner) { repositories = it.associateBy { repo -> repo.id } } - viewModel.installed.observe(viewLifecycleOwner) { - // Avoid the compiler using the same class as observer - Log.d(this::class.java.canonicalName, this.toString()) - } } @OptIn(ExperimentalMaterial3Api::class) 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 0b0af6b2..e8219c91 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/InstalledFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/InstalledFragment.kt @@ -2,7 +2,6 @@ package com.looker.droidify.ui.fragments import android.content.Intent import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -60,10 +59,6 @@ class InstalledFragment : MainNavFragmentX() { viewModel.repositories.observe(viewLifecycleOwner) { repositories = it.associateBy { repo -> repo.id } } - viewModel.installed.observe(viewLifecycleOwner) { - // Avoid the compiler using the same class as observer - Log.d(this::class.java.canonicalName, this.toString()) - } } @OptIn(ExperimentalMaterial3Api::class) 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 6c307239..f9ca030b 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/LatestFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/LatestFragment.kt @@ -2,7 +2,6 @@ package com.looker.droidify.ui.fragments import android.content.Intent import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -58,10 +57,6 @@ class LatestFragment : MainNavFragmentX() { viewModel.repositories.observe(viewLifecycleOwner) { repositories = it.associateBy { repo -> repo.id } } - viewModel.installed.observe(viewLifecycleOwner) { - // Avoid the compiler using the same class as observer - Log.d(this::class.java.canonicalName, this.toString()) - } } @OptIn(ExperimentalMaterial3Api::class)