mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-22 19:02:12 +00:00
Clean up
This commit is contained in:
parent
9941354bcb
commit
1a8db05955
@ -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"
|
||||
|
@ -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<Pair<String, Long?>>()
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<Installed> {
|
||||
fun emptyTable()
|
||||
}
|
||||
|
||||
@Dao
|
||||
interface LockDao : BaseDao<Ignored> {
|
||||
@Query("DELETE FROM memory_lock WHERE packageName = :packageName")
|
||||
fun delete(packageName: String)
|
||||
}
|
||||
|
||||
@Dao
|
||||
interface ProductTempDao : BaseDao<ProductTemp> {
|
||||
@get:Query("SELECT * FROM temporary_product")
|
||||
|
@ -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
|
||||
)
|
@ -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<ProductPreference>(json)
|
||||
}
|
||||
}
|
@ -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) }
|
||||
},
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user