ktlint: Reformat all util classes

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2026-01-01 12:25:22 +08:00
parent 0e3f8ae150
commit a8d37cb2ba
8 changed files with 209 additions and 263 deletions

View File

@@ -20,16 +20,17 @@
package com.aurora.store.util
import com.aurora.store.data.network.HttpClient
import okhttp3.RequestBody.Companion.toRequestBody
import java.util.Locale
import javax.inject.Inject
import okhttp3.RequestBody.Companion.toRequestBody
class AC2DMTask @Inject constructor(private val httpClient: HttpClient) {
@Throws(Exception::class)
fun getAC2DMResponse(email: String?, oAuthToken: String?): Map<String, String> {
if (email == null || oAuthToken == null)
if (email == null || oAuthToken == null) {
return mapOf()
}
val params: MutableMap<String, Any> = hashMapOf()
params["lang"] = Locale.getDefault().toString().replace("_", "-")

View File

@@ -52,13 +52,12 @@ object CertUtil {
"com.machiav3lli.fdroid"
)
fun isFDroidApp(context: Context, packageName: String): Boolean {
return isInstalledByFDroid(context, packageName) || isSignedByFDroid(context, packageName)
}
fun isFDroidApp(context: Context, packageName: String): Boolean =
isInstalledByFDroid(context, packageName) || isSignedByFDroid(context, packageName)
fun isAppGalleryApp(context: Context, packageName: String): Boolean {
return context.packageManager.getUpdateOwnerPackageNameCompat(packageName) == PACKAGE_NAME_APP_GALLERY
}
fun isAppGalleryApp(context: Context, packageName: String): Boolean =
context.packageManager.getUpdateOwnerPackageNameCompat(packageName) ==
PACKAGE_NAME_APP_GALLERY
fun isAuroraStoreApp(context: Context, packageName: String): Boolean {
val installerPackageNames = AppInstaller.getAvailableInstallersInfo(context)
@@ -68,8 +67,7 @@ object CertUtil {
return installerPackageNames.contains(packageInstaller)
}
fun getEncodedCertificateHashes(context: Context, packageName: String): List<String> {
return try {
fun getEncodedCertificateHashes(context: Context, packageName: String): List<String> = try {
val certificates = getX509Certificates(context, packageName)
certificates.map {
val messageDigest = MessageDigest.getInstance(Algorithm.SHA.value)
@@ -83,10 +81,8 @@ object CertUtil {
Log.e(TAG, "Failed to get SHA256 certificate hash", exception)
emptyList()
}
}
private fun isSignedByFDroid(context: Context, packageName: String): Boolean {
return try {
private fun isSignedByFDroid(context: Context, packageName: String): Boolean = try {
getX509Certificates(context, packageName).any { cert ->
cert.subjectDN.name.split(",").associate {
val (left, right) = it.split("=")
@@ -97,7 +93,6 @@ object CertUtil {
Log.e(TAG, "Failed to check signing cert for $packageName")
false
}
}
fun isMicroGGms(context: Context): Boolean {
return try {
@@ -114,20 +109,23 @@ object CertUtil {
}
}
private fun isInstalledByFDroid(context: Context, packageName: String): Boolean {
return fdroidPackages.contains(
private fun isInstalledByFDroid(context: Context, packageName: String): Boolean =
fdroidPackages.contains(
context.packageManager.getUpdateOwnerPackageNameCompat(packageName)
)
}
private fun getX509Certificates(context: Context, packageName: String): List<X509Certificate> {
return try {
private fun getX509Certificates(context: Context, packageName: String): List<X509Certificate> =
try {
val packageInfo = getPackageInfoWithSignature(context, packageName)
if (isPAndAbove) {
if (packageInfo.signingInfo!!.hasMultipleSigners()) {
packageInfo.signingInfo!!.apkContentsSigners.map { it.generateX509Certificate() }
packageInfo.signingInfo!!.apkContentsSigners.map {
it.generateX509Certificate()
}
} else {
packageInfo.signingInfo!!.signingCertificateHistory.map { it.generateX509Certificate() }
packageInfo.signingInfo!!.signingCertificateHistory.map {
it.generateX509Certificate()
}
}
} else {
@Suppress("DEPRECATION")
@@ -137,16 +135,14 @@ object CertUtil {
Log.e(TAG, "Failed to get X509 certificates", exception)
emptyList()
}
}
private fun getPackageInfoWithSignature(context: Context, packageName: String): PackageInfo {
return if (isPAndAbove) {
private fun getPackageInfoWithSignature(context: Context, packageName: String): PackageInfo =
if (isPAndAbove) {
getPackageInfo(context, packageName, PackageManager.GET_SIGNING_CERTIFICATES)
} else {
@Suppress("DEPRECATION")
getPackageInfo(context, packageName, PackageManager.GET_SIGNATURES)
}
}
private fun extractSHA1Fingerprint(certificate: X509Certificate): String {
val messageDigest = MessageDigest.getInstance(Algorithm.SHA1.value)
@@ -156,10 +152,9 @@ object CertUtil {
.lowercase()
}
private fun parseX500Principal(principal: X500Principal): Map<String, String> {
return principal.name.split(",").associate {
private fun parseX500Principal(principal: X500Principal): Map<String, String> =
principal.name.split(",").associate {
val (left, right) = it.split("=")
left.trim() to right.trim()
}
}
}

View File

@@ -48,8 +48,9 @@ object CommonUtil {
)
fun addSiPrefix(value: Long): String {
if (value <= 1L)
if (value <= 1L) {
return "NA"
}
var tempValue = value
var order = 0
while (tempValue >= 1000.0) {
@@ -100,7 +101,8 @@ object CommonUtil {
val exp = (ln(bytes.toDouble()) / ln(unit.toDouble())).toInt()
val pre = (if (si) "kMGTPE" else "KMGTPE")[exp - 1].toString() + if (si) "" else "i"
return String.format(
Locale.getDefault(), "%.1f %sB/s",
Locale.getDefault(),
"%.1f %sB/s",
bytes / unit.toDouble().pow(exp.toDouble()),
pre
)
@@ -120,8 +122,8 @@ object CommonUtil {
}
fun parseProxyUrl(proxyUrl: String): ProxyInfo? {
val pattern = """^(https?|socks5?)://(?:([^\s:@]+):([^\s:@]+)@)?([^\s:@]+):(\d+)$""".toRegex()
val match = pattern.find(proxyUrl)
val pattern = """^(https?|socks5?)://(?:([^\s:@]+):([^\s:@]+)@)?([^\s:@]+):(\d+)$"""
val match = pattern.toRegex().find(proxyUrl)
return when {
match != null -> {

View File

@@ -24,10 +24,10 @@ import com.aurora.store.data.installer.AppInstaller
import com.aurora.store.data.model.DownloadStatus
import com.aurora.store.data.receiver.DownloadCancelReceiver
import com.aurora.store.data.room.download.Download
import com.aurora.store.data.room.download.Download as AuroraDownload
import com.aurora.store.data.room.update.Update
import java.util.UUID
import kotlin.math.absoluteValue
import com.aurora.store.data.room.download.Download as AuroraDownload
object NotificationUtil {
@@ -78,14 +78,13 @@ object NotificationUtil {
}
}
fun getDownloadNotification(context: Context): Notification {
return NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_DOWNLOADS)
fun getDownloadNotification(context: Context): Notification =
NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_DOWNLOADS)
.setSmallIcon(android.R.drawable.stat_sys_download)
.setContentTitle(context.getString(R.string.app_updater_service_notif_title))
.setContentText(context.getString(R.string.app_updater_service_notif_text))
.setOngoing(true)
.build()
}
fun getDownloadNotification(
context: Context,
@@ -186,37 +185,32 @@ object NotificationUtil {
context: Context,
displayName: String,
packageName: String
): Notification {
return NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_INSTALL)
): Notification = NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_INSTALL)
.setSmallIcon(R.drawable.ic_install)
.setLargeIcon(PackageUtil.getIconForPackage(context, packageName))
.setContentTitle(displayName)
.setContentText(context.getString(R.string.installer_status_success))
.setContentIntent(getContentIntentForDetails(context, packageName))
.build()
}
fun getInstallerStatusNotification(
context: Context,
packageName: String,
displayName: String,
content: String?
): Notification {
return NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_INSTALL)
): Notification = NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_INSTALL)
.setSmallIcon(R.drawable.ic_install)
.setContentTitle(displayName)
.setContentText(content)
.setContentIntent(getContentIntentForDetails(context, packageName))
.build()
}
fun getUpdateNotification(context: Context): Notification {
return NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_UPDATES)
fun getUpdateNotification(context: Context): Notification =
NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_UPDATES)
.setSmallIcon(R.drawable.ic_updates)
.setContentTitle(context.getString(R.string.checking_updates))
.setOngoing(true)
.build()
}
fun getUpdateNotification(context: Context, updatesList: List<Update>): Notification {
val contentIntent = NavDeepLinkBuilder(context)
@@ -229,16 +223,17 @@ object NotificationUtil {
return NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_UPDATES)
.setSmallIcon(R.drawable.ic_updates)
.setContentTitle(
if (updatesList.size == 1)
if (updatesList.size == 1) {
context.getString(
R.string.notification_updates_available_1,
updatesList.size
)
else
} else {
context.getString(
R.string.notification_updates_available,
updatesList.size
)
}
)
.setContentText(
when (updatesList.size) {
@@ -284,17 +279,16 @@ object NotificationUtil {
.build()
}
fun getExportNotification(context: Context): Notification {
return NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_EXPORT)
fun getExportNotification(context: Context): Notification =
NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_EXPORT)
.setSmallIcon(R.drawable.ic_file_copy)
.setContentTitle(context.getString(R.string.export_app_title))
.setContentText(context.getString(R.string.export_app_summary))
.setOngoing(true)
.build()
}
fun getUnarchiveAuthNotification(context: Context, packageName: String): Notification {
return NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_ACCOUNT)
fun getUnarchiveAuthNotification(context: Context, packageName: String): Notification =
NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_ACCOUNT)
.setSmallIcon(R.drawable.ic_account)
.setContentTitle(context.getString(R.string.authentication_required_title))
.setContentText(context.getString(R.string.authentication_required_unarchive))
@@ -303,7 +297,6 @@ object NotificationUtil {
.setCategory(NotificationCompat.CATEGORY_ERROR)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.build()
}
fun getExportStatusNotification(
context: Context,
@@ -362,23 +355,21 @@ object NotificationUtil {
)
}
private fun getContentIntentForSplash(context: Context, packageName: String): PendingIntent {
return NavDeepLinkBuilder(context)
private fun getContentIntentForSplash(context: Context, packageName: String): PendingIntent =
NavDeepLinkBuilder(context)
.setGraph(R.navigation.mobile_navigation)
.setDestination(R.id.splashFragment)
.setComponentName(MainActivity::class.java)
.setArguments(bundleOf("packageName" to packageName))
.createPendingIntent()
}
private fun getContentIntentForDetails(context: Context, packageName: String): PendingIntent {
return NavDeepLinkBuilder(context)
private fun getContentIntentForDetails(context: Context, packageName: String): PendingIntent =
NavDeepLinkBuilder(context)
.setGraph(R.navigation.mobile_navigation)
.setDestination(R.id.splashFragment)
.setComponentName(MainActivity::class.java)
.setArguments(bundleOf("packageName" to packageName))
.createPendingIntent()
}
private fun getInstallIntent(context: Context, download: Download): PendingIntent? {
val intent = Intent(context, InstallActivity::class.java).apply {

View File

@@ -58,14 +58,13 @@ object PackageUtil {
private const val VERSION_CODE_MICROG_COMPANION_MIN: Long = 84022620
private const val MICROG_INSTALL_ACTIVITY = "org.microg.vending.installer.AppInstallActivity"
fun getAllValidPackages(context: Context): List<PackageInfo> {
return context.packageManager.getInstalledPackages(PackageManager.GET_META_DATA)
fun getAllValidPackages(context: Context): List<PackageInfo> =
context.packageManager.getInstalledPackages(PackageManager.GET_META_DATA)
.filter { it.isValidApp(context.packageManager) }
.sortedBy {
it.applicationInfo!!.loadLabel(context.packageManager).toString()
.lowercase(Locale.getDefault())
}
}
fun hasSupportedAppGallery(context: Context): Boolean {
return try {
@@ -85,10 +84,11 @@ object PackageUtil {
)
@Suppress("DEPRECATION")
val versionCode = if (Build.VERSION.SDK_INT >= 28)
val versionCode = if (Build.VERSION.SDK_INT >= 28) {
packageInfo.longVersionCode
else
} else {
packageInfo.versionCode.toLong()
}
Log.i(TAG, "AppGallery - ${packageInfo.versionName} ($versionCode)")
@@ -119,8 +119,7 @@ object PackageUtil {
return resolveInfo != null
}
fun hasMicroGCompanion(context: Context): Boolean {
return isInstalled(
fun hasMicroGCompanion(context: Context): Boolean = isInstalled(
context,
PACKAGE_NAME_PLAY_STORE,
VERSION_CODE_MICROG_COMPANION_MIN
@@ -129,10 +128,9 @@ object PackageUtil {
PACKAGE_NAME_PLAY_STORE,
MICROG_INSTALL_ACTIVITY
)
}
fun isInstalled(context: Context, packageName: String, versionCode: Long? = null): Boolean {
return try {
fun isInstalled(context: Context, packageName: String, versionCode: Long? = null): Boolean =
try {
val packageInfo = getPackageInfo(context, packageName, PackageManager.GET_META_DATA)
if (versionCode != null) {
PackageInfoCompat.getLongVersionCode(packageInfo) >= versionCode
@@ -142,30 +140,24 @@ object PackageUtil {
} catch (_: PackageManager.NameNotFoundException) {
false
}
}
fun isArchived(context: Context, packageName: String): Boolean {
return try {
fun isArchived(context: Context, packageName: String): Boolean = try {
isVAndAbove && context.packageManager.getArchivedPackage(packageName) != null
} catch (e: Exception) {
false
}
}
fun isSharedLibrary(context: Context, packageName: String): Boolean {
return if (isOAndAbove) {
fun isSharedLibrary(context: Context, packageName: String): Boolean = if (isOAndAbove) {
getAllSharedLibraries(context).any { it.name == packageName }
} else {
false
}
}
fun isSharedLibraryInstalled(
context: Context,
packageName: String,
versionCode: Long
): Boolean {
return if (isOAndAbove) {
): Boolean = if (isOAndAbove) {
val sharedLibraries = getAllSharedLibraries(context)
if (isPAndAbove) {
sharedLibraries.any {
@@ -180,7 +172,6 @@ object PackageUtil {
} else {
false
}
}
fun isUpdatable(context: Context, packageName: String, versionCode: Long): Boolean {
return try {
@@ -191,48 +182,45 @@ object PackageUtil {
}
}
fun isMicroGBundleInstalled(context: Context): Boolean {
/**
* Confirm if MicroG bundle is installed
* Considering the following:
* 1. GmsCore is installed and it is a microG huawei variant
* 2. Play Store is installed - (microG Companion)
*/
return hasSupportedMicroGVariant(context) && isInstalled(context, PACKAGE_NAME_PLAY_STORE)
}
fun isMicroGBundleInstalled(context: Context): Boolean =
hasSupportedMicroGVariant(context) && isInstalled(context, PACKAGE_NAME_PLAY_STORE)
fun getInstalledVersionName(context: Context, packageName: String): String {
return try {
fun getInstalledVersionName(context: Context, packageName: String): String = try {
getPackageInfo(context, packageName).versionName ?: ""
} catch (e: PackageManager.NameNotFoundException) {
""
}
}
fun getInstalledVersionCode(context: Context, packageName: String): Long {
return try {
fun getInstalledVersionCode(context: Context, packageName: String): Long = try {
PackageInfoCompat.getLongVersionCode(getPackageInfo(context, packageName))
} catch (e: PackageManager.NameNotFoundException) {
0
}
}
fun isTv(context: Context): Boolean {
return context.packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
}
fun isTv(context: Context): Boolean =
context.packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
fun getLaunchIntent(context: Context, packageName: String?): Intent? {
val intent = if (isTv(context)) {
context.packageManager.getLeanbackLaunchIntentForPackage(packageName!!)
} else {
context.packageManager.getLaunchIntentForPackage(packageName!!)
}
} ?: return null
return if (intent == null) {
null
return intent.apply {
addCategory(
if (isTv(context)) {
Intent.CATEGORY_LEANBACK_LAUNCHER
} else {
intent.addCategory(if (isTv(context)) Intent.CATEGORY_LEANBACK_LAUNCHER else Intent.CATEGORY_LAUNCHER)
intent
Intent.CATEGORY_LAUNCHER
}
)
}
}
@@ -257,8 +245,7 @@ object PackageUtil {
}
}
fun getInstallUnknownAppsIntent(): Intent {
return if (isOAndAbove) {
fun getInstallUnknownAppsIntent(): Intent = if (isOAndAbove) {
Intent(
Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES,
"package:${BuildConfig.APPLICATION_ID}".toUri()
@@ -266,7 +253,6 @@ object PackageUtil {
} else {
Intent(Settings.ACTION_SECURITY_SETTINGS)
}
}
fun canRequestPackageInstalls(context: Context): Boolean {
return if (isOAndAbove) {
@@ -275,7 +261,8 @@ object PackageUtil {
@Suppress("DEPRECATION")
val secureResult = Settings.Secure.getInt(
context.contentResolver,
Settings.Secure.INSTALL_NON_MARKET_APPS, 0
Settings.Secure.INSTALL_NON_MARKET_APPS,
0
)
return secureResult == 1
@@ -283,8 +270,8 @@ object PackageUtil {
}
@Throws(Exception::class)
fun getPackageInfo(context: Context, packageName: String, flags: Int = 0): PackageInfo {
return if (isTAndAbove) {
fun getPackageInfo(context: Context, packageName: String, flags: Int = 0): PackageInfo =
if (isTAndAbove) {
context.packageManager.getPackageInfo(
packageName,
PackageInfoFlags.of(flags.toLong())
@@ -292,10 +279,8 @@ object PackageUtil {
} else {
context.packageManager.getPackageInfo(packageName, flags)
}
}
fun getIconForPackage(context: Context, packageName: String): Bitmap? {
return try {
fun getIconForPackage(context: Context, packageName: String): Bitmap? = try {
val packageInfo = context.packageManager.getPackageInfo(packageName, 0)
val icon = packageInfo.applicationInfo!!.loadIcon(context.packageManager)
if (icon.intrinsicWidth > 0 && icon.intrinsicHeight > 0) {
@@ -307,7 +292,6 @@ object PackageUtil {
Log.e(TAG, "Failed to get icon for package!", exception)
null
}
}
fun getIconDrawableForPackage(context: Context, packageName: String): Drawable? {
val placeholder = AppCompatResources.getDrawable(context, R.drawable.bg_placeholder)
@@ -323,15 +307,14 @@ object PackageUtil {
}
}
private fun getAllSharedLibraries(context: Context, flags: Int = 0): List<SharedLibraryInfo> {
return if (isTAndAbove) {
private fun getAllSharedLibraries(context: Context, flags: Int = 0): List<SharedLibraryInfo> =
if (isTAndAbove) {
context.packageManager.getSharedLibraries(PackageInfoFlags.of(flags.toLong()))
} else if (isOAndAbove) {
context.packageManager.getSharedLibraries(flags)
} else {
emptyList()
}
}
fun getFilter(): IntentFilter {
val filter = IntentFilter()

View File

@@ -32,36 +32,28 @@ object PathUtil {
private const val DOWNLOADS = "Downloads"
private const val SPOOF = "SpoofConfigs"
fun getOldDownloadDirectories(context: Context): List<File> {
return listOf(
fun getOldDownloadDirectories(context: Context): List<File> = listOf(
File(context.filesDir, DOWNLOADS), // till 4.4.2
File(context.getExternalFilesDir(null), DOWNLOADS) // till 4.4.2
)
}
fun getDownloadDirectory(context: Context): File {
return File(context.cacheDir, DOWNLOADS)
}
fun getDownloadDirectory(context: Context): File = File(context.cacheDir, DOWNLOADS)
private fun getPackageDirectory(context: Context, packageName: String): File {
return File(getDownloadDirectory(context), packageName)
}
private fun getPackageDirectory(context: Context, packageName: String): File =
File(getDownloadDirectory(context), packageName)
fun getAppDownloadDir(context: Context, packageName: String, versionCode: Long): File {
return File(getPackageDirectory(context, packageName), versionCode.toString())
}
fun getAppDownloadDir(context: Context, packageName: String, versionCode: Long): File =
File(getPackageDirectory(context, packageName), versionCode.toString())
fun getLibDownloadDir(
context: Context,
packageName: String,
versionCode: Long,
sharedLibPackageName: String
): File {
return File(
): File = File(
getAppDownloadDir(context, packageName, versionCode),
"$LIBRARIES/$sharedLibPackageName"
)
}
/**
* Returns an instance of java's [File] class for the given [PlayFile]
@@ -92,23 +84,19 @@ object PathUtil {
}
}
fun getZipFile(context: Context, packageName: String, versionCode: Long): File {
return File(
fun getZipFile(context: Context, packageName: String, versionCode: Long): File = File(
getAppDownloadDir(
context,
packageName,
versionCode,
), "${packageName}_${versionCode}.apks"
versionCode
),
"${packageName}_$versionCode.apks"
)
}
fun getObbDownloadDir(packageName: String): File {
return File(Environment.getExternalStorageDirectory(), "/Android/obb/$packageName")
}
fun getObbDownloadDir(packageName: String): File =
File(Environment.getExternalStorageDirectory(), "/Android/obb/$packageName")
fun getSpoofDirectory(context: Context): File {
return File(context.filesDir, SPOOF)
}
fun getSpoofDirectory(context: Context): File = File(context.filesDir, SPOOF)
fun getNewEmptySpoofConfig(context: Context): File {
val file = File(getSpoofDirectory(context), "${UUID.randomUUID()}.properties")
@@ -117,4 +105,3 @@ object PathUtil {
return file
}
}

View File

@@ -64,8 +64,7 @@ object Preferences {
private var prefs: SharedPreferences? = null
fun getPrefs(context: Context): SharedPreferences {
return when (BuildConfig.FLAVOR) {
fun getPrefs(context: Context): SharedPreferences = when (BuildConfig.FLAVOR) {
"vanilla" -> {
prefs ?: PreferenceManager.getDefaultSharedPreferences(context).also { prefs = it }
}
@@ -76,7 +75,6 @@ object Preferences {
.also { prefs = it }
}
}
}
fun remove(context: Context, key: String) {
getPrefs(context).edit { remove(key) }
@@ -110,33 +108,24 @@ object Preferences {
getPrefs(context).edit(true) { putBoolean(key, value) }
}
fun getString(context: Context, key: String, default: String = ""): String {
return getPrefs(context).getString(key, default).toString()
}
fun getString(context: Context, key: String, default: String = ""): String =
getPrefs(context).getString(key, default).toString()
fun getStringSet(
context: Context,
key: String,
default: Set<String> = emptySet()
): Set<String> {
return getPrefs(context).getStringSet(key, default) ?: emptySet()
}
): Set<String> = getPrefs(context).getStringSet(key, default) ?: emptySet()
fun getInteger(context: Context, key: String, default: Int = 0): Int {
return getPrefs(context).getInt(key, default)
}
fun getInteger(context: Context, key: String, default: Int = 0): Int =
getPrefs(context).getInt(key, default)
fun getFloat(context: Context, key: String): Float {
return getPrefs(context).getFloat(key, 0.0f)
}
fun getFloat(context: Context, key: String): Float = getPrefs(context).getFloat(key, 0.0f)
fun getLong(context: Context, key: String): Long {
return getPrefs(context).getLong(key, 0L)
}
fun getLong(context: Context, key: String): Long = getPrefs(context).getLong(key, 0L)
fun getBoolean(context: Context, key: String, default: Boolean = false): Boolean {
return getPrefs(context).getBoolean(key, default)
}
fun getBoolean(context: Context, key: String, default: Boolean = false): Boolean =
getPrefs(context).getBoolean(key, default)
}
/*Preference Extensions*/
@@ -151,7 +140,6 @@ fun Context.save(key: String, value: Set<String>) = Preferences.putStringSet(thi
fun Context.remove(key: String) = Preferences.remove(this, key)
fun Fragment.save(key: String, value: Int) = requireContext().save(key, value)
fun Fragment.save(key: String, value: Boolean) = requireContext().save(key, value)

View File

@@ -11,10 +11,9 @@ object ShortcutManagerUtil {
private const val TAG = "ShortcutManagerUtil"
fun canPinShortcut(context: Context, packageName: String): Boolean {
return ShortcutManagerCompat.isRequestPinShortcutSupported(context) &&
fun canPinShortcut(context: Context, packageName: String): Boolean =
ShortcutManagerCompat.isRequestPinShortcutSupported(context) &&
context.packageManager.getLaunchIntentForPackage(packageName) != null
}
fun requestPinShortcut(context: Context, packageName: String) {
val packageManager = context.packageManager