Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
RoomView
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
LOISIL Paul
RoomView
Commits
b741ba72
Commit
b741ba72
authored
2 years ago
by
FurWaz
Browse files
Options
Downloads
Patches
Plain Diff
Set building saving async to avoid lag
parent
79ad0da3
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
Sources/app/src/main/java/Common/BuildingManager.java
+19
-14
19 additions, 14 deletions
Sources/app/src/main/java/Common/BuildingManager.java
with
19 additions
and
14 deletions
Sources/app/src/main/java/Common/BuildingManager.java
+
19
−
14
View file @
b741ba72
...
...
@@ -15,6 +15,8 @@ import java.io.ObjectOutputStream;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
Structures.BuildingInfo
;
...
...
@@ -76,22 +78,25 @@ public class BuildingManager {
// saves the given building to the file system
public
static
void
saveBuilding
(
BuildingInfo
building
)
{
new
File
(
save_dir
,
building
.
getName
()).
delete
();
ExecutorService
executor
=
Executors
.
newSingleThreadExecutor
();
executor
.
execute
(()
->
{
try
{
try
{
FileOutputStream
outputStream
=
new
FileOutputStream
(
new
File
(
save_dir
,
building
.
getName
())
);
ObjectOutputStream
obStream
=
new
ObjectOutputStream
(
outputStream
);
obStream
.
writeObject
(
building
);
obStream
.
close
();
outputStream
.
close
();
}
catch
(
Exception
e
)
{
Toast
.
makeText
(
context
,
"Error saving building "
+
building
.
getName
()+
": "
+
e
.
toString
(),
Toast
.
LENGTH_SHORT
).
show
();
}
FileOutputStream
outputStream
=
new
FileOutputStream
(
new
File
(
save_dir
,
building
.
getName
())
);
ObjectOutputStream
obStream
=
new
ObjectOutputStream
(
outputStream
);
obStream
.
writeObject
(
building
);
obStream
.
close
();
outputStream
.
close
();
}
catch
(
Exception
e
)
{
Toast
.
makeText
(
context
,
"Error saving building "
+
building
.
getName
()+
": "
+
e
.
toString
(),
Toast
.
LENGTH_SHORT
).
show
();
}
int
index
=
BuildingManager
.
buildings
.
indexOf
(
building
);
if
(
index
!=
-
1
)
{
BuildingManager
.
buildings
.
remove
(
index
);
}
BuildingManager
.
buildings
.
add
(
building
);
int
index
=
BuildingManager
.
buildings
.
indexOf
(
building
);
if
(
index
!=
-
1
)
{
BuildingManager
.
buildings
.
remove
(
index
);
}
BuildingManager
.
buildings
.
add
(
building
);
});
}
// saves all the buildings to the file system
...
...
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