Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
BriarWithLoRa
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
Thomas
BriarWithLoRa
Commits
5beed1a7
Commit
5beed1a7
authored
6 years ago
by
Torsten Grote
Browse files
Options
Downloads
Plain Diff
Merge branch '1594-preview-fails-to-load' into 'master'
Use a fresh LiveData for each attachment creation task Closes
#1594
See merge request
!1144
parents
774047d8
be1c33cb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
briar-android/src/main/java/org/briarproject/briar/android/attachment/AttachmentCreator.java
+19
-8
19 additions, 8 deletions
...arproject/briar/android/attachment/AttachmentCreator.java
with
19 additions
and
8 deletions
briar-android/src/main/java/org/briarproject/briar/android/attachment/AttachmentCreator.java
+
19
−
8
View file @
5beed1a7
...
@@ -49,11 +49,12 @@ public class AttachmentCreator {
...
@@ -49,11 +49,12 @@ public class AttachmentCreator {
private
final
CopyOnWriteArrayList
<
AttachmentItemResult
>
itemResults
=
private
final
CopyOnWriteArrayList
<
AttachmentItemResult
>
itemResults
=
new
CopyOnWriteArrayList
<>();
new
CopyOnWriteArrayList
<>();
private
final
MutableLiveData
<
AttachmentResult
>
result
=
new
MutableLiveData
<>();
@Nullable
@Nullable
private
AttachmentCreationTask
task
;
private
AttachmentCreationTask
task
;
@Nullable
private
volatile
MutableLiveData
<
AttachmentResult
>
result
;
public
AttachmentCreator
(
Application
app
,
@IoExecutor
Executor
ioExecutor
,
public
AttachmentCreator
(
Application
app
,
@IoExecutor
Executor
ioExecutor
,
MessagingManager
messagingManager
,
AttachmentRetriever
retriever
)
{
MessagingManager
messagingManager
,
AttachmentRetriever
retriever
)
{
this
.
app
=
app
;
this
.
app
=
app
;
...
@@ -65,7 +66,7 @@ public class AttachmentCreator {
...
@@ -65,7 +66,7 @@ public class AttachmentCreator {
@UiThread
@UiThread
public
LiveData
<
AttachmentResult
>
storeAttachments
(
public
LiveData
<
AttachmentResult
>
storeAttachments
(
LiveData
<
GroupId
>
groupId
,
Collection
<
Uri
>
newUris
)
{
LiveData
<
GroupId
>
groupId
,
Collection
<
Uri
>
newUris
)
{
if
(
task
!=
null
||
!
uris
.
isEmpty
())
if
(
task
!=
null
||
result
!=
null
||
!
uris
.
isEmpty
())
throw
new
IllegalStateException
();
throw
new
IllegalStateException
();
uris
.
addAll
(
newUris
);
uris
.
addAll
(
newUris
);
observeForeverOnce
(
groupId
,
id
->
{
observeForeverOnce
(
groupId
,
id
->
{
...
@@ -75,6 +76,8 @@ public class AttachmentCreator {
...
@@ -75,6 +76,8 @@ public class AttachmentCreator {
app
.
getContentResolver
(),
this
,
id
,
uris
,
needsSize
);
app
.
getContentResolver
(),
this
,
id
,
uris
,
needsSize
);
ioExecutor
.
execute
(()
->
task
.
storeAttachments
());
ioExecutor
.
execute
(()
->
task
.
storeAttachments
());
});
});
MutableLiveData
<
AttachmentResult
>
result
=
new
MutableLiveData
<>();
this
.
result
=
result
;
return
result
;
return
result
;
}
}
...
@@ -85,7 +88,8 @@ public class AttachmentCreator {
...
@@ -85,7 +88,8 @@ public class AttachmentCreator {
*/
*/
@UiThread
@UiThread
public
LiveData
<
AttachmentResult
>
getLiveAttachments
()
{
public
LiveData
<
AttachmentResult
>
getLiveAttachments
()
{
if
(
task
==
null
||
uris
.
isEmpty
())
MutableLiveData
<
AttachmentResult
>
result
=
this
.
result
;
if
(
task
==
null
||
result
==
null
||
uris
.
isEmpty
())
throw
new
IllegalStateException
();
throw
new
IllegalStateException
();
// A task is already running. It will update the result LiveData.
// A task is already running. It will update the result LiveData.
// So nothing more to do here.
// So nothing more to do here.
...
@@ -103,7 +107,8 @@ public class AttachmentCreator {
...
@@ -103,7 +107,8 @@ public class AttachmentCreator {
AttachmentItemResult
itemResult
=
AttachmentItemResult
itemResult
=
new
AttachmentItemResult
(
uri
,
item
);
new
AttachmentItemResult
(
uri
,
item
);
itemResults
.
add
(
itemResult
);
itemResults
.
add
(
itemResult
);
result
.
postValue
(
getResult
(
false
));
MutableLiveData
<
AttachmentResult
>
result
=
this
.
result
;
if
(
result
!=
null
)
result
.
postValue
(
getResult
(
false
));
}
catch
(
IOException
|
DbException
e
)
{
}
catch
(
IOException
|
DbException
e
)
{
logException
(
LOG
,
WARNING
,
e
);
logException
(
LOG
,
WARNING
,
e
);
onAttachmentError
(
uri
,
e
);
onAttachmentError
(
uri
,
e
);
...
@@ -127,13 +132,15 @@ public class AttachmentCreator {
...
@@ -127,13 +132,15 @@ public class AttachmentCreator {
AttachmentItemResult
itemResult
=
AttachmentItemResult
itemResult
=
new
AttachmentItemResult
(
uri
,
errorMsg
);
new
AttachmentItemResult
(
uri
,
errorMsg
);
itemResults
.
add
(
itemResult
);
itemResults
.
add
(
itemResult
);
result
.
postValue
(
getResult
(
false
));
MutableLiveData
<
AttachmentResult
>
result
=
this
.
result
;
if
(
result
!=
null
)
result
.
postValue
(
getResult
(
false
));
// expect to receive a cancel from the UI
// expect to receive a cancel from the UI
}
}
@IoExecutor
@IoExecutor
void
onAttachmentCreationFinished
()
{
void
onAttachmentCreationFinished
()
{
result
.
postValue
(
getResult
(
true
));
MutableLiveData
<
AttachmentResult
>
result
=
this
.
result
;
if
(
result
!=
null
)
result
.
postValue
(
getResult
(
true
));
}
}
@UiThread
@UiThread
...
@@ -180,7 +187,11 @@ public class AttachmentCreator {
...
@@ -180,7 +187,11 @@ public class AttachmentCreator {
task
=
null
;
task
=
null
;
uris
.
clear
();
uris
.
clear
();
itemResults
.
clear
();
itemResults
.
clear
();
result
.
setValue
(
null
);
MutableLiveData
<
AttachmentResult
>
result
=
this
.
result
;
if
(
result
!=
null
)
{
result
.
setValue
(
null
);
this
.
result
=
null
;
}
}
}
@UiThread
@UiThread
...
...
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