From 8b456a85cc2faba5c6fe74f0fee81fe362d9f5b5 Mon Sep 17 00:00:00 2001 From: Camden Fullmer Date: Sat, 27 May 2017 13:06:44 -0400 Subject: [PATCH] Added channel id context. --- README.md | 8 ++++---- .../src/main/java/com/boxcast/android/BoxCastClient.java | 9 +++++---- .../main/java/com/boxcast/android/model/Broadcast.java | 4 ++-- .../java/com/boxcast/android/model/BroadcastList.java | 4 ++-- .../java/com/boxcast/android/demo/BroadcastActivity.java | 8 ++++++-- .../java/com/boxcast/android/demo/BroadcastsAdapter.java | 1 + .../main/java/com/boxcast/android/demo/MainActivity.java | 4 ++++ .../com/boxcast/android/demo/MediaPlayerActivity.java | 7 +++++-- 8 files changed, 29 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a3d2dae..436c44f 100644 --- a/README.md +++ b/README.md @@ -70,11 +70,11 @@ mClient.getArchivedBroadcasts("YOUR_CHANNEL_ID", new BoxCastCallback() { +mClient.getBroadcast("CHANNEL_ID", "BROADCAST_ID", new BoxCastCallback() { @Override public void onSuccess(Broadcast result) { - // Do something special with the detailed brodcast. + // Do something special with the detailed broadcast. } @Override @@ -89,11 +89,11 @@ mClient.getBroadcast("BROADCAST_ID", new BoxCastCallback() { ```java mClient = BoxCastClient.getInstance(); -mClient.getBroadcast("BROADCAST_ID", new BoxCastCallback() { +mClient.getBroadcastView("BROADCAST_ID", new BoxCastCallback() { @Override public void onSuccess(Broadcast result) { - // Do something special with the detailed brodcast. + // Do something special with the broadcast view. } @Override diff --git a/boxcast-sdk/src/main/java/com/boxcast/android/BoxCastClient.java b/boxcast-sdk/src/main/java/com/boxcast/android/BoxCastClient.java index 9062112..b1e8b3e 100644 --- a/boxcast-sdk/src/main/java/com/boxcast/android/BoxCastClient.java +++ b/boxcast-sdk/src/main/java/com/boxcast/android/BoxCastClient.java @@ -75,10 +75,11 @@ public void getArchivedBroadcasts(String channelId, final BoxCastCallback callback) { + public void getBroadcast(final String channelId, String broadcastId, final BoxCastCallback callback) { Request request = new Request.Builder() .url(apiUrl + "/broadcasts/" + broadcastId) .get() @@ -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 @@ -167,7 +168,7 @@ public void run() { }); } - private void findBroadcasts(String channelId, String query, final BoxCastCallback callback) { + private void findBroadcasts(final String channelId, String query, final BoxCastCallback callback) { @SuppressWarnings("ConstantConditions") HttpUrl url = HttpUrl.parse(apiUrl + "/channels/" + channelId + "/broadcasts") .newBuilder() @@ -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 diff --git a/boxcast-sdk/src/main/java/com/boxcast/android/model/Broadcast.java b/boxcast-sdk/src/main/java/com/boxcast/android/model/Broadcast.java index 2bdfeb1..fc34b8d 100644 --- a/boxcast-sdk/src/main/java/com/boxcast/android/model/Broadcast.java +++ b/boxcast-sdk/src/main/java/com/boxcast/android/model/Broadcast.java @@ -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"); } diff --git a/boxcast-sdk/src/main/java/com/boxcast/android/model/BroadcastList.java b/boxcast-sdk/src/main/java/com/boxcast/android/model/BroadcastList.java index 3891caf..f0a3244 100644 --- a/boxcast-sdk/src/main/java/com/boxcast/android/model/BroadcastList.java +++ b/boxcast-sdk/src/main/java/com/boxcast/android/model/BroadcastList.java @@ -18,11 +18,11 @@ public class BroadcastList { private ArrayList 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); } } diff --git a/demo/src/main/java/com/boxcast/android/demo/BroadcastActivity.java b/demo/src/main/java/com/boxcast/android/demo/BroadcastActivity.java index 53f3d0e..09a27a9 100644 --- a/demo/src/main/java/com/boxcast/android/demo/BroadcastActivity.java +++ b/demo/src/main/java/com/boxcast/android/demo/BroadcastActivity.java @@ -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; @@ -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(); @@ -59,7 +62,7 @@ public boolean onOptionsItemSelected(MenuItem menuItem) { } private void loadBroadcast() { - mClient.getBroadcast(mBroadcastId, new BoxCastCallback() { + mClient.getBroadcast(mChannelId, mBroadcastId, new BoxCastCallback() { @Override public void onSuccess(Broadcast result) { mBroadcast = result; @@ -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); } } diff --git a/demo/src/main/java/com/boxcast/android/demo/BroadcastsAdapter.java b/demo/src/main/java/com/boxcast/android/demo/BroadcastsAdapter.java index 2861865..ff5e780 100644 --- a/demo/src/main/java/com/boxcast/android/demo/BroadcastsAdapter.java +++ b/demo/src/main/java/com/boxcast/android/demo/BroadcastsAdapter.java @@ -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); } } diff --git a/demo/src/main/java/com/boxcast/android/demo/MainActivity.java b/demo/src/main/java/com/boxcast/android/demo/MainActivity.java index c05a6d8..e9d1107 100644 --- a/demo/src/main/java/com/boxcast/android/demo/MainActivity.java +++ b/demo/src/main/java/com/boxcast/android/demo/MainActivity.java @@ -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() { @Override diff --git a/demo/src/main/java/com/boxcast/android/demo/MediaPlayerActivity.java b/demo/src/main/java/com/boxcast/android/demo/MediaPlayerActivity.java index a6c3c51..a2f45e3 100644 --- a/demo/src/main/java/com/boxcast/android/demo/MediaPlayerActivity.java +++ b/demo/src/main/java/com/boxcast/android/demo/MediaPlayerActivity.java @@ -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; @@ -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(); @@ -65,7 +68,7 @@ private void play() { } private void loadBroadcast() { - mClient.getBroadcast(mBroadcastId, new BoxCastCallback() { + mClient.getBroadcast(mChannelId, mBroadcastId, new BoxCastCallback() { @Override public void onSuccess(Broadcast result) { mBroadcast = result;