Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
circles-android
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Circles
circles-android
Commits
12d73391
"java/src/git@gitlab.futo.org:keyboard/latinime.git" did not exist on "a7f2500001c53dc5a6de9c2525a75229cc7c6645"
Commit
12d73391
authored
3 years ago
by
Taras
Browse files
Options
Downloads
Patches
Plain Diff
Create glide data fetcher
parent
e0e65171
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/com/futo/circles/glide/CirclesGlideDataFetcher.kt
+79
-0
79 additions, 0 deletions
...in/java/com/futo/circles/glide/CirclesGlideDataFetcher.kt
with
79 additions
and
0 deletions
app/src/main/java/com/futo/circles/glide/CirclesGlideDataFetcher.kt
0 → 100644
+
79
−
0
View file @
12d73391
package
com.futo.circles.glide
import
android.content.Context
import
android.util.Log
import
com.bumptech.glide.Priority
import
com.bumptech.glide.load.DataSource
import
com.bumptech.glide.load.data.DataFetcher
import
com.futo.circles.extensions.coroutineScope
import
com.futo.circles.model.ImageContent
import
com.futo.circles.provider.MatrixSessionProvider
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withContext
import
org.matrix.android.sdk.api.Matrix
import
java.io.IOException
import
java.io.InputStream
class
CirclesGlideDataFetcher
(
context
:
Context
,
private
val
data
:
ImageContent
)
:
DataFetcher
<
InputStream
>
{
private
val
localFilesHelper
=
LocalFileHelper
(
context
)
private
val
matrixSession
=
MatrixSessionProvider
.
currentSession
override
fun
getDataClass
():
Class
<
InputStream
>
{
return
InputStream
::
class
.
java
}
private
var
stream
:
InputStream
?
=
null
override
fun
cleanup
()
{
cancel
()
}
override
fun
getDataSource
():
DataSource
{
return
DataSource
.
REMOTE
}
override
fun
cancel
()
{
if
(
stream
!=
null
)
{
try
{
stream
?.
close
()
stream
=
null
}
catch
(
ignore
:
Throwable
)
{
Log
.
e
(
this
.
javaClass
.
name
,
"Failed to close stream ${ignore.localizedMessage}"
)
}
finally
{
stream
=
null
}
}
}
override
fun
loadData
(
priority
:
Priority
,
callback
:
DataFetcher
.
DataCallback
<
in
InputStream
>)
{
if
(
localFilesHelper
.
isLocalFile
(
data
.
fileUrl
))
{
localFilesHelper
.
openInputStream
(
data
.
fileUrl
)
?.
use
{
callback
.
onDataReady
(
it
)
}
return
}
val
fileService
=
matrixSession
?.
fileService
()
?:
return
Unit
.
also
{
callback
.
onLoadFailed
(
IllegalArgumentException
(
"No File service"
))
}
matrixSession
.
coroutineScope
.
launch
{
val
result
=
runCatching
{
fileService
.
downloadFile
(
fileName
=
data
.
fileName
,
mimeType
=
data
.
mimeType
,
url
=
data
.
fileUrl
,
elementToDecrypt
=
data
.
elementToDecrypt
)
}
withContext
(
Dispatchers
.
Main
)
{
result
.
fold
(
{
callback
.
onDataReady
(
it
.
inputStream
())
},
{
callback
.
onLoadFailed
(
it
as
?
Exception
?:
IOException
(
it
.
localizedMessage
))
}
)
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment