├── app ├── .gitignore ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── hadi │ │ │ │ └── retrofitmvvm │ │ │ │ ├── model │ │ │ │ ├── PicsResponse.kt │ │ │ │ ├── loginResponse │ │ │ │ │ └── LoginResponse.kt │ │ │ │ └── DataItem.kt │ │ │ │ ├── app │ │ │ │ └── MyApplication.kt │ │ │ │ ├── util │ │ │ │ ├── Constants.kt │ │ │ │ ├── Resource.kt │ │ │ │ ├── Event.kt │ │ │ │ ├── Utils.kt │ │ │ │ └── SnackbarExtensions.kt │ │ │ │ ├── network │ │ │ │ ├── RequestBodies.kt │ │ │ │ ├── API.kt │ │ │ │ └── RetrofitInstance.kt │ │ │ │ ├── repository │ │ │ │ └── AppRepository.kt │ │ │ │ ├── viewmodel │ │ │ │ ├── ViewModelProviderFactory.kt │ │ │ │ ├── PicsViewModel.kt │ │ │ │ └── LoginViewModel.kt │ │ │ │ ├── adapter │ │ │ │ └── PicsAdapter.kt │ │ │ │ └── ui │ │ │ │ ├── MainActivity.kt │ │ │ │ └── LoginActivity.kt │ │ ├── res │ │ │ ├── font │ │ │ │ └── avenirltstd_medium.otf │ │ │ ├── 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 │ │ │ ├── drawable │ │ │ │ ├── gradient_bg.xml │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ ├── styles.xml │ │ │ │ └── material_colors.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ ├── activity_main.xml │ │ │ │ ├── item_pics.xml │ │ │ │ └── activity_login.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── hadi │ │ │ └── retrofitmvvm │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── hadi │ │ └── retrofitmvvm │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── .idea ├── .name ├── codeStyles │ ├── codeStyleConfig.xml │ └── Project.xml ├── vcs.xml ├── misc.xml ├── runConfigurations.xml ├── gradle.xml └── jarRepositories.xml ├── settings.gradle ├── art └── screenshot.jpg ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── README.md ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Retrofit Coroutine MVVM -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name = "Retrofit Coroutine MVVM" -------------------------------------------------------------------------------- /art/screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unaisulhadi/MVVM-Retrofit-Coroutine/HEAD/art/screenshot.jpg -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unaisulhadi/MVVM-Retrofit-Coroutine/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/model/PicsResponse.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.model 2 | 3 | class PicsResponse : ArrayList() -------------------------------------------------------------------------------- /app/src/main/res/font/avenirltstd_medium.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unaisulhadi/MVVM-Retrofit-Coroutine/HEAD/app/src/main/res/font/avenirltstd_medium.otf -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unaisulhadi/MVVM-Retrofit-Coroutine/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unaisulhadi/MVVM-Retrofit-Coroutine/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unaisulhadi/MVVM-Retrofit-Coroutine/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unaisulhadi/MVVM-Retrofit-Coroutine/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unaisulhadi/MVVM-Retrofit-Coroutine/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unaisulhadi/MVVM-Retrofit-Coroutine/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/unaisulhadi/MVVM-Retrofit-Coroutine/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/unaisulhadi/MVVM-Retrofit-Coroutine/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/app/MyApplication.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.app 2 | 3 | import android.app.Application 4 | 5 | class MyApplication : Application() -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unaisulhadi/MVVM-Retrofit-Coroutine/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/unaisulhadi/MVVM-Retrofit-Coroutine/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/util/Constants.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.util 2 | 3 | object Constants{ 4 | const val BASE_URL = "https://picsum.photos" 5 | const val BASE_URL_2 = "https://reqres.in" 6 | } -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/network/RequestBodies.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.network 2 | 3 | object RequestBodies { 4 | 5 | data class LoginBody( 6 | val email:String, 7 | val password:String 8 | ) 9 | 10 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/gradient_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 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 | -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/model/loginResponse/LoginResponse.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.model.loginResponse 2 | 3 | 4 | import com.google.gson.annotations.SerializedName 5 | 6 | data class LoginResponse( 7 | @SerializedName("token") 8 | val token: String 9 | ) -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | @color/md_cyan_700 4 | @color/md_cyan_700 5 | @color/md_red_500 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/model/DataItem.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.model 2 | 3 | data class DataItem( 4 | val author: String, 5 | val download_url: String, 6 | val height: Int, 7 | val id: String, 8 | val url: String, 9 | val width: Int 10 | ) -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Sep 27 20:01:17 IST 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-6.1.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Retrofit Coroutine MVVM 3 | No internet connection 4 | Network Failure 5 | Conversion Error 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/util/Resource.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.util 2 | 3 | sealed class Resource( 4 | val data: T? = null, 5 | val message: String? = null 6 | ) { 7 | class Success(data: T) : Resource(data) 8 | class Error(message: String, data: T? = null) : Resource(data, message) 9 | class Loading : Resource() 10 | } -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/util/Event.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.util 2 | 3 | open class Event(private val content: T) { 4 | 5 | var hasBeenHandled = false 6 | private set 7 | 8 | fun getContentIfNotHandled() = if(hasBeenHandled) { 9 | null 10 | } else { 11 | hasBeenHandled = true 12 | content 13 | } 14 | 15 | fun peekContent() = content 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Retrofit with Coroutines and MVVM Architecture. 2 | ### A simple Android Application with MVVM Architecture 3 | ![alt text](https://raw.githubusercontent.com/unaisulhadi/MVVM-Retrofit-Coroutine/master/art/screenshot.jpg) 4 | 5 | # Developed Using 6 | ### LiveData. 7 | ### MVVM Architecture. 8 | ### Retrofit2 for Network Requests. 9 | ### Kotlin Coroutine for Async Programming. 10 | ### Coil for Image Loading. 11 | ### Kotin Extentions. 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/repository/AppRepository.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.repository 2 | 3 | import com.hadi.retrofitmvvm.network.RequestBodies 4 | import com.hadi.retrofitmvvm.network.RetrofitInstance 5 | 6 | class AppRepository { 7 | 8 | suspend fun getPictures() = RetrofitInstance.picsumApi.getPictures() 9 | 10 | suspend fun loginUser(body: RequestBodies.LoginBody) = RetrofitInstance.loginApi.loginUser(body) 11 | } -------------------------------------------------------------------------------- /app/src/test/java/com/hadi/retrofitmvvm/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm 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/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/network/API.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.network 2 | 3 | import com.hadi.retrofitmvvm.model.PicsResponse 4 | import com.hadi.retrofitmvvm.model.loginResponse.LoginResponse 5 | import retrofit2.Response 6 | import retrofit2.http.Body 7 | import retrofit2.http.GET 8 | import retrofit2.http.POST 9 | 10 | interface API { 11 | 12 | @GET("v2/list") 13 | suspend fun getPictures(): Response 14 | 15 | @POST("api/login") 16 | suspend fun loginUser(@Body body:RequestBodies.LoginBody): Response 17 | } -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/hadi/retrofitmvvm/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm 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.hadi.retrofitcoroutinemvvm", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/viewmodel/ViewModelProviderFactory.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.viewmodel 2 | 3 | import android.app.Application 4 | import androidx.lifecycle.ViewModel 5 | import androidx.lifecycle.ViewModelProvider 6 | import com.hadi.retrofitmvvm.repository.AppRepository 7 | 8 | class ViewModelProviderFactory( 9 | val app: Application, 10 | val appRepository: AppRepository 11 | ) : ViewModelProvider.Factory { 12 | 13 | override fun create(modelClass: Class): T { 14 | if (modelClass.isAssignableFrom(PicsViewModel::class.java)) { 15 | return PicsViewModel(app, appRepository) as T 16 | } 17 | 18 | if (modelClass.isAssignableFrom(LoginViewModel::class.java)) { 19 | return LoginViewModel(app, appRepository) as T 20 | } 21 | throw IllegalArgumentException("Unknown class name") 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /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 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 -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/util/Utils.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.util 2 | 3 | import android.content.Context 4 | import android.net.ConnectivityManager 5 | import android.net.NetworkCapabilities 6 | import android.os.Build 7 | import com.hadi.retrofitmvvm.app.MyApplication 8 | 9 | object Utils { 10 | fun hasInternetConnection(application: MyApplication): Boolean { 11 | val connectivityManager = application.getSystemService( 12 | Context.CONNECTIVITY_SERVICE 13 | ) as ConnectivityManager 14 | if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 15 | val activeNetwork = connectivityManager.activeNetwork ?: return false 16 | val capabilities = connectivityManager.getNetworkCapabilities(activeNetwork) ?: return false 17 | return when { 18 | capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> true 19 | capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> true 20 | capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> true 21 | else -> false 22 | } 23 | } else { 24 | connectivityManager.activeNetworkInfo?.run { 25 | return when(type) { 26 | ConnectivityManager.TYPE_WIFI -> true 27 | ConnectivityManager.TYPE_MOBILE -> true 28 | ConnectivityManager.TYPE_ETHERNET -> true 29 | else -> false 30 | } 31 | } 32 | } 33 | return false 34 | } 35 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 | 30 | 31 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/network/RetrofitInstance.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.network 2 | 3 | import com.hadi.retrofitmvvm.util.Constants.BASE_URL 4 | import com.hadi.retrofitmvvm.util.Constants.BASE_URL_2 5 | import okhttp3.OkHttpClient 6 | import okhttp3.logging.HttpLoggingInterceptor 7 | import retrofit2.Retrofit 8 | import retrofit2.converter.gson.GsonConverterFactory 9 | 10 | class RetrofitInstance { 11 | companion object { 12 | 13 | private val retrofitLogin by lazy { 14 | val logging = HttpLoggingInterceptor() 15 | logging.setLevel(HttpLoggingInterceptor.Level.BODY) 16 | val client = OkHttpClient.Builder() 17 | .addInterceptor(logging) 18 | .build() 19 | Retrofit.Builder() 20 | .baseUrl(BASE_URL_2) 21 | .addConverterFactory(GsonConverterFactory.create()) 22 | .client(client) 23 | .build() 24 | } 25 | 26 | private val retrofitPicsum by lazy { 27 | val logging = HttpLoggingInterceptor() 28 | logging.setLevel(HttpLoggingInterceptor.Level.BODY) 29 | val client = OkHttpClient.Builder() 30 | .addInterceptor(logging) 31 | .build() 32 | Retrofit.Builder() 33 | .baseUrl(BASE_URL) 34 | .addConverterFactory(GsonConverterFactory.create()) 35 | .client(client) 36 | .build() 37 | } 38 | 39 | 40 | val loginApi by lazy { 41 | retrofitLogin.create(API::class.java) 42 | } 43 | 44 | val picsumApi by lazy { 45 | retrofitPicsum.create(API::class.java) 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /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/hadi/retrofitmvvm/adapter/PicsAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.adapter 2 | 3 | import android.view.LayoutInflater 4 | import android.view.View 5 | import android.view.ViewGroup 6 | import androidx.recyclerview.widget.AsyncListDiffer 7 | import androidx.recyclerview.widget.DiffUtil 8 | import androidx.recyclerview.widget.RecyclerView 9 | import coil.api.load 10 | import com.hadi.retrofitmvvm.R 11 | import com.hadi.retrofitmvvm.model.DataItem 12 | import kotlinx.android.synthetic.main.item_pics.view.* 13 | 14 | class PicsAdapter : RecyclerView.Adapter() { 15 | 16 | inner class PicsViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) 17 | 18 | private val differCallback = object : DiffUtil.ItemCallback() { 19 | override fun areItemsTheSame(oldItem: DataItem, newItem: DataItem): Boolean { 20 | return oldItem.id == newItem.id 21 | } 22 | 23 | override fun areContentsTheSame(oldItem: DataItem, newItem: DataItem): Boolean { 24 | return oldItem == newItem 25 | } 26 | } 27 | 28 | val differ = AsyncListDiffer(this, differCallback) 29 | 30 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = PicsViewHolder( 31 | LayoutInflater.from(parent.context).inflate( 32 | R.layout.item_pics, 33 | parent, 34 | false 35 | ) 36 | ) 37 | override fun getItemCount() = differ.currentList.size 38 | 39 | override fun onBindViewHolder(holder: PicsViewHolder, position: Int) { 40 | val picItem = differ.currentList[position] 41 | holder.itemView.apply { 42 | ivImage.load(picItem.download_url) 43 | tvImageId.text = picItem.id 44 | tvImageSize.text = "${picItem.width} x ${picItem.height}" 45 | tvImageAuthor.text = picItem.author 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/util/SnackbarExtensions.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.util 2 | 3 | import android.annotation.SuppressLint 4 | import android.content.Context 5 | import android.graphics.Color 6 | import android.view.View 7 | import android.widget.ProgressBar 8 | import android.widget.Toast 9 | import androidx.annotation.IntegerRes 10 | import com.google.android.material.snackbar.Snackbar 11 | 12 | @SuppressLint("ResourceType") 13 | inline fun View.snack(@IntegerRes messageRes: Int, length: Int = Snackbar.LENGTH_LONG, f: Snackbar.() -> Unit) { 14 | snack(resources.getString(messageRes), length, f) 15 | } 16 | 17 | 18 | inline fun View.snack(message: String, length: Int = Snackbar.LENGTH_LONG, f: Snackbar.() -> Unit) { 19 | val snack = Snackbar.make(this, message, length) 20 | snack.f() 21 | snack.show() 22 | } 23 | 24 | fun View.showSnack(message: String, length: Int = Snackbar.LENGTH_LONG) { 25 | val snack = Snackbar.make(this, message, length) 26 | snack.show() 27 | } 28 | 29 | inline fun View.errorSnack(message: String, length: Int = Snackbar.LENGTH_LONG, f: Snackbar.() -> Unit) { 30 | val snack = Snackbar.make(this, message, length) 31 | snack.f() 32 | snack.setActionTextColor(Color.parseColor("#FFFFFF")) 33 | snack.view.setBackgroundColor(Color.parseColor("#C62828")) 34 | snack.show() 35 | } 36 | 37 | fun View.errorSnack(message: String, length: Int = Snackbar.LENGTH_LONG) { 38 | val snack = Snackbar.make(this, message, length) 39 | snack.setActionTextColor(Color.parseColor("#FFFFFF")) 40 | snack.view.setBackgroundColor(Color.parseColor("#C62828")) 41 | snack.show() 42 | } 43 | 44 | @SuppressLint("ResourceType") 45 | fun Snackbar.action(@IntegerRes actionRes: Int, color: Int? = null, listener: (View) -> Unit) { 46 | action(view.resources.getString(actionRes), color, listener) 47 | } 48 | 49 | fun Snackbar.action(action: String, color: Int? = null, listener: (View) -> Unit) { 50 | setAction(action, listener) 51 | color?.let { setActionTextColor(color) } 52 | } 53 | 54 | fun Context.toast(message: String){ 55 | Toast.makeText(this,message,Toast.LENGTH_SHORT).show() 56 | } 57 | 58 | fun ProgressBar.show(){ 59 | this.visibility = View.VISIBLE 60 | } 61 | 62 | fun ProgressBar.hide(){ 63 | this.visibility = View.GONE 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_pics.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 17 | 18 | 27 | 28 | 35 | 36 | 44 | 45 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /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/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 30 7 | buildToolsVersion "30.0.1" 8 | 9 | defaultConfig { 10 | applicationId "com.hadi.retrofitcoroutinemvvm" 11 | minSdkVersion 21 12 | targetSdkVersion 30 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | compileOptions { 27 | sourceCompatibility JavaVersion.VERSION_1_8 28 | targetCompatibility JavaVersion.VERSION_1_8 29 | } 30 | 31 | kotlinOptions { 32 | jvmTarget = JavaVersion.VERSION_1_8.toString() 33 | } 34 | } 35 | 36 | dependencies { 37 | implementation fileTree(dir: "libs", include: ["*.jar"]) 38 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 39 | implementation 'androidx.core:core-ktx:1.3.1' 40 | implementation 'androidx.appcompat:appcompat:1.2.0' 41 | implementation 'androidx.constraintlayout:constraintlayout:2.0.1' 42 | 43 | // Architectural Components 44 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0" 45 | 46 | // Coroutines 47 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9' 48 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9' 49 | 50 | // Coroutine Lifecycle Scopes 51 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0" 52 | implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0" 53 | 54 | // Retrofit 55 | implementation 'com.squareup.retrofit2:retrofit:2.9.0' 56 | implementation 'com.squareup.retrofit2:converter-gson:2.9.0' 57 | implementation "com.squareup.okhttp3:logging-interceptor:4.7.2" 58 | 59 | //UI 60 | implementation 'com.google.android.material:material:1.2.1' 61 | implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" 62 | implementation 'com.intuit.sdp:sdp-android:1.0.6' 63 | implementation 'com.intuit.ssp:ssp-android:1.0.6' 64 | implementation "io.coil-kt:coil:0.9.5" 65 | 66 | testImplementation 'junit:junit:4.13' 67 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 68 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 69 | 70 | } -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/viewmodel/PicsViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.viewmodel 2 | 3 | import android.app.Application 4 | import androidx.lifecycle.AndroidViewModel 5 | import androidx.lifecycle.LiveData 6 | import androidx.lifecycle.MutableLiveData 7 | import androidx.lifecycle.viewModelScope 8 | import com.hadi.retrofitmvvm.R 9 | import com.hadi.retrofitmvvm.app.MyApplication 10 | import com.hadi.retrofitmvvm.model.PicsResponse 11 | import com.hadi.retrofitmvvm.repository.AppRepository 12 | import com.hadi.retrofitmvvm.util.Resource 13 | import com.hadi.retrofitmvvm.util.Utils.hasInternetConnection 14 | import kotlinx.coroutines.launch 15 | import retrofit2.Response 16 | import java.io.IOException 17 | 18 | class PicsViewModel( 19 | app: Application, 20 | private val appRepository: AppRepository 21 | ) : AndroidViewModel(app) { 22 | 23 | val picsData: MutableLiveData> = MutableLiveData() 24 | 25 | init { 26 | getPictures() 27 | } 28 | 29 | fun getPictures() = viewModelScope.launch { 30 | fetchPics() 31 | } 32 | 33 | 34 | private suspend fun fetchPics() { 35 | picsData.postValue(Resource.Loading()) 36 | try { 37 | if (hasInternetConnection(getApplication())) { 38 | val response = appRepository.getPictures() 39 | picsData.postValue(handlePicsResponse(response)) 40 | } else { 41 | picsData.postValue(Resource.Error(getApplication().getString(R.string.no_internet_connection))) 42 | } 43 | } catch (t: Throwable) { 44 | when (t) { 45 | is IOException -> picsData.postValue( 46 | Resource.Error( 47 | getApplication().getString( 48 | R.string.network_failure 49 | ) 50 | ) 51 | ) 52 | else -> picsData.postValue( 53 | Resource.Error( 54 | getApplication().getString( 55 | R.string.conversion_error 56 | ) 57 | ) 58 | ) 59 | } 60 | } 61 | } 62 | 63 | private fun handlePicsResponse(response: Response): Resource { 64 | if (response.isSuccessful) { 65 | response.body()?.let { resultResponse -> 66 | return Resource.Success(resultResponse) 67 | } 68 | } 69 | return Resource.Error(response.message()) 70 | } 71 | 72 | 73 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 19 | 20 | 26 | 27 | 33 | 34 | 35 | 36 | 42 | 43 | 44 | 50 | 51 | 52 | 53 | 54 | 60 | 61 | 62 | 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/ui/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.ui 2 | 3 | import android.content.Intent 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.view.View 7 | import androidx.lifecycle.Observer 8 | import androidx.lifecycle.ViewModelProvider 9 | import androidx.recyclerview.widget.LinearLayoutManager 10 | import com.google.android.material.snackbar.Snackbar 11 | import com.hadi.retrofitmvvm.R 12 | import com.hadi.retrofitmvvm.adapter.PicsAdapter 13 | import com.hadi.retrofitmvvm.repository.AppRepository 14 | import com.hadi.retrofitmvvm.util.* 15 | import com.hadi.retrofitmvvm.viewmodel.PicsViewModel 16 | import com.hadi.retrofitmvvm.viewmodel.ViewModelProviderFactory 17 | import kotlinx.android.synthetic.main.activity_main.* 18 | 19 | class MainActivity : AppCompatActivity() { 20 | 21 | private lateinit var viewModel: PicsViewModel 22 | lateinit var picsAdapter: PicsAdapter 23 | 24 | override fun onCreate(savedInstanceState: Bundle?) { 25 | super.onCreate(savedInstanceState) 26 | setContentView(R.layout.activity_main) 27 | 28 | 29 | init() 30 | } 31 | 32 | private fun init() { 33 | rvPics.setHasFixedSize(true) 34 | rvPics.layoutManager = LinearLayoutManager(this) 35 | picsAdapter = PicsAdapter() 36 | setupViewModel() 37 | } 38 | 39 | private fun setupViewModel() { 40 | val repository = AppRepository() 41 | val factory = ViewModelProviderFactory(application, repository) 42 | viewModel = ViewModelProvider(this, factory).get(PicsViewModel::class.java) 43 | getPictures() 44 | } 45 | 46 | private fun getPictures() { 47 | viewModel.picsData.observe(this, Observer { response -> 48 | when (response) { 49 | is Resource.Success -> { 50 | hideProgressBar() 51 | response.data?.let { picsResponse -> 52 | picsAdapter.differ.submitList(picsResponse) 53 | rvPics.adapter = picsAdapter 54 | } 55 | } 56 | 57 | is Resource.Error -> { 58 | hideProgressBar() 59 | response.message?.let { message -> 60 | rootLayout.errorSnack(message,Snackbar.LENGTH_LONG) 61 | } 62 | 63 | } 64 | 65 | is Resource.Loading -> { 66 | showProgressBar() 67 | } 68 | } 69 | }) 70 | } 71 | 72 | private fun hideProgressBar() { 73 | progress.visibility = View.GONE 74 | } 75 | 76 | private fun showProgressBar() { 77 | progress.visibility = View.VISIBLE 78 | } 79 | 80 | 81 | fun onProgressClick(view: View) { 82 | //Preventing Click during loading 83 | } 84 | } -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/viewmodel/LoginViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.viewmodel 2 | 3 | import android.app.Application 4 | import androidx.lifecycle.AndroidViewModel 5 | import androidx.lifecycle.LiveData 6 | import androidx.lifecycle.MutableLiveData 7 | import androidx.lifecycle.viewModelScope 8 | import com.hadi.retrofitmvvm.R 9 | import com.hadi.retrofitmvvm.app.MyApplication 10 | import com.hadi.retrofitmvvm.model.loginResponse.LoginResponse 11 | import com.hadi.retrofitmvvm.network.RequestBodies 12 | import com.hadi.retrofitmvvm.repository.AppRepository 13 | import com.hadi.retrofitmvvm.util.Event 14 | import com.hadi.retrofitmvvm.util.Resource 15 | import com.hadi.retrofitmvvm.util.Utils 16 | import kotlinx.coroutines.launch 17 | import retrofit2.Response 18 | import java.io.IOException 19 | 20 | class LoginViewModel( 21 | app: Application, 22 | private val appRepository: AppRepository 23 | ) : AndroidViewModel(app) { 24 | 25 | private val _loginResponse = MutableLiveData>>() 26 | val loginResponse:LiveData>> = _loginResponse 27 | 28 | 29 | fun loginUser(body: RequestBodies.LoginBody) = viewModelScope.launch { 30 | login(body) 31 | } 32 | 33 | private suspend fun login(body: RequestBodies.LoginBody) { 34 | _loginResponse.postValue(Event(Resource.Loading())) 35 | try { 36 | if (Utils.hasInternetConnection(getApplication())) { 37 | val response = appRepository.loginUser(body) 38 | _loginResponse.postValue(handlePicsResponse(response)) 39 | } else { 40 | _loginResponse.postValue(Event(Resource.Error(getApplication().getString(R.string.no_internet_connection)))) 41 | } 42 | } catch (t: Throwable) { 43 | when (t) { 44 | is IOException -> { 45 | _loginResponse.postValue( 46 | Event(Resource.Error( 47 | getApplication().getString( 48 | R.string.network_failure 49 | ) 50 | )) 51 | ) 52 | } 53 | else -> { 54 | _loginResponse.postValue( 55 | Event(Resource.Error( 56 | getApplication().getString( 57 | R.string.conversion_error 58 | ) 59 | )) 60 | ) 61 | } 62 | } 63 | } 64 | } 65 | 66 | private fun handlePicsResponse(response: Response): Event>? { 67 | if (response.isSuccessful) { 68 | response.body()?.let { resultResponse -> 69 | return Event(Resource.Success(resultResponse)) 70 | } 71 | } 72 | return Event(Resource.Error(response.message())) 73 | } 74 | } -------------------------------------------------------------------------------- /app/src/main/java/com/hadi/retrofitmvvm/ui/LoginActivity.kt: -------------------------------------------------------------------------------- 1 | package com.hadi.retrofitmvvm.ui 2 | 3 | import android.content.Intent 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.text.TextUtils 7 | import android.view.View 8 | import androidx.lifecycle.Observer 9 | import androidx.lifecycle.ViewModelProvider 10 | import com.google.android.material.snackbar.Snackbar 11 | import com.hadi.retrofitmvvm.R 12 | import com.hadi.retrofitmvvm.network.RequestBodies 13 | import com.hadi.retrofitmvvm.repository.AppRepository 14 | import com.hadi.retrofitmvvm.util.Resource 15 | import com.hadi.retrofitmvvm.util.errorSnack 16 | import com.hadi.retrofitmvvm.viewmodel.LoginViewModel 17 | import com.hadi.retrofitmvvm.viewmodel.ViewModelProviderFactory 18 | import kotlinx.android.synthetic.main.activity_login.* 19 | 20 | class LoginActivity : AppCompatActivity() { 21 | 22 | lateinit var loginViewModel: LoginViewModel 23 | 24 | override fun onCreate(savedInstanceState: Bundle?) { 25 | super.onCreate(savedInstanceState) 26 | setContentView(R.layout.activity_login) 27 | 28 | init() 29 | } 30 | 31 | private fun init() { 32 | val repository = AppRepository() 33 | val factory = ViewModelProviderFactory(application, repository) 34 | loginViewModel = ViewModelProvider(this, factory).get(LoginViewModel::class.java) 35 | } 36 | 37 | fun onLoginClick(view: View) { 38 | var email = edt_mail.text.toString() 39 | val password = edt_pass.text.toString() 40 | 41 | if (email.isNotEmpty() && password.isNotEmpty()) { 42 | val body = RequestBodies.LoginBody( 43 | email, 44 | password 45 | ) 46 | 47 | loginViewModel.loginUser(body) 48 | loginViewModel.loginResponse.observe(this, Observer { event -> 49 | event.getContentIfNotHandled()?.let { response -> 50 | when (response) { 51 | is Resource.Success -> { 52 | hideProgressBar() 53 | response.data?.let { loginResponse -> 54 | Intent(this@LoginActivity, MainActivity::class.java).also { 55 | startActivity(it) 56 | } 57 | } 58 | } 59 | 60 | is Resource.Error -> { 61 | hideProgressBar() 62 | response.message?.let { message -> 63 | progress.errorSnack(message, Snackbar.LENGTH_LONG) 64 | } 65 | } 66 | 67 | is Resource.Loading -> { 68 | showProgressBar() 69 | } 70 | } 71 | } 72 | }) 73 | } 74 | } 75 | 76 | private fun hideProgressBar() { 77 | progress.visibility = View.GONE 78 | } 79 | 80 | private fun showProgressBar() { 81 | progress.visibility = View.VISIBLE 82 | } 83 | 84 | 85 | } -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | xmlns:android 17 | 18 | ^$ 19 | 20 | 21 | 22 |
23 |
24 | 25 | 26 | 27 | xmlns:.* 28 | 29 | ^$ 30 | 31 | 32 | BY_NAME 33 | 34 |
35 |
36 | 37 | 38 | 39 | .*:id 40 | 41 | http://schemas.android.com/apk/res/android 42 | 43 | 44 | 45 |
46 |
47 | 48 | 49 | 50 | .*:name 51 | 52 | http://schemas.android.com/apk/res/android 53 | 54 | 55 | 56 |
57 |
58 | 59 | 60 | 61 | name 62 | 63 | ^$ 64 | 65 | 66 | 67 |
68 |
69 | 70 | 71 | 72 | style 73 | 74 | ^$ 75 | 76 | 77 | 78 |
79 |
80 | 81 | 82 | 83 | .* 84 | 85 | ^$ 86 | 87 | 88 | BY_NAME 89 | 90 |
91 |
92 | 93 | 94 | 95 | .* 96 | 97 | http://schemas.android.com/apk/res/android 98 | 99 | 100 | ANDROID_ATTRIBUTE_ORDER 101 | 102 |
103 |
104 | 105 | 106 | 107 | .* 108 | 109 | .* 110 | 111 | 112 | BY_NAME 113 | 114 |
115 |
116 |
117 |
118 | 119 | 121 |
122 |
-------------------------------------------------------------------------------- /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/res/values/material_colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | #FFEBEE 9 | #FFCDD2 10 | #EF9A9A 11 | #E57373 12 | #EF5350 13 | #F44336 14 | #E53935 15 | #D32F2F 16 | #C62828 17 | #B71C1C 18 | #FF8A80 19 | #FF5252 20 | #FF1744 21 | #D50000 22 | 23 | 24 | #FCE4EC 25 | #F8BBD0 26 | #F48FB1 27 | #F06292 28 | #EC407A 29 | #E91E63 30 | #D81B60 31 | #C2185B 32 | #AD1457 33 | #880E4F 34 | #FF80AB 35 | #FF4081 36 | #F50057 37 | #C51162 38 | 39 | 40 | #F3E5F5 41 | #E1BEE7 42 | #CE93D8 43 | #BA68C8 44 | #AB47BC 45 | #9C27B0 46 | #8E24AA 47 | #7B1FA2 48 | #6A1B9A 49 | #4A148C 50 | #EA80FC 51 | #E040FB 52 | #D500F9 53 | #AA00FF 54 | 55 | 56 | #EDE7F6 57 | #D1C4E9 58 | #B39DDB 59 | #9575CD 60 | #7E57C2 61 | #673AB7 62 | #5E35B1 63 | #512DA8 64 | #4527A0 65 | #311B92 66 | #B388FF 67 | #7C4DFF 68 | #651FFF 69 | #6200EA 70 | 71 | 72 | #E8EAF6 73 | #C5CAE9 74 | #9FA8DA 75 | #7986CB 76 | #5C6BC0 77 | #3F51B5 78 | #3949AB 79 | #303F9F 80 | #283593 81 | #1A237E 82 | #8C9EFF 83 | #536DFE 84 | #3D5AFE 85 | #304FFE 86 | 87 | 88 | #E3F2FD 89 | #BBDEFB 90 | #90CAF9 91 | #64B5F6 92 | #42A5F5 93 | #2196F3 94 | #1E88E5 95 | #1976D2 96 | #1565C0 97 | #0D47A1 98 | #82B1FF 99 | #448AFF 100 | #2979FF 101 | #2962FF 102 | 103 | 104 | #E1F5FE 105 | #B3E5FC 106 | #81D4fA 107 | #4fC3F7 108 | #29B6FC 109 | #03A9F4 110 | #039BE5 111 | #0288D1 112 | #0277BD 113 | #01579B 114 | #80D8FF 115 | #40C4FF 116 | #00B0FF 117 | #0091EA 118 | 119 | 120 | #E0F7FA 121 | #B2EBF2 122 | #80DEEA 123 | #4DD0E1 124 | #26C6DA 125 | #00BCD4 126 | #00ACC1 127 | #0097A7 128 | #00838F 129 | #006064 130 | #84FFFF 131 | #18FFFF 132 | #00E5FF 133 | #00B8D4 134 | 135 | 136 | #E0F2F1 137 | #B2DFDB 138 | #80CBC4 139 | #4DB6AC 140 | #26A69A 141 | #009688 142 | #00897B 143 | #00796B 144 | #00695C 145 | #004D40 146 | #A7FFEB 147 | #64FFDA 148 | #1DE9B6 149 | #00BFA5 150 | 151 | 152 | #E8F5E9 153 | #C8E6C9 154 | #A5D6A7 155 | #81C784 156 | #66BB6A 157 | #4CAF50 158 | #43A047 159 | #388E3C 160 | #2E7D32 161 | #1B5E20 162 | #B9F6CA 163 | #69F0AE 164 | #00E676 165 | #00C853 166 | 167 | 168 | #F1F8E9 169 | #DCEDC8 170 | #C5E1A5 171 | #AED581 172 | #9CCC65 173 | #8BC34A 174 | #7CB342 175 | #689F38 176 | #558B2F 177 | #33691E 178 | #CCFF90 179 | #B2FF59 180 | #76FF03 181 | #64DD17 182 | 183 | 184 | #F9FBE7 185 | #F0F4C3 186 | #E6EE9C 187 | #DCE775 188 | #D4E157 189 | #CDDC39 190 | #C0CA33 191 | #A4B42B 192 | #9E9D24 193 | #827717 194 | #F4FF81 195 | #EEFF41 196 | #C6FF00 197 | #AEEA00 198 | 199 | 200 | #FFFDE7 201 | #FFF9C4 202 | #FFF590 203 | #FFF176 204 | #FFEE58 205 | #FFEB3B 206 | #FDD835 207 | #FBC02D 208 | #F9A825 209 | #F57F17 210 | #FFFF82 211 | #FFFF00 212 | #FFEA00 213 | #FFD600 214 | 215 | 216 | #FFF8E1 217 | #FFECB3 218 | #FFE082 219 | #FFD54F 220 | #FFCA28 221 | #FFC107 222 | #FFB300 223 | #FFA000 224 | #FF8F00 225 | #FF6F00 226 | #FFE57F 227 | #FFD740 228 | #FFC400 229 | #FFAB00 230 | 231 | 232 | #FFF3E0 233 | #FFE0B2 234 | #FFCC80 235 | #FFB74D 236 | #FFA726 237 | #FF9800 238 | #FB8C00 239 | #F57C00 240 | #EF6C00 241 | #E65100 242 | #FFD180 243 | #FFAB40 244 | #FF9100 245 | #FF6D00 246 | 247 | 248 | #FBE9A7 249 | #FFCCBC 250 | #FFAB91 251 | #FF8A65 252 | #FF7043 253 | #FF5722 254 | #F4511E 255 | #E64A19 256 | #D84315 257 | #BF360C 258 | #FF9E80 259 | #FF6E40 260 | #FF3D00 261 | #DD2600 262 | 263 | 264 | #EFEBE9 265 | #D7CCC8 266 | #BCAAA4 267 | #A1887F 268 | #8D6E63 269 | #795548 270 | #6D4C41 271 | #5D4037 272 | #4E342E 273 | #3E2723 274 | 275 | 276 | #FAFAFA 277 | #F5F5F5 278 | #EEEEEE 279 | #E0E0E0 280 | #BDBDBD 281 | #9E9E9E 282 | #757575 283 | #616161 284 | #424242 285 | #212121 286 | #000000 287 | #ffffff 288 | 289 | 290 | #ECEFF1 291 | #CFD8DC 292 | #B0BBC5 293 | #90A4AE 294 | #78909C 295 | #607D8B 296 | #546E7A 297 | #455A64 298 | #37474F 299 | #263238 300 | 301 | --------------------------------------------------------------------------------