├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── kotlin │ └── io │ │ └── github │ │ └── erikjhordanrey │ │ └── livebinding │ │ ├── di │ │ └── ServiceLocator.kt │ │ ├── model │ │ ├── DcCharacter.kt │ │ ├── DcCharacterDataSource.kt │ │ └── DcCharacterRepository.kt │ │ ├── view │ │ ├── DcCharacterActivity.kt │ │ ├── DcCharacterBinderAdapter.kt │ │ ├── DcCharacterBinderHolder.kt │ │ ├── DcCharacterBindingAdapter.kt │ │ └── images │ │ │ └── MarginDecoration.kt │ │ └── viewmodel │ │ ├── DcCharacterViewModel.kt │ │ └── DcCharacterViewModelFactory.kt │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ ├── activity_dc_character.xml │ └── item_dc_character.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.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 │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── art ├── Screenshot_1515036002.png ├── dc_data-live.png └── device-2018-01-03-211827.gif ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | .DS_Store 4 | /build 5 | /captures 6 | **.iml 7 | /.idea 8 | sdcard 9 | sdcard.lock 10 | libs/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LiveData-DataBinding-Kotlin 2 | 3 | As you may know Google introduced support for LiveData with Data Binding in [Android Studio 3.1 Canary 6](https://androidstudio.googleblog.com/2017/12/android-studio-31-canary-6-is-now.html). 4 | 5 | ## Project Goal 6 | 7 | Learn to use LiveData + Databinding 8 | 9 | ## LiveData + Data Binding 10 | 11 | 12 | ![](./art/dc_data-live.png) 13 | 14 | 15 | " You can now use a LiveData object as an observable field in data binding expressions. The ViewDataBinding class now includes a new setLifecycle method that you need to use to use to observe LiveData objects " 16 | 17 | 18 | ## Demo 19 | 20 | 21 | 22 | 23 | Do you want to contribute? 24 | -------------------------- 25 | Feel free to report or add any useful feature, I will be glad to improve it with your help. 26 | 27 | 28 | Code style 29 | -------------------------- 30 | 31 | This project is written on [Kotlin](https://kotlinlang.org/) and uses [ktlint](https://github.com/shyiko/ktlint). 32 | If you find that one of your pull reviews does not pass the CI server check due to a code style conflict, you can 33 | easily fix it by running: `./gradlew ktlintFormat`, or running IntelliJ/Android Studio's code formatter. 34 | 35 | 36 | Developed By 37 | ------------ 38 | 39 | * Erik Jhordan Rey - 40 | 41 | License 42 | ------- 43 | 44 | Copyright 2017 Erik Jhordan Rey 45 | 46 | Licensed under the Apache License, Version 2.0 (the "License"); 47 | you may not use this file except in compliance with the License. 48 | You may obtain a copy of the License at 49 | 50 | http://www.apache.org/licenses/LICENSE-2.0 51 | 52 | Unless required by applicable law or agreed to in writing, software 53 | distributed under the License is distributed on an "AS IS" BASIS, 54 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 55 | See the License for the specific language governing permissions and 56 | limitations under the License. 57 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'kotlin-kapt' 5 | 6 | configurations { 7 | ktlint 8 | } 9 | 10 | android { 11 | compileSdkVersion versions.compileSdk 12 | defaultConfig { 13 | applicationId "io.github.erikjhordanrey.livedata_databinding" 14 | minSdkVersion versions.minSdk 15 | targetSdkVersion versions.targetSdk 16 | versionCode 1 17 | versionName "1.0" 18 | } 19 | 20 | buildFeatures { 21 | dataBinding = true 22 | } 23 | 24 | buildTypes { 25 | release { 26 | minifyEnabled false 27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 28 | } 29 | } 30 | 31 | sourceSets { 32 | main.java.srcDirs += 'src/main/kotlin' 33 | } 34 | } 35 | 36 | dependencies { 37 | 38 | ktlint "com.github.shyiko:ktlint:${versions.ktlint}" 39 | 40 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}" 41 | implementation "androidx.appcompat:appcompat:${versions.androidxAppcompat}" 42 | implementation "androidx.recyclerview:recyclerview:${versions.androidx}" 43 | 44 | implementation "com.github.bumptech.glide:glide:${versions.glide}" 45 | kapt "com.github.bumptech.glide:compiler:${versions.glide}" 46 | 47 | implementation "androidx.lifecycle:lifecycle-extensions:${versions.lifecycle}" 48 | kapt "androidx.lifecycle:lifecycle-compiler:${versions.lifecycle}" 49 | } 50 | 51 | task ktlint(type: JavaExec) { 52 | main = "com.github.shyiko.ktlint.Main" 53 | classpath = configurations.ktlint 54 | args "src/**/*.kt" 55 | } 56 | 57 | check.dependsOn ktlint 58 | 59 | task ktlintFormat(type: JavaExec) { 60 | main = "com.github.shyiko.ktlint.Main" 61 | classpath = configurations.ktlint 62 | args "-F", "src/**/*.kt" 63 | } 64 | -------------------------------------------------------------------------------- /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 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/kotlin/io/github/erikjhordanrey/livebinding/di/ServiceLocator.kt: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.livebinding.di 2 | 3 | import androidx.lifecycle.ViewModelProvider 4 | import io.github.erikjhordanrey.livebinding.model.DcCharacterDataSource 5 | import io.github.erikjhordanrey.livebinding.model.DcCharacterRepository 6 | import io.github.erikjhordanrey.livebinding.view.DcCharacterActivity 7 | import io.github.erikjhordanrey.livebinding.viewmodel.DcCharacterViewModel 8 | import io.github.erikjhordanrey.livebinding.viewmodel.DcCharacterViewModelFactory 9 | 10 | object ServiceLocator { 11 | 12 | private val dcCharacterDataSource: DcCharacterDataSource = DcCharacterDataSource() 13 | 14 | private val dcCharacterRepository = DcCharacterRepository(dcCharacterDataSource) 15 | 16 | fun getDcCharacterViewModel(dcCharacterActivity: DcCharacterActivity) = 17 | ViewModelProvider(dcCharacterActivity, DcCharacterViewModelFactory(dcCharacterRepository)) 18 | .get(DcCharacterViewModel::class.java) 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/kotlin/io/github/erikjhordanrey/livebinding/model/DcCharacter.kt: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.livebinding.model 2 | 3 | data class DcCharacter(val name: String, val imageProfile: String) 4 | -------------------------------------------------------------------------------- /app/src/main/kotlin/io/github/erikjhordanrey/livebinding/model/DcCharacterDataSource.kt: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.livebinding.model 2 | 3 | class DcCharacterDataSource { 4 | 5 | val all: List 6 | get() = listOf(greenArrow(), 7 | greenLantern(), 8 | batman(), 9 | aquaman(), 10 | flash(), 11 | captainBoomerang(), 12 | superMan(), 13 | harleyQuinn(), 14 | joker(), 15 | captainCold() 16 | ) 17 | 18 | private fun greenArrow() = DcCharacter( 19 | "Green Arrow", 20 | "${IMAGE_URL}Char_Profile_GreenArrow_5c4915494b4039.94050514.jpg" 21 | ) 22 | 23 | private fun greenLantern() = DcCharacter( 24 | "Green Lantern", 25 | "${IMAGE_URL}Char_Profile_GreenLantern_20190116_5c3fc8c14ceda8.50076512.jpg" 26 | ) 27 | 28 | private fun batman() = DcCharacter( 29 | "Batman", 30 | "${IMAGE_URL}Char_Profile_Batman_20190116_5c3fc4b40faec2.47318964.jpg" 31 | ) 32 | 33 | private fun aquaman() = DcCharacter( 34 | "Aquaman", 35 | "${IMAGE_URL}Char_Profile_Aquaman_5c411a95e71072.35445903.jpg" 36 | ) 37 | 38 | private fun flash() = DcCharacter( 39 | "Flash", 40 | "${IMAGE_URL}Char_Profile_Flash_20190116_5c3fcaaa18f0e8.03668117.jpg" 41 | ) 42 | 43 | private fun captainBoomerang() = DcCharacter( 44 | "Captain Boomerang", 45 | "${IMAGE_URL}Char_Profile_CaptainBoomerang_5c47c7697e4c81.97961521.jpg" 46 | ) 47 | 48 | private fun superMan() = DcCharacter( 49 | "Bizarro", 50 | "${IMAGE_URL}Char_Profile_Bizarro_5c4114e7bebcd5.79694855.jpg" 51 | ) 52 | 53 | private fun harleyQuinn() = DcCharacter( 54 | "Harley Quinn", 55 | "${IMAGE_URL}Char_Profile_HarleyQuinn_5c4a3e75812334.21707976.jpg" 56 | ) 57 | 58 | private fun joker() = DcCharacter( 59 | "Joker", 60 | "${IMAGE_URL}Char_Profile_Joker_5c4a42b7ef2091.76638294.jpg" 61 | ) 62 | 63 | private fun captainCold() = DcCharacter( 64 | "Captain Cold", 65 | "${IMAGE_URL}Char_Profile_CaptainCold_5c47c824a31862.57032666.jpg" 66 | ) 67 | 68 | companion object { 69 | private const val IMAGE_URL = "https://www.dccomics.com/sites/default/files/styles/character_thumb_160x160/public/" 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/src/main/kotlin/io/github/erikjhordanrey/livebinding/model/DcCharacterRepository.kt: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.livebinding.model 2 | 3 | import java.util.Timer 4 | import java.util.Random 5 | import java.util.TimerTask 6 | import java.util.concurrent.TimeUnit 7 | 8 | typealias DcCharacterCommand = (List) -> Unit 9 | 10 | class DcCharacterRepository constructor(private val dcCharacterDataSource: DcCharacterDataSource) { 11 | 12 | private val timer = Timer() 13 | private val random = Random() 14 | private val period = TimeUnit.SECONDS.toMillis(PERIOD_SECONDS) 15 | 16 | internal fun receiverDcCharacterList(dcCommand: DcCharacterCommand) { 17 | timer.schedule(object : TimerTask() { 18 | override fun run() { 19 | val dcCharacterList = dcCharacterDataSource.all 20 | var randomMax = random.nextInt(dcCharacterList.size) 21 | 22 | when (randomMax) { 23 | MIN_INDEX -> { 24 | randomMax += 1 25 | } 26 | } 27 | 28 | dcCommand.invoke(dcCharacterList.subList(MIN_INDEX, randomMax)) 29 | } 30 | }, period, period) 31 | } 32 | 33 | companion object { 34 | private const val PERIOD_SECONDS: Long = 2 35 | private const val MIN_INDEX = 0 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/kotlin/io/github/erikjhordanrey/livebinding/view/DcCharacterActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.livebinding.view 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import androidx.databinding.DataBindingUtil 6 | import androidx.recyclerview.widget.GridLayoutManager 7 | import io.github.erikjhordanrey.livebinding.R 8 | import io.github.erikjhordanrey.livebinding.databinding.ActivityDcCharacterBinding 9 | import io.github.erikjhordanrey.livebinding.di.ServiceLocator 10 | import io.github.erikjhordanrey.livebinding.view.images.MarginDecoration 11 | import kotlinx.android.synthetic.main.activity_dc_character.recycler_dc_character 12 | 13 | class DcCharacterActivity : AppCompatActivity() { 14 | 15 | private val dcCharacterBinderAdapter: DcCharacterBinderAdapter by lazy { DcCharacterBinderAdapter() } 16 | private lateinit var activityDcCharacterBinding: ActivityDcCharacterBinding 17 | 18 | override fun onCreate(savedInstanceState: Bundle?) { 19 | super.onCreate(savedInstanceState) 20 | activityDcCharacterBinding = DataBindingUtil.setContentView(this, R.layout.activity_dc_character) 21 | initRecycler() 22 | initObserver() 23 | } 24 | 25 | private fun initRecycler() { 26 | recycler_dc_character.run { 27 | addItemDecoration(MarginDecoration(context)) 28 | layoutManager = GridLayoutManager(context, 2) 29 | setHasFixedSize(true) 30 | adapter = dcCharacterBinderAdapter 31 | } 32 | } 33 | 34 | private fun initObserver() { 35 | val dcCharacterViewModel = ServiceLocator.getDcCharacterViewModel(this) 36 | activityDcCharacterBinding.run { 37 | viewModel = dcCharacterViewModel 38 | lifecycleOwner = this@DcCharacterActivity 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/kotlin/io/github/erikjhordanrey/livebinding/view/DcCharacterBinderAdapter.kt: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.livebinding.view 2 | 3 | import android.view.LayoutInflater 4 | import android.view.ViewGroup 5 | import androidx.databinding.DataBindingUtil 6 | import androidx.recyclerview.widget.RecyclerView 7 | import io.github.erikjhordanrey.livebinding.R 8 | import io.github.erikjhordanrey.livebinding.model.DcCharacter 9 | 10 | class DcCharacterBinderAdapter : RecyclerView.Adapter() { 11 | 12 | private var dcCharacterList: List = emptyList() 13 | 14 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DcCharacterBinderHolder = 15 | DcCharacterBinderHolder(DataBindingUtil.inflate(LayoutInflater.from(parent.context), 16 | R.layout.item_dc_character, parent, false)) 17 | 18 | override fun onBindViewHolder(holder: DcCharacterBinderHolder, position: Int) { 19 | val dcCharacter = dcCharacterList[position] 20 | holder.bind(dcCharacter) 21 | } 22 | 23 | override fun getItemCount() = dcCharacterList.size 24 | 25 | fun setDcCharacterList(dcCharacterList: List) { 26 | this.dcCharacterList = dcCharacterList 27 | notifyDataSetChanged() 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/kotlin/io/github/erikjhordanrey/livebinding/view/DcCharacterBinderHolder.kt: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.livebinding.view 2 | 3 | import androidx.databinding.ViewDataBinding 4 | import androidx.recyclerview.widget.RecyclerView 5 | import io.github.erikjhordanrey.livebinding.BR 6 | import io.github.erikjhordanrey.livebinding.model.DcCharacter 7 | 8 | class DcCharacterBinderHolder constructor(private val viewDataBinding: ViewDataBinding) : RecyclerView.ViewHolder(viewDataBinding.root) { 9 | 10 | fun bind(dcCharacter: DcCharacter) { 11 | viewDataBinding.setVariable(BR.dcCharacter, dcCharacter) 12 | viewDataBinding.executePendingBindings() 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/kotlin/io/github/erikjhordanrey/livebinding/view/DcCharacterBindingAdapter.kt: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.livebinding.view 2 | 3 | import android.widget.ImageView 4 | import androidx.databinding.BindingAdapter 5 | import androidx.recyclerview.widget.RecyclerView 6 | import com.bumptech.glide.Glide 7 | import io.github.erikjhordanrey.livebinding.model.DcCharacter 8 | 9 | @BindingAdapter("imageUrl") 10 | fun loadImage(imageView: ImageView, url: String) { 11 | Glide.with(imageView.context).load(url).into(imageView) 12 | } 13 | 14 | @BindingAdapter(value = ["android:characters"]) 15 | fun bindAdapter(recyclerView: RecyclerView, characters: List?) { 16 | val adapter = recyclerView.adapter 17 | characters?.let { if (adapter is DcCharacterBinderAdapter) adapter.setDcCharacterList(it) } 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/kotlin/io/github/erikjhordanrey/livebinding/view/images/MarginDecoration.kt: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.livebinding.view.images 2 | 3 | import android.content.Context 4 | import android.graphics.Rect 5 | import android.view.View 6 | import androidx.recyclerview.widget.RecyclerView 7 | import io.github.erikjhordanrey.livebinding.R 8 | 9 | class MarginDecoration(context: Context) : RecyclerView.ItemDecoration() { 10 | 11 | private var margin: Int = context.resources.getDimensionPixelSize(R.dimen.item_margin) 12 | 13 | override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) { 14 | outRect.set(margin, margin, margin, margin) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/kotlin/io/github/erikjhordanrey/livebinding/viewmodel/DcCharacterViewModel.kt: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.livebinding.viewmodel 2 | 3 | import androidx.lifecycle.LiveData 4 | import androidx.lifecycle.MutableLiveData 5 | import androidx.lifecycle.ViewModel 6 | import io.github.erikjhordanrey.livebinding.model.DcCharacter 7 | import io.github.erikjhordanrey.livebinding.model.DcCharacterRepository 8 | 9 | class DcCharacterViewModel(dcCharacterRepository: DcCharacterRepository) : ViewModel() { 10 | 11 | private val dcCharacterListMutableLive = MutableLiveData>() 12 | 13 | init { 14 | dcCharacterRepository.receiverDcCharacterList { dcCharacterListMutableLive.postValue(it) } 15 | } 16 | 17 | fun getDcCharacterList() = dcCharacterListMutableLive as LiveData> 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/kotlin/io/github/erikjhordanrey/livebinding/viewmodel/DcCharacterViewModelFactory.kt: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.livebinding.viewmodel 2 | 3 | import androidx.lifecycle.ViewModel 4 | import androidx.lifecycle.ViewModelProvider 5 | import io.github.erikjhordanrey.livebinding.model.DcCharacterRepository 6 | 7 | @Suppress("UNCHECKED_CAST") 8 | class DcCharacterViewModelFactory(private val dcCharacterRepository: DcCharacterRepository) : ViewModelProvider.Factory { 9 | 10 | override fun create(modelClass: Class): T { 11 | if (modelClass.isAssignableFrom(DcCharacterViewModel::class.java)) { 12 | return DcCharacterViewModel(dcCharacterRepository) as T 13 | } 14 | throw IllegalArgumentException("Unknown ViewModel class") 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /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/layout/activity_dc_character.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 16 | 17 | 28 | 29 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_dc_character.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 15 | 16 | 22 | 23 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/LiveData-DataBinding-Kotlin/75ae78923f900c18debdf0f88805e71ce0a06587/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/LiveData-DataBinding-Kotlin/75ae78923f900c18debdf0f88805e71ce0a06587/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/LiveData-DataBinding-Kotlin/75ae78923f900c18debdf0f88805e71ce0a06587/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/LiveData-DataBinding-Kotlin/75ae78923f900c18debdf0f88805e71ce0a06587/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/LiveData-DataBinding-Kotlin/75ae78923f900c18debdf0f88805e71ce0a06587/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/LiveData-DataBinding-Kotlin/75ae78923f900c18debdf0f88805e71ce0a06587/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/LiveData-DataBinding-Kotlin/75ae78923f900c18debdf0f88805e71ce0a06587/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/LiveData-DataBinding-Kotlin/75ae78923f900c18debdf0f88805e71ce0a06587/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/LiveData-DataBinding-Kotlin/75ae78923f900c18debdf0f88805e71ce0a06587/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/LiveData-DataBinding-Kotlin/75ae78923f900c18debdf0f88805e71ce0a06587/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #1E88E5 4 | #1565C0 5 | #212121 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4dp 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | LiveData-DataBinding 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /art/Screenshot_1515036002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/LiveData-DataBinding-Kotlin/75ae78923f900c18debdf0f88805e71ce0a06587/art/Screenshot_1515036002.png -------------------------------------------------------------------------------- /art/dc_data-live.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/LiveData-DataBinding-Kotlin/75ae78923f900c18debdf0f88805e71ce0a06587/art/dc_data-live.png -------------------------------------------------------------------------------- /art/device-2018-01-03-211827.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/LiveData-DataBinding-Kotlin/75ae78923f900c18debdf0f88805e71ce0a06587/art/device-2018-01-03-211827.gif -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | 3 | ext.versions = [ 4 | 'compileSdk' : 29, 5 | 'minSdk' : 21, 6 | 'targetSdk' : 29, 7 | 'androidGradle' : '4.0.1', 8 | 'androidx' : '1.1.0', 9 | 'androidxAppcompat': '1.1.0', 10 | 'lifecycle' : '2.2.0', 11 | 'glide' : '4.11.0', 12 | 'kotlin' : '1.3.72', 13 | 'ktlint' : '0.29.0' 14 | ] 15 | 16 | repositories { 17 | mavenCentral() 18 | google() 19 | jcenter() 20 | } 21 | dependencies { 22 | classpath "com.android.tools.build:gradle:${versions.androidGradle}" 23 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" 24 | } 25 | } 26 | 27 | allprojects { 28 | repositories { 29 | mavenCentral() 30 | google() 31 | jcenter() 32 | } 33 | } 34 | 35 | task clean(type: Delete) { 36 | delete rootProject.buildDir 37 | } 38 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | 19 | # AndroidX 20 | android.useAndroidX=true 21 | android.enableJetifier=true 22 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/LiveData-DataBinding-Kotlin/75ae78923f900c18debdf0f88805e71ce0a06587/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jul 15 15:19:47 CDT 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 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------