Skip to content

Commit 37b80bd

Browse files
author
Ashwini Kumar
committed
Update to Kotlin 1.4.21
* Migration to databinding from kotlin synthetic view accessors wherever applicable * Migration to kotlinx parcelize plugin
1 parent c77c7bb commit 37b80bd

File tree

10 files changed

+114
-82
lines changed

10 files changed

+114
-82
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id("com.android.application")
33
kotlin("android")
44
kotlin("kapt")
5-
kotlin("android.extensions")
5+
kotlin("plugin.parcelize")
66
id("dagger.hilt.android.plugin")
77
}
88

app/src/main/java/com/android/tvmaze/favorite/FavoriteShowsActivity.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@ import androidx.appcompat.app.AppCompatActivity
1414
import androidx.core.content.ContextCompat
1515
import androidx.recyclerview.widget.GridLayoutManager
1616
import com.android.tvmaze.R
17+
import com.android.tvmaze.databinding.ActivityFavoriteShowsBinding
1718
import com.android.tvmaze.db.favouriteshow.FavoriteShow
1819
import com.android.tvmaze.utils.GridItemDecoration
1920
import dagger.hilt.android.AndroidEntryPoint
20-
import kotlinx.android.synthetic.main.activity_favorite_shows.*
21-
import kotlinx.android.synthetic.main.toolbar.view.*
2221

2322
@AndroidEntryPoint
2423
class FavoriteShowsActivity : AppCompatActivity(), FavoriteShowsAdapter.Callback {
2524
private val favoriteShowsViewModel: FavoriteShowsViewModel by viewModels()
25+
private val binding by lazy { ActivityFavoriteShowsBinding.inflate(layoutInflater) }
2626

2727
override fun onCreate(savedInstanceState: Bundle?) {
2828
super.onCreate(savedInstanceState)
29-
setContentView(R.layout.activity_favorite_shows)
29+
setContentView(binding.root)
3030
setToolbar()
3131
favoriteShowsViewModel.loadFavoriteShows()
3232
favoriteShowsViewModel.getFavoriteShowsLiveData()
3333
.observe(this, { showFavorites(it) })
3434
}
3535

3636
private fun setToolbar() {
37-
val toolbar = toolbar.toolbar
37+
val toolbar = binding.toolbar.toolbar
3838
setSupportActionBar(toolbar)
3939
toolbar.setTitleTextColor(ContextCompat.getColor(this, android.R.color.white))
4040
toolbar.setSubtitleTextColor(ContextCompat.getColor(this, android.R.color.white))
@@ -43,24 +43,24 @@ class FavoriteShowsActivity : AppCompatActivity(), FavoriteShowsAdapter.Callback
4343
}
4444

4545
private fun showFavorites(favoriteShows: List<FavoriteShow>) {
46-
progress.visibility = View.GONE
46+
binding.progress.visibility = View.GONE
4747
if (favoriteShows.isNotEmpty()) {
4848
val layoutManager = GridLayoutManager(this, COLUMNS_COUNT)
49-
shows.layoutManager = layoutManager
49+
binding.shows.layoutManager = layoutManager
5050
val favoriteShowsAdapter = FavoriteShowsAdapter(favoriteShows.toMutableList(), this)
51-
shows.adapter = favoriteShowsAdapter
51+
binding.shows.adapter = favoriteShowsAdapter
5252
val spacing = resources.getDimensionPixelSize(R.dimen.show_grid_spacing)
53-
shows.addItemDecoration(GridItemDecoration(spacing, COLUMNS_COUNT))
54-
shows.visibility = View.VISIBLE
53+
binding.shows.addItemDecoration(GridItemDecoration(spacing, COLUMNS_COUNT))
54+
binding.shows.visibility = View.VISIBLE
5555
} else {
5656
val bookmarkSpan = ImageSpan(this, R.drawable.favorite_border)
5757
val spannableString = SpannableString(getString(R.string.favorite_hint_msg))
5858
spannableString.setSpan(
5959
bookmarkSpan, FAVORITE_ICON_START_OFFSET,
6060
FAVORITE_ICON_END_OFFSET, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
6161
)
62-
favorite_hint.text = spannableString
63-
favorite_hint.visibility = View.VISIBLE
62+
binding.favoriteHint.text = spannableString
63+
binding.favoriteHint.visibility = View.VISIBLE
6464
}
6565
}
6666

app/src/main/java/com/android/tvmaze/home/HomeActivity.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ import androidx.appcompat.app.AppCompatActivity
1010
import androidx.core.content.ContextCompat
1111
import androidx.recyclerview.widget.GridLayoutManager
1212
import com.android.tvmaze.R
13+
import com.android.tvmaze.databinding.ActivityHomeBinding
1314
import com.android.tvmaze.favorite.FavoriteShowsActivity
1415
import com.android.tvmaze.shows.AllShowsActivity
1516
import com.android.tvmaze.utils.GridItemDecoration
1617
import dagger.hilt.android.AndroidEntryPoint
17-
import kotlinx.android.synthetic.main.activity_home.*
18-
import kotlinx.android.synthetic.main.toolbar.view.*
1918

2019
@AndroidEntryPoint
2120
class HomeActivity : AppCompatActivity(), ShowsAdapter.Callback {
2221
private val homeViewModel: HomeViewModel by viewModels()
2322
private lateinit var showsAdapter: ShowsAdapter
23+
private val binding by lazy { ActivityHomeBinding.inflate(layoutInflater) }
2424

2525
override fun onCreate(savedInstanceState: Bundle?) {
2626
super.onCreate(savedInstanceState)
27-
setContentView(R.layout.activity_home)
27+
setContentView(binding.root)
2828
setToolbar()
2929
homeViewModel.onScreenCreated()
3030
homeViewModel.getHomeViewState().observe(this, { setViewState(it) })
31-
popular_show_header.text = String.format(
31+
binding.popularShowHeader.text = String.format(
3232
getString(R.string.popular_shows_airing_today),
3333
homeViewModel.country
3434
)
@@ -49,7 +49,7 @@ class HomeActivity : AppCompatActivity(), ShowsAdapter.Callback {
4949
}
5050

5151
private fun setToolbar() {
52-
val toolbar = toolbar.toolbar
52+
val toolbar = binding.toolbar.toolbar
5353
setSupportActionBar(toolbar)
5454
toolbar.setTitleTextColor(ContextCompat.getColor(this, android.R.color.white))
5555
toolbar.setSubtitleTextColor(ContextCompat.getColor(this, android.R.color.white))
@@ -68,7 +68,7 @@ class HomeActivity : AppCompatActivity(), ShowsAdapter.Callback {
6868
val gridLayoutManager = GridLayoutManager(this, NO_OF_COLUMNS)
6969
showsAdapter = ShowsAdapter(this)
7070
showsAdapter.updateList(homeViewData.episodes.toMutableList())
71-
popular_shows.apply {
71+
binding.popularShows.apply {
7272
layoutManager = gridLayoutManager
7373
setHasFixedSize(true)
7474
adapter = showsAdapter
@@ -82,11 +82,11 @@ class HomeActivity : AppCompatActivity(), ShowsAdapter.Callback {
8282
}
8383

8484
private fun showProgress() {
85-
progress.visibility = View.VISIBLE
85+
binding.progress.visibility = View.VISIBLE
8686
}
8787

8888
private fun hideProgress() {
89-
progress.visibility = View.GONE
89+
binding.progress.visibility = View.GONE
9090
}
9191

9292
override fun onCreateOptionsMenu(menu: Menu): Boolean {

app/src/main/java/com/android/tvmaze/network/home/Episode.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.android.tvmaze.network.home
22

33
import android.os.Parcelable
44
import com.squareup.moshi.JsonClass
5-
import kotlinx.android.parcel.Parcelize
5+
import kotlinx.parcelize.Parcelize
66

77
@Parcelize
88
@JsonClass(generateAdapter = true)

app/src/main/java/com/android/tvmaze/network/home/Show.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.android.tvmaze.network.home
33
import android.os.Parcelable
44
import com.squareup.moshi.Json
55
import com.squareup.moshi.JsonClass
6-
import kotlinx.android.parcel.Parcelize
6+
import kotlinx.parcelize.Parcelize
77

88
@Parcelize
99
@JsonClass(generateAdapter = true)

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Deps {
55
const val target_sdk = 26
66
const val app_version_code = 104
77
const val app_version_name = "2.1.0"
8-
const val android_plugin = "4.0.1"
8+
const val android_plugin = "4.1.1"
99
const val constraint_layout = "2.0.0-beta4"
1010
const val lifecycle = "2.2.0"
1111
const val android_test = "1.2.0"
@@ -15,14 +15,14 @@ object Deps {
1515
const val mockito = "3.2.4"
1616
const val okhttp = "4.8.0"
1717
const val retrofit = "2.9.0"
18-
const val paging = "3.0.0-alpha04"
18+
const val paging = "3.0.0-alpha10"
1919
const val room = "2.2.5"
20-
const val kotlin = "1.4.0"
20+
const val kotlin = "1.4.21"
2121
const val timber = "4.7.1"
2222
const val mockito_kotlin = "2.2.0"
2323
const val arch_core_testing = "2.0.0"
24-
const val moshi = "1.9.2"
25-
const val coroutines = "1.3.7"
24+
const val moshi = "1.11.0"
25+
const val coroutines = "1.3.9"
2626
const val truth = "1.0.1"
2727
const val annotation = "1.1.0"
2828
const val chucker = "3.2.0"

gradle/wrapper/gradle-wrapper.jar

4.94 KB
Binary file not shown.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Sun Jun 14 15:55:13 IST 2020
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

gradlew

Lines changed: 66 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,59 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env sh
2+
3+
#
4+
# Copyright 2015 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
218

319
##############################################################################
420
##
521
## Gradle start up script for UN*X
622
##
723
##############################################################################
824

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=""
25+
# Attempt to set APP_HOME
26+
# Resolve links: $0 may be a link
27+
PRG="$0"
28+
# Need this for relative symlinks.
29+
while [ -h "$PRG" ] ; do
30+
ls=`ls -ld "$PRG"`
31+
link=`expr "$ls" : '.*-> \(.*\)$'`
32+
if expr "$link" : '/.*' > /dev/null; then
33+
PRG="$link"
34+
else
35+
PRG=`dirname "$PRG"`"/$link"
36+
fi
37+
done
38+
SAVED="`pwd`"
39+
cd "`dirname \"$PRG\"`/" >/dev/null
40+
APP_HOME="`pwd -P`"
41+
cd "$SAVED" >/dev/null
1142

1243
APP_NAME="Gradle"
1344
APP_BASE_NAME=`basename "$0"`
1445

46+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48+
1549
# Use the maximum available, or set MAX_FD != -1 to use that value.
1650
MAX_FD="maximum"
1751

18-
warn ( ) {
52+
warn () {
1953
echo "$*"
2054
}
2155

22-
die ( ) {
56+
die () {
2357
echo
2458
echo "$*"
2559
echo
@@ -30,6 +64,7 @@ die ( ) {
3064
cygwin=false
3165
msys=false
3266
darwin=false
67+
nonstop=false
3368
case "`uname`" in
3469
CYGWIN* )
3570
cygwin=true
@@ -40,26 +75,11 @@ case "`uname`" in
4075
MINGW* )
4176
msys=true
4277
;;
78+
NONSTOP* )
79+
nonstop=true
80+
;;
4381
esac
4482

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-
6383
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
6484

6585
# Determine the Java command to use to start the JVM.
@@ -85,7 +105,7 @@ location of your Java installation."
85105
fi
86106

87107
# Increase the maximum file descriptors if we can.
88-
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
108+
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
89109
MAX_FD_LIMIT=`ulimit -H -n`
90110
if [ $? -eq 0 ] ; then
91111
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
@@ -105,8 +125,8 @@ if $darwin; then
105125
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106126
fi
107127

108-
# For Cygwin, switch paths to Windows format before running java
109-
if $cygwin ; then
128+
# For Cygwin or MSYS, switch paths to Windows format before running java
129+
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
110130
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111131
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112132
JAVACMD=`cygpath --unix "$JAVACMD"`
@@ -134,27 +154,30 @@ if $cygwin ; then
134154
else
135155
eval `echo args$i`="\"$arg\""
136156
fi
137-
i=$((i+1))
157+
i=`expr $i + 1`
138158
done
139159
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" ;;
160+
0) set -- ;;
161+
1) set -- "$args0" ;;
162+
2) set -- "$args0" "$args1" ;;
163+
3) set -- "$args0" "$args1" "$args2" ;;
164+
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
165+
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
166+
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
167+
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
168+
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
169+
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150170
esac
151171
fi
152172

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=("$@")
173+
# Escape application args
174+
save () {
175+
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
176+
echo " "
156177
}
157-
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158-
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
178+
APP_ARGS=`save "$@"`
179+
180+
# Collect all arguments for the java command, following the shell quoting and substitution rules
181+
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
159182

160-
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
183+
exec "$JAVACMD" "$@"

0 commit comments

Comments
 (0)