{"id":15040908,"url":"https://github.com/gurleensethi/liteutilities","last_synced_at":"2025-04-09T08:11:44.847Z","repository":{"id":98501544,"uuid":"100854527","full_name":"gurleensethi/LiteUtilities","owner":"gurleensethi","description":"Speed up your android development by removing boilerplate code","archived":false,"fork":false,"pushed_at":"2019-04-04T00:13:05.000Z","size":173,"stargazers_count":397,"open_issues_count":5,"forks_count":38,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-09T08:11:37.798Z","etag":null,"topics":["android","android-development","android-library","kotlin","kotlin-android","kotlin-library"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gurleensethi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-20T10:38:53.000Z","updated_at":"2025-02-06T09:06:56.000Z","dependencies_parsed_at":"2023-07-04T18:02:07.981Z","dependency_job_id":null,"html_url":"https://github.com/gurleensethi/LiteUtilities","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gurleensethi%2FLiteUtilities","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gurleensethi%2FLiteUtilities/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gurleensethi%2FLiteUtilities/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gurleensethi%2FLiteUtilities/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gurleensethi","download_url":"https://codeload.github.com/gurleensethi/LiteUtilities/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999864,"owners_count":21031046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-development","android-library","kotlin","kotlin-android","kotlin-library"],"created_at":"2024-09-24T20:45:16.304Z","updated_at":"2025-04-09T08:11:44.823Z","avatar_url":"https://github.com/gurleensethi.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![](https://jitpack.io/v/gurleensethi/LiteUtilities.svg)](https://jitpack.io/#gurleensethi/LiteUtilities)\n\n# LiteUtilities\nSpeed up your android development by removing boilerplate code\n\n#### To use this library in your project, do as follows:\n\n1. In your top level `build.gradle` file, in the `repository` section add the `maven { url 'https://jitpack.io' }` as shown below\n```gradle\nallprojects {\n  repositories {\n    ...\n    maven { url 'https://jitpack.io' }\n  }\n}\n```\n2. Add the `LiteUtilities` dependency in your app level `build.gradle` file\n```gradle\ncompile 'com.github.gurleensethi:LiteUtilities:v1.3.0'\n```\n\n#### Current Features\n* [RecyclerUtils](#recyclerutils) - Remove the need to make an adapter everytime, set up recycler adapter in as little as 4 lines.\n* [ScrollUtils](#scrollutils) - Easily hide/show FloationActionButton on scroll when using RecyclerView or NestedScrollView.\n* [ToastUtils](#toastutils) - Creating toasts are just a function away.\n* [SPUtils](#sputils) - Simple DSL for Shared Preferences.\n* [ValidatorUtils](#validatorutils) - Fast and simple text validation.\n* [LogUtils](#logutils) - Simple and easy android logging.\n\n##### The library is designed in such a way that if don't want to import the complete library but only want a specific Util, then you can download the corresponding file for the required Util, every Util has its own file/files and is independent of any other Util. You can find the code [here](https://github.com/gurleensethi/LiteUtilities/tree/master/liteutils/src/main/java/com/thetechnocafe/gurleensethi/liteutils).\n\n#### Motivation\nPrimary motivation behind the development of this library is to hide the day-to-day boilerplate code that android developers have to deal with, by providing a simple and concise API, but also maintaining complete functionality at the same time.\n\nRecyclerUtils\n======\n\nRecyclerUtils contain a very handy class named `RecyclerAdapterUtil` which can be used to make recycler adapters in as little as 4 lines. No need to create a separate adapter class for every recycler view.\n\nThe constructor of `RecyclerAdapterUtil` takes 3 parameters.\n* Context - Application `Context`.\n* ItemList - `List` of objects of type T which will be used as the primary data source for setting data to view holder items.\n* LayoutResourceId - Resource id of the layout that represents single item view for RecyclerView.\n\nSo to create a recycler adapter that displays a list of strings, you would write something like this:\n```kotlin\nval list = listOf(\"Test\", \"1\", \"2\", \"3\", \"This is a test\", \"123\")\nval recyclerAdapter = RecyclerAdapterUtil\u003cString\u003e(this, list, R.layout.item_recycler_view)\nrecyclerAdapter.addViewsList(R.id.textView, R.id.imageView)\n```\nThe `addViewsList` function is important, pass the id's of all views contained in the single layout file provided in constructor (in this case it is`R.layout.item_recycler_view`) that you want to refer to while binding data. There are two ways to pass these id's.\n##### All the views that you want to reference while binding data should be provided before hand, else the app will not function properly.\n```kotlin\nrecyclerAdapter.addViewsList(R.id.textView, R.id.imageView)\n                  /* OR */\nval listOfViews = listOf(R.id.textView, R.id.imageView)\nrecyclerAdapter.addViewsList(listOfViews)\n```\nTo bind data, add data bind listener:\n```kotlin\nrecyclerAdapter.addOnDataBindListener { itemView, item, position. innerViews -\u003e \n            val textView = innerViews[R.id.textView] as TextView\n            textView.text = item\n        }\n```\n`addOnDataBindListener` is a lambda which provides three items:\n* `itemView` - The ViewHolder itself.\n* `item` - Data item from the list.\n* `position` - Position of the data item in the list.\n* `innerViews` - A `Map\u003cInt, View\u003e` containing the reference to the views that were provided in the `addViewsList` function.\n\n### Click Listeners\nYou can also add `OnClickListener` and `OnLongClickListener` simply by implementing two lambdas.\n\n```kotlin\n//OnClickListener\nrecyclerAdapter.addOnClickListener { item, position -\u003e \n            //Take action when item is pressed\n        }\n\n//OnLongClickListener\nrecyclerAdapter.addOnLongClickListener { item, position -\u003e\n            //Take action when item is long pressed\n        }\n```\n\nBoth `addOnClickListener` and `addOnLongClickListener` provide lambda with two parameters:\n* `item` - Data item from the list.\n* `position` - Position of the data item in the list.\n\n### Using Builder pattern for more consice code\n\nUse `RecyclerAdapterUtil.Builder` to chain functions as shown below.\n\n```kotlin\nRecyclerAdapterUtil.Builder(this, list, R.layout.item_recycler_view)\n                .viewsList(R.id.textView, R.id.imageView)\n                .bindView { itemView, item, position, innerViews -\u003e\n                    val textView = innerViews[R.id.textView] as TextView\n                    textView.text = item\n                }\n                .addClickListener { item, position -\u003e\n                    //Take action when item is pressed\n                }\n                .addLongClickListener { item, position -\u003e\n                    //Take action when item is long pressed\n                }\n                .into(recyclerView)\n```\n\n`into(RecyclerView)` function takes the reference of `RecyclerView` and directly sets the adapter to it so you don't have to do it explicitly.\nIf you want the object of adapter and want to set it manually use `build()` instead of `into(RecyclerView)`.\n\nScrollUtils\n======\n\nHide FloatingActionButton when user scrolls up and show it again when scrolled down. You can achieve this by using function `hideFloatingActionButtonOnScroll` on `NestedScrollView` and `RecyclerView`. These functions are implemented as extension functions.\n```kotlin\nval nestedScrollView = findViewById(R.id.nestedScrollView) as NestedScrollView\nval floatingActionButton = findViewById(R.id.floatingActionButton) as FloatingActionButton\n\nnestedSrollView.hideFloatingActionButtonOnScroll(floatingActionButton)\n```\n\n### Take custom action when scrolled up and down\nIf you want to take custom action when scrolled up or down you can implement `ScrollListener` using the function `addScrollListener(ScrollListener)`. This works with both `NestedScrollView` and `RecyclerView`.\n\n```kotlin\nnestedScrollView.addScrollListener(object : ScrollListener {\n            override fun scrolledDown() {\n                //Take Action when user scrolls down\n            }\n\n            override fun scrolledUp() {\n                //Take Action when user scrolls up\n            }\n        })\n```\n\nToastUtils\n======\n\nMaking toast has never been easier. Just use `shortToast(String)` for making short toast and `longToast(String)` for making long ones. These functions are implemented as extension functions on `Context`, so wherever `Context` is available, these functions can be used.\n\n```kotlin\nshortToast(\"This is a short toast\")\nlongToast(\"This is a long toast\")\n```\n\n### Making colored Toasts\nTo make a toast with custom background and text color use `coloredShortToast(message, backgroundColor, textColor)` or `coloredLongToast(message, backgroundColor, textColor)`.\n\nBoth of these functions take three parameters:\n* `message`: String displayed by the toast.\n* `backgroundColor`: Background Color of the toast.\n* `textColor`: Color of the text shown.\n\n```kotlin\ncoloredShortToast(\"Colored short toast\", R.color.darker_gray, R.color.black)\ncoloredLongToast(\"Colored long toast\", R.color.darker_gray, R.color.black)\n```\n\nSPUtils\n======\n\nEasy DSL for sharedpreferences. No need to write long lines of code when using SharedPreferences. The below functions are implemented as extension functions on `Context`, so they are available wherever `Context` is available.\n\n### Storing values\nTo use the default SharedPreferences file which is provided by the library itself, use `defaultSharedPreferences` function which takes a lambda for required operations, much easier to understand with an example. The mode used to open file is `MODE_PRIVATE`.\n\n```kotlin\ndefaultSharedPreferences {\n            putString(\"string\", \"Some Value 123\")\n            putInt(\"integer\", 1)\n        }\n```\n\nIf you want to use your own file and mode the use `sharedPreferences(fileName, mode, lambda)`.\n\n```kotlin\nsharedPreferences(\"SP\", Context.MODE_PRIVATE) {\n            putString(\"string\", \"Some Value 123\")\n            putInt(\"integer\", 1)\n        }\n```\n\n### Fetching values\nTo get value from default SharedPreferences use `getFromDefaultSharedPreferences\u003cT\u003e(key, defaultValue)`.\n\n```kotlin\ngetFromDefaultSharedPreferences\u003cString\u003e(\"string\", \"default value\")\n```\n\nYou can also eliminate the need to specify a type explicitly, but in that case the type will be inferred from the type of `defaultValue` which is the second parameter so you can write.\n\n```kotlin\ngetFromDefaultSharedPreferences(\"string\", \"default value\")\n```\n\nTo get from custom SharedPreferences file use `getFromSharedPreferences\u003cT\u003e(fileName, key, defaultValue)`.\n\n```kotlin\ngetFromSharedPreferences\u003cString\u003e(\"SP\", \"string\", \"default\")\n                /* OR */\ngetFromSharedPreferences(\"SP\", \"string\", \"default\")\n```\n\nValidatorUtils\n======\n\nSet of functions that provide easy and fast text validation. More than 15+ validation types available.\nUse the `Validator` class to access all the validation functions. This class is available using an extension function on `EditText` and `TextInputEditText`. Just call the `validator()` function.\n\nUsing `Validator` directly on `EditText`.\n```kotlin\nvar result: Boolean = editText.validator()\n                    .email()\n                    .atLeastOneUpperCase()\n                    .atLeastOneLowerCase()\n                    .maximumLength(20)\n                    .minimumLength(5)\n                    .noNumbers()\n                    .validate()\n```\nThe `Validator` class has all the validation functions, chain all the functions that you require and call `validate()` to process. The result returned is a `Boolean`, `true` if all validation are passed, `false` if any one of them fails.\n\n### Adding callbacks to listen to results\nIf you want to take action after the validation is complete, there are two callbacks available, `addSuccessCallback()` and `addErrorCallback(ValidationError)`. The `addSuccessCallback` is invoked when the valdiation passes, `addErrorCallback` is invoked when validation fails.\n\n```kotlin\nvar result = editText.validator()\n                    .email()\n                    .atLeastOneUpperCase()\n                    .atLeastOneLowerCase()\n                    .maximumLength(20)\n                    .minimumLength(5)\n                    .noNumbers()\n                    .addSuccessCallback {\n                        //Proceed\n                    }\n                    .addErrorCallback { errorType -\u003e\n                        when (errorType) {\n                            ValidationError.EMAIL -\u003e {\n                                editText.error = \"Email format is incorrect\"\n                            }\n                            ValidationError.AT_LEAST_ONE_LOWER_CASE -\u003e {\n                                editText.error = \"Please provide at-least one lower case letter\"\n                            }\n                            ValidationError.AT_LEAST_ONE_UPPER_CASE -\u003e {\n                                editText.error = \"Please provide at-least one upper case letter\"\n                            }\n                            else -\u003e {\n                                editText.error = \"Not Enough\"\n                            }\n                        }\n                    }\n                    .validate()\n```\nThe `addErrorCallback` also provides a parameter of type `ValidationError`. This parameter provies the type of validation error that has occured. `ValidationError` is an enum, the naming convention is very simple, the names are same as the corresponding validation functions. For example, for validation function `atLeastOneLowerCase`, the validation error will be `ValidationError.AT_LEAST_ONE_LOWER_CASE`.\n\n### Using Validator independently \n`Validator` class can also be used independently, just instantiate an object of it.\n```kotlin\nval validator = Validator(\"somePassword#123\")\nvalidator.atLeastOneNumber()\n    .atLeastOneUpperCase()\n    .minimumLength(8)\n    .maximumLength(32)\n    .atLeastOneSpecialCharacter()\n    .validate()\n```\n\nLogUtils\n======\n\nSimple and easy logging for android using LogUtils. Supported 6 log levels.\nTo begin, set the log levels that you want to be logged. Messages will not be logged if no `LogLevel` is added.\n\n```kotlin\nLogUtils.addLevel(LogLevel.DEBUG)\nLogUtils.addLevel(LogLevel.INFO)\nLogUtils.addLevel(LogLevel.ERROR)\nLogUtils.addLevel(LogLevel.VERBOSE)\nLogUtils.addLevel(LogLevel.WARN)\nLogUtils.addLevel(LogLevel.WTF)\n```\n\nTo enable all log levels just use `LogLevel.ALL`\n```kotlin\nLogUtils.addLevel(LogLevel.ALL)\n```\n\nUse the following functions throughout your app for logging purposes.\n```kotlin\ndebug(\"This is a debug message\")\nerror(\"Some error occurred\")\nwarn(\"This is a warning\")\ninfo(\"Some information\")\nverbose(\"VERBOSE!\")\nwtf(\"Ignore this\")\njson(\"{message:'This is a message', version: {num: 10}}\")\nshout(\"Shout this message loud!\\nThank YOU\")\nexception(Exception(\"ERROR\"))\n```\n\n#### JSON\nTo log a json string use the `json(jsonString)` function. This function will throw error if json structure is not right. To see the error `LogLevel.ERROR` should be enabled.\n```kotlin\njson(\"{message:'This is a message', version: {num: 10}}\")\n```\nOutput:\n```\n{\n    \"message\": \"This is a message\",\n    \"version\": {\n        \"num\": 10\n    }\n}\n```\n\n#### Shout\n`shout(message)` prints a big box around the message.\n```kotlin\nshout(\"Shout this message loud!\\nThank YOU\")\n```\nOutput:\n```\n************************************\n*                                  *\n*     Shout this message loud!     *\n*             Thank YOU            *\n*                                  *\n************************************\n```\n\nSupport\n======\n\nThe primary purpose of this library is to speed up development process by removing boilerplate code, so if you have any idea or a new feature that meets the requirement and enhances the library as a whole or you found a bug in the existing code please open an [issue](https://github.com/gurleensethi/LiteUtilities/issues/new), it is much appreciated.\n\nLicense\n======\n```\nMIT License\n\nCopyright (c) 2017, Gurleen Sethi\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgurleensethi%2Fliteutilities","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgurleensethi%2Fliteutilities","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgurleensethi%2Fliteutilities/lists"}