├── .DS_Store ├── .gitignore ├── README.md ├── _config.yml ├── android-view-ktx ├── .DS_Store ├── readme.md ├── view-click-ktx.md └── view-visibility-ktx.md ├── androidbites_awesome_extension.jpg ├── androidbites_awesome_extension_banner.jpg ├── contribution.md └── json-ktx ├── gson-ktx.md └── readme.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ch8n/awesome-kotlin-extensions/4dce52d2669a45e8bc460ecf0d1d695f4b826c2b/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Awesome Android Extensions and DSLs- AndroidBites 2 |

3 | 4 | ![awesome-android-extension-androidbites](./androidbites_awesome_extension.jpg) 5 | 6 |

7 | A curated list of Awesome Kotlin Extensions. :octocat: 8 |

9 | 10 |

11 | Android Language Badge 12 | Kotlin Language Badge 13 |

14 | 15 | 16 | ## :hand: About 17 | Hola Amigos! 🙌, Welcome to AndroidBites collection, this repo is a place where I keep all of my faviourite kotlin extension, some are creation of my own and other are gathered from various sources. So this is the one point stop where I point my fellow android devs 👩‍💻 to get some quality extensions. 18 | 19 | Btw do checkout my website 👉 [AndroidBites](https://chetangupta.net), I share all my stuff there, my learnings, my snippets, my research all are here. I believe in sharing so if you like to share too your always invited to contribute! 🤩 20 | 21 | Let's grow together 💪🏻 ! happy hacking 💻. 22 | 23 | P.S : Don't forget to show love and support 🥰 by sharing! & providing feedback! 📝 and PRs are always welcome 24 | 25 | Chao! 26 | 27 | ## :eyes: Social 28 | [LinkedIn](https://bit.ly/ch8n-linkdIn) | 29 | [Medium](https://bit.ly/ch8n-medium-blog) | 30 | [Twitter](https://bit.ly/ch8n-twitter) | 31 | [StackOverflow](https://bit.ly/ch8n-stackOflow) | 32 | [CodeWars](https://bit.ly/ch8n-codewar) | 33 | [Portfolio](https://bit.ly/ch8n-home) | 34 | [Github](https://bit.ly/ch8n-git) | 35 | [Instagram](https://bit.ly/ch8n-insta) | 36 | [Youtube](https://bit.ly/ch8n-youtube) 37 | 38 | 39 | 40 | ## :memo: Contribution 41 | Do checkout if you wanna add to action, 👉 [Contribution Guide](./contribution.md) 42 | 43 | 44 | ## :book: Content 45 | * [Android-View-KTX](./android-view-ktx) 46 | * [Json-KTX](./json-ktx) 47 | 48 | 49 | 50 | ## :cop: License 51 | ``` 52 | Copyright [2020] [Chetan gupta] [chetangupta.net] 53 | Licensed under the Apache License, Version 2.0 (the "License"); 54 | you may not use this file except in compliance with the License. 55 | You may obtain a copy of the License at 56 | 57 | http://www.apache.org/licenses/LICENSE-2.0 58 | 59 | Unless required by applicable law or agreed to in writing, software 60 | distributed under the License is distributed on an "AS IS" BASIS, 61 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 62 | See the License for the specific language governing permissions and 63 | limitations under the License. 64 | 65 | ``` 66 | 67 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /android-view-ktx/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ch8n/awesome-kotlin-extensions/4dce52d2669a45e8bc460ecf0d1d695f4b826c2b/android-view-ktx/.DS_Store -------------------------------------------------------------------------------- /android-view-ktx/readme.md: -------------------------------------------------------------------------------- 1 |

Awesome Android Extensions - AndroidBites 2 |

3 | 4 | ![awesome-android-extension-androidbites](./../androidbites_awesome_extension_banner.jpg) 5 | 6 |

7 | A curated list of Awesome Kotlin Extensions. :octocat: 8 |

9 | 10 |

11 | Android Language Badge 12 | Kotlin Language Badge 13 |

14 | 15 | ## :eyes: Social 16 | [LinkedIn](https://bit.ly/ch8n-linkdIn) | 17 | [Medium](https://bit.ly/ch8n-medium) | 18 | [Twitter](https://bit.ly/ch8n-twitter) | 19 | [StackOverflow](https://bit.ly/ch8n-stackOflow) | 20 | [CodeWars](https://bit.ly/ch8n-codewar) | 21 | [Portfolio](https://bit.ly/ch8n-home) | 22 | [Github](https://bit.ly/ch8n-git) | 23 | [Instagram](https://bit.ly/ch8n-insta) | 24 | [Youtube](https://bit.ly/ch8n-youtube) 25 | 26 | 27 | ## :memo: Contribution 28 | See [contributing.md](contribution.md) 29 | 30 | 31 | ## Android View KTX 32 | Collection of Extension realted to Android Views 33 | 34 | ## :book: Content 35 | * [View-Visibility-KTX](./view-visibility-ktx.md) 36 | * [View-Click-KTX](./view-click-ktx.md) 37 | 38 | ## :cop: License 39 | ``` 40 | Copyright [2020] [Chetan gupta] [chetangupta.net] 41 | Licensed under the Apache License, Version 2.0 (the "License"); 42 | you may not use this file except in compliance with the License. 43 | You may obtain a copy of the License at 44 | 45 | http://www.apache.org/licenses/LICENSE-2.0 46 | 47 | Unless required by applicable law or agreed to in writing, software 48 | distributed under the License is distributed on an "AS IS" BASIS, 49 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 50 | See the License for the specific language governing permissions and 51 | limitations under the License. 52 | 53 | ``` 54 | 55 | -------------------------------------------------------------------------------- /android-view-ktx/view-click-ktx.md: -------------------------------------------------------------------------------- 1 |

Awesome Android Extensions - AndroidBites 2 |

3 | 4 | ![awesome-android-extension-androidbites](./../androidbites_awesome_extension_banner.jpg) 5 | 6 |

7 | A curated list of Awesome Kotlin Extensions. :octocat: 8 |

9 | 10 |

11 | Android Language Badge 12 | Kotlin Language Badge 13 |

14 | 15 | ## :eyes: Social 16 | [LinkedIn](https://bit.ly/ch8n-linkdIn) | 17 | [Medium](https://bit.ly/ch8n-medium) | 18 | [Twitter](https://bit.ly/ch8n-twitter) | 19 | [StackOverflow](https://bit.ly/ch8n-stackOflow) | 20 | [CodeWars](https://bit.ly/ch8n-codewar) | 21 | [Portfolio](https://bit.ly/ch8n-home) | 22 | [Github](https://bit.ly/ch8n-git) | 23 | [Instagram](https://bit.ly/ch8n-insta) | 24 | [Youtube](https://bit.ly/ch8n-youtube) 25 | 26 | 27 | ## :memo: Contribution 28 | See [contributing.md](contribution.md) 29 | 30 | ## Android Click KTX 31 | Useful extension for click behaviour for your views 32 | 33 | ### :book: Content 34 | * [Debounce click listener](#debounce) 35 | * [Double click listener](#double) 36 | 37 | --- 38 | 39 | ### Debounce click listener 40 | Useful to debounce/throttle mutiple click on a view. 41 | ```kotlin 42 | /** 43 | * [Submitted by] : Chetan Gupta 44 | * [Updated on] : 21/9/2020 45 | **/ 46 | inline fun View.onDebounceClick(debounceInMillis: Long = 1200L, crossinline action: () -> Unit) { 47 | this.setOnClickListener(object : View.OnClickListener { 48 | private var lastClickTime: Long = 0 49 | override fun onClick(v: View) { 50 | if (SystemClock.elapsedRealtime() - lastClickTime < debounceTime) return 51 | else action() 52 | lastClickTime = SystemClock.elapsedRealtime() 53 | } 54 | }) 55 | } 56 | ``` 57 | #### Usage 58 | ```kotlin 59 | button.onDebounceClick(debounceInMillis = 1500L){ 60 | // do stuff.. 61 | } 62 | ``` 63 | --- 64 | 65 | ### Double click listener 66 | Useful to simulate double click on a view in a specificed time interval 67 | ```kotlin 68 | /** 69 | * [Submitted by] : Chetan Gupta 70 | * [Updated on] : 21/9/2020 71 | **/ 72 | inline fun View.onDoubleClick(intervalMillis: Long = 1500L, crossinline action: () -> Unit) { 73 | var count = 0 74 | var firstClickRecord: Long = 0 75 | var secondClickRecord: Long = 0 76 | this.setOnClickListener { 77 | count += 1 78 | when (count) { 79 | 1 -> firstClickRecord = Calendar.getInstance().timeInMillis 80 | 2 -> { 81 | secondClickRecord = Calendar.getInstance().timeInMillis 82 | if (abs(firstClickRecord - secondClickRecord) < interval) { 83 | action() 84 | } 85 | count = 0 86 | } 87 | } 88 | } 89 | } 90 | 91 | ``` 92 | #### Usage 93 | ```kotlin 94 | button.onDoubleClick(intervalMillis = 1200L){ 95 | // do stuff.. 96 | } 97 | ``` 98 | 99 | ## :cop: License 100 | ``` 101 | Copyright [2020] [Chetan gupta] [chetangupta.net] 102 | Licensed under the Apache License, Version 2.0 (the "License"); 103 | you may not use this file except in compliance with the License. 104 | You may obtain a copy of the License at 105 | 106 | http://www.apache.org/licenses/LICENSE-2.0 107 | 108 | Unless required by applicable law or agreed to in writing, software 109 | distributed under the License is distributed on an "AS IS" BASIS, 110 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 111 | See the License for the specific language governing permissions and 112 | limitations under the License. 113 | 114 | ``` 115 | 116 | 117 | -------------------------------------------------------------------------------- /android-view-ktx/view-visibility-ktx.md: -------------------------------------------------------------------------------- 1 |

Awesome Android Extensions - AndroidBites 2 |

3 | 4 | ![awesome-android-extension-androidbites](./../androidbites_awesome_extension_banner.jpg) 5 | 6 |

7 | A curated list of Awesome Kotlin Extensions. :octocat: 8 |

9 | 10 |

11 | Android Language Badge 12 | Kotlin Language Badge 13 |

14 | 15 | ## :eyes: Social 16 | [LinkedIn](https://bit.ly/ch8n-linkdIn) | 17 | [Medium](https://bit.ly/ch8n-medium) | 18 | [Twitter](https://bit.ly/ch8n-twitter) | 19 | [StackOverflow](https://bit.ly/ch8n-stackOflow) | 20 | [CodeWars](https://bit.ly/ch8n-codewar) | 21 | [Portfolio](https://bit.ly/ch8n-home) | 22 | [Github](https://bit.ly/ch8n-git) | 23 | [Instagram](https://bit.ly/ch8n-insta) | 24 | [Youtube](https://bit.ly/ch8n-youtube) 25 | 26 | 27 | ## :memo: Contribution 28 | See [contributing.md](contribution.md) 29 | 30 | ## Android View's Visibility KTX 31 | Useful extension for updating visibility of your views 32 | 33 | ### :book: Content 34 | * [Set View Visibility to VISIBLE](#show) 35 | * [Set View Visibility to GONE](#gone) 36 | * [Set View Visibility to INVISIBLE](#invisible) 37 | * [Set View Visibility based on boolean condition](#showBool) 38 | * [Set View InVisibility based on boolean condition](#showWeakBool) 39 | 40 | --- 41 | 42 | ### Set View Visibility to VISIBLE 43 | ```kotlin 44 | /** 45 | * [Author] : Anonymous 46 | * [Updated on] : 8/9/2020 47 | **/ 48 | fun View.show() { 49 | this.visibility = View.VISIBLE 50 | } 51 | ``` 52 | #### Usage 53 | ```kotlin 54 | text_view.show() 55 | ``` 56 | --- 57 | 58 | ### Set View Visibility to GONE 59 | ```kotlin 60 | /** 61 | * [Author] : Anonymous 62 | * [Updated on] : 8/9/2020 63 | **/ 64 | fun View.gone() { 65 | this.visibility = View.GONE 66 | } 67 | ``` 68 | #### Usage 69 | ```kotlin 70 | text_view.gone() 71 | ``` 72 | --- 73 | ### Set View Visibility to INVISIBLE 74 | 75 | ```kotlin 76 | /** 77 | * [Author] : Anonymous 78 | * [Updated on] : 8/9/2020 79 | **/ 80 | fun View.invisible() { 81 | this.visibility = View.INVISIBLE 82 | } 83 | ``` 84 | #### Usage 85 | ```kotlin 86 | text_view.invisible() 87 | ``` 88 | --- 89 | 90 | ### Set View Visibility based on boolean condition 91 | 92 | ```kotlin 93 | /** 94 | * [Author] : Anonymous 95 | * [Updated on] : 8/9/2020 96 | **/ 97 | fun View.setVisibility(isVisible:Boolean) { 98 | if(isVisible){ 99 | this.visibility = View.VISIBLE 100 | }else{ 101 | this.visibility = View.GONE 102 | } 103 | } 104 | ``` 105 | #### Usage 106 | ```kotlin 107 | progress.setVisibility(progress < 95) 108 | ``` 109 | 110 | --- 111 | 112 | ### Set View Invisible based on boolean condition 113 | 114 | ```kotlin 115 | /** 116 | * [Author] : Anonymous 117 | * [Updated on] : 8/9/2020 118 | **/ 119 | fun View.setVisibilityWeak(isVisible:Boolean) { 120 | if(isVisible){ 121 | this.visibility = View.VISIBLE 122 | }else{ 123 | this.visibility = View.INVISIBLE 124 | } 125 | } 126 | ``` 127 | 128 | #### Usage 129 | ```kotlin 130 | progress.setVisibilityWeak(progress < 95) 131 | ``` 132 | 133 | --- 134 | 135 | ## :cop: License 136 | ``` 137 | Copyright [2020] [Chetan gupta] [chetangupta.net] 138 | Licensed under the Apache License, Version 2.0 (the "License"); 139 | you may not use this file except in compliance with the License. 140 | You may obtain a copy of the License at 141 | 142 | http://www.apache.org/licenses/LICENSE-2.0 143 | 144 | Unless required by applicable law or agreed to in writing, software 145 | distributed under the License is distributed on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 147 | See the License for the specific language governing permissions and 148 | limitations under the License. 149 | 150 | ``` 151 | 152 | 153 | -------------------------------------------------------------------------------- /androidbites_awesome_extension.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ch8n/awesome-kotlin-extensions/4dce52d2669a45e8bc460ecf0d1d695f4b826c2b/androidbites_awesome_extension.jpg -------------------------------------------------------------------------------- /androidbites_awesome_extension_banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ch8n/awesome-kotlin-extensions/4dce52d2669a45e8bc460ecf0d1d695f4b826c2b/androidbites_awesome_extension_banner.jpg -------------------------------------------------------------------------------- /contribution.md: -------------------------------------------------------------------------------- 1 |

Awesome Android Extensions - AndroidBites 2 |

3 | 4 | ![awesome-android-extension-androidbites](./androidbites_awesome_extension_banner.jpg) 5 | 6 |

7 | A curated list of Awesome Kotlin Extensions. :octocat: 8 |

9 | 10 |

11 | Android Language Badge 12 | Kotlin Language Badge 13 |

14 | 15 | ## :eyes: Social 16 | [LinkedIn](https://bit.ly/ch8n-linkdIn) | 17 | [Medium](https://bit.ly/ch8n-medium) | 18 | [Twitter](https://bit.ly/ch8n-twitter) | 19 | [StackOverflow](https://bit.ly/ch8n-stackOflow) | 20 | [CodeWars](https://bit.ly/ch8n-codewar) | 21 | [Portfolio](https://bit.ly/ch8n-home) | 22 | [Github](https://bit.ly/ch8n-git) | 23 | [Instagram](https://bit.ly/ch8n-insta) | 24 | [Youtube](https://bit.ly/ch8n-youtube) 25 | 26 | 27 | ## Contributing Guide 28 | 29 | It's so nice to see you here, please do follow these guidelines and thank you for your contribution! 🤩 30 | 31 | ### How to contribute 32 | - Please open a issue first so that it's in notice of maintainers that your working on a feature/issue 33 | 34 | - Have a healthy discussion about your approach/strategy/question before you start you task, 35 | 36 | - Fork the project from the `master` branch and submit a Pull Request (PR) 37 | 38 | - Explain what the PR fixes or improves. 39 | 40 | - If your PR aims to add a new resource to the list, provide the `author/origin` of the resource, along with updated on `date` 41 | 42 | - Use sensible commit messages 43 | 44 | - Your PR should not have 1000s of commits. 45 | 46 | - be respectful/humble or you would be displayed on `Wall of Shame 🐴` 47 | 48 | 49 | ## :cop: License 50 | ``` 51 | Copyright [2020] [Chetan gupta] [chetangupta.net] 52 | Licensed under the Apache License, Version 2.0 (the "License"); 53 | you may not use this file except in compliance with the License. 54 | You may obtain a copy of the License at 55 | 56 | http://www.apache.org/licenses/LICENSE-2.0 57 | 58 | Unless required by applicable law or agreed to in writing, software 59 | distributed under the License is distributed on an "AS IS" BASIS, 60 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 61 | See the License for the specific language governing permissions and 62 | limitations under the License. 63 | 64 | ``` 65 | 66 | -------------------------------------------------------------------------------- /json-ktx/gson-ktx.md: -------------------------------------------------------------------------------- 1 |

Awesome Android Extensions - AndroidBites 2 |

3 | 4 | ![awesome-android-extension-androidbites](./../androidbites_awesome_extension_banner.jpg) 5 | 6 |

7 | A curated list of Awesome Kotlin Extensions. :octocat: 8 |

9 | 10 |

11 | Android Language Badge 12 | Kotlin Language Badge 13 |

14 | 15 | ## :eyes: Social 16 | [LinkedIn](https://bit.ly/ch8n-linkdIn) | 17 | [Medium](https://bit.ly/ch8n-medium) | 18 | [Twitter](https://bit.ly/ch8n-twitter) | 19 | [StackOverflow](https://bit.ly/ch8n-stackOflow) | 20 | [CodeWars](https://bit.ly/ch8n-codewar) | 21 | [Portfolio](https://bit.ly/ch8n-home) | 22 | [Github](https://bit.ly/ch8n-git) | 23 | [Instagram](https://bit.ly/ch8n-insta) | 24 | [Youtube](https://bit.ly/ch8n-youtube) 25 | 26 | 27 | ## :memo: Contribution 28 | See [contributing.md](contribution.md) 29 | 30 | ## Gson Parsing KTX 31 | Useful extension for parsing GSONString to Object and vice-versa 32 | 33 | ### :book: Content 34 | * [Convert Object class to JSONString](#ObjectToJSONStringConversion) 35 | * [Convert JSONString to respective Object Class](#JSONStringToObjectConversion) 36 | --- 37 | 38 | ### Convert Given Object class to JSON String 39 | ```kotlin 40 | /** 41 | * [Submitted by] : Ashok 42 | * [Updated on] : 12/10/2020 43 | **/ 44 | fun Any.toJson(): String? { 45 | return try { 46 | gson.toJson(this) 47 | } catch (exception: Exception) { 48 | //..you can log the exception for debugging 49 | null 50 | } 51 | } 52 | ``` 53 | #### Usage 54 | ```kotlin 55 | //test class used for demonstration 56 | data class TestObject(val name: String,val rollNo: Int) 57 | 58 | val testObject = TestObject("Ashok", 922) 59 | val json:String = testObject.toJson()?:"" 60 | ``` 61 | --- 62 | 63 | ### Convert JSON String to respective Object class 64 | ```kotlin 65 | /** 66 | * [Submitted by] : Ashok 67 | * [Updated on] : 12/10/2020 68 | * Below method uses generics and can convert JSONString 69 | * to Any type of object depending on the type provided] 70 | **/ 71 | fun String.fromJson(type: Type): T? { 72 | if (this.isEmpty()) { 73 | return null 74 | } 75 | return try { 76 | gson.fromJson(this, type) 77 | } catch (exception: Exception) { 78 | //..you can log the exception for debugging 79 | null 80 | } 81 | } 82 | ``` 83 | #### Usage 84 | ```kotlin 85 | //test class used for demonstration 86 | data class TestObject(val name: String,val rollNo: Int) 87 | 88 | val json= "{\"name\":\"Ashok\",\"rollNo\":922}" 89 | val testObject: TestObject? = json.fromJson(TestObject::class.java) 90 | ``` 91 | 92 | ## :cop: License 93 | ``` 94 | Copyright [2020] [Chetan gupta] [chetangupta.net] 95 | Licensed under the Apache License, Version 2.0 (the "License"); 96 | you may not use this file except in compliance with the License. 97 | You may obtain a copy of the License at 98 | 99 | http://www.apache.org/licenses/LICENSE-2.0 100 | 101 | Unless required by applicable law or agreed to in writing, software 102 | distributed under the License is distributed on an "AS IS" BASIS, 103 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 104 | See the License for the specific language governing permissions and 105 | limitations under the License. 106 | 107 | ``` 108 | 109 | 110 | -------------------------------------------------------------------------------- /json-ktx/readme.md: -------------------------------------------------------------------------------- 1 |

Awesome Android Extensions - AndroidBites 2 |

3 | 4 | ![awesome-android-extension-androidbites](./../androidbites_awesome_extension_banner.jpg) 5 | 6 |

7 | A curated list of Awesome Kotlin Extensions. :octocat: 8 |

9 | 10 |

11 | Android Language Badge 12 | Kotlin Language Badge 13 |

14 | 15 | ## :eyes: Social 16 | [LinkedIn](https://bit.ly/ch8n-linkdIn) | 17 | [Medium](https://bit.ly/ch8n-medium) | 18 | [Twitter](https://bit.ly/ch8n-twitter) | 19 | [StackOverflow](https://bit.ly/ch8n-stackOflow) | 20 | [CodeWars](https://bit.ly/ch8n-codewar) | 21 | [Portfolio](https://bit.ly/ch8n-home) | 22 | [Github](https://bit.ly/ch8n-git) | 23 | [Instagram](https://bit.ly/ch8n-insta) | 24 | [Youtube](https://bit.ly/ch8n-youtube) 25 | 26 | 27 | ## :memo: Contribution 28 | See [contributing.md](contribution.md) 29 | 30 | 31 | ## Json KTX 32 | Collection of Extension related to Json 33 | 34 | ## :book: Content 35 | * [Gson-KTX](./gson-ktx.md) 36 | 37 | 38 | ## :cop: License 39 | ``` 40 | Copyright [2020] [Chetan gupta] [chetangupta.net] 41 | Licensed under the Apache License, Version 2.0 (the "License"); 42 | you may not use this file except in compliance with the License. 43 | You may obtain a copy of the License at 44 | 45 | http://www.apache.org/licenses/LICENSE-2.0 46 | 47 | Unless required by applicable law or agreed to in writing, software 48 | distributed under the License is distributed on an "AS IS" BASIS, 49 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 50 | See the License for the specific language governing permissions and 51 | limitations under the License. 52 | 53 | ``` 54 | 55 | --------------------------------------------------------------------------------