Fix crash
This commit is contained in:
parent
b6acafb54e
commit
73fda4e8ab
@ -29,7 +29,7 @@ interface IconDao {
|
||||
fun deleteIcons(iconPack: String)
|
||||
|
||||
@Transaction
|
||||
fun installIconPack(iconPack: IconPackEntity, icons: List<IconEntity>) {
|
||||
suspend fun installIconPack(iconPack: IconPackEntity, icons: List<IconEntity>) {
|
||||
deleteIconPack(iconPack)
|
||||
deleteIcons(iconPack.packageName)
|
||||
insertAll(icons)
|
||||
@ -37,7 +37,7 @@ interface IconDao {
|
||||
}
|
||||
|
||||
@Transaction
|
||||
fun installGrayscaleIconMap(packageName: String, icons: List<IconEntity>) {
|
||||
suspend fun installGrayscaleIconMap(packageName: String, icons: List<IconEntity>) {
|
||||
deleteIcons(packageName)
|
||||
insertAll(icons)
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ import android.util.Log
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import de.mm20.launcher2.crashreporter.CrashReporter
|
||||
import de.mm20.launcher2.customattrs.CustomIconPackIcon
|
||||
import de.mm20.launcher2.database.AppDatabase
|
||||
import de.mm20.launcher2.ktx.obtainTypedArrayOrNull
|
||||
import de.mm20.launcher2.ktx.randomElementOrNull
|
||||
@ -269,8 +268,6 @@ class IconPackManager(
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
suspend fun getGreyscaleIcon(packageName: String): IconPackIcon? {
|
||||
val iconDao = AppDatabase.getInstance(context).iconDao()
|
||||
return iconDao.getGreyscaleIcon(ComponentName(packageName, packageName).flattenToString())
|
||||
@ -461,6 +458,10 @@ class UpdateIconPacksWorker(val context: Context) {
|
||||
|
||||
private fun installIconPack(iconPack: IconPack) {
|
||||
val pkgName = iconPack.packageName
|
||||
|
||||
val icons = mutableListOf<IconPackIcon>()
|
||||
val database = AppDatabase.getInstance(context)
|
||||
database.runInTransaction {
|
||||
try {
|
||||
val res = context.packageManager.getResourcesForApplication(pkgName)
|
||||
val parser: XmlPullParser
|
||||
@ -474,15 +475,13 @@ class UpdateIconPacksWorker(val context: Context) {
|
||||
"MM20",
|
||||
"Icon pack $pkgName has no appfilter.xml, neither in xml nor in raw"
|
||||
)
|
||||
return
|
||||
return@runInTransaction
|
||||
}
|
||||
parser = XmlPullParserFactory.newInstance().newPullParser()
|
||||
inStream = res.openRawResource(rawId).reader()
|
||||
parser.setInput(inStream)
|
||||
}
|
||||
|
||||
val icons = mutableListOf<IconPackIcon>()
|
||||
val iconDao = AppDatabase.getInstance(context).iconDao()
|
||||
val iconDao = database.iconDao()
|
||||
|
||||
iconDao.deleteIconPack(iconPack.toDatabaseEntity())
|
||||
iconDao.deleteIcons(iconPack.packageName)
|
||||
@ -600,16 +599,20 @@ class UpdateIconPacksWorker(val context: Context) {
|
||||
} catch (e: XmlPullParserException) {
|
||||
CrashReporter.logException(e)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun installGrayscaleIconMap(packageName: String) {
|
||||
val iconDao = AppDatabase.getInstance(context).iconDao()
|
||||
val database = AppDatabase.getInstance(context)
|
||||
database.runInTransaction {
|
||||
val iconDao = database.iconDao()
|
||||
try {
|
||||
val resources = context.packageManager.getResourcesForApplication(packageName)
|
||||
val resId = resources.getIdentifier("grayscale_icon_map", "xml", packageName)
|
||||
if (resId == 0) {
|
||||
iconDao.deleteIcons(packageName)
|
||||
return
|
||||
if (resId == 0) {
|
||||
return@runInTransaction
|
||||
}
|
||||
val icons = mutableListOf<IconPackIcon>()
|
||||
val parser = resources.getXml(resId)
|
||||
@ -630,11 +633,19 @@ class UpdateIconPacksWorker(val context: Context) {
|
||||
icons.add(icon)
|
||||
}
|
||||
}
|
||||
if (icons.size >= 100) {
|
||||
iconDao.insertAll(icons.map { it.toDatabaseEntity() })
|
||||
icons.clear()
|
||||
}
|
||||
}
|
||||
if (icons.isNotEmpty()) {
|
||||
iconDao.insertAll(icons.map { it.toDatabaseEntity() })
|
||||
}
|
||||
iconDao.installGrayscaleIconMap(packageName, icons.map { it.toDatabaseEntity() })
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
iconDao.deleteIcons(packageName)
|
||||
return
|
||||
return@runInTransaction
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user