├── .github
└── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
├── .gitignore
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── opensooq
│ │ └── supernova
│ │ └── gligarexample
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── opensooq
│ │ │ └── supernova
│ │ │ └── gligarexample
│ │ │ └── MainActivity.kt
│ └── res
│ │ ├── drawable-v21
│ │ └── ic_lock_white_24dp.xml
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── ic_launcher_background.xml
│ │ └── ic_lock_white_24dp.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── opensooq
│ └── supernova
│ └── gligarexample
│ └── ExampleUnitTest.kt
├── build.gradle
├── demo.gif
├── gligar
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── opensooq
│ │ └── supernova
│ │ └── gligar
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── opensooq
│ │ │ └── supernova
│ │ │ └── gligar
│ │ │ ├── GligarPicker.kt
│ │ │ ├── adapters
│ │ │ ├── AlbumsAdapter.kt
│ │ │ ├── ImagesAdapter.kt
│ │ │ ├── ItemClickListener.kt
│ │ │ └── LoadMoreListener.kt
│ │ │ ├── dataSource
│ │ │ ├── ImagesDataSource.kt
│ │ │ └── model
│ │ │ │ ├── AlbumItem.kt
│ │ │ │ ├── ImageItem.kt
│ │ │ │ └── ImageSource.kt
│ │ │ ├── ui
│ │ │ ├── ImagePickerActivity.kt
│ │ │ └── PickerViewModel.kt
│ │ │ └── utils
│ │ │ ├── Consts.kt
│ │ │ └── Ext.kt
│ └── res
│ │ ├── drawable-v21
│ │ ├── ic_arrow_drop_down_white_24dp.xml
│ │ ├── ic_check_white_24dp.xml
│ │ ├── ic_lock_white_24dp.xml
│ │ ├── ic_photo_camera_black_36dp.xml
│ │ ├── transparent_selector.xml
│ │ └── white_selector_no_corners.xml
│ │ ├── drawable
│ │ ├── circle_shape.xml
│ │ ├── ic_arrow_drop_down_white_24dp.xml
│ │ ├── ic_check_white_24dp.xml
│ │ ├── ic_lock_white_24dp.xml
│ │ ├── ic_photo_camera_black_36dp.xml
│ │ ├── transparent_selector.xml
│ │ └── white_selector_no_corners.xml
│ │ ├── layout
│ │ ├── activity_image_picker_gligar.xml
│ │ ├── include_permssion_alert_gligar.xml
│ │ ├── item_picker_image_gligar.xml
│ │ ├── item_spinner_gligar.xml
│ │ └── layout_album_spinner_gligar.xml
│ │ ├── values-v21
│ │ ├── dimens.xml
│ │ └── values.xml
│ │ ├── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ │ └── xml
│ │ └── file_paths.xml
│ └── test
│ └── java
│ └── com
│ └── opensooq
│ └── supernova
│ └── gligar
│ └── ExampleUnitTest.kt
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: hani-momanii
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Include stack trace if exist**
27 |
28 | **Smartphone (please complete the following information):**
29 | - Device: [e.g. Pixle2]
30 | - OS: [e.g. andoird 6 ]
31 |
32 | **Additional context**
33 | Add any other context about the problem here.
34 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: hani-momanii
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | .idea
16 | *.apk
17 | signing.properties
18 |
19 |
20 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, sex characteristics, gender identity and expression,
9 | level of experience, education, socio-economic status, nationality, personal
10 | appearance, race, religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at hani.a@opensooq.com. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 | For answers to common questions about this code of conduct, see
76 | https://www.contributor-covenant.org/faq
77 |
--------------------------------------------------------------------------------
/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 | Copyright 2019 OpenSooq
179 |
180 | Licensed under the Apache License, Version 2.0 (the "License");
181 | you may not use this file except in compliance with the License.
182 | You may obtain a copy of the License at
183 |
184 | http://www.apache.org/licenses/LICENSE-2.0
185 |
186 | Unless required by applicable law or agreed to in writing, software
187 | distributed under the License is distributed on an "AS IS" BASIS,
188 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189 | See the License for the specific language governing permissions and
190 | limitations under the License.
191 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Gliger [Android Image Picker Library]
6 | ======================
7 |   [](https://opensource.org/licenses/Apache-2.0) [  ](https://bintray.com/opensooq/Gligar/gligar/1.0.0/link) [](https://android-arsenal.com/details/1/8021)
8 |
9 |
10 | :star: Star us on GitHub — it helps!
11 |
12 | [](https://forthebadge.com)
13 |
14 | ##### Gliger is an Easy, lightweight and high performance image picker library for Android!
15 | ##### Gliger load images using Android content resolver with the help of coroutines to lazy load the images and improve the performance!
16 | ##### Gliger handle permission requests, support camera capture, and limit for the max number of images to pick.
17 |
18 |
19 |
20 | Demo
21 | ======================
22 |
23 |
24 | ## Table of content
25 |
26 | * [Download](#download)
27 | * [Sample Project](#sample-project)
28 | * [Usage](#usage)
29 | * [UI customization](#UI-customization)
30 | - [License](#license)
31 |
32 | # Download
33 |
34 | This library is available in **jCenter** which is the default Maven repository used in Android Studio. You can also import this library from source as a module.
35 |
36 | ```groovy
37 | dependencies {
38 | // other dependencies here
39 | implementation 'com.opensooq.supernova:gligar:1.1.0'
40 | }
41 | ```
42 |
43 |
44 | # Sample Project
45 | We have a sample project demonstrating how to use the library.
46 |
47 | Checkout the demo [here](https://github.com/OpenSooq/Gligar/tree/master/app/src/main/java/com/opensooq/supernova/gligarexample)
48 |
49 |
50 |
51 | # Usage
52 | #### Simpler than ever!
53 |
54 | To open the Picker:
55 |
56 | ### Kotlin
57 | ```kotlin
58 | GligarPicker().requestCode(PICKER_REQUEST_CODE).withActivity(this).show()
59 | ```
60 | ### Java
61 |
62 | ```java
63 | new GligarPicker().requestCode(PICKER_REQUEST_CODE).withActivity(this).show();
64 | ```
65 |
66 | To get the result override onActivityResult method:
67 |
68 | ### Kotlin
69 | ```kotlin
70 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
71 | super.onActivityResult(requestCode, resultCode, data)
72 | if (resultCode != Activity.RESULT_OK) {
73 | return
74 | }
75 |
76 | when (requestCode) {
77 | PICKER_REQUEST_CODE -> {
78 | val imagesList = data?.extras?.getStringArray(GligarPicker.IMAGES_RESULT)// return list of selected images paths.
79 | if (!imagesList.isNullOrEmpty()) {
80 | imagesCount.text = "Number of selected Images: ${imagesList.size}"
81 | }
82 | }
83 | }
84 | }
85 | ```
86 |
87 | ### Java
88 |
89 | ```java
90 | @Override
91 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
92 | super.onActivityResult(requestCode, resultCode, data);
93 | if (resultCode != Activity.RESULT_OK) {
94 | return;
95 | }
96 | switch (requestCode){
97 | case PICKER_REQUEST_CODE : {
98 | String pathsList[]= data.getExtras().getStringArray(GligarPicker.IMAGES_RESULT); // return list of selected images paths.
99 | imagesCount.text = "Number of selected Images: " + pathsList.length;
100 | break;
101 | }
102 | }
103 | }
104 | ```
105 |
106 |
107 | | Method | usage |
108 | | ------ | ------ |
109 | | ``` withActivity(activity: Activity) ``` | used to set the activity will recive the result |
110 | | ``` withFragment(fragment: Fragment) ``` | used to set the fragment will recive the result |
111 | | ``` requestCode(requestCode: Int) ``` | used to set the request code for the result |
112 | | ``` limit(limit: Int) ``` | used to set the max number of images to select |
113 | | ``` disableCamera(disableCamera: Boolean) ``` | by default the value of disableCamera is false, it determine to allow camera captures or not |
114 | | ``` cameraDirect(cameraDirect: Boolean) ``` | by default the value of cameraDirect is false, it determine to open the camera before showing the picker or not |
115 |
116 |
117 | ## UI customization
118 |
119 | ### Customizable Colors
120 | override any color to change inside your project colors.xml
121 |
122 | | Property | Description |
123 | |:----------------------|:---------------------:|
124 | | `counter_bg` | selection counter background color |
125 | | `counter_color` | selection counter text color |
126 | | `selector_color` | selection tint color |
127 | | `place_holder_color` | empty image holder color |
128 | | `ripple_color` | selection ripple color |
129 | | `toolbar_bg` | toolbar color |
130 | | `done` | Done button color |
131 | | `change_album_color` | change album text color |
132 | | `camera_icon_color` | camera icon color |
133 | | `camera_text_color` | camera text color |
134 | | `permission_alert_bg` | permission alert background color |
135 | | `permission_alert_color` | permission alert text color |
136 |
137 |
138 |
139 | ### Customizable Texts
140 | override any string to change inside your project strings.xml
141 |
142 | | Property | Description |
143 | |:----------------------|:---------------------:|
144 | | `over_limit_msg` | selection limit reached message |
145 | | `capture_new_image` | capture image text |
146 | | `change_album_text` | change album text |
147 | | `permission_storage_never_ask` | permission denied message |
148 | | `all_images` | all images album name |
149 |
150 |
151 |
152 |
153 | # License
154 |
155 | ```
156 | Copyright 2019 OpenSooq
157 |
158 | Licensed under the Apache License, Version 2.0 (the "License");
159 | you may not use this file except in compliance with the License.
160 | You may obtain a copy of the License at
161 |
162 | http://www.apache.org/licenses/LICENSE-2.0
163 |
164 | Unless required by applicable law or agreed to in writing, software
165 | distributed under the License is distributed on an "AS IS" BASIS,
166 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
167 | See the License for the specific language governing permissions and
168 | limitations under the License.
169 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | signingConfigs {
9 | test {
10 | storePassword '123456'
11 | keyAlias = 'test'
12 | keyPassword '123456'
13 | }
14 | }
15 | compileSdkVersion 29
16 | buildToolsVersion "29.0.0"
17 | defaultConfig {
18 | applicationId "com.opensooq.supernova.gligarexample"
19 | minSdkVersion 17
20 | targetSdkVersion 29
21 | versionCode 1
22 | versionName "1.0"
23 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
24 | }
25 | buildTypes {
26 | release {
27 | minifyEnabled false
28 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
29 | }
30 | }
31 | }
32 |
33 | dependencies {
34 | implementation fileTree(dir: 'libs', include: ['*.jar'])
35 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
36 | implementation 'androidx.appcompat:appcompat:1.1.0'
37 | implementation 'androidx.core:core-ktx:1.1.0'
38 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
39 | implementation project(':gligar')
40 | }
41 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/opensooq/supernova/gligarexample/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.supernova.gligarexample
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.opensooq.supernova.gligarexample", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/opensooq/supernova/gligarexample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.supernova.gligarexample
2 |
3 | import android.app.Activity
4 | import android.content.Intent
5 | import android.os.Bundle
6 | import androidx.appcompat.app.AppCompatActivity
7 | import com.opensooq.supernova.gligar.GligarPicker
8 | import kotlinx.android.synthetic.main.activity_main.*
9 |
10 | class MainActivity : AppCompatActivity() {
11 |
12 | val PICKER_REQUEST_CODE = 30
13 |
14 | override fun onCreate(savedInstanceState: Bundle?) {
15 | super.onCreate(savedInstanceState)
16 | setContentView(R.layout.activity_main)
17 | GligarPicker().limit(10).disableCamera(false).cameraDirect(false).requestCode(PICKER_REQUEST_CODE)
18 | .withActivity(this).show()
19 | }
20 |
21 |
22 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
23 | super.onActivityResult(requestCode, resultCode, data)
24 | if (resultCode != Activity.RESULT_OK) {
25 | return
26 | }
27 |
28 | when (requestCode) {
29 | PICKER_REQUEST_CODE -> {
30 | val imagesList = data?.extras?.getStringArray(GligarPicker.IMAGES_RESULT)
31 | if (!imagesList.isNullOrEmpty()) {
32 | imagesCount.text = "Number of selected Images: ${imagesList.size}"
33 | }
34 | }
35 | }
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_lock_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_lock_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OpenSooq/Gligar/081f6996208fbfd7817f1a8324c60623f8b86c64/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OpenSooq/Gligar/081f6996208fbfd7817f1a8324c60623f8b86c64/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OpenSooq/Gligar/081f6996208fbfd7817f1a8324c60623f8b86c64/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OpenSooq/Gligar/081f6996208fbfd7817f1a8324c60623f8b86c64/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OpenSooq/Gligar/081f6996208fbfd7817f1a8324c60623f8b86c64/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OpenSooq/Gligar/081f6996208fbfd7817f1a8324c60623f8b86c64/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OpenSooq/Gligar/081f6996208fbfd7817f1a8324c60623f8b86c64/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OpenSooq/Gligar/081f6996208fbfd7817f1a8324c60623f8b86c64/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OpenSooq/Gligar/081f6996208fbfd7817f1a8324c60623f8b86c64/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OpenSooq/Gligar/081f6996208fbfd7817f1a8324c60623f8b86c64/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Gligar Example
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/opensooq/supernova/gligarexample/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.supernova.gligarexample
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/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.3.50'
5 | repositories {
6 | google()
7 | jcenter()
8 |
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.5.0'
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0'
14 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 |
18 |
19 |
20 | }
21 | }
22 |
23 | allprojects {
24 | repositories {
25 | google()
26 | jcenter()
27 |
28 | }
29 | }
30 |
31 | task clean(type: Delete) {
32 | delete rootProject.buildDir
33 | }
34 |
--------------------------------------------------------------------------------
/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OpenSooq/Gligar/081f6996208fbfd7817f1a8324c60623f8b86c64/demo.gif
--------------------------------------------------------------------------------
/gligar/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/gligar/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'com.jfrog.bintray'
5 | apply plugin: 'com.github.dcendents.android-maven'
6 |
7 | ext {
8 | bintrayRepo = 'Gligar'
9 | bintrayName = 'gligar' // Has to be same as your library module name
10 |
11 | publishedGroupId = 'com.opensooq.supernova'
12 | libraryName = 'gligar'
13 | artifact = 'gligar' // Has to be same as your library module name
14 |
15 | libraryDescription = 'Image Picker for Android, Pick an image from Gallery or Capture a new image with Camera'
16 |
17 | // Your github repo link
18 | siteUrl = 'https://github.com/OpenSooq/GligarPicker'
19 | gitUrl = 'https://github.com/OpenSooq/GligarPicker.git'
20 | githubRepository= 'OpenSooq/GligarPicker'
21 |
22 | libraryVersion = '1.1.0'
23 |
24 | developerId = 'OpenSooq'
25 | developerName = 'OpenSooq'
26 | developerEmail = 'hani.momanii@gmail.com'
27 |
28 | licenseName = 'The Apache Software License, Version 2.0'
29 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
30 | allLicenses = ["Apache-2.0"]
31 | }
32 |
33 | android {
34 | compileSdkVersion 29
35 | buildToolsVersion "29.0.0"
36 |
37 | androidExtensions {
38 | experimental = true
39 | }
40 |
41 | defaultConfig {
42 | vectorDrawables.useSupportLibrary = true
43 | minSdkVersion 17
44 | targetSdkVersion 29
45 | versionCode 1
46 | versionName "1"
47 |
48 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
49 | consumerProguardFiles 'consumer-rules.pro'
50 | }
51 |
52 | buildTypes {
53 | release {
54 | minifyEnabled false
55 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
56 | }
57 | }
58 |
59 | }
60 |
61 | dependencies {
62 | implementation fileTree(dir: 'libs', include: ['*.jar'])
63 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
64 | implementation 'androidx.appcompat:appcompat:1.1.0'
65 | implementation 'androidx.core:core-ktx:1.1.0'
66 |
67 | implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha04'
68 | implementation "androidx.lifecycle:lifecycle-runtime:2.1.0-alpha04"
69 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0-alpha04"
70 | implementation 'androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-rc02'
71 |
72 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'
73 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0'
74 | implementation "android.arch.paging:runtime:1.0.1"
75 |
76 | implementation 'com.github.bumptech.glide:glide:4.9.0'
77 | annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
78 | implementation 'com.google.android.material:material:1.2.0-alpha02'
79 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
80 |
81 | }
82 |
83 | apply from: 'https://raw.githubusercontent.com/nisrulz/JCenter/master/installv1.gradle'
84 | apply from: 'https://gist.githubusercontent.com/tamtom/f54a538637178e4818bbc72f24a73e2d/raw/af6f8b6782475230cfff852ae11669c936e739a2/bintrayv1.gradle'
85 | tasks.withType(Javadoc).all {
86 | enabled = false
87 | }
--------------------------------------------------------------------------------
/gligar/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OpenSooq/Gligar/081f6996208fbfd7817f1a8324c60623f8b86c64/gligar/consumer-rules.pro
--------------------------------------------------------------------------------
/gligar/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/gligar/src/androidTest/java/com/opensooq/supernova/gligar/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.supernova.gligar
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 |
5 | import org.junit.Test
6 | import org.junit.runner.RunWith
7 |
8 | import org.junit.Assert.*
9 |
10 | /**
11 | * Instrumented test, which will execute on an Android device.
12 | *
13 | * See [testing documentation](http://d.android.com/tools/testing).
14 | */
15 | class ExampleInstrumentedTest {
16 | @Test
17 | fun useAppContext() {
18 | // Context of the app under test.
19 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
20 | assertEquals("com.opensooq.supernova.gligar.test", appContext.packageName)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/gligar/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
9 |
10 |
14 |
19 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/gligar/src/main/java/com/opensooq/supernova/gligar/GligarPicker.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.supernova.gligar
2 |
3 | import android.app.Activity
4 | import android.content.Intent
5 | import androidx.fragment.app.Fragment
6 | import com.opensooq.supernova.gligar.ui.ImagePickerActivity.Companion.EXTRA_CAMERA_DIRECT
7 | import com.opensooq.supernova.gligar.ui.ImagePickerActivity.Companion.EXTRA_DISABLE_CAMERA
8 | import com.opensooq.supernova.gligar.ui.ImagePickerActivity.Companion.EXTRA_LIMIT
9 | import com.opensooq.supernova.gligar.ui.ImagePickerActivity.Companion.startActivityForResult
10 | import java.lang.IllegalStateException
11 |
12 | /**
13 | * Created by Hani AlMomani on 30,November,2019
14 | */
15 |
16 |
17 | class GligarPicker {
18 |
19 | companion object {
20 | const val IMAGES_RESULT = "images"
21 | }
22 |
23 | private var withActivity: Activity? = null
24 | private var withFragment: Fragment? = null
25 | private var requestCode: Int = 0
26 | private var limit: Int = 10
27 | private var disableCamera: Boolean = false
28 | private var cameraDirect: Boolean = false
29 |
30 |
31 | fun requestCode(requestCode: Int) = apply { this.requestCode = requestCode }
32 | fun limit(limit: Int) = apply { this.limit = limit }
33 | fun disableCamera(disableCamera: Boolean) = apply { this.disableCamera = disableCamera }
34 | fun cameraDirect(cameraDirect: Boolean) = apply { this.cameraDirect = cameraDirect }
35 | fun withActivity(activity: Activity) = apply { this.withActivity = activity }
36 | fun withFragment(fragment: Fragment) = apply { this.withFragment = fragment }
37 |
38 |
39 | fun show() {
40 | if(withActivity == null && withFragment ==null){
41 | throw IllegalStateException("Activity or fragment should be passed, use withActivity(activity) or withFragment(fragment) to set any.")
42 | }
43 |
44 | val intent = Intent()
45 | intent.putExtra(EXTRA_LIMIT, limit)
46 | intent.putExtra(EXTRA_CAMERA_DIRECT, cameraDirect)
47 | if (!cameraDirect) {
48 | intent.putExtra(EXTRA_DISABLE_CAMERA, disableCamera)
49 | }
50 |
51 | if(withActivity!=null){
52 | startActivityForResult(withActivity!!,requestCode,intent)
53 | }else{
54 | startActivityForResult(withFragment!!,requestCode,intent)
55 | }
56 |
57 | }
58 | }
--------------------------------------------------------------------------------
/gligar/src/main/java/com/opensooq/supernova/gligar/adapters/AlbumsAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.supernova.gligar.adapters
2 |
3 | import android.content.Context
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import android.widget.ArrayAdapter
8 | import android.widget.TextView
9 | import com.opensooq.OpenSooq.ui.imagePicker.model.AlbumItem
10 | import com.opensooq.supernova.gligar.R
11 |
12 | /**
13 | * Created by Hani AlMomani on 24,Sep,2019
14 | */
15 |
16 | internal class AlbumsAdapter(var albumItems: List, context: Context) : ArrayAdapter(context, android.R.layout.simple_list_item_1, albumItems) {
17 | private val mInflater: LayoutInflater = LayoutInflater.from(context)
18 |
19 | override fun getDropDownView(position: Int, view: View?, parent: ViewGroup): View {
20 | var convertView = view
21 | val viewHolder: ViewHolderDrop
22 | if (convertView == null) {
23 | convertView = mInflater.inflate(R.layout.item_spinner_gligar, parent, false)
24 | viewHolder = ViewHolderDrop(convertView)
25 | convertView.tag = viewHolder
26 | } else {
27 | viewHolder = convertView.tag as ViewHolderDrop
28 | }
29 | val item = getItem(position)
30 | if (item != null) {
31 | viewHolder.name?.text = item.name
32 | }
33 | return convertView!!
34 | }
35 |
36 | override fun getView(position: Int, view: View?, parent: ViewGroup): View {
37 | var convertView = view
38 | val viewHolder: ViewHolderView
39 | if (convertView == null) {
40 | convertView = mInflater.inflate(R.layout.layout_album_spinner_gligar, parent, false)
41 | viewHolder = ViewHolderView(convertView)
42 | convertView.tag = viewHolder
43 | } else {
44 | viewHolder = convertView.tag as ViewHolderView
45 | }
46 | val item = getItem(position)
47 | if (item != null) {
48 | viewHolder.tvLabel?.text = item.name
49 | }
50 | return convertView!!
51 | }
52 |
53 |
54 | internal class ViewHolderView(view: View) {
55 | var tvLabel: TextView? = null
56 |
57 | init {
58 | tvLabel = view.findViewById(R.id.tvLabel)
59 | }
60 | }
61 |
62 | internal class ViewHolderDrop(view: View) {
63 | var name: TextView? = null
64 |
65 | init {
66 | name = view.findViewById(R.id.label)
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/gligar/src/main/java/com/opensooq/supernova/gligar/adapters/ImagesAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.supernova.gligar.adapters
2 |
3 | import android.view.LayoutInflater
4 | import android.view.View
5 | import android.view.ViewGroup
6 | import android.widget.ImageView
7 | import android.widget.TextView
8 | import androidx.constraintlayout.widget.ConstraintLayout
9 | import androidx.recyclerview.widget.RecyclerView
10 | import com.bumptech.glide.Glide
11 | import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
12 | import com.opensooq.OpenSooq.ui.imagePicker.model.ImageItem
13 | import com.opensooq.OpenSooq.ui.imagePicker.model.ImageSource
14 | import com.opensooq.supernova.gligar.R
15 |
16 |
17 | /**
18 | * Created by Hani AlMomani on 24,April,2019
19 | */
20 |
21 | internal class ImagesAdapter(var clickListener: ItemClickListener) :
22 | RecyclerView.Adapter() {
23 | var images = arrayListOf()
24 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ImageViewHolder =
25 | ImageViewHolder(
26 | LayoutInflater.from(parent.context).inflate(
27 | R.layout.item_picker_image_gligar,
28 | parent,
29 | false
30 | )
31 | )
32 |
33 | override fun getItemCount(): Int {
34 | return images.size
35 | }
36 |
37 | override fun onBindViewHolder(holder: ImageViewHolder, position: Int) {
38 | holder.itemView.setOnClickListener { clickListener.onItemClicked(position) }
39 | val data = images[position]
40 |
41 | if (data.source== ImageSource.GALLERY) {
42 | holder.imgView.visibility = View.VISIBLE
43 | holder.captureView.visibility = View.GONE
44 | if (data.selected > 0) {
45 | holder.selectionNum.text = data.selected.toString()
46 | holder.selectionViews.visibility = ConstraintLayout.VISIBLE
47 | } else {
48 | holder.selectionViews.visibility = ConstraintLayout.GONE
49 | holder.selectionNum.text = data.selected.toString()
50 | }
51 | if (data.source == ImageSource.DUM) {
52 | holder.imgView.visibility = View.VISIBLE
53 | holder.captureView.visibility = View.GONE
54 | return
55 | }
56 | Glide.with(holder.img).load(data.imagePath)
57 | .transition(DrawableTransitionOptions().crossFade()).into(holder.img)
58 | return
59 | }
60 | if (data.source== ImageSource.CAMERA) {
61 | holder.imgView.visibility = View.GONE
62 | holder.captureView.visibility = View.VISIBLE
63 | }
64 | }
65 |
66 | class ImageViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
67 | val selectionNum: TextView = itemView.findViewById(R.id.tv_num)
68 | val selectionViews: View = itemView.findViewById(R.id.v_group)
69 | val imgView: View = itemView.findViewById(R.id.image_view)
70 | val captureView: View = itemView.findViewById(R.id.capture_view)
71 | val img: ImageView = itemView.findViewById(R.id.img_image)
72 | }
73 | }
--------------------------------------------------------------------------------
/gligar/src/main/java/com/opensooq/supernova/gligar/adapters/ItemClickListener.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.supernova.gligar.adapters
2 |
3 | /**
4 | * Created by Hani AlMomani on 28,November,2019
5 | */
6 |
7 | internal interface ItemClickListener {
8 | fun onItemClicked(position : Int)
9 | }
--------------------------------------------------------------------------------
/gligar/src/main/java/com/opensooq/supernova/gligar/adapters/LoadMoreListener.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.supernova.gligar.adapters
2 |
3 | import androidx.recyclerview.widget.GridLayoutManager
4 | import androidx.recyclerview.widget.RecyclerView
5 |
6 | /**
7 | * Created by Hani AlMomani on 28,November,2019
8 | */
9 |
10 | internal class LoadMoreListener(layoutManager: GridLayoutManager) : RecyclerView.OnScrollListener() {
11 |
12 | private var visibleThreshold = 5
13 | private lateinit var mOnLoadMoreListener: OnLoadMoreListener
14 | private var isLoading: Boolean = false
15 | private var isFinish: Boolean = false
16 | private var lastVisibleItem: Int = 0
17 | private var totalItemCount: Int = 0
18 | private var mLayoutManager: GridLayoutManager = layoutManager
19 |
20 | fun setLoaded() {
21 | isLoading = false
22 | }
23 |
24 | internal fun setFinished(finished:Boolean= true) {
25 | isFinish = finished
26 | }
27 |
28 |
29 | internal fun setOnLoadMoreListener(mOnLoadMoreListener: OnLoadMoreListener) {
30 | this.mOnLoadMoreListener = mOnLoadMoreListener
31 | }
32 |
33 | init {
34 | visibleThreshold *= layoutManager.spanCount
35 | }
36 |
37 | override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
38 | super.onScrolled(recyclerView, dx, dy)
39 |
40 | if (dy <= 0) return
41 |
42 | totalItemCount = mLayoutManager.itemCount
43 | lastVisibleItem = mLayoutManager.findLastVisibleItemPosition()
44 |
45 | if (!isFinish && !isLoading && totalItemCount <= lastVisibleItem + visibleThreshold) {
46 | mOnLoadMoreListener.onLoadMore()
47 | isLoading = true
48 | }
49 |
50 | }
51 |
52 | interface OnLoadMoreListener {
53 | fun onLoadMore()
54 | }
55 | }
--------------------------------------------------------------------------------
/gligar/src/main/java/com/opensooq/supernova/gligar/dataSource/ImagesDataSource.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.supernova.gligar.dataSource
2 |
3 | import android.content.ContentResolver
4 | import android.database.Cursor
5 | import android.provider.MediaStore
6 | import androidx.paging.PositionalDataSource
7 | import com.opensooq.OpenSooq.ui.imagePicker.model.AlbumItem
8 | import com.opensooq.OpenSooq.ui.imagePicker.model.ImageItem
9 | import com.opensooq.OpenSooq.ui.imagePicker.model.ImageSource
10 | import com.opensooq.supernova.gligar.utils.*
11 | import kotlinx.coroutines.CoroutineScope
12 | import kotlinx.coroutines.Dispatchers
13 | import kotlinx.coroutines.Job
14 | import kotlinx.coroutines.launch
15 | import java.lang.Exception
16 | import kotlin.coroutines.CoroutineContext
17 |
18 | /**
19 | * Created by Hani AlMomani on 24,September,2019
20 | */
21 |
22 |
23 | internal class ImagesDataSource(private val contentResolver: ContentResolver){
24 |
25 | fun loadAlbums(): ArrayList {
26 | val albumCursor = contentResolver.query(
27 | cursorUri,
28 | arrayOf(DISPLAY_NAME_COLUMN,MediaStore.Images.ImageColumns.BUCKET_ID),
29 | null,
30 | null,
31 | ORDER_BY
32 | )
33 | val list = arrayListOf()
34 | try {
35 | list.add(AlbumItem("All", true,"0"))
36 | if (albumCursor == null) {
37 | return list
38 | }
39 | albumCursor.doWhile {
40 | val bucketId = albumCursor.getString(albumCursor.getColumnIndex(MediaStore.Images.ImageColumns.BUCKET_ID))
41 | val name = albumCursor.getString(albumCursor.getColumnIndex(DISPLAY_NAME_COLUMN)) ?: bucketId
42 | var albumItem = AlbumItem(name, false, bucketId)
43 | if (!list.contains(albumItem)) {
44 | list.add(albumItem)
45 | }
46 | }
47 | } finally {
48 | if (albumCursor != null && !albumCursor.isClosed) {
49 | albumCursor.close()
50 | }
51 | }
52 | return list
53 | }
54 |
55 | fun loadAlbumImages(
56 | albumItem: AlbumItem?,
57 | page: Int
58 | ): ArrayList {
59 | val offset = page * PAGE_SIZE
60 | val list: ArrayList = arrayListOf()
61 | var photoCursor: Cursor? = null
62 | try {
63 | if (albumItem == null || albumItem.isAll) {
64 | photoCursor = contentResolver.query(
65 | cursorUri,
66 | arrayOf(
67 | ID_COLUMN,
68 | PATH_COLUMN
69 | ),
70 | null,
71 | null,
72 | "$ORDER_BY LIMIT $PAGE_SIZE OFFSET $offset"
73 | )
74 | } else {
75 | photoCursor = contentResolver.query(
76 | cursorUri,
77 | arrayOf(
78 | ID_COLUMN,
79 | PATH_COLUMN
80 | ),
81 | "${MediaStore.Images.ImageColumns.BUCKET_ID} =?",
82 | arrayOf(albumItem.bucketId),
83 | "$ORDER_BY LIMIT $PAGE_SIZE OFFSET $offset"
84 | )
85 | }
86 | photoCursor?.isAfterLast ?: return list
87 | photoCursor.doWhile {
88 | val image = photoCursor.getString((photoCursor.getColumnIndex(PATH_COLUMN)))
89 | list.add(ImageItem(image, ImageSource.GALLERY, 0))
90 | }
91 | } finally {
92 | if (photoCursor != null && !photoCursor.isClosed()) {
93 | photoCursor.close()
94 | }
95 | }
96 | return list
97 | }
98 | }
--------------------------------------------------------------------------------
/gligar/src/main/java/com/opensooq/supernova/gligar/dataSource/model/AlbumItem.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.OpenSooq.ui.imagePicker.model
2 |
3 | import android.os.Parcelable
4 | import kotlinx.android.parcel.Parcelize
5 |
6 | /**
7 | * Created by Hani AlMomani on 24,April,2019
8 | */
9 | @Parcelize
10 | internal data class AlbumItem(val name: String, val isAll: Boolean,val bucketId: String) : Parcelable
--------------------------------------------------------------------------------
/gligar/src/main/java/com/opensooq/supernova/gligar/dataSource/model/ImageItem.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.OpenSooq.ui.imagePicker.model
2 |
3 | import android.os.Parcelable
4 | import kotlinx.android.parcel.Parcelize
5 |
6 | /**
7 | * Created by Hani AlMomani on 23,April,2019
8 | */
9 |
10 | @Parcelize
11 | internal data class ImageItem(var imagePath: String, var source: ImageSource, var selected: Int) : Parcelable
12 |
--------------------------------------------------------------------------------
/gligar/src/main/java/com/opensooq/supernova/gligar/dataSource/model/ImageSource.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.OpenSooq.ui.imagePicker.model
2 |
3 | /**
4 | * Created by Hani AlMomani on 23,April,2019
5 | */
6 |
7 | internal enum class ImageSource(val source: Int) {
8 | GALLERY(1),
9 | CAMERA(2),
10 | DUM(3)
11 | }
--------------------------------------------------------------------------------
/gligar/src/main/java/com/opensooq/supernova/gligar/ui/ImagePickerActivity.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.supernova.gligar.ui
2 |
3 | import android.app.Activity
4 | import android.content.Intent
5 | import android.content.pm.PackageManager
6 | import android.net.Uri
7 | import android.os.Build
8 | import android.os.Bundle
9 | import android.provider.MediaStore
10 | import android.provider.Settings
11 | import android.util.Log
12 | import android.view.View
13 | import android.widget.AdapterView
14 | import android.widget.ImageView
15 | import androidx.appcompat.app.AppCompatActivity
16 | import androidx.appcompat.app.AppCompatDelegate
17 | import androidx.appcompat.widget.AppCompatSpinner
18 | import androidx.core.app.ActivityCompat.requestPermissions
19 | import androidx.core.app.ActivityCompat.shouldShowRequestPermissionRationale
20 | import androidx.core.content.ContextCompat
21 | import androidx.core.content.FileProvider
22 | import androidx.fragment.app.Fragment
23 | import androidx.lifecycle.Observer
24 | import androidx.lifecycle.SavedStateViewModelFactory
25 | import androidx.lifecycle.ViewModelProvider
26 | import androidx.recyclerview.widget.GridLayoutManager
27 | import androidx.recyclerview.widget.RecyclerView
28 | import com.google.android.material.button.MaterialButton
29 | import com.google.android.material.snackbar.Snackbar
30 | import com.opensooq.OpenSooq.ui.imagePicker.model.AlbumItem
31 | import com.opensooq.OpenSooq.ui.imagePicker.model.ImageItem
32 | import com.opensooq.supernova.gligar.GligarPicker.Companion.IMAGES_RESULT
33 | import com.opensooq.supernova.gligar.R
34 | import com.opensooq.supernova.gligar.adapters.AlbumsAdapter
35 | import com.opensooq.supernova.gligar.adapters.ImagesAdapter
36 | import com.opensooq.supernova.gligar.adapters.ItemClickListener
37 | import com.opensooq.supernova.gligar.adapters.LoadMoreListener
38 | import com.opensooq.supernova.gligar.utils.PAGE_SIZE
39 | import com.opensooq.supernova.gligar.utils.createTempImageFile
40 | import java.io.File
41 |
42 |
43 | /**
44 | * Created by Hani AlMomani on 24,September,2019
45 | */
46 |
47 |
48 | internal class ImagePickerActivity : AppCompatActivity(), LoadMoreListener.OnLoadMoreListener,
49 | ItemClickListener {
50 |
51 | init {
52 | AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
53 | }
54 |
55 | companion object {
56 | const val EXTRA_LIMIT = "limit"
57 | const val EXTRA_CAMERA_DIRECT = "camera_direct"
58 | const val EXTRA_DISABLE_CAMERA = "disable_camera"
59 | const val STORAGE_PERMISSION_REQUEST_CODE = 100
60 | const val CAMERA_PERMISSION_REQUEST_CODE = 101
61 | private const val REQUEST_CODE_CAMERA_IMAGE = 102
62 |
63 | fun startActivityForResult(
64 | fragment: Fragment,
65 | requestCode: Int,
66 | intent: Intent
67 | ) {
68 | intent.setClass(fragment.context!!, ImagePickerActivity::class.java)
69 | fragment.startActivityForResult(intent, requestCode)
70 | }
71 |
72 | fun startActivityForResult(
73 | activity: Activity,
74 | requestCode: Int,
75 | intent: Intent
76 | ) {
77 | intent.setClass(activity, ImagePickerActivity::class.java)
78 | activity.startActivityForResult(intent, requestCode)
79 | }
80 | }
81 |
82 | private lateinit var mainViewModel: PickerViewModel
83 | private var mAlbumAdapter: AlbumsAdapter? = null
84 | private var mImagesAdapter: ImagesAdapter? = null
85 | private var loadMoreListener: LoadMoreListener? = null
86 | private var isPermissionGranted = false
87 | private var isSaveState = false
88 | private var forceCamera = false
89 |
90 | private lateinit var icDone: ImageView
91 | private lateinit var alertBtn: MaterialButton
92 | private lateinit var alert: View
93 | private lateinit var albumsSpinner: AppCompatSpinner
94 | private lateinit var rvImages: RecyclerView
95 | private lateinit var changeAlbum: View
96 | private lateinit var rootView: View
97 |
98 |
99 | override fun onCreate(savedInstanceState: Bundle?) {
100 | super.onCreate(savedInstanceState)
101 | setContentView(R.layout.activity_image_picker_gligar)
102 |
103 | icDone = findViewById(R.id._ic_done)
104 | alertBtn = findViewById(R.id._alert_btn)
105 | alert = findViewById(R.id._v_alert)
106 | albumsSpinner = findViewById(R.id._albums_spinner)
107 | rvImages = findViewById(R.id._rv_images)
108 | changeAlbum = findViewById(R.id._change_album)
109 | rootView = findViewById(R.id._v_rootView)
110 |
111 |
112 | mainViewModel = ViewModelProvider(this, SavedStateViewModelFactory(application, this)).get(
113 | PickerViewModel::class.java
114 | )
115 | mainViewModel.init(contentResolver)
116 | if (savedInstanceState != null) {
117 | isSaveState = true
118 | mainViewModel.loadSaveState()
119 | } else {
120 | mainViewModel.bindArguments(intent.extras)
121 |
122 | }
123 | setImagesAdapter()
124 | icDone.setOnClickListener { sendResults() }
125 | }
126 |
127 | private fun openCamera() = checkCameraPermission()
128 |
129 | private fun loadAlbums() {
130 | isPermissionGranted = true
131 | mainViewModel.loadAlbums()
132 | }
133 |
134 | private fun storagePermissionGranted() {
135 | hideAlert()
136 | loadAlbums()
137 | }
138 |
139 | private fun cameraPermissionGranted() {
140 | hideAlert()
141 | try {
142 | val photoFile: File? = createTempImageFile(this)
143 | mainViewModel.mCurrentPhotoPath = photoFile?.absolutePath
144 | val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
145 | val myPhotoFileUri = FileProvider.getUriForFile(
146 | this,
147 | this.applicationContext.packageName + ".provider",
148 | photoFile!!
149 | )
150 | cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, myPhotoFileUri)
151 | cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
152 | startActivityForResult(
153 | Intent.createChooser(cameraIntent, ""),
154 | REQUEST_CODE_CAMERA_IMAGE
155 | )
156 | } catch (e: Exception) {
157 | Log.e("Picker", e.message, e)
158 | }
159 | }
160 |
161 | private fun checkCameraPermission() {
162 | if (mainViewModel.isOverLimit()) {
163 | showLimitMsg()
164 | return
165 | }
166 |
167 | if (Build.VERSION.SDK_INT >= 23) {
168 | if (checkPermission(android.Manifest.permission.CAMERA)) {
169 | cameraPermissionGranted()
170 | } else {
171 | requestPermission(
172 | arrayOf(android.Manifest.permission.CAMERA),
173 | CAMERA_PERMISSION_REQUEST_CODE
174 | )
175 | }
176 | } else {
177 | cameraPermissionGranted()
178 | }
179 | }
180 |
181 | private fun checkStoragePermission() {
182 | if (Build.VERSION.SDK_INT >= 23) {
183 | if (checkPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)) {
184 | storagePermissionGranted()
185 | } else {
186 | requestPermission(
187 | arrayOf(android.Manifest.permission.READ_EXTERNAL_STORAGE),
188 | STORAGE_PERMISSION_REQUEST_CODE
189 | );
190 | }
191 | } else {
192 | storagePermissionGranted()
193 | }
194 | }
195 |
196 | private fun checkPermission(permission: String): Boolean {
197 | val result = ContextCompat.checkSelfPermission(this, permission)
198 | return result == PackageManager.PERMISSION_GRANTED
199 | }
200 |
201 | private fun requestPermission(permissions: Array, requestCode: Int) {
202 | if (shouldShowRequestPermissionRationale(this, permissions[0])) {
203 | showAlert()
204 | } else {
205 | requestPermissions(this, permissions, requestCode);
206 | }
207 | }
208 |
209 | private fun showAlert() {
210 | alertBtn.setOnClickListener { showAppPage() }
211 | alert.visibility = View.VISIBLE
212 | }
213 |
214 | private fun hideAlert() {
215 | alert.visibility = View.GONE
216 | }
217 |
218 | private fun setAlbumsAdapter(albums: List) {
219 | mAlbumAdapter = AlbumsAdapter(albums, applicationContext)
220 | albumsSpinner.adapter = mAlbumAdapter
221 | albumsSpinner.setSelection(mainViewModel.mCurrentSelectedAlbum, false)
222 | albumsSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
223 | override fun onNothingSelected(parent: AdapterView<*>?) {
224 |
225 | }
226 |
227 | override fun onItemSelected(
228 | adapterView: AdapterView<*>,
229 | view: View,
230 | pos: Int,
231 | l: Long
232 | ) {
233 | mainViewModel.onAlbumChanged(mAlbumAdapter?.getItem(pos), pos)
234 | mImagesAdapter?.images?.clear()
235 | mImagesAdapter?.notifyDataSetChanged()
236 | }
237 | }
238 | changeAlbum.setOnClickListener { albumsSpinner.performClick() }
239 | }
240 |
241 | private fun setImagesAdapter() {
242 | mImagesAdapter = ImagesAdapter(this)
243 | val mLayoutManager = GridLayoutManager(this, 3)
244 | rvImages.layoutManager = mLayoutManager
245 | rvImages.setHasFixedSize(true)
246 | mImagesAdapter?.images = arrayListOf()
247 | mImagesAdapter?.images?.addAll(if (isSaveState && !mainViewModel.saveStateImages.isNullOrEmpty()) mainViewModel.saveStateImages else mainViewModel.dumpImagesList)
248 | mainViewModel.saveStateImages.clear()
249 | rvImages.adapter = mImagesAdapter
250 | observe()
251 | setLoadMoreListener()
252 | }
253 |
254 | override fun onItemClicked(position: Int) {
255 | when (position) {
256 | 0 -> openCamera()
257 | else -> {
258 | mainViewModel.setImageSelection(position, mImagesAdapter?.images)
259 | }
260 | }
261 | }
262 |
263 | private fun observe() {
264 |
265 | mainViewModel.mDirectCamera.observe(this, Observer {
266 | forceCamera = it
267 | })
268 | mainViewModel.mAlbums.observe(this, Observer {
269 | setAlbumsAdapter(it)
270 | })
271 | mainViewModel.mLastAddedImages.observe(this, Observer {
272 | addImages(it)
273 | })
274 | mainViewModel.mNotifyPosition.observe(this, Observer {
275 | mImagesAdapter?.notifyItemChanged(it)
276 | })
277 |
278 | mainViewModel.mNotifyInsert.observe(this, Observer {
279 | mImagesAdapter?.notifyDataSetChanged()
280 | })
281 |
282 | mainViewModel.mDoneEnabled.observe(this, Observer {
283 | setDoneVisibilty(it)
284 | })
285 |
286 | mainViewModel.showOverLimit.observe(this, Observer {
287 | showLimitMsg()
288 | })
289 | }
290 |
291 | private fun addImages(it: ArrayList) {
292 | loadMoreListener?.setFinished(false)
293 | if (it.isNullOrEmpty()) {
294 | loadMoreListener?.setFinished()
295 | loadMoreListener?.setLoaded()
296 | return
297 | }
298 | val isFirstPage = mainViewModel.mPage == 0
299 | isPermissionGranted = true
300 | if (it.size < PAGE_SIZE) {
301 | loadMoreListener?.setFinished()
302 | }
303 |
304 | var lastPos = mImagesAdapter?.images?.size ?: 0
305 | if (isFirstPage) {
306 | mImagesAdapter?.images = it
307 | mImagesAdapter?.notifyDataSetChanged()
308 | } else {
309 | mImagesAdapter?.images?.addAll(it)
310 | mImagesAdapter?.notifyItemRangeInserted(lastPos, it.size)
311 | }
312 | loadMoreListener?.setLoaded()
313 | if (forceCamera) {
314 | openCamera()
315 | forceCamera = false
316 | }
317 | }
318 |
319 | private fun setDoneVisibilty(visible: Boolean) {
320 | icDone.visibility = if (visible) View.VISIBLE else View.GONE
321 | }
322 |
323 | private fun setLoadMoreListener() {
324 | if (loadMoreListener != null) {
325 | rvImages.removeOnScrollListener(loadMoreListener!!)
326 | }
327 | loadMoreListener = LoadMoreListener(rvImages.layoutManager as GridLayoutManager)
328 | loadMoreListener?.setOnLoadMoreListener(this@ImagePickerActivity)
329 | rvImages.addOnScrollListener(loadMoreListener!!)
330 | }
331 |
332 | override fun onLoadMore() {
333 | if (!isPermissionGranted) {
334 | return
335 | }
336 | mainViewModel.loadMoreImages()
337 | }
338 |
339 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
340 | super.onActivityResult(requestCode, resultCode, data)
341 | if (resultCode == Activity.RESULT_OK) {
342 | when (requestCode) {
343 | REQUEST_CODE_CAMERA_IMAGE -> {
344 | mainViewModel.addCameraItem(mImagesAdapter?.images)
345 | setDoneVisibilty(true)
346 | }
347 | }
348 | }
349 | }
350 |
351 | override fun onRequestPermissionsResult(
352 | requestCode: Int,
353 | permissions: Array,
354 | grantResults: IntArray
355 | ) {
356 | super.onRequestPermissionsResult(requestCode, permissions, grantResults)
357 | when (requestCode) {
358 | STORAGE_PERMISSION_REQUEST_CODE -> {
359 | if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
360 | storagePermissionGranted()
361 | } else {
362 | showAlert()
363 | }
364 | return
365 | }
366 | CAMERA_PERMISSION_REQUEST_CODE -> {
367 | if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
368 | cameraPermissionGranted()
369 | } else {
370 | showAlert()
371 | }
372 | return
373 | }
374 | }
375 | }
376 |
377 | private fun sendResults() {
378 | val images = mainViewModel.getSelectedPaths()
379 | val intent = Intent()
380 | intent.putExtra(IMAGES_RESULT, images)
381 | setResult(Activity.RESULT_OK, intent)
382 | finish()
383 | }
384 |
385 | private fun showLimitMsg() {
386 | Snackbar.make(rootView, R.string.over_limit_msg, Snackbar.LENGTH_LONG).show()
387 | }
388 |
389 |
390 | private fun showAppPage() {
391 | val intent = Intent(
392 | Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
393 | Uri.fromParts("package", packageName, null)
394 | )
395 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
396 | startActivity(intent)
397 | }
398 |
399 | override fun onResume() {
400 | super.onResume()
401 | checkStoragePermission()
402 | }
403 |
404 | override fun onSaveInstanceState(outState: Bundle) {
405 | if (::mainViewModel.isInitialized) {
406 | mainViewModel.saveStateImages = mImagesAdapter?.images ?: arrayListOf()
407 | mainViewModel.saveState()
408 | }
409 | super.onSaveInstanceState(outState)
410 | }
411 |
412 | }
413 |
--------------------------------------------------------------------------------
/gligar/src/main/java/com/opensooq/supernova/gligar/ui/PickerViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.supernova.gligar.ui
2 |
3 | import android.content.ContentResolver
4 | import android.os.Bundle
5 | import androidx.lifecycle.MutableLiveData
6 | import androidx.lifecycle.SavedStateHandle
7 | import androidx.lifecycle.ViewModel
8 | import androidx.lifecycle.viewModelScope
9 | import com.opensooq.OpenSooq.ui.imagePicker.model.AlbumItem
10 | import com.opensooq.OpenSooq.ui.imagePicker.model.ImageItem
11 | import com.opensooq.OpenSooq.ui.imagePicker.model.ImageSource
12 | import com.opensooq.supernova.gligar.dataSource.ImagesDataSource
13 | import com.opensooq.supernova.gligar.ui.ImagePickerActivity.Companion.EXTRA_LIMIT
14 | import com.opensooq.supernova.gligar.utils.*
15 | import kotlinx.coroutines.Dispatchers
16 | import kotlinx.coroutines.launch
17 | import kotlinx.coroutines.withContext
18 |
19 | /**
20 | * Created by Hani AlMomani on 24,September,2019
21 | */
22 |
23 |
24 | internal class PickerViewModel(private val savedStateHandle: SavedStateHandle) : ViewModel() {
25 |
26 |
27 | internal fun init(contentResolver: ContentResolver) {
28 | this.contentResolver = contentResolver
29 | this.mImageDataSource = ImagesDataSource(this.contentResolver)
30 | }
31 |
32 | internal var mDoneEnabled = MutableLiveData()
33 | internal var mDirectCamera = MutableLiveData()
34 | internal var showOverLimit = MutableLiveData()
35 | internal var mNotifyPosition = MutableLiveData()
36 | internal var mNotifyInsert = MutableLiveData()
37 | internal var mAlbums = MutableLiveData>()
38 | internal var mLastAddedImages = MutableLiveData>()
39 | internal var saveStateImages = arrayListOf()
40 | internal var dumpImagesList = getDumItems()
41 | internal var mCurrentPhotoPath: String? = null
42 | internal var mCurrentSelectedAlbum = 0
43 | internal var mPage = 0
44 |
45 | private var mSelectedAlbum: AlbumItem? = null
46 | private var mSelectedList = hashMapOf()
47 | private var mCurrentSelection: Int = 0
48 | private var mLimit = 0
49 | private var mCameraCisabled: Boolean = true
50 |
51 | private lateinit var mImageDataSource: ImagesDataSource
52 | private lateinit var contentResolver: ContentResolver
53 | private fun getCurrentSelection() = mCurrentSelection
54 |
55 | internal fun isOverLimit() = mCurrentSelection >= mLimit
56 |
57 | internal fun bindArguments(extras: Bundle?) {
58 | if (extras == null) {
59 | return
60 | }
61 | mLimit = extras.getInt(EXTRA_LIMIT, 0)
62 | mCameraCisabled = extras.getBoolean(ImagePickerActivity.EXTRA_DISABLE_CAMERA, false)
63 | mDirectCamera.value = extras.getBoolean(ImagePickerActivity.EXTRA_CAMERA_DIRECT, false)
64 | }
65 |
66 |
67 | internal fun loadAlbums() {
68 | if (!mAlbums.value.isNullOrEmpty()) {
69 | return
70 | }
71 | viewModelScope.launch {
72 | val albums = getAlbums()
73 | mAlbums.value = albums
74 | loadImages()
75 | }
76 | }
77 |
78 | internal fun loadMoreImages() {
79 | loadImages(true)
80 |
81 | }
82 |
83 | private fun loadImages(isLoadMore: Boolean = false) {
84 | if (isLoadMore) {
85 | mPage += 1
86 | } else {
87 | mPage = 0
88 | }
89 | viewModelScope.launch() {
90 | val images = getImages()
91 | if (!isLoadMore && !mCameraCisabled) {
92 | images.add(0, ImageItem("", ImageSource.CAMERA, 0))
93 | }
94 | mLastAddedImages.value = images
95 | }
96 | }
97 |
98 | private suspend fun getImages() = withContext(Dispatchers.Default) {
99 | mImageDataSource.loadAlbumImages(mSelectedAlbum, mPage)
100 | }
101 |
102 |
103 | private suspend fun getAlbums() = withContext(Dispatchers.Default) {
104 | mImageDataSource.loadAlbums()
105 | }
106 |
107 | internal fun addCameraItem(adapterItems: ArrayList?) {
108 | if (mCurrentPhotoPath.isNullOrEmpty()) {
109 | return
110 | }
111 | val imageItem =
112 | ImageItem(mCurrentPhotoPath!!, ImageSource.GALLERY, getCurrentSelectionCountForCamera())
113 | mSelectedList[imageItem.imagePath] = imageItem
114 | adapterItems?.add(1, imageItem)
115 | mNotifyInsert.value = 1
116 | }
117 |
118 |
119 | internal fun setImageSelection(position: Int, adapterImageItem: ArrayList?) {
120 | if (adapterImageItem.isNullOrEmpty()) {
121 | return
122 | }
123 | val imageItem = adapterImageItem[position]
124 |
125 | if (adapterImageItem[position].source == ImageSource.DUM) {
126 | return
127 | }
128 |
129 | if (imageItem.selected == 0) {
130 | if (isOverLimit()) {
131 | showOverLimit.value = true
132 | return
133 | }
134 | mCurrentSelection++
135 | imageItem.selected = mCurrentSelection
136 | mSelectedList[imageItem.imagePath] = imageItem
137 | } else {
138 | for ((i, mItem) in adapterImageItem.withIndex()) {
139 | if (mItem.selected > imageItem.selected) {
140 | mItem.selected--
141 | mNotifyPosition.value = i
142 | }
143 | }
144 | imageItem.selected = 0
145 | mCurrentSelection--
146 | mSelectedList.remove(imageItem.imagePath)
147 | }
148 | mNotifyPosition.value = position
149 | mDoneEnabled.value = getCurrentSelection() > 0
150 | }
151 |
152 |
153 | private fun getCurrentSelectionCountForCamera(): Int {
154 | mCurrentSelection++
155 | return mCurrentSelection
156 | }
157 |
158 |
159 | internal fun getSelectedPaths(): Array {
160 | val sortedList = mSelectedList.values.sortedWith(compareByDescending { it.selected })
161 | val pathsList = mutableListOf()
162 | for (imageItem in sortedList) {
163 | pathsList.add(imageItem.imagePath)
164 | }
165 | return pathsList.toTypedArray()
166 | }
167 |
168 | private fun getDumItems(): ArrayList {
169 | val list = arrayListOf()
170 | for (x in 0..PAGE_SIZE) list.add(ImageItem("", ImageSource.DUM, 0))
171 | return list
172 | }
173 |
174 | internal fun onAlbumChanged(item: AlbumItem?, pos: Int) {
175 | mSelectedAlbum = item
176 | mSelectedList.clear()
177 | mCurrentSelection = 0
178 | mCurrentSelectedAlbum = pos
179 | loadImages()
180 | }
181 |
182 | internal fun saveState() {
183 | savedStateHandle.set(IMAGES, saveStateImages)
184 | savedStateHandle.set(ALBUMS, mAlbums.value)
185 | savedStateHandle.set(PHOTO_PATH, mCurrentPhotoPath)
186 | savedStateHandle.set(ALBUM_POS, mCurrentSelectedAlbum)
187 | savedStateHandle.set(PAGE, mPage)
188 | savedStateHandle.set(SELECTED_ALBUM, mSelectedAlbum)
189 | savedStateHandle.set(SELECTED_IMAGES, mSelectedList)
190 | savedStateHandle.set(CURRENT_SELECTION, mCurrentSelection)
191 | savedStateHandle.set(LIMIT, mLimit)
192 | savedStateHandle.set(DISABLE_CAMERA, mCameraCisabled)
193 |
194 | }
195 |
196 | internal fun loadSaveState() {
197 | saveStateImages = savedStateHandle.get(IMAGES) ?: arrayListOf()
198 | mAlbums.value = savedStateHandle.get(ALBUMS) ?: arrayListOf()
199 | mCurrentPhotoPath = savedStateHandle.get(PHOTO_PATH)
200 | mCurrentSelectedAlbum = savedStateHandle.get(ALBUM_POS) ?: 0
201 | mPage = savedStateHandle.get(PAGE) ?: 0
202 | mSelectedAlbum = savedStateHandle.get(SELECTED_ALBUM)
203 | mSelectedList = savedStateHandle.get(SELECTED_IMAGES) ?: hashMapOf()
204 | mCurrentSelection = savedStateHandle.get(CURRENT_SELECTION) ?: 0
205 | mLimit = savedStateHandle.get(LIMIT) ?: 0
206 | mCameraCisabled = savedStateHandle.get(DISABLE_CAMERA) ?: false
207 | }
208 |
209 | }
--------------------------------------------------------------------------------
/gligar/src/main/java/com/opensooq/supernova/gligar/utils/Consts.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.supernova.gligar.utils
2 |
3 | import android.net.Uri
4 | import android.provider.MediaStore
5 |
6 | /**
7 | * Created by Hani AlMomani on 24,September,2019
8 | */
9 |
10 | internal val cursorUri: Uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI
11 | internal const val ORDER_BY = MediaStore.Images.Media.DATE_TAKEN + " DESC"
12 | internal const val DISPLAY_NAME_COLUMN = MediaStore.Images.Media.BUCKET_DISPLAY_NAME
13 | internal const val ID_COLUMN = MediaStore.Images.Media._ID
14 | internal const val PATH_COLUMN = MediaStore.Images.Media.DATA
15 | internal const val PAGE_SIZE = 20
16 |
17 | internal const val IMAGES = "images"
18 | internal const val ALBUMS = "albums"
19 | internal const val PHOTO_PATH = "photo_path"
20 | internal const val ALBUM_POS = "album_pos"
21 | internal const val PAGE = "page"
22 | internal const val SELECTED_ALBUM = "selected_album"
23 | internal const val SELECTED_IMAGES = "selected_images"
24 | internal const val CURRENT_SELECTION = "curren_selection"
25 | internal const val LIMIT = "limit"
26 | internal const val DISABLE_CAMERA = "limit"
27 |
--------------------------------------------------------------------------------
/gligar/src/main/java/com/opensooq/supernova/gligar/utils/Ext.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.supernova.gligar.utils
2 |
3 | import android.app.Activity
4 | import android.content.Context
5 | import android.database.Cursor
6 | import android.os.Environment
7 | import androidx.paging.PagedList
8 | import java.io.File
9 | import android.os.Environment.DIRECTORY_PICTURES
10 | import android.os.Environment.getExternalStoragePublicDirectory
11 | import android.view.View
12 | import androidx.annotation.IdRes
13 | import java.io.IOException
14 | import java.text.SimpleDateFormat
15 | import java.util.*
16 |
17 |
18 | /**
19 | * Created by Hani AlMomani on 24,September,2019
20 | */
21 |
22 | internal fun Cursor.doWhile(action: () -> Unit) {
23 | this.use {
24 | if (this.moveToFirst()) {
25 | do {
26 | action()
27 | } while (this.moveToNext())
28 | }
29 | }
30 | }
31 |
32 |
33 | @Throws(IOException::class)
34 | internal fun createTempImageFile(context : Context): File {
35 | val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.ENGLISH).format(Date())
36 | val imageFileName = "JPEG_" + timeStamp + "_"
37 | val storageDir = context.getExternalFilesDir(DIRECTORY_PICTURES)
38 | val image = File.createTempFile(
39 | imageFileName,
40 | ".jpg",
41 | storageDir
42 | )
43 | return image
44 | }
--------------------------------------------------------------------------------
/gligar/src/main/res/drawable-v21/ic_arrow_drop_down_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/gligar/src/main/res/drawable-v21/ic_check_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/gligar/src/main/res/drawable-v21/ic_lock_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/gligar/src/main/res/drawable-v21/ic_photo_camera_black_36dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gligar/src/main/res/drawable-v21/transparent_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | -
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/gligar/src/main/res/drawable-v21/white_selector_no_corners.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | -
6 |
7 |
-
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/gligar/src/main/res/drawable/circle_shape.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/gligar/src/main/res/drawable/ic_arrow_drop_down_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/gligar/src/main/res/drawable/ic_check_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/gligar/src/main/res/drawable/ic_lock_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/gligar/src/main/res/drawable/ic_photo_camera_black_36dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gligar/src/main/res/drawable/transparent_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/gligar/src/main/res/drawable/white_selector_no_corners.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/gligar/src/main/res/layout/activity_image_picker_gligar.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
23 |
24 |
35 |
36 |
43 |
44 |
45 |
54 |
55 |
56 |
57 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
85 |
86 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/gligar/src/main/res/layout/include_permssion_alert_gligar.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
21 |
22 |
23 |
39 |
40 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/gligar/src/main/res/layout/item_picker_image_gligar.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
24 |
25 |
31 |
32 |
39 |
40 |
54 |
55 |
61 |
62 |
63 |
68 |
69 |
70 |
71 |
72 |
79 |
80 |
91 |
92 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/gligar/src/main/res/layout/item_spinner_gligar.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
--------------------------------------------------------------------------------
/gligar/src/main/res/layout/layout_album_spinner_gligar.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/gligar/src/main/res/values-v21/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 12sp
4 | 6dp
5 | 40dp
6 | 14sp
7 | 6dp
8 |
--------------------------------------------------------------------------------
/gligar/src/main/res/values-v21/values.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
--------------------------------------------------------------------------------
/gligar/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | #008577
6 | #FFF
7 | #000
8 | #F0F0F0
9 | #dddddd
10 | #80ebf5ff
11 | #008577
12 | #ffffff
13 | #ffffff
14 | #CAC9C9
15 | #000
16 | #000
17 | #fff
18 | #c62828
19 | #FFF
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gligar/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 12sp
4 | 6dp
5 | 40dp
6 | 14sp
7 | 0dp
8 | 4dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/gligar/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | All images
3 | The permission to access Files is not granted, please go to settings to grant it
4 | Settings
5 | Change Album
6 | Capture new image
7 | You have exceeded Images limit
8 |
9 |
10 |
--------------------------------------------------------------------------------
/gligar/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
--------------------------------------------------------------------------------
/gligar/src/main/res/xml/file_paths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
10 |
13 |
14 |
17 |
20 |
21 |
24 |
27 |
30 |
33 |
34 |
37 |
40 |
43 |
46 |
49 |
50 |
53 |
56 |
59 |
62 |
63 |
66 |
--------------------------------------------------------------------------------
/gligar/src/test/java/com/opensooq/supernova/gligar/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.opensooq.supernova.gligar
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OpenSooq/Gligar/081f6996208fbfd7817f1a8324c60623f8b86c64/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Sep 28 13:43:42 EEST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':gligar'
2 | rootProject.name='Gligar Example'
3 |
--------------------------------------------------------------------------------