عکس yasandev
[DEPRECATED] A simple Android library with useful (Kotlin extension) functions to help you write less code.Kotlin
موضوع‌ها
۰
فورک‌ها
۰
ستاره‌ها
۱۰
تاریخ ایجاد
۴ بهمن ۱۳۹۹
آخرین بروزرسانی
۴ ماه قبل
لایسنس
MIT License

YASAN Helper: Android

Build Status Codacy Badge

A simple Android library with useful (Kotlin extension) functions to help you write less code.

Usage

General app helper functions

String.isNumeric(): Boolean // == if the String is numeric

String.isInteger(): Boolean // == if the string can be converted to Int 

String.isLong(): Boolean // == if the string can be converted to Long 

String.isFloat(): Boolean // == if the string can be converted to Float 

String.isDouble(): Boolean // == if the string can be converted to Double 

View.clearOnClickListener()

You can also use these functions using AppHelper object


Navigation helper functions

Context.startIntentAndClearHistory(intent: Intent) // starts an activity and clears the history

You can also use these functions using NavigationHelper object


Resources helper functions

Context.getColorWithContext(resourceId: Int): Int 

Context.getDrawableWithContext(resourceId: Int): Drawable?

These functions use ContextCompat but you dont have to manually pass Context


SharedPreferences helper functions

Context.getMySharedPreferences(): SharedPreferences

Context.getMySharedPreferencesEditor(): SharedPreferences.Editor

You can also use these functions using SharedPreferencesHelper object


View helper functions

fun View.visible() = ViewHelper.visible(this) // == view.visibility = View.VISIBLE

fun View.invisible() = ViewHelper.invisible(this) // == view.visibility = View.INVISIBLE

fun View.gone() = ViewHelper.gone(this) // == view.visibility = View.GONE

fun View.showSnackBar(message: String) 

fun String.showSnackBar(parent: View) 

fun View.showSnackBarOnTop(message: String) 

fun String.showSnackBarOnTop(parent: View)

fun Activity.closeKeyboard()

You can also use these functions using ViewHelper object


Web helper functions

Context.openWebView(url: String?) // Opens the url in a WebView.
// Opens an app's Play Store page. Opens the current app if `packageName` is null.
WebHelper.openAppOnPlayStore(packageName: String? = null)
String.isURL() // Checks if the string is a valid URL or not using Regex.

You can also use these functions using WebHelper object


Clipboard helper functions

// Copies the string to the clipboard and runs onSuccess if its succeeds.
Context.copyToClipboard(string: String, onSuccess: () -> Unit = {})

You can also use these functions using ClipboardHelper object

Including in your project

This library is available via JitPack, so getting it as simple as adding it as a dependency, like this:

  1. Add JitPack repository to your project build.gradle file:
    allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
    }
    
  2. Add the dependency to your module build.gradle file:
    dependencies {
    implementation 'com.github.yasandev:yasan-helper-android:{latest version}'
    }
    

You can also use 'main-SNAPSHOT' to get the snapshot builds.


Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.


License

GPL-3.0