ktlint: Format all extensions
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -21,6 +21,4 @@ package com.aurora.extensions
|
||||
|
||||
import com.aurora.gplayapi.data.models.PlayFile
|
||||
|
||||
fun List<PlayFile>.requiresObbDir(): Boolean {
|
||||
return this.any { it.type == PlayFile.Type.OBB }
|
||||
}
|
||||
fun List<PlayFile>.requiresObbDir(): Boolean = this.any { it.type == PlayFile.Type.OBB }
|
||||
|
||||
@@ -76,7 +76,7 @@ fun Context.share(displayName: String, packageName: String) {
|
||||
val sendIntent = Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_SUBJECT, displayName)
|
||||
putExtra(Intent.EXTRA_TEXT, "${Constants.SHARE_URL}${packageName}")
|
||||
putExtra(Intent.EXTRA_TEXT, "${Constants.SHARE_URL}$packageName")
|
||||
type = "text/plain"
|
||||
}
|
||||
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) {
|
||||
val intent = Intent(this, className)
|
||||
if (newTask)
|
||||
if (newTask) {
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
}
|
||||
startActivity(
|
||||
intent,
|
||||
getEmptyActivityBundle()
|
||||
)
|
||||
}
|
||||
|
||||
fun Context.getEmptyActivityBundle(): Bundle? {
|
||||
return ActivityOptionsCompat.makeCustomAnimation(
|
||||
this,
|
||||
android.R.anim.fade_in,
|
||||
android.R.anim.fade_out
|
||||
).toBundle()
|
||||
}
|
||||
fun Context.getEmptyActivityBundle(): Bundle? = ActivityOptionsCompat.makeCustomAnimation(
|
||||
this,
|
||||
android.R.anim.fade_in,
|
||||
android.R.anim.fade_out
|
||||
).toBundle()
|
||||
|
||||
fun Context.copyToClipBoard(data: String?) {
|
||||
val clipboard = getSystemService<ClipboardManager>()
|
||||
@@ -141,39 +140,31 @@ fun Context.getStyledAttributeColor(id: Int): Int {
|
||||
return styledAttr
|
||||
}
|
||||
|
||||
fun Context.isIgnoringBatteryOptimizations(): Boolean {
|
||||
return getSystemService<PowerManager>()?.isIgnoringBatteryOptimizations(packageName) ?: true
|
||||
fun Context.isIgnoringBatteryOptimizations(): Boolean =
|
||||
getSystemService<PowerManager>()?.isIgnoringBatteryOptimizations(packageName) ?: true
|
||||
|
||||
fun Context.areNotificationsEnabled(): Boolean = when {
|
||||
isNAndAbove -> getSystemService<NotificationManager>()!!.areNotificationsEnabled()
|
||||
else -> true
|
||||
}
|
||||
|
||||
fun Context.areNotificationsEnabled(): Boolean {
|
||||
return if (isNAndAbove) {
|
||||
getSystemService<NotificationManager>()!!.areNotificationsEnabled()
|
||||
} else {
|
||||
true
|
||||
}
|
||||
fun Context.checkManifestPermission(permission: String): Boolean =
|
||||
ActivityCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED
|
||||
|
||||
fun Context.isExternalStorageAccessible(): Boolean = when {
|
||||
isRAndAbove -> Environment.isExternalStorageManager()
|
||||
else -> checkManifestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
}
|
||||
|
||||
fun Context.checkManifestPermission(permission: String): Boolean {
|
||||
return ActivityCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
|
||||
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) {
|
||||
fun Context.isDomainVerified(domain: String): Boolean = when {
|
||||
isSAndAbove -> {
|
||||
val domainVerificationManager = getSystemService<DomainVerificationManager>()
|
||||
val userState = domainVerificationManager!!.getDomainVerificationUserState(packageName)
|
||||
val domainMap = userState?.hostToStateMap?.filterKeys { it == domain }
|
||||
domainMap?.values?.first() == DomainVerificationUserState.DOMAIN_STATE_SELECTED
|
||||
} else {
|
||||
true
|
||||
}
|
||||
|
||||
else -> true
|
||||
}
|
||||
|
||||
fun Context.navigate(screen: Screen) {
|
||||
|
||||
@@ -53,7 +53,6 @@ fun Context.showDialog(
|
||||
negativeListener?.let {
|
||||
setNegativeButton(android.R.string.cancel, negativeListener)
|
||||
}
|
||||
|
||||
}.create()
|
||||
|
||||
builder.show()
|
||||
|
||||
@@ -1,37 +1,36 @@
|
||||
package com.aurora.extensions
|
||||
|
||||
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.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
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> {
|
||||
return flow {
|
||||
var bytesCopied: Long = 0
|
||||
val buffer = ByteArray(DEFAULT_BUFFER_SIZE)
|
||||
var bytes = read(buffer)
|
||||
var lastTotalBytesRead: 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
|
||||
}
|
||||
fun InputStream.copyTo(out: OutputStream, streamSize: Long): Flow<DownloadInfo> = flow {
|
||||
var bytesCopied: Long = 0
|
||||
val buffer = ByteArray(DEFAULT_BUFFER_SIZE)
|
||||
var bytes = read(buffer)
|
||||
var lastTotalBytesRead: Long = 0
|
||||
var speed: Long = 0
|
||||
|
||||
while (bytes >= 0) {
|
||||
out.write(buffer, 0, bytes)
|
||||
out.flush()
|
||||
@Suppress("KotlinConstantConditions") // False-positive for bytesCopied always being zero
|
||||
val timer = fixedRateTimer("timer", true, 0L, 1000) {
|
||||
val totalBytesRead = bytesCopied
|
||||
speed = totalBytesRead - lastTotalBytesRead
|
||||
lastTotalBytesRead = totalBytesRead
|
||||
}
|
||||
|
||||
bytesCopied += bytes
|
||||
// Emit stream progress in percentage
|
||||
emit(DownloadInfo((bytesCopied * 100 / streamSize).toInt(), bytes.toLong(), speed))
|
||||
bytes = read(buffer)
|
||||
}
|
||||
timer.cancel()
|
||||
}.flowOn(Dispatchers.IO)
|
||||
}
|
||||
while (bytes >= 0) {
|
||||
out.write(buffer, 0, bytes)
|
||||
out.flush()
|
||||
|
||||
bytesCopied += bytes
|
||||
// Emit stream progress in percentage
|
||||
emit(DownloadInfo((bytesCopied * 100 / streamSize).toInt(), bytes.toLong(), speed))
|
||||
bytes = read(buffer)
|
||||
}
|
||||
timer.cancel()
|
||||
}.flowOn(Dispatchers.IO)
|
||||
|
||||
@@ -23,21 +23,21 @@ import android.content.Intent
|
||||
import android.net.UrlQuerySanitizer
|
||||
import android.os.Bundle
|
||||
|
||||
fun Intent.getPackageName(fallbackBundle: Bundle? = null): String? {
|
||||
return when (action) {
|
||||
Intent.ACTION_VIEW -> {
|
||||
data?.getQueryParameter("id")
|
||||
}
|
||||
Intent.ACTION_SEND -> {
|
||||
val clipData = getStringExtra(Intent.EXTRA_TEXT).orEmpty()
|
||||
UrlQuerySanitizer(clipData).getValue("id")
|
||||
}
|
||||
Intent.ACTION_SHOW_APP_INFO -> {
|
||||
extras?.getString(Intent.EXTRA_PACKAGE_NAME)
|
||||
}
|
||||
else -> {
|
||||
extras?.getString("packageName") ?: fallbackBundle?.getString("packageName")
|
||||
}
|
||||
fun Intent.getPackageName(fallbackBundle: Bundle? = null): String? = when (action) {
|
||||
Intent.ACTION_VIEW -> {
|
||||
data?.getQueryParameter("id")
|
||||
}
|
||||
|
||||
Intent.ACTION_SEND -> {
|
||||
val clipData = getStringExtra(Intent.EXTRA_TEXT).orEmpty()
|
||||
UrlQuerySanitizer(clipData).getValue("id")
|
||||
}
|
||||
|
||||
Intent.ACTION_SHOW_APP_INFO -> {
|
||||
extras?.getString(Intent.EXTRA_PACKAGE_NAME)
|
||||
}
|
||||
|
||||
else -> {
|
||||
extras?.getString("packageName") ?: fallbackBundle?.getString("packageName")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,18 +13,26 @@ fun PackageInfo.isValidApp(packageManager: PackageManager): Boolean {
|
||||
// Filter out core AOSP system apps
|
||||
if (this.applicationInfo!!.flags and ApplicationInfo.FLAG_SYSTEM != 0) {
|
||||
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("-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 {
|
||||
isQAndAbove -> {
|
||||
Process.isApplicationUid(this.applicationInfo!!.uid) &&
|
||||
!this.applicationInfo!!.isResourceOverlay && !this.isApex
|
||||
!this.applicationInfo!!.isResourceOverlay && !this.isApex
|
||||
}
|
||||
|
||||
isNAndAbove -> Process.isApplicationUid(this.applicationInfo!!.uid)
|
||||
|
||||
else -> this.versionName != null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ fun PackageManager.getUpdateOwnerPackageNameCompat(packageName: String): String?
|
||||
installSourceInfo.installingPackageName
|
||||
}
|
||||
|
||||
else -> @Suppress("DEPRECATION") getInstallerPackageName(packageName)
|
||||
else -> {
|
||||
@Suppress("DEPRECATION")
|
||||
getInstallerPackageName(packageName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,5 @@ import kotlinx.coroutines.flow.flowOf
|
||||
* Empty lazy paging item flow for optional methods
|
||||
*/
|
||||
@Composable
|
||||
fun <T: Any> emptyPagingItems(): LazyPagingItems<T> {
|
||||
return flowOf(PagingData.empty<T>()).collectAsLazyPagingItems()
|
||||
}
|
||||
fun <T : Any> emptyPagingItems(): LazyPagingItems<T> =
|
||||
flowOf(PagingData.empty<T>()).collectAsLazyPagingItems()
|
||||
|
||||
@@ -55,31 +55,31 @@ val isMIUI: Boolean
|
||||
get() = !getSystemProperty("ro.miui.ui.version.name").isNullOrBlank()
|
||||
|
||||
val isHuawei: Boolean
|
||||
get() = Build.MANUFACTURER.lowercase(Locale.getDefault()).contains("huawei")
|
||||
|| Build.HARDWARE.lowercase(Locale.getDefault()).contains("kirin")
|
||||
|| Build.HARDWARE.lowercase(Locale.getDefault()).contains("hi3")
|
||||
get() = Build.MANUFACTURER.lowercase(Locale.getDefault()).contains("huawei") ||
|
||||
Build.HARDWARE.lowercase(Locale.getDefault()).contains("kirin") ||
|
||||
Build.HARDWARE.lowercase(Locale.getDefault()).contains("hi3")
|
||||
|
||||
@get:SuppressLint("PrivateApi")
|
||||
val isMiuiOptimizationDisabled: Boolean
|
||||
get() {
|
||||
return if ("0" == getSystemProperty("persist.sys.miui_optimization")) {
|
||||
true
|
||||
} else try {
|
||||
Class.forName("android.miui.AppOpsUtils")
|
||||
.getDeclaredMethod("isXOptMode")
|
||||
.invoke(null) as Boolean
|
||||
} catch (_: java.lang.Exception) {
|
||||
false
|
||||
} else {
|
||||
try {
|
||||
Class.forName("android.miui.AppOpsUtils")
|
||||
.getDeclaredMethod("isXOptMode")
|
||||
.invoke(null) as Boolean
|
||||
} catch (_: java.lang.Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("PrivateApi")
|
||||
private fun getSystemProperty(key: String): String? {
|
||||
return try {
|
||||
Class.forName("android.os.SystemProperties")
|
||||
.getDeclaredMethod("get", String::class.java)
|
||||
.invoke(null, key) as String
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
private fun getSystemProperty(key: String): String? = try {
|
||||
Class.forName("android.os.SystemProperties")
|
||||
.getDeclaredMethod("get", String::class.java)
|
||||
.invoke(null, key) as String
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
|
||||
@@ -22,20 +22,19 @@ fun <T> SharedPreferences.observeAsStateFlow(
|
||||
started: SharingStarted = SharingStarted.Eagerly,
|
||||
initial: T,
|
||||
valueProvider: () -> T
|
||||
): StateFlow<T> =
|
||||
callbackFlow {
|
||||
val listener =
|
||||
SharedPreferences.OnSharedPreferenceChangeListener { _, changedKey ->
|
||||
if (changedKey == key) {
|
||||
trySend(valueProvider())
|
||||
}
|
||||
): StateFlow<T> = callbackFlow {
|
||||
val listener =
|
||||
SharedPreferences.OnSharedPreferenceChangeListener { _, changedKey ->
|
||||
if (changedKey == key) {
|
||||
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)
|
||||
|
||||
@@ -28,38 +28,36 @@ import androidx.compose.ui.unit.IntSize
|
||||
* Modifier for composable to play shimmer animation
|
||||
* @param toShow Whether to play shimmer animation
|
||||
*/
|
||||
fun Modifier.shimmer(toShow: Boolean): Modifier {
|
||||
return composed {
|
||||
if (toShow) {
|
||||
val shimmerColors = listOf(
|
||||
Color.LightGray.copy(alpha = 0.6f),
|
||||
Color.LightGray.copy(alpha = 0.2f),
|
||||
Color.LightGray.copy(alpha = 0.6f)
|
||||
)
|
||||
fun Modifier.shimmer(toShow: Boolean): Modifier = composed {
|
||||
if (toShow) {
|
||||
val shimmerColors = listOf(
|
||||
Color.LightGray.copy(alpha = 0.6f),
|
||||
Color.LightGray.copy(alpha = 0.2f),
|
||||
Color.LightGray.copy(alpha = 0.6f)
|
||||
)
|
||||
|
||||
var size by remember { mutableStateOf(IntSize.Zero) }
|
||||
var size by remember { mutableStateOf(IntSize.Zero) }
|
||||
|
||||
val transition = rememberInfiniteTransition()
|
||||
val transitionAnimation = transition.animateFloat(
|
||||
initialValue = 0f,
|
||||
targetValue = 1000f,
|
||||
animationSpec = infiniteRepeatable(
|
||||
animation = tween(
|
||||
durationMillis = 1000,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
repeatMode = RepeatMode.Reverse
|
||||
)
|
||||
val transition = rememberInfiniteTransition()
|
||||
val transitionAnimation = transition.animateFloat(
|
||||
initialValue = 0f,
|
||||
targetValue = 1000f,
|
||||
animationSpec = infiniteRepeatable(
|
||||
animation = tween(
|
||||
durationMillis = 1000,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
repeatMode = RepeatMode.Reverse
|
||||
)
|
||||
background(
|
||||
brush = Brush.linearGradient(
|
||||
colors = shimmerColors,
|
||||
start = Offset.Zero,
|
||||
end = Offset(x = transitionAnimation.value, y = transitionAnimation.value)
|
||||
)
|
||||
).onGloballyPositioned { size = it.size }
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
)
|
||||
background(
|
||||
brush = Brush.linearGradient(
|
||||
colors = shimmerColors,
|
||||
start = Offset.Zero,
|
||||
end = Offset(x = transitionAnimation.value, y = transitionAnimation.value)
|
||||
)
|
||||
).onGloballyPositioned { size = it.size }
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user