Skip to content

Commit 7547601

Browse files
author
Adrian Devezin
committed
Convert Java to Kotlin
1 parent 6c446d9 commit 7547601

File tree

16 files changed

+374
-409
lines changed

16 files changed

+374
-409
lines changed

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
apply plugin: 'com.android.application'
2-
32
apply plugin: 'kotlin-android'
4-
53
apply plugin: 'kotlin-android-extensions'
64

75
android {
8-
compileSdkVersion 26
6+
compileSdkVersion 28
97
defaultConfig {
108
applicationId "com.alessandrosperotti.expandablecardviewexample"
119
minSdkVersion 22
12-
targetSdkVersion 26
10+
targetSdkVersion 28
1311
versionCode 1
1412
versionName "1.0"
15-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1614
}
1715
buildTypes {
1816
release {
@@ -24,12 +22,12 @@ android {
2422

2523
dependencies {
2624
implementation fileTree(dir: 'libs', include: ['*.jar'])
27-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
28-
implementation 'com.android.support:appcompat-v7:26.1.0'
29-
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
30-
implementation "com.android.support:design:26.1.0"
25+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
26+
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
27+
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
28+
implementation "com.google.android.material:material:1.1.0-alpha02"
3129
testImplementation 'junit:junit:4.12'
32-
androidTestImplementation 'com.android.support.test:runner:1.0.1'
33-
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
34-
compile project(':expandablecardview')
30+
androidTestImplementation 'androidx.test:runner:1.1.1'
31+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
32+
implementation project(':expandablecardview')
3533
}

app/src/androidTest/java/com/alessandrosperotti/expandablecardviewexample/ExampleInstrumentedTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.alessandrosperotti.expandablecardviewexample
22

3-
import android.support.test.InstrumentationRegistry
4-
import android.support.test.runner.AndroidJUnit4
3+
import androidx.test.InstrumentationRegistry
4+
import androidx.test.runner.AndroidJUnit4
55

66
import org.junit.Test
77
import org.junit.runner.RunWith

app/src/main/java/com/alessandrosperotti/expandablecardviewexample/MainActivity.kt

+6-16
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@ package com.alessandrosperotti.expandablecardviewexample
22

33
import android.content.res.ColorStateList
44
import android.graphics.Color
5-
import android.support.v7.app.AppCompatActivity
5+
import androidx.appcompat.app.AppCompatActivity
66
import android.os.Bundle
7-
import android.support.design.widget.CollapsingToolbarLayout
8-
import android.support.v7.widget.Toolbar
97
import android.view.Menu
10-
import android.view.View
118
import android.widget.Toast
12-
import com.alespero.expandablecardview.ExpandableCardView
13-
import android.R.menu
149
import android.content.Intent
1510
import android.net.Uri
16-
import android.view.MenuInflater
1711
import android.view.MenuItem
12+
import kotlinx.android.synthetic.main.activity_main.*
1813
import kotlinx.android.synthetic.main.location.*
1914

2015

@@ -26,23 +21,18 @@ class MainActivity : AppCompatActivity() {
2621
super.onCreate(savedInstanceState)
2722
setContentView(R.layout.activity_main)
2823

29-
val toolbar = findViewById<Toolbar>(R.id.toolbar)
30-
setSupportActionBar(toolbar)
24+
setSupportActionBar(main_toolbar)
3125

32-
val collapsingToolbarLayout = findViewById<CollapsingToolbarLayout>(R.id.ctl)
33-
collapsingToolbarLayout.setCollapsedTitleTextColor(Color.WHITE)
34-
collapsingToolbarLayout.setExpandedTitleTextColor(ColorStateList.valueOf(Color.WHITE))
26+
main_collapsing_toolbar_layout.setCollapsedTitleTextColor(Color.WHITE)
27+
main_collapsing_toolbar_layout.setExpandedTitleTextColor(ColorStateList.valueOf(Color.WHITE))
3528

3629
buttonMaps.setOnClickListener {
3730
val uri = Uri.parse("geo:25.7906500,-80.1300500?q=Miami Beach&z=10")
3831
intent = Intent(Intent.ACTION_VIEW, uri)
3932
startActivity(intent)
4033
}
4134

42-
43-
val card : ExpandableCardView = findViewById(R.id.profile)
44-
45-
card.setOnExpandedListener { _, isExpanded ->
35+
main_profile_card.setOnExpandedListener { _, isExpanded ->
4636
if(isExpanded) Toast.makeText(applicationContext, "Expanded!", Toast.LENGTH_SHORT).show()
4737
else Toast.makeText(applicationContext, "Collapsed!", Toast.LENGTH_SHORT).show()
4838
}

app/src/main/res/layout/activity_main.xml

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent"
2+
<androidx.coordinatorlayout.widget.CoordinatorLayout android:layout_width="match_parent"
33
android:layout_height="match_parent"
44
xmlns:android="http://schemas.android.com/apk/res/android"
55
xmlns:app="http://schemas.android.com/apk/res-auto">
66

7-
<android.support.design.widget.AppBarLayout
7+
<com.google.android.material.appbar.AppBarLayout
88
android:layout_height="252dp"
99
android:layout_width="match_parent"
1010
android:fitsSystemWindows="true">
11-
<android.support.design.widget.CollapsingToolbarLayout
12-
android:id="@+id/ctl"
11+
<com.google.android.material.appbar.CollapsingToolbarLayout
12+
android:id="@+id/main_collapsing_toolbar_layout"
1313
android:layout_width="match_parent"
1414
android:layout_height="match_parent"
1515
app:layout_scrollFlags="scroll|exitUntilCollapsed"
@@ -25,16 +25,16 @@
2525
android:adjustViewBounds="true"
2626
android:fitsSystemWindows="true"
2727
android:scaleType="centerCrop"/>
28-
<android.support.v7.widget.Toolbar
29-
android:id="@+id/toolbar"
28+
<androidx.appcompat.widget.Toolbar
29+
android:id="@+id/main_toolbar"
3030
android:layout_height="?attr/actionBarSize"
3131
android:layout_width="match_parent"
3232
android:theme="@style/toolbarTheme"
3333
app:layout_collapseMode="pin"/>
34-
</android.support.design.widget.CollapsingToolbarLayout>
35-
</android.support.design.widget.AppBarLayout>
34+
</com.google.android.material.appbar.CollapsingToolbarLayout>
35+
</com.google.android.material.appbar.AppBarLayout>
3636

37-
<android.support.v4.widget.NestedScrollView android:layout_width="match_parent"
37+
<androidx.core.widget.NestedScrollView android:layout_width="match_parent"
3838
android:layout_height="match_parent"
3939
xmlns:android="http://schemas.android.com/apk/res/android"
4040
app:layout_behavior="@string/appbar_scrolling_view_behavior">
@@ -53,7 +53,7 @@
5353

5454

5555
<com.alespero.expandablecardview.ExpandableCardView
56-
android:id="@+id/profile"
56+
android:id="@+id/main_profile_card"
5757
android:layout_marginLeft="20dp"
5858
android:layout_marginRight="20dp"
5959
android:layout_marginTop="10dp"
@@ -66,7 +66,7 @@
6666
app:expandOnClick="true" />
6767

6868
<com.alespero.expandablecardview.ExpandableCardView
69-
android:id="@+id/location"
69+
android:id="@+id/main_location"
7070
android:layout_marginLeft="20dp"
7171
android:layout_marginRight="20dp"
7272
android:layout_marginTop="10dp"
@@ -79,7 +79,7 @@
7979
app:expandOnClick="true"/>
8080

8181
<com.alespero.expandablecardview.ExpandableCardView
82-
android:id="@+id/dates"
82+
android:id="@+id/main_dates"
8383
android:layout_marginLeft="20dp"
8484
android:layout_marginRight="20dp"
8585
android:layout_marginTop="10dp"
@@ -94,5 +94,5 @@
9494

9595
</LinearLayout>
9696

97-
</android.support.v4.widget.NestedScrollView>
98-
</android.support.design.widget.CoordinatorLayout>
97+
</androidx.core.widget.NestedScrollView>
98+
</androidx.coordinatorlayout.widget.CoordinatorLayout>

app/src/main/res/layout/passengers.xml

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@
1212
android:orientation="vertical"
1313
android:layout_marginBottom="20dp">
1414

15-
<android.support.design.widget.TextInputLayout
15+
<com.google.android.material.textfield.TextInputLayout
1616
android:layout_width="match_parent"
1717
android:layout_height="wrap_content">
1818

19-
<android.support.design.widget.TextInputEditText
19+
<com.google.android.material.textfield.TextInputEditText
2020
android:layout_width="match_parent"
2121
android:layout_height="wrap_content"
2222
android:text="Alessandro Sperotti"
2323
android:hint="Name"/>
2424

25-
</android.support.design.widget.TextInputLayout>
25+
</com.google.android.material.textfield.TextInputLayout>
2626

27-
<android.support.design.widget.TextInputLayout
27+
<com.google.android.material.textfield.TextInputLayout
2828
android:layout_width="match_parent"
2929
android:layout_height="wrap_content">
3030

31-
<android.support.design.widget.TextInputEditText
31+
<com.google.android.material.textfield.TextInputEditText
3232
android:layout_width="match_parent"
3333
android:layout_height="wrap_content"
3434
android:text="Milano Malpensa (MXP)"
3535
android:hint="Departure Airport"/>
3636

37-
</android.support.design.widget.TextInputLayout>
37+
</com.google.android.material.textfield.TextInputLayout>
3838

3939
</LinearLayout>
4040

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.1.51'
4+
ext.kotlin_version = '1.3.11'
55
repositories {
66
google()
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.0.1'
10+
classpath 'com.android.tools.build:gradle:3.2.1'
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1212

1313
// NOTE: Do not place your application dependencies here; they belong

expandablecardview/build.gradle

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
apply plugin: 'com.android.library'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
24

35
ext {
46
PUBLISH_GROUP_ID = 'com.alespero'
@@ -7,15 +9,15 @@ ext {
79
}
810

911
android {
10-
compileSdkVersion 26
12+
compileSdkVersion 28
1113

1214
defaultConfig {
1315
minSdkVersion 18
14-
targetSdkVersion 26
16+
targetSdkVersion 28
1517
versionCode 3
1618
versionName "0.7"
1719

18-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
20+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1921

2022
}
2123

@@ -31,11 +33,16 @@ android {
3133
dependencies {
3234
implementation fileTree(dir: 'libs', include: ['*.jar'])
3335

34-
implementation 'com.android.support:appcompat-v7:26.1.0'
36+
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
37+
implementation "androidx.cardview:cardview:1.0.0"
38+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
3539
testImplementation 'junit:junit:4.12'
36-
androidTestImplementation 'com.android.support.test:runner:1.0.1'
37-
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
38-
implementation "com.android.support:cardview-v7:26.1.0"
40+
androidTestImplementation 'androidx.test:runner:1.1.1'
41+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
3942

4043
apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle'
44+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
45+
}
46+
repositories {
47+
mavenCentral()
4148
}

expandablecardview/src/androidTest/java/com/alespero/expandablecardview/ExampleInstrumentedTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.alespero.expandablecardview;
22

33
import android.content.Context;
4-
import android.support.test.InstrumentationRegistry;
5-
import android.support.test.runner.AndroidJUnit4;
4+
import androidx.test.InstrumentationRegistry;
5+
import androidx.test.runner.AndroidJUnit4;
66

77
import org.junit.Test;
88
import org.junit.runner.RunWith;

0 commit comments

Comments
 (0)