Skip to content

Commit ee3d2c7

Browse files
committed
Updated some dependencies.
Some refactoring to be able to use the application with the API changes
1 parent edece59 commit ee3d2c7

File tree

10 files changed

+75
-70
lines changed

10 files changed

+75
-70
lines changed

app/build.gradle

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
4+
apply plugin: 'kotlin-kapt'
45

56
android {
6-
compileSdkVersion 26
7-
buildToolsVersion "26.0.1"
7+
compileSdkVersion 27
8+
buildToolsVersion "27.0.3"
89
defaultConfig {
910
applicationId "com.example.tamaskozmer.kotlinrxexample"
1011
minSdkVersion 16
11-
targetSdkVersion 26
12+
targetSdkVersion 27
1213
versionCode 1
1314
versionName "1.0"
1415
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -29,37 +30,37 @@ dependencies {
2930
implementation fileTree(dir: 'libs', include: ['*.jar'])
3031
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
3132

32-
implementation 'com.google.dagger:dagger:2.11'
33-
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
34-
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
35-
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
36-
implementation 'io.reactivex.rxjava2:rxjava:2.1.1'
37-
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
38-
implementation 'com.github.bumptech.glide:glide:4.0.0-RC1'
39-
implementation "android.arch.persistence.room:runtime:1.0.0-alpha8"
40-
implementation "android.arch.persistence.room:rxjava2:1.0.0-alpha8"
41-
implementation 'com.facebook.stetho:stetho:1.5.0'
42-
implementation 'com.android.support:appcompat-v7:26.0.1'
43-
implementation 'com.android.support:recyclerview-v7:26.0.1'
33+
implementation "com.google.dagger:dagger:$DAGGER_VERSION"
34+
implementation "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION"
35+
implementation "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION"
36+
implementation "com.squareup.retrofit2:adapter-rxjava2:$RETROFIT_VERSION"
37+
implementation "io.reactivex.rxjava2:rxjava:$RXJAVA_VERSION"
38+
implementation "io.reactivex.rxjava2:rxandroid:$RXANDROID_VERSION"
39+
implementation "com.github.bumptech.glide:glide:$GLIDE_VERSION"
40+
implementation "android.arch.persistence.room:runtime:$ROOM_VERSION"
41+
implementation "android.arch.persistence.room:rxjava2:$ROOM_VERSION"
42+
implementation "com.facebook.stetho:stetho:$STETHO_VERSION"
43+
implementation "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
44+
implementation "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION"
4445

45-
kapt "android.arch.persistence.room:compiler:1.0.0-alpha8"
46-
kapt 'com.google.dagger:dagger-compiler:2.11'
46+
kapt "android.arch.persistence.room:compiler:$ROOM_VERSION"
47+
kapt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
4748

48-
testImplementation 'org.mockito:mockito-core:2.8.47'
49-
testImplementation 'junit:junit:4.12'
49+
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:$MOCKITO_KOTLIN_VERSION"
50+
testImplementation "junit:junit:$JUNIT_VERSION"
5051

51-
androidTestImplementation ('com.android.support.test.espresso:espresso-core:2.2.2', {
52+
androidTestImplementation ("com.android.support.test.espresso:espresso-core:$ESPRESSO_VERSION", {
5253
exclude group: 'com.android.support', module: 'support-annotations'
5354
})
5455

55-
androidTestImplementation('com.android.support.test.espresso:espresso-contrib:2.2') {
56+
androidTestImplementation("com.android.support.test.espresso:espresso-contrib:$ESPRESSO_VERSION") {
5657
// Necessary to avoid version conflicts
5758
exclude group: 'com.android.support', module: 'appcompat'
5859
exclude group: 'com.android.support', module: 'support-v4'
5960
exclude group: 'com.android.support', module: 'support-annotations'
6061
exclude module: 'recyclerview-v7'
6162
}
6263

63-
androidTestImplementation "com.nhaarman:mockito-kotlin-kt1.1:1.5.0"
64-
androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito:2.2.0'
64+
androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:$MOCKITO_KOTLIN_VERSION"
65+
androidTestImplementation "com.linkedin.dexmaker:dexmaker-mockito:$DEXMAKER_VERSION"
6566
}

app/src/main/java/com/example/tamaskozmer/kotlinrxexample/model/persistence/daos/AnswerDao.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import com.example.tamaskozmer.kotlinrxexample.model.entities.Answer
1212
@Dao
1313
interface AnswerDao {
1414

15-
@Query("SELECT * FROM answer WHERE userId = :arg0 ORDER BY score DESC LIMIT 3")
15+
@Query("SELECT * FROM answer WHERE userId = :userId ORDER BY score DESC LIMIT 3")
1616
fun getAnswersByUser(userId: Long) : List<Answer>
1717

1818
@Insert(onConflict = OnConflictStrategy.REPLACE)

app/src/main/java/com/example/tamaskozmer/kotlinrxexample/model/persistence/daos/FavoritedByUserDao.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import com.example.tamaskozmer.kotlinrxexample.model.entities.FavoritedByUser
1212
@Dao
1313
interface FavoritedByUserDao {
1414

15-
@Query("SELECT * FROM favoritedByUser WHERE userId = :arg0")
15+
@Query("SELECT * FROM favoritedByUser WHERE userId = :userId")
1616
fun getFavoritesForUser(userId: Long) : FavoritedByUser?
1717

1818
@Insert(onConflict = OnConflictStrategy.REPLACE)

app/src/main/java/com/example/tamaskozmer/kotlinrxexample/model/persistence/daos/QuestionDao.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ import com.example.tamaskozmer.kotlinrxexample.model.entities.Question
1111
*/
1212
@Dao
1313
interface QuestionDao {
14-
// TODO Change these when the bug is fixed
15-
// This is a bug in Kotlin, we need to use arg0 here, instead of the actual name of the parameter
16-
@Query("SELECT * FROM question WHERE userId = :arg0 ORDER BY score DESC LIMIT 3")
14+
15+
@Query("SELECT * FROM question WHERE userId = :userId ORDER BY score DESC LIMIT 3")
1716
fun getQuestionsByUser(userId: Long) : List<Question>
1817

19-
@Query("SELECT * FROM question WHERE questionId IN (:arg0) ORDER BY score DESC")
18+
@Query("SELECT * FROM question WHERE questionId IN (:questionIds) ORDER BY score DESC")
2019
fun getQuestionsById(questionIds: List<Long>) : List<Question>
2120

2221
@Insert(onConflict = OnConflictStrategy.REPLACE)

app/src/main/java/com/example/tamaskozmer/kotlinrxexample/model/persistence/daos/UserDao.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import com.example.tamaskozmer.kotlinrxexample.model.entities.User
1212
@Dao
1313
interface UserDao {
1414
// TODO Find a more optimal solution
15-
@Query("SELECT * FROM user ORDER BY reputation DESC LIMIT (:arg0 - 1) * 30, 30")
15+
@Query("SELECT * FROM user ORDER BY reputation DESC LIMIT (:page - 1) * 30, 30")
1616
fun getUsers(page: Int) : List<User>
1717

1818
@Insert(onConflict = OnConflictStrategy.REPLACE)

app/src/main/java/com/example/tamaskozmer/kotlinrxexample/presentation/view/activities/MainActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import android.view.View
1212
import com.example.tamaskozmer.kotlinrxexample.R
1313
import com.example.tamaskozmer.kotlinrxexample.util.TransitionListener
1414
import com.example.tamaskozmer.kotlinrxexample.util.isLollipopOrAbove
15-
import com.example.tamaskozmer.kotlinrxexample.view.fragments.DetailsFragment
16-
import com.example.tamaskozmer.kotlinrxexample.view.fragments.UserListFragment
15+
import com.example.tamaskozmer.kotlinrxexample.presentation.view.fragments.DetailsFragment
16+
import com.example.tamaskozmer.kotlinrxexample.presentation.view.fragments.UserListFragment
1717

1818
class MainActivity : AppCompatActivity() {
1919

app/src/main/java/com/example/tamaskozmer/kotlinrxexample/presentation/view/fragments/DetailsFragment.kt

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.tamaskozmer.kotlinrxexample.view.fragments
1+
package com.example.tamaskozmer.kotlinrxexample.presentation.view.fragments
22

33
import android.content.Intent
44
import android.net.Uri
@@ -18,18 +18,16 @@ import com.example.tamaskozmer.kotlinrxexample.util.customApplication
1818
import com.example.tamaskozmer.kotlinrxexample.view.adapters.DetailsAdapter
1919
import kotlinx.android.synthetic.main.fragment_details.*
2020

21-
22-
/**
23-
* Created by Tamas_Kozmer on 7/6/2017.
24-
*/
2521
class DetailsFragment : Fragment(), DetailView {
2622

2723
private val component by lazy { customApplication.component.plus(DetailFragmentModule()) }
2824
private val presenter by lazy { component.presenter() }
29-
private val detailsAdapter by lazy { DetailsAdapter({ link ->
30-
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(link))
31-
startActivity(browserIntent)
32-
}) }
25+
private val detailsAdapter by lazy {
26+
DetailsAdapter({ link ->
27+
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(link))
28+
startActivity(browserIntent)
29+
})
30+
}
3331

3432
var transitionEnded = false
3533

@@ -43,15 +41,11 @@ class DetailsFragment : Fragment(), DetailView {
4341
}
4442
}
4543

46-
override fun onCreate(savedInstanceState: Bundle?) {
47-
super.onCreate(savedInstanceState)
48-
}
49-
50-
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
51-
return inflater?.inflate(R.layout.fragment_details, container, false)
44+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
45+
return inflater.inflate(R.layout.fragment_details, container, false)
5246
}
5347

54-
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
48+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
5549
super.onViewCreated(view, savedInstanceState)
5650

5751
presenter.attachView(this)
@@ -71,13 +65,16 @@ class DetailsFragment : Fragment(), DetailView {
7165
}
7266

7367
private fun processArguments() {
74-
val user = arguments.getParcelable<UserViewModel>("user")
75-
detailsAdapter.addItem(user)
76-
detailsAdapter.notifyDataSetChanged()
77-
presenter.getDetails(user.userId)
68+
val user = arguments?.getParcelable<UserViewModel>("user")
69+
70+
if (user != null) {
71+
detailsAdapter.addItem(user)
72+
detailsAdapter.notifyDataSetChanged()
73+
presenter.getDetails(user.userId)
7874

79-
swipeRefreshLayout.setOnRefreshListener {
80-
presenter.getDetails(user.userId, true)
75+
swipeRefreshLayout.setOnRefreshListener {
76+
presenter.getDetails(user.userId, true)
77+
}
8178
}
8279
}
8380

app/src/main/java/com/example/tamaskozmer/kotlinrxexample/presentation/view/fragments/UserListFragment.kt

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.tamaskozmer.kotlinrxexample.view.fragments
1+
package com.example.tamaskozmer.kotlinrxexample.presentation.view.fragments
22

33
import android.os.Bundle
44
import android.support.v4.app.Fragment
@@ -18,31 +18,24 @@ import com.example.tamaskozmer.kotlinrxexample.view.activities.MainActivity
1818
import com.example.tamaskozmer.kotlinrxexample.view.adapters.UserListAdapter
1919
import kotlinx.android.synthetic.main.fragment_user_list.*
2020

21-
/**
22-
* Created by Tamas_Kozmer on 7/6/2017.
23-
*/
2421
class UserListFragment : Fragment(), UserListView {
2522

2623
private val presenter: UserListPresenter by lazy { component.presenter() }
2724
private val component by lazy { customApplication.component.plus(UserListFragmentModule()) }
2825
private val adapter by lazy {
2926
val userList = mutableListOf<UserViewModel>()
30-
UserListAdapter(userList) {
31-
user, view -> openDetailFragment(user, view)
27+
UserListAdapter(userList) { user, view ->
28+
openDetailFragment(user, view)
3229
}
3330
}
3431

3532
private lateinit var layoutManager: LinearLayoutManager
3633

37-
override fun onCreate(savedInstanceState: Bundle?) {
38-
super.onCreate(savedInstanceState)
34+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
35+
return inflater.inflate(R.layout.fragment_user_list, container, false)
3936
}
4037

41-
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
42-
return inflater?.inflate(R.layout.fragment_user_list, container, false)
43-
}
44-
45-
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
38+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
4639
super.onViewCreated(view, savedInstanceState)
4740

4841
initViews()

app/src/main/java/com/example/tamaskozmer/kotlinrxexample/util/Extensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ val Activity.customApplication: CustomApplication
3131
get() = application as CustomApplication
3232

3333
val Fragment.customApplication: CustomApplication
34-
get() = activity.application as CustomApplication
34+
get() = activity?.application as CustomApplication

build.gradle

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
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.3-2'
4+
ext.kotlin_version = '1.2.30'
55
repositories {
66
google()
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.1.0'
10+
classpath 'com.android.tools.build:gradle:3.1.4'
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1212

1313
// NOTE: Do not place your application dependencies here; they belong
1414
// in the individual module build.gradle files
1515
}
1616
}
1717

18+
ext {
19+
SUPPORT_LIBRARY_VERSION = '27.1.1'
20+
ROOM_VERSION = '1.1.1'
21+
RETROFIT_VERSION = '2.4.0'
22+
DAGGER_VERSION = '2.17'
23+
RXJAVA_VERSION = '2.1.13'
24+
RXANDROID_VERSION = '2.0.2'
25+
GLIDE_VERSION = '4.7.1'
26+
STETHO_VERSION = '1.5.0'
27+
MOCKITO_KOTLIN_VERSION = '2.0.0-RC1'
28+
ESPRESSO_VERSION = '2.2.2'
29+
JUNIT_VERSION = '4.12'
30+
DEXMAKER_VERSION = '2.2.0'
31+
}
32+
1833
allprojects {
1934
repositories {
2035
google()

0 commit comments

Comments
 (0)