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