├── .github
└── workflows
│ └── publish.yml
├── .gitignore
├── CHANGELOG.MD
├── LICENSE
├── README.md
├── android
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── io
│ └── github
│ └── ackeecz
│ └── extensions
│ └── android
│ ├── CollectionsExtensions.kt
│ ├── Common.kt
│ ├── ContextExtensions.kt
│ ├── DrawableExtensions.kt
│ ├── FragmentExtensions.kt
│ ├── SpannableExtensions.kt
│ ├── StringExtensions.kt
│ └── ViewExtensions.kt
├── anko
├── .gitignore
├── build.gradle
├── consumer-proguard-rules.txt
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── io
│ └── github
│ └── ackeecz
│ └── extensions
│ └── anko
│ ├── AnkoExtensions.kt
│ └── layout
│ ├── LayoutExtensions.kt
│ └── ViewLayout.kt
├── build.gradle
├── build.properties
├── epoxy
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── io
│ │ └── github
│ │ └── ackeecz
│ │ └── extensions
│ │ └── epoxy
│ │ ├── EpoxyExtensions.kt
│ │ └── EpoxyModelWithLayout.kt
│ └── res
│ └── values
│ └── ids.xml
├── epoxy2
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── io
│ └── github
│ └── ackeecz
│ └── extensions
│ └── epoxy2
│ └── EpoxyModelWithViewBinding.kt
├── gradle.properties
├── gradle
├── mavencentral
│ └── publish.gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── lib.properties
├── picasso
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── io
│ └── github
│ └── ackeecz
│ └── extensions
│ └── picasso
│ └── PicassoExtensions.kt
├── rxjava2
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── io
│ └── github
│ └── ackeecz
│ └── extensions
│ └── rxjava2
│ ├── Disposables.kt
│ └── Schedulers.kt
└── settings.gradle
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish
2 |
3 | on:
4 | push:
5 | tags:
6 | - '*'
7 |
8 | jobs:
9 | build:
10 | name: Release build and publish
11 | runs-on: ubuntu-latest
12 | steps:
13 | - name: Check out code
14 | uses: actions/checkout@v2
15 | with:
16 | fetch-depth: 20
17 | - name: Fetch Git tags
18 | run: |
19 | git fetch --prune --unshallow --tags
20 | - name: Set up JDK 1.8
21 | uses: actions/setup-java@v1
22 | with:
23 | java-version: 1.8
24 | # Base64 decodes and pipes the GPG key content into the secret file
25 | - name: Prepare environment
26 | env:
27 | GPG_KEY: ${{ secrets.ANDROID_GPG_KEY }}
28 | SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.ANDROID_SECRET_RING_FILE }}
29 | run: |
30 | sudo bash -c "echo '$GPG_KEY' | base64 -d > '$SIGNING_SECRET_KEY_RING_FILE'"
31 |
32 | - name: Grant execute permission for gradlew
33 | run: chmod +x gradlew
34 | - name: Assemble
35 | run: ./gradlew assemble
36 | - name: Publish to Maven Central
37 | run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseRepository
38 | env:
39 | OSSRH_USERNAME: ${{ secrets.ANDROID_OSSRH_USERNAME }}
40 | OSSRH_PASSWORD: ${{ secrets.ANDROID_OSSRH_PASSWORD }}
41 | SIGNING_KEY_ID: ${{ secrets.ANDROID_SIGNING_KEY_ID }}
42 | SIGNING_PASSWORD: ${{ secrets.ANDROID_SIGNING_PASSWORD }}
43 | SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.ANDROID_SECRET_RING_FILE }}
44 | SONATYPE_STAGING_PROFILE_ID: ${{ secrets.ANDROID_SONATYPE_STAGING_ID }}
45 | - name: Prepare Slack notification message
46 | id: prepare_slack_message
47 | run: |
48 | wget https://raw.githubusercontent.com/AckeeCZ/android-github-actions-scripts/master/slack/prepare_slack_msg.sh
49 | chmod u+x prepare_slack_msg.sh
50 | ./prepare_slack_msg.sh
51 | - name: Send Slack notification
52 | uses: rtCamp/action-slack-notify@v2
53 | if: ${{ job.status == 'success' }}
54 | env:
55 | SLACK_WEBHOOK: ${{ secrets.ANDROID_OSS_NOTIFICATION_WEBHOOK }}
56 | SLACK_USERNAME: 'github-snitch'
57 | SLACK_ICON_EMOJI: ':octocat:'
58 | SLACK_TITLE: ${{ steps.prepare_slack_message.outputs.SLACK_MSG_TITLE }}
59 | SLACK_MESSAGE: ${{ steps.prepare_slack_message.outputs.SLACK_MSG }}
60 | MSG_MINIMAL: true
61 |
62 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .idea/
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/CHANGELOG.MD:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | ## [3.1.0] - 2023-06-14
4 | ### Changed
5 | - Upgrade dependencies (for AndroidX)
6 | - Remove Jetifier
7 |
8 |
9 | ## **2.0.3**
10 | - Update Epoxy dependency to 4.6.3
11 |
12 | ## **2.0.2**
13 | - Add support for `unbind` in `EpoxyModelWithViewBinding`
14 |
15 | ## **2.0.1**
16 | - Fix proguard rules in `anko` module which were not changed after package name changes in `2.0.0`
17 |
18 | ## **2.0.0**
19 | - ‼ Breaking changes ahead ‼
20 | - Change package name of a libraries. It follows the groupId defined in 1.5.0. New package name is `io.github.ackeecz.extensions.$libraryName`
21 | - Removed deprecated code
22 | - Removed recyclerview and viewmodel libraries because there are far better alternatives through androidx libraries.
23 | - Added more docs
24 |
25 | ## **1.5.0**
26 | - Migration from jCenter to Maven Central 🎉
27 | - ‼️ Important ‼️ groupId and artifactId has changed. New groupId is `io.github.ackeecz` and artifact ids now have a prefix `extensions`. See README.MD
28 |
29 | ## 1.4.1
30 | - Tweak luminance threshold in the ripple color formula for `backgroundDrawable`
31 |
32 | ## 1.4.0
33 | - Add `epoxy2` module that does not have a dependency on Anko. This module now contains EpoxyModelWithViewBinding.
34 |
35 | ## 1.3.2
36 | - Add `openPlayStore` extension on `Context` and `Fragment`
37 |
38 | ## 1.3.1
39 | - Deprecate `Drawable.toBitmap`, `View.visible` and `View.asBitmap` in favor of the Core KTX extensions
40 | - Add check for dark mode with `Context.isDarkModeOn` and `View.isDarkModeOn`
41 | - Adjust `backgroundDrawable` to calculate default ripple color based on luminance of the normal color
42 |
43 | ## 1.3.0
44 | - Add `focused` state to `backgroundDrawable` extension
45 | - Move `Drawable.toBitmap` function to `DrawableExtensions`
46 | - Create `onThrottledClick` extension which prevents the view to be clicked on again for a small time interval
47 |
48 | ## 1.2.0
49 | - Rename extensions `drawableLeft` (Right, Top, Bottom) to `drawableLeftResource` and corresponding variants
50 | - Add extensions `drawableLeft` (Right, Top, Bottom) which are using Drawable as input parameter
51 |
52 | ## 1.1.1
53 | - Use darker color for pressed state in buttonDrawable function
54 |
55 | ## 1.1.0
56 | - AndroidX support
57 |
58 | ## 1.0.10
59 | - Added proguard rules to `anko` module.
60 | - Deprecated `CompositeDisposable.plus` in favor of RxKotlin library extension
61 | - Added Drawable extensions
62 |
63 | ## 1.0.9
64 | - Add `EpoxyModelWithLayout` - Epoxy Model with view contained in `ViewLayout`
65 |
66 | ## 1.0.8
67 | - Add `ViewLayout` - class representation of layout created with anko, extensions for creating such layout.
68 |
69 | ## 1.0.7
70 | - Deprecated `colorWithAlpha` in favor of `colorWithOpacity` to match better naming
71 | - Add extension `Int.withOpacity` method to use opacity in percentage directly on Int color
72 |
73 | ## 1.0.4, 1.0.5, 1.0.6
74 | - Service update when migrating from internal GitLab to GitHub
75 |
76 | ## 1.0.3
77 | - Little code clean in RxExtensions
78 | - Add extensions for Schedulers to Flowable type
79 |
80 | ## 1.0.2
81 | - Add conversion from Drawable to Bitmap via Drawable.toBitmap() function
82 | - Add conversion between Int and Boolean
83 |
84 | ## 1.0.1
85 | - Add color and colorWithAlpha extensions for Fragment
86 |
87 | ## 1.0.0
88 | - 🎉 Update to 1.0.0 version 💪
89 | - Add extensions to ViewModels - shortcut for providing ViewModels in Fragments/Activities
90 | - Breaking Changes - methods returning Drawables are now nullables to comply with the new support library
91 |
92 | ## 0.1.9
93 | - Add extensions (one) for Epoxy
94 |
95 | ## 0.1.8
96 | - Add Extension function operator for CompositeDisposable so you can call
97 | ```
98 | disposables += viewmodel.observeSomething().subscribe()
99 | ```
100 |
101 | ## 0.1.7
102 | - Add extensions for tinting drawables and retrieving colors list
103 | - Add CardView with its own lparams. Fixes issue with ClassCastException
104 |
105 | ## 0.1.6
106 | - Finally attached sources
107 |
108 | ## 0.1.5
109 | - Remove dimen() extension on context/view
110 |
111 | ## 0.1.4
112 | - Add subscribeOn*/observeOnMainThread extensnions for Completable, Maybe and Single
113 |
114 | ## 0.1.3
115 | - Add optinal attribute to Context.statusbarHeight for restricting size resolving to Lollipop and higher
116 |
117 | ## 0.1.2
118 | - Add `ViewGroup.inflate` method to Android Extensions
119 |
120 | ## 0.1.1
121 | - Add `ViewGroup.ankoContext` property to Anko extensions
122 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [ ](https://maven-badges.herokuapp.com/maven-central/io.github.ackeecz/extensions-android)
2 |
3 | # Android Kotlin Extensions
4 |
5 | ## Purpose of library
6 | This library serves as a collection of various Kotlin extensions that simplifies developers life. All of our Kotlin projects had its own extensions and in most cases they've done the same but had different names, syntax etc. This project tries to unify that problem with clear separation of extensions based on its dependencies.
7 |
8 | All extensions are collected from projects that are based on Kotlin/Anko
9 |
10 | ## Structure
11 | Extensions are grouped to submodules that have the same dependency. So for example if extensions have dependency to RxJava they are in separate module.
12 |
13 | All modules has the same version. Current version is in `lib.properties` file and can be seen in the badge above.
14 |
15 | ### Android Extensions
16 | Extensions to core Android Framework and some Support Library classes like Fragment.
17 |
18 | ```
19 | compile "io.github.ackeecz:extensions-android:x.x.x"
20 | ```
21 |
22 | ### Anko Extensions
23 | Extensions to Anko DSL library. Basically this adds only easier support to DSL with components that are not included in Anko.
24 |
25 | ```
26 | compile "io.github.ackeecz:extensions-anko:x.x.x"
27 | ```
28 |
29 | ### Picasso Extensions
30 | Extensions dependent on Picasso. Contains async loading of URL to ImageView
31 |
32 | ```
33 | compile "io.github.ackeecz:extensions-picasso:x.x.x"
34 | ```
35 |
36 | ### RxJava2 Extensions
37 | Extensions to RxJava2 with easier subscribing/observing on particular threads and safe disposing of observables.
38 |
39 | ```
40 | compile "io.github.ackeecz:extensions-rxjava2:x.x.x"
41 | ```
42 |
43 | ### Epoxy Extensions
44 | Extensions to Epoxy and base epoxy model.
45 | @Deprecated due to its dependency on Anko. Use epoxy2 on projects without Anko.
46 |
47 | ```
48 | compile "io.github.ackeecz:extensions-epoxy:x.x.x"
49 | ```
50 |
51 | ### Epoxy 2 Extensions
52 | Epoxy extensions without dependency on Anko.
53 |
54 | ```
55 | compile "io.github.ackeecz:extensions-epoxy2:x.x.x"
56 | ```
57 |
58 | ## License
59 | Copyright 2021 Ackee, s.r.o.
60 |
61 | Licensed under the Apache License, Version 2.0 (the "License");
62 | you may not use this file except in compliance with the License.
63 | You may obtain a copy of the License at
64 |
65 | http://www.apache.org/licenses/LICENSE-2.0
66 |
67 | Unless required by applicable law or agreed to in writing, software
68 | distributed under the License is distributed on an "AS IS" BASIS,
69 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
70 | See the License for the specific language governing permissions and
71 | limitations under the License.
72 |
73 |
--------------------------------------------------------------------------------
/android/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion Integer.parseInt(buildProperties["SDK_VERSION"])
6 |
7 | defaultConfig {
8 | minSdkVersion Integer.parseInt(buildProperties["MIN_SDK_VERSION"])
9 | targetSdkVersion Integer.parseInt(buildProperties["SDK_VERSION"])
10 | versionCode = libProperties['VERSION_CODE']
11 | versionName libProperties['VERSION_NAME']
12 |
13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
26 | implementation 'androidx.appcompat:appcompat:1.2.0'
27 | }
28 |
29 | ext {
30 | PUBLISH_ARTIFACT_ID = 'extensions-android'
31 | POM_DESCRIPTION = 'Kotlin extensions for Android framework'
32 | }
33 |
34 | apply from: "${rootProject.projectDir}/gradle/mavencentral/publish.gradle"
35 |
--------------------------------------------------------------------------------
/android/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/billda/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/android/src/main/java/io/github/ackeecz/extensions/android/CollectionsExtensions.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.android
2 |
3 |
4 | // Extensions to collections
5 |
6 | /**
7 | * Check if this collection is null or empty
8 | */
9 | fun Collection<*>?.isNullOrEmpty(): Boolean {
10 | return this == null || this.isEmpty()
11 | }
12 |
--------------------------------------------------------------------------------
/android/src/main/java/io/github/ackeecz/extensions/android/Common.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.android
2 |
3 | import android.graphics.Color
4 | import androidx.annotation.ColorInt
5 | import androidx.annotation.IntRange
6 | import java.util.Date
7 |
8 | // Useful functions not related to any class
9 |
10 | fun now() = Date()
11 |
12 | fun nowMillis() = System.currentTimeMillis()
13 |
14 | fun Int.toBoolean() = this > 0
15 |
16 | fun Boolean.toInt() = if (this) 1 else 0
17 |
18 | /**
19 | * Assume that this Int is a color and apply [opacity] to it.
20 | */
21 | @ColorInt
22 | fun Int.withOpacity(@IntRange(from = 0, to = 100) opacity: Int): Int {
23 | return Color.argb((opacity / 100f * 255).toInt(), Color.red(this), Color.green(this), Color.blue(this))
24 | }
25 |
--------------------------------------------------------------------------------
/android/src/main/java/io/github/ackeecz/extensions/android/ContextExtensions.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.android
2 |
3 | import android.content.Context
4 | import android.content.Intent
5 | import android.content.res.ColorStateList
6 | import android.content.res.Configuration
7 | import android.graphics.Point
8 | import android.graphics.drawable.Drawable
9 | import android.net.Uri
10 | import android.os.Build
11 | import android.util.TypedValue
12 | import android.view.LayoutInflater
13 | import android.view.ViewGroup
14 | import android.view.WindowManager
15 | import androidx.annotation.ColorInt
16 | import androidx.annotation.ColorRes
17 | import androidx.annotation.DrawableRes
18 | import androidx.annotation.IntRange
19 | import androidx.annotation.LayoutRes
20 | import androidx.annotation.StringRes
21 | import androidx.core.content.ContextCompat
22 | import androidx.core.graphics.drawable.DrawableCompat
23 |
24 | // Extensions to context class
25 |
26 | @ColorInt
27 | fun Context.color(@ColorRes res: Int): Int {
28 | return ContextCompat.getColor(this, res)
29 | }
30 |
31 | fun Context.drawable(@DrawableRes res: Int): Drawable? {
32 | return ContextCompat.getDrawable(this, res)
33 | }
34 |
35 | fun Context.tintedDrawable(@DrawableRes drawableId: Int, @ColorRes colorId: Int): Drawable? {
36 | val tint: Int = color(colorId)
37 | val drawable = drawable(drawableId)
38 | drawable?.mutate()
39 | drawable?.let {
40 | it.mutate()
41 | DrawableCompat.setTint(it, tint)
42 | }
43 | return drawable
44 | }
45 |
46 | fun Context.string(@StringRes res: Int): String {
47 | return getString(res)
48 | }
49 |
50 | /**
51 | * Get color from resources with applied [opacity]
52 | */
53 | @ColorInt
54 | fun Context.colorWithOpacity(@ColorRes res: Int, @IntRange(from = 0, to = 100) opacity: Int): Int {
55 | return color(res).withOpacity(opacity)
56 | }
57 |
58 | fun Context.colors(@ColorRes stateListRes: Int): ColorStateList? {
59 | return ContextCompat.getColorStateList(this, stateListRes)
60 | }
61 |
62 | internal fun Context.attribute(value: Int): TypedValue {
63 | val ret = TypedValue()
64 | theme.resolveAttribute(value, ret, true)
65 | return ret
66 | }
67 |
68 | /**
69 | * Get dimension defined by attribute [attr]
70 | */
71 | fun Context.attrDimen(attr: Int): Int {
72 | return TypedValue.complexToDimensionPixelSize(attribute(attr).data, resources.displayMetrics)
73 | }
74 |
75 | /**
76 | * Get drawable defined by attribute [attr]
77 | */
78 | fun Context.attrDrawable(attr: Int): Drawable? {
79 | val a = theme.obtainStyledAttributes(intArrayOf(attr))
80 | val attributeResourceId = a.getResourceId(0, 0)
81 | a.recycle()
82 | return drawable(attributeResourceId)
83 | }
84 |
85 | /**
86 | * Inflater layout defined by [res] into view group [parent]. Optionaly attach view to parent with [attachView] attribute
87 | */
88 | fun Context.inflate(@LayoutRes res: Int, parent: ViewGroup, attachView: Boolean = true) {
89 | LayoutInflater.from(this).inflate(res, parent, attachView)
90 | }
91 |
92 | /**
93 | * Get screen width
94 | */
95 | fun Context.screenWidth(): Int {
96 | return getDisplaySize().x
97 | }
98 |
99 | /**
100 | * Get screen height
101 | */
102 | fun Context.screenHeight(): Int {
103 | return getDisplaySize().y
104 | }
105 |
106 | /**
107 | * Get status bar height
108 | * @param restrictToLollipop indicator if status bar height resource should be lookup only on versions higher than Lollipop
109 | */
110 | fun Context.statusBarHeight(restrictToLollipop: Boolean = true): Int {
111 | var result = 0
112 | val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
113 | if (resourceId > 0 && (!restrictToLollipop || (restrictToLollipop && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP))) {
114 | result = resources.getDimensionPixelSize(resourceId)
115 | }
116 | return result
117 | }
118 |
119 | /**
120 | * Get whether dark mode is enabled or not
121 | */
122 | fun Context.isDarkModeOn(): Boolean {
123 | val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
124 | return currentNightMode == Configuration.UI_MODE_NIGHT_YES
125 | }
126 |
127 | /**
128 | * Open Play Store with the application ID from provided context. Return true if the intent can be
129 | * and will be handled, false otherwise.
130 | */
131 | fun Context.openPlayStore(): Boolean {
132 | val intent = Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageName"))
133 | val availableActivities = packageManager.queryIntentActivities(intent, 0);
134 |
135 | return if (availableActivities.isNotEmpty()) {
136 | startActivity(intent)
137 | true
138 | } else {
139 | false
140 | }
141 | }
142 |
143 | private fun Context.getDisplaySize(): Point {
144 | val display = (getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay
145 | val size = Point()
146 | display.getSize(size)
147 |
148 | return size
149 | }
150 |
--------------------------------------------------------------------------------
/android/src/main/java/io/github/ackeecz/extensions/android/DrawableExtensions.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.android
2 |
3 | import android.content.res.ColorStateList
4 | import android.graphics.Color
5 | import android.graphics.drawable.Drawable
6 | import android.graphics.drawable.GradientDrawable
7 | import android.graphics.drawable.RippleDrawable
8 | import android.graphics.drawable.StateListDrawable
9 | import androidx.annotation.ColorInt
10 | import androidx.core.graphics.ColorUtils
11 |
12 | // Extensions for creating drawables and other drawable-related helpers
13 |
14 | /**
15 | * Create a drawable programmatically with optional properties. When [isButton] defined as
16 | * true result is a drawable with ripple effect.
17 | *
18 | * @param color - color of a drawable
19 | * @param isButton - wheter drawable should respond to pressed state
20 | * @param checkedColor - color of checked state
21 | * @param pressedColor - color of pressed state
22 | * @param focusedColor - color of focused state
23 | * @param disabledColor - color of a disabled state
24 | * @param mask - mask drawable applied on a result ripple drawable.
25 | * @param radius - corner radius in px
26 | * @param strokeColor - color of a stroke effect
27 | * @param strokeWidth - width of a stroke effect
28 | * @param topLeftRadius - top left corner radius
29 | * @param topRightRadius - top right corner radius
30 | * @param bottomLeftRadius - bottom left corner radius
31 | * @param bottomRightRadius - bottom right corner radius
32 | */
33 | fun backgroundDrawable(
34 | @ColorInt color: Int,
35 | isButton: Boolean = false,
36 | @ColorInt checkedColor: Int = color,
37 | @ColorInt pressedColor: Int = color.toPressedColor(),
38 | @ColorInt focusedColor: Int = color,
39 | @ColorInt disabledColor: Int = color,
40 | mask: Drawable? = null,
41 | radius: Number = 0f,
42 | strokeColor: Int = Color.TRANSPARENT,
43 | strokeWidth: Int = 0,
44 | topLeftRadius: Number = 0f,
45 | topRightRadius: Number = 0f,
46 | bottomLeftRadius: Number = 0f,
47 | bottomRightRadius: Number = 0f
48 | ): Drawable {
49 | val baseDrawable = StateListDrawable().apply {
50 | addState(intArrayOf(-android.R.attr.state_enabled), GradientDrawable().apply {
51 | setCornerRadius(radius, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius)
52 | setColor(disabledColor)
53 | setStroke(strokeWidth, strokeColor)
54 | })
55 | addState(intArrayOf(android.R.attr.state_focused), GradientDrawable().apply {
56 | setCornerRadius(radius, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius)
57 | setColor(focusedColor)
58 | setStroke(strokeWidth, strokeColor)
59 | })
60 | addState(intArrayOf(android.R.attr.state_checked), GradientDrawable().apply {
61 | setCornerRadius(radius, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius)
62 | setColor(checkedColor)
63 | setStroke(strokeWidth, strokeColor)
64 | })
65 | addState(intArrayOf(), GradientDrawable().apply {
66 | setCornerRadius(radius, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius)
67 | setColor(color)
68 | setStroke(strokeWidth, strokeColor)
69 | })
70 | }
71 |
72 | if (!isButton) return baseDrawable
73 |
74 | // set pressed state only if isButton = true
75 | return RippleDrawable(ColorStateList.valueOf(pressedColor), baseDrawable, mask)
76 | }
77 |
78 | private fun Int.toPressedColor(): Int {
79 | return if (isDarkColor(this)) {
80 | toLighterColor()
81 | } else {
82 | toDarkerColor()
83 | }
84 | }
85 |
86 | private fun isDarkColor(color: Int): Boolean {
87 | return ColorUtils.calculateLuminance(color) < 0.15
88 | }
89 |
90 | /**
91 | * Convert color to lighter shade
92 | */
93 | fun Int.toLighterColor(): Int {
94 | val hsv = floatArrayOf(0f, 0f, 0f)
95 | Color.colorToHSV(this, hsv)
96 | hsv[2] = 0.2f + 0.8f * hsv[2];
97 | return Color.HSVToColor(hsv)
98 | }
99 |
100 | /**
101 | * Convert color to darker shade
102 | */
103 | fun Int.toDarkerColor(): Int {
104 | val hsv = floatArrayOf(0f, 0f, 0f)
105 | Color.colorToHSV(this, hsv)
106 | hsv[2] *= 0.8f
107 | return Color.HSVToColor(hsv)
108 | }
109 |
110 | private fun GradientDrawable.setCornerRadius(
111 | radius: Number,
112 | topLeftRadius: Number = 0f,
113 | topRightRadius: Number = 0f,
114 | bottomLeftRadius: Number = 0f,
115 | bottomRightRadius: Number = 0f
116 | ) {
117 | if (radius != 0f) {
118 | cornerRadius = radius.toFloat()
119 | } else {
120 | cornerRadii = floatArrayOf(
121 | topLeftRadius.toFloat(), topLeftRadius.toFloat(),
122 | topRightRadius.toFloat(), topRightRadius.toFloat(),
123 | bottomRightRadius.toFloat(), bottomRightRadius.toFloat(),
124 | bottomLeftRadius.toFloat(), bottomLeftRadius.toFloat()
125 | )
126 | }
127 | }
128 |
129 | /**
130 | * Create a [ColorStateList] programmatically
131 | */
132 | fun colorStateList(
133 | @ColorInt normalColor: Int,
134 | @ColorInt checkedColor: Int? = null,
135 | @ColorInt selectedColor: Int? = null,
136 | @ColorInt disabledColor: Int? = null,
137 | @ColorInt pressedColor: Int? = null,
138 | @ColorInt focusedColor: Int? = null
139 | ): ColorStateList {
140 | val states = mapOf(
141 | intArrayOf(-android.R.attr.state_enabled) to disabledColor,
142 | intArrayOf(android.R.attr.state_pressed) to pressedColor,
143 | intArrayOf(android.R.attr.state_checked) to checkedColor,
144 | intArrayOf(android.R.attr.state_selected) to selectedColor,
145 | intArrayOf(android.R.attr.state_focused) to focusedColor,
146 | intArrayOf() to normalColor
147 | ).filterValues { it != null }
148 | return ColorStateList(states.keys.toTypedArray(), states.values.map { it!!.toInt() }.toIntArray())
149 | }
150 |
--------------------------------------------------------------------------------
/android/src/main/java/io/github/ackeecz/extensions/android/FragmentExtensions.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.android
2 |
3 | import android.os.Bundle
4 | import androidx.annotation.ColorInt
5 | import androidx.annotation.ColorRes
6 | import androidx.annotation.IntRange
7 | import androidx.fragment.app.Fragment
8 |
9 | // Extensions for [Fragment] class
10 |
11 | /**
12 | * Set arguments to fragment and return current instance
13 | */
14 | inline fun T.withArguments(args: Bundle): T {
15 | this.arguments = args
16 | return this
17 | }
18 |
19 | /**
20 | * Set target fragment with request code and return current instance
21 | */
22 | fun Fragment.withTargetFragment(fragment: Fragment, reqCode: Int): Fragment {
23 | setTargetFragment(fragment, reqCode)
24 | return this
25 | }
26 |
27 | /**
28 | * Get color from resource with fragment context.
29 | */
30 | fun Fragment.color(@ColorRes res: Int) = context!!.color(res)
31 |
32 |
33 | /**
34 | * Get color from resource with fragment context and apply [opacity] to it.
35 | */
36 | @ColorInt
37 | fun Fragment.colorWithOpacity(@ColorRes res: Int, @IntRange(from = 0, to = 100) opacity: Int) = context!!.colorWithOpacity(res, opacity)
38 |
39 | /**
40 | * Open Play Store with the application ID from provided context. Return true if the intent can be
41 | * and will be handled, false otherwise.
42 | */
43 | fun Fragment.openPlayStore() = requireContext().openPlayStore()
44 |
--------------------------------------------------------------------------------
/android/src/main/java/io/github/ackeecz/extensions/android/SpannableExtensions.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.android
2 |
3 | import android.text.Spannable
4 | import android.text.style.StyleSpan
5 | import androidx.annotation.StyleRes
6 |
7 | // Extensions for [Spannable]
8 |
9 | /**
10 | * Highlight substring [query] in this spannable with custom [style]. All occurrences of this substring
11 | * are stylized
12 | */
13 | fun Spannable.highlightSubstring(query: String, @StyleRes style: Int): Spannable {
14 | val spannable = Spannable.Factory.getInstance().newSpannable(this)
15 | val substrings = query.toLowerCase().split("\\s+".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
16 | var lastIndex = 0
17 | for (i in substrings.indices) {
18 | do {
19 | lastIndex = this.toString().toLowerCase().indexOf(substrings[i], lastIndex)
20 | if (lastIndex != -1) {
21 | spannable.setSpan(StyleSpan(style), lastIndex, lastIndex + substrings[i].length, Spannable.SPAN_EXCLUSIVE_INCLUSIVE)
22 | lastIndex++
23 | }
24 | } while (lastIndex != -1)
25 | }
26 | return spannable
27 | }
28 |
--------------------------------------------------------------------------------
/android/src/main/java/io/github/ackeecz/extensions/android/StringExtensions.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.android
2 |
3 | import java.text.Normalizer
4 |
5 | // Extensions for String class
6 |
7 | /**
8 | * Normalize string - convert to lowercase, replace diacritics and trim trailing whitespaces
9 | */
10 | fun String.normalize(): String {
11 | return Normalizer.normalize(toLowerCase(), Normalizer.Form.NFD)
12 | .replace("[\\p{InCombiningDiacriticalMarks}]".toRegex(), "").trim()
13 | }
14 |
--------------------------------------------------------------------------------
/android/src/main/java/io/github/ackeecz/extensions/android/ViewExtensions.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.android
2 |
3 | import android.content.Context
4 | import android.content.res.ColorStateList
5 | import android.graphics.drawable.Drawable
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import android.view.inputmethod.InputMethodManager
9 | import android.widget.TextView
10 | import androidx.annotation.ColorInt
11 | import androidx.annotation.ColorRes
12 | import androidx.annotation.DrawableRes
13 | import androidx.annotation.IntRange
14 | import androidx.annotation.LayoutRes
15 | import androidx.annotation.StringRes
16 |
17 | // Extensions for [View] class
18 |
19 | fun View.hideIme() {
20 | val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
21 | imm.hideSoftInputFromWindow(windowToken, 0)
22 | }
23 |
24 | @ColorInt
25 | fun View.color(@ColorRes res: Int): Int {
26 | return context.color(res)
27 | }
28 |
29 | fun View.drawable(@DrawableRes res: Int): Drawable? {
30 | return context.drawable(res)
31 | }
32 |
33 | fun View.tintedDrawable(@DrawableRes drawableId: Int, @ColorRes colorId: Int): Drawable? {
34 | return context.tintedDrawable(drawableId, colorId)
35 | }
36 |
37 | fun View.string(@StringRes res: Int): String {
38 | return context.string(res)
39 | }
40 |
41 | /**
42 | * Get color from resources with applied [opacity]
43 | */
44 | @ColorInt
45 | fun View.colorWithOpacity(@ColorRes res: Int, @IntRange(from = 0, to = 100) opacity: Int): Int {
46 | return context.colorWithOpacity(res, opacity)
47 | }
48 |
49 | /**
50 | * Get color state list from resources
51 | */
52 | fun View.colors(@ColorRes stateListRes: Int): ColorStateList? {
53 | return context.colors(stateListRes)
54 | }
55 |
56 | /**
57 | * Get dimension defined by attribute [attr]
58 | */
59 | fun View.attrDimen(attr: Int): Int {
60 | return context.attrDimen(attr)
61 | }
62 |
63 | /**
64 | * Get whether dark mode is enabled or not
65 | */
66 | fun View.isDarkModeOn(): Boolean {
67 | return context.isDarkModeOn()
68 | }
69 |
70 | /**
71 | * Get drawable defined by attribute [attr]
72 | */
73 | fun View.attrDrawable(attr: Int): Drawable? {
74 | return context.attrDrawable(attr)
75 | }
76 |
77 | /**
78 | * View artificial attribute that sets compound left drawable resource
79 | */
80 | var TextView.drawableLeftResource: Int
81 | get() = throw IllegalAccessException("Property drawableLeftResource only as setter")
82 | set(value) {
83 | drawableLeft = context.drawable(value)
84 | }
85 |
86 | /**
87 | * View artificial attribute that sets compound right drawable resource
88 | */
89 | var TextView.drawableRightResource: Int
90 | get() = throw IllegalAccessException("Property drawableRightResource only as setter")
91 | set(value) {
92 | drawableRight = context.drawable(value)
93 | }
94 |
95 | /**
96 | * View artificial attribute that sets compound top drawable resource
97 | */
98 | var TextView.drawableTopResource: Int
99 | get() = throw IllegalAccessException("Property drawableTopResource only as setter")
100 | set(value) {
101 | drawableTop = context.drawable(value)
102 | }
103 |
104 | /**
105 | * View artificial attribute that sets compound bottom drawable resource
106 | */
107 | var TextView.drawableBottomResource: Int
108 | get() = throw IllegalAccessException("Property drawableBottomResource only as setter")
109 | set(value) {
110 | drawableBottom = context.drawable(value)
111 | }
112 |
113 | /**
114 | * View artificial attribute that sets compound left drawable
115 | */
116 | var TextView.drawableLeft: Drawable?
117 | get() = throw IllegalAccessException("Property drawableLeft only as setter")
118 | set(value) {
119 | val drawables = compoundDrawables
120 | setCompoundDrawablesWithIntrinsicBounds(value, drawables[1], drawables[2], drawables[3])
121 | }
122 |
123 | /**
124 | * View artificial attribute that sets compound right drawable
125 | */
126 | var TextView.drawableRight: Drawable?
127 | get() = throw IllegalAccessException("Property drawableRight only as setter")
128 | set(value) {
129 | val drawables = compoundDrawables
130 | setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], value, drawables[3])
131 | }
132 |
133 | /**
134 | * View artificial attribute that sets compound top drawable
135 | */
136 | var TextView.drawableTop: Drawable?
137 | get() = throw IllegalAccessException("Property drawableTop only as setter")
138 | set(value) {
139 | val drawables = compoundDrawables
140 | setCompoundDrawablesWithIntrinsicBounds(drawables[0], value, drawables[2], drawables[3])
141 | }
142 |
143 | /**
144 | * View artificial attribute that sets compound bottom drawable
145 | */
146 | var TextView.drawableBottom: Drawable?
147 | get() = throw IllegalAccessException("Property drawableBottom only as setter")
148 | set(value) {
149 | val drawables = compoundDrawables
150 | setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], drawables[2], value)
151 | }
152 |
153 | /**
154 | * Inflate [layout] into this ViewGroup
155 | */
156 | fun ViewGroup.inflate(@LayoutRes layout: Int, attachToParent: Boolean = true) {
157 | return context.inflate(layout, this, attachToParent)
158 | }
159 |
160 | const val CLICK_THROTTLE_DELAY = 200L
161 |
162 | /**
163 | * Set a callback on a view that responds to a click events. It throttles clicks
164 | * so rapid burst of clicks does not emit multiple callback calls.
165 | *
166 | * @param throttleDelay - optional delay in milliseconds between clicks
167 | */
168 | fun View.onThrottledClick(
169 | throttleDelay: Long = CLICK_THROTTLE_DELAY,
170 | onClick: (View) -> Unit
171 | ) {
172 | setOnClickListener {
173 | onClick(this)
174 | isClickable = false
175 | postDelayed({ isClickable = true }, throttleDelay)
176 | }
177 | }
178 |
--------------------------------------------------------------------------------
/anko/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/anko/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion Integer.parseInt(buildProperties["SDK_VERSION"])
6 |
7 | defaultConfig {
8 | minSdkVersion Integer.parseInt(buildProperties["MIN_SDK_VERSION"])
9 | targetSdkVersion Integer.parseInt(buildProperties["SDK_VERSION"])
10 | versionCode = libProperties['VERSION_CODE']
11 | versionName libProperties['VERSION_NAME']
12 |
13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14 | consumerProguardFiles 'consumer-proguard-rules.txt'
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | def ankoVersion = "0.10.8"
27 |
28 | implementation "org.jetbrains.anko:anko-sdk15:$ankoVersion"
29 | implementation "org.jetbrains.anko:anko-appcompat-v7:$ankoVersion"
30 | implementation "org.jetbrains.anko:anko-design:$ankoVersion"
31 | implementation "org.jetbrains.anko:anko-recyclerview-v7:$ankoVersion"
32 |
33 | implementation "com.google.android.material:material:1.3.0"
34 | implementation "androidx.cardview:cardview:1.0.0"
35 | }
36 |
37 | ext {
38 | PUBLISH_ARTIFACT_ID = 'extensions-anko'
39 | POM_DESCRIPTION = 'Kotlin extensions for Anko library'
40 | }
41 |
42 | apply from: "${rootProject.projectDir}/gradle/mavencentral/publish.gradle"
43 |
--------------------------------------------------------------------------------
/anko/consumer-proguard-rules.txt:
--------------------------------------------------------------------------------
1 | -keepclassmembers public class * extends io.github.ackeecz.extensions.anko.layout.ViewLayout {
2 | public (...);
3 | }
4 |
--------------------------------------------------------------------------------
/anko/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/billda/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/anko/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/anko/src/main/java/io/github/ackeecz/extensions/anko/AnkoExtensions.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.anko
2 |
3 | import android.content.Context
4 | import android.view.View
5 | import android.view.ViewGroup
6 | import android.view.ViewManager
7 | import androidx.cardview.widget.CardView
8 | import com.google.android.material.textfield.TextInputEditText
9 | import org.jetbrains.anko.AnkoContext
10 | import org.jetbrains.anko.custom.ankoView
11 |
12 | // Extensions to Anko DSL
13 |
14 | /**
15 | * Anko extensions for [TextInputEditText]
16 | */
17 | inline fun ViewManager.textInputEditText() = textInputEditText {}
18 |
19 | inline fun ViewManager.textInputEditText(theme: Int = 0, init: TextInputEditText.() -> Unit) = ankoView(::TextInputEditText, theme, init)
20 |
21 | /**
22 | * Get Anko context from view group
23 | */
24 | val ViewGroup.ankoContext
25 | get() = AnkoContext.Companion.create(context, this)
26 |
27 | /**
28 | * Fixed cardView extension to Anko. CardView from Anko does not have lparams extensions
29 | * and crashes when defining some. This solution uses same lparams as FrameLayout
30 | */
31 | inline fun ViewManager.cardView(theme: Int = 0): CardView = cardView(theme) {}
32 |
33 | inline fun ViewManager.cardView(theme: Int = 0, init: _CardView.() -> Unit): CardView {
34 | return ankoView(::_CardView, theme, init)
35 | }
36 |
37 | open class _CardView(ctx: Context) : CardView(ctx) {
38 | private val defaultInit: Any.() -> Unit = {}
39 |
40 | fun T.lparams(
41 | c: android.content.Context?,
42 | attrs: android.util.AttributeSet?,
43 | init: android.widget.FrameLayout.LayoutParams.() -> Unit = defaultInit
44 | ): T {
45 | val layoutParams = android.widget.FrameLayout.LayoutParams(c!!, attrs!!)
46 | layoutParams.init()
47 | this@lparams.layoutParams = layoutParams
48 | return this
49 | }
50 |
51 | fun T.lparams(
52 | width: Int = android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
53 | height: Int = android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
54 | init: android.widget.FrameLayout.LayoutParams.() -> Unit = defaultInit
55 | ): T {
56 | val layoutParams = android.widget.FrameLayout.LayoutParams(width, height)
57 | layoutParams.init()
58 | this@lparams.layoutParams = layoutParams
59 | return this
60 | }
61 |
62 | fun T.lparams(
63 | width: Int = android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
64 | height: Int = android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
65 | gravity: Int,
66 | init: android.widget.FrameLayout.LayoutParams.() -> Unit = defaultInit
67 | ): T {
68 | val layoutParams = android.widget.FrameLayout.LayoutParams(width, height, gravity)
69 | layoutParams.init()
70 | this@lparams.layoutParams = layoutParams
71 | return this
72 | }
73 |
74 | fun T.lparams(
75 | source: android.view.ViewGroup.LayoutParams?,
76 | init: android.widget.FrameLayout.LayoutParams.() -> Unit = defaultInit
77 | ): T {
78 | val layoutParams = android.widget.FrameLayout.LayoutParams(source!!)
79 | layoutParams.init()
80 | this@lparams.layoutParams = layoutParams
81 | return this
82 | }
83 |
84 | fun T.lparams(
85 | source: android.view.ViewGroup.MarginLayoutParams?,
86 | init: android.widget.FrameLayout.LayoutParams.() -> Unit = defaultInit
87 | ): T {
88 | val layoutParams = android.widget.FrameLayout.LayoutParams(source!!)
89 | layoutParams.init()
90 | this@lparams.layoutParams = layoutParams
91 | return this
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/anko/src/main/java/io/github/ackeecz/extensions/anko/layout/LayoutExtensions.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.anko.layout
2 |
3 | import android.app.Activity
4 | import android.content.Context
5 | import android.view.ViewGroup
6 | import android.view.ViewManager
7 | import org.jetbrains.anko.AnkoException
8 | import org.jetbrains.anko.internals.AnkoInternals
9 |
10 | /**
11 | * Automatically instantiates ViewLayout with no constructor parameter or single Context parameter
12 | * and adds the layout to the ViewManager's view hierarchy
13 | */
14 | inline fun ViewManager.customLayout(theme: Int = 0, init: T.() -> Unit = {}): T =
15 | ankoLayout({ ctx -> instantiateLayout(ctx, this as ViewGroup?, T::class.java) }, theme) { init() }
16 |
17 | inline fun Context.customLayout(theme: Int = 0, init: T.() -> Unit = {}): T =
18 | ankoLayout({ ctx -> instantiateLayout(ctx, null, T::class.java) }, theme) { init() }
19 |
20 | inline fun Activity.customLayout(theme: Int = 0, init: T.() -> Unit = {}): T =
21 | ankoLayout({ ctx -> instantiateLayout(ctx, this.window.decorView as ViewGroup?, T::class.java) }, theme) { init() }
22 |
23 | /**
24 | * Adds layout's view to ViewManager's view hierarchy and returns it. Useful only if the layout
25 | * has custom constructor and cannot be created with default [Context] parameter.
26 | */
27 | inline fun ViewManager.customLayout(layout: T, init: T.() -> Unit = {}): T {
28 | return layout.apply {
29 | view
30 | init()
31 | AnkoInternals.addView(this@customLayout, view)
32 | }
33 | }
34 |
35 | /**
36 | * Internal. Use [ViewManager.customLayout] instead.
37 | */
38 | inline fun ViewManager.ankoLayout(factory: (ctx: Context) -> T, theme: Int, init: T.() -> Unit): T {
39 | val ctx = AnkoInternals.wrapContextIfNeeded(AnkoInternals.getContext(this), theme)
40 | return factory(ctx).apply {
41 | view
42 | init()
43 | AnkoInternals.addView(this@ankoLayout, view)
44 | }
45 | }
46 |
47 | /**
48 | * Internal. Use [Context.customLayout] instead.
49 | */
50 | inline fun Context.ankoLayout(factory: (ctx: Context) -> T, theme: Int, init: T.() -> Unit): T {
51 | val ctx = AnkoInternals.wrapContextIfNeeded(this, theme)
52 | return factory(ctx).apply {
53 | view
54 | init()
55 | AnkoInternals.addView(this@ankoLayout, view)
56 | }
57 | }
58 |
59 | /**
60 | * Internal. Use [Activity.customLayout] instead.
61 | */
62 | inline fun Activity.ankoLayout(factory: (ctx: Context) -> T, theme: Int, init: T.() -> Unit): T {
63 | val ctx = AnkoInternals.wrapContextIfNeeded(this, theme)
64 | return factory(ctx).apply {
65 | view
66 | init()
67 | AnkoInternals.addView(this@ankoLayout, view)
68 | }
69 | }
70 |
71 | /**
72 | * Internal. Cannot be marked as private because it is used in other public inline methods.
73 | *
74 | * Instantiates a subclass of [ViewLayout].
75 | */
76 | fun instantiateLayout(ctx: Context, parent: ViewGroup?, layoutClass: Class): T {
77 | try {
78 | return layoutClass.getConstructor(Context::class.java).newInstance(ctx)
79 | } catch (e: NoSuchMethodException) {
80 | if (parent != null) {
81 | try {
82 | return layoutClass.getConstructor(ViewGroup::class.java).newInstance(parent)
83 | } catch (e: NoSuchMethodException) {
84 | }
85 | }
86 | }
87 | throw AnkoException("Can't initiate View of class ${layoutClass.name}: can't find proper constructor")
88 | }
89 |
--------------------------------------------------------------------------------
/anko/src/main/java/io/github/ackeecz/extensions/anko/layout/ViewLayout.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.anko.layout
2 |
3 | import android.content.Context
4 | import android.view.View
5 | import android.view.ViewGroup
6 | import org.jetbrains.anko.AnkoComponent
7 | import org.jetbrains.anko.AnkoContext
8 |
9 | /**
10 | * Class representing layout created with anko
11 | */
12 | abstract class ViewLayout(val context: Context) : AnkoComponent {
13 |
14 | constructor(parent: ViewGroup) : this(parent.context)
15 |
16 | val view: View by lazy { createView(AnkoContext.create(context)) }
17 |
18 | fun view(block: View.() -> Unit = {}) = view.apply(block)
19 | }
20 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.8.20'
5 |
6 | repositories {
7 | jcenter()
8 | google()
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:7.4.2'
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13 | classpath 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0'
14 | classpath "org.jetbrains.dokka:dokka-gradle-plugin:$kotlin_version"
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | jcenter()
21 | google()
22 | mavenLocal()
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
30 | /**
31 | * Define properties with build info
32 | */
33 | ext.buildProperties = new Properties()
34 | ext.buildProperties.load(file("${rootDir}/build.properties").newReader())
35 |
36 |
37 | /**
38 | * Define properties with library info
39 | */
40 | ext.libProperties = new Properties()
41 | ext.libProperties.load(file("${rootDir}/lib.properties").newReader())
42 |
43 | apply plugin: 'io.codearte.nexus-staging'
44 |
--------------------------------------------------------------------------------
/build.properties:
--------------------------------------------------------------------------------
1 | # build properties
2 | MIN_SDK_VERSION=21
3 | SDK_VERSION=31
4 |
--------------------------------------------------------------------------------
/epoxy/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/epoxy/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion Integer.parseInt(buildProperties["SDK_VERSION"])
6 |
7 | defaultConfig {
8 | minSdkVersion Integer.parseInt(buildProperties["MIN_SDK_VERSION"])
9 | targetSdkVersion Integer.parseInt(buildProperties["SDK_VERSION"])
10 | versionCode = libProperties['VERSION_CODE']
11 | versionName libProperties['VERSION_NAME']
12 |
13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
26 | implementation 'com.airbnb.android:epoxy:5.1.3'
27 | implementation "io.github.ackeecz:extensions-anko:2.0.3"
28 | implementation "org.jetbrains.anko:anko-sdk15:0.10.8"
29 | }
30 |
31 | ext {
32 | PUBLISH_ARTIFACT_ID = 'extensions-epoxy'
33 | POM_DESCRIPTION = 'Kotlin extensions for Epoxy library'
34 | }
35 |
36 | apply from: "${rootProject.projectDir}/gradle/mavencentral/publish.gradle"
37 |
--------------------------------------------------------------------------------
/epoxy/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/billda/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/epoxy/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/epoxy/src/main/java/io/github/ackeecz/extensions/epoxy/EpoxyExtensions.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.epoxy
2 |
3 | import com.airbnb.epoxy.EpoxyController
4 | import kotlin.properties.ObservableProperty
5 | import kotlin.properties.ReadWriteProperty
6 | import kotlin.reflect.KProperty
7 |
8 | // Extensions for EpoxyController
9 |
10 | /**
11 | * Returns a property delegate for a read/write property that calls [EpoxyController#requestModelBuild] method when property is changed
12 | * @param initialValue the initial value of the property.
13 | */
14 | @Deprecated("Usage of this encourages bad design of EpoxyControllers with multiple refreshing properties. Use TypedEpoxyController instead.")
15 | fun EpoxyController.adapterProperty(initialValue: T): ReadWriteProperty = object : ObservableProperty(initialValue) {
16 | override fun afterChange(property: KProperty<*>, oldValue: T, newValue: T) {
17 | requestModelBuild()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/epoxy/src/main/java/io/github/ackeecz/extensions/epoxy/EpoxyModelWithLayout.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.epoxy
2 |
3 | import android.view.View
4 | import android.view.ViewGroup
5 | import com.airbnb.epoxy.EpoxyModelWithView
6 | import io.github.ackeecz.extensions.anko.layout.ViewLayout
7 |
8 | /**
9 | * Epoxy model with [ViewLayout] implementation
10 | */
11 | abstract class EpoxyModelWithLayout : EpoxyModelWithView() {
12 |
13 | abstract fun createViewLayout(parent: ViewGroup): T
14 |
15 | final override fun buildView(parent: ViewGroup): View {
16 | val layout: T = createViewLayout(parent)
17 | val view = layout.view
18 | view.setTag(R.id.epoxy_view_layout, layout)
19 | return view
20 | }
21 |
22 | final override fun bind(view: View) {
23 | super.bind(view)
24 |
25 | @Suppress("UNCHECKED_CAST")
26 | (view.getTag(R.id.epoxy_view_layout) as T).bind()
27 | }
28 |
29 | abstract fun T.bind()
30 |
31 | open fun T.unbind() {
32 | }
33 |
34 | override fun unbind(view: View) {
35 | super.unbind(view)
36 |
37 | @Suppress("UNCHECKED_CAST")
38 | (view.getTag(R.id.epoxy_view_layout) as T).unbind()
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/epoxy/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/epoxy2/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/epoxy2/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion Integer.parseInt(buildProperties["SDK_VERSION"])
6 |
7 | defaultConfig {
8 | minSdkVersion Integer.parseInt(buildProperties["MIN_SDK_VERSION"])
9 | targetSdkVersion Integer.parseInt(buildProperties["SDK_VERSION"])
10 | versionCode = libProperties['VERSION_CODE']
11 | versionName libProperties['VERSION_NAME']
12 |
13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14 | consumerProguardFiles 'proguard-rules.pro'
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | buildFeatures {
25 | viewBinding true
26 | }
27 | }
28 |
29 | dependencies {
30 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
31 | implementation ('com.airbnb.android:epoxy:5.1.3')
32 | }
33 |
34 | ext {
35 | PUBLISH_ARTIFACT_ID = 'extensions-epoxy2'
36 | POM_DESCRIPTION = 'Kotlin extensions for Epoxy library. Version without Anko dependency'
37 | }
38 |
39 | apply from: "${rootProject.projectDir}/gradle/mavencentral/publish.gradle"
40 |
--------------------------------------------------------------------------------
/epoxy2/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/billda/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
27 | # keep viewbinding classes for viewbinding delegate
28 | -keepclassmembers public final class * implements androidx.viewbinding.ViewBinding {
29 | public static *** bind(...);
30 | public static *** inflate(...);
31 | }
--------------------------------------------------------------------------------
/epoxy2/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/epoxy2/src/main/java/io/github/ackeecz/extensions/epoxy2/EpoxyModelWithViewBinding.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.epoxy2
2 |
3 | import android.view.View
4 | import android.view.ViewParent
5 | import androidx.annotation.LayoutRes
6 | import androidx.viewbinding.ViewBinding
7 | import com.airbnb.epoxy.EpoxyHolder
8 | import com.airbnb.epoxy.EpoxyModelWithHolder
9 | import java.lang.reflect.Method
10 | import java.lang.reflect.ParameterizedType
11 | import java.util.concurrent.ConcurrentHashMap
12 |
13 | /**
14 | * EpoxyModel class with view binding support
15 | *
16 | * Taken from https://github.com/airbnb/epoxy/blob/master/kotlinsample/src/main/java/com/airbnb/epoxy/kotlinsample/helpers/ViewBindingEpoxyModelWithHolder.kt
17 | */
18 | abstract class EpoxyModelWithViewBinding(@LayoutRes val resId: Int) : EpoxyModelWithHolder() {
19 |
20 | override fun getDefaultLayout(): Int {
21 | return resId
22 | }
23 |
24 | @Suppress("UNCHECKED_CAST")
25 | override fun bind(holder: ViewBindingHolder) {
26 | (holder.viewBinding as T).bind()
27 | }
28 |
29 | abstract fun T.bind()
30 |
31 | @Suppress("UNCHECKED_CAST")
32 | override fun unbind(holder: ViewBindingHolder) {
33 | (holder.viewBinding as T).unbind()
34 | }
35 |
36 | open fun T.unbind() = Unit
37 |
38 | override fun createNewHolder(parent: ViewParent): ViewBindingHolder {
39 | return ViewBindingHolder(this::class.java)
40 | }
41 | }
42 |
43 | // Static cache of a method pointer for each type of item used.
44 | private val sBindingMethodByClass = ConcurrentHashMap, Method>()
45 |
46 | @Suppress("UNCHECKED_CAST")
47 | @Synchronized
48 | private fun getBindMethodFrom(javaClass: Class<*>): Method {
49 | return sBindingMethodByClass.getOrPut(javaClass) {
50 | val actualTypeOfThis = getSuperclassParameterizedType(javaClass)
51 | val viewBindingClass = actualTypeOfThis.actualTypeArguments[0] as Class
52 | viewBindingClass.getDeclaredMethod("bind", View::class.java)
53 | ?: error("The binder class ${javaClass.canonicalName} should have a method bind(View)")
54 | }
55 | }
56 |
57 | private fun getSuperclassParameterizedType(klass: Class<*>): ParameterizedType {
58 | val genericSuperclass = klass.genericSuperclass
59 | return (genericSuperclass as? ParameterizedType) ?: getSuperclassParameterizedType(genericSuperclass as Class<*>)
60 | }
61 |
62 | class ViewBindingHolder(private val epoxyModelClass: Class<*>) : EpoxyHolder() {
63 | // Using reflection to get the static binding method.
64 | // Lazy so it's computed only once by instance, when the 1st ViewHolder is actually created.
65 | private val bindingMethod by lazy { getBindMethodFrom(epoxyModelClass) }
66 |
67 | internal lateinit var viewBinding: ViewBinding
68 |
69 | override fun bindView(itemView: View) {
70 | // The 1st param is null because the binding method is static.
71 | viewBinding = bindingMethod.invoke(null, itemView) as ViewBinding
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 | android.useAndroidX=true
19 |
--------------------------------------------------------------------------------
/gradle/mavencentral/publish.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven-publish'
2 | apply plugin: 'signing'
3 | apply plugin: 'org.jetbrains.dokka'
4 |
5 | task androidSourcesJar(type: Jar) {
6 | archiveClassifier.set('sources')
7 | if (project.plugins.findPlugin("com.android.library")) {
8 | // For Android libraries
9 | from android.sourceSets.main.java.srcDirs
10 | from android.sourceSets.main.kotlin.srcDirs
11 | } else {
12 | // For pure Kotlin libraries, in case you have them
13 | from sourceSets.main.java.srcDirs
14 | from sourceSets.main.kotlin.srcDirs
15 | }
16 | }
17 |
18 | task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
19 | archiveClassifier.set('javadoc')
20 | from dokkaJavadoc.outputDirectory
21 | }
22 |
23 | artifacts {
24 | archives androidSourcesJar
25 | archives javadocJar
26 | }
27 |
28 |
29 | group = libProperties['GROUP']
30 | version = libProperties['VERSION_NAME']
31 |
32 | ext["signing.keyId"] = ''
33 | ext["signing.password"] = ''
34 | ext["signing.secretKeyRingFile"] = ''
35 | ext["ossrhUsername"] = ''
36 | ext["ossrhPassword"] = ''
37 | ext["sonatypeStagingProfileId"] = ''
38 |
39 | File secretPropsFile = project.rootProject.file('local.properties')
40 | if (secretPropsFile.exists()) {
41 | Properties p = new Properties()
42 | new FileInputStream(secretPropsFile).withCloseable { is ->
43 | p.load(is)
44 | }
45 | p.each { name, value ->
46 | ext[name] = value
47 | }
48 | } else {
49 | ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
50 | ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
51 | ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
52 | ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
53 | ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
54 | ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
55 | }
56 |
57 | publishing {
58 | publications {
59 | release(MavenPublication) {
60 | // The coordinates of the library, being set from variables that
61 | // we'll set up later
62 | groupId libProperties['GROUP']
63 | artifactId PUBLISH_ARTIFACT_ID
64 | version libProperties['VERSION_NAME']
65 |
66 | // Two artifacts, the `aar` (or `jar`) and the sources
67 | if (project.plugins.findPlugin("com.android.library")) {
68 | artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
69 | } else {
70 | artifact("$buildDir/libs/${project.getName()}-${version}.jar")
71 | }
72 | artifact androidSourcesJar
73 | artifact javadocJar
74 |
75 | // Mostly self-explanatory metadata
76 | pom {
77 | name = PUBLISH_ARTIFACT_ID
78 | description = POM_DESCRIPTION
79 | url = libProperties['SITE_URL']
80 | licenses {
81 | license {
82 | name = libProperties['POM_LICENCE_NAME']
83 | url = libProperties['POM_LICENCE_URL']
84 | }
85 | }
86 | developers {
87 | developer {
88 | id = libProperties['POM_DEVELOPER_ID']
89 | name = libProperties['POM_DEVELOPER_NAME']
90 | email = libProperties['POM_DEVELOPER_EMAIL']
91 | }
92 | // Add all other devs here...
93 | }
94 | // Version control info - if you're using GitHub, follow the format as seen here
95 | scm {
96 | connection = libProperties['POM_SCM_CONNECTION']
97 | developerConnection = libProperties['POM_SCM_DEVELOPER_CONNECTION']
98 | url = libProperties['POM_SCM_URL']
99 | }
100 | // A slightly hacky fix so that your POM will include any transitive dependencies
101 | // that your library builds upon
102 | withXml {
103 | def dependenciesNode = asNode().appendNode('dependencies')
104 |
105 | project.configurations.implementation.allDependencies.each {
106 | def dependencyNode = dependenciesNode.appendNode('dependency')
107 | dependencyNode.appendNode('groupId', it.group)
108 | dependencyNode.appendNode('artifactId', it.name)
109 | dependencyNode.appendNode('version', it.version)
110 | }
111 | }
112 | }
113 | }
114 | }
115 | // The repository to publish to, Sonatype/MavenCentral
116 | repositories {
117 | maven {
118 | // This is an arbitrary name, you may also use "mavencentral" or
119 | // any other name that's descriptive for you
120 | name = "sonatype"
121 | url = libProperties['SONATYPE_URL']
122 | credentials {
123 | username ossrhUsername
124 | password ossrhPassword
125 | }
126 | }
127 | }
128 | }
129 |
130 | signing {
131 | sign publishing.publications
132 | }
133 |
134 | nexusStaging {
135 | packageGroup = libProperties['GROUP']
136 | stagingProfileId = sonatypeStagingProfileId
137 | username = ossrhUsername
138 | password = ossrhPassword
139 | serverUrl = 'https://s01.oss.sonatype.org/service/local'
140 | }
141 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AckeeCZ/kotlin-extensions/9d6c2d22382fb88af56d1874ad65c11e0bc8b1b3/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jun 15 09:51:25 CEST 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | #
21 | # Gradle start up script for POSIX generated by Gradle.
22 | #
23 | # Important for running:
24 | #
25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26 | # noncompliant, but you have some other compliant shell such as ksh or
27 | # bash, then to run this script, type that shell name before the whole
28 | # command line, like:
29 | #
30 | # ksh Gradle
31 | #
32 | # Busybox and similar reduced shells will NOT work, because this script
33 | # requires all of these POSIX shell features:
34 | # * functions;
35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37 | # * compound commands having a testable exit status, especially «case»;
38 | # * various built-in commands including «command», «set», and «ulimit».
39 | #
40 | # Important for patching:
41 | #
42 | # (2) This script targets any POSIX shell, so it avoids extensions provided
43 | # by Bash, Ksh, etc; in particular arrays are avoided.
44 | #
45 | # The "traditional" practice of packing multiple parameters into a
46 | # space-separated string is a well documented source of bugs and security
47 | # problems, so this is (mostly) avoided, by progressively accumulating
48 | # options in "$@", and eventually passing that to Java.
49 | #
50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52 | # see the in-line comments for details.
53 | #
54 | # There are tweaks for specific operating systems such as AIX, CygWin,
55 | # Darwin, MinGW, and NonStop.
56 | #
57 | # (3) This script is generated from the Groovy template
58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59 | # within the Gradle project.
60 | #
61 | # You can find Gradle at https://github.com/gradle/gradle/.
62 | #
63 | ##############################################################################
64 |
65 | # Attempt to set APP_HOME
66 |
67 | # Resolve links: $0 may be a link
68 | app_path=$0
69 |
70 | # Need this for daisy-chained symlinks.
71 | while
72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73 | [ -h "$app_path" ]
74 | do
75 | ls=$( ls -ld "$app_path" )
76 | link=${ls#*' -> '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
84 |
85 | APP_NAME="Gradle"
86 | APP_BASE_NAME=${0##*/}
87 |
88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137 |
138 | Please set the JAVA_HOME variable in your environment to match the
139 | location of your Java installation."
140 | fi
141 |
142 | # Increase the maximum file descriptors if we can.
143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144 | case $MAX_FD in #(
145 | max*)
146 | MAX_FD=$( ulimit -H -n ) ||
147 | warn "Could not query maximum file descriptor limit"
148 | esac
149 | case $MAX_FD in #(
150 | '' | soft) :;; #(
151 | *)
152 | ulimit -n "$MAX_FD" ||
153 | warn "Could not set maximum file descriptor limit to $MAX_FD"
154 | esac
155 | fi
156 |
157 | # Collect all arguments for the java command, stacking in reverse order:
158 | # * args from the command line
159 | # * the main class name
160 | # * -classpath
161 | # * -D...appname settings
162 | # * --module-path (only if needed)
163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
164 |
165 | # For Cygwin or MSYS, switch paths to Windows format before running java
166 | if "$cygwin" || "$msys" ; then
167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
169 |
170 | JAVACMD=$( cygpath --unix "$JAVACMD" )
171 |
172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
173 | for arg do
174 | if
175 | case $arg in #(
176 | -*) false ;; # don't mess with options #(
177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
178 | [ -e "$t" ] ;; #(
179 | *) false ;;
180 | esac
181 | then
182 | arg=$( cygpath --path --ignore --mixed "$arg" )
183 | fi
184 | # Roll the args list around exactly as many times as the number of
185 | # args, so each arg winds up back in the position where it started, but
186 | # possibly modified.
187 | #
188 | # NB: a `for` loop captures its iteration list before it begins, so
189 | # changing the positional parameters here affects neither the number of
190 | # iterations, nor the values presented in `arg`.
191 | shift # remove old arg
192 | set -- "$@" "$arg" # push replacement arg
193 | done
194 | fi
195 |
196 | # Collect all arguments for the java command;
197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
198 | # shell script including quotes and variable substitutions, so put them in
199 | # double quotes to make sure that they get re-expanded; and
200 | # * put everything else in single quotes, so that it's not re-expanded.
201 |
202 | set -- \
203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
204 | -classpath "$CLASSPATH" \
205 | org.gradle.wrapper.GradleWrapperMain \
206 | "$@"
207 |
208 | # Use "xargs" to parse quoted args.
209 | #
210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
211 | #
212 | # In Bash we could simply go:
213 | #
214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
215 | # set -- "${ARGS[@]}" "$@"
216 | #
217 | # but POSIX shell has neither arrays nor command substitution, so instead we
218 | # post-process each arg (as a line of input to sed) to backslash-escape any
219 | # character that might be a shell metacharacter, then use eval to reverse
220 | # that process (while maintaining the separation between arguments), and wrap
221 | # the whole thing up as a single "set" statement.
222 | #
223 | # This will of course break if any of these variables contains a newline or
224 | # an unmatched quote.
225 | #
226 |
227 | eval "set -- $(
228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
229 | xargs -n1 |
230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
231 | tr '\n' ' '
232 | )" '"$@"'
233 |
234 | exec "$JAVACMD" "$@"
235 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/lib.properties:
--------------------------------------------------------------------------------
1 | GROUP=io.github.ackeecz
2 | VERSION_NAME=2.1.0
3 | VERSION_CODE=1
4 | SITE_URL=https://github.com/AckeeCZ/kotlin-extensions
5 | POM_DEVELOPER_ID=ackee
6 | POM_DEVELOPER_NAME=Ackee
7 | POM_DEVELOPER_EMAIL=info@ackee.cz
8 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
9 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
10 | POM_SCM_CONNECTION=scm:git:github.com/ackeecz/kotlin-extensions.git
11 | POM_SCM_DEVELOPER_CONNECTION='scm:git:ssh://github.com/ackeecz/kotlin-extensions.git'
12 | POM_SCM_URL=https://github.com/ackeeCZ/kotlin-extensions/tree/main
13 | SONATYPE_URL=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/
14 |
--------------------------------------------------------------------------------
/picasso/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/picasso/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion Integer.parseInt(buildProperties["SDK_VERSION"])
6 |
7 | defaultConfig {
8 | minSdkVersion Integer.parseInt(buildProperties["MIN_SDK_VERSION"])
9 | targetSdkVersion Integer.parseInt(buildProperties["SDK_VERSION"])
10 | versionCode = libProperties['VERSION_CODE']
11 | versionName libProperties['VERSION_NAME']
12 |
13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
26 | implementation 'com.squareup.picasso:picasso:2.8'
27 | }
28 |
29 |
30 | ext {
31 | PUBLISH_ARTIFACT_ID = 'extensions-picasso'
32 | POM_DESCRIPTION = 'Kotlin extensions for Picasso library'
33 | }
34 |
35 | apply from: "${rootProject.projectDir}/gradle/mavencentral/publish.gradle"
36 |
--------------------------------------------------------------------------------
/picasso/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/billda/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/picasso/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/picasso/src/main/java/io/github/ackeecz/extensions/picasso/PicassoExtensions.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.picasso
2 |
3 | import android.widget.ImageView
4 | import com.squareup.picasso.Callback
5 | import com.squareup.picasso.Picasso
6 |
7 | // Extensions for Picasso
8 |
9 | /**
10 | * Load url to ImageView and use optional callback or noFade to disable fade animation
11 | */
12 | fun ImageView.loadUrl(url: String, noFade: Boolean = false, callback: Callback? = null) {
13 | Picasso.get()
14 | .load(url)
15 | .apply {
16 | if (noFade) {
17 | noFade()
18 | }
19 | }
20 | .into(this, callback)
21 | }
22 |
--------------------------------------------------------------------------------
/rxjava2/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/rxjava2/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion Integer.parseInt(buildProperties["SDK_VERSION"])
6 |
7 | defaultConfig {
8 | minSdkVersion Integer.parseInt(buildProperties["MIN_SDK_VERSION"])
9 | targetSdkVersion Integer.parseInt(buildProperties["SDK_VERSION"])
10 | versionCode = libProperties['VERSION_CODE']
11 | versionName libProperties['VERSION_NAME']
12 |
13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compileOnly 'io.reactivex.rxjava2:rxjava:2.2.6'
26 | compileOnly 'io.reactivex.rxjava2:rxandroid:2.1.0'
27 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
28 | }
29 |
30 | ext {
31 | PUBLISH_ARTIFACT_ID = 'extensions-rxjava2'
32 | POM_DESCRIPTION = 'Kotlin extensions for RxJava2 framework'
33 | }
34 |
35 | apply from: "${rootProject.projectDir}/gradle/mavencentral/publish.gradle"
36 |
--------------------------------------------------------------------------------
/rxjava2/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/billda/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/rxjava2/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/rxjava2/src/main/java/io/github/ackeecz/extensions/rxjava2/Disposables.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.rxjava2
2 |
3 | import io.reactivex.disposables.Disposable
4 |
5 | // Extensions for RxJava2
6 |
7 | /**
8 | * Safely dispose = if not null and not already disposed
9 | */
10 | fun Disposable?.safeDispose() {
11 | if (this?.isDisposed == false) {
12 | dispose()
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/rxjava2/src/main/java/io/github/ackeecz/extensions/rxjava2/Schedulers.kt:
--------------------------------------------------------------------------------
1 | package io.github.ackeecz.extensions.rxjava2
2 |
3 | import io.reactivex.Completable
4 | import io.reactivex.Flowable
5 | import io.reactivex.Maybe
6 | import io.reactivex.Observable
7 | import io.reactivex.Single
8 | import io.reactivex.android.schedulers.AndroidSchedulers
9 | import io.reactivex.schedulers.Schedulers
10 |
11 | // Extensions for applying schedulers
12 |
13 | // Observable
14 |
15 | fun Observable.observeOnMainThread(): Observable {
16 | return this.observeOn(AndroidSchedulers.mainThread())
17 | }
18 |
19 | fun Observable.subscribeOnIO(): Observable {
20 | return this.subscribeOn(Schedulers.io())
21 | }
22 |
23 | fun Observable.subscribeOnNewThread(): Observable {
24 | return this.subscribeOn(Schedulers.newThread())
25 | }
26 |
27 | fun Observable.subscribeOnComputation(): Observable {
28 | return this.subscribeOn(Schedulers.computation())
29 | }
30 |
31 | // Completable
32 |
33 | fun Completable.observeOnMainThread(): Completable {
34 | return this.observeOn(AndroidSchedulers.mainThread())
35 | }
36 |
37 | fun Completable.subscribeOnIO(): Completable {
38 | return this.subscribeOn(Schedulers.io())
39 | }
40 |
41 | fun Completable.subscribeOnNewThread(): Completable {
42 | return this.subscribeOn(Schedulers.newThread())
43 | }
44 |
45 | fun Completable.subscribeOnComputation(): Completable {
46 | return this.subscribeOn(Schedulers.computation())
47 | }
48 |
49 | // Maybe
50 |
51 | fun Maybe.observeOnMainThread(): Maybe {
52 | return this.observeOn(AndroidSchedulers.mainThread())
53 | }
54 |
55 | fun Maybe.subscribeOnIO(): Maybe {
56 | return this.subscribeOn(Schedulers.io())
57 | }
58 |
59 | fun Maybe.subscribeOnNewThread(): Maybe {
60 | return this.subscribeOn(Schedulers.newThread())
61 | }
62 |
63 | fun Maybe.subscribeOnComputation(): Maybe {
64 | return this.subscribeOn(Schedulers.computation())
65 | }
66 |
67 | // Single
68 |
69 | fun Single.observeOnMainThread(): Single {
70 | return this.observeOn(AndroidSchedulers.mainThread())
71 | }
72 |
73 | fun Single.subscribeOnIO(): Single {
74 | return this.subscribeOn(Schedulers.io())
75 | }
76 |
77 | fun Single.subscribeOnNewThread(): Single {
78 | return this.subscribeOn(Schedulers.newThread())
79 | }
80 |
81 | fun Single.subscribeOnComputation(): Single {
82 | return this.subscribeOn(Schedulers.computation())
83 | }
84 |
85 | // Flowable
86 |
87 | fun Flowable.observeOnMainThread(): Flowable {
88 | return this.observeOn(AndroidSchedulers.mainThread())
89 | }
90 |
91 | fun Flowable.subscribeOnIO(): Flowable {
92 | return this.subscribeOn(Schedulers.io())
93 | }
94 |
95 | fun Flowable.subscribeOnNewThread(): Flowable {
96 | return this.subscribeOn(Schedulers.newThread())
97 | }
98 |
99 | fun Flowable.subscribeOnComputation(): Flowable {
100 | return this.subscribeOn(Schedulers.computation())
101 | }
102 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':android',
2 | ':anko',
3 | ':epoxy',
4 | ':epoxy2',
5 | ':picasso',
6 | ':rxjava2'
7 |
--------------------------------------------------------------------------------