Skip to content

Commit

Permalink
Merge pull request #86 from learning-layers/integration
Browse files Browse the repository at this point in the history
Release v1.3.6
  • Loading branch information
bqqbarbhg committed Mar 23, 2016
2 parents 4e83878 + b818bd6 commit 9c16fb7
Show file tree
Hide file tree
Showing 18 changed files with 225 additions and 42 deletions.
11 changes: 8 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply from: 'build-helpers.gradle'

android {
compileSdkVersion 23
buildToolsVersion '22.0.0'
buildToolsVersion '23.0.2'

useLibrary 'org.apache.http.legacy'

Expand All @@ -12,6 +12,7 @@ android {
minSdkVersion 16
targetSdkVersion 23
multiDexEnabled true
generatedDensities = []

(versionName, versionCode) = project.getGitVersions()
}
Expand All @@ -20,6 +21,10 @@ android {
javaMaxHeapSize '4g'
}

aaptOptions {
additionalParameters "--no-version-vectors"
}

buildTypes {
release {
minifyEnabled true
Expand Down Expand Up @@ -52,8 +57,8 @@ dependencies {

// Android backwards-compatibility
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.0.1'

// Material design dialogs
Expand Down
14 changes: 6 additions & 8 deletions app/src/main/java/fi/aalto/legroup/achso/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.widget.Toast;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.api.client.repackaged.com.google.common.base.Strings;
import com.rollbar.android.Rollbar;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.otto.Bus;
Expand All @@ -36,6 +35,7 @@
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;

public final class App extends MultiDexApplication
Expand Down Expand Up @@ -254,16 +254,14 @@ public static void setupUploaders(Context context) {
combinedRepository.addHost(achRails);
combinedRepository.setCacheRoot(makeCacheVideoDirectory());

// Temporary uploader until ClViTra2 is fixed in the Layers Box
// TODO: Remove this
String achsoStorageUrlString = context.getString(R.string.achsoStorageUrl);
if (!Strings.isNullOrEmpty(achsoStorageUrlString)) {
UploadService.addUploader(new DumbPhpStrategy(getAchsoStorageUrl(context)));
// HACK: Use Achminup for uploading for now
if (usePublicLayersBox) {
UploadService.addUploader(new DumbPhpStrategy(getAchsoStorageUrl(context), false));
} else {
UploadService.addUploader(new GoViTraStrategy(jsonSerializer, getAchsoStorageUrl(context)));
}

Uri clViTra2Url = Uri.parse(context.getString(R.string.clvitra2Url));
Uri sssUrl = Uri.parse(context.getString(R.string.sssUrl));

ClViTra2Strategy videoStrategy = new ClViTra2Strategy(clViTra2Url);

UploadService.addUploader(videoStrategy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public String getBearerToken(Account account) {
AccountManager accountManager = AccountManager.get(context);
String token = null;

// Try retrieving an ID token from the account manager
// Try retrieving an access token from the account manager
try {
token = accountManager.blockingGetAuthToken(account, Authenticator.TOKEN_TYPE_ID, true);
token = accountManager.blockingGetAuthToken(account, Authenticator.TOKEN_TYPE_ACCESS, true);
} catch (Exception e) {
Log.e(TAG, "Could not get ID token from account: " + e.getMessage());
Log.e(TAG, "Could not get access token from account: " + e.getMessage());
e.printStackTrace();
}
return token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.webkit.CookieManager;
import android.webkit.ValueCallback;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

Expand Down Expand Up @@ -64,11 +68,15 @@ protected void onCreate(Bundle savedInstanceState) {
account = extras.getParcelable(KEY_ACCOUNT_OBJECT);

// Fetch the authentication URL that was given to us by the calling activity
String authUrl = extras.getString(KEY_AUTH_URL);
final String authUrl = extras.getString(KEY_AUTH_URL);

// Initialise the WebView
WebView webView = (WebView) findViewById(R.id.WebView);

// JavaScript needs to be enabled for some OAuth2 providers
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);

final Context context = this;
webView.setWebViewClient(new WebViewClient() {
@Override
Expand All @@ -78,6 +86,10 @@ public void onPageStarted(WebView view, String urlString, Bitmap favicon) {
Uri url = Uri.parse(urlString);
Set<String> parameterNames = url.getQueryParameterNames();

// Our redirect URL:s must start with app://
if (!url.getScheme().equals("app"))
return;

// The URL will contain a `code` parameter when the user has been authenticated
if (parameterNames.contains("code")) {
// We won't need to keep loading anymore. This also prevents errors when using
Expand Down Expand Up @@ -107,14 +119,33 @@ public void onPageStarted(WebView view, String urlString, Bitmap favicon) {
// message.
//
// TODO: Read error codes and provide a more helpful error message
if ( ! error.equals("access_denied")) {
if (!error.equals("access_denied")) {
showErrorDialog(String.format("Error code: %s\n\n%s", error,
errorDescription));
}
}
}
});

// Delete cookies before authenticating to give the user a chance to switch accounts.
// NOTE: This affects all the cookies in this app globally, if we want to store some other
// WebView session data that should not be removed should be more careful here.
CookieManager cookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.removeAllCookies(new ValueCallback<Boolean>() {
@Override
public void onReceiveValue(Boolean value) {
postCookiesDeleted(authUrl);
}
});
} else {
cookieManager.removeAllCookie();
postCookiesDeleted(authUrl);
}
}

private void postCookiesDeleted(String authUrl) {
WebView webView = (WebView) findViewById(R.id.WebView);
webView.loadUrl(authUrl);
}

Expand Down Expand Up @@ -204,21 +235,23 @@ private void createAccount(IdTokenResponse response) {
e.printStackTrace();
}

// Get the user information so we can grab the `preferred_username`
// Get the user information so we can grab the `preferred_username` or `name`
JsonObject userInfo = new JsonObject();

try {
userInfo = OIDCUtils.getUserInfo(OIDCConfig.getUserInfoUrl(this), response.getIdToken());
userInfo = OIDCUtils.getUserInfo(OIDCConfig.getUserInfoUrl(this), response.getAccessToken());
} catch (IOException e) {
Log.e(TAG, "Could not get UserInfo.");
e.printStackTrace();
}

if (userInfo.has("preferred_username")) {
accountName = userInfo.get("preferred_username").getAsString();
} else if (userInfo.has("name")) {
accountName = userInfo.get("name").getAsString();
}

account = new Account(String.format("%s (%s)", accountName, App.getLayersBoxUrl()), Authenticator.ACH_SO_ACCOUNT_TYPE);
account = new Account(String.format("%s (%s) [%s]", accountName, App.getLayersBoxUrl(), accountId), Authenticator.ACH_SO_ACCOUNT_TYPE);
accountManager.addAccountExplicitly(account, null, null);

// Store the tokens in the account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ public static boolean isValidIdToken(String clientId, String tokenString) throws
/**
* Gets user information from the UserInfo endpoint.
*/
public static JsonObject getUserInfo(String userInfoUrl, String idToken) throws IOException {
public static JsonObject getUserInfo(String userInfoUrl, String accessToken) throws IOException {
Request request = new Request.Builder()
.url(userInfoUrl)
.header("Accept", "application/json")
.header("Authorization", "Bearer " + idToken)
.header("Authorization", "Bearer " + accessToken)
.get()
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import fi.aalto.legroup.achso.settings.SettingsActivity;
import fi.aalto.legroup.achso.sharing.SharingActivity;
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.utilities.BaseActivity;
Expand Down Expand Up @@ -520,6 +521,11 @@ public void onVideoCreationState(VideoCreatorService.VideoCreationStateEvent eve
}
}

@Subscribe
public void onSyncRequired(SyncRequiredEvent event) {
SyncService.syncWithCloudStorage(this);
}

@Override
public void onRefresh() {
// @Note: This won't be called currently since pull to refresh is disabled (see
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class OptimizedVideo {

private String videoUri;
private String thumbUri;
private String deleteUri;
private UUID id;
private String title;
private String genre;
Expand Down Expand Up @@ -200,6 +201,11 @@ public OptimizedVideo(Video video) {
manifestUri = video.getManifestUri().toString();
videoUri = video.getVideoUri().toString();
thumbUri = video.getThumbUri().toString();
if (video.getDeleteUri() != null) {
deleteUri = video.getDeleteUri().toString();
} else {
deleteUri = null;
}

repository = video.getRepository();

Expand Down Expand Up @@ -313,6 +319,11 @@ public Video inflate(PooledVideo pooled) {
video.setManifestUri(Uri.parse(manifestUri));
video.setVideoUri(Uri.parse(videoUri));
video.setThumbUri(Uri.parse(thumbUri));
if (deleteUri != null) {
video.setDeleteUri(Uri.parse(deleteUri));
} else {
video.setDeleteUri(null);
}

video.setRepository(repository);
video.setId(id);
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/fi/aalto/legroup/achso/entities/Video.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Video implements JsonSerializable {

protected Uri videoUri;
protected Uri thumbUri;
protected Uri deleteUri;
protected UUID id;
protected String title;
protected String genre;
Expand Down Expand Up @@ -233,4 +234,12 @@ public int getFormatVersion() {
public void setFormatVersion(int formatVersion) {
this.formatVersion = formatVersion;
}

public void setDeleteUri(Uri deleteUri) {
this.deleteUri = deleteUri;
}

public Uri getDeleteUri() {
return deleteUri;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import fi.aalto.legroup.achso.entities.VideoReference;
import fi.aalto.legroup.achso.entities.migration.VideoMigration;
import fi.aalto.legroup.achso.entities.serialization.json.JsonSerializer;
import fi.aalto.legroup.achso.storage.remote.SyncRequiredEvent;
import fi.aalto.legroup.achso.storage.remote.SyncService;
import fi.aalto.legroup.achso.storage.remote.VideoHost;

public class CombinedVideoRepository implements VideoRepository {
Expand Down Expand Up @@ -535,6 +537,31 @@ protected Video doInBackground(UUID... params) {
}
}

private class DeleteVideoTask extends AsyncTask<UUID, Void, Void> {

@Override
protected Void doInBackground(UUID... params) {

for (UUID id : params) {
for (VideoHost host : cloudHosts) {
try {
host.deleteVideoManifest(id);
} catch (IOException e) {
e.printStackTrace();
}
}
}

return null;
}

@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
bus.post(new SyncRequiredEvent(CombinedVideoRepository.this));
}
}

@Override
public void delete(UUID id) throws IOException {
OptimizedVideo video = getVideo(id);
Expand All @@ -552,14 +579,14 @@ public void delete(UUID id) throws IOException {
// Doesn't matter if these fail, not necessary operation
thumbFile.delete();
videoFile.delete();

// Remove the video from memory, if deleting has failed we have thrown before this
allVideos.remove(id);
bus.post(new VideoRepositoryUpdatedEvent(this));

} else {
// TODO: Delete shared file
throw new IOException("Can't delete remote file");
new DeleteVideoTask().execute(id);
}

// Remove the video from memory, if deleting has failed we have thrown before this
allVideos.remove(id);
bus.post(new VideoRepositoryUpdatedEvent(this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fi.aalto.legroup.achso.storage.remote;

import fi.aalto.legroup.achso.storage.VideoRepository;

public class SyncRequiredEvent {
private final VideoRepository repository;

public SyncRequiredEvent(VideoRepository repository) {
this.repository = repository;
}

public VideoRepository getRepository() {
return repository;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private boolean tryUpload(Video video) {
return false;
}
video.setVideoUri(videoResult.videoUrl);
video.setDeleteUri(videoResult.deleteUrl);

Uri thumbUrl = null;
if (videoResult.thumbUrl != null) {
Expand Down Expand Up @@ -159,7 +160,8 @@ private boolean tryUpload(Video video) {

// The uploaded video will have normalized rotation after transcoding, so clear the hacky
// rotation compensation property.
video.setRotation(0);
if (videoResult.didNormalizeRotation)
video.setRotation(0);

try {
// Upload the video manifest.
Expand Down
Loading

0 comments on commit 9c16fb7

Please sign in to comment.