Skip to content

Commit

Permalink
Merge pull request #93 from learning-layers/integration
Browse files Browse the repository at this point in the history
v1.4.2 — “The Secret Six"
  • Loading branch information
melonmanchan committed May 20, 2016
2 parents 665b757 + 3ed0061 commit ba4e3b4
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public final class BrowserActivity extends BaseActivity implements View.OnClickL
private VideoTabAdapter tabAdapter;
private MenuItem searchItem;
private SwipeRefreshLayout swipeRefreshLayout;
private ViewPager viewPager;

private PendingRepositoryUpdateListener pendingListener = new PendingRepositoryUpdateListener();

Expand Down Expand Up @@ -135,11 +136,12 @@ protected void onCreate(Bundle savedInstanceState) {
// expects pendingListener to be registered)
bus.register(pendingListener);

ViewPager pager = (ViewPager) findViewById(R.id.pager);
viewPager = (ViewPager) findViewById(R.id.pager);
PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.toolbar_tabs);

pager.setAdapter(this.tabAdapter);
tabs.setViewPager(pager);
viewPager.setAdapter(this.tabAdapter);
tabs.setViewPager(viewPager);


swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipe_refresh);
swipeRefreshLayout.setOnRefreshListener(this);
Expand Down Expand Up @@ -272,6 +274,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;

case R.id.action_logout:
// Go back to the 'All videos' tab since we're logging out!
// TODO: Disable user tapping the tabs after log out has not completed fully!
viewPager.setCurrentItem(0);
bus.post(new LoginRequestEvent(LoginRequestEvent.Type.EXPLICIT_LOGOUT));
return true;

Expand Down
13 changes: 13 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 @@ -7,6 +7,7 @@
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern;

import fi.aalto.legroup.achso.entities.serialization.json.JsonSerializable;
import fi.aalto.legroup.achso.storage.VideoRepository;
Expand All @@ -26,6 +27,8 @@ public class Video implements JsonSerializable {
protected transient Uri manifestUri;
protected transient VideoRepository repository;
protected transient Date lastModified;
protected static final Pattern uuidPattern = Pattern.compile("");


protected Uri videoUri;
protected Uri thumbUri;
Expand Down Expand Up @@ -232,4 +235,14 @@ public void setDeleteUri(Uri deleteUri) {
public Uri getDeleteUri() {
return deleteUri;
}

public static boolean isStringValidVideoID(String IDCandidate) {
try {
UUID test = UUID.fromString(IDCandidate);
return true;
} catch(IllegalArgumentException iaex) {
return false;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public final class PlayerActivity extends ActionBarActivity implements Annotatio
// Can be either a ViewStub or an inflated LinearLayout
private View annotationControls;

private long lastAnnotationCreateTime = -6666;
private ImageButton playPauseButton;
private TextView elapsedTimeText;
private MarkedSeekBar seekBar;
Expand Down Expand Up @@ -354,7 +355,7 @@ public void createAnnotation(PointF position) {
if (playerFragment.getState() == PlayerFragment.State.ANNOTATION_PAUSED) {
return;

} else if (playerFragment.getState() != PlayerFragment.State.PAUSED) {
} if (playerFragment.getState() != PlayerFragment.State.PAUSED) {
playerFragment.pause();
playerFragment.setState(PlayerFragment.State.PAUSED);
}
Expand All @@ -364,7 +365,7 @@ public void createAnnotation(PointF position) {
}

long time = playerFragment.getPlaybackPosition();

lastAnnotationCreateTime = time;

Date now = new Date();
Annotation annotation = new Annotation(time, position, "", App.loginManager.getUser(), now);
Expand Down Expand Up @@ -507,6 +508,10 @@ public void onPlaybackStateChanged(PlayerFragment.State state) {
break;

case PAUSED:
if (lastAnnotationCreateTime != -6666) {
playerFragment.seekTo(lastAnnotationCreateTime);
lastAnnotationCreateTime = -6666;
}
showControlsOverlay();
playPauseButton.setImageResource(R.drawable.ic_action_play);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.support.v7.app.AlertDialog;
import android.webkit.CookieManager;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
Expand All @@ -31,6 +32,7 @@
import com.google.common.base.Strings;
import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager;
import com.rollbar.android.Rollbar;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -44,6 +46,8 @@
import fi.aalto.legroup.achso.R;
import fi.aalto.legroup.achso.app.App;
import fi.aalto.legroup.achso.authentication.Authenticator;
import fi.aalto.legroup.achso.playback.PlayerActivity;
import fi.aalto.legroup.achso.entities.Video;

public class SharingActivity extends Activity {

Expand Down Expand Up @@ -123,6 +127,12 @@ public void run(String token, String refreshToken) {
return true;
}

public void openVideoActivity(UUID videoID) {
Intent detailIntent = new Intent(this, PlayerActivity.class);
detailIntent.putExtra(PlayerActivity.ARG_VIDEO_ID, videoID);
startActivity(detailIntent);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -142,8 +152,32 @@ protected void onCreate(Bundle savedInstanceState) {
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String urlToLoad) {
try {
String[] pathParts = urlToLoad.split("/");
String possibleUUID = pathParts[pathParts.length - 1];
if (urlToLoad.contains("videos") && Video.isStringValidVideoID(possibleUUID)) {
UUID videoId = UUID.fromString(possibleUUID);
if (App.videoRepository.doesVideoExist(videoId)) {
openVideoActivity(videoId);
return true;
} else {
return false;
}
} else {
return false;
}
} catch(Exception ex) {
Rollbar.reportException(ex);
return false;
}
}
});

webView.setWebChromeClient(new WebChromeClient());

achRailsJavascriptInterface = new AchRailsJavascriptInterface(this);

webView.addJavascriptInterface(achRailsJavascriptInterface, "Android");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,16 @@ public OptimizedVideo getVideo(UUID id) throws IOException {
return video;
}

@Override
public boolean doesVideoExist(UUID id) {
try {
getVideo(id);
return true;
} catch (IOException ex) {
return false;
}
}

@Override
public void forceNextSyncImportant() {
forceImportant = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ interface VideoCallback {
*/
public void findVideoByVideoUri(Uri videoUri, String type, VideoCallback callback);

/**
* Checks whether video storage contains a video with a certain ID.
*/
public boolean doesVideoExist(UUID id);

/**
* Migrate all videos to the current format version.
*/
Expand Down

0 comments on commit ba4e3b4

Please sign in to comment.