mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2024-09-29 08:20:51 +00:00
Refactoring
This commit is contained in:
parent
9b26ffd92a
commit
ec700ca61f
@ -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) {
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user