Skip to content

Commit

Permalink
Merge pull request #96 from learning-layers/integration
Browse files Browse the repository at this point in the history
Release v1.6.0
  • Loading branch information
melonmanchan authored Aug 17, 2016
2 parents 9d4672c + 17d9791 commit 6e5915d
Show file tree
Hide file tree
Showing 41 changed files with 529 additions and 49 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
android:parentActivityName=".browsing.BrowserActivity" />

<service android:name=".storage.local.ExportService" />
<service android:name=".storage.remote.UploadService" />
<service android:name=".storage.remote.upload.UploadService" />
<service android:name=".storage.remote.download.DownloadService" />
<service android:name=".storage.remote.SyncService" />
<service android:name=".authoring.VideoCreatorService" />

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/fi/aalto/legroup/achso/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
import fi.aalto.legroup.achso.storage.VideoInfoRepository;
import fi.aalto.legroup.achso.storage.VideoRepository;
import fi.aalto.legroup.achso.storage.remote.SyncService;
import fi.aalto.legroup.achso.storage.remote.UploadService;
import fi.aalto.legroup.achso.storage.remote.upload.UploadService;
import fi.aalto.legroup.achso.storage.remote.strategies.AchRailsStrategy;
import fi.aalto.legroup.achso.storage.remote.strategies.ClViTra2Strategy;
import fi.aalto.legroup.achso.storage.remote.strategies.DumbPhpStrategy;
import fi.aalto.legroup.achso.storage.remote.strategies.GoViTraStrategy;
import fi.legroup.aalto.cryptohelper.CryptoHelper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ protected void onHandleIntent(Intent intent) {
// Save always with the most recent version.
int formatVersion = Video.VIDEO_FORMAT_VERSION;

Video video = new Video(App.videoRepository, manifestUri, videoUri, thumbUri, id, title,
tag, rotation, date, author, location, formatVersion, annotations);
Video video = new Video(App.videoRepository, manifestUri, videoUri, thumbUri, null, null,
id, title, tag, rotation, date, author, location, formatVersion, annotations);

video.save(null);

Expand Down Expand Up @@ -377,6 +377,7 @@ protected VideoBuilder(Parcel parcel) {
id = (UUID) parcel.readValue(UUID.class.getClassLoader());
videoUri = (Uri) parcel.readValue(Uri.class.getClassLoader());
authorUri = (Uri) parcel.readValue(Uri.class.getClassLoader());

location = (Location) parcel.readValue(Location.class.getClassLoader());

title = parcel.readString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import fi.aalto.legroup.achso.storage.VideoRepositoryUpdatedEvent;
import fi.aalto.legroup.achso.storage.remote.SyncRequiredEvent;
import fi.aalto.legroup.achso.storage.remote.SyncService;
import fi.aalto.legroup.achso.storage.remote.UploadStateEvent;
import fi.aalto.legroup.achso.storage.remote.upload.UploadStateEvent;
import fi.aalto.legroup.achso.utilities.BaseActivity;
import fi.aalto.legroup.achso.utilities.ProgressDialogFragment;
import fi.aalto.legroup.achso.views.adapters.VideoTabAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@
import fi.aalto.legroup.achso.playback.PlayerActivity;
import fi.aalto.legroup.achso.sharing.SharingActivity;
import fi.aalto.legroup.achso.storage.local.ExportService;
import fi.aalto.legroup.achso.storage.remote.UploadErrorEvent;
import fi.aalto.legroup.achso.storage.remote.UploadService;
import fi.aalto.legroup.achso.storage.remote.UploadStateEvent;
import fi.aalto.legroup.achso.storage.remote.TransferErrorEvent;
import fi.aalto.legroup.achso.storage.remote.TransferStateEvent;
import fi.aalto.legroup.achso.storage.remote.download.DownloadErrorEvent;
import fi.aalto.legroup.achso.storage.remote.download.DownloadStateEvent;
import fi.aalto.legroup.achso.storage.remote.upload.UploadErrorEvent;
import fi.aalto.legroup.achso.storage.remote.upload.UploadService;
import fi.aalto.legroup.achso.storage.remote.upload.UploadStateEvent;
import fi.aalto.legroup.achso.storage.remote.download.DownloadService;
import fi.aalto.legroup.achso.views.RecyclerItemClickListener;
import fi.aalto.legroup.achso.views.adapters.VideoGridAdapter;
import fi.aalto.legroup.achso.views.utilities.DimensionUnits;
Expand Down Expand Up @@ -138,17 +143,31 @@ public boolean onPrepareActionMode(ActionMode mode, Menu menu) {

MenuItem upload_menu_item = menu.findItem(R.id.action_upload);
MenuItem share_menu_item = menu.findItem(R.id.action_share_to_group);
MenuItem download_menu_item = menu.findItem(R.id.action_download);
MenuItem export_menu_item = menu.findItem(R.id.action_export_video);

if (App.loginManager.isLoggedIn()) {
upload_menu_item.setEnabled(true);
share_menu_item.setEnabled(true);
download_menu_item.setEnabled(true);
export_menu_item.setEnabled(true);

upload_menu_item.getIcon().setAlpha(255);
share_menu_item.getIcon().setAlpha(255);
download_menu_item.getIcon().setAlpha(255);
export_menu_item.getIcon().setAlpha(255);
} else {
upload_menu_item.setEnabled(false);
share_menu_item.setEnabled(false);
download_menu_item.setEnabled(false);
export_menu_item.setEnabled(false);

upload_menu_item.getIcon().setAlpha(130);
share_menu_item.getIcon().setAlpha(130);
download_menu_item.getIcon().setAlpha(130);
export_menu_item.getIcon().setAlpha(130);
}

return true;
}

Expand Down Expand Up @@ -195,9 +214,11 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
e.printStackTrace();
}
}

if (!hasLocal) {
SharingActivity.openShareActivity(getActivity(), selection);
}

mode.finish();
return true;
}
Expand All @@ -210,6 +231,28 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
mode.finish();
return true;

case R.id.action_download:
{
List<UUID> selection = getSelection();
DownloadService.download(getActivity(), selection);
mode.finish();
return true;
}

case R.id.action_cache_remove:
{
List<UUID> selection = getSelection();

try {
App.videoRepository.deleteCachedFiles(selection);
} catch (IOException e) {
e.printStackTrace();
}

mode.finish();
return true;
}

case R.id.action_export_video:
{
ArrayList<Video> videos = getSelectionVideos();
Expand Down Expand Up @@ -268,8 +311,7 @@ public void setVideos(List<UUID> videos) {
}
}

@Subscribe
public void onUploadState(UploadStateEvent event) {
private void onTransferState(TransferStateEvent event) {
UUID videoId = event.getVideoId();

switch (event.getType()) {
Expand All @@ -285,19 +327,39 @@ public void onUploadState(UploadStateEvent event) {
}

@Subscribe
public void onUploadError(UploadErrorEvent event) {
public void onDownloadState(DownloadStateEvent event) {
onTransferState(event);
}

@Subscribe
public void onUploadState(UploadStateEvent event) {
onTransferState(event);
}

private void onTransferError(TransferErrorEvent event, String defaultErrorMessage) {
UUID videoId = event.getVideoId();
String message = event.getErrorMessage();

this.adapter.hideProgress(videoId);

if (message == null) {
message = getString(R.string.upload_error);
message = defaultErrorMessage;
}

SnackbarManager.show(Snackbar.with(getActivity()).text(message));
}

@Subscribe
public void onDownloadError(DownloadErrorEvent event) {
onTransferError(event, getString(R.string.download_error));
}

@Subscribe
public void onUploadError(UploadErrorEvent event) {
onTransferError(event, getString(R.string.upload_error));
}


private List<UUID> getSelection() {
List<Integer> positions = this.adapter.getSelectedItems();
List<UUID> items = new ArrayList<>();
Expand Down Expand Up @@ -350,17 +412,24 @@ private void toggleSelection(int position) {
}

private void showExportFragment(String email, ArrayList<Video> videos) {
ExportDialogFragment.newInstance(email, videos).show(getActivity().getFragmentManager(), "ExportDialog");
ExportDialogFragment.newInstance(email, videos)
.show(getActivity().getFragmentManager(), "ExportDialog");
}

private void updateMenuItems() {
Menu menu = this.actionMode.getMenu();
boolean hasLocal = false;
boolean hasCached = false;
List<UUID> selection = getSelection();

for (UUID id : selection) {
try {
OptimizedVideo video = App.videoRepository.getVideo(id);

if (video.hasCachedFiles()) {
hasCached = true;
}

if (video.isLocal()) {
hasLocal = true;
break;
Expand All @@ -370,15 +439,35 @@ private void updateMenuItems() {
e.printStackTrace();
}
}

MenuItem upload_menu_item = menu.findItem(R.id.action_upload);
MenuItem export_menu_item = menu.findItem(R.id.action_export_video);
MenuItem download_menu_item = menu.findItem(R.id.action_download);
MenuItem cache_remove_item = menu.findItem(R.id.action_cache_remove);
MenuItem share_menu_item = menu.findItem(R.id.action_share_to_group);

if (hasLocal) {
share_menu_item.setVisible(false);
export_menu_item.setVisible(false);
upload_menu_item.setVisible(true);
} else {
share_menu_item.setVisible(true);
export_menu_item.setVisible(true);
upload_menu_item.setVisible(false);
}

if (hasCached || hasLocal) {
download_menu_item.setVisible(false);

} else {
download_menu_item.setVisible(true);
}

if (hasCached) {
cache_remove_item.setVisible(true);
} else {
cache_remove_item.setVisible(false);
}
}

private void showVideo(int position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public class OptimizedVideo {
private String videoUri;
private String thumbUri;
private String deleteUri;

private String cacheThumbUri;
private String cacheVideoUri;

private UUID id;
private String title;
private String tag;
Expand Down Expand Up @@ -113,10 +117,23 @@ public int getRevision() {
public VideoRepository getRepository() {
return this.repository;
}

public void setRepository(VideoRepository repository) {
this.repository = repository;
}

public boolean hasCachedFiles() {
return this.cacheThumbUri != null && this.cacheVideoUri != null;
}

public Uri getCacheThumbUri() {
return Uri.parse(cacheThumbUri);
}

public Uri getCacheVideoUri() {
return Uri.parse(cacheVideoUri);
}

public long getLastModified() {
return lastModified;
}
Expand Down Expand Up @@ -201,12 +218,25 @@ public OptimizedVideo(Video video) {

videoUri = video.getVideoUri().toString();
thumbUri = video.getThumbUri().toString();

if (video.getDeleteUri() != null) {
deleteUri = video.getDeleteUri().toString();
} else {
deleteUri = null;
}

if (video.getCacheVideoUri() != null) {
cacheVideoUri = video.getCacheVideoUri().toString();
} else {
cacheVideoUri = null;
}

if (video.getCacheThumbUri() != null) {
cacheThumbUri = video.getCacheThumbUri().toString();
} else {
cacheThumbUri = null;
}

isTemporary = video.getIsTemporary();
repository = video.getRepository();

Expand Down Expand Up @@ -318,8 +348,21 @@ public Video inflate(PooledVideo pooled) {
video.setManifestUri(null);
}

if (cacheVideoUri != null) {
video.setCacheVideoUri(Uri.parse(cacheVideoUri));
} else {
video.setCacheVideoUri(null);
}

if (cacheThumbUri != null) {
video.setCacheThumbUri(Uri.parse(cacheThumbUri));
} else {
video.setCacheThumbUri(null);
}

video.setVideoUri(Uri.parse(videoUri));
video.setThumbUri(Uri.parse(thumbUri));

if (deleteUri != null) {
video.setDeleteUri(Uri.parse(deleteUri));
} else {
Expand Down
Loading

0 comments on commit 6e5915d

Please sign in to comment.