Skip to content

Commit

Permalink
Merge pull request #27 from learning-layers/integration
Browse files Browse the repository at this point in the history
Release v1.0.2.
  • Loading branch information
lnikkila committed Jan 20, 2015
2 parents d921aba + 7954a92 commit 13d2574
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@
import fi.aalto.legroup.achso.views.adapters.VideoGridAdapter;
import fi.aalto.legroup.achso.views.utilities.DimensionUnits;

public class BrowserFragment extends Fragment implements ActionMode.Callback,
public final class BrowserFragment extends Fragment implements ActionMode.Callback,
RecyclerItemClickListener.OnItemClickListener {

private List<UUID> videos = Collections.emptyList();

private RecyclerView grid;
private TextView placeHolder;

private VideoGridAdapter adapter;
private GridLayoutManager layoutManager;
private ActionMode actionMode;

public static BrowserFragment newInstance(List<UUID> videos) {
Expand Down Expand Up @@ -79,20 +77,22 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

this.placeHolder = (TextView) view.findViewById(R.id.place_holder);
this.grid = (RecyclerView) view.findViewById(R.id.video_list);
RecyclerView grid = (RecyclerView) view.findViewById(R.id.video_list);

// Default span count is 1, will be recalculated with the layout
this.layoutManager = new GridLayoutManager(getActivity(), 1);
// Default span count is 1
GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), 1);

this.adapter = new VideoGridAdapter(getActivity(), App.videoInfoRepository);
this.adapter.registerAdapterDataObserver(new PlaceholderDataObserver());
this.adapter.setItems(videos);

this.grid.setHasFixedSize(true);
this.grid.setAdapter(this.adapter);
this.grid.setLayoutManager(this.layoutManager);
this.grid.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), this));
this.grid.getViewTreeObserver().addOnGlobalLayoutListener(new GridOnLayoutChangeListener());
grid.setHasFixedSize(true);
grid.setAdapter(this.adapter);
grid.setLayoutManager(layoutManager);
grid.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), this));

// This listener sets the span count on layout and then stops listening.
new GridOnLayoutChangeListener(grid);
}

@Override
Expand Down Expand Up @@ -259,7 +259,7 @@ private void startActionMode() {
/**
* Shows or hides the placeholder text appropriately when the adapter items change.
*/
private final class PlaceholderDataObserver extends RecyclerView.AdapterDataObserver {
private class PlaceholderDataObserver extends RecyclerView.AdapterDataObserver {

@Override
public void onChanged() {
Expand All @@ -280,10 +280,18 @@ public void onChanged() {
/**
* Calculates the number of columns when the grid's layout bounds change.
*/
private final class GridOnLayoutChangeListener implements ViewTreeObserver.OnGlobalLayoutListener {
private static class GridOnLayoutChangeListener
implements ViewTreeObserver.OnGlobalLayoutListener {

private static final int MINIMUM_ITEM_WIDTH_DP = 250;

private RecyclerView grid;

private GridOnLayoutChangeListener(RecyclerView grid) {
this.grid = grid;
grid.getViewTreeObserver().addOnGlobalLayoutListener(this);
}

@Override
public void onGlobalLayout() {
int gridWidth = grid.getWidth();
Expand All @@ -294,7 +302,19 @@ public void onGlobalLayout() {
if (spanCount < 1) {
spanCount = 1;
}
layoutManager.setSpanCount(spanCount);

RecyclerView.LayoutManager layoutManager = grid.getLayoutManager();

if (layoutManager instanceof GridLayoutManager) {
((GridLayoutManager) layoutManager).setSpanCount(spanCount);

// Workaround for an upstream GridLayoutManager issue:
// https://code.google.com/p/android/issues/detail?id=93710
grid.requestLayout();
}

// This listener needs to be removed to avoid an infinite loop due to the workaround.
grid.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
/**
* Handles view logic for the video player controls. Actual playback is handled by
* VideoPlayerFragment.
* <p/>
*
* TODO: Extract annotation editing into a separate fragment.
*/
public final class VideoPlayerActivity extends ActionBarActivity implements AnnotationEditor,
Expand Down Expand Up @@ -202,31 +202,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}


@Subscribe
public void onExportCreatorTaskResult(ExportCreatorTaskResultEvent event) {
List<Uri> uris = event.getResult();

if (uris == null || uris.isEmpty()) {
App.showError(R.string.error_sharing);
return;
}

Intent intent;

if (uris.size() == 1) {
intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));
} else {
intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, new ArrayList<>(uris));
}

intent.setType("application/achso");

startActivity(Intent.createChooser(intent, getString(R.string.video_share)));
}

/**
* Called when a view with this listener is clicked.
*/
Expand Down Expand Up @@ -268,7 +243,9 @@ public void togglePlayback() {
private void anchorSubtitleContainerTo(View view) {
int height = 0;

if (view != null) height = view.getHeight();
if (view != null) {
height = view.getHeight();
}

playerFragment.getSubtitleContainer().setPadding(0, 0, 0, height);
}
Expand All @@ -293,11 +270,11 @@ private void hideControlsOverlay() {
@Override
public void run() {
// Don't hide if we're paused
if (playerFragment.getState() == VideoPlayerFragment.State.PAUSED) return;

if (playerFragment.getState() == VideoPlayerFragment.State.PAUSED) {
return;
}

toolbar.animate().translationY(-toolbar.getHeight()).setDuration(
CONTROLS_ANIMATION_DURATION).start();
toolbar.animate().alpha(0).setDuration(CONTROLS_ANIMATION_DURATION).start();
controlsOverlay.animate().alpha(0).setDuration(CONTROLS_ANIMATION_DURATION).start();

anchorSubtitleContainerTo(null);
Expand All @@ -320,7 +297,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@Override
public void createAnnotation(PointF position) {
// Allow creating annotations only when paused
if (playerFragment.getState() != VideoPlayerFragment.State.PAUSED) return;
if (playerFragment.getState() != VideoPlayerFragment.State.PAUSED) {
return;
}

long time = playerFragment.getPlaybackPosition();

Expand Down Expand Up @@ -456,7 +435,9 @@ public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) {

elapsedTimeText.setText(elapsedTimeString);

if (fromUser) playerFragment.seekTo(progress);
if (fromUser) {
playerFragment.seekTo(progress);
}
}

/**
Expand Down Expand Up @@ -500,6 +481,30 @@ public boolean dispatchTouchEvent(@Nonnull MotionEvent event) {
return super.dispatchTouchEvent(event);
}

@Subscribe
public void onExportCreatorTaskResult(ExportCreatorTaskResultEvent event) {
List<Uri> uris = event.getResult();

if (uris == null || uris.isEmpty()) {
App.showError(R.string.error_sharing);
return;
}

Intent intent;

if (uris.size() == 1) {
intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));
} else {
intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, new ArrayList<>(uris));
}

intent.setType("application/achso");

startActivity(Intent.createChooser(intent, getString(R.string.video_share)));
}

private final class SeekBarUpdater extends RepeatingTask {

// How often the seek bar should be updated (in milliseconds)
Expand All @@ -512,7 +517,6 @@ public SeekBarUpdater() {
@Override
protected void doWork() {
int progress = (int) playerFragment.getPlaybackPosition();

animateTo(progress);
}

Expand All @@ -531,5 +535,4 @@ private void animateTo(int progress) {

}


}

0 comments on commit 13d2574

Please sign in to comment.