-
Notifications
You must be signed in to change notification settings - Fork 161
Migrate ResultsScreen to use Nav3 #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
df7c28c
7bb6ccd
048c502
500f5dc
50e8395
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.android.developers.androidify.navigation | ||
|
||
import android.net.Uri | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
import androidx.core.net.toUri | ||
|
||
object UriSerializer: KSerializer<Uri> { | ||
override val descriptor: SerialDescriptor = | ||
PrimitiveSerialDescriptor("Uri", PrimitiveKind.STRING) | ||
|
||
override fun serialize(encoder: Encoder, value: Uri) { | ||
encoder.encodeString(value.toString()) | ||
} | ||
|
||
override fun deserialize(decoder: Decoder): Uri = decoder.decodeString().toUri() | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,6 +18,7 @@ package com.android.developers.androidify.util | |||||||||||||||
import android.app.Application | ||||||||||||||||
import android.content.ContentValues | ||||||||||||||||
import android.graphics.Bitmap | ||||||||||||||||
import android.graphics.BitmapFactory | ||||||||||||||||
import android.net.Uri | ||||||||||||||||
import android.os.Build | ||||||||||||||||
import android.os.Environment | ||||||||||||||||
|
@@ -53,6 +54,9 @@ interface LocalFileProvider { | |||||||||||||||
|
||||||||||||||||
@WorkerThread | ||||||||||||||||
suspend fun saveUriToSharedStorage(inputUri: Uri, fileName: String, mimeType: String): Uri | ||||||||||||||||
|
||||||||||||||||
@WorkerThread | ||||||||||||||||
suspend fun loadBitmapFromUri(uri: Uri): Bitmap? | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
@Singleton | ||||||||||||||||
|
@@ -120,6 +124,20 @@ class LocalFileProviderImpl @Inject constructor( | |||||||||||||||
return@withContext newUri | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
override suspend fun loadBitmapFromUri(uri: Uri): Bitmap? { | ||||||||||||||||
return withContext(ioDispatcher) { | ||||||||||||||||
try { | ||||||||||||||||
application.contentResolver.openInputStream(uri)?.use { | ||||||||||||||||
return@withContext BitmapFactory.decodeStream(it) | ||||||||||||||||
} | ||||||||||||||||
null | ||||||||||||||||
} catch (e: Exception) { | ||||||||||||||||
e.printStackTrace() | ||||||||||||||||
null | ||||||||||||||||
Comment on lines
+134
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
@Throws(IOException::class) | ||||||||||||||||
@WorkerThread | ||||||||||||||||
private fun saveFileToUri(file: File, uri: Uri) { | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I wonder if there is a way to register the UriSerializer for Nav3? @dturner