Skip to content

Commit

Permalink
Added channel id context.
Browse files Browse the repository at this point in the history
  • Loading branch information
camdenfullmer committed May 27, 2017
1 parent 534bd02 commit 8b456a8
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ mClient.getArchivedBroadcasts("YOUR_CHANNEL_ID", new BoxCastCallback<BroadcastLi

```java
mClient = BoxCastClient.getInstance();
mClient.getBroadcast("BROADCAST_ID", new BoxCastCallback<Broadcast>() {
mClient.getBroadcast("CHANNEL_ID", "BROADCAST_ID", new BoxCastCallback<Broadcast>() {

@Override
public void onSuccess(Broadcast result) {
// Do something special with the detailed brodcast.
// Do something special with the detailed broadcast.
}

@Override
Expand All @@ -89,11 +89,11 @@ mClient.getBroadcast("BROADCAST_ID", new BoxCastCallback<Broadcast>() {

```java
mClient = BoxCastClient.getInstance();
mClient.getBroadcast("BROADCAST_ID", new BoxCastCallback<Broadcast>() {
mClient.getBroadcastView("BROADCAST_ID", new BoxCastCallback<Broadcast>() {

@Override
public void onSuccess(Broadcast result) {
// Do something special with the detailed brodcast.
// Do something special with the broadcast view.
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ public void getArchivedBroadcasts(String channelId, final BoxCastCallback<Broadc

/**
* Gets a detailed broadcast.
* @param channelId The channel id.
* @param broadcastId The broadcast id.
* @param callback The callback to be called when finished loading the broadcast.
*/
public void getBroadcast(String broadcastId, final BoxCastCallback<Broadcast> callback) {
public void getBroadcast(final String channelId, String broadcastId, final BoxCastCallback<Broadcast> callback) {
Request request = new Request.Builder()
.url(apiUrl + "/broadcasts/" + broadcastId)
.get()
Expand All @@ -99,7 +100,7 @@ public void onResponse(@NonNull Call call, @NonNull Response response) throws IO
try {
String responseData = response.body().string();
JSONObject object = new JSONObject(responseData);
final Broadcast broadcast = new Broadcast(object);
final Broadcast broadcast = new Broadcast(channelId, object);

runOnUiThread(new Runnable() {
@Override
Expand Down Expand Up @@ -167,7 +168,7 @@ public void run() {
});
}

private void findBroadcasts(String channelId, String query, final BoxCastCallback<BroadcastList> callback) {
private void findBroadcasts(final String channelId, String query, final BoxCastCallback<BroadcastList> callback) {
@SuppressWarnings("ConstantConditions")
HttpUrl url = HttpUrl.parse(apiUrl + "/channels/" + channelId + "/broadcasts")
.newBuilder()
Expand All @@ -193,7 +194,7 @@ public void onResponse(@NonNull Call call, @NonNull Response response) throws IO
try {
String responseData = response.body().string();
JSONArray array = new JSONArray(responseData);
final BroadcastList list = new BroadcastList(array);
final BroadcastList list = new BroadcastList(channelId, array);

runOnUiThread(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public class Broadcast {
private String mChannelId;
private Uri mThumbnailUri;

public Broadcast(JSONObject object) throws JSONException {
public Broadcast(String channelId, JSONObject object) throws JSONException {
mId = object.getString("id");
mName = object.getString("name");
mDescription = object.getString("description");
String thumbnailUriString = object.getString("preview");
mThumbnailUri = Uri.parse(thumbnailUriString);
mChannelId = object.getString("channel_id");
mChannelId = channelId;
if (object.has("account_id")) {
mAccountId = object.getString("account_id");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class BroadcastList {

private ArrayList<Broadcast> mBroadcasts;

public BroadcastList(JSONArray array) throws JSONException {
public BroadcastList(String channelId, JSONArray array) throws JSONException {
mBroadcasts = new ArrayList<>();
for (int i = 0; i < array.length(); ++i) {
JSONObject obj = array.getJSONObject(i);
Broadcast broadcast = new Broadcast(obj);
Broadcast broadcast = new Broadcast(channelId, obj);
mBroadcasts.add(broadcast);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
public class BroadcastActivity extends AppCompatActivity implements View.OnClickListener {

public static final String EXTRA_BROADCAST_ID = "com.boxcast.demo.BROADCAST_ID";
public static final String EXTRA_CHANNEL_ID = "com.boxcast.demo.CHANNEL_ID";

private String mBroadcastId;
private String mChannelId;
private BoxCastClient mClient;
private SimpleDraweeView mImageView;
private TextView mDescriptionTextView;
Expand All @@ -39,9 +41,10 @@ protected void onCreate(Bundle savedInstanceState) {
mPlayButton = (Button) findViewById(R.id.playButton);
mPlayButton.setOnClickListener(this);

// Get the Intent that started this activity and extract the broadcast id.
// Get the Intent that started this activity and extract the broadcast and channel id.
Intent intent = getIntent();
mBroadcastId = intent.getStringExtra(BroadcastActivity.EXTRA_BROADCAST_ID);
mChannelId = intent.getStringExtra(BroadcastActivity.EXTRA_CHANNEL_ID);

mClient = BoxCastClient.getInstance();

Expand All @@ -59,7 +62,7 @@ public boolean onOptionsItemSelected(MenuItem menuItem) {
}

private void loadBroadcast() {
mClient.getBroadcast(mBroadcastId, new BoxCastCallback<Broadcast>() {
mClient.getBroadcast(mChannelId, mBroadcastId, new BoxCastCallback<Broadcast>() {
@Override
public void onSuccess(Broadcast result) {
mBroadcast = result;
Expand All @@ -80,6 +83,7 @@ public void onClick(View v) {
if (v == mPlayButton) {
Intent intent = new Intent(this, MediaPlayerActivity.class);
intent.putExtra(MediaPlayerActivity.EXTRA_BROADCAST_ID, mBroadcast.getId());
intent.putExtra(MediaPlayerActivity.EXTRA_CHANNEL_ID, mBroadcast.getChannelId());
startActivity(intent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void bindBroadcast(Broadcast broadcast) {
public void onClick(View v) {
Intent intent = new Intent(itemView.getContext(), BroadcastActivity.class);
intent.putExtra(BroadcastActivity.EXTRA_BROADCAST_ID, mBroadcast.getId());
intent.putExtra(BroadcastActivity.EXTRA_CHANNEL_ID, mBroadcast.getChannelId());
itemView.getContext().startActivity(intent);
}
}
Expand Down
4 changes: 4 additions & 0 deletions demo/src/main/java/com/boxcast/android/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ protected void onCreate(Bundle savedInstanceState) {
}

void getBroadcasts() {
if (CHANNEL_ID == "YOUR_CHANNEL_ID") {
throw new RuntimeException("change CHANNEL_ID to your actual channel ID");
}

mClient.getLiveBroadcasts(CHANNEL_ID, new BoxCastCallback<BroadcastList>() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
public class MediaPlayerActivity extends AppCompatActivity {

public static final String EXTRA_BROADCAST_ID = "com.boxcast.demo.EXTRA_BROADCAST_ID";
public static final String EXTRA_CHANNEL_ID= "com.boxcast.demo.EXTRA_CHANNEL_ID";

private BoxCastVideoView mVideoView;
private String mBroadcastId;
private String mChannelId;
private BoxCastClient mClient;
private Broadcast mBroadcast;
private BroadcastView mBroadcastView;
Expand All @@ -39,8 +41,9 @@ protected void onCreate(Bundle savedInstanceState) {
controller.setAnchorView(mVideoView);
mVideoView.setMediaController(controller);

// Get the Intent that started this activity and extract the broadcast id.
// Get the Intent that started this activity and extract the broadcast and channel id.
mBroadcastId = getIntent().getStringExtra(MediaPlayerActivity.EXTRA_BROADCAST_ID);
mChannelId = getIntent().getStringExtra(MediaPlayerActivity.EXTRA_CHANNEL_ID);

mClient = BoxCastClient.getInstance();

Expand All @@ -65,7 +68,7 @@ private void play() {
}

private void loadBroadcast() {
mClient.getBroadcast(mBroadcastId, new BoxCastCallback<Broadcast>() {
mClient.getBroadcast(mChannelId, mBroadcastId, new BoxCastCallback<Broadcast>() {
@Override
public void onSuccess(Broadcast result) {
mBroadcast = result;
Expand Down

0 comments on commit 8b456a8

Please sign in to comment.