Refactoring

This commit is contained in:
Vitor Pamplona 2024-09-23 21:51:15 -04:00
parent 9b26ffd92a
commit ec700ca61f
3 changed files with 16 additions and 13 deletions

View File

@ -38,7 +38,6 @@ interface PushDistributorActions {
} }
object PushDistributorHandler : PushDistributorActions { object PushDistributorHandler : PushDistributorActions {
private val appContext = Amethyst.instance.applicationContext
private val unifiedPush: UnifiedPush = UnifiedPush private val unifiedPush: UnifiedPush = UnifiedPush
private var endpointInternal = "" private var endpointInternal = ""
@ -54,11 +53,13 @@ object PushDistributorHandler : PushDistributorActions {
endpointInternal = "" endpointInternal = ""
} }
override fun getSavedDistributor(): String = unifiedPush.getSavedDistributor(appContext) ?: "" fun appContext(): Context = Amethyst.instance.applicationContext
override fun getSavedDistributor(): String = unifiedPush.getSavedDistributor(appContext()) ?: ""
fun savedDistributorExists(): Boolean = getSavedDistributor().isNotEmpty() fun savedDistributorExists(): Boolean = getSavedDistributor().isNotEmpty()
override fun getInstalledDistributors(): List<String> = unifiedPush.getDistributors(appContext) override fun getInstalledDistributors(): List<String> = unifiedPush.getDistributors(appContext())
fun formattedDistributorNames(): List<String> { fun formattedDistributorNames(): List<String> {
val distributorsArray = getInstalledDistributors().toTypedArray() val distributorsArray = getInstalledDistributors().toTypedArray()
@ -68,16 +69,16 @@ object PushDistributorHandler : PushDistributorActions {
try { try {
val ai = val ai =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
appContext.packageManager.getApplicationInfo( appContext().packageManager.getApplicationInfo(
it, it,
PackageManager.ApplicationInfoFlags.of( PackageManager.ApplicationInfoFlags.of(
PackageManager.GET_META_DATA.toLong(), PackageManager.GET_META_DATA.toLong(),
), ),
) )
} else { } else {
appContext.packageManager.getApplicationInfo(it, 0) appContext().packageManager.getApplicationInfo(it, 0)
} }
appContext.packageManager.getApplicationLabel(ai) appContext().packageManager.getApplicationLabel(ai)
} catch (e: PackageManager.NameNotFoundException) { } catch (e: PackageManager.NameNotFoundException) {
it it
} }
@ -87,12 +88,12 @@ object PushDistributorHandler : PushDistributorActions {
} }
override fun saveDistributor(distributor: String) { override fun saveDistributor(distributor: String) {
unifiedPush.saveDistributor(appContext, distributor) unifiedPush.saveDistributor(appContext(), distributor)
unifiedPush.registerApp(appContext) unifiedPush.registerApp(appContext())
} }
override fun removeSavedDistributor() { override fun removeSavedDistributor() {
unifiedPush.safeRemoveDistributor(appContext) unifiedPush.safeRemoveDistributor(appContext())
} }
fun forceRemoveDistributor(context: Context) { fun forceRemoveDistributor(context: Context) {

View File

@ -111,14 +111,16 @@ suspend fun parseHtml(
// sniff charset from Content-Type header or BOM // sniff charset from Content-Type header or BOM
val sniffedCharset = type.charset() ?: source.readBomAsCharset() val sniffedCharset = type.charset() ?: source.readBomAsCharset()
if (sniffedCharset != null) { if (sniffedCharset != null) {
val metaTags = MetaTagsParser.parse(source.readByteArray().toString(sniffedCharset)) val content = source.readByteArray().toString(sniffedCharset)
val metaTags = MetaTagsParser.parse(content)
return@withContext extractUrlInfo(url, metaTags, type) return@withContext extractUrlInfo(url, metaTags, type)
} }
// if sniffing was failed, detect charset from content // if sniffing was failed, detect charset from content
val bodyBytes = source.readByteArray() val bodyBytes = source.readByteArray()
val charset = detectCharset(bodyBytes) val charset = detectCharset(bodyBytes)
val metaTags = MetaTagsParser.parse(bodyBytes.toString(charset)) val content = bodyBytes.toString(charset)
val metaTags = MetaTagsParser.parse(content)
return@withContext extractUrlInfo(url, metaTags, type) return@withContext extractUrlInfo(url, metaTags, type)
} }

View File

@ -347,8 +347,8 @@ private fun NavigateIfIntentRequested(
DisposableEffect(nav, activity) { DisposableEffect(nav, activity) {
val consumer = val consumer =
Consumer<Intent> { intent -> Consumer<Intent> { intent ->
val uri = intent.data.toString() val uri = intent.data?.toString()
if (uri.isNotBlank()) { if (!uri.isNullOrBlank()) {
// navigation functions // navigation functions
val newPage = uriToRoute(uri) val newPage = uriToRoute(uri)