Skip to content

Commit

Permalink
Merge pull request #81 from learning-layers/integration
Browse files Browse the repository at this point in the history
Release v1.3.1
  • Loading branch information
bqqbarbhg committed Nov 2, 2015
2 parents 19cbb7a + 8ba4c8b commit 1aab903
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
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

0 comments on commit 1aab903

Please sign in to comment.