├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_download.png
│ │ │ │ ├── gradient.xml
│ │ │ │ ├── bg_white_round_top.xml
│ │ │ │ ├── ic_close.xml
│ │ │ │ ├── ic_photo.xml
│ │ │ │ ├── ic_save.xml
│ │ │ │ ├── ic_image_error.xml
│ │ │ │ ├── ic_search.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
│ │ │ ├── menu
│ │ │ │ ├── menu_details.xml
│ │ │ │ └── menu_gallery.xml
│ │ │ ├── layout
│ │ │ │ ├── footer_photo_load_state.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── item_photo.xml
│ │ │ │ ├── fragment_gallery.xml
│ │ │ │ ├── bottom_sheet_loading.xml
│ │ │ │ └── fragment_details.xml
│ │ │ ├── navigation
│ │ │ │ └── nav_graph.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── raw
│ │ │ │ ├── download2.json
│ │ │ │ └── download.json
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── myphotoloaderapp
│ │ │ │ ├── Util
│ │ │ │ ├── Common
│ │ │ │ │ ├── CommonUtils.kt
│ │ │ │ │ ├── FragmentUtils.kt
│ │ │ │ │ ├── StringUtils.kt
│ │ │ │ │ ├── TextviewUtils.kt
│ │ │ │ │ ├── ActivityUtils.kt
│ │ │ │ │ ├── ViewUtils.kt
│ │ │ │ │ ├── Other.kt
│ │ │ │ │ └── ContextUtils.kt
│ │ │ │ └── StorageUtil.kt
│ │ │ │ ├── UI
│ │ │ │ ├── details
│ │ │ │ │ ├── DetailsViewModel.kt
│ │ │ │ │ └── DetailsFragment.kt
│ │ │ │ └── gallery
│ │ │ │ │ ├── GalleryViewModel.kt
│ │ │ │ │ ├── PhotoLoadStateAdapter.kt
│ │ │ │ │ ├── PhotoAdapter.kt
│ │ │ │ │ └── GalleryFragment.kt
│ │ │ │ ├── MyApp.kt
│ │ │ │ ├── network
│ │ │ │ ├── PhotoResponse.kt
│ │ │ │ └── PhotoApi.kt
│ │ │ │ ├── data
│ │ │ │ ├── PhotoRepository.kt
│ │ │ │ ├── MyPhoto.kt
│ │ │ │ └── PhotoPagingSource.kt
│ │ │ │ ├── di
│ │ │ │ └── AppModule.kt
│ │ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── myphotoloaderapp
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── myphotoloaderapp
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── screenshots
├── .gitkeep
├── photo5803347900867130566.jpg
├── photo5803347900867130568.jpg
├── photo5803347900867130569.jpg
└── photo5803347900867130570.jpg
├── settings.gradle
├── .idea
├── .gitignore
├── codeStyles
│ ├── codeStyleConfig.xml
│ └── Project.xml
├── compiler.xml
├── vcs.xml
├── runConfigurations.xml
├── $PROJECT_FILE$
├── qaplug_profiles.xml
├── misc.xml
├── gradle.xml
└── jarRepositories.xml
├── Apk
└── MyPhotoLoader.apk
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/screenshots/.gitkeep:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name = "MyPhotoLoaderApp"
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/Apk/MyPhotoLoader.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/behnawwm/MyPhotoLoaderApp/HEAD/Apk/MyPhotoLoader.apk
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MyPhotoLoaderApp
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/behnawwm/MyPhotoLoaderApp/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/behnawwm/MyPhotoLoaderApp/HEAD/app/src/main/res/drawable/ic_download.png
--------------------------------------------------------------------------------
/screenshots/photo5803347900867130566.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/behnawwm/MyPhotoLoaderApp/HEAD/screenshots/photo5803347900867130566.jpg
--------------------------------------------------------------------------------
/screenshots/photo5803347900867130568.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/behnawwm/MyPhotoLoaderApp/HEAD/screenshots/photo5803347900867130568.jpg
--------------------------------------------------------------------------------
/screenshots/photo5803347900867130569.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/behnawwm/MyPhotoLoaderApp/HEAD/screenshots/photo5803347900867130569.jpg
--------------------------------------------------------------------------------
/screenshots/photo5803347900867130570.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/behnawwm/MyPhotoLoaderApp/HEAD/screenshots/photo5803347900867130570.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/behnawwm/MyPhotoLoaderApp/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/behnawwm/MyPhotoLoaderApp/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/behnawwm/MyPhotoLoaderApp/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/behnawwm/MyPhotoLoaderApp/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/behnawwm/MyPhotoLoaderApp/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/behnawwm/MyPhotoLoaderApp/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/behnawwm/MyPhotoLoaderApp/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/behnawwm/MyPhotoLoaderApp/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/Util/Common/CommonUtils.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.Util
2 |
3 | fun Any?.isNull() = this == null
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/behnawwm/MyPhotoLoaderApp/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/behnawwm/MyPhotoLoaderApp/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/UI/details/DetailsViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.UI.details
2 |
3 | import androidx.lifecycle.ViewModel
4 |
5 |
6 | class DetailsViewModel : ViewModel() {
7 |
8 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/MyApp.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp
2 |
3 | import android.app.Application
4 | import dagger.hilt.android.HiltAndroidApp
5 |
6 |
7 | @HiltAndroidApp
8 | class MyApp : Application() {
9 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/network/PhotoResponse.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.network
2 |
3 | import com.example.myphotoloaderapp.data.MyPhoto
4 |
5 | data class PhotoResponse(
6 | var results: List
7 | ) {
8 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun May 02 10:29:36 IRDT 2021
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-6.5-all.zip
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/Util/StorageUtil.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.Util
2 |
3 | import android.os.Build
4 |
5 | inline fun sdk29AndUp(onSdk29: () -> T): T? {
6 | return if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
7 | onSdk29()
8 | } else null
9 | }
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/gradient.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/Util/Common/FragmentUtils.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.Util.Common
2 |
3 | import android.widget.Toast
4 | import androidx.fragment.app.Fragment
5 |
6 | /**
7 | * Extension method to display toast text for SupportFragment.
8 | */
9 | fun Fragment.toast(text: CharSequence, duration: Int = Toast.LENGTH_LONG) = this?.let { activity.toast(text, duration) }
--------------------------------------------------------------------------------
/.idea/$PROJECT_FILE$:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_details.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_white_round_top.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
12 |
--------------------------------------------------------------------------------
/.idea/qaplug_profiles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/myphotoloaderapp/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_gallery.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_close.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_photo.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_save.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_image_error.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
11 |
12 | #6200EE
13 | #3700B3
14 | #03DAC5
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_search.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/data/PhotoRepository.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.data
2 |
3 | import androidx.paging.Pager
4 | import androidx.paging.PagingConfig
5 | import androidx.paging.liveData
6 | import com.example.myphotoloaderapp.network.PhotoApi
7 | import javax.inject.Inject
8 | import javax.inject.Singleton
9 |
10 | @Singleton
11 | class PhotoRepository @Inject constructor(var api: PhotoApi) {
12 |
13 | fun getSearchResults(query: String) =
14 | Pager(
15 | config = PagingConfig(
16 | pageSize = 10,
17 | maxSize = 50,
18 | enablePlaceholders = false
19 | ),
20 | pagingSourceFactory = { PhotoPagingSource(api, query) }
21 | ).liveData
22 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/network/PhotoApi.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.network
2 |
3 | import com.example.myphotoloaderapp.BuildConfig
4 | import retrofit2.http.GET
5 | import retrofit2.http.Header
6 | import retrofit2.http.Headers
7 | import retrofit2.http.Query
8 |
9 | interface PhotoApi {
10 |
11 | companion object {
12 | const val ACCESS_KEY = BuildConfig.UNSPLASH_ACCESS_KEY
13 | const val BASE_URL = "https://api.unsplash.com/"
14 | }
15 |
16 | @Headers("Accept-Version: v1", "Authorization: Client-ID $ACCESS_KEY")
17 | @GET("search/photos")
18 | suspend fun searchPhoto(
19 | @Query("query") query: String,
20 | @Query("page") page: Int,
21 | @Query("per_page") perPage: Int
22 | ): PhotoResponse
23 |
24 |
25 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/data/MyPhoto.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.data
2 |
3 | import android.os.Parcelable
4 | import kotlinx.android.parcel.Parcelize
5 |
6 | @Parcelize
7 | data class MyPhoto(
8 | var id: String,
9 | var desc: String?,
10 | var urls: PhotoUrls,
11 | var user: User
12 | ) : Parcelable {
13 |
14 | @Parcelize
15 | data class PhotoUrls(
16 | var raw: String,
17 | var full: String,
18 | var regular: String,
19 | var thumb: String
20 | ) : Parcelable
21 |
22 | @Parcelize
23 | data class User(
24 | var username: String,
25 | var name: String
26 | ) : Parcelable {
27 | val attributionUrl get() = "https://unsplash.com/$username?utm_source=MyImageLoader&utm_medium=referral"
28 | }
29 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/myphotoloaderapp/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.example.myphotoloaderapp", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/Util/Common/StringUtils.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.Util.Common
2 |
3 |
4 | /**
5 | * Extension method to check if String is Phone Number.
6 | */
7 | fun String.isPhone(): Boolean {
8 | val p = "^1([34578])\\d{9}\$".toRegex()
9 | return matches(p)
10 | }
11 |
12 | /**
13 | * Extension method to check if String is Email.
14 | */
15 | fun String.isEmail(): Boolean {
16 | val p = "^(\\w)+(\\.\\w+)*@(\\w)+((\\.\\w+)+)\$".toRegex()
17 | return matches(p)
18 | }
19 |
20 | /**
21 | * Extension method to check if String is Number.
22 | */
23 | fun String.isNumeric(): Boolean {
24 | val p = "^[0-9]+$".toRegex()
25 | return matches(p)
26 | }
27 | /**
28 | * Extension method to check String equalsIgnoreCase
29 | */
30 | fun String.equalsIgnoreCase(other: String) = this.toLowerCase().contentEquals(other.toLowerCase())
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/di/AppModule.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.di
2 |
3 | import com.example.myphotoloaderapp.network.PhotoApi
4 | import dagger.Module
5 | import dagger.Provides
6 | import dagger.hilt.InstallIn
7 | import dagger.hilt.android.components.ApplicationComponent
8 | import retrofit2.Retrofit
9 | import retrofit2.converter.gson.GsonConverterFactory
10 | import javax.inject.Singleton
11 |
12 |
13 | @Module
14 | @InstallIn(ApplicationComponent::class)
15 | object AppModule {
16 |
17 | @Provides
18 | @Singleton
19 | fun provideRetrofit(): Retrofit =
20 | Retrofit.Builder()
21 | .baseUrl(PhotoApi.BASE_URL)
22 | .addConverterFactory(GsonConverterFactory.create())
23 | .build()
24 |
25 | @Provides
26 | @Singleton
27 | fun provideApi(retrofit: Retrofit): PhotoApi =
28 | retrofit.create(PhotoApi::class.java)
29 |
30 |
31 | }
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/footer_photo_load_state.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
19 |
20 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/UI/gallery/GalleryViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.UI.gallery
2 |
3 | import androidx.hilt.Assisted
4 | import androidx.hilt.lifecycle.ViewModelInject
5 | import androidx.lifecycle.SavedStateHandle
6 | import androidx.lifecycle.ViewModel
7 | import androidx.lifecycle.switchMap
8 | import androidx.lifecycle.viewModelScope
9 | import androidx.paging.cachedIn
10 | import com.example.myphotoloaderapp.data.PhotoRepository
11 |
12 |
13 | class GalleryViewModel @ViewModelInject constructor(
14 | private val repository: PhotoRepository,
15 | @Assisted state: SavedStateHandle
16 | ) : ViewModel() {
17 |
18 | private val currentQuery = state.getLiveData(CURRENT_QUERY, DEFAULT_QUERY)
19 |
20 | var photos = currentQuery.switchMap { queryString ->
21 | repository.getSearchResults(queryString).cachedIn(viewModelScope)
22 | }
23 |
24 | fun searchPhotos(query: String) {
25 | currentQuery.value = query
26 | }
27 |
28 | companion object {
29 | private const val CURRENT_QUERY = "unique_query!"
30 | private const val DEFAULT_QUERY = "Nature"
31 | }
32 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/navigation/nav_graph.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
16 |
17 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/data/PhotoPagingSource.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.data
2 |
3 | import androidx.paging.PagingSource
4 | import com.example.myphotoloaderapp.network.PhotoApi
5 | import retrofit2.HttpException
6 | import java.io.IOException
7 |
8 | private const val STARTING_PAGE_INDEX = 1
9 |
10 | class PhotoPagingSource(
11 | var api: PhotoApi,
12 | var query: String
13 | ) : PagingSource() {
14 |
15 | override suspend fun load(params: LoadParams): LoadResult {
16 | val posistion = params.key ?: STARTING_PAGE_INDEX
17 |
18 | return try {
19 | val response = api.searchPhoto(query, posistion, params.loadSize)
20 | val photos: List = response.results
21 |
22 | LoadResult.Page(
23 | data = photos,
24 | prevKey = if (posistion == STARTING_PAGE_INDEX) null else posistion - 1,
25 | nextKey = if (photos.isEmpty()) null else posistion + 1
26 | )
27 | } catch (ex: IOException) {
28 | LoadResult.Error(ex)
29 | } catch (ex: HttpException) {
30 | LoadResult.Error(ex)
31 | }
32 |
33 |
34 | }
35 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/Util/Common/TextviewUtils.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.Util.Common
2 |
3 | import android.text.Spannable
4 | import android.text.style.ForegroundColorSpan
5 | import android.util.Log
6 | import android.widget.TextView
7 | import androidx.core.content.ContextCompat
8 |
9 | /**
10 | * Extension method to set different color for substring TextView.
11 | */
12 | fun TextView.setColorOfSubstring(substring: String, color: Int) {
13 | try {
14 | val spannable = android.text.SpannableString(text)
15 | val start = text.indexOf(substring)
16 | spannable.setSpan(
17 | ForegroundColorSpan(
18 | ContextCompat.getColor(context, color)
19 | ), start, start + substring.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
20 | )
21 | text = spannable
22 | } catch (e: Exception) {
23 | Log.d(
24 | "ViewExtensions",
25 | "exception in setColorOfSubstring, text=$text, substring=$substring",
26 | e
27 | )
28 | }
29 | }
30 |
31 | /**
32 | * Extension method to set a drawable to the left of a TextView.
33 | */
34 | fun TextView.setDrawableLeft(drawable: Int) {
35 | this.setCompoundDrawablesWithIntrinsicBounds(drawable, 0, 0, 0)
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_photo.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
18 |
19 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import androidx.navigation.NavController
6 | import androidx.navigation.fragment.NavHostFragment
7 | import androidx.navigation.fragment.findNavController
8 | import androidx.navigation.ui.AppBarConfiguration
9 | import androidx.navigation.ui.setupActionBarWithNavController
10 | import dagger.hilt.android.AndroidEntryPoint
11 |
12 | @AndroidEntryPoint
13 | class MainActivity : AppCompatActivity() {
14 | private lateinit var navController: NavController
15 |
16 | override fun onCreate(savedInstanceState: Bundle?) {
17 | super.onCreate(savedInstanceState)
18 | setContentView(R.layout.activity_main)
19 |
20 | val navHostFragment =
21 | supportFragmentManager.findFragmentById(R.id.nav_host_main) as NavHostFragment
22 | navController = navHostFragment.findNavController()
23 |
24 | val appBarConfiguration = AppBarConfiguration(navController.graph)
25 | setupActionBarWithNavController(navController, appBarConfiguration)
26 |
27 | }
28 |
29 | override fun onSupportNavigateUp(): Boolean {
30 | return navController.navigateUp() || super.onSupportNavigateUp()
31 | }
32 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
23 |
24 | #unsplash_access_key = "XVnsZlEUSduNJux8gHGWYb27hhTeOOiSrq-HerXrDnM"
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/Util/Common/ActivityUtils.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.Util.Common
2 |
3 | import android.app.Activity
4 | import android.os.Build
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import android.view.WindowManager
8 | import androidx.annotation.IdRes
9 | import androidx.appcompat.app.ActionBar
10 | import androidx.appcompat.app.AppCompatActivity
11 |
12 | /**
13 | * Extension method to set Status Bar Color and Status Bar Icon Color Type(dark/light)
14 | */
15 | enum class StatusIconColorType {
16 | Dark, Light
17 | }
18 | fun Activity.setStatusBarColor(color: Int, iconColorType: StatusIconColorType = StatusIconColorType.Light) {
19 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
20 | this.window.apply {
21 | clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
22 | statusBarColor = color
23 | decorView.systemUiVisibility = when (iconColorType) {
24 | StatusIconColorType.Dark -> View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
25 | StatusIconColorType.Light -> 0
26 | }
27 | }
28 | } else
29 | this.window.statusBarColor = color
30 | }
31 |
32 | /**
33 | * Setup actionbar
34 | */
35 | fun AppCompatActivity.setupActionBar(@IdRes toolbarId: Int, action: ActionBar.() -> Unit) {
36 | setSupportActionBar(findViewById(toolbarId))
37 | supportActionBar?.run {
38 | action()
39 | }
40 | }
41 |
42 | /**
43 | * Extension method to get ContentView for ViewGroup.
44 | */
45 | fun Activity.getContentView(): ViewGroup {
46 | return this.findViewById(android.R.id.content) as ViewGroup
47 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/UI/gallery/PhotoLoadStateAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.UI.gallery
2 |
3 | import android.view.LayoutInflater
4 | import android.view.ViewGroup
5 | import androidx.core.view.isVisible
6 | import androidx.paging.LoadState
7 | import androidx.paging.LoadStateAdapter
8 | import androidx.recyclerview.widget.RecyclerView
9 | import com.example.myphotoloaderapp.databinding.FooterPhotoLoadStateBinding
10 |
11 | class PhotoLoadStateAdapter(private val retry: () -> Unit) :
12 | LoadStateAdapter() {
13 |
14 | override fun onCreateViewHolder(parent: ViewGroup, loadState: LoadState): LoadStateViewHolder {
15 | val binding = FooterPhotoLoadStateBinding.inflate(
16 | LayoutInflater.from(parent.context), parent, false
17 | )
18 | return LoadStateViewHolder(binding)
19 | }
20 |
21 | override fun onBindViewHolder(holder: LoadStateViewHolder, loadState: LoadState) {
22 | holder.bind(loadState)
23 |
24 | }
25 |
26 |
27 | inner class LoadStateViewHolder(
28 | private val binding: FooterPhotoLoadStateBinding
29 | ) : RecyclerView.ViewHolder(binding.root) {
30 |
31 | init {
32 | binding.buttonRetry.setOnClickListener {
33 | retry.invoke()
34 | }
35 | }
36 |
37 | fun bind(loadState: LoadState) {
38 | binding.apply {
39 | progressBar.isVisible = loadState is LoadState.Loading
40 | buttonRetry.isVisible = loadState !is LoadState.Loading
41 | textViewError.isVisible = loadState is LoadState.Loading
42 | }
43 | }
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.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 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/Util/Common/ViewUtils.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.Util.Common
2 |
3 | import android.graphics.Bitmap
4 | import android.graphics.Canvas
5 | import android.view.View
6 | import com.google.android.material.snackbar.BaseTransientBottomBar
7 | import com.google.android.material.snackbar.Snackbar
8 |
9 | ///**
10 | // * Extension method to simplify view binding.
11 | // */
12 | //fun View.bind() = DataBindingUtil.bind(this) as T
13 | //
14 | ///**
15 | // * Extension method to provide quicker access to the [LayoutInflater] from a [View].
16 | // */
17 | //fun View.getLayoutInflater() = context.getLayoutInflater()
18 |
19 |
20 | /**
21 | * Show a snackbar with [message]
22 | */
23 | inline fun View.snack(
24 | message: String,
25 | @BaseTransientBottomBar.Duration length: Int = Snackbar.LENGTH_LONG,
26 | f: Snackbar.() -> Unit
27 | ) {
28 | val snack = Snackbar.make(this, message, length)
29 | snack.f()
30 | snack.show()
31 | }
32 |
33 |
34 | /**
35 | * Extension method to get a view as bitmap.
36 | */
37 | fun View.getBitmap(): Bitmap {
38 | val bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
39 | val canvas = Canvas(bmp)
40 | draw(canvas)
41 | canvas.save()
42 | return bmp
43 | }
44 |
45 | /**
46 | * Toggle a view's visibility
47 | */
48 | fun View.toggleVisibility(): View {
49 | if (visibility == View.VISIBLE) {
50 | visibility = View.INVISIBLE
51 | } else {
52 | visibility = View.INVISIBLE
53 | }
54 | return this
55 | }
56 |
57 | fun View.invisible(): View {
58 | visibility = View.INVISIBLE
59 | return this
60 | }
61 | /**
62 | * Set an onclick listener
63 | */
64 | fun T.click(block: (T) -> Unit) = setOnClickListener { block(it as T) }
65 |
66 | /**
67 | * Extension method to set OnClickListener on a view.
68 | */
69 | fun T.longClick(block: (T) -> Boolean) = setOnLongClickListener { block(it as T) }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/Util/Common/Other.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.Util.Common
2 |
3 | import android.content.SharedPreferences
4 | import android.graphics.Bitmap
5 | import android.os.Build
6 | import android.widget.ImageView
7 | import com.bumptech.glide.Glide
8 | import java.io.File
9 | import java.io.FileOutputStream
10 |
11 | /**
12 | * Extension method to load imageView from url.
13 | */
14 | fun ImageView.loadFromUrl(imageUrl: String) {
15 | Glide.with(this).load(imageUrl).into(this)
16 | }
17 |
18 | /**
19 | * Extension method to write preferences.
20 | */
21 | inline fun SharedPreferences.edit(preferApply: Boolean = false, f: SharedPreferences.Editor.() -> Unit) {
22 | val editor = edit()
23 | editor.f()
24 | if (preferApply) editor.apply() else editor.commit()
25 | }
26 |
27 | /**
28 | * Extension method to check is aboveApi.
29 | */
30 | inline fun aboveApi(api: Int, included: Boolean = false, block: () -> Unit) {
31 | if (Build.VERSION.SDK_INT > if (included) api - 1 else api) {
32 | block()
33 | }
34 | }
35 |
36 | /**
37 | * Extension method to check is belowApi.
38 | */
39 | inline fun belowApi(api: Int, included: Boolean = false, block: () -> Unit) {
40 | if (Build.VERSION.SDK_INT < if (included) api + 1 else api) {
41 | block()
42 | }
43 | }
44 |
45 | /**
46 | * Extension method to save Bitmap to specified file path.
47 | */
48 | fun Bitmap.saveFile(path: String) {
49 | val f = File(path)
50 | if (!f.exists()) {
51 | f.createNewFile()
52 | }
53 | val stream = FileOutputStream(f)
54 | compress(Bitmap.CompressFormat.PNG, 100, stream)
55 | stream.flush()
56 | stream.close()
57 | }
58 |
59 | ///**
60 | // * Extension method to get connectivityManager for Context.
61 | // */
62 | //inline val connectivityManager: ConnectivityManager
63 | // get() = Ext.ctx.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
64 |
65 | /**
66 | * Extension method to get the TAG name for all object
67 | */
68 | fun T.TAG() = this::class.simpleName
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | MyPhotoLoaderApp
2 |
3 | Simple photo loading app powered by [Unsplash.com](https://unsplash.com)
4 |
5 | ## Features
6 | - Vieweing the high quality image + description of the owner
7 | - Searching among the whole Unsplash photos
8 | - Saving photo to selected path of external storage
9 | - Zooming Image
10 | - Handling high loads of data
11 | - Handling errors and network issues
12 | - viewing saved & favorite photos (todo)
13 |
14 | ## Tech stack & Open-source libraries
15 | This project is based on MVVM architecture, using following tech-stacks:
16 | - Jetpack
17 | - Navigation Component
18 | - Hilt
19 | - Paging 3
20 | - Lifecycle
21 | - View Binding
22 | - Retrofit
23 | - Glide
24 | - Coroutines
25 | - [Zoombale ImageView](https://github.com/stfalcon-studio/StfalconImageViewer)
26 | - [File Picker](https://github.com/spacecowboy/NoNonsense-FilePicker)
27 | - [Downloader](https://github.com/tonyofrancis/Fetch)
28 |
29 | ## How to use?
30 | Build & install or [Get .APK](https://github.com/behnawwm/MyPhotoLoaderApp/raw/master/Apk/MyPhotoLoader.apk)
31 |
32 | If no results were shown:
33 | - Use proxy!
34 | - Replace ``UNSPLASH_ACCESS_KEY`` in ``build.gradle`` with your own access_key from [Unsplash Developers](https://unsplash.com/developers).
35 |
36 | ## Screenshots:
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | ## Architecture
46 | This app is based on MVVM architecture and a repository pattern.
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_gallery.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
23 |
24 |
33 |
34 |
42 |
43 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
14 |
21 |
22 |
27 |
28 |
29 |
34 |
35 |
36 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
11 |
12 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
35 |
38 |
39 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/bottom_sheet_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
24 |
25 |
26 |
45 |
46 |
53 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_details.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
18 |
19 |
28 |
29 |
38 |
39 |
49 |
50 |
51 |
52 |
53 |
54 |
59 |
60 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/UI/gallery/PhotoAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.UI.gallery
2 |
3 | import android.view.LayoutInflater
4 | import android.view.ViewGroup
5 | import androidx.paging.PagingDataAdapter
6 | import androidx.recyclerview.widget.DiffUtil
7 | import androidx.recyclerview.widget.RecyclerView
8 | import com.bumptech.glide.Glide
9 | import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
10 | import com.example.myphotoloaderapp.R
11 | import com.example.myphotoloaderapp.data.MyPhoto
12 | import com.example.myphotoloaderapp.databinding.ItemPhotoBinding
13 |
14 | class PhotoAdapter(val listener: OnItemPressListener) :
15 | PagingDataAdapter(DIFF_CALLBACK) {
16 |
17 |
18 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PhotoViewHolder {
19 | val binding = ItemPhotoBinding.inflate(LayoutInflater.from(parent.context), parent, false)
20 |
21 | return PhotoViewHolder(binding)
22 | }
23 |
24 | override fun onBindViewHolder(holder: PhotoViewHolder, position: Int) {
25 | val currentItem = getItem(position)
26 |
27 | if (currentItem != null)
28 | holder.bind(currentItem)
29 | }
30 |
31 | inner class PhotoViewHolder(private val binding: ItemPhotoBinding) :
32 | RecyclerView.ViewHolder(binding.root) {
33 |
34 | init {
35 | binding.root.setOnClickListener {
36 | var position = bindingAdapterPosition
37 | if (position != RecyclerView.NO_POSITION) {
38 | var item = getItem(position)
39 | if (item != null) {
40 | listener.OnItemClick(item)
41 | }
42 | }
43 | }
44 | }
45 |
46 | fun bind(photo: MyPhoto) {
47 | binding.apply {
48 | Glide.with(itemView)
49 | .load(photo.urls.regular)
50 | .centerCrop()
51 | .transition(DrawableTransitionOptions.withCrossFade())
52 | .error(R.drawable.ic_image_error)
53 | .into(binding.imageView)
54 |
55 | textViewUserName.text = photo.user.username
56 | }
57 | }
58 |
59 | }
60 |
61 | interface OnItemPressListener {
62 | fun OnItemClick(photo: MyPhoto)
63 | }
64 |
65 | object DIFF_CALLBACK : DiffUtil.ItemCallback() {
66 | override fun areItemsTheSame(oldItem: MyPhoto, newItem: MyPhoto): Boolean =
67 | newItem.id == oldItem.id
68 |
69 |
70 | override fun areContentsTheSame(oldItem: MyPhoto, newItem: MyPhoto): Boolean =
71 | newItem == oldItem
72 |
73 | }
74 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/Util/Common/ContextUtils.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.Util.Common
2 |
3 | import android.app.Activity
4 | import android.content.Context
5 | import android.content.Context.CONNECTIVITY_SERVICE
6 | import android.content.Intent
7 | import android.net.ConnectivityManager
8 | import android.util.DisplayMetrics
9 | import android.view.LayoutInflater
10 | import android.view.View
11 | import android.view.ViewGroup
12 | import android.widget.Toast
13 | import androidx.annotation.ColorRes
14 | import androidx.annotation.DrawableRes
15 | import androidx.annotation.LayoutRes
16 | import androidx.core.content.ContextCompat
17 | import es.dmoral.toasty.Toasty
18 |
19 | /**
20 | * Extension method to provide simpler access to {@link ContextCompat#getColor(int)}.
21 | */
22 | fun Context.getColorCompat(color: Int) = ContextCompat.getColor(this, color)
23 |
24 |
25 | /**
26 | * Extension method to find a device width in pixels
27 | */
28 | inline val Context.displayWidth: Int
29 | get() = resources.displayMetrics.widthPixels
30 |
31 | /**
32 | * Extension method to find a device height in pixels
33 | */
34 | inline val Context.displayHeight: Int
35 | get() = resources.displayMetrics.heightPixels
36 |
37 | /**
38 | * Extension method to get displayMetrics in Context.displayMetricks
39 | */
40 | inline val Context.displayMetrics: DisplayMetrics
41 | get() = resources.displayMetrics
42 |
43 | /**
44 | * Extension method to get a new Intent for an Activity class
45 | */
46 | inline fun Context.intent() = Intent(this, T::class.java)
47 |
48 | /**
49 | * Create an intent for [T] and apply a lambda on it
50 | */
51 | inline fun Context.intent(body: Intent.() -> Unit): Intent {
52 | val intent = Intent(this, T::class.java)
53 | intent.body()
54 | return intent
55 | }
56 |
57 | /**
58 | * Extension method to startActivity for Context.
59 | */
60 | inline fun Context?.startActivity() =
61 | this?.startActivity(Intent(this, T::class.java))
62 |
63 | /**
64 | * Extension method to show toast for Context.
65 | */
66 | fun Context?.toast(text: CharSequence, duration: Int = Toast.LENGTH_LONG) =
67 | this?.let { Toast.makeText(it, text, duration).show() }
68 |
69 | /**
70 | * Extension method to Get Color for resource for Context.
71 | */
72 | fun Context.getColor(@ColorRes id: Int) = ContextCompat.getColor(this, id)
73 |
74 | /**
75 | * Extension method to Get Drawable for resource for Context.
76 | */
77 | fun Context.getDrawable(@DrawableRes id: Int) = ContextCompat.getDrawable(this, id)
78 |
79 | /**
80 | * InflateLayout
81 | */
82 | fun Context.inflateLayout(
83 | @LayoutRes layoutId: Int,
84 | parent: ViewGroup? = null,
85 | attachToRoot: Boolean = false
86 | ): View = LayoutInflater.from(this).inflate(layoutId, parent, attachToRoot)
87 |
88 | /**
89 | * Extension method to get connectivityManager for Context.
90 | */
91 | inline val Context.connectivityManager: ConnectivityManager?
92 | get() = getSystemService(CONNECTIVITY_SERVICE) as? ConnectivityManager
93 |
94 | /**
95 | * Extension method to provide quicker access to the [LayoutInflater] from [Context].
96 | */
97 | fun Context.getLayoutInflater() =
98 | getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
99 |
100 |
101 | /**
102 | * Toasty
103 | * */
104 | fun Context?.successToasty(text: CharSequence, duration: Int = Toast.LENGTH_SHORT) =
105 | this?.let { Toasty.success(it, text, duration).show() }
106 |
107 | fun Context?.infoToasty(text: CharSequence, duration: Int = Toast.LENGTH_LONG) =
108 | this?.let { Toasty.info(it, text, duration).show() }
109 |
110 | fun Context?.errorToasty(text: CharSequence, duration: Int = Toast.LENGTH_LONG) =
111 | this?.let { Toasty.error(it, text, duration).show() }
--------------------------------------------------------------------------------
/app/src/main/res/raw/download2.json:
--------------------------------------------------------------------------------
1 | {"v":"5.5.9","fr":60,"ip":0,"op":41,"w":375,"h":667,"nm":"Comp 1","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Layer 2/01 Outlines","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[189.5,295.5,0],"ix":2},"a":{"a":0,"k":[83.5,60.5,0],"ix":1},"s":{"a":1,"k":[{"i":{"x":[0.667,0.667,0.667],"y":[1,1,1]},"o":{"x":[0.167,0.167,0.167],"y":[0.167,0.167,0.153]},"t":10,"s":[100,100,100]},{"i":{"x":[0.667,0.667,0.667],"y":[1,1,1]},"o":{"x":[0.167,0.167,0.167],"y":[0.167,0.167,-0.153]},"t":21,"s":[110,110,100]},{"t":32,"s":[100,100,100]}],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[9.62,13.681],[9.866,-0.008],[0,0],[25.919,-6.651],[-6.65,-25.919],[-5.089,-5.75]],"o":[[13.681,-9.62],[-5.676,-8.071],[0,0],[-6.652,-25.92],[-25.919,6.651],[1.909,7.439],[0,0]],"v":[[54.307,48.296],[61.659,6.107],[36.865,-6.757],[29.234,-6.757],[-29.74,-41.645],[-64.629,17.327],[-53.982,37.395]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0.050883326811,0.041530545553,0.043982752632,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":12.113,"ix":5},"lc":2,"lj":2,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[83.392,60.41],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":180,"st":0,"bm":0},{"ddd":0,"ind":3,"ty":4,"nm":"Layer 3/01 Outlines","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":1,"k":[{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0.167},"t":10,"s":[187.5,359.5,0],"to":[0,0,0],"ti":[0,0,0]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0.167},"t":16,"s":[187.5,383.5,0],"to":[0,0,0],"ti":[0,0,0]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0.167},"t":21,"s":[187.5,359.5,0],"to":[0,0,0],"ti":[0,0,0]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0.167},"t":26,"s":[187.5,383.5,0],"to":[0,0,0],"ti":[0,0,0]},{"t":32,"s":[187.5,359.5,0]}],"ix":2},"a":{"a":0,"k":[36.5,24.5,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[-24.226,-12.113],[0,12.113],[24.226,-12.113]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0.050883326811,0.041530545553,0.043982752632,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":12.113,"ix":5},"lc":2,"lj":2,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[36.339,24.226],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":180,"st":0,"bm":0},{"ddd":0,"ind":5,"ty":4,"nm":"Layer 4/01 Outlines","parent":3,"sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[36.5,-1.5,0],"ix":2},"a":{"a":0,"k":[6.5,33.5,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[6.057,6.057],[6.057,60.564]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0.050883326811,0.041530545553,0.043982752632,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":12.113,"ix":5},"lc":2,"lj":2,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":180,"st":0,"bm":0}],"markers":[]}
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | xmlns:android
18 |
19 | ^$
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | xmlns:.*
29 |
30 | ^$
31 |
32 |
33 | BY_NAME
34 |
35 |
36 |
37 |
38 |
39 |
40 | .*:id
41 |
42 | http://schemas.android.com/apk/res/android
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | .*:name
52 |
53 | http://schemas.android.com/apk/res/android
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | name
63 |
64 | ^$
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | style
74 |
75 | ^$
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 | .*
85 |
86 | ^$
87 |
88 |
89 | BY_NAME
90 |
91 |
92 |
93 |
94 |
95 |
96 | .*
97 |
98 | http://schemas.android.com/apk/res/android
99 |
100 |
101 | ANDROID_ATTRIBUTE_ORDER
102 |
103 |
104 |
105 |
106 |
107 |
108 | .*
109 |
110 | .*
111 |
112 |
113 | BY_NAME
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/UI/gallery/GalleryFragment.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.UI.gallery
2 |
3 | import android.os.Bundle
4 | import android.view.Menu
5 | import android.view.MenuInflater
6 | import android.view.View
7 | import androidx.appcompat.widget.SearchView
8 | import androidx.core.view.isVisible
9 | import androidx.fragment.app.Fragment
10 | import androidx.fragment.app.viewModels
11 | import androidx.navigation.fragment.findNavController
12 | import androidx.paging.LoadState
13 | import androidx.paging.LoadStateAdapter
14 | import com.example.myphotoloaderapp.R
15 | import com.example.myphotoloaderapp.data.MyPhoto
16 | import com.example.myphotoloaderapp.databinding.FragmentGalleryBinding
17 | import dagger.hilt.android.AndroidEntryPoint
18 | import kotlinx.android.synthetic.main.fragment_gallery.*
19 |
20 | @AndroidEntryPoint
21 | class GalleryFragment : Fragment(R.layout.fragment_gallery), PhotoAdapter.OnItemPressListener {
22 |
23 | val viewmodel by viewModels()
24 |
25 | private var _binding: FragmentGalleryBinding? = null
26 | private val binding get() = _binding!!
27 |
28 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
29 | super.onViewCreated(view, savedInstanceState)
30 |
31 | _binding = FragmentGalleryBinding.bind(view)
32 |
33 | val adapter = PhotoAdapter(this)
34 | binding.apply {
35 | rv_photos.setHasFixedSize(true)
36 | rv_photos.adapter = adapter.withLoadStateHeaderAndFooter(
37 | header = PhotoLoadStateAdapter { adapter.retry() },
38 | footer = PhotoLoadStateAdapter { adapter.retry() }
39 | )
40 | btnPhotoRetry.setOnClickListener {
41 | adapter.retry()
42 | }
43 | }
44 |
45 | viewmodel.photos.observe(viewLifecycleOwner) {
46 | adapter.submitData(viewLifecycleOwner.lifecycle, it)
47 | }
48 |
49 | adapter.addLoadStateListener { loadState ->
50 | binding.apply {
51 | loadingMain.isVisible = loadState.source.refresh is LoadState.Loading
52 | rvPhotos.isVisible = loadState.source.refresh is LoadState.NotLoading
53 | btnPhotoRetry.isVisible = loadState.source.refresh is LoadState.Error
54 | tvErrorGallery.isVisible = loadState.source.refresh is LoadState.Error
55 |
56 | // empty view
57 | if (loadState.source.refresh is LoadState.NotLoading &&
58 | loadState.append.endOfPaginationReached &&
59 | adapter.itemCount < 1) {
60 | rvPhotos.isVisible = false
61 | tv_empty_gallery.isVisible = true
62 | } else {
63 | tv_empty_gallery.isVisible = false
64 | }
65 | }
66 | }
67 |
68 | setHasOptionsMenu(true)
69 | }
70 |
71 | override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
72 | super.onCreateOptionsMenu(menu, inflater)
73 | inflater.inflate(R.menu.menu_gallery, menu)
74 |
75 | val searchItem = menu.findItem(R.id.menu_gallery_search)
76 | val searchView = searchItem.actionView as SearchView
77 |
78 | searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
79 | override fun onQueryTextSubmit(query: String?): Boolean {
80 | if (query != null) {
81 | binding.rvPhotos.scrollToPosition(0)
82 | viewmodel.searchPhotos(query)
83 | searchView.clearFocus()
84 | }
85 | return true
86 | }
87 |
88 | override fun onQueryTextChange(newText: String?): Boolean {
89 | return true
90 | }
91 |
92 | })
93 | }
94 |
95 | override fun onDestroyView() {
96 | super.onDestroyView()
97 | _binding = null
98 | }
99 |
100 | override fun OnItemClick(photo: MyPhoto) {
101 | val action = GalleryFragmentDirections.actionGalleryFragmentToDetailsFragment(photo)
102 | findNavController().navigate(action)
103 | }
104 | }
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'kotlin-android'
4 | id 'kotlin-android-extensions'
5 | id 'kotlin-kapt'
6 | id "androidx.navigation.safeargs.kotlin"
7 | id 'dagger.hilt.android.plugin'
8 | }
9 |
10 | android {
11 | compileSdkVersion 30
12 | buildToolsVersion "30.0.3"
13 |
14 | defaultConfig {
15 | applicationId "com.example.myphotoloaderapp"
16 | minSdkVersion 21
17 | targetSdkVersion 30
18 | versionCode 1
19 | versionName "1.0"
20 |
21 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
22 |
23 | buildConfigField "String", "UNSPLASH_ACCESS_KEY", "\"XVnsZlEUSduNJux8gHGWYb27hhTeOOiSrq-HerXrDnM\""
24 |
25 | }
26 |
27 | buildTypes {
28 | release {
29 | minifyEnabled false
30 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
31 | }
32 | }
33 | buildFeatures {
34 | viewBinding true
35 | }
36 |
37 | compileOptions {
38 | sourceCompatibility JavaVersion.VERSION_1_8
39 | targetCompatibility JavaVersion.VERSION_1_8
40 | }
41 | kotlinOptions {
42 | jvmTarget = '1.8'
43 | }
44 |
45 | }
46 |
47 | dependencies {
48 |
49 | // Default dependencies
50 | implementation fileTree(dir: "libs", include: ["*.jar"])
51 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
52 | implementation "androidx.core:core-ktx:$ktxVersion"
53 | implementation "androidx.appcompat:appcompat:$appCompatVersion"
54 | implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion"
55 | testImplementation "junit:junit:$junitVersion"
56 | androidTestImplementation "androidx.test.ext:junit:$testExtJunitVersion"
57 | androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
58 |
59 | //AndroidX Base
60 | // Java language implementation
61 | implementation "androidx.fragment:fragment:$fragment_version"
62 | // Kotlin
63 | implementation "androidx.fragment:fragment-ktx:$fragment_version"
64 |
65 | // Navigation Component
66 | implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
67 | implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"
68 |
69 | // Dagger Hilt
70 | implementation "com.google.dagger:hilt-android:$hiltVersion"
71 | kapt "com.google.dagger:hilt-android-compiler:$hiltVersion"
72 | implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hiltAndroidXVersion"
73 | kapt "androidx.hilt:hilt-compiler:$hiltAndroidXVersion"
74 |
75 | // Retrofit + GSON
76 | implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
77 | implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
78 |
79 | // Glide
80 | implementation "com.github.bumptech.glide:glide:$glideVersion"
81 |
82 | // Paging 3
83 | implementation "androidx.paging:paging-runtime:$pagingVersion"
84 |
85 | // Blur hash for placeholder //todo
86 | implementation 'xyz.belvi.blurHash:blurHash:1.0.4'
87 |
88 | //Downloader
89 | implementation 'com.mindorks.android:prdownloader:0.6.0'
90 | implementation "androidx.tonyodev.fetch2:xfetch2:3.1.6"
91 |
92 | //file picker
93 | implementation 'com.nononsenseapps:filepicker:4.1.0'
94 |
95 | //Dialog
96 | // Material Dialog Library
97 | implementation 'dev.shreyaspatil.MaterialDialog:MaterialDialog:2.2.2'
98 | // Material Design Library
99 | implementation 'com.google.android.material:material:1.3.0'
100 | //bottom sheet
101 | implementation 'com.maxkeppeler.sheets:info:2.2.4'
102 | implementation 'com.maxkeppeler.sheets:storage:2.2.4'
103 | implementation 'com.maxkeppeler.sheets:core:2.2.4'
104 |
105 |
106 | // Lottie Animation Library
107 | implementation 'com.airbnb.android:lottie:3.7.0'
108 |
109 | //Toasty
110 | implementation 'com.github.GrenderG:Toasty:1.5.0'
111 |
112 | //progreebar
113 | implementation "com.github.skydoves:progressview:1.1.1"
114 |
115 | //Zoomable ImageView
116 | implementation 'com.github.stfalcon-studio:StfalconImageViewer:d11578fe3f'
117 |
118 | }
119 | kapt {
120 | correctErrorTypes true
121 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myphotoloaderapp/UI/details/DetailsFragment.kt:
--------------------------------------------------------------------------------
1 | package com.example.myphotoloaderapp.UI.details
2 |
3 | import android.Manifest
4 | import android.content.ContentResolver
5 | import android.content.Intent
6 | import android.content.pm.PackageManager
7 | import android.graphics.drawable.Drawable
8 | import android.net.Uri
9 | import android.os.Bundle
10 | import android.os.Environment
11 | import android.util.Log
12 | import android.view.Menu
13 | import android.view.MenuInflater
14 | import android.view.View
15 | import android.widget.Button
16 | import androidx.activity.result.contract.ActivityResultContracts
17 | import androidx.core.content.ContextCompat
18 | import androidx.core.view.isVisible
19 | import androidx.fragment.app.Fragment
20 | import androidx.fragment.app.viewModels
21 | import androidx.navigation.fragment.navArgs
22 | import com.bumptech.glide.Glide
23 | import com.bumptech.glide.load.DataSource
24 | import com.bumptech.glide.load.engine.GlideException
25 | import com.bumptech.glide.request.RequestListener
26 | import com.bumptech.glide.request.target.Target
27 | import com.example.myphotoloaderapp.R
28 | import com.example.myphotoloaderapp.Util.Common.errorToasty
29 | import com.example.myphotoloaderapp.Util.Common.infoToasty
30 | import com.example.myphotoloaderapp.Util.Common.successToasty
31 | import com.example.myphotoloaderapp.data.MyPhoto
32 | import com.example.myphotoloaderapp.databinding.FragmentDetailsBinding
33 | import com.google.android.material.bottomsheet.BottomSheetDialog
34 | import com.nononsenseapps.filepicker.FilePickerActivity
35 | import com.skydoves.progressview.ProgressView
36 | import com.stfalcon.imageviewer.StfalconImageViewer
37 | import com.tonyodev.fetch2.*
38 | import com.tonyodev.fetch2core.DownloadBlock
39 | import java.io.File
40 |
41 |
42 | class DetailsFragment : Fragment(R.layout.fragment_details) {
43 |
44 | lateinit var binding: FragmentDetailsBinding
45 | private val args by navArgs()
46 | val viewModel by viewModels()
47 |
48 | lateinit var contentResolver: ContentResolver
49 | lateinit var fetch: Fetch
50 |
51 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
52 | super.onViewCreated(view, savedInstanceState)
53 | binding = FragmentDetailsBinding.bind(view)
54 |
55 | contentResolver = activity?.contentResolver!!
56 | initializeDownloader()
57 |
58 | binding.apply {
59 | val photo = args.photo
60 |
61 | fillImageView(photo)
62 |
63 | imageView.setOnClickListener {
64 | val images = listOf(photo.urls.full)
65 |
66 | StfalconImageViewer.Builder(context, images) { view, image ->
67 |
68 | Glide.with(this@DetailsFragment)
69 | .load(image)
70 | .error(R.drawable.ic_image_error)
71 | .into(view)
72 | .onLoadStarted(resources.getDrawable(R.drawable.ic_download))
73 | }.show()
74 | }
75 |
76 | textViewDescription.text = photo.desc
77 | val uri = Uri.parse(photo.user.attributionUrl)
78 | val intent = Intent(Intent.ACTION_VIEW, uri)
79 |
80 | textViewCreator.apply {
81 | text = "Photo by ${photo.user.name} on Unsplash"
82 | setOnClickListener {
83 | context.startActivity(intent)
84 | }
85 | paint.isUnderlineText = true
86 | }
87 | }
88 |
89 | setHasOptionsMenu(true)
90 | }
91 |
92 | private fun fillImageView(photo: MyPhoto) {
93 | binding.apply {
94 | Glide.with(this@DetailsFragment)
95 | .load(photo.urls.regular)
96 | .error(R.drawable.ic_image_error)
97 | .listener(object : RequestListener {
98 | override fun onLoadFailed(
99 | e: GlideException?,
100 | model: Any?,
101 | target: Target?,
102 | isFirstResource: Boolean
103 | ): Boolean {
104 | binding.progressBar.isVisible = false
105 | return false
106 | }
107 |
108 | override fun onResourceReady(
109 | resource: Drawable?,
110 | model: Any?,
111 | target: Target?,
112 | dataSource: DataSource?,
113 | isFirstResource: Boolean
114 | ): Boolean {
115 | progressBar.isVisible = false
116 | textViewCreator.isVisible = true
117 | textViewDescription.isVisible = photo.desc != null
118 | return false
119 | }
120 | })
121 | .into(imageView)
122 | }
123 | }
124 |
125 |
126 | override fun onCreate(savedInstanceState: Bundle?) {
127 | super.onCreate(savedInstanceState)
128 | grantStoragePermission()
129 | }
130 |
131 | override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
132 | super.onCreateOptionsMenu(menu, inflater);
133 |
134 | inflater.inflate(R.menu.menu_details, menu)
135 |
136 | val saveItem = menu.findItem(R.id.menu_details_save)
137 | saveItem.setOnMenuItemClickListener {
138 |
139 | val chooseFolderIntent = Intent(Intent.ACTION_GET_CONTENT);
140 | chooseFolderIntent.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)
141 | chooseFolderIntent.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true)
142 | chooseFolderIntent.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR)
143 |
144 | chooseFolderIntent.putExtra(
145 | FilePickerActivity.EXTRA_START_PATH,
146 | Environment.getExternalStorageDirectory().path
147 | )
148 |
149 | startActivityForResult(chooseFolderIntent, 9999)
150 |
151 | true
152 | }
153 |
154 | }
155 |
156 | private fun initializeDownloader() {
157 | val fetchConfiguration: FetchConfiguration =
158 | FetchConfiguration.Builder(requireContext())
159 | .setDownloadConcurrentLimit(3)
160 | .build()
161 |
162 | fetch = Fetch.Impl.getInstance(fetchConfiguration)
163 | }
164 |
165 | private fun grantStoragePermission() {
166 | val requestPermissionLauncher =
167 | registerForActivityResult(
168 | ActivityResultContracts.RequestPermission()
169 | ) { isGranted: Boolean ->
170 | if (isGranted) {
171 | // context.successToasty("Permission granted!")
172 | } else {
173 | context.errorToasty("Permission declined! App won't be able to save external files!")
174 | }
175 | }
176 |
177 | when {
178 | ContextCompat.checkSelfPermission(
179 | requireContext(),
180 | Manifest.permission.WRITE_EXTERNAL_STORAGE
181 | ) == PackageManager.PERMISSION_GRANTED -> {
182 | // You can use the API that requires the permission.
183 | }
184 | shouldShowRequestPermissionRationale("mamad")
185 | -> {
186 | // Toasty.warning(requireContext(), "grant permission mamad jan", Toasty.LENGTH_SHORT)
187 | // .show()
188 | }
189 | else -> {
190 | requestPermissionLauncher.launch(
191 | Manifest.permission.WRITE_EXTERNAL_STORAGE
192 | )
193 | }
194 | }
195 | }
196 |
197 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
198 | super.onActivityResult(requestCode, resultCode, data)
199 | when (requestCode) {
200 | 9999 -> {
201 | if (data == null)
202 | return
203 |
204 | initializeDownloader()
205 | val download = makeDownloadRequest(data)
206 |
207 | if (download != null) {
208 | val mBottomSheetDialog = makeDownloadDialog(download)
209 | mBottomSheetDialog.show()
210 |
211 | enqueueDownloadRequest(fetch, download, mBottomSheetDialog)
212 | } else {
213 | context.infoToasty("Image already downloaded in this path!")
214 | }
215 | }
216 | }
217 | }
218 |
219 | private fun makeDownloadRequest(pathData: Intent): Request? {
220 | val url = args.photo.urls.full
221 | val path = pathData.data?.path?.substringAfter("/root") + "/${args.photo.id}.jpg"
222 |
223 | if (File(path).exists())
224 | return null
225 |
226 |
227 | var download = Request(url, path)
228 | download.priority = Priority.HIGH
229 | download.networkType = NetworkType.ALL
230 |
231 | return download
232 | }
233 |
234 |
235 | private fun makeDownloadDialog(download: Request?): BottomSheetDialog {
236 | // val bottomSheetLoadingBinding = //todo : changes not appliable
237 | // BottomSheetLoadingBinding.inflate(LayoutInflater.from(context))
238 |
239 | val dialog = BottomSheetDialog(requireContext(), R.style.SheetDialog)
240 | dialog.apply {
241 | setContentView(R.layout.bottom_sheet_loading)
242 | setCancelable(false)
243 | findViewById