Skip to content

Commit 7242bd8

Browse files
authored
Update Kotlin and Gradle (#438)
1 parent 558ab6f commit 7242bd8

File tree

20 files changed

+281
-270
lines changed

20 files changed

+281
-270
lines changed

test-app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
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.4.31'
4+
ext.kotlin_version = '1.5.20'
55

66
repositories {
77
google()
88
jcenter()
99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:4.1.2'
11+
classpath 'com.android.tools.build:gradle:4.2.2'
1212

1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1414

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Oct 29 14:00:53 CET 2020
1+
#Fri Jun 25 13:42:26 CEST 2021
22
distributionBase=GRADLE_USER_HOME
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
34
distributionPath=wrapper/dists
4-
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
6+
zipStoreBase=GRADLE_USER_HOME

test-app/r2-testapp/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ dependencies {
118118
implementation "androidx.browser:browser:1.3.0"
119119
implementation "androidx.cardview:cardview:1.0.0"
120120
implementation "androidx.constraintlayout:constraintlayout:2.0.4"
121-
implementation "androidx.fragment:fragment-ktx:1.3.4"
121+
implementation "androidx.fragment:fragment-ktx:1.3.5"
122122
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.1"
123123
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
124124
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
@@ -142,7 +142,7 @@ dependencies {
142142
//noinspection GradleDependency
143143
implementation "com.squareup.picasso:picasso:2.5.2"
144144
implementation "joda-time:joda-time:2.10.10"
145-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3"
145+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0-native-mt"
146146
// AM NOTE: needs to stay this version for now (June 24,2020)
147147
//noinspection GradleDependency
148148
implementation 'org.jsoup:jsoup:1.13.1'

test-app/r2-testapp/src/main/java/org/readium/r2/testapp/audiobook/AudioNavigatorFragment.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* available in the top-level LICENSE file of the project.
55
*/
66

7+
@file:Suppress("DEPRECATION")
8+
79
package org.readium.r2.testapp.audiobook
810

911
import android.app.ProgressDialog
@@ -67,6 +69,7 @@ class AudioNavigatorFragment(
6769
}
6870
}
6971

72+
// TODO Replace or add a ProgressBar in the navigator to use here, then remove the deprecation annotation for this file
7073
activity.mediaPlayer.progress = ProgressDialog.show(requireContext(), null, getString(R.string.progress_wait_while_preparing_audiobook), true)
7174
initialLocator?.let { go(it) }
7275
}

test-app/r2-testapp/src/main/java/org/readium/r2/testapp/bookshelf/BookshelfViewModel.kt

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import org.readium.r2.shared.extensions.mediaType
2424
import org.readium.r2.shared.extensions.tryOrNull
2525
import org.readium.r2.shared.publication.Publication
2626
import org.readium.r2.shared.publication.asset.FileAsset
27-
import org.readium.r2.shared.publication.asset.PublicationAsset
28-
import org.readium.r2.shared.publication.opds.images
2927
import org.readium.r2.shared.publication.services.cover
3028
import org.readium.r2.shared.publication.services.isRestricted
3129
import org.readium.r2.shared.publication.services.protectionError
@@ -220,13 +218,13 @@ class BookshelfViewModel(application: Application) : AndroidViewModel(applicatio
220218
channel.send(Event.OpenBookError(error.getUserMessage(r2Application)))
221219
}
222220
} else {
223-
val url = prepareToServe(it, asset)
221+
val url = prepareToServe(it)
224222
callback.invoke(asset, asset.mediaType(), it, remoteAsset, url)
225223
}
226224
}
227225
}
228226

229-
private fun prepareToServe(publication: Publication, asset: PublicationAsset): URL? {
227+
private fun prepareToServe(publication: Publication): URL? {
230228
val userProperties =
231229
r2Application.filesDir.path + "/" + Injectable.Style.rawValue + "/UserProperties.json"
232230
return server.addPublication(publication, userPropertiesFile = File(userProperties))
@@ -241,18 +239,7 @@ class BookshelfViewModel(application: Application) : AndroidViewModel(applicatio
241239
}
242240
val coverImageFile = File("${r2Directory}covers/${imageName}.png")
243241

244-
var bitmap: Bitmap? = null
245-
if (publication.cover() == null) {
246-
publication.coverLink?.let { link ->
247-
bitmap = getBitmapFromURL(link.href)
248-
} ?: run {
249-
if (publication.images.isNotEmpty()) {
250-
bitmap = getBitmapFromURL(publication.images.first().href)
251-
}
252-
}
253-
} else {
254-
bitmap = publication.cover()
255-
}
242+
val bitmap: Bitmap? = publication.cover()
256243

257244
val resized = bitmap?.let { Bitmap.createScaledBitmap(it, 120, 200, true) }
258245
val fos = FileOutputStream(coverImageFile)

test-app/r2-testapp/src/main/java/org/readium/r2/testapp/catalogs/CatalogDetailFragment.kt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,8 @@ class CatalogDetailFragment : Fragment() {
5050
super.onViewCreated(view, savedInstanceState)
5151
(activity as MainActivity).supportActionBar?.title = publication?.metadata?.title
5252

53-
publication?.coverLink?.let { link ->
54-
Picasso.with(requireContext()).load(link.href).into(binding.catalogListCoverImage)
55-
} ?: run {
56-
if (publication?.images?.isNotEmpty() == true) {
57-
Picasso.with(requireContext()).load(publication!!.images.first().href)
58-
.into(binding.catalogListCoverImage)
59-
}
60-
}
61-
// viewLifecycleOwner.lifecycleScope.launchWhenCreated {
62-
// binding.coverImageView.setImageBitmap(mPublication?.cover())
63-
// }
53+
Picasso.with(requireContext()).load(publication?.images?.first()?.href)
54+
.into(binding.catalogDetailCoverImage)
6455

6556
binding.catalogDetailDownloadButton.setOnClickListener {
6657
publication?.let { it1 ->

test-app/r2-testapp/src/main/java/org/readium/r2/testapp/catalogs/CatalogViewModel.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,8 @@ class CatalogViewModel(application: Application) : AndroidViewModel(application)
123123
}
124124
val coverImageFile = File("${r2Directory}covers/${imageName}.png")
125125

126-
var bitmap: Bitmap? = null
127-
if (publication.cover() == null) {
128-
publication.coverLink?.let { link ->
129-
bitmap = getBitmapFromURL(link.href)
130-
} ?: run {
131-
if (publication.images.isNotEmpty()) {
132-
bitmap = getBitmapFromURL(publication.images.first().href)
133-
}
134-
}
135-
} else {
136-
bitmap = publication.cover()
137-
}
126+
val bitmap: Bitmap? =
127+
publication.cover() ?: getBitmapFromURL(publication.images.first().href)
138128

139129
val resized = bitmap?.let { Bitmap.createScaledBitmap(it, 120, 200, true) }
140130
val fos = FileOutputStream(coverImageFile)

test-app/r2-testapp/src/main/java/org/readium/r2/testapp/epub/EpubActivity.kt

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ package org.readium.r2.testapp.epub
1212

1313
import android.content.Context
1414
import android.graphics.Color
15-
import android.graphics.Point
1615
import android.graphics.Rect
1716
import android.os.Bundle
1817
import android.os.Handler
19-
import android.util.DisplayMetrics
2018
import android.view.*
2119
import android.view.accessibility.AccessibilityManager
2220
import android.view.inputmethod.InputMethodManager
@@ -182,13 +180,11 @@ class EpubActivity : R2EpubActivity() {
182180
val rect =
183181
try {
184182
with(JSONObject(it)) {
185-
val display = windowManager.defaultDisplay
186-
val metrics = DisplayMetrics()
187-
display.getMetrics(metrics)
183+
val density = this@EpubActivity.resources.displayMetrics.density
188184
val left = getDouble("left")
189185
val width = getDouble("width")
190-
val top = getDouble("top") * metrics.density
191-
val height = getDouble("height") * metrics.density
186+
val top = getDouble("top") * density
187+
val height = getDouble("height") * density
192188
Rect(
193189
left.toInt(),
194190
top.toInt(),
@@ -230,30 +226,31 @@ class EpubActivity : R2EpubActivity() {
230226
// // when the corresponding highlight in DB is.
231227
// }
232228

233-
val display = windowManager.defaultDisplay
234-
val rect = size ?: Rect()
235-
236-
val mDisplaySize = Point()
237-
display.getSize(mDisplaySize)
238-
239229
val popupView = layoutInflater.inflate(
240-
if (rect.top > rect.height()) R.layout.view_action_mode_reverse else R.layout.view_action_mode,
241-
null,
242-
false
230+
if (size.top > size.height()) R.layout.view_action_mode_reverse else R.layout.view_action_mode,
231+
null,
232+
false
233+
)
234+
popupView.measure(
235+
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
236+
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
243237
)
244-
popupView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED))
245238

246-
popupWindow = PopupWindow(popupView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)
239+
popupWindow = PopupWindow(
240+
popupView,
241+
LinearLayout.LayoutParams.WRAP_CONTENT,
242+
LinearLayout.LayoutParams.WRAP_CONTENT
243+
)
247244
popupWindow?.isFocusable = true
248245

249-
val x = rect.left
250-
val y = if (rect.top > rect.height()) rect.top - rect.height() - 80 else rect.bottom
246+
val x = size.left
247+
val y = if (size.top > size.height()) size.top - size.height() - 80 else size.bottom
251248

252249
popupWindow?.showAtLocation(popupView, Gravity.NO_GRAVITY, x, y)
253250

254251
popupView.run {
255252
findViewById<View>(R.id.notch).run {
256-
setX((rect.left * 2).toFloat())
253+
setX((size.left * 2).toFloat())
257254
}
258255
findViewById<View>(R.id.red).setOnClickListener {
259256
changeHighlightColor(highlight, Color.rgb(247, 124, 124))
@@ -425,7 +422,7 @@ class EpubActivity : R2EpubActivity() {
425422
userSettings = UserSettings(preferences, this, publication.userSettingsUIPreset)
426423
userSettings.saveChanges()
427424

428-
Handler().postDelayed({
425+
Handler(mainLooper).postDelayed({
429426
userSettings.resourcePager = resourcePager
430427
userSettings.updateViewCSS(SCROLL_REF)
431428
}, 500)

test-app/r2-testapp/src/main/java/org/readium/r2/testapp/epub/UserSettings.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ class UserSettings(var preferences: SharedPreferences, val context: Context, pri
178178
view.setProperty(userSetting.name, userSetting.toString())
179179
}
180180

181-
181+
// There isn't an easy way to migrate from TabHost/TabWidget to TabLayout
182+
@Suppress("DEPRECATION")
182183
fun userSettingsPopUp(): PopupWindow {
183184

184185
val layoutInflater = LayoutInflater.from(context)

test-app/r2-testapp/src/main/java/org/readium/r2/testapp/opds/OPDSDownloader.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class OPDSDownloader(context: Context) {
4242
}
4343

4444
suspend fun publicationUrl(
45-
url: String,
46-
parameters: List<Pair<String, Any?>>? = null
45+
url: String
4746
): Try<Pair<String, String>, Exception> {
4847
val fileName = UUID.randomUUID().toString()
4948
if (DEBUG) Timber.i("download url %s", url)

0 commit comments

Comments
 (0)