Permalink
Browse files

Merge pull request #570 from ianhanniballake/authority_as_key

Use the MuzeiArtProvider's authority as the unique key
  • Loading branch information...
ianhanniballake committed Sep 14, 2018
2 parents a6e68e8 + ee26492 commit 4603f5f87c48300f426fe9351f0fc6169eeb4b35
Showing with 583 additions and 304 deletions.
  1. +196 −0 android-client-common/schemas/com.google.android.apps.muzei.room.MuzeiDatabase/8.json
  2. +7 −4 android-client-common/src/main/java/com/google/android/apps/muzei/provider/MuzeiProvider.kt
  3. +2 −5 android-client-common/src/main/java/com/google/android/apps/muzei/room/Artwork.kt
  4. +6 −10 android-client-common/src/main/java/com/google/android/apps/muzei/room/ArtworkDao.kt
  5. +97 −8 android-client-common/src/main/java/com/google/android/apps/muzei/room/MuzeiDatabase.kt
  6. +1 −6 android-client-common/src/main/java/com/google/android/apps/muzei/room/Provider.kt
  7. +0 −61 android-client-common/src/main/java/com/google/android/apps/muzei/room/ProviderExt.kt
  8. +11 −11 android-client-common/src/main/java/com/google/android/apps/muzei/sync/ArtworkLoadWorker.kt
  9. +6 −6 android-client-common/src/main/java/com/google/android/apps/muzei/sync/ProviderChangedWorker.kt
  10. +42 −10 android-client-common/src/main/java/com/google/android/apps/muzei/sync/ProviderManager.kt
  11. +2 −1 example-unsplash/src/main/java/com/example/muzei/unsplash/UnsplashExampleWorker.kt
  12. +3 −8 main/src/main/java/com/google/android/apps/muzei/ArtDetailFragment.kt
  13. +20 −27 main/src/main/java/com/google/android/apps/muzei/ChooseProviderFragment.kt
  14. +36 −35 main/src/main/java/com/google/android/apps/muzei/ChooseProviderViewModel.kt
  15. +2 −3 main/src/main/java/com/google/android/apps/muzei/MuzeiWallpaperService.kt
  16. +3 −2 main/src/main/java/com/google/android/apps/muzei/PhotoSetAsTargetActivity.kt
  17. +3 −6 main/src/main/java/com/google/android/apps/muzei/browse/BrowseProviderViewModel.kt
  18. +5 −5 main/src/main/java/com/google/android/apps/muzei/sources/SourceArtProvider.kt
  19. +21 −13 main/src/main/java/com/google/android/apps/muzei/sources/SourceManager.kt
  20. +2 −1 main/src/main/java/com/google/android/apps/muzei/sources/SourceSubscriberService.kt
  21. +74 −35 muzei-api/src/main/java/com/google/android/apps/muzei/api/provider/ProviderContract.java
  22. +2 −1 source-featured-art/src/main/java/com/google/android/apps/muzei/featuredart/FeaturedArtWorker.kt
  23. +2 −1 source-single/src/main/java/com/google/android/apps/muzei/single/SingleArtProvider.kt
  24. +4 −3 source-single/src/main/java/com/google/android/apps/muzei/single/SingleArtSource.kt
  25. +9 −10 wearable/src/main/java/com/google/android/apps/muzei/ChooseProviderActivity.kt
  26. +9 −9 wearable/src/main/java/com/google/android/apps/muzei/ChooseProviderViewModel.kt
  27. +8 −14 wearable/src/main/java/com/google/android/apps/muzei/MuzeiActivity.kt
  28. +2 −3 wearable/src/main/java/com/google/android/apps/muzei/MuzeiWatchFace.kt
  29. +3 −3 ...e/src/main/java/com/google/android/apps/muzei/complications/ArtworkComplicationProviderService.kt
  30. +3 −2 wearable/src/main/java/com/google/android/apps/muzei/datalayer/CapabilityListenerService.kt
  31. +2 −1 wearable/src/main/java/com/google/android/apps/muzei/datalayer/DataLayerLoadWorker.kt
@@ -0,0 +1,196 @@
{
"formatVersion": 1,
"database": {
"version": 8,
"identityHash": "47c297dbd8769484cda0e189bcfba4c4",
"entities": [
{
"tableName": "Artwork",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `providerAuthority` TEXT NOT NULL, `title` TEXT, `byline` TEXT, `attribution` TEXT, `metaFont` TEXT NOT NULL, `date_added` INTEGER NOT NULL, `imageUri` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "providerAuthority",
"columnName": "providerAuthority",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "byline",
"columnName": "byline",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "attribution",
"columnName": "attribution",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "metaFont",
"columnName": "metaFont",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "dateAdded",
"columnName": "date_added",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "imageUri",
"columnName": "imageUri",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"_id"
],
"autoGenerate": true
},
"indices": [
{
"name": "index_Artwork_providerAuthority",
"unique": false,
"columnNames": [
"providerAuthority"
],
"createSql": "CREATE INDEX `index_Artwork_providerAuthority` ON `${TABLE_NAME}` (`providerAuthority`)"
}
],
"foreignKeys": []
},
{
"tableName": "sources",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`selected` INTEGER NOT NULL, `label` TEXT, `defaultDescription` TEXT, `description` TEXT, `color` INTEGER NOT NULL, `targetSdkVersion` INTEGER NOT NULL, `settingsActivity` TEXT, `setupActivity` TEXT, `wantsNetworkAvailable` INTEGER NOT NULL, `supportsNextArtwork` INTEGER NOT NULL, `commands` TEXT NOT NULL, `component_name` TEXT NOT NULL, PRIMARY KEY(`component_name`))",
"fields": [
{
"fieldPath": "selected",
"columnName": "selected",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "label",
"columnName": "label",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "defaultDescription",
"columnName": "defaultDescription",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "description",
"columnName": "description",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "color",
"columnName": "color",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "targetSdkVersion",
"columnName": "targetSdkVersion",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "settingsActivity",
"columnName": "settingsActivity",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "setupActivity",
"columnName": "setupActivity",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "wantsNetworkAvailable",
"columnName": "wantsNetworkAvailable",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "supportsNextArtwork",
"columnName": "supportsNextArtwork",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "commands",
"columnName": "commands",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "componentName",
"columnName": "component_name",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"component_name"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "provider",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`authority` TEXT NOT NULL, `supportsNextArtwork` INTEGER NOT NULL, PRIMARY KEY(`authority`))",
"fields": [
{
"fieldPath": "authority",
"columnName": "authority",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "supportsNextArtwork",
"columnName": "supportsNextArtwork",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"authority"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"47c297dbd8769484cda0e189bcfba4c4\")"
]
}
}
@@ -32,7 +32,8 @@ import android.support.v4.os.UserManagerCompat
import android.util.Log
import com.google.android.apps.muzei.api.MuzeiContract
import com.google.android.apps.muzei.room.MuzeiDatabase
import com.google.android.apps.muzei.room.getDescription
import com.google.android.apps.muzei.room.getComponentName
import com.google.android.apps.muzei.sync.ProviderManager
import kotlinx.coroutines.experimental.runBlocking
import net.nurik.roman.muzei.androidclientcommon.BuildConfig
import java.io.FileNotFoundException
@@ -177,7 +178,7 @@ class MuzeiProvider : ContentProvider() {
}
var finalSelection = provider?.run {
DatabaseUtils.concatenateWhere(selection,
"providerComponentName = \"${provider.componentName.flattenToShortString()}\"")
"providerAuthority = \"${provider.authority}\"")
} ?: selection
if (MuzeiProvider.uriMatcher.match(uri) == ARTWORK_ID) {
// If the incoming URI is for a single artwork identified by its ID, appends "_ID = <artworkId>"
@@ -204,10 +205,12 @@ class MuzeiProvider : ContentProvider() {
currentProvider?.let { provider ->
c.newRow().apply {
add(BaseColumns._ID, 0L)
add(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, provider.componentName)
val componentName = context.packageManager.resolveContentProvider(provider
.authority, 0)?.getComponentName()?.flattenToShortString()
add(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, componentName)
add(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED, true)
add(MuzeiContract.Sources.COLUMN_NAME_DESCRIPTION, runBlocking {
provider.getDescription(context)
ProviderManager.getDescription(context, provider.authority)
})
add(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, false)
add(MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND,
@@ -21,21 +21,19 @@ import android.arch.persistence.room.Entity
import android.arch.persistence.room.Index
import android.arch.persistence.room.PrimaryKey
import android.arch.persistence.room.TypeConverters
import android.content.ComponentName
import android.content.ContentResolver
import android.content.ContentUris
import android.net.Uri
import android.provider.BaseColumns
import com.google.android.apps.muzei.api.MuzeiContract
import com.google.android.apps.muzei.room.converter.ComponentNameTypeConverter
import com.google.android.apps.muzei.room.converter.DateTypeConverter
import com.google.android.apps.muzei.room.converter.UriTypeConverter
import java.util.Date
/**
* Artwork's representation in Room
*/
@Entity(indices = [(Index(value = ["providerComponentName"]))])
@Entity(indices = [(Index(value = ["providerAuthority"]))])
class Artwork(
@field:TypeConverters(UriTypeConverter::class)
val imageUri: Uri
@@ -44,8 +42,7 @@ class Artwork(
@ColumnInfo(name = BaseColumns._ID)
var id: Long = 0
@TypeConverters(ComponentNameTypeConverter::class)
lateinit var providerComponentName: ComponentName
lateinit var providerAuthority: String
var title: String? = null
@@ -20,9 +20,6 @@ import android.arch.lifecycle.LiveData
import android.arch.persistence.room.Dao
import android.arch.persistence.room.Insert
import android.arch.persistence.room.Query
import android.arch.persistence.room.TypeConverters
import android.content.ComponentName
import com.google.android.apps.muzei.room.converter.ComponentNameTypeConverter
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.withContext
@@ -40,12 +37,12 @@ abstract class ArtworkDao {
}
@get:Query("SELECT artwork.* FROM artwork " +
"inner join provider on providerComponentName = componentName " +
"inner join provider on providerAuthority = authority " +
"ORDER BY date_added DESC")
abstract val currentArtwork: LiveData<Artwork?>
@get:Query("SELECT artwork.* FROM artwork " +
"inner join provider on providerComponentName = componentName " +
"inner join provider on providerAuthority = authority " +
"ORDER BY date_added DESC")
internal abstract val currentArtworkBlocking: Artwork?
@@ -56,16 +53,15 @@ abstract class ArtworkDao {
@Insert
abstract fun insert(artwork: Artwork): Long
@TypeConverters(ComponentNameTypeConverter::class)
@Query("SELECT * FROM artwork WHERE providerComponentName = :providerComponentName ORDER BY date_added DESC")
@Query("SELECT * FROM artwork WHERE providerAuthority = :providerAuthority ORDER BY date_added DESC")
internal abstract fun getCurrentArtworkForProviderBlocking(
providerComponentName: ComponentName
providerAuthority: String
): Artwork?
suspend fun getCurrentArtworkForProvider(
providerComponentName: ComponentName
providerAuthority: String
) = withContext(CommonPool) {
getCurrentArtworkForProviderBlocking(providerComponentName)
getCurrentArtworkForProviderBlocking(providerAuthority)
}
@get:Query("SELECT * FROM artwork art1 WHERE _id IN (" +
Oops, something went wrong.

0 comments on commit 4603f5f

Please sign in to comment.