mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-24 03:42:15 +00:00
Remove: Allowing queries on MainThread
This commit is contained in:
parent
251b6195d6
commit
d427968ccb
@ -86,8 +86,10 @@ class MainApplication : Application(), ImageLoaderFactory {
|
||||
val installedItems =
|
||||
packageManager.getInstalledPackages(Android.PackageManager.signaturesFlag)
|
||||
.map { it.toInstalledItem() }
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
db.installedDao.put(*installedItems.toTypedArray())
|
||||
}
|
||||
}
|
||||
|
||||
private fun listenPreferences() {
|
||||
updateProxy()
|
||||
|
@ -12,7 +12,6 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.nio.charset.Charset
|
||||
@ -27,9 +26,10 @@ object ProductPreferences {
|
||||
fun init(context: Context) {
|
||||
db = DatabaseX.getInstance(context)
|
||||
preferences = context.getSharedPreferences("product_preferences", Context.MODE_PRIVATE)
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
db.lockDao.insert(*preferences.all.keys
|
||||
.mapNotNull { pName ->
|
||||
this[pName].databaseVersionCode?.let {
|
||||
this@ProductPreferences[pName].databaseVersionCode?.let {
|
||||
Lock().apply {
|
||||
package_name = pName
|
||||
version_code = it
|
||||
@ -38,7 +38,6 @@ object ProductPreferences {
|
||||
}
|
||||
.toTypedArray()
|
||||
)
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
subject.collect { (packageName, versionCode) ->
|
||||
if (versionCode != null) db.lockDao.insert(Lock().apply {
|
||||
package_name = packageName
|
||||
|
@ -6,6 +6,9 @@ import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import com.looker.droidify.entity.Repository.Companion.defaultRepositories
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Database(
|
||||
entities = [
|
||||
@ -42,14 +45,15 @@ abstract class DatabaseX : RoomDatabase() {
|
||||
"main_database.db"
|
||||
)
|
||||
.fallbackToDestructiveMigration()
|
||||
.allowMainThreadQueries()
|
||||
.build()
|
||||
INSTANCE?.let { instance ->
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
if (instance.repositoryDao.count == 0) defaultRepositories.forEach {
|
||||
instance.repositoryDao.put(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return INSTANCE!!
|
||||
}
|
||||
}
|
||||
|
@ -99,10 +99,12 @@ class SyncService : ConnectionService<SyncService.Binder>() {
|
||||
}
|
||||
|
||||
fun sync(request: SyncRequest) {
|
||||
GlobalScope.launch {
|
||||
val ids = db.repositoryDao.all.mapNotNull { it.trueData }
|
||||
.asSequence().filter { it.enabled }.map { it.id }.toList()
|
||||
sync(ids, request)
|
||||
}
|
||||
}
|
||||
|
||||
fun sync(repository: Repository) {
|
||||
if (repository.enabled) {
|
||||
@ -332,6 +334,7 @@ class SyncService : ConnectionService<SyncService.Binder>() {
|
||||
|
||||
private fun handleNextTask(hasUpdates: Boolean) {
|
||||
if (currentTask == null) {
|
||||
GlobalScope.launch {
|
||||
if (tasks.isNotEmpty()) {
|
||||
val task = tasks.removeAt(0)
|
||||
val repository = db.repositoryDao.get(task.repositoryId)?.trueData
|
||||
@ -349,7 +352,7 @@ class SyncService : ConnectionService<SyncService.Binder>() {
|
||||
val unstable = Preferences[Preferences.Key.UpdateUnstable]
|
||||
lateinit var disposable: Disposable
|
||||
disposable = RepositoryUpdater
|
||||
.update(this, repository, unstable) { stage, progress, total ->
|
||||
.update(this@SyncService, repository, unstable) { stage, progress, total ->
|
||||
if (!disposable.isDisposed) {
|
||||
scope.launch {
|
||||
mutableStateSubject.emit(
|
||||
@ -422,6 +425,7 @@ class SyncService : ConnectionService<SyncService.Binder>() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs automatic update after a repo sync if it is enabled. Otherwise, it continues on to
|
||||
|
@ -63,7 +63,7 @@ class ExploreFragment : MainNavFragmentX(), CursorOwner.Callback {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
viewModel.fillList(source)
|
||||
//viewModel.fillList(source)
|
||||
viewModel.db.repositoryDao.allFlowable
|
||||
.observeOn(Schedulers.io())
|
||||
.flatMapSingle { list -> RxUtils.querySingle { list.mapNotNull { it.trueData } } }
|
||||
|
@ -80,7 +80,7 @@ class InstalledFragment : MainNavFragmentX(), CursorOwner.Callback {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
viewModel.fillList(source)
|
||||
//viewModel.fillList(source)
|
||||
viewModel.db.repositoryDao.allFlowable
|
||||
.observeOn(Schedulers.io())
|
||||
.flatMapSingle { list -> RxUtils.querySingle { list.mapNotNull { it.trueData } } }
|
||||
|
@ -80,7 +80,7 @@ class LatestFragment : MainNavFragmentX(), CursorOwner.Callback {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
viewModel.fillList(source)
|
||||
//viewModel.fillList(source)
|
||||
viewModel.db.repositoryDao.allFlowable
|
||||
.observeOn(Schedulers.io())
|
||||
.flatMapSingle { list -> RxUtils.querySingle { list.mapNotNull { it.trueData } } }
|
||||
|
@ -18,7 +18,7 @@ abstract class MainNavFragmentX : Fragment(), CursorOwner.Callback {
|
||||
internal fun setSearchQuery(searchQuery: String) {
|
||||
viewModel.setSearchQuery(searchQuery) {
|
||||
if (view != null) {
|
||||
viewModel.fillList(source)
|
||||
//viewModel.fillList(source)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -26,7 +26,7 @@ abstract class MainNavFragmentX : Fragment(), CursorOwner.Callback {
|
||||
internal fun setSection(section: ProductItem.Section) {
|
||||
viewModel.setSection(section) {
|
||||
if (view != null) {
|
||||
viewModel.fillList(source)
|
||||
//viewModel.fillList(source)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -34,7 +34,7 @@ abstract class MainNavFragmentX : Fragment(), CursorOwner.Callback {
|
||||
internal fun setOrder(order: ProductItem.Order) {
|
||||
viewModel.setOrder(order) {
|
||||
if (view != null) {
|
||||
viewModel.fillList(source)
|
||||
//viewModel.fillList(source)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user