Skip to content

Commit

Permalink
2019-06-2 11:45
Browse files Browse the repository at this point in the history
LogUtils bug fix
  • Loading branch information
Aryan-mor authored and Aryan-mor committed Jun 2, 2019
1 parent d495c35 commit 44b67b5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
2 changes: 1 addition & 1 deletion UtilsLibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.3.6"
versionName "1.3.7"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
59 changes: 55 additions & 4 deletions UtilsLibrary/src/main/java/com/aryanmo/utils/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.aryanmo.utils.utils

import android.annotation.SuppressLint
import android.app.Activity
import android.app.Application
import android.content.Context
import android.content.Intent
import android.net.Uri
Expand Down Expand Up @@ -38,6 +39,21 @@ fun Activity.getVersionCode(): Int {
return -1
}

fun Application.getVersionCode(): Int {
try {
val pInfo = this.packageManager.getPackageInfo(this.packageName, 0)
return if (android.os.Build.VERSION.SDK_INT >= 28) {
pInfo.longVersionCode.toInt()
} else {
pInfo.versionCode
}
} catch (e: Exception) {
logError("getVersionCode", e)
}

return -1
}

fun Activity.getVersionName(): String {
try {
val pInfo = this.packageManager.getPackageInfo(this.packageName, 0)
Expand All @@ -63,6 +79,31 @@ fun Activity.getAppInfo(): HashMap<String, String> {

}

fun Application.getVersionName(): String {
try {
val pInfo = this.packageManager.getPackageInfo(this.packageName, 0)
return pInfo.versionName
} catch (e: Exception) {
logError("getVersionCode", e)
return ""
}

}

fun Application.getAppInfo(): HashMap<String, String> {
try {
val hashMap = HashMap<String, String>()
hashMap["os"] = "android"
hashMap["android_sdk_api_level"] = sdkApiLevel.toString()
hashMap["version"] = this.getVersionCode().toString()
return hashMap
} catch (e: Exception) {
logError("getAppInfo", e)
return HashMap()
}

}

fun Activity.openLink(link: String): Boolean {
try {
this.intentTo(Intent(Intent.ACTION_VIEW, Uri.parse(link)))
Expand Down Expand Up @@ -134,10 +175,10 @@ fun Activity.delayOnUiThread(duration: Int, runnable: () -> Unit) {
} catch (e: InterruptedException) {
e.printStackTrace()
}
this.runOnUiThread {
runnable()
}
}).start()
this.runOnUiThread {
runnable()
}
}

fun delay(duration: Long) {
Expand All @@ -147,7 +188,7 @@ fun delay(duration: Long) {
} catch (e: InterruptedException) {
e.printStackTrace()
}
})
}).start()
}

fun Context.dpTOInt(f: Float): Int {
Expand Down Expand Up @@ -182,7 +223,17 @@ fun Activity.hideSoftKeyboard(view: View) {
} catch (e: Exception) {
logError("hideSoftKeyboard", e)
}
}

fun Activity.showSoftKeyboard() {
val view = currentFocus ?: return
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
}

fun Activity.showSoftKeyboard(view: View) {
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
}

//Device
Expand Down

0 comments on commit 44b67b5

Please sign in to comment.