File tree Expand file tree Collapse file tree 1 file changed +33
-2
lines changed
app/src/main/java/org/lineageos/glimpse/viewmodels Expand file tree Collapse file tree 1 file changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ import org.lineageos.glimpse.models.MediaType
3535import org.lineageos.glimpse.models.RequestStatus
3636import org.lineageos.glimpse.models.RequestStatus.Companion.map
3737import org.lineageos.glimpse.utils.MimeUtils
38+ import java.util.Date
3839
3940/* *
4041 * A view model used by activities to handle intents.
@@ -270,8 +271,38 @@ class IntentsViewModel(application: Application) : GlimpseViewModel(application)
270271 is RequestStatus .Success -> it.data
271272
272273 is RequestStatus .Error -> {
273- Log .e(LOG_TAG , " Cannot get media of $uri , error: ${it.error} " )
274- null
274+ // Build a `Media` object with the available data
275+ Log .i(
276+ LOG_TAG ,
277+ " Cannot get media object from media provider, trying manual fallback"
278+ )
279+ when (type) {
280+ MediaType .IMAGE ,
281+ MediaType .VIDEO ->
282+ Media (
283+ uri,
284+ type,
285+ applicationContext.contentResolver.getType(uri) ? : run {
286+ Log .e(LOG_TAG , " Cannot get media type of $uri " )
287+ return null
288+ },
289+ uri,
290+ albumName = null ,
291+ displayName = null ,
292+ isFavorite = false ,
293+ isTrashed = false ,
294+ dateAdded = Date (),
295+ dateModified = Date (),
296+ width = 0 ,
297+ height = 0 ,
298+ orientation = 0 ,
299+ )
300+
301+ else -> {
302+ Log .e(LOG_TAG , " Cannot build media object for $uri " )
303+ null
304+ }
305+ }
275306 }
276307 }
277308 }
You can’t perform that action at this time.
0 commit comments