Skip to content
Permalink
Browse files

Convert all muzei-api classes to Kotlin

Replace all usages of Artwork().apply {} with the new Artwork constructor with default values as Artwork is now immutable.
  • Loading branch information...
ianhanniballake committed Sep 16, 2019
1 parent 39fa4c4 commit ff9d59554dd62ca595054c0299bbda3bb3edbc5f
Showing with 2,451 additions and 2,849 deletions.
  1. +2 −3 android-client-common/src/main/java/com/google/android/apps/muzei/sync/ArtworkLoadWorker.kt
  2. +6 −9 android-client-common/src/main/java/com/google/android/apps/muzei/wearable/ArtworkTransfer.kt
  3. +8 −9 example-unsplash/src/main/java/com/example/muzei/unsplash/UnsplashExampleWorker.kt
  4. +8 −9 legacy-standalone/src/main/java/com/google/android/apps/muzei/sources/SourceSubscriberService.kt
  5. +2 −0 muzei-api/build.gradle
  6. +0 −199 muzei-api/src/main/java/com/google/android/apps/muzei/api/Artwork.java
  7. +130 −0 muzei-api/src/main/java/com/google/android/apps/muzei/api/Artwork.kt
  8. +0 −299 muzei-api/src/main/java/com/google/android/apps/muzei/api/MuzeiContract.java
  9. +301 −0 muzei-api/src/main/java/com/google/android/apps/muzei/api/MuzeiContract.kt
  10. +0 −129 muzei-api/src/main/java/com/google/android/apps/muzei/api/UserCommand.java
  11. +71 −0 muzei-api/src/main/java/com/google/android/apps/muzei/api/UserCommand.kt
  12. +0 −49 muzei-api/src/main/java/com/google/android/apps/muzei/api/internal/ProtocolConstants.java
  13. +45 −0 muzei-api/src/main/java/com/google/android/apps/muzei/api/internal/ProtocolConstants.kt
  14. +0 −47 muzei-api/src/main/java/com/google/android/apps/muzei/api/internal/RecentArtworkIdsConverter.java
  15. +53 −0 muzei-api/src/main/java/com/google/android/apps/muzei/api/internal/RecentArtworkIdsConverter.kt
  16. +0 −591 muzei-api/src/main/java/com/google/android/apps/muzei/api/provider/Artwork.java
  17. +426 −0 muzei-api/src/main/java/com/google/android/apps/muzei/api/provider/Artwork.kt
  18. +0 −1,151 muzei-api/src/main/java/com/google/android/apps/muzei/api/provider/MuzeiArtProvider.java
  19. +1,050 −0 muzei-api/src/main/java/com/google/android/apps/muzei/api/provider/MuzeiArtProvider.kt
  20. +21 −34 ...rc/main/java/com/google/android/apps/muzei/api/provider/{ProviderClient.java → ProviderClient.kt}
  21. +0 −296 muzei-api/src/main/java/com/google/android/apps/muzei/api/provider/ProviderContract.java
  22. +310 −0 muzei-api/src/main/java/com/google/android/apps/muzei/api/provider/ProviderContract.kt
  23. +7 −8 source-featured-art/src/main/java/com/google/android/apps/muzei/featuredart/FeaturedArtWorker.kt
  24. +8 −9 source-gallery/src/main/java/com/google/android/apps/muzei/gallery/GalleryScanWorker.kt
  25. +3 −7 source-single/src/main/java/com/google/android/apps/muzei/single/SingleArtProvider.kt
@@ -37,7 +37,7 @@ import com.google.android.apps.muzei.api.internal.ProtocolConstants.KEY_RECENT_A
import com.google.android.apps.muzei.api.internal.ProtocolConstants.METHOD_GET_LOAD_INFO
import com.google.android.apps.muzei.api.internal.ProtocolConstants.METHOD_MARK_ARTWORK_LOADED
import com.google.android.apps.muzei.api.internal.ProtocolConstants.METHOD_REQUEST_LOAD
import com.google.android.apps.muzei.api.internal.RecentArtworkIdsConverter
import com.google.android.apps.muzei.api.internal.getRecentIds
import com.google.android.apps.muzei.api.provider.MuzeiArtProvider
import com.google.android.apps.muzei.api.provider.ProviderContract
import com.google.android.apps.muzei.render.isValidImage
@@ -114,8 +114,7 @@ class ArtworkLoadWorker(
val result = client.call(METHOD_GET_LOAD_INFO)
?: return@withContext Result.failure()
val maxLoadedArtworkId = result.getLong(KEY_MAX_LOADED_ARTWORK_ID, 0L)
val recentArtworkIds = RecentArtworkIdsConverter.fromString(
result.getString(KEY_RECENT_ARTWORK_IDS, ""))
val recentArtworkIds = result.getRecentIds(KEY_RECENT_ARTWORK_IDS)
client.query(
contentUri,
selection = "_id > ?",
@@ -46,13 +46,10 @@ fun Artwork.toDataMap(): DataMap = DataMap.fromBundle(bundleOf(
*/
fun DataMap.toArtwork(): com.google.android.apps.muzei.api.provider.Artwork {
val bundle = toBundle()
return com.google.android.apps.muzei.api.provider.Artwork().apply {
val imageUri = bundle.getString(KEY_IMAGE_URI)
if (imageUri != null && !imageUri.isBlank()) {
persistentUri = imageUri.toUri()
}
title = bundle.getString(KEY_TITLE)
byline = bundle.getString(KEY_BYLINE)
attribution = bundle.getString(KEY_ATTRIBUTION)
}
return com.google.android.apps.muzei.api.provider.Artwork(
persistentUri = bundle.getString(KEY_IMAGE_URI)?.takeUnless { it.isBlank() }?.toUri(),
title = bundle.getString(KEY_TITLE),
byline = bundle.getString(KEY_BYLINE),
attribution = bundle.getString(KEY_ATTRIBUTION)
)
}
@@ -65,15 +65,14 @@ class UnsplashExampleWorker(
applicationContext, UNSPLASH_AUTHORITY)
val attributionString = applicationContext.getString(R.string.attribution)
providerClient.addArtwork(photos.map { photo ->
Artwork().apply {
token = photo.id
title = photo.description ?: attributionString
byline = photo.user.name
attribution = if (photo.description != null) attributionString else null
persistentUri = photo.urls.full.toUri()
webUri = photo.links.webUri
metadata = photo.user.links.webUri.toString()
}
Artwork(
token = photo.id,
title = photo.description ?: attributionString,
byline = photo.user.name,
attribution = if (photo.description != null) attributionString else null,
persistentUri = photo.urls.full.toUri(),
webUri = photo.links.webUri,
metadata = photo.user.links.webUri.toString())
})
return Result.success()
}
@@ -81,15 +81,14 @@ class SourceSubscriberService : IntentService("SourceSubscriberService") {

val currentArtwork = state.currentArtwork
if (currentArtwork?.imageUri != null) {
val newArtwork = Artwork().apply {
metadata = source.componentName.toShortString()
persistentUri = currentArtwork.imageUri
title = currentArtwork.title
byline = currentArtwork.byline
attribution = currentArtwork.attribution
token = currentArtwork.imageUri.toString()
webUri = currentArtwork.viewIntent?.toUri(Intent.URI_INTENT_SCHEME)?.toUri()
}
val newArtwork = Artwork(
metadata = source.componentName.toShortString(),
persistentUri = currentArtwork.imageUri,
title = currentArtwork.title,
byline = currentArtwork.byline,
attribution = currentArtwork.attribution,
token = currentArtwork.imageUri.toString(),
webUri = currentArtwork.viewIntent?.toUri(Intent.URI_INTENT_SCHEME)?.toUri())

val artworkUri = ProviderContract.getProviderClient(this,
LEGACY_AUTHORITY).setArtwork(newArtwork)
@@ -15,6 +15,7 @@
*/

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'maven'
apply plugin: 'signing'

@@ -34,6 +35,7 @@ allprojects { ext."signing.secretKeyRingFile" = props["signing.secretKeyRingFile

dependencies {
api "androidx.annotation:annotation:1.1.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion

This file was deleted.

0 comments on commit ff9d595

Please sign in to comment.
You can’t perform that action at this time.