├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── 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
│ │ │ ├── strings.xml
│ │ │ ├── styles.xml
│ │ │ └── colors.xml
│ │ └── layout
│ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── kc
│ │ └── splashpickerdemo
│ │ └── MainActivity.java
├── proguard-rules.pro
└── build.gradle
├── splashpicker
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ └── strings.xml
│ │ ├── menu
│ │ │ └── menu_main.xml
│ │ ├── drawable
│ │ │ ├── ic_close.xml
│ │ │ └── ic_search.xml
│ │ └── layout
│ │ │ ├── item_photo.xml
│ │ │ └── activity_picker.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── kc
│ │ └── splashpicker
│ │ ├── views
│ │ ├── SquareImageView.java
│ │ └── EndlessRecyclerViewScrollListener.java
│ │ ├── SplashPicker.java
│ │ ├── PhotoRecyclerAdapter.java
│ │ └── PickerActivity.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── caches
│ └── build_file_checksums.ser
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
├── codeStyles
│ └── Project.xml
├── assetWizardSettings.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── LICENSE
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/splashpicker/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':splashpicker'
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KeenenCharles/SplashPicker/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KeenenCharles/SplashPicker/HEAD/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KeenenCharles/SplashPicker/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KeenenCharles/SplashPicker/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KeenenCharles/SplashPicker/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KeenenCharles/SplashPicker/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KeenenCharles/SplashPicker/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KeenenCharles/SplashPicker/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KeenenCharles/SplashPicker/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KeenenCharles/SplashPicker/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KeenenCharles/SplashPicker/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KeenenCharles/SplashPicker/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SplashPickerDemo
3 | Pick Image
4 |
5 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/splashpicker/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #888888
4 | #A0000000
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Oct 23 01:24:25 BOT 2018
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-4.6-all.zip
7 |
--------------------------------------------------------------------------------
/splashpicker/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/splashpicker/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SplashPickerDemo
3 | Select Image
4 | Search
5 | Search
6 | Settings
7 |
8 |
--------------------------------------------------------------------------------
/splashpicker/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
12 |
--------------------------------------------------------------------------------
/splashpicker/src/main/res/drawable/ic_close.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #000000
4 | #000000
5 | #FF4081
6 | #DC376F
7 | #FAFAFA
8 | #EEEEEE
9 | #555555
10 | #20000000
11 | #A0000000
12 |
13 |
--------------------------------------------------------------------------------
/splashpicker/src/main/res/drawable/ic_search.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/splashpicker/src/main/res/layout/item_photo.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/splashpicker/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 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
20 |
--------------------------------------------------------------------------------
/splashpicker/src/main/java/com/kc/splashpicker/views/SquareImageView.java:
--------------------------------------------------------------------------------
1 | package com.kc.splashpicker.views;
2 |
3 | import android.content.Context;
4 | import androidx.appcompat.widget.AppCompatImageView;
5 | import android.util.AttributeSet;
6 |
7 | public class SquareImageView extends AppCompatImageView {
8 |
9 | public SquareImageView(Context context) {
10 | super(context);
11 | }
12 |
13 | public SquareImageView(Context context, AttributeSet attrs) {
14 | super(context, attrs);
15 | }
16 |
17 | public SquareImageView(Context context, AttributeSet attrs, int defStyle) {
18 | super(context, attrs, defStyle);
19 | }
20 |
21 | @Override
22 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
23 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
24 | int width = getMeasuredWidth();
25 | if(getMeasuredHeight() == 0)
26 | width = 0;
27 | setMeasuredDimension(width, width);
28 | }
29 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
16 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\kcred\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
11 |
18 |
19 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Keenen Charles
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | buildToolsVersion '28.0.3'
6 | dataBinding {
7 | enabled = true
8 | }
9 | defaultConfig {
10 | applicationId "com.kc.splashpickerdemo"
11 | minSdkVersion 17
12 | targetSdkVersion 28
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | debug {
19 | }
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | compileOptions {
26 | sourceCompatibility = '1.8'
27 | targetCompatibility = '1.8'
28 | }
29 | }
30 |
31 | dependencies {
32 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
33 | implementation 'androidx.appcompat:appcompat:1.0.2'
34 | implementation 'com.google.android.material:material:1.0.0'
35 |
36 | implementation 'com.squareup.picasso:picasso:2.71828'
37 | implementation 'com.kc.androidunsplash:androidunsplash:1.0.4'
38 | implementation project(path: ':splashpicker')
39 | }
--------------------------------------------------------------------------------
/splashpicker/src/main/java/com/kc/splashpicker/SplashPicker.java:
--------------------------------------------------------------------------------
1 | package com.kc.splashpicker;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 |
6 | import androidx.fragment.app.Fragment;
7 |
8 | public class SplashPicker {
9 |
10 | public static final int PICK_IMAGE_REQUEST = 0x4;
11 | public static final String KEY_IMAGE = "IMAGE";
12 |
13 | public static void open(Activity activity, String clientID){
14 | open(activity, clientID, null);
15 | }
16 |
17 | public static void open(Fragment fragment, Activity activity, String clientID){
18 | open(fragment, activity, clientID, null);
19 | }
20 |
21 | public static void open(Activity activity, String clientID, String title){
22 | Intent intent = getIntent(activity, clientID, title);
23 | activity.startActivityForResult(intent, PICK_IMAGE_REQUEST);
24 | }
25 | public static void open(Fragment fragment, Activity activity, String clientID, String title){
26 | Intent intent = getIntent(activity, clientID, title);
27 | fragment.startActivityForResult(intent, PICK_IMAGE_REQUEST);
28 | }
29 |
30 | private static Intent getIntent(Activity activity, String clientID, String title) {
31 | Intent intent = new Intent(activity, PickerActivity.class);
32 | intent.putExtra("CLIENT_ID", clientID);
33 | intent.putExtra("TITLE", title == null ? "Select Image" : title);
34 | return intent;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kc/splashpickerdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.kc.splashpickerdemo;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 |
7 | import com.kc.splashpicker.SplashPicker;
8 | import com.kc.splashpickerdemo.databinding.ActivityMainBinding;
9 | import com.kc.unsplash.models.Photo;
10 | import com.squareup.picasso.Picasso;
11 |
12 | import androidx.annotation.Nullable;
13 | import androidx.appcompat.app.AppCompatActivity;
14 | import androidx.databinding.DataBindingUtil;
15 |
16 | public class MainActivity extends AppCompatActivity {
17 |
18 | private final String CLIENT_ID = "";//BuildConfig.Unsplash;
19 |
20 | private ActivityMainBinding mBinding;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
26 |
27 | mBinding.pickButton.setOnClickListener(v -> SplashPicker.open(this, CLIENT_ID));
28 | }
29 |
30 | @Override
31 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
32 | if(requestCode == SplashPicker.PICK_IMAGE_REQUEST) {
33 | if(resultCode == Activity.RESULT_OK) {
34 | Photo photo = data.getParcelableExtra(SplashPicker.KEY_IMAGE);
35 | displayPhoto(photo);
36 | }
37 | }
38 | }
39 |
40 | private void displayPhoto(Photo photo) {
41 | Picasso.get()
42 | .load(photo.getUrls().getRegular())
43 | .resize(300, 300)
44 | .centerCrop()
45 | .into(mBinding.imageView);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/assetWizardSettings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/splashpicker/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 | dataBinding {
6 | enabled = true
7 | }
8 | defaultConfig {
9 | minSdkVersion 14
10 | targetSdkVersion 28
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | }
25 |
26 | dependencies {
27 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
28 | implementation 'androidx.appcompat:appcompat:1.0.2'
29 | implementation 'androidx.recyclerview:recyclerview:1.0.0'
30 | implementation 'com.google.android.material:material:1.0.0'
31 |
32 | implementation 'com.squareup.picasso:picasso:2.71828'
33 |
34 | implementation 'com.kc.androidunsplash:androidunsplash:1.0.4'
35 | }
36 |
37 | ext {
38 | bintrayRepo = 'SplashPicker'
39 | bintrayName = 'SplashPicker'
40 |
41 | publishedGroupId = 'com.kc.splashpicker'
42 | libraryName = 'splashpicker'
43 | artifact = 'splashpicker'
44 |
45 | libraryDescription = 'An image picker that shows images from Unsplash'
46 |
47 | siteUrl = 'https://github.com/KeenenCharles/SplashPicker'
48 | gitUrl = 'https://github.com/KeenenCharles/SplashPicker.git'
49 |
50 | libraryVersion = '1.1.0'
51 |
52 | developerId = 'keenencharles'
53 | developerName = 'Keenen Charles'
54 | developerEmail = 'keenencharles@gmail.com'
55 |
56 | licenseName = 'MIT License'
57 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
58 | allLicenses = ["MIT"]
59 | }
60 |
61 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
62 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
63 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | Android API 25 Platform
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SplashPicker
2 | An image picker that displays images from Unsplash and lets the user select an image and it's returned to your app.
3 |
4 |
5 |
6 | ## Usage
7 |
8 | ### Open Image Picker
9 | ~~~~~
10 | SplashPicker.open(this, YOUR_CLIENT_ID)
11 | ~~~~~
12 | You can sign up for a Client Id at
13 |
14 | ### Receive the Selected Photo
15 | ~~~~~
16 | @Override
17 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
18 | if(requestCode == SplashPicker.PICK_IMAGE_REQUEST) {
19 | if(resultCode == Activity.RESULT_OK) {
20 | Photo photo = data.getParcelableExtra(SplashPicker.KEY_IMAGE);
21 | }
22 | }
23 | }
24 | ~~~~~
25 |
26 | ## Gradle
27 | Add the line below to your build.gradle to use:
28 | ~~~
29 | dependencies {
30 | implementation 'com.kc.splashpicker:splashpicker:1.1.0'
31 | implementation 'com.kc.androidunsplash:androidunsplash:1.0.4'
32 | }
33 | ~~~
34 |
35 | # License
36 | ~~~
37 | MIT License
38 |
39 | Copyright (c) 2019 Keenen Charles
40 |
41 | Permission is hereby granted, free of charge, to any person obtaining a copy
42 | of this software and associated documentation files (the "Software"), to deal
43 | in the Software without restriction, including without limitation the rights
44 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
45 | copies of the Software, and to permit persons to whom the Software is
46 | furnished to do so, subject to the following conditions:
47 |
48 | The above copyright notice and this permission notice shall be included in all
49 | copies or substantial portions of the Software.
50 |
51 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
54 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
57 | SOFTWARE.
58 |
59 | ~~~
60 |
--------------------------------------------------------------------------------
/splashpicker/src/main/java/com/kc/splashpicker/PhotoRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.kc.splashpicker;
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.ImageView;
8 |
9 | import com.kc.unsplash.models.Photo;
10 | import com.squareup.picasso.Picasso;
11 |
12 | import java.util.List;
13 |
14 | import androidx.recyclerview.widget.RecyclerView;
15 |
16 | public class PhotoRecyclerAdapter extends RecyclerView.Adapter {
17 |
18 | private final List photoList;
19 | private Context mContext;
20 | private OnPhotoClickedListener mListener;
21 |
22 | public PhotoRecyclerAdapter(List photos, Context context, OnPhotoClickedListener listener) {
23 | photoList = photos;
24 | mContext = context;
25 | mListener = listener;
26 | }
27 |
28 | @Override
29 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
30 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_photo, parent, false);
31 | return new ViewHolder(view);
32 | }
33 |
34 | @Override
35 | public void onBindViewHolder(final ViewHolder holder, final int position) {
36 | Photo photo = photoList.get(position);
37 |
38 | holder.imageView.setOnClickListener(new View.OnClickListener() {
39 | @Override
40 | public void onClick(View v) {
41 | mListener.photoClicked(photoList.get(holder.getAdapterPosition()), (ImageView)v);
42 | }
43 | });
44 |
45 | Picasso.get()
46 | .load(photo.getUrls().getRegular())
47 | .resize(300, 300)
48 | .centerCrop()
49 | .into(holder.imageView);
50 | }
51 |
52 | public void addPhotos(List photos){
53 | int lastCount = getItemCount();
54 | photoList.addAll(photos);
55 | notifyItemRangeInserted(lastCount, photos.size());
56 | }
57 |
58 | @Override
59 | public int getItemCount() {
60 | return photoList.size();
61 | }
62 |
63 |
64 | public class ViewHolder extends RecyclerView.ViewHolder {
65 |
66 | public final ImageView imageView;
67 |
68 | public ViewHolder(View view) {
69 | super(view);
70 | imageView = view.findViewById(R.id.imageView);
71 | }
72 |
73 | }
74 |
75 | public interface OnPhotoClickedListener {
76 |
77 | void photoClicked(Photo photo, ImageView imageView);
78 |
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/splashpicker/src/main/res/layout/activity_picker.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
16 |
17 |
27 |
28 |
29 |
30 |
37 |
38 |
53 |
54 |
62 |
63 |
64 |
65 |
68 |
69 |
75 |
76 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/splashpicker/src/main/java/com/kc/splashpicker/views/EndlessRecyclerViewScrollListener.java:
--------------------------------------------------------------------------------
1 | package com.kc.splashpicker.views;
2 |
3 |
4 | import androidx.recyclerview.widget.GridLayoutManager;
5 | import androidx.recyclerview.widget.LinearLayoutManager;
6 | import androidx.recyclerview.widget.RecyclerView;
7 | import androidx.recyclerview.widget.StaggeredGridLayoutManager;
8 |
9 | public abstract class EndlessRecyclerViewScrollListener extends RecyclerView.OnScrollListener {
10 | // The minimum amount of items to have below your current scroll position
11 | // before loading more.
12 | private int visibleThreshold = 5;
13 | // The current offset index of data you have loaded
14 | private int currentPage = 0;
15 | // The total number of items in the dataset after the last load
16 | private int previousTotalItemCount = 0;
17 | // True if we are still waiting for the last set of data to load.
18 | private boolean loading = true;
19 | // Sets the starting page index
20 | private int startingPageIndex = 0;
21 |
22 | RecyclerView.LayoutManager mLayoutManager;
23 |
24 | public EndlessRecyclerViewScrollListener(LinearLayoutManager layoutManager) {
25 | this.mLayoutManager = layoutManager;
26 | }
27 |
28 | public EndlessRecyclerViewScrollListener(GridLayoutManager layoutManager) {
29 | this.mLayoutManager = layoutManager;
30 | visibleThreshold = visibleThreshold * layoutManager.getSpanCount();
31 | }
32 |
33 | public EndlessRecyclerViewScrollListener(StaggeredGridLayoutManager layoutManager) {
34 | this.mLayoutManager = layoutManager;
35 | visibleThreshold = visibleThreshold * layoutManager.getSpanCount();
36 | }
37 |
38 | public int getLastVisibleItem(int[] lastVisibleItemPositions) {
39 | int maxSize = 0;
40 | for (int i = 0; i < lastVisibleItemPositions.length; i++) {
41 | if (i == 0) {
42 | maxSize = lastVisibleItemPositions[i];
43 | }
44 | else if (lastVisibleItemPositions[i] > maxSize) {
45 | maxSize = lastVisibleItemPositions[i];
46 | }
47 | }
48 | return maxSize;
49 | }
50 |
51 | // This happens many times a second during a scroll, so be wary of the code you place here.
52 | // We are given a few useful parameters to help us work out if we need to load some more data,
53 | // but first we check if we are waiting for the previous load to finish.
54 | @Override
55 | public void onScrolled(RecyclerView view, int dx, int dy) {
56 | int lastVisibleItemPosition = 0;
57 | int totalItemCount = mLayoutManager.getItemCount();
58 |
59 | if (mLayoutManager instanceof StaggeredGridLayoutManager) {
60 | int[] lastVisibleItemPositions = ((StaggeredGridLayoutManager) mLayoutManager).findLastVisibleItemPositions(null);
61 | // get maximum element within the list
62 | lastVisibleItemPosition = getLastVisibleItem(lastVisibleItemPositions);
63 | } else if (mLayoutManager instanceof GridLayoutManager) {
64 | lastVisibleItemPosition = ((GridLayoutManager) mLayoutManager).findLastVisibleItemPosition();
65 | } else if (mLayoutManager instanceof LinearLayoutManager) {
66 | lastVisibleItemPosition = ((LinearLayoutManager) mLayoutManager).findLastVisibleItemPosition();
67 | }
68 |
69 | // If the total item count is zero and the previous isn't, assume the
70 | // list is invalidated and should be reset back to initial state
71 | if (totalItemCount < previousTotalItemCount) {
72 | this.currentPage = this.startingPageIndex;
73 | this.previousTotalItemCount = totalItemCount;
74 | if (totalItemCount == 0) {
75 | this.loading = true;
76 | }
77 | }
78 | // If it’s still loading, we check to see if the dataset count has
79 | // changed, if so we conclude it has finished loading and update the current page
80 | // number and total item count.
81 | if (loading && (totalItemCount > previousTotalItemCount)) {
82 | loading = false;
83 | previousTotalItemCount = totalItemCount;
84 | }
85 |
86 | // If it isn’t currently loading, we check to see if we have breached
87 | // the visibleThreshold and need to reload more data.
88 | // If we do need to reload some more data, we execute onLoadMore to fetch the data.
89 | // threshold should reflect how many total columns there are too
90 | if (!loading && (lastVisibleItemPosition + visibleThreshold) > totalItemCount) {
91 | currentPage++;
92 | onLoadMore(currentPage, totalItemCount, view);
93 | loading = true;
94 | }
95 | }
96 |
97 | // Call this method whenever performing new searches
98 | public void resetState() {
99 | this.currentPage = this.startingPageIndex;
100 | this.previousTotalItemCount = 0;
101 | this.loading = true;
102 | }
103 |
104 | // Defines the process for actually loading more data based on page
105 | public abstract void onLoadMore(int page, int totalItemsCount, RecyclerView view);
106 |
107 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/splashpicker/src/main/java/com/kc/splashpicker/PickerActivity.java:
--------------------------------------------------------------------------------
1 | package com.kc.splashpicker;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.KeyEvent;
7 | import android.view.Menu;
8 | import android.view.MenuInflater;
9 | import android.view.MenuItem;
10 | import android.view.View;
11 | import android.view.WindowManager;
12 | import android.view.inputmethod.EditorInfo;
13 | import android.widget.ImageView;
14 | import android.widget.TextView;
15 |
16 | import com.kc.splashpicker.databinding.ActivityPickerBinding;
17 | import com.kc.splashpicker.views.EndlessRecyclerViewScrollListener;
18 | import com.kc.unsplash.Unsplash;
19 | import com.kc.unsplash.api.Order;
20 | import com.kc.unsplash.models.Photo;
21 | import com.kc.unsplash.models.SearchResults;
22 |
23 | import java.util.ArrayList;
24 | import java.util.List;
25 |
26 | import androidx.appcompat.app.AppCompatActivity;
27 | import androidx.databinding.DataBindingUtil;
28 | import androidx.recyclerview.widget.GridLayoutManager;
29 | import androidx.recyclerview.widget.RecyclerView;
30 |
31 | public class PickerActivity extends AppCompatActivity implements PhotoRecyclerAdapter.OnPhotoClickedListener{
32 |
33 | private final String TAG = "PlasterMain";
34 |
35 | private Unsplash unsplash;
36 | private PhotoRecyclerAdapter adapter;
37 |
38 | private int page = 1;
39 | private ActivityPickerBinding mBinding;
40 |
41 | @Override
42 | protected void onCreate(Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 | mBinding = DataBindingUtil.setContentView(this, R.layout.activity_picker);
45 |
46 | setSupportActionBar(mBinding.toolbar);
47 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
48 |
49 | Intent intent = getIntent();
50 | String clientID = intent.getStringExtra("CLIENT_ID");
51 | String title = intent.getStringExtra("TITLE");
52 |
53 | getSupportActionBar().setTitle(title);
54 | unsplash = new Unsplash(clientID);
55 |
56 | setupPhotoGrid();
57 | setupSearch();
58 | }
59 |
60 | private void setupSearch() {
61 | mBinding.searchBar.setOnEditorActionListener(new TextView.OnEditorActionListener() {
62 | @Override
63 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
64 | if ( (actionId == EditorInfo.IME_ACTION_DONE) || ((event.getKeyCode() == KeyEvent.KEYCODE_ENTER) && (event.getAction() == KeyEvent.ACTION_DOWN ))){
65 | search(mBinding.searchBar.getText().toString());
66 | return true;
67 | }
68 | else{
69 | return false;
70 | }
71 | }
72 | });
73 | }
74 |
75 | private void setupPhotoGrid() {
76 | GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
77 | mBinding.recyclerView.setLayoutManager(layoutManager);
78 | adapter = new PhotoRecyclerAdapter(new ArrayList(), this, this);
79 | mBinding.recyclerView.setAdapter(adapter);
80 | mBinding.recyclerView.addOnScrollListener(new EndlessRecyclerViewScrollListener(layoutManager) {
81 | @Override
82 | public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
83 | loadPhotos();
84 | }
85 | });
86 |
87 | loadPhotos();
88 | }
89 |
90 | @Override
91 | public void photoClicked(Photo photo, ImageView imageView) {
92 | Intent intent = new Intent();
93 | intent.putExtra(SplashPicker.KEY_IMAGE, photo);
94 | setResult(RESULT_OK, intent);
95 | finish();
96 | }
97 |
98 | private void loadPhotos() {
99 | mBinding.progressBar.setVisibility(View.VISIBLE);
100 | unsplash.getPhotos(page, null, Order.LATEST, new Unsplash.OnPhotosLoadedListener() {
101 | @Override
102 | public void onComplete(List photos) {
103 | Log.d("Photos", "Photos Fetched " + photos.size());
104 | //add to adapter
105 | page++;
106 | adapter.addPhotos(photos);
107 | mBinding.progressBar.setVisibility(View.GONE);
108 | }
109 |
110 | @Override
111 | public void onError(String error) {
112 |
113 | }
114 | });
115 | }
116 |
117 | public void search(String query){
118 | if(query != null && !query.equals("")) {
119 | mBinding.progressBar.setVisibility(View.VISIBLE);
120 | unsplash.searchPhotos(query, new Unsplash.OnSearchCompleteListener() {
121 | @Override
122 | public void onComplete(SearchResults results) {
123 | Log.d("Photos", "Total Results Found " + results.getTotal());
124 | List photos = results.getResults();
125 | PhotoRecyclerAdapter adapter = new PhotoRecyclerAdapter(photos, PickerActivity.this, PickerActivity.this);
126 | mBinding.recyclerView.setAdapter(adapter);
127 | mBinding.progressBar.setVisibility(View.GONE);
128 | }
129 |
130 | @Override
131 | public void onError(String error) {
132 | Log.d("Unsplash", error);
133 | }
134 | });
135 | }
136 | else {
137 | loadPhotos();
138 | }
139 | }
140 |
141 | private void showSearchBar() {
142 | mBinding.appBarLayout.setVisibility(View.GONE);
143 | mBinding.searchBox.setVisibility(View.VISIBLE);
144 | mBinding.searchBar.requestFocus();
145 | }
146 |
147 | public void hideSearchBar(View view) {
148 | mBinding.searchBox.setVisibility(View.GONE);
149 | mBinding.appBarLayout.setVisibility(View.VISIBLE);
150 | mBinding.searchBar.clearFocus();
151 | getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
152 | }
153 |
154 | @Override
155 | public boolean onCreateOptionsMenu(Menu menu) {
156 | MenuInflater inflater = getMenuInflater();
157 | inflater.inflate(R.menu.menu_main, menu);
158 | return true;
159 | }
160 |
161 | @Override
162 | public boolean onOptionsItemSelected(MenuItem item) {
163 | if(item.getItemId() == R.id.action_search) {
164 | Log.d(TAG, "Search bar open");
165 | showSearchBar();
166 | return true;
167 | }
168 | if(item.getItemId() == android.R.id.home) {
169 | super.onBackPressed();
170 | return true;
171 | }
172 |
173 | return super.onOptionsItemSelected(item);
174 | }
175 |
176 | @Override
177 | public void onBackPressed() {
178 | if(mBinding.searchBox.getVisibility() == View.VISIBLE){
179 | Log.d(TAG, "Search bar visible");
180 | hideSearchBar(null);
181 | return;
182 | }
183 | super.onBackPressed();
184 | }
185 |
186 |
187 | }
188 |
--------------------------------------------------------------------------------