-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unsplash api integration to show university images
- Loading branch information
1 parent
4240542
commit 7f753aa
Showing
13 changed files
with
249 additions
and
86 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/bera/josaahelpertool/models/UniversityImage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.bera.josaahelpertool.models | ||
|
||
import com.bera.josaahelpertool.models.ui.TopHalfItem | ||
import com.google.gson.annotations.SerializedName | ||
|
||
data class UniversityImageResponse( | ||
val results: List<UniversityImage> | ||
) | ||
|
||
data class UniversityImage( | ||
val description: String?, | ||
@SerializedName("alt_description") | ||
val altDescription: String, | ||
val urls: Urls, | ||
) | ||
|
||
data class Urls( | ||
val raw: String, | ||
val full: String, | ||
val regular: String, | ||
val small: String, | ||
val thumb: String, | ||
@SerializedName("small_s3") | ||
val smallS3: String | ||
) | ||
|
||
fun UniversityImage.toModel() = | ||
TopHalfItem(imageUrl = urls.regular, name = description ?: altDescription) |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/bera/josaahelpertool/models/ui/TopHalfItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.bera.josaahelpertool.models.ui | ||
|
||
data class TopHalfItem( | ||
val imageUrl: String, | ||
val name: String | ||
) |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/bera/josaahelpertool/network/UnsplashApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.bera.josaahelpertool.network | ||
|
||
import com.bera.josaahelpertool.models.UniversityImageResponse | ||
import com.bera.josaahelpertool.utils.Constants.API_KEY_UNSPLASH | ||
import com.bera.josaahelpertool.utils.Constants.QUERY | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
interface UnsplashApi { | ||
@GET("search/photos") | ||
suspend fun getUniversityImages( | ||
@Query("page") page: Int = 1, | ||
@Query("client_id") clientId: String = API_KEY_UNSPLASH, | ||
@Query("query") query: String = QUERY, | ||
@Query("per_page") perPage: Int = 30 | ||
): UniversityImageResponse | ||
} |
1 change: 1 addition & 0 deletions
1
app/src/main/java/com/bera/josaahelpertool/repository/QuotesRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/bera/josaahelpertool/repository/UniversityImageRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.bera.josaahelpertool.repository | ||
|
||
import android.util.Log | ||
import com.bera.josaahelpertool.models.UniversityImageResponse | ||
import com.bera.josaahelpertool.network.UnsplashApi | ||
import javax.inject.Inject | ||
import kotlin.random.Random | ||
|
||
class UniversityImageRepository @Inject constructor(private val unsplashApi: UnsplashApi) { | ||
suspend fun getUniversityImages(): UniversityImageResponse { | ||
val page = Random.nextInt(1, 4) | ||
return unsplashApi.getUniversityImages(page) | ||
} | ||
} |
Oops, something went wrong.