diff options
author | Allan Wang <me@allanwang.ca> | 2017-06-23 13:58:44 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-06-23 13:58:44 -0700 |
commit | 96aec553a2ecfc8706d8707dc0fdb502864a5000 (patch) | |
tree | 05c74309245c21a328f09a24a6ebc1c1a962a6fd /library | |
parent | e48d21718c3a0b0663fb5e2a7ca67a20853df584 (diff) | |
download | kau-96aec553a2ecfc8706d8707dc0fdb502864a5000.tar.gz kau-96aec553a2ecfc8706d8707dc0fdb502864a5000.tar.bz2 kau-96aec553a2ecfc8706d8707dc0fdb502864a5000.zip |
Add play store checking
Diffstat (limited to 'library')
4 files changed, 48 insertions, 31 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt b/library/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt index d58f99c..dff0f07 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt @@ -10,6 +10,7 @@ import android.support.annotation.StringRes import android.util.DisplayMetrics import ca.allanwang.kau.R import ca.allanwang.kau.logging.KL +import ca.allanwang.kau.utils.installerPackageName import ca.allanwang.kau.utils.isAppInstalled import ca.allanwang.kau.utils.string @@ -37,17 +38,19 @@ class EmailBuilder(@StringRes val emailId: Int, @StringRes val subjectId: Int) { val emailBuilder = StringBuilder() emailBuilder.append(message).append("\n\n") if (deviceDetails) { - emailBuilder.append("\nOS Version: ").append(System.getProperty("os.version")).append("(").append(Build.VERSION.INCREMENTAL).append(")") - .append("\nOS API Level: ").append(Build.VERSION.SDK_INT) - .append("\nDevice: ").append(Build.DEVICE) - .append("\nManufacturer: ").append(Build.MANUFACTURER) - .append("\nModel (and Product): ").append(Build.MODEL).append(" (").append(Build.PRODUCT).append(")") + val deviceItems = mutableMapOf( + "OS Version" to "${System.getProperty("os.version")} (${Build.VERSION.INCREMENTAL})", + "OS API Level" to Build.DEVICE, + "Manufacturer" to Build.MANUFACTURER, + "Model (and Product)" to "${Build.MODEL} (${Build.PRODUCT})", + "Package Installer" to (context.installerPackageName ?: "None") + ) if (context is Activity) { val metric = DisplayMetrics() context.windowManager.defaultDisplay.getMetrics(metric) - emailBuilder.append("\nScreen Dimensions: ${metric.widthPixels} x ${metric.heightPixels}") + deviceItems.put("Screen Dimensions", "${metric.widthPixels} x ${metric.heightPixels}") } - emailBuilder.append("\n") + deviceItems.forEach { k, v -> emailBuilder.append("$k: $v\n") } } if (appInfo) { try { diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt index 3499647..8590d6f 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt @@ -28,7 +28,7 @@ fun Int.toHexString(withAlpha: Boolean = false, withHexPrefix: Boolean = true): return if (withHexPrefix) hex else hex.substring(1) } -fun Int.toRgbaString() :String = "rgba(${Color.red(this)}, ${Color.green(this)}, ${Color.blue(this)}, ${(Color.alpha(this)/255f).round(3)})" +fun Int.toRgbaString(): String = "rgba(${Color.red(this)}, ${Color.green(this)}, ${Color.blue(this)}, ${(Color.alpha(this) / 255f).round(3)})" fun Int.toHSV(): FloatArray { val hsv = FloatArray(3) diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt new file mode 100644 index 0000000..99e5ace --- /dev/null +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt @@ -0,0 +1,37 @@ +package ca.allanwang.kau.utils + +import android.content.Context +import android.content.pm.PackageManager +import android.os.Build + +/** + * Created by Allan Wang on 2017-06-23. + */ + +/** + * Checks if a given package is installed + * @param packageName packageId + * @return true if installed with activity, false otherwise + */ +fun Context.isAppInstalled(packageName: String): Boolean { + val pm = packageManager + var installed: Boolean + try { + pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES) + installed = true + } catch (e: PackageManager.NameNotFoundException) { + installed = false + } + return installed +} + +val buildIsLollipopAndUp: Boolean + get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP + +val buildIsMarshmallowAndUp: Boolean + get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M + +const val KAU_GOOGLE_PLAY_INSTALLER = "com.android.vending" + +val Context.installerPackageName: String? + get() = packageManager.getInstallerPackageName(packageName)
\ No newline at end of file diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt index 1ba54e0..629dfb2 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt @@ -22,12 +22,6 @@ val Int.dpToPx: Int val Int.pxToDp: Int get() = (this / Resources.getSystem().displayMetrics.density).toInt() -val buildIsLollipopAndUp: Boolean - get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP - -val buildIsMarshmallowAndUp: Boolean - get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M - /** * Log whether current state is in the main thread */ @@ -37,23 +31,6 @@ fun checkThread(id: Int) { } /** - * Checks if a given package is installed - * @param packageName packageId - * @return true if installed with activity, false otherwise - */ -fun Context.isAppInstalled(packageName: String): Boolean { - val pm = packageManager - var installed: Boolean - try { - pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES) - installed = true - } catch (e: PackageManager.NameNotFoundException) { - installed = false - } - return installed -} - -/** * Converts minute value to string * Whole hours and days will be converted as such, otherwise it will default to x minutes */ |