Skip to content
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

Release v1.3.1 #81

Merged
merged 3 commits into from
Nov 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/src/main/java/fi/aalto/legroup/achso/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ public void onCreate() {
File cacheVideoDirectory = new File(localStorageDirectory, "cache");
cacheVideoDirectory.mkdirs();

if (!cacheVideoDirectory.isDirectory()) {
// If the cache directory can't be created use internal App storage
// There is a slim chance that the user saves some modified videos to the internal
// storage and then inserts and SD card causing videos not to be uploaded, but it
// doesn't seem worth the trouble.

File internalDataDirectory = new File(getApplicationInfo().dataDir);
cacheVideoDirectory = new File(internalDataDirectory, "manifestcache");
cacheVideoDirectory.mkdirs();
}

CombinedVideoRepository combinedRepository = new CombinedVideoRepository(bus, jsonSerializer,
localStorageDirectory, cacheVideoDirectory);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public CombinedVideoRepository(Bus bus, JsonSerializer serializer, File localRoo

private List<UUID> getCacheIds() {
String[] entries = cacheRoot.list();
if (entries == null) {
return Collections.emptyList();
}

ArrayList<UUID> results = new ArrayList<>(entries.length);

for (String entry : entries) {
Expand Down Expand Up @@ -127,6 +131,15 @@ protected void updateVideos(List<OptimizedVideo> videos, List<Group> groups) {
bus.post(new VideoRepositoryUpdatedEvent(this));
}

private File[] safeListFiles(File root, FilenameFilter filter) {
File[] files = root.listFiles(filter);
if (files != null) {
return files;
} else {
return new File[0];
}
}

/**
* Add a host to the repository to sync to.
*/
Expand Down Expand Up @@ -170,7 +183,7 @@ public void refreshOffline() {
List<OptimizedVideo> videos = new ArrayList<>();

// Add the local videos
File[] localFiles = localRoot.listFiles(new ManifestFileFilter());
File[] localFiles = safeListFiles(localRoot, new ManifestFileFilter());
for (File file : localFiles) {

OptimizedVideo video = tryLoadOrReUseVideo(file, getIdFromFile(file));
Expand Down Expand Up @@ -246,7 +259,7 @@ public void refreshOnline() {

// Add the local videos
// TODO: These can be cached
File[] localFiles = localRoot.listFiles(new ManifestFileFilter());
File[] localFiles = safeListFiles(localRoot, new ManifestFileFilter());
for (File file : localFiles) {

OptimizedVideo localVideo = tryLoadOrReUseVideo(file, getIdFromFile(file));
Expand Down