mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-27 06:30:29 +00:00
update handling of watchlist
This commit is contained in:
parent
cc53340c8a
commit
66bcf4afe1
2 changed files with 37 additions and 30 deletions
|
@ -55,8 +55,7 @@ public class ItemViewClickedListener implements OnItemViewClickedListener {
|
||||||
((ImageCardView) itemViewHolder.view).getMainImageView(),
|
((ImageCardView) itemViewHolder.view).getMainImageView(),
|
||||||
EventDetailsActivity.SHARED_ELEMENT_NAME).toBundle();
|
EventDetailsActivity.SHARED_ELEMENT_NAME).toBundle();
|
||||||
fragment.getActivity().startActivity(i, bundle);
|
fragment.getActivity().startActivity(i, bundle);
|
||||||
}
|
} else if (item instanceof Room) {
|
||||||
if (item instanceof Room) {
|
|
||||||
Room room = (Room) item;
|
Room room = (Room) item;
|
||||||
Intent i = new Intent(fragment.getActivity(), DetailsActivity.class);
|
Intent i = new Intent(fragment.getActivity(), DetailsActivity.class);
|
||||||
i.putExtra(DetailsActivity.TYPE, DetailsActivity.TYPE_STREAM);
|
i.putExtra(DetailsActivity.TYPE, DetailsActivity.TYPE_STREAM);
|
||||||
|
|
|
@ -13,8 +13,6 @@ import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -26,7 +24,6 @@ import de.nicidienase.chaosflix.activities.AbstractServiceConnectedAcitivty;
|
||||||
import de.nicidienase.chaosflix.entities.WatchlistItem;
|
import de.nicidienase.chaosflix.entities.WatchlistItem;
|
||||||
import de.nicidienase.chaosflix.entities.recording.Conference;
|
import de.nicidienase.chaosflix.entities.recording.Conference;
|
||||||
import de.nicidienase.chaosflix.entities.recording.ConferencesWrapper;
|
import de.nicidienase.chaosflix.entities.recording.ConferencesWrapper;
|
||||||
import de.nicidienase.chaosflix.entities.recording.Event;
|
|
||||||
import de.nicidienase.chaosflix.entities.streaming.Group;
|
import de.nicidienase.chaosflix.entities.streaming.Group;
|
||||||
import de.nicidienase.chaosflix.entities.streaming.LiveConference;
|
import de.nicidienase.chaosflix.entities.streaming.LiveConference;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
|
@ -42,11 +39,13 @@ public class ConferencesBrowseFragment extends BrowseFragment {
|
||||||
|
|
||||||
private static final String TAG = ConferencesBrowseFragment.class.getSimpleName();
|
private static final String TAG = ConferencesBrowseFragment.class.getSimpleName();
|
||||||
public static final int FRAGMENT = R.id.browse_fragment;
|
public static final int FRAGMENT = R.id.browse_fragment;
|
||||||
private static final boolean OLDEST_FIRST = false;
|
|
||||||
private ArrayObjectAdapter mRowsAdapter;
|
private ArrayObjectAdapter mRowsAdapter;
|
||||||
private Map<String, List<Conference>> mConferences;
|
private Map<String, List<Conference>> mConferences;
|
||||||
CompositeDisposable mDisposables = new CompositeDisposable();
|
CompositeDisposable mDisposables = new CompositeDisposable();
|
||||||
private ArrayObjectAdapter watchListAdapter;
|
private ArrayObjectAdapter watchListAdapter;
|
||||||
|
private ListRow mWatchlistRow;
|
||||||
|
private boolean streamsAvailable = false;
|
||||||
|
private SectionRow mRecomendationsSectionsRow;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -80,6 +79,8 @@ public class ConferencesBrowseFragment extends BrowseFragment {
|
||||||
.subscribe(objects -> {
|
.subscribe(objects -> {
|
||||||
List<LiveConference> liveConferences = (List<LiveConference>) objects.get(0);
|
List<LiveConference> liveConferences = (List<LiveConference>) objects.get(0);
|
||||||
ConferencesWrapper conferences = (ConferencesWrapper) objects.get(1);
|
ConferencesWrapper conferences = (ConferencesWrapper) objects.get(1);
|
||||||
|
liveConferences.add(LiveConference.getDummyObject());
|
||||||
|
streamsAvailable = liveConferences.size() > 0;
|
||||||
addStreams(cardPresenter, liveConferences);
|
addStreams(cardPresenter, liveConferences);
|
||||||
addRecordings(cardPresenter, conferences);
|
addRecordings(cardPresenter, conferences);
|
||||||
errorFragment.dismiss();
|
errorFragment.dismiss();
|
||||||
|
@ -92,11 +93,6 @@ public class ConferencesBrowseFragment extends BrowseFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addRecordings(CardPresenter cardPresenter, ConferencesWrapper conferences) {
|
private void addRecordings(CardPresenter cardPresenter, ConferencesWrapper conferences) {
|
||||||
mRowsAdapter.add(new SectionRow(getString(R.string.recomendations)));
|
|
||||||
HeaderItem header = new HeaderItem(getString(R.string.watchlist));
|
|
||||||
// header.setDescription(description);
|
|
||||||
ListRow watchRow = new ListRow(header, watchListAdapter);
|
|
||||||
mRowsAdapter.add(watchRow);
|
|
||||||
mRowsAdapter.add(new SectionRow(getString(R.string.conferences)));
|
mRowsAdapter.add(new SectionRow(getString(R.string.conferences)));
|
||||||
mConferences = conferences.getConferencesBySeries();
|
mConferences = conferences.getConferencesBySeries();
|
||||||
Set<String> keySet = mConferences.keySet();
|
Set<String> keySet = mConferences.keySet();
|
||||||
|
@ -132,7 +128,7 @@ public class ConferencesBrowseFragment extends BrowseFragment {
|
||||||
header.setContentDescription(g.getGroup());
|
header.setContentDescription(g.getGroup());
|
||||||
mRowsAdapter.add(i + 1, new ListRow(header, listRowAdapter));
|
mRowsAdapter.add(i + 1, new ListRow(header, listRowAdapter));
|
||||||
}
|
}
|
||||||
mRowsAdapter.add(i + 1, new DividerRow());
|
// mRowsAdapter.add(i + 1, new DividerRow());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,29 +137,41 @@ public class ConferencesBrowseFragment extends BrowseFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
mDisposables.add(((AbstractServiceConnectedAcitivty) getActivity()).getmApiServiceObservable()
|
List<WatchlistItem> watchlistItems
|
||||||
|
= Lists.newArrayList(WatchlistItem.findAll(WatchlistItem.class));
|
||||||
|
// setup and list items
|
||||||
|
if(mWatchlistRow == null && mRecomendationsSectionsRow == null){
|
||||||
|
int offset = streamsAvailable ? 2 : 0;
|
||||||
|
mRecomendationsSectionsRow = new SectionRow(getString(R.string.recomendations));
|
||||||
|
mRowsAdapter.add(offset, mRecomendationsSectionsRow);
|
||||||
|
HeaderItem header = new HeaderItem(getString(R.string.watchlist));
|
||||||
|
// header.setDescription(description);
|
||||||
|
mWatchlistRow = new ListRow(header, watchListAdapter);
|
||||||
|
mRowsAdapter.add(offset + 1, mWatchlistRow);
|
||||||
|
}
|
||||||
|
updateWatchlist(watchlistItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Disposable updateWatchlist(List<WatchlistItem> watchlistItems) {
|
||||||
|
return ((AbstractServiceConnectedAcitivty) getActivity()).getmApiServiceObservable()
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(mediaApiService -> {
|
.subscribe(mediaApiService -> {
|
||||||
List<WatchlistItem> watchlistItems
|
|
||||||
= Lists.newArrayList(WatchlistItem.findAll(WatchlistItem.class));
|
|
||||||
Collections.sort(watchlistItems, (o1, o2) -> {
|
|
||||||
WatchlistItem i1, i2;
|
|
||||||
i1 = (WatchlistItem) o1;
|
|
||||||
i2 = (WatchlistItem) o2;
|
|
||||||
int result = i1.getAdded().compareTo(i2.getAdded());
|
|
||||||
if(OLDEST_FIRST){
|
|
||||||
return result * -1;
|
|
||||||
} else {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
List < Event > watchEvents = new LinkedList<>();
|
|
||||||
watchListAdapter.clear();
|
watchListAdapter.clear();
|
||||||
for(WatchlistItem i : watchlistItems){
|
if(watchlistItems.size() > 0){
|
||||||
mediaApiService.getEvent(i.getEventId())
|
Observable.fromIterable(watchlistItems)
|
||||||
|
.flatMap(watchlistItem -> mediaApiService.getEvent(watchlistItem.getEventId()))
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(event -> watchListAdapter.add(event));
|
.subscribe(event -> watchListAdapter.add(event));
|
||||||
|
} else {
|
||||||
|
watchListAdapter.add("Watchlist empty");
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue