Skip to content

Commit

Permalink
v1.0.2 released
Browse files Browse the repository at this point in the history
  • Loading branch information
death14stroke committed Mar 10, 2020
1 parent 434e7ce commit 6b3e2d2
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 26 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
kotlin_version = "1.3.61"
kotlin_version = "1.3.70"
dokka_version = "0.10.1"
}

Expand Down
14 changes: 1 addition & 13 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ android {
minSdkVersion 23
targetSdkVersion 29
versionCode 2
versionName "1.0.1"
versionName "1.0.2"
consumerProguardFiles "consumer-rules.pro"
}

Expand Down Expand Up @@ -44,18 +44,6 @@ android {
outputFormat = 'html'
outputDirectory = "$buildDir/dokka"
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude("META-INF/*.kotlin_module")
}
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion library/publish.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
PUBLISH_GROUP_ID = 'com.andruid.magic'
PUBLISH_ARTIFACT_ID = 'eezetensions'
PUBLISH_VERSION = '1.0.1'
PUBLISH_VERSION = '1.0.2'
}

apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle'
58 changes: 57 additions & 1 deletion library/src/main/java/com/andruid/magic/eezetensions/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ package com.andruid.magic.eezetensions
import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
import android.os.Handler
import android.os.Looper
import android.provider.Settings
import android.widget.Toast
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.RequiresPermission
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService

Expand Down Expand Up @@ -55,4 +61,54 @@ fun Context.hasInternet(): Boolean {
nc.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
}
} ?: false
}
}

/**
* Extension function to get package version name for the application
* @return package version string
* @receiver context of the calling component
*/
fun Context.getPackageVersion(): String? {
return try {
val pInfo = packageManager.getPackageInfo(applicationContext.packageName, 0)
pInfo.versionName
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
null
}
}

/**
* Extension function to show toast from background threads
* @param msg toast message
* @param duration toast duration (default = [Toast.LENGTH_SHORT]
* @param fromBg toast from background (default = false)
* @receiver context of the calling component
*/
fun Context.toast(msg: String, duration: Int = Toast.LENGTH_SHORT, fromBg: Boolean = false) {
if (fromBg) {
Handler(Looper.getMainLooper()).post {
toast(msg, duration, false)
}
} else
Toast.makeText(this, msg, duration).show()
}

/**
* Extension function to show toast from background threads
* @param msgRes string resource for toast message
* @param duration toast duration (default = [Toast.LENGTH_SHORT]
* @param fromBg toast from background (default = false)
* @receiver context of the calling component
*/
fun Context.toast(@StringRes msgRes: Int, duration: Int = Toast.LENGTH_SHORT, fromBg: Boolean = false) {
toast(getString(msgRes), duration, fromBg)
}

/**
* Extension function to get device name set in settings
* @return user set device name
* @receiver context of the calling component
*/
fun Context.getUserDeviceName(): String =
Settings.Global.getString(contentResolver, "device_name")
36 changes: 28 additions & 8 deletions library/src/main/java/com/andruid/magic/eezetensions/Fragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,60 @@
package com.andruid.magic.eezetensions

import android.content.Intent
import android.widget.Toast
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.RequiresPermission
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment

/**
* Extension function to load color from resource
* @param color id of the color resource
* @return color from color resource
* @receiver active fragment
* @receiver calling fragment
*/
fun Fragment.color(@ColorRes color: Int) = requireContext().color(color)

/**
* Extension function to load drawable from resource
* @param res id of the drawable resource
* @return drawable from drawable resource
* @receiver active fragment
* @receiver calling fragment
*/
fun Fragment.drawable(@DrawableRes res: Int) = requireContext().drawable(res)

/**
* Extension function to start foreground service above API 26 else start background service
* @param intent to launch the service
* @receiver active fragment
* @receiver calling fragment
*/
fun Fragment.startFgOrBgService(intent: Intent) {
requireContext().startFgOrBgService(intent)
}

/**
* Extension function to check whether device is connected to internet or not
* @return true/false
* @receiver active fragment
* Extension function to show toast from background threads
* @param msg toast message
* @param duration toast duration (default = [Toast.LENGTH_SHORT]
* @param fromBg toast from background (default = false)
* @receiver calling fragment
*/
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
fun Fragment.hasInternet() = requireContext().hasInternet()
fun Fragment.toast(msg: String, duration: Int = Toast.LENGTH_SHORT, fromBg: Boolean = false) {
requireContext().toast(msg, duration, fromBg)
}

/**
* Extension function to show toast from background threads
* @param msgRes string resource for toast message
* @param duration toast duration (default = [Toast.LENGTH_SHORT]
* @param fromBg toast from background (default = false)
* @receiver calling fragment
*/
fun Fragment.toast(
@StringRes msgRes: Int,
duration: Int = Toast.LENGTH_SHORT,
fromBg: Boolean = false
) {
requireContext().toast(msgRes, duration, fromBg)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import android.net.Uri
import android.provider.Settings

/**
* Get intent to show the settings screen of the app or permissions and other settings
* Get intent to show the settings screen of the app for permissions and other settings
* @return intent to launch settings page
* @receiver context of the component
*/
fun Context.buildSettingsIntent(): Intent {
val uri = Uri.fromParts("package", packageName, null)
return Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
.setData(uri)
.setData(uri)
}

0 comments on commit 6b3e2d2

Please sign in to comment.