ktlint: Format all extensions

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2025-12-30 15:53:26 +08:00
parent a084a57619
commit 13c9b946af
11 changed files with 143 additions and 149 deletions

View File

@@ -21,6 +21,4 @@ package com.aurora.extensions
import com.aurora.gplayapi.data.models.PlayFile import com.aurora.gplayapi.data.models.PlayFile
fun List<PlayFile>.requiresObbDir(): Boolean { fun List<PlayFile>.requiresObbDir(): Boolean = this.any { it.type == PlayFile.Type.OBB }
return this.any { it.type == PlayFile.Type.OBB }
}

View File

@@ -76,7 +76,7 @@ fun Context.share(displayName: String, packageName: String) {
val sendIntent = Intent().apply { val sendIntent = Intent().apply {
action = Intent.ACTION_SEND action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_SUBJECT, displayName) putExtra(Intent.EXTRA_SUBJECT, displayName)
putExtra(Intent.EXTRA_TEXT, "${Constants.SHARE_URL}${packageName}") putExtra(Intent.EXTRA_TEXT, "${Constants.SHARE_URL}$packageName")
type = "text/plain" type = "text/plain"
} }
startActivity(Intent.createChooser(sendIntent, getString(R.string.action_share))) startActivity(Intent.createChooser(sendIntent, getString(R.string.action_share)))
@@ -112,21 +112,20 @@ fun Context.openInfo(packageName: String) {
fun <T> Context.open(className: Class<T>, newTask: Boolean = false) { fun <T> Context.open(className: Class<T>, newTask: Boolean = false) {
val intent = Intent(this, className) val intent = Intent(this, className)
if (newTask) if (newTask) {
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
startActivity( startActivity(
intent, intent,
getEmptyActivityBundle() getEmptyActivityBundle()
) )
} }
fun Context.getEmptyActivityBundle(): Bundle? { fun Context.getEmptyActivityBundle(): Bundle? = ActivityOptionsCompat.makeCustomAnimation(
return ActivityOptionsCompat.makeCustomAnimation( this,
this, android.R.anim.fade_in,
android.R.anim.fade_in, android.R.anim.fade_out
android.R.anim.fade_out ).toBundle()
).toBundle()
}
fun Context.copyToClipBoard(data: String?) { fun Context.copyToClipBoard(data: String?) {
val clipboard = getSystemService<ClipboardManager>() val clipboard = getSystemService<ClipboardManager>()
@@ -141,39 +140,31 @@ fun Context.getStyledAttributeColor(id: Int): Int {
return styledAttr return styledAttr
} }
fun Context.isIgnoringBatteryOptimizations(): Boolean { fun Context.isIgnoringBatteryOptimizations(): Boolean =
return getSystemService<PowerManager>()?.isIgnoringBatteryOptimizations(packageName) ?: true getSystemService<PowerManager>()?.isIgnoringBatteryOptimizations(packageName) ?: true
fun Context.areNotificationsEnabled(): Boolean = when {
isNAndAbove -> getSystemService<NotificationManager>()!!.areNotificationsEnabled()
else -> true
} }
fun Context.areNotificationsEnabled(): Boolean { fun Context.checkManifestPermission(permission: String): Boolean =
return if (isNAndAbove) { ActivityCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED
getSystemService<NotificationManager>()!!.areNotificationsEnabled()
} else { fun Context.isExternalStorageAccessible(): Boolean = when {
true isRAndAbove -> Environment.isExternalStorageManager()
} else -> checkManifestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
} }
fun Context.checkManifestPermission(permission: String): Boolean { fun Context.isDomainVerified(domain: String): Boolean = when {
return ActivityCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED isSAndAbove -> {
}
fun Context.isExternalStorageAccessible(): Boolean {
return if (isRAndAbove) {
Environment.isExternalStorageManager()
} else {
checkManifestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
}
}
fun Context.isDomainVerified(domain: String): Boolean {
return if (isSAndAbove) {
val domainVerificationManager = getSystemService<DomainVerificationManager>() val domainVerificationManager = getSystemService<DomainVerificationManager>()
val userState = domainVerificationManager!!.getDomainVerificationUserState(packageName) val userState = domainVerificationManager!!.getDomainVerificationUserState(packageName)
val domainMap = userState?.hostToStateMap?.filterKeys { it == domain } val domainMap = userState?.hostToStateMap?.filterKeys { it == domain }
domainMap?.values?.first() == DomainVerificationUserState.DOMAIN_STATE_SELECTED domainMap?.values?.first() == DomainVerificationUserState.DOMAIN_STATE_SELECTED
} else {
true
} }
else -> true
} }
fun Context.navigate(screen: Screen) { fun Context.navigate(screen: Screen) {

View File

@@ -53,7 +53,6 @@ fun Context.showDialog(
negativeListener?.let { negativeListener?.let {
setNegativeButton(android.R.string.cancel, negativeListener) setNegativeButton(android.R.string.cancel, negativeListener)
} }
}.create() }.create()
builder.show() builder.show()

View File

@@ -1,37 +1,36 @@
package com.aurora.extensions package com.aurora.extensions
import com.aurora.store.data.model.DownloadInfo import com.aurora.store.data.model.DownloadInfo
import java.io.InputStream
import java.io.OutputStream
import kotlin.concurrent.fixedRateTimer
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.flowOn
import java.io.InputStream
import java.io.OutputStream
import kotlin.concurrent.fixedRateTimer
fun InputStream.copyTo(out: OutputStream, streamSize: Long): Flow<DownloadInfo> { fun InputStream.copyTo(out: OutputStream, streamSize: Long): Flow<DownloadInfo> = flow {
return flow { var bytesCopied: Long = 0
var bytesCopied: Long = 0 val buffer = ByteArray(DEFAULT_BUFFER_SIZE)
val buffer = ByteArray(DEFAULT_BUFFER_SIZE) var bytes = read(buffer)
var bytes = read(buffer) var lastTotalBytesRead: Long = 0
var lastTotalBytesRead: Long = 0 var speed: Long = 0
var speed: Long = 0
@Suppress("KotlinConstantConditions") // False-positive for bytesCopied always being zero
val timer = fixedRateTimer("timer", true, 0L, 1000) {
val totalBytesRead = bytesCopied
speed = totalBytesRead - lastTotalBytesRead
lastTotalBytesRead = totalBytesRead
}
while (bytes >= 0) { @Suppress("KotlinConstantConditions") // False-positive for bytesCopied always being zero
out.write(buffer, 0, bytes) val timer = fixedRateTimer("timer", true, 0L, 1000) {
out.flush() val totalBytesRead = bytesCopied
speed = totalBytesRead - lastTotalBytesRead
lastTotalBytesRead = totalBytesRead
}
bytesCopied += bytes while (bytes >= 0) {
// Emit stream progress in percentage out.write(buffer, 0, bytes)
emit(DownloadInfo((bytesCopied * 100 / streamSize).toInt(), bytes.toLong(), speed)) out.flush()
bytes = read(buffer)
} bytesCopied += bytes
timer.cancel() // Emit stream progress in percentage
}.flowOn(Dispatchers.IO) emit(DownloadInfo((bytesCopied * 100 / streamSize).toInt(), bytes.toLong(), speed))
} bytes = read(buffer)
}
timer.cancel()
}.flowOn(Dispatchers.IO)

View File

@@ -23,21 +23,21 @@ import android.content.Intent
import android.net.UrlQuerySanitizer import android.net.UrlQuerySanitizer
import android.os.Bundle import android.os.Bundle
fun Intent.getPackageName(fallbackBundle: Bundle? = null): String? { fun Intent.getPackageName(fallbackBundle: Bundle? = null): String? = when (action) {
return when (action) { Intent.ACTION_VIEW -> {
Intent.ACTION_VIEW -> { data?.getQueryParameter("id")
data?.getQueryParameter("id") }
}
Intent.ACTION_SEND -> { Intent.ACTION_SEND -> {
val clipData = getStringExtra(Intent.EXTRA_TEXT).orEmpty() val clipData = getStringExtra(Intent.EXTRA_TEXT).orEmpty()
UrlQuerySanitizer(clipData).getValue("id") UrlQuerySanitizer(clipData).getValue("id")
} }
Intent.ACTION_SHOW_APP_INFO -> {
extras?.getString(Intent.EXTRA_PACKAGE_NAME) Intent.ACTION_SHOW_APP_INFO -> {
} extras?.getString(Intent.EXTRA_PACKAGE_NAME)
else -> { }
extras?.getString("packageName") ?: fallbackBundle?.getString("packageName")
} else -> {
extras?.getString("packageName") ?: fallbackBundle?.getString("packageName")
} }
} }

View File

@@ -13,18 +13,26 @@ fun PackageInfo.isValidApp(packageManager: PackageManager): Boolean {
// Filter out core AOSP system apps // Filter out core AOSP system apps
if (this.applicationInfo!!.flags and ApplicationInfo.FLAG_SYSTEM != 0) { if (this.applicationInfo!!.flags and ApplicationInfo.FLAG_SYSTEM != 0) {
if (this.packageName.endsWith(".resources")) return false if (this.packageName.endsWith(".resources")) return false
if (this.applicationInfo!!.loadLabel(packageManager).startsWith(this.packageName)) return false if (this.applicationInfo!!.loadLabel(packageManager).startsWith(this.packageName)) {
return false
}
if (this.versionName?.endsWith("system image") == true) return false if (this.versionName?.endsWith("system image") == true) return false
if (this.versionName?.endsWith("-initial") == true) return false if (this.versionName?.endsWith("-initial") == true) return false
if (this.versionName == Build.VERSION.RELEASE && PackageInfoCompat.getLongVersionCode(this) == Build.VERSION.SDK_INT.toLong()) return false if (this.versionName == Build.VERSION.RELEASE &&
PackageInfoCompat.getLongVersionCode(this) == Build.VERSION.SDK_INT.toLong()
) {
return false
}
} }
return when { return when {
isQAndAbove -> { isQAndAbove -> {
Process.isApplicationUid(this.applicationInfo!!.uid) && Process.isApplicationUid(this.applicationInfo!!.uid) &&
!this.applicationInfo!!.isResourceOverlay && !this.isApex !this.applicationInfo!!.isResourceOverlay && !this.isApex
} }
isNAndAbove -> Process.isApplicationUid(this.applicationInfo!!.uid) isNAndAbove -> Process.isApplicationUid(this.applicationInfo!!.uid)
else -> this.versionName != null else -> this.versionName != null
} }
} }

View File

@@ -22,6 +22,9 @@ fun PackageManager.getUpdateOwnerPackageNameCompat(packageName: String): String?
installSourceInfo.installingPackageName installSourceInfo.installingPackageName
} }
else -> @Suppress("DEPRECATION") getInstallerPackageName(packageName) else -> {
@Suppress("DEPRECATION")
getInstallerPackageName(packageName)
}
} }
} }

View File

@@ -15,6 +15,5 @@ import kotlinx.coroutines.flow.flowOf
* Empty lazy paging item flow for optional methods * Empty lazy paging item flow for optional methods
*/ */
@Composable @Composable
fun <T: Any> emptyPagingItems(): LazyPagingItems<T> { fun <T : Any> emptyPagingItems(): LazyPagingItems<T> =
return flowOf(PagingData.empty<T>()).collectAsLazyPagingItems() flowOf(PagingData.empty<T>()).collectAsLazyPagingItems()
}

View File

@@ -55,31 +55,31 @@ val isMIUI: Boolean
get() = !getSystemProperty("ro.miui.ui.version.name").isNullOrBlank() get() = !getSystemProperty("ro.miui.ui.version.name").isNullOrBlank()
val isHuawei: Boolean val isHuawei: Boolean
get() = Build.MANUFACTURER.lowercase(Locale.getDefault()).contains("huawei") get() = Build.MANUFACTURER.lowercase(Locale.getDefault()).contains("huawei") ||
|| Build.HARDWARE.lowercase(Locale.getDefault()).contains("kirin") Build.HARDWARE.lowercase(Locale.getDefault()).contains("kirin") ||
|| Build.HARDWARE.lowercase(Locale.getDefault()).contains("hi3") Build.HARDWARE.lowercase(Locale.getDefault()).contains("hi3")
@get:SuppressLint("PrivateApi") @get:SuppressLint("PrivateApi")
val isMiuiOptimizationDisabled: Boolean val isMiuiOptimizationDisabled: Boolean
get() { get() {
return if ("0" == getSystemProperty("persist.sys.miui_optimization")) { return if ("0" == getSystemProperty("persist.sys.miui_optimization")) {
true true
} else try { } else {
Class.forName("android.miui.AppOpsUtils") try {
.getDeclaredMethod("isXOptMode") Class.forName("android.miui.AppOpsUtils")
.invoke(null) as Boolean .getDeclaredMethod("isXOptMode")
} catch (_: java.lang.Exception) { .invoke(null) as Boolean
false } catch (_: java.lang.Exception) {
false
}
} }
} }
@SuppressLint("PrivateApi") @SuppressLint("PrivateApi")
private fun getSystemProperty(key: String): String? { private fun getSystemProperty(key: String): String? = try {
return try { Class.forName("android.os.SystemProperties")
Class.forName("android.os.SystemProperties") .getDeclaredMethod("get", String::class.java)
.getDeclaredMethod("get", String::class.java) .invoke(null, key) as String
.invoke(null, key) as String } catch (_: Exception) {
} catch (e: Exception) { null
null
}
} }

View File

@@ -22,20 +22,19 @@ fun <T> SharedPreferences.observeAsStateFlow(
started: SharingStarted = SharingStarted.Eagerly, started: SharingStarted = SharingStarted.Eagerly,
initial: T, initial: T,
valueProvider: () -> T valueProvider: () -> T
): StateFlow<T> = ): StateFlow<T> = callbackFlow {
callbackFlow { val listener =
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, changedKey ->
SharedPreferences.OnSharedPreferenceChangeListener { _, changedKey -> if (changedKey == key) {
if (changedKey == key) { trySend(valueProvider())
trySend(valueProvider())
}
} }
// Emit the initial value
trySend(valueProvider())
registerOnSharedPreferenceChangeListener(listener)
awaitClose {
unregisterOnSharedPreferenceChangeListener(listener)
} }
}.stateIn(scope, started, initial)
// Emit the initial value
trySend(valueProvider())
registerOnSharedPreferenceChangeListener(listener)
awaitClose {
unregisterOnSharedPreferenceChangeListener(listener)
}
}.stateIn(scope, started, initial)

View File

@@ -28,38 +28,36 @@ import androidx.compose.ui.unit.IntSize
* Modifier for composable to play shimmer animation * Modifier for composable to play shimmer animation
* @param toShow Whether to play shimmer animation * @param toShow Whether to play shimmer animation
*/ */
fun Modifier.shimmer(toShow: Boolean): Modifier { fun Modifier.shimmer(toShow: Boolean): Modifier = composed {
return composed { if (toShow) {
if (toShow) { val shimmerColors = listOf(
val shimmerColors = listOf( Color.LightGray.copy(alpha = 0.6f),
Color.LightGray.copy(alpha = 0.6f), Color.LightGray.copy(alpha = 0.2f),
Color.LightGray.copy(alpha = 0.2f), Color.LightGray.copy(alpha = 0.6f)
Color.LightGray.copy(alpha = 0.6f) )
)
var size by remember { mutableStateOf(IntSize.Zero) } var size by remember { mutableStateOf(IntSize.Zero) }
val transition = rememberInfiniteTransition() val transition = rememberInfiniteTransition()
val transitionAnimation = transition.animateFloat( val transitionAnimation = transition.animateFloat(
initialValue = 0f, initialValue = 0f,
targetValue = 1000f, targetValue = 1000f,
animationSpec = infiniteRepeatable( animationSpec = infiniteRepeatable(
animation = tween( animation = tween(
durationMillis = 1000, durationMillis = 1000,
easing = FastOutSlowInEasing easing = FastOutSlowInEasing
), ),
repeatMode = RepeatMode.Reverse repeatMode = RepeatMode.Reverse
)
) )
background( )
brush = Brush.linearGradient( background(
colors = shimmerColors, brush = Brush.linearGradient(
start = Offset.Zero, colors = shimmerColors,
end = Offset(x = transitionAnimation.value, y = transitionAnimation.value) start = Offset.Zero,
) end = Offset(x = transitionAnimation.value, y = transitionAnimation.value)
).onGloballyPositioned { size = it.size } )
} else { ).onGloballyPositioned { size = it.size }
Modifier } else {
} Modifier
} }
} }