├── 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 │ │ │ ├── colors.xml │ │ │ └── styles.xml │ │ ├── menu │ │ │ └── main_menu.xml │ │ └── layout │ │ │ ├── item_photo.xml │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── keenencharles │ │ └── unsplashdemo │ │ ├── PhotoAdapter.kt │ │ └── MainActivity.kt ├── proguard-rules.pro └── build.gradle ├── androidunsplash ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ └── ic_launcher_background.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 │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ └── drawable │ │ │ └── ic_launcher_foreground.xml │ │ ├── ic_launcher-playstore.png │ │ ├── java │ │ └── com │ │ │ └── keenencharles │ │ │ └── unsplash │ │ │ ├── models │ │ │ ├── ContentFilter.kt │ │ │ ├── Order.kt │ │ │ ├── Orientation.kt │ │ │ ├── Download.kt │ │ │ ├── Value.kt │ │ │ ├── Position.kt │ │ │ ├── UserStat.kt │ │ │ ├── SearchResults.kt │ │ │ ├── Portfolio.kt │ │ │ ├── Badge.kt │ │ │ ├── Location.kt │ │ │ ├── ProfileImage.kt │ │ │ ├── UserStats.kt │ │ │ ├── Urls.kt │ │ │ ├── Color.kt │ │ │ ├── Stats.kt │ │ │ ├── Historical.kt │ │ │ ├── Category.kt │ │ │ ├── Token.kt │ │ │ ├── Exif.kt │ │ │ ├── Links.kt │ │ │ ├── CurrentUserCollection.kt │ │ │ ├── CoverPhoto.kt │ │ │ ├── Collection.kt │ │ │ ├── Result.kt │ │ │ ├── Photo.kt │ │ │ └── User.kt │ │ │ ├── api │ │ │ ├── ErrorResponse.kt │ │ │ ├── UnsplashResource.kt │ │ │ ├── Scope.kt │ │ │ ├── endpoints │ │ │ │ ├── StatsEndpointInterface.kt │ │ │ │ ├── AuthEndpointInterface.kt │ │ │ │ ├── CollectionsEndpointInterface.kt │ │ │ │ ├── UserEndpointInterface.kt │ │ │ │ └── PhotosEndpointInterface.kt │ │ │ ├── HeaderInterceptor.kt │ │ │ ├── UnsplashCallback.kt │ │ │ └── UnsplashResponseHandler.kt │ │ │ ├── StatsAPI.kt │ │ │ ├── Unsplash.kt │ │ │ ├── CollectionAPI.kt │ │ │ ├── UserAPI.kt │ │ │ └── PhotoAPI.kt │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── LICENSE ├── gradlew.bat ├── README-JAVA.md ├── README.md └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /androidunsplash/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':androidunsplash' 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /androidunsplash/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Android Unsplash 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /androidunsplash/src/main/ic_launcher-playstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/androidunsplash/src/main/ic_launcher-playstore.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/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/AndroidUnplash/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/AndroidUnplash/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/AndroidUnplash/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/AndroidUnplash/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /androidunsplash/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/androidunsplash/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /androidunsplash/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/androidunsplash/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /androidunsplash/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/androidunsplash/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /androidunsplash/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/androidunsplash/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /androidunsplash/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/androidunsplash/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /androidunsplash/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/androidunsplash/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /androidunsplash/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/androidunsplash/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /androidunsplash/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/androidunsplash/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /androidunsplash/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/androidunsplash/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /androidunsplash/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeenenCharles/AndroidUnplash/HEAD/androidunsplash/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /androidunsplash/src/main/res/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #6328AC 4 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/ContentFilter.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | enum class ContentFilter(val type: String) { 4 | LOW("low"), 5 | HIGH("high"), 6 | } 7 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Order.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | enum class Order(val order: String) { 4 | LATEST("latest"), 5 | OLDEST("oldest"), 6 | POPULAR("popular") 7 | } 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Unsplash Demo 3 | Sign In 4 | Search 5 | Go 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Orientation.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | enum class Orientation(val orientation: String) { 4 | LANDSCAPE("landscape"), 5 | PORTRAIT("portrait"), 6 | SQUARISH("squarish") 7 | } 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Nov 15 17:08:50 BOT 2020 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-7.0.2-all.zip -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Download.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import kotlinx.parcelize.Parcelize 5 | 6 | @Parcelize 7 | data class Download( 8 | var url: String? = null, 9 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/api/ErrorResponse.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.api 2 | 3 | import com.google.gson.annotations.SerializedName 4 | 5 | data class ErrorResponse( 6 | val error: String, 7 | @SerializedName("error_description") val description: String? 8 | ) -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Value.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import kotlinx.parcelize.Parcelize 5 | 6 | @Parcelize 7 | data class Value( 8 | var date: String? = null, 9 | var value: Int? = null, 10 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Position.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import kotlinx.parcelize.Parcelize 5 | 6 | @Parcelize 7 | data class Position( 8 | var latitude: Double? = null, 9 | var longitude: Double? = null 10 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/UserStat.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import kotlinx.parcelize.Parcelize 5 | 6 | @Parcelize 7 | data class UserStat( 8 | var total: Int? = null, 9 | var historical: Historical? = null 10 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/SearchResults.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import com.google.gson.annotations.SerializedName 4 | 5 | data class SearchResults( 6 | var total: Int? = null, 7 | var results: List = listOf(), 8 | @SerializedName("total_pages") var totalPages: Int? = null 9 | ) -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Portfolio.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import com.google.gson.annotations.SerializedName 5 | import kotlinx.parcelize.Parcelize 6 | 7 | @Parcelize 8 | data class Portfolio( 9 | @SerializedName("url") val url: String? = null 10 | ): Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Badge.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import kotlinx.parcelize.Parcelize 5 | 6 | @Parcelize 7 | data class Badge( 8 | var title: String, 9 | var primary: Boolean, 10 | var slug: String, 11 | var link: String 12 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Location.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import kotlinx.parcelize.Parcelize 5 | 6 | @Parcelize 7 | data class Location( 8 | var city: String? = null, 9 | var country: String? = null, 10 | var position: Position? = null 11 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/ProfileImage.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import kotlinx.parcelize.Parcelize 5 | 6 | @Parcelize 7 | data class ProfileImage( 8 | var small: String? = null, 9 | var medium: String? = null, 10 | var large: String? = null 11 | ) : Parcelable -------------------------------------------------------------------------------- /app/src/main/res/menu/main_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/UserStats.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import kotlinx.parcelize.Parcelize 5 | 6 | @Parcelize 7 | data class UserStats( 8 | var username: String? = null, 9 | var downloads: UserStat? = null, 10 | var views: UserStat? = null, 11 | var likes: UserStat? = null 12 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Urls.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import kotlinx.parcelize.Parcelize 5 | 6 | @Parcelize 7 | data class Urls( 8 | var raw: String? = null, 9 | var full: String? = null, 10 | var regular: String? = null, 11 | var small: String? = null, 12 | var thumb: String? = null 13 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/api/UnsplashResource.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.api 2 | 3 | /** 4 | * Class used for API responses 5 | */ 6 | 7 | sealed class UnsplashResource( 8 | val data: T? = null, 9 | val errorMessage: String 10 | ) { 11 | class Success(data: T?) : UnsplashResource(data, "") 12 | class Error(errorMessage: String) : UnsplashResource(null, errorMessage) 13 | } -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Color.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | enum class Color(val color: String) { 4 | BLACK_WHITE("black_and_white"), 5 | BLACK("black"), 6 | WHITE("white"), 7 | ORANGE("orange"), 8 | RED("red"), 9 | PURPLE("purple"), 10 | MAGENTA("magenta"), 11 | GREEN("green"), 12 | TEAL("teal"), 13 | BLUE("blue"), 14 | YELLOW("yellow") 15 | } 16 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Stats.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import com.google.gson.annotations.SerializedName 5 | import kotlinx.parcelize.Parcelize 6 | 7 | @Parcelize 8 | data class Stats( 9 | @SerializedName("total_photos") var totalPhotos: Int? = null, 10 | @SerializedName("photo_downloads") var photoDownloads: Int? = null 11 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Historical.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import kotlinx.parcelize.Parcelize 5 | 6 | @Parcelize 7 | data class Historical( 8 | var change: Int? = null, 9 | var average: Int? = null, 10 | var resolution: String? = null, 11 | var quantity: Int? = null, 12 | var values: List? = null 13 | ) : Parcelable -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Category.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import com.google.gson.annotations.SerializedName 5 | import kotlinx.parcelize.Parcelize 6 | 7 | @Parcelize 8 | data class Category( 9 | var id: Int? = null, 10 | var title: String? = null, 11 | var links: Links? = null, 12 | @SerializedName("photo_count") var photoCount: Int? = null 13 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/api/Scope.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.api 2 | 3 | enum class Scope private constructor(val scope: String) { 4 | 5 | PUBLIC("public"), 6 | READ_USER("read_user"), 7 | WRITE_USER("write_user"), 8 | READ_PHOTOS("read_photos"), 9 | WRITE_PHOTOS("write_photos"), 10 | WRITE_LIKES("write_likes"), 11 | WRITE_FOLLOWERS("write_likes"), 12 | WRITE_COLLECTIONS("write_collections"), 13 | READ_COLLECTIONS("read_collections") 14 | } 15 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Token.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import com.google.gson.annotations.SerializedName 5 | import kotlinx.parcelize.Parcelize 6 | 7 | @Parcelize 8 | data class Token( 9 | var scope: String, 10 | @SerializedName("access_token") var accessToken: String, 11 | @SerializedName("token_type") var tokenType: String, 12 | @SerializedName("created_at") var createdAt: Int 13 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Exif.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import com.google.gson.annotations.SerializedName 5 | import kotlinx.parcelize.Parcelize 6 | 7 | @Parcelize 8 | data class Exif( 9 | var make: String? = null, 10 | var model: String? = null, 11 | var aperture: String? = null, 12 | var iso: Int? = null, 13 | @SerializedName("exposure_time") var exposureTime: String? = null, 14 | @SerializedName("focal_length") var focalLength: String? = null 15 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/api/endpoints/StatsEndpointInterface.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.api.endpoints 2 | 3 | import com.keenencharles.unsplash.models.Stats 4 | import retrofit2.Call 5 | import retrofit2.http.GET 6 | 7 | interface StatsEndpointInterface { 8 | 9 | @GET("stats/total") 10 | fun getTotal(): Call 11 | 12 | @GET("stats/total") 13 | suspend fun getTotalSuspend(): Stats 14 | 15 | @GET("stats/month") 16 | fun getMonth(): Call 17 | 18 | @GET("stats/month") 19 | suspend fun getMonthSuspend(): Stats 20 | 21 | } 22 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Links.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import com.google.gson.annotations.SerializedName 5 | import kotlinx.parcelize.Parcelize 6 | 7 | @Parcelize 8 | data class Links( 9 | var self: String? = null, 10 | var html: String? = null, 11 | var photos: String? = null, 12 | var likes: String? = null, 13 | var portfolio: String? = null, 14 | var download: String? = null, 15 | @SerializedName("download_location") var downloadLocation: String? = null 16 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/CurrentUserCollection.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import com.google.gson.annotations.SerializedName 5 | import kotlinx.parcelize.Parcelize 6 | 7 | @Parcelize 8 | data class CurrentUserCollection( 9 | var id: Int? = null, 10 | var title: String? = null, 11 | var curated: Boolean? = null, 12 | @SerializedName("user") var user: User? = null, 13 | @SerializedName("cover_photo") var coverPhoto: CoverPhoto? = null, 14 | @SerializedName("published_at") var publishedAt: String? = null, 15 | @SerializedName("updated_at") var updatedAt: String? = null, 16 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 11 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/CoverPhoto.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import com.google.gson.annotations.SerializedName 5 | import kotlinx.parcelize.Parcelize 6 | import java.util.* 7 | 8 | @Parcelize 9 | data class CoverPhoto( 10 | var id: String? = null, 11 | var width: Int? = null, 12 | var height: Int? = null, 13 | var color: String? = null, 14 | var likes: Int? = null, 15 | var user: User? = null, 16 | var urls: Urls? = null, 17 | var categories: List = ArrayList(), 18 | var links: Links? = null, 19 | @SerializedName("liked_by_user") var likedByUser: Boolean? = null 20 | ) : Parcelable -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #built application files 2 | *.apk 3 | *.ap_ 4 | *.aab 5 | 6 | # files for the dex VM 7 | *.dex 8 | 9 | # Java class files 10 | *.class 11 | 12 | # generated files 13 | bin/ 14 | gen/ 15 | 16 | # Local configuration file (sdk path, etc) 17 | local.properties 18 | 19 | # Windows thumbnail db 20 | Thumbs.db 21 | 22 | # OSX files 23 | .DS_Store 24 | 25 | # Android Studio 26 | *.iml 27 | .idea 28 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs. 29 | .gradle 30 | build/ 31 | .navigation 32 | captures/ 33 | output.json 34 | 35 | #NDK 36 | obj/ 37 | .externalNativeBuild 38 | 39 | *.gpg 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_photo.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/api/HeaderInterceptor.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.api 2 | 3 | import java.io.IOException 4 | 5 | import okhttp3.Interceptor 6 | import okhttp3.Request 7 | import okhttp3.Response 8 | 9 | class HeaderInterceptor(private val clientId: String, private val token: String?) : Interceptor { 10 | 11 | @Throws(IOException::class) 12 | override fun intercept(chain: Interceptor.Chain): Response { 13 | var auth = "Client-ID $clientId" 14 | if (token != null) { 15 | auth += ",Bearer $token" 16 | } 17 | var request = chain.request() 18 | request = request.newBuilder() 19 | .addHeader("Authorization", auth) 20 | .build() 21 | return chain.proceed(request) 22 | } 23 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | android.enableJetifier=true 2 | android.useAndroidX=true 3 | org.gradle.jvmargs=-Xmx1536m 4 | 5 | GROUP=com.keenencharles 6 | POM_ARTIFACT_ID=androidunsplash 7 | VERSION_NAME=3.1.2 8 | 9 | POM_NAME=androidunsplash 10 | POM_PACKAGING=aar 11 | 12 | POM_DESCRIPTION=An unofficial library to access the Unsplash API. 13 | POM_INCEPTION_YEAR=2017 14 | 15 | POM_URL=https://github.com/KeenenCharles/AndroidUnplash 16 | POM_SCM_URL=https://github.com/KeenenCharles/AndroidUnplash 17 | POM_SCM_CONNECTION=scm:git@github.com:KeenenCharles/AndroidUnplash.git 18 | POM_SCM_DEV_CONNECTION=scm:git@github.com:KeenenCharles/AndroidUnplash.git 19 | 20 | POM_LICENCE_NAME=MIT License 21 | POM_LICENCE_URL=https://github.com/KeenenCharles/AndroidUnplash/blob/master/LICENSE 22 | POM_LICENCE_DIST=repo 23 | 24 | POM_DEVELOPER_ID=KeenenCharles 25 | POM_DEVELOPER_NAME=KeenenCharles 26 | POM_DEVELOPER_URL=https://github.com/KeenenCharles -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Collection.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import com.google.gson.annotations.SerializedName 5 | import kotlinx.parcelize.Parcelize 6 | 7 | @Parcelize 8 | data class Collection( 9 | var id: String? = null, 10 | var title: String? = null, 11 | var description: String? = null, 12 | var curated: Boolean? = null, 13 | var private: Boolean? = null, 14 | var user: User? = null, 15 | var links: Links? = null, 16 | @SerializedName("cover_photo") var coverPhoto: CoverPhoto? = null, 17 | @SerializedName("share_key") var shareKey: String? = null, 18 | @SerializedName("total_photos") var totalPhotos: Int? = null, 19 | @SerializedName("published_at") var publishedAt: String? = null, 20 | @SerializedName("updated_at") var updatedAt: String? = null 21 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Result.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import com.google.gson.annotations.SerializedName 5 | import kotlinx.parcelize.Parcelize 6 | 7 | @Parcelize 8 | data class Result( 9 | var id: String? = null, 10 | var width: Int? = null, 11 | var height: Int? = null, 12 | var color: String? = null, 13 | var likes: Int? = null, 14 | var user: User? = null, 15 | var urls: Urls? = null, 16 | var links: Links? = null, 17 | val categories: List? = null, 18 | @SerializedName("current_user_collections") var currentUserCollections: List? = null, 19 | @SerializedName("liked_by_user") var likedByUser: Boolean? = null, 20 | @SerializedName("created_at") var createdAt: String? = null, 21 | @SerializedName("updated_at") var updatedAt: String? = null 22 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/api/UnsplashCallback.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.api 2 | 3 | import com.google.gson.Gson 4 | import retrofit2.Call 5 | import retrofit2.Callback 6 | import retrofit2.Response 7 | 8 | class UnsplashCallback(private var onComplete: (T) -> Unit, private var onError: (String) -> Unit) : Callback { 9 | 10 | override fun onResponse(call: Call, response: Response) { 11 | when (response.code()) { 12 | in 200..299 -> { 13 | onComplete(response.body()!!) 14 | } 15 | in 400..500 -> { 16 | val res = response.errorBody()?.string()?.trim() 17 | val error = Gson().fromJson(res, ErrorResponse::class.java) 18 | onError(error.description ?: "An error occurred") 19 | } 20 | } 21 | } 22 | 23 | override fun onFailure(call: Call, t: Throwable) { 24 | onError(t.message?: "Error") 25 | } 26 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/api/endpoints/AuthEndpointInterface.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.api.endpoints 2 | 3 | import com.keenencharles.unsplash.models.Token 4 | import retrofit2.Call 5 | import retrofit2.http.POST 6 | import retrofit2.http.Query 7 | import retrofit2.http.Url 8 | 9 | interface AuthEndpointInterface { 10 | 11 | @POST 12 | fun getToken(@Url url: String, 13 | @Query("client_id") clientID: String, 14 | @Query("client_secret") clientSecret: String, 15 | @Query("redirect_uri") redirectURI: String, 16 | @Query("code") code: String, 17 | @Query("grant_type") grantType: String): Call 18 | 19 | @POST 20 | suspend fun getTokenSuspend(@Url url: String, 21 | @Query("client_id") clientID: String, 22 | @Query("client_secret") clientSecret: String, 23 | @Query("redirect_uri") redirectURI: String, 24 | @Query("code") code: String, 25 | @Query("grant_type") grantType: String): Token 26 | } 27 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/Photo.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import com.google.gson.annotations.SerializedName 5 | import kotlinx.parcelize.Parcelize 6 | import java.util.* 7 | 8 | @Parcelize 9 | data class Photo( 10 | var id: String? = null, 11 | var width: Int? = null, 12 | var height: Int? = null, 13 | var color: String? = null, 14 | var downloads: Int? = null, 15 | var likes: Int? = null, 16 | var exif: Exif? = null, 17 | var location: Location? = null, 18 | var urls: Urls? = null, 19 | var links: Links? = null, 20 | var user: User? = null, 21 | var categories: List = ArrayList(), 22 | @SerializedName("current_user_collections") var currentUserCollections: List = ArrayList(), 23 | @SerializedName("liked_by_user") var likedByUser: Boolean? = null, 24 | @SerializedName("created_at") var createdAt: String? = null, 25 | @SerializedName("updated_at") var updatedAt: String? = null 26 | ) : Parcelable -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 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 | -------------------------------------------------------------------------------- /androidunsplash/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 | 27 | -keep class com.keenencharles.unsplash.models.** { *; } 28 | -keep class kotlin.coroutines.Continuation { *; } -------------------------------------------------------------------------------- /androidunsplash/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-parcelize' 4 | apply plugin: 'com.vanniktech.maven.publish' 5 | 6 | android { 7 | compileSdkVersion 30 8 | defaultConfig { 9 | minSdkVersion 16 10 | targetSdkVersion 30 11 | 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | consumerProguardFiles("proguard-rules.pro") 14 | } 15 | compileOptions { 16 | sourceCompatibility JavaVersion.VERSION_1_8 17 | targetCompatibility JavaVersion.VERSION_1_8 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | 24 | implementation 'androidx.appcompat:appcompat:1.3.1' 25 | implementation 'androidx.browser:browser:1.3.0' 26 | implementation "androidx.core:core-ktx:1.6.0" 27 | 28 | implementation "com.squareup.okhttp3:okhttp:4.9.0" 29 | implementation "com.squareup.okhttp3:logging-interceptor:4.9.0" 30 | implementation 'com.squareup.retrofit2:converter-gson:2.9.0' 31 | implementation("com.squareup.retrofit2:retrofit:2.9.0") { 32 | exclude module: "okhttp" 33 | } 34 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/api/UnsplashResponseHandler.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.api 2 | 3 | import com.google.gson.Gson 4 | import retrofit2.HttpException 5 | import java.net.ConnectException 6 | import java.net.SocketTimeoutException 7 | 8 | class UnsplashResponseHandler { 9 | 10 | fun handleSuccess(data: T? = null): UnsplashResource.Success { 11 | return UnsplashResource.Success(data) 12 | } 13 | 14 | fun handleException(e: Exception): UnsplashResource.Error { 15 | return when (e) { 16 | is ConnectException -> { 17 | UnsplashResource.Error("Connection Error") 18 | } 19 | is HttpException -> { 20 | val res = e.response()?.errorBody()?.string()?.trim() 21 | val error = Gson().fromJson(res, ErrorResponse::class.java) 22 | val message = error.description ?: "An error occurred" 23 | UnsplashResource.Error(message) 24 | } 25 | is SocketTimeoutException -> { 26 | UnsplashResource.Error("Timeout") 27 | } 28 | else -> { 29 | UnsplashResource.Error("Unknown Error") 30 | } 31 | } 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/models/User.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash.models 2 | 3 | import android.os.Parcelable 4 | import com.google.gson.annotations.SerializedName 5 | import kotlinx.parcelize.Parcelize 6 | 7 | @Parcelize 8 | data class User( 9 | var id: String? = null, 10 | var username: String? = null, 11 | var name: String? = null, 12 | var bio: String? = null, 13 | var location: String? = null, 14 | var totalLikes: Int? = null, 15 | var downloads: Int? = null, 16 | var badge: Badge? = null, 17 | var links: Links? = null, 18 | @SerializedName("current_user_collections") var currentUserCollections: List? = null, 19 | @SerializedName("profile_image") var profileImage: ProfileImage? = null, 20 | @SerializedName("total_photos") var totalPhotos: Int? = null, 21 | @SerializedName("total_collections") var totalCollections: Int? = null, 22 | @SerializedName("followed_by_user") var followedByUser: Boolean? = null, 23 | @SerializedName("followers_count") var followersCount: Int? = null, 24 | @SerializedName("first_name") var firstName: String? = null, 25 | @SerializedName("last_name") var lastName: String? = null, 26 | @SerializedName("instagram_username") var instagramUsername: String? = null, 27 | @SerializedName("twitter_username") var twitterUsername: String? = null, 28 | @SerializedName("portfolio_url") var portfolioUrl: String? = null, 29 | @SerializedName("updated_at") var updatedAt: String? = null 30 | ) : Parcelable -------------------------------------------------------------------------------- /androidunsplash/src/main/java/com/keenencharles/unsplash/StatsAPI.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplash 2 | 3 | import com.keenencharles.unsplash.api.UnsplashCallback 4 | import com.keenencharles.unsplash.api.UnsplashResource 5 | import com.keenencharles.unsplash.api.UnsplashResponseHandler 6 | import com.keenencharles.unsplash.api.endpoints.StatsEndpointInterface 7 | import com.keenencharles.unsplash.models.Stats 8 | 9 | @JvmSuppressWildcards 10 | class StatsAPI( 11 | private var apiService: StatsEndpointInterface, 12 | private var responseHandler: UnsplashResponseHandler 13 | ) { 14 | 15 | fun getTotal( 16 | onComplete: (Stats) -> Unit, 17 | onError: (String) -> Unit 18 | ) { 19 | val call = apiService.getTotal() 20 | call.enqueue(UnsplashCallback(onComplete, onError)) 21 | } 22 | 23 | suspend fun getTotal(): UnsplashResource { 24 | return try { 25 | val res = apiService.getTotalSuspend() 26 | responseHandler.handleSuccess(res) 27 | 28 | } catch (e: Exception) { 29 | responseHandler.handleException(e) 30 | } 31 | } 32 | 33 | fun getMonth( 34 | onComplete: (Stats) -> Unit, 35 | onError: (String) -> Unit 36 | ) { 37 | val call = apiService.getMonth() 38 | call.enqueue(UnsplashCallback(onComplete, onError)) 39 | } 40 | 41 | suspend fun getMonth(): UnsplashResource { 42 | return try { 43 | val res = apiService.getMonthSuspend() 44 | responseHandler.handleSuccess(res) 45 | 46 | } catch (e: Exception) { 47 | responseHandler.handleException(e) 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/keenencharles/unsplashdemo/PhotoAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.keenencharles.unsplashdemo 2 | 3 | import android.view.LayoutInflater 4 | import android.view.ViewGroup 5 | import androidx.recyclerview.widget.RecyclerView 6 | import com.keenencharles.unsplash.models.Photo 7 | import com.keenencharles.unsplashdemo.databinding.ItemPhotoBinding 8 | import com.squareup.picasso.Picasso 9 | import java.util.Collections.emptyList 10 | 11 | class PhotoAdapter(private var onSelected: (Photo) -> Unit) : RecyclerView.Adapter() { 12 | 13 | private var photos: List = emptyList() 14 | 15 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 16 | val layoutInflater = LayoutInflater.from(parent.context) 17 | val itemBinding = ItemPhotoBinding.inflate(layoutInflater, parent, false) 18 | return ViewHolder(itemBinding) 19 | } 20 | 21 | override fun onBindViewHolder(holder: ViewHolder, position: Int) { 22 | val photo = photos[position] 23 | holder.bind(photo) 24 | 25 | 26 | holder.binding.root.setOnClickListener { 27 | run { 28 | onSelected(photo) 29 | } 30 | } 31 | } 32 | 33 | override fun getItemCount(): Int { 34 | return photos.size 35 | } 36 | 37 | fun updateList(items: List) { 38 | this.photos = items 39 | notifyDataSetChanged() 40 | } 41 | 42 | inner class ViewHolder(val binding: ItemPhotoBinding) : RecyclerView.ViewHolder(binding.root) { 43 | 44 | fun bind(photo: Photo) { 45 | Picasso.get().load(photo.urls?.small).into(binding.imageView) 46 | binding.executePendingBindings() 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-kapt' 4 | apply plugin: 'kotlin-parcelize' 5 | 6 | Properties properties = new Properties() 7 | properties.load(project.rootProject.file("local.properties").newDataInputStream()) 8 | 9 | android { 10 | compileSdkVersion 30 11 | defaultConfig { 12 | applicationId "com.keenencharles.unsplashdemo" 13 | minSdkVersion 16 14 | targetSdkVersion 30 15 | versionCode 1 16 | versionName "0.1.3" 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | compileOptions { 20 | sourceCompatibility JavaVersion.VERSION_1_8 21 | targetCompatibility JavaVersion.VERSION_1_8 22 | } 23 | buildTypes { 24 | debug { 25 | buildConfigField "String", "UnsplashID", properties.getProperty("unsplash.id", "") 26 | buildConfigField "String", "UnsplashSecret", properties.getProperty("unsplash.secret", "") 27 | } 28 | } 29 | buildFeatures { 30 | dataBinding = true 31 | } 32 | } 33 | 34 | dependencies { 35 | implementation fileTree(dir: 'libs', include: ['*.jar']) 36 | implementation project(':androidunsplash') 37 | 38 | implementation 'androidx.appcompat:appcompat:1.3.1' 39 | implementation 'androidx.recyclerview:recyclerview:1.2.1' 40 | implementation 'androidx.core:core-ktx:1.6.0' 41 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3' 42 | 43 | implementation 'com.google.android.material:material:1.4.0' 44 | implementation 'com.google.code.gson:gson:2.8.6' 45 | 46 | implementation 'com.squareup.picasso:picasso:2.71828' 47 | implementation 'com.squareup.okhttp3:okhttp:4.9.0' 48 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 11 | 18 | 19 | 33 | 34 |