Skip to content

Commit

Permalink
Upgraded Compose to beta07 and other dependencies. Removed kotlin-and…
Browse files Browse the repository at this point in the history
…roid-extensions (#549)

Tech debt dependencies cleanup.

The biggest change is migrating from kotlin-android-extensions to view binding and kotlin-parcelize
  • Loading branch information
gpeal authored May 19, 2021
1 parent d67c701 commit b6dddde
Show file tree
Hide file tree
Showing 52 changed files with 173 additions and 188 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ buildscript {
}
dependencies {
classpath "com.android.tools.build:gradle:${Versions.gradlePlugin}"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:${Versions.kotlin}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
classpath "com.google.dagger:hilt-android-gradle-plugin:${Versions.hilt}"

Expand Down
4 changes: 2 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {

dependencies {
implementation(gradleApi())
implementation("com.android.tools.build:gradle:7.0.0-alpha08")
implementation("com.android.tools.build:gradle:7.0.0-beta01")
implementation("org.jacoco:org.jacoco.core:0.8.5")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32")
}
26 changes: 13 additions & 13 deletions buildSrc/src/main/java/dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ object Versions {
// Build tools and SDK
const val buildTools = "30.0.3"
const val compileSdk = 30
const val gradlePlugin = "7.0.0-alpha14"
const val gradlePlugin = "7.0.0-beta01"
const val kotlin = "1.4.32"
const val minSdk = 16
const val targetSdk = 29

// Android libraries
const val activity = "1.2.0"
const val activityCompose = "1.3.0-alpha03"
const val appcompat = "1.2.0"
const val activity = "1.2.3"
const val activityCompose = "1.3.0-alpha08"
const val appcompat = "1.3.0"
const val arch = "2.1.0"
const val cardview = "1.0.0"
const val constraintlayout = "2.0.0"
const val coordinatorLayout = "1.1.0"
const val compose = "1.0.0-beta01"
const val core = "1.3.1"
const val fragment = "1.3.0"
const val lifecycle = "2.2.0"
const val navigation = "2.3.0"
const val navigationCompose = "1.0.0-alpha08"
const val recyclerview = "1.1.0"
const val room = "2.2.5"
const val viewModelCompose = "1.0.0-alpha02"
const val compose = "1.0.0-beta07"
const val core = "1.5.0"
const val fragment = "1.3.4"
const val lifecycle = "2.3.1"
const val navigation = "2.3.5"
const val navigationCompose = "2.4.0-alpha01"
const val recyclerview = "1.2.0"
const val room = "2.3.0"
const val viewModelCompose = "1.0.0-alpha05"

// Libraries
const val autoValue = "1.6.6"
Expand Down
6 changes: 5 additions & 1 deletion counter/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"

android {
defaultConfig {
applicationId 'com.airbnb.mvrx.counter'
versionCode 1
versionName '1.0'
}

buildFeatures {
viewBinding true
}
}

dependencies {
Expand All @@ -17,6 +20,7 @@ dependencies {
implementation Libraries.lifecycleCommon

implementation project(":mvrx")
implementation project(":view-binding-utils")

testImplementation TestLibraries.junit
testImplementation project(":testing")
Expand Down
19 changes: 7 additions & 12 deletions counter/src/main/java/com/airbnb/mvrx/counter/CounterFragment.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.airbnb.mvrx.counter

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.airbnb.mvrx.MavericksState
import com.airbnb.mvrx.MavericksView
import com.airbnb.mvrx.MavericksViewModel
import com.airbnb.mvrx.MavericksState
import com.airbnb.mvrx.PersistState
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.counter.databinding.CounterFragmentBinding
import com.airbnb.mvrx.viewbinding.viewBinding
import com.airbnb.mvrx.withState
import kotlinx.android.synthetic.main.fragment_counter.counterText

data class CounterState(@PersistState val count: Int = 0) : MavericksState

Expand All @@ -20,21 +19,17 @@ class CounterViewModel(state: CounterState) : MavericksViewModel<CounterState>(s
fun incrementCount() = setState { copy(count = count + 1) }
}

class CounterFragment : Fragment(), MavericksView {

class CounterFragment : Fragment(R.layout.counter_fragment), MavericksView {
private val binding: CounterFragmentBinding by viewBinding()
private val viewModel: CounterViewModel by activityViewModel()

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_counter, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
counterText.setOnClickListener {
binding.counterText.setOnClickListener {
viewModel.incrementCount()
}
}

override fun invalidate() = withState(viewModel) { state ->
counterText.text = "${state.count}"
binding.counterText.text = "${state.count}"
}
}
4 changes: 3 additions & 1 deletion dogs/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply plugin: "kotlin-kapt"
apply plugin: "kotlin-android-extensions"

android {

defaultConfig {
applicationId "com.airbnb.mvrx.dogs"
versionCode 1
versionName "1.0"
multiDexEnabled true
}

buildFeatures {
Expand All @@ -23,10 +23,12 @@ dependencies {
implementation Libraries.coreKtx
implementation Libraries.epoxy
implementation Libraries.lottie
implementation Libraries.multidex
implementation Libraries.navigationFragmentKtx
implementation Libraries.navigationUiKtx
implementation Libraries.picasso
implementation project(":mvrx-rxjava2")
implementation project(":view-binding-utils")

testImplementation TestLibraries.junit
testImplementation project(":testing")
Expand Down
16 changes: 4 additions & 12 deletions dogs/src/main/java/com/airbnb/mvrx/dogs/AdoptionFragment.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
package com.airbnb.mvrx.dogs

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.airbnb.mvrx.MvRxView
import com.airbnb.mvrx.MavericksView
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.dogs.databinding.AdoptionFragmentBinding
import com.airbnb.mvrx.viewbinding.viewBinding
import com.airbnb.mvrx.withState

class AdoptionFragment : Fragment(), MvRxView {
class AdoptionFragment : Fragment(R.layout.adoption_fragment), MavericksView {
private val binding: AdoptionFragmentBinding by viewBinding()
private val viewModel: DogViewModel by activityViewModel()
private lateinit var binding: AdoptionFragmentBinding

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = AdoptionFragmentBinding.inflate(inflater, container, false)
return binding.root
}

override fun invalidate() = withState(viewModel) { state ->
binding.dog = state.adoptionRequest()
Expand Down
15 changes: 5 additions & 10 deletions dogs/src/main/java/com/airbnb/mvrx/dogs/DogDetailFragment.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
package com.airbnb.mvrx.dogs

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.MvRxView
import com.airbnb.mvrx.MavericksView
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.args
import com.airbnb.mvrx.dogs.databinding.DogDetailFragmentBinding
import com.airbnb.mvrx.dogs.views.DogDetailFragmentHandler
import com.airbnb.mvrx.viewbinding.viewBinding
import com.airbnb.mvrx.withState

class DogDetailFragment : Fragment(), MvRxView, DogDetailFragmentHandler {

class DogDetailFragment : Fragment(R.layout.dog_detail_fragment), MavericksView, DogDetailFragmentHandler {
private val binding: DogDetailFragmentBinding by viewBinding()
private val viewModel: DogViewModel by activityViewModel()
private val dogId: Long by args()

private lateinit var binding: DogDetailFragmentBinding

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = DogDetailFragmentBinding.inflate(inflater, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding.handler = this
return binding.root
}

override fun onLoveClicked() {
Expand Down
21 changes: 8 additions & 13 deletions dogs/src/main/java/com/airbnb/mvrx/dogs/DogsFragment.kt
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
package com.airbnb.mvrx.dogs

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.airbnb.mvrx.MvRxView
import com.airbnb.mvrx.MavericksView
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.dogs.data.Dog
import com.airbnb.mvrx.dogs.databinding.DogsFragmentBinding
import com.airbnb.mvrx.dogs.views.DogsFragmentHandler
import com.airbnb.mvrx.viewbinding.viewBinding
import com.airbnb.mvrx.withState

class DogsFragment : Fragment(), MvRxView, DogsFragmentHandler {

class DogsFragment : Fragment(R.layout.dogs_fragment), MavericksView, DogsFragmentHandler {
private val binding: DogsFragmentBinding by viewBinding()
private val viewModel: DogViewModel by activityViewModel()
private lateinit var bindings: DogsFragmentBinding
private val adapter = DogAdapter(this)

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
bindings = DogsFragmentBinding.inflate(inflater, container, false)
bindings.dogsRecyclerView.adapter = adapter
bindings.handler = this
return bindings.root
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding.handler = this
binding.dogsRecyclerView.adapter = DogAdapter(this)
}

override fun onDogClicked(dog: Dog) {
Expand All @@ -36,6 +31,6 @@ class DogsFragment : Fragment(), MvRxView, DogsFragmentHandler {
}

override fun invalidate() = withState(viewModel) { state ->
bindings.state = state
binding.state = state
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 5 additions & 1 deletion hellodagger/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
apply plugin: "kotlin-kapt"

android {
Expand Down Expand Up @@ -29,6 +28,10 @@ android {
keyPassword "testing"
}
}

buildFeatures {
viewBinding true
}
}

dependencies {
Expand All @@ -45,6 +48,7 @@ dependencies {
implementation project(":mvrx")
implementation project(":mvrx-mocking")
implementation project(":launcher")
implementation project(":view-binding-utils")

debugImplementation Libraries.fragmentTesting

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@ import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.Success
import com.airbnb.mvrx.Uninitialized
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.hellodagger.databinding.HelloFragmentBinding
import com.airbnb.mvrx.mocking.MavericksViewMocks
import com.airbnb.mvrx.mocking.MockableMavericksView
import com.airbnb.mvrx.mocking.mockSingleViewModel
import com.airbnb.mvrx.viewbinding.viewBinding
import com.airbnb.mvrx.withState
import kotlinx.android.synthetic.main.fragment_hello.helloButton
import kotlinx.android.synthetic.main.fragment_hello.messageTextView

class HelloFragment : Fragment(R.layout.fragment_hello), MockableMavericksView {
class HelloFragment : Fragment(R.layout.hello_fragment), MockableMavericksView {
private val binding: HelloFragmentBinding by viewBinding()

val viewModel: HelloDaggerViewModel by fragmentViewModel()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
helloButton.setOnClickListener { viewModel.sayHello() }
binding.helloButton.setOnClickListener { viewModel.sayHello() }
}

override fun invalidate() = withState(viewModel) { state ->
helloButton.isEnabled = state.message !is Loading
messageTextView.text = when (state.message) {
binding.helloButton.isEnabled = state.message !is Loading
binding.messageTextView.text = when (state.message) {
is Uninitialized, is Loading -> getString(R.string.hello_fragment_loading_text)
is Success -> state.message()
is Fail -> getString(R.string.hello_fragment_failure_text)
Expand Down
1 change: 1 addition & 0 deletions hellohilt/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ dependencies {
kapt AnnotationProcessors.hilt
implementation Libraries.hilt
implementation project(":mvrx-rxjava2")
implementation project(":view-binding-utils")
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
package com.airbnb.mvrx.hellohilt

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.annotation.SuppressLint
import androidx.fragment.app.Fragment
import com.airbnb.mvrx.MvRxView
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.hellohilt.databinding.HelloHiltFragmentBinding
import com.airbnb.mvrx.viewbinding.viewBinding
import com.airbnb.mvrx.withState
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class HelloHiltFragment : Fragment(R.layout.hello_hilt_fragment), MvRxView {
val viewModel1: HelloHiltViewModel by fragmentViewModel(keyFactory = { "a" })
val viewModel2: HelloHiltViewModel by fragmentViewModel(keyFactory = { "b" })

private var _binding: HelloHiltFragmentBinding? = null
private val binding get() = _binding ?: error("Binding was null!")

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
_binding = HelloHiltFragmentBinding.inflate(inflater, container, false)
return binding.root
}

override fun onDestroyView() {
_binding = null
super.onDestroyView()
}
private val binding: HelloHiltFragmentBinding by viewBinding()
private val viewModel1: HelloHiltViewModel by fragmentViewModel(keyFactory = { "a" })
private val viewModel2: HelloHiltViewModel by fragmentViewModel(keyFactory = { "b" })

@SuppressLint("SetTextI18n")
override fun invalidate() = withState(viewModel1, viewModel2) { state1, state2 ->
@Suppress("Detekt.MaxLineLength")
binding.with.text = "@MavericksViewModelScoped: VM1: [${state1.viewModelScopedClassId1},${state1.viewModelScopedClassId2}] VM2: [${state2.viewModelScopedClassId1},${state2.viewModelScopedClassId2}]"
Expand Down
2 changes: 1 addition & 1 deletion mvrx-compose/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ POM_NAME=Mavericks Compose
POM_ARTIFACT_ID=mavericks-compose
POM_PACKAGING=aar
GROUP=com.airbnb.android
VERSION_NAME=2.1.0-alpha01-SNAPSHOT
VERSION_NAME=2.1.0-alpha02-SNAPSHOT
Loading

0 comments on commit b6dddde

Please sign in to comment.