Skip to content

Commit 24105ad

Browse files
committed
Channels section: open channel fix; upd MediaServiceCore
1 parent aa88ce2 commit 24105ad

File tree

6 files changed

+66
-41
lines changed

6 files changed

+66
-41
lines changed

common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/ChannelPresenter.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,13 @@ private void extractChannelId(Video item, OnChannelId callback) {
312312
callback.onChannelId(item.channelId);
313313
} else if (item.videoId != null) {
314314
LoadingManager.showLoading(getContext(), true);
315-
//MessageHelpers.showMessage(getContext(), R.string.wait_data_loading);
316315
getServiceManager().loadMetadata(item, metadata -> {
317316
LoadingManager.showLoading(getContext(), false);
318317
callback.onChannelId(metadata.getChannelId());
319318
item.channelId = metadata.getChannelId();
320-
});
319+
},
320+
e -> LoadingManager.showLoading(getContext(), false),
321+
() -> LoadingManager.showLoading(getContext(), false));
321322
} else if (item.belongsToChannelUploads()) {
322323
LoadingManager.showLoading(getContext(), true);
323324
// Maybe this is subscribed items view
@@ -329,7 +330,12 @@ private void extractChannelId(Video item, OnChannelId callback) {
329330
if (group.getChannelId() == null) {
330331
List<MediaItem> mediaItems = group.getMediaItems();
331332

332-
if (mediaItems != null && mediaItems.size() > 0) {
333+
// Filter collaborative items
334+
MediaItem first = Helpers.findFirst(mediaItems, mediaItem -> Helpers.startsWith(mediaItem.getAuthor(), item.getAuthor()));
335+
336+
if (first != null) {
337+
extractChannelId(Video.from(first), callback);
338+
} else if (mediaItems != null && !mediaItems.isEmpty()) {
333339
extractChannelId(Video.from(mediaItems.get(0)), callback);
334340
}
335341

@@ -338,7 +344,9 @@ private void extractChannelId(Video item, OnChannelId callback) {
338344

339345
callback.onChannelId(group.getChannelId());
340346
item.channelId = group.getChannelId();
341-
});
347+
},
348+
e -> LoadingManager.showLoading(getContext(), false),
349+
() -> LoadingManager.showLoading(getContext(), false));
342350
}
343351
}
344352
}

common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/ChannelUploadsPresenter.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
import com.liskovsoft.smartyoutubetv2.common.app.views.ChannelUploadsView;
2424
import com.liskovsoft.smartyoutubetv2.common.misc.BrowseProcessorManager;
2525
import com.liskovsoft.smartyoutubetv2.common.misc.MediaServiceManager;
26+
import com.liskovsoft.smartyoutubetv2.common.misc.MediaServiceManager.OnComplete;
27+
import com.liskovsoft.smartyoutubetv2.common.misc.MediaServiceManager.OnError;
28+
import com.liskovsoft.smartyoutubetv2.common.misc.MediaServiceManager.OnMediaGroup;
29+
2630
import io.reactivex.Observable;
2731
import io.reactivex.disposables.Disposable;
2832

@@ -145,9 +149,13 @@ public void openChannel(Video item) {
145149
}
146150
}
147151

148-
public void obtainGroup(Video item, VideoGroupCallback callback) {
152+
public void obtainGroup(Video item, OnMediaGroup callback) {
153+
obtainGroup(item, callback, null, null);
154+
}
155+
156+
public void obtainGroup(Video item, OnMediaGroup callback, OnError onError, OnComplete onComplete) {
149157
if (item != null && item.mediaItem != null) {
150-
obtainGroup(item.mediaItem, callback);
158+
obtainGroup(item.mediaItem, callback, onError, onComplete);
151159
}
152160
}
153161

@@ -283,25 +291,28 @@ private void update(VideoGroup group) {
283291
}
284292
}
285293

286-
private void obtainGroup(MediaItem mediaItem, VideoGroupCallback callback) {
294+
private void obtainGroup(MediaItem mediaItem, OnMediaGroup callback, OnError onError, OnComplete onComplete) {
287295
Log.d(TAG, "obtainGroup: Start loading group...");
288296

289297
disposeActions();
290298

291-
//Observable<MediaGroup> group = getContentService().getGroupObserve(mediaItem);
292-
293-
//mUpdateAction = group
294299
mUpdateAction = obtainUploadsObservable(Video.from(mediaItem))
295300
.subscribe(
296-
callback::onGroup,
297-
error -> Log.e(TAG, "obtainGroup error: %s", error.getMessage())
301+
callback::onMediaGroup,
302+
error -> {
303+
Log.e(TAG, "obtainGroup error: %s", error.getMessage());
304+
if (onError != null) {
305+
onError.onError(error);
306+
}
307+
},
308+
() -> {
309+
if (onComplete != null) {
310+
onComplete.onComplete();
311+
}
312+
}
298313
);
299314
}
300315

301-
public interface VideoGroupCallback {
302-
void onGroup(MediaGroup mediaGroup);
303-
}
304-
305316
/**
306317
* Playlist usually is the first row with media items.<br/>
307318
* NOTE: before playlist may be the video description row

common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/dialogs/VideoActionPresenter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ private void startFistPlaylistItem(Video item) {
5454
if (!mediaGroup.isEmpty()) {
5555
PlaybackPresenter.instance(getContext()).openVideo(Video.from(mediaGroup.getMediaItems().get(0)));
5656
}
57-
});
57+
},
58+
e -> LoadingManager.showLoading(getContext(), false),
59+
() -> LoadingManager.showLoading(getContext(), false));
5860
}
5961
}

common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/dialogs/menu/ChannelUploadsMenuPresenter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private void appendUnsubscribeButton() {
115115
if (group.getChannelId() == null) {
116116
List<MediaItem> mediaItems = group.getMediaItems();
117117

118-
if (mediaItems != null && mediaItems.size() > 0) {
118+
if (mediaItems != null && !mediaItems.isEmpty()) {
119119
mServiceManager.loadMetadata(mediaItems.get(0), metadata -> {
120120
unsubscribe(metadata.getChannelId());
121121
mVideo.channelId = metadata.getChannelId();

common/src/main/java/com/liskovsoft/smartyoutubetv2/common/misc/MediaServiceManager.java

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,22 @@ public static MediaServiceManager instance() {
116116
return sInstance;
117117
}
118118

119+
public void loadMetadata(MediaItem mediaItem, OnMetadata onMetadata) {
120+
loadMetadata(mediaItem, onMetadata, null, null);
121+
}
122+
123+
/**
124+
* NOTE: Load suggestions from MediaItem isn't robust. Because playlistId may be initialized from RemoteControlManager.
125+
*/
126+
public void loadMetadata(MediaItem mediaItem, OnMetadata onMetadata, OnError onError, OnComplete onComplete) {
127+
loadMetadata(Video.from(mediaItem), onMetadata, onError, onComplete);
128+
}
129+
119130
public void loadMetadata(Video video, OnMetadata onMetadata) {
131+
loadMetadata(video, onMetadata, null, null);
132+
}
133+
134+
public void loadMetadata(Video video, OnMetadata onMetadata, OnError onError, OnComplete onComplete) {
120135
if (video == null) {
121136
return;
122137
}
@@ -138,28 +153,17 @@ public void loadMetadata(Video video, OnMetadata onMetadata) {
138153
mMetadataAction = observable
139154
.subscribe(
140155
onMetadata::onMetadata,
141-
error -> Log.e(TAG, "loadMetadata error: %s", error.getMessage())
142-
);
143-
}
144-
145-
/**
146-
* NOTE: Load suggestions from MediaItem isn't robust. Because playlistId may be initialized from RemoteControlManager.
147-
*/
148-
public void loadMetadata(MediaItem mediaItem, OnMetadata onMetadata) {
149-
if (mediaItem == null) {
150-
return;
151-
}
152-
153-
RxHelper.disposeActions(mMetadataAction);
154-
155-
Observable<MediaItemMetadata> observable;
156-
157-
observable = mItemService.getMetadataObserve(mediaItem);
158-
159-
mMetadataAction = observable
160-
.subscribe(
161-
onMetadata::onMetadata,
162-
error -> Log.e(TAG, "loadMetadata error: %s", error.getMessage())
156+
error -> {
157+
Log.e(TAG, "loadMetadata error: %s", error.getMessage());
158+
if (onError != null) {
159+
onError.onError(error);
160+
}
161+
},
162+
() -> {
163+
if (onComplete != null) {
164+
onComplete.onComplete();
165+
}
166+
}
163167
);
164168
}
165169

0 commit comments

Comments
 (0)