Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit 2f7fd72

Browse files
committed
Fixes GithubBrowser
1 parent 8b14dd6 commit 2f7fd72

File tree

13 files changed

+32
-31
lines changed

13 files changed

+32
-31
lines changed

GithubBrowserSample/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ android {
2929
compileSdkVersion build_versions.compile_sdk
3030
defaultConfig {
3131
applicationId "com.android.example.github"
32-
minSdkVersion build_versions.min_sdk
32+
minSdkVersion 21
3333
targetSdkVersion build_versions.target_sdk
3434
versionCode 1
3535
versionName "1.0"
@@ -60,6 +60,7 @@ android {
6060
}
6161
lintOptions {
6262
lintConfig rootProject.file('lint.xml')
63+
disable 'InvalidPackage'
6364
}
6465
}
6566

@@ -98,7 +99,6 @@ dependencies {
9899
testImplementation deps.arch_core.testing
99100
testImplementation deps.mockito.core
100101

101-
androidTestImplementation deps.atsl.core
102102
androidTestImplementation deps.atsl.ext_junit
103103
androidTestImplementation deps.atsl.runner
104104
androidTestImplementation deps.atsl.rules

GithubBrowserSample/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package="com.android.example.github">
2020

2121
<uses-permission android:name="android.permission.INTERNET" />
22+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
2223
<application
2324
android:name=".GithubApp"
2425
android:allowBackup="false"

GithubBrowserSample/app/src/main/java/com/android/example/github/repository/FetchNextSearchPageTask.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class FetchNextSearchPageTask constructor(
3636
private val githubService: GithubService,
3737
private val db: GithubDb
3838
) : Runnable {
39-
private val _liveData = MutableLiveData<Resource<Boolean>>()
40-
val liveData: LiveData<Resource<Boolean>> = _liveData
39+
private val _liveData = MutableLiveData<Resource<Boolean>?>()
40+
val liveData: MutableLiveData<Resource<Boolean>?> = _liveData
4141

4242
override fun run() {
4343
val current = db.repoDao().findSearchResult(query)

GithubBrowserSample/app/src/main/java/com/android/example/github/repository/RepoRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class RepoRepository @Inject constructor(
125125
}.asLiveData()
126126
}
127127

128-
fun searchNextPage(query: String): LiveData<Resource<Boolean>> {
128+
fun searchNextPage(query: String): LiveData<Resource<Boolean>?> {
129129
val fetchNextSearchPageTask = FetchNextSearchPageTask(
130130
query = query,
131131
githubService = githubService,

GithubBrowserSample/app/src/main/java/com/android/example/github/ui/repo/RepoFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ class RepoFragment : Fragment(), Injectable {
9090
}
9191
}
9292
binding = dataBinding
93-
sharedElementReturnTransition = TransitionInflater.from(context).inflateTransition(R.transition.move)
93+
sharedElementReturnTransition = TransitionInflater.from(requireContext())
94+
.inflateTransition(R.transition.move)
9495
return dataBinding.root
9596
}
9697

GithubBrowserSample/app/src/main/java/com/android/example/github/ui/search/SearchViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ class SearchViewModel @Inject constructor(repoRepository: RepoRepository) : View
8585
}
8686
}
8787

88-
class NextPageHandler(private val repository: RepoRepository) : Observer<Resource<Boolean>> {
89-
private var nextPageLiveData: LiveData<Resource<Boolean>>? = null
88+
class NextPageHandler(private val repository: RepoRepository) : Observer<Resource<Boolean>?> {
89+
private var nextPageLiveData: LiveData<Resource<Boolean>?>? = null
9090
val loadMoreState = MutableLiveData<LoadMoreState>()
9191
private var query: String? = null
9292
private var _hasMore: Boolean = false

GithubBrowserSample/app/src/main/java/com/android/example/github/ui/user/UserFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ class UserFragment : Fragment(), Injectable {
7777
}
7878
}
7979
binding = dataBinding
80-
sharedElementEnterTransition = TransitionInflater.from(context).inflateTransition(R.transition.move)
80+
sharedElementEnterTransition = TransitionInflater.from(requireContext())
81+
.inflateTransition(R.transition.move)
8182
// When the image is loaded, set the image request listener to start the transaction
8283
binding.imageRequestListener = object: RequestListener<Drawable> {
8384
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {

GithubBrowserSample/app/src/test/java/com/android/example/github/repository/FetchNextSearchPageTaskTest.kt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,19 @@ import com.android.example.github.util.mock
2727
import com.android.example.github.vo.RepoSearchResult
2828
import com.android.example.github.vo.Resource
2929
import okhttp3.Headers
30-
import okhttp3.MediaType
31-
import okhttp3.ResponseBody
30+
import okhttp3.Headers.Companion.headersOf
31+
import okhttp3.MediaType.Companion.toMediaTypeOrNull
32+
import okhttp3.ResponseBody.Companion.toResponseBody
3233
import org.junit.Before
3334
import org.junit.Rule
3435
import org.junit.Test
3536
import org.junit.runner.RunWith
3637
import org.junit.runners.JUnit4
3738
import org.mockito.ArgumentMatchers.any
38-
import org.mockito.Mockito.`when`
3939
import org.mockito.Mockito.mock
4040
import org.mockito.Mockito.verify
4141
import org.mockito.Mockito.verifyNoMoreInteractions
42+
import org.mockito.Mockito.`when`
4243
import retrofit2.Call
4344
import retrofit2.Response
4445
import java.io.IOException
@@ -58,7 +59,7 @@ class FetchNextSearchPageTaskTest {
5859

5960
private lateinit var task: FetchNextSearchPageTask
6061

61-
private val observer: Observer<Resource<Boolean>> = mock()
62+
private val observer: Observer<Resource<Boolean>?> = mock()
6263

6364
@Before
6465
fun init() {
@@ -120,9 +121,8 @@ class FetchNextSearchPageTaskTest {
120121
val call = mock<Call<RepoSearchResponse>>()
121122
`when`(call.execute()).thenReturn(
122123
Response.error(
123-
400, ResponseBody.create(
124-
MediaType.parse("txt"), "bar"
125-
)
124+
400, "bar"
125+
.toResponseBody("txt".toMediaTypeOrNull())
126126
)
127127
)
128128
`when`(service.searchRepos("foo", 1)).thenReturn(call)
@@ -152,12 +152,11 @@ class FetchNextSearchPageTaskTest {
152152
val headers = if (nextPage == null)
153153
null
154154
else
155-
Headers
156-
.of(
157-
"link",
158-
"<https://api.github.com/search/repositories?q=foo&page=" + nextPage
159-
+ ">; rel=\"next\""
160-
)
155+
headersOf(
156+
"link",
157+
"<https://api.github.com/search/repositories?q=foo&page=" + nextPage
158+
+ ">; rel=\"next\""
159+
)
161160
val success = if (headers == null)
162161
Response.success(body)
163162
else
@@ -167,4 +166,4 @@ class FetchNextSearchPageTaskTest {
167166

168167
return call
169168
}
170-
}
169+
}

GithubBrowserSample/app/src/test/java/com/android/example/github/repository/RepoRepositoryTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class RepoRepositoryTest {
145145
@Test
146146
fun searchNextPage_null() {
147147
`when`(dao.findSearchResult("foo")).thenReturn(null)
148-
val observer = mock<Observer<Resource<Boolean>>>()
148+
val observer = mock<Observer<Resource<Boolean>?>>()
149149
repository.searchNextPage("foo").observeForever(observer)
150150
verify(observer).onChanged(null)
151151
}
@@ -230,4 +230,4 @@ class RepoRepositoryTest {
230230
apiResponse.postValue(ApiResponse.create(Exception("idk")))
231231
verify(observer).onChanged(Resource.error("idk", null))
232232
}
233-
}
233+
}

GithubBrowserSample/app/src/test/java/com/android/example/github/ui/search/NextPageHandlerTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ class NextPageHandlerTest {
147147
assertThat(liveData.hasActiveObservers(), `is`(false))
148148
}
149149

150-
private fun enqueueResponse(query: String): MutableLiveData<Resource<Boolean>> {
151-
val liveData = MutableLiveData<Resource<Boolean>>()
150+
private fun enqueueResponse(query: String): MutableLiveData<Resource<Boolean>?> {
151+
val liveData = MutableLiveData<Resource<Boolean>?>()
152152
`when`(repository.searchNextPage(query)).thenReturn(liveData)
153153
return liveData
154154
}
155-
}
155+
}

0 commit comments

Comments
 (0)