Skip to content

Commit 0a71db4

Browse files
committed
Merge branch 'androidx'
2 parents c2c92e2 + a36d5f2 commit 0a71db4

18 files changed

Lines changed: 165 additions & 98 deletions

‎app/build.gradle‎

Lines changed: 69 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,33 @@ apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-kapt'
44

5+
def packageName = "ysuzuki.githubclient"
6+
7+
def localProperties() {
8+
Properties properties = new Properties()
9+
properties.load(project.rootProject.file('local.properties').newDataInputStream())
10+
return properties
11+
}
12+
13+
def localHost = localProperties().getProperty("local_host")
14+
15+
def lifecycle_version = "2.0.0"
16+
517
android {
6-
compileSdkVersion 25
7-
buildToolsVersion "25.0.2"
18+
19+
compileSdkVersion 28
20+
buildToolsVersion '28.0.3'
21+
flavorDimensions "default"
22+
823
defaultConfig {
9-
applicationId "ysuzuki.githubclient"
24+
applicationId packageName
1025
minSdkVersion 19
11-
targetSdkVersion 25
26+
targetSdkVersion 28
1227
versionCode 1
1328
versionName "1.0"
14-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
29+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1530
}
31+
1632
buildTypes {
1733
release {
1834
minifyEnabled true
@@ -25,53 +41,76 @@ android {
2541
buildConfigField "String", "HOST", "\"https://api.github.com/\""
2642
}
2743
}
44+
45+
productFlavors {
46+
product {
47+
dimension "default"
48+
applicationId packageName
49+
buildConfigField "String", "HOST", "\"${product_host}\""
50+
}
51+
develop {
52+
dimension "default"
53+
applicationId packageName + ".dev"
54+
buildConfigField "String", "HOST", "\"" + localHost + "\""
55+
}
56+
}
57+
2858
dataBinding {
2959
enabled = true
3060
}
61+
62+
kapt {
63+
mapDiagnosticLocations = true
64+
}
3165
}
3266

3367
dependencies {
34-
compile fileTree(dir: 'libs', include: ['*.jar'])
35-
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
68+
implementation fileTree(dir: 'libs', include: ['*.jar'])
69+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
3670

3771
// Android support libraries.
38-
compile "com.android.support:appcompat-v7:${android_support_lib_version}"
39-
compile "com.android.support:design:${android_support_lib_version}"
40-
compile "com.android.support:customtabs:${android_support_lib_version}"
41-
compile 'com.android.support.constraint:constraint-layout:1.0.1'
72+
implementation 'androidx.core:core-ktx:1.0.1'
73+
implementation 'androidx.appcompat:appcompat:1.0.2'
74+
implementation 'androidx.browser:browser:1.0.0'
75+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
76+
// ViewModel and LiveData
77+
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
78+
79+
implementation 'com.google.android.material:material:1.0.0'
4280

4381
// Data binding
44-
kapt 'com.android.databinding:compiler:2.3.0'
82+
kapt 'androidx.databinding:databinding-compiler:3.4.0'
4583

4684
// RxJava
47-
compile 'io.reactivex.rxjava2:rxjava:2.0.7'
48-
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
85+
implementation 'io.reactivex.rxjava2:rxjava:2.1.5'
86+
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
4987

5088
// Square
51-
compile 'com.squareup.picasso:picasso:2.5.2'
52-
compile 'com.squareup.moshi:moshi:1.4.0'
89+
implementation 'com.squareup.picasso:picasso:2.5.2'
90+
implementation 'com.squareup.moshi:moshi:1.4.0'
5391

5492
// Retrofit2
55-
compile 'com.squareup.retrofit2:retrofit:2.2.0'
56-
compile "com.squareup.retrofit2:converter-moshi:2.2.0"
57-
compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
93+
implementation 'com.squareup.retrofit2:retrofit:2.2.0'
94+
implementation "com.squareup.retrofit2:converter-moshi:2.2.0"
95+
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
5896

5997
// Dagger2
60-
compile "com.google.dagger:dagger:2.9"
98+
implementation "com.google.dagger:dagger:2.9"
6199
kapt "com.google.dagger:dagger-compiler:2.9"
62-
provided 'javax.annotation:jsr250-api:1.0'
100+
compileOnly 'javax.annotation:jsr250-api:1.0'
63101

64102
// Test libraries
65-
testCompile 'junit:junit:4.12'
66-
testCompile 'org.mockito:mockito-core:1.10.19'
67-
testCompile "org.robolectric:robolectric:3.3.2"
68-
69-
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
70-
androidTestCompile "com.android.support:support-annotations:${android_support_lib_version}"
71-
androidTestCompile 'com.android.support.test:runner:0.5'
72-
androidTestCompile 'com.android.support.test:rules:0.5'
73-
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
103+
testImplementation 'junit:junit:4.12'
104+
testImplementation 'org.mockito:mockito-core:2.23.4'
105+
testImplementation "org.robolectric:robolectric:3.3.2"
106+
107+
androidTestImplementation 'org.hamcrest:hamcrest-library:1.3'
108+
androidTestImplementation 'androidx.annotation:annotation:1.0.2'
109+
androidTestImplementation 'androidx.test:runner:1.1.1'
110+
androidTestImplementation 'androidx.test:rules:1.1.1'
111+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
74112
}
75113
repositories {
76114
mavenCentral()
115+
google()
77116
}

‎app/src/androidTest/java/ysuzuki/githubclient/ExampleInstrumentedTest.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package ysuzuki.githubclient
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

‎app/src/main/java/ysuzuki/githubclient/di/AppComponent.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import javax.inject.Singleton
88
* Created by Yasuhiro Suzuki on 2017/09/17.
99
*/
1010
@Singleton
11-
@Component(modules = arrayOf(AppModule::class))
11+
@Component(modules = [AppModule::class])
1212
interface AppComponent {
1313

1414
fun inject(fragment: SearchFragment)

‎app/src/main/java/ysuzuki/githubclient/di/AppModule.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AppModule(val context: Application) {
2828

2929
@Provides
3030
@Singleton
31-
fun provideSharedPrefences(context: Context): SharedPreferences {
31+
fun provideSharedPreferences(context: Context): SharedPreferences {
3232
return context.getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE)
3333
}
3434

‎app/src/main/java/ysuzuki/githubclient/extention/ActivityExtention.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package ysuzuki.githubclient.extention
22

3-
import android.support.v4.app.Fragment
4-
import android.support.v7.app.AppCompatActivity
3+
import androidx.fragment.app.Fragment
4+
import androidx.appcompat.app.AppCompatActivity
55
import ysuzuki.githubclient.R
66

77
/**

‎app/src/main/java/ysuzuki/githubclient/util/DataBindingHelper.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ysuzuki.githubclient.util
22

3-
import android.databinding.BindingAdapter
3+
import androidx.databinding.BindingAdapter
44
import android.graphics.drawable.Drawable
55
import android.widget.ImageView
66
import com.squareup.picasso.Picasso

‎app/src/main/java/ysuzuki/githubclient/util/OnScrollListener.kt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package ysuzuki.githubclient.util
22

3-
import android.support.v7.widget.LinearLayoutManager
4-
import android.support.v7.widget.RecyclerView
3+
import androidx.recyclerview.widget.LinearLayoutManager
4+
import androidx.recyclerview.widget.RecyclerView
55

66
/**
77
* Set this listener to RecyclerView#addOnScrollListener
@@ -23,7 +23,7 @@ class OnScrollListener(val mLayoutManager: LinearLayoutManager,
2323
var mLoading = true
2424
private set
2525

26-
override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
26+
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
2727
super.onScrolled(recyclerView, dx, dy)
2828
onScrolled()
2929
val visibleItemCount = mLayoutManager.childCount

‎app/src/main/java/ysuzuki/githubclient/view/MainActivity.kt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package ysuzuki.githubclient.view
22

3-
import android.databinding.DataBindingUtil
3+
import androidx.databinding.DataBindingUtil
44
import android.os.Bundle
5-
import android.support.v7.app.AppCompatActivity
5+
import androidx.appcompat.app.AppCompatActivity
66
import ysuzuki.githubclient.R
77
import ysuzuki.githubclient.databinding.ActivityMainBinding
88
import ysuzuki.githubclient.extention.addFragment
@@ -11,7 +11,7 @@ import ysuzuki.githubclient.view.search.SearchFragment
1111

1212
class MainActivity : AppCompatActivity() {
1313

14-
lateinit var binding: ActivityMainBinding
14+
private lateinit var binding: ActivityMainBinding
1515

1616
override fun onCreate(savedInstanceState: Bundle?) {
1717
super.onCreate(savedInstanceState)
@@ -20,7 +20,7 @@ class MainActivity : AppCompatActivity() {
2020
addFragment(SearchFragment.TAG, SearchFragment.newInstance())
2121
}
2222

23-
fun initToolbar() {
23+
private fun initToolbar() {
2424
setSupportActionBar(binding.toolbar)
2525
supportActionBar?.setDisplayHomeAsUpEnabled(true)
2626
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_home_black_24dp)

‎app/src/main/java/ysuzuki/githubclient/view/search/SearchFragment.kt‎

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package ysuzuki.githubclient.view.search
22

33
import android.os.Bundle
4-
import android.support.v4.app.Fragment
5-
import android.support.v7.widget.LinearLayoutManager
6-
import android.support.v7.widget.SearchView
4+
import androidx.fragment.app.Fragment
5+
import androidx.recyclerview.widget.LinearLayoutManager
6+
import androidx.appcompat.widget.SearchView
77
import android.view.*
8+
import androidx.lifecycle.ViewModelProviders
89
import ysuzuki.githubclient.MyApplication
910
import ysuzuki.githubclient.R
1011
import ysuzuki.githubclient.databinding.FragmentSearchBinding
@@ -18,46 +19,49 @@ import javax.inject.Inject
1819
class SearchFragment : Fragment() {
1920

2021
@Inject
21-
lateinit var viewModel: SearchViewModel
22+
lateinit var viewModelProvider: SearchViewModelFactory
2223

23-
lateinit var binding: FragmentSearchBinding
24+
val viewModel: SearchViewModel by lazy {
25+
ViewModelProviders.of(this, viewModelProvider).get(SearchViewModel::class.java)
26+
}
27+
28+
private lateinit var binding: FragmentSearchBinding
2429

25-
lateinit var searchView: SearchView
30+
private lateinit var searchView: SearchView
2631

27-
val layoutManager: LinearLayoutManager by lazy { LinearLayoutManager(context) }
32+
private val layoutManager: LinearLayoutManager by lazy {
33+
LinearLayoutManager(context)
34+
}
2835

29-
val scrollListener: OnScrollListener by lazy {
36+
private val scrollListener: OnScrollListener by lazy {
3037
OnScrollListener(layoutManager, { viewModel.fetch() })
3138
}
3239

33-
val adapter: SearchViewAdapter by lazy { SearchViewAdapter(viewModel) }
40+
private val adapter: SearchViewAdapter by lazy {
41+
SearchViewAdapter(viewModel)
42+
}
3443

3544
companion object {
3645
val TAG: String = SearchFragment::class.java.simpleName
3746
fun newInstance() = SearchFragment()
3847
}
3948

40-
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
41-
(context.applicationContext as MyApplication).appComponent.inject(this)
49+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
50+
(context?.applicationContext as MyApplication).appComponent.inject(this)
4251
binding = FragmentSearchBinding.inflate(inflater, container, false)
4352
setHasOptionsMenu(true)
4453
initViewModel()
4554
initRecyclerView()
4655
return binding.root
4756
}
4857

49-
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
58+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
5059
super.onViewCreated(view, savedInstanceState)
5160
viewModel.fetch()
5261
}
5362

54-
override fun onDetach() {
55-
viewModel.destroy()
56-
super.onDetach()
57-
}
58-
5963
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
60-
activity.menuInflater.inflate(R.menu.main, menu)
64+
requireActivity().menuInflater.inflate(R.menu.main, menu)
6165
searchView = (menu?.findItem(R.id.search)?.actionView as SearchView).apply {
6266
setOnQueryTextListener(viewModel.queryTextListener)
6367
setIconifiedByDefault(true)
@@ -71,21 +75,21 @@ class SearchFragment : Fragment() {
7175
else -> true
7276
}
7377

74-
fun refreshItems(): Boolean {
78+
private fun refreshItems(): Boolean {
7579
viewModel.refreshItems()
76-
activity.title = viewModel.qualifiers
80+
activity?.title = viewModel.qualifiers
7781
return true
7882
}
7983

80-
fun initViewModel() {
84+
private fun initViewModel() {
8185
binding.viewModel = viewModel
8286
viewModel.onQueryTextSubmit = { query ->
83-
activity.title = query
87+
activity?.title = query
8488
}
8589
}
8690

87-
fun initRecyclerView() {
88-
activity.title = viewModel.qualifiers
91+
private fun initRecyclerView() {
92+
activity?.title = viewModel.qualifiers
8993
binding.recyclerView.adapter = adapter
9094
binding.recyclerView.layoutManager = layoutManager
9195
binding.recyclerView.addOnScrollListener(scrollListener)

‎app/src/main/java/ysuzuki/githubclient/view/search/SearchItemViewModel.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package ysuzuki.githubclient.view.search
22

3-
import android.databinding.ObservableField
3+
import androidx.databinding.ObservableField
44
import android.net.Uri
55
import ysuzuki.githubclient.model.Repository
6-
import android.support.customtabs.CustomTabsIntent
6+
import androidx.browser.customtabs.CustomTabsIntent
77
import android.view.View
88

99

0 commit comments

Comments
 (0)