mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-06-20 22:29:19 +00:00
Merge branch 'master' into installer-improvements
This commit is contained in:
@ -3,8 +3,8 @@ package com.looker.droidify.content
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.Configuration
|
||||
import com.looker.droidify.Common.PREFS_LANGUAGE
|
||||
import com.looker.droidify.Common.PREFS_LANGUAGE_DEFAULT
|
||||
import com.looker.droidify.PREFS_LANGUAGE
|
||||
import com.looker.droidify.PREFS_LANGUAGE_DEFAULT
|
||||
import com.looker.droidify.R
|
||||
import com.looker.droidify.entity.ProductItem
|
||||
import com.looker.droidify.utility.extension.android.Android
|
||||
@ -18,8 +18,8 @@ import java.net.Proxy
|
||||
object Preferences {
|
||||
private lateinit var preferences: SharedPreferences
|
||||
|
||||
private val _subject = MutableSharedFlow<Key<*>>()
|
||||
val subject = _subject.asSharedFlow()
|
||||
private val mutableSubject = MutableSharedFlow<Key<*>>()
|
||||
val subject = mutableSubject.asSharedFlow()
|
||||
|
||||
private val keys = sequenceOf(
|
||||
Key.Language,
|
||||
@ -39,12 +39,14 @@ object Preferences {
|
||||
|
||||
fun init(context: Context) {
|
||||
preferences =
|
||||
context.getSharedPreferences("${context.packageName}_preferences",
|
||||
Context.MODE_PRIVATE)
|
||||
context.getSharedPreferences(
|
||||
"${context.packageName}_preferences",
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
preferences.registerOnSharedPreferenceChangeListener { _, keyString ->
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
keys[keyString]?.let {
|
||||
_subject.emit(it)
|
||||
mutableSubject.emit(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -167,10 +169,11 @@ object Preferences {
|
||||
|
||||
sealed class AutoSync(override val valueString: String) : Enumeration<AutoSync> {
|
||||
override val values: List<AutoSync>
|
||||
get() = listOf(Never, Wifi, Always)
|
||||
get() = listOf(Never, Wifi, WifiBattery, Always)
|
||||
|
||||
object Never : AutoSync("never")
|
||||
object Wifi : AutoSync("wifi")
|
||||
object WifiBattery : AutoSync("wifi-battery")
|
||||
object Always : AutoSync("always")
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,8 @@ package com.looker.droidify.content
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import com.looker.droidify.database.Database
|
||||
import com.looker.droidify.database.DatabaseX
|
||||
import com.looker.droidify.database.Lock
|
||||
import com.looker.droidify.entity.ProductPreference
|
||||
import com.looker.droidify.utility.extension.json.Json
|
||||
import com.looker.droidify.utility.extension.json.parseDictionary
|
||||
@ -21,17 +22,30 @@ object ProductPreferences {
|
||||
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)
|
||||
Database.LockAdapter.putAll(preferences.all.keys
|
||||
.mapNotNull { packageName ->
|
||||
this[packageName].databaseVersionCode?.let { Pair(packageName, it) }
|
||||
})
|
||||
db.lockDao.insert(*preferences.all.keys
|
||||
.mapNotNull { pName ->
|
||||
this[pName].databaseVersionCode?.let {
|
||||
Lock().apply {
|
||||
package_name = pName
|
||||
version_code = it
|
||||
}
|
||||
}
|
||||
}
|
||||
.toTypedArray()
|
||||
)
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
subject.collect { (packageName, versionCode) ->
|
||||
if (versionCode != null) Database.LockAdapter.put(Pair(packageName, versionCode))
|
||||
else Database.LockAdapter.delete(packageName)
|
||||
if (versionCode != null) db.lockDao.insert(Lock().apply {
|
||||
package_name = packageName
|
||||
version_code = versionCode
|
||||
}
|
||||
)
|
||||
else db.lockDao.delete(packageName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user