share feature

This commit is contained in:
danijoo
2015-11-01 00:06:38 +01:00
parent 1f1d3ee57b
commit f8cf189d70
9 changed files with 41 additions and 0 deletions

View File

@@ -10,6 +10,9 @@ import android.support.v4.app.Fragment;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
@@ -65,6 +68,7 @@ public class MovieDetailsFragment extends Fragment implements Callback<VideoList
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
if(getArguments().containsKey(BUNDLE_ARG_MOVIE)) { if(getArguments().containsKey(BUNDLE_ARG_MOVIE)) {
mMovie = getArguments().getParcelable(BUNDLE_ARG_MOVIE); mMovie = getArguments().getParcelable(BUNDLE_ARG_MOVIE);
Log.d(TAG, "Bundled movie: " + mMovie.getTitle()); Log.d(TAG, "Bundled movie: " + mMovie.getTitle());
@@ -157,6 +161,38 @@ public class MovieDetailsFragment extends Fragment implements Callback<VideoList
} }
} }
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.movie_details_menu, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == R.id.action_share) {
shareTrailer();
return true;
}
else
return super.onOptionsItemSelected(item);
}
/**
* Fires an intent to share the trailer url of this movie
* Code from http://www.techrepublic.com/blog/software-engineer/get-social-using-android-intents-to-share-a-link/
*/
private void shareTrailer() {
if(mVideoList == null || mVideoList.getVideos().size() == 0)
Toast.makeText(getActivity(), "Nothing to share. :(", Toast.LENGTH_SHORT).show();
else {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_TEXT, "https://youtu.be/" + mVideoList.getVideos().get(0).getKey());
i.putExtra(Intent.EXTRA_SUBJECT, "Check out this movie!");
startActivity(Intent.createChooser(i, "Share"));
}
}
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
if(mVideoList != null) if(mVideoList != null)

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 883 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:icon="@drawable/ic_action_share" android:id="@+id/action_share" android:title="Share" app:showAsAction="ifRoom" />
</menu>