mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-26 14:10:23 +00:00
Leanback: start building new DetailsFragment
This commit is contained in:
parent
72a9ef966c
commit
ee7bf82193
8 changed files with 377 additions and 156 deletions
|
@ -24,15 +24,15 @@ class EventDetailsDescriptionPresenter(private val context: Context) : Presenter
|
|||
}
|
||||
val dataHolder: DetailDataHolder
|
||||
if (item is PersistentEvent) {
|
||||
val (_, _, _, _, title, subtitle, _, _, description, _, _, releaseDate, _, _, _, _, _, _, _, _, _, persons, tags) = item
|
||||
val persistentEvent = item
|
||||
val sb = StringBuilder()
|
||||
val speaker = TextUtils.join(", ", persons!!)
|
||||
sb.append(description)
|
||||
val speaker = TextUtils.join(", ", persistentEvent.persons)
|
||||
sb.append(persistentEvent.description)
|
||||
.append("\n")
|
||||
.append("\nreleased at: ").append(releaseDate)
|
||||
.append("\nTags: ").append(android.text.TextUtils.join(", ", tags!!))
|
||||
dataHolder = DetailDataHolder(title,
|
||||
subtitle,
|
||||
.append("\nreleased at: ").append(persistentEvent.releaseDate)
|
||||
.append("\nTags: ").append(android.text.TextUtils.join(", ", persistentEvent.tags!!))
|
||||
dataHolder = DetailDataHolder(persistentEvent.title,
|
||||
persistentEvent.subtitle,
|
||||
speaker,
|
||||
sb.toString())
|
||||
} else if (item is Room) {
|
||||
|
|
|
@ -34,12 +34,12 @@ public class ItemViewClickedListener implements OnItemViewClickedListener {
|
|||
FragmentActivity activity = fragment.requireActivity();
|
||||
if (item instanceof PersistentConference) {
|
||||
PersistentConference conference = (PersistentConference) item;
|
||||
// Start EventsActivity for this conference
|
||||
Bundle transition = ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||
activity,
|
||||
((ImageCardView) itemViewHolder.view).getMainImageView(),
|
||||
EventsActivity.Companion.getSHARED_ELEMENT_NAME()).toBundle();
|
||||
EventsActivity.start(fragment.requireContext(),conference,transition);
|
||||
// EventsActivity.start(fragment.requireContext(),conference);
|
||||
} else if (item instanceof PersistentEvent) {
|
||||
Bundle transistion = ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||
activity,
|
||||
|
@ -54,7 +54,6 @@ public class ItemViewClickedListener implements OnItemViewClickedListener {
|
|||
EventDetailsActivity.Companion.getSHARED_ELEMENT_NAME()).toBundle();
|
||||
Room room = (Room) item;
|
||||
DetailsActivity.start(fragment.requireContext(), room, transition);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,19 +42,27 @@ class DetailsActivity : FragmentActivity() {
|
|||
val TYPE_STREAM = 1
|
||||
|
||||
@JvmStatic
|
||||
fun start(context: Context, event: PersistentEvent, transistion: Bundle? = null){
|
||||
fun start(context: Context, event: PersistentEvent, transition: Bundle? = null){
|
||||
val i = Intent(context, DetailsActivity::class.java)
|
||||
i.putExtra(DetailsActivity.TYPE, DetailsActivity.TYPE_RECORDING)
|
||||
i.putExtra(DetailsActivity.EVENT, event)
|
||||
context.startActivity(i, transistion)
|
||||
if(transition != null){
|
||||
context.startActivity(i, transition)
|
||||
} else {
|
||||
context.startActivity(i)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun start(context: Context, room: Room, transition: Bundle){
|
||||
fun start(context: Context, room: Room, transition: Bundle? = null){
|
||||
val i = Intent(context, DetailsActivity::class.java)
|
||||
i.putExtra(DetailsActivity.TYPE, DetailsActivity.TYPE_STREAM)
|
||||
i.putExtra(DetailsActivity.ROOM, room)
|
||||
if(transition != null){
|
||||
context.startActivity(i, transition)
|
||||
} else {
|
||||
context.startActivity(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,10 +30,15 @@ class EventsActivity : FragmentActivity() {
|
|||
val SHARED_ELEMENT_NAME = "shared_element"
|
||||
|
||||
@JvmStatic
|
||||
fun start(context: Context ,conference: PersistentConference, transition: Bundle){
|
||||
@JvmOverloads
|
||||
fun start(context: Context ,conference: PersistentConference, transition: Bundle? = null){
|
||||
val i = Intent(context, EventsActivity::class.java)
|
||||
i.putExtra(EventsActivity.CONFERENCE, conference)
|
||||
if(transition != null){
|
||||
context.startActivity(i, transition)
|
||||
} else {
|
||||
context.startActivity(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,21 +87,21 @@ class EventsBrowseFragment : BrowseSupportFragment() {
|
|||
}
|
||||
}
|
||||
}
|
||||
val events = it?.data
|
||||
if (events != null) {
|
||||
Log.d(TAG, "Got ${events.size} events")
|
||||
val eventsByTags = getEventsByTags(events, conference.acronym)
|
||||
Log.d(TAG, "Got ${eventsByTags.keys.size} Tags")
|
||||
for (item in eventsByTags) {
|
||||
updateRowForTag(cardPresenter, item.key, item.value)
|
||||
}
|
||||
errorFragment?.dismiss()
|
||||
}
|
||||
// val events = it?.data
|
||||
// if (events != null) {
|
||||
// Log.d(TAG, "Got ${events.size} events")
|
||||
// val eventsByTags = getEventsByTags(events, conference.acronym)
|
||||
// Log.d(TAG, "Got ${eventsByTags.keys.size} Tags")
|
||||
// for (item in eventsByTags) {
|
||||
// updateRowForTag(cardPresenter, item.key, item.value)
|
||||
// }
|
||||
// errorFragment?.dismiss()
|
||||
// }
|
||||
})
|
||||
viewModel.getEventsforConference(conference).observe(
|
||||
this,
|
||||
Observer {
|
||||
if (it != null) {
|
||||
if (it != null && it.size > 0) {
|
||||
val eventsByTags = getEventsByTags(it, conference.acronym)
|
||||
for (item in eventsByTags) {
|
||||
updateRowForTag(cardPresenter, item.key, item.value)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package de.nicidienase.chaosflix.leanback.fragments;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.arch.lifecycle.ViewModelProviders;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -8,6 +9,7 @@ import android.content.res.Resources;
|
|||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v17.leanback.app.BackgroundManager;
|
||||
import android.support.v17.leanback.app.DetailsSupportFragment;
|
||||
|
@ -47,8 +49,10 @@ import de.nicidienase.chaosflix.common.mediadata.entities.streaming.LiveConferen
|
|||
import de.nicidienase.chaosflix.common.mediadata.entities.streaming.Room;
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.streaming.Stream;
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.streaming.StreamUrl;
|
||||
import de.nicidienase.chaosflix.common.userdata.entities.watchlist.WatchlistItem;
|
||||
import de.nicidienase.chaosflix.common.viewmodel.DetailsViewModel;
|
||||
import de.nicidienase.chaosflix.common.viewmodel.ViewModelFactory;
|
||||
import de.nicidienase.chaosflix.leanback.EventDetailsDescriptionPresenter;
|
||||
import de.nicidienase.chaosflix.leanback.ItemViewClickedListener;
|
||||
import de.nicidienase.chaosflix.leanback.activities.ConferencesActivity;
|
||||
import de.nicidienase.chaosflix.leanback.activities.DetailsActivity;
|
||||
import de.nicidienase.chaosflix.leanback.activities.EventDetailsActivity;
|
||||
|
@ -66,26 +70,29 @@ public class EventsDetailsFragment extends DetailsSupportFragment {
|
|||
|
||||
private static final String TAG = EventsDetailsFragment.class.getSimpleName();
|
||||
public static final int FRAGMENT = R.id.details_fragment;
|
||||
public static final int DUMMY_ID = 1646465164;
|
||||
public static final int DEFAULT_DRAWABLE = R.drawable.default_background;
|
||||
private static final long ADD_WATCHLIST_ACTION = 1646465165;
|
||||
private static final long REMOVE_WATCHLIST_ACTION = 1646465166;
|
||||
|
||||
private static final long ACTION_PLAY = 1646465164;
|
||||
private static final long ACTION_ADD_WATCHLIST = 1646465165;
|
||||
private static final long ACTION_REMOVE_WATCHLIST = 1646465166;
|
||||
|
||||
private PersistentEvent event;
|
||||
private Room room;
|
||||
private int eventType;
|
||||
private ArrayList<StreamUrl> streamUrlList;
|
||||
private BackgroundManager backgroundManager;
|
||||
private DisplayMetrics metrics;
|
||||
private WatchlistItem watchlistItem;
|
||||
private ArrayObjectAdapter recordingActionsAdapter;
|
||||
private OnActionClickedListener onActionClickedListener = new DetailActionClickedListener();
|
||||
private DetailsViewModel viewModel;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.d(TAG, "onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
prepareBackgroundManager();
|
||||
viewModel = ViewModelProviders.of(this, new ViewModelFactory(requireContext())).get(DetailsViewModel.class);
|
||||
|
||||
// prepareBackgroundManager();
|
||||
final BrowseErrorFragment browseErrorFragment =
|
||||
BrowseErrorFragment.showErrorFragment(getFragmentManager(), FRAGMENT);
|
||||
eventType = getActivity().getIntent().getIntExtra(DetailsActivity.Companion.getTYPE(), -1);
|
||||
|
@ -93,7 +100,23 @@ public class EventsDetailsFragment extends DetailsSupportFragment {
|
|||
if (eventType == DetailsActivity.Companion.getTYPE_RECORDING()) {
|
||||
event = getActivity().getIntent()
|
||||
.getParcelableExtra(DetailsActivity.Companion.getEVENT());
|
||||
// watchlistItem = WatchlistItem.findById(WatchlistItem.class, event.getApiID());
|
||||
setTitle(event.getTitle());
|
||||
// viewModel.setEvent(event).observe(this, event1 -> {
|
||||
// List<PersistentRecording> recordings = event1.getRecordings();
|
||||
// if(recordings != null){
|
||||
// recordingActionsAdapter.setItems(recordings, new DiffCallback<PersistentRecording>() {
|
||||
// @Override
|
||||
// public boolean areItemsTheSame(@NonNull PersistentRecording oldItem, @NonNull PersistentRecording newItem) {
|
||||
// return oldItem.getUrl().equals(newItem.getUrl());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean areContentsTheSame(@NonNull PersistentRecording oldItem, @NonNull PersistentRecording newItem) {
|
||||
// return oldItem.getRecordingUrl().equals(newItem.getRecordingUrl());
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
} else if (eventType == DetailsActivity.Companion.getTYPE_STREAM()) {
|
||||
room = getActivity().getIntent()
|
||||
.getParcelableExtra(DetailsActivity.Companion.getROOM());
|
||||
|
@ -101,10 +124,17 @@ public class EventsDetailsFragment extends DetailsSupportFragment {
|
|||
|
||||
FullWidthDetailsOverviewRowPresenter mDetailsPresenter
|
||||
= setupDetailsOverviewRowPresenter();
|
||||
ClassPresenterSelector mPresenterSelector = new ClassPresenterSelector();
|
||||
mPresenterSelector.addClassPresenter(DetailsOverviewRow.class, mDetailsPresenter);
|
||||
mPresenterSelector.addClassPresenter(ListRow.class, new ListRowPresenter());
|
||||
final ArrayObjectAdapter adapter = new ArrayObjectAdapter(mPresenterSelector);
|
||||
ClassPresenterSelector presenterSelector = new ClassPresenterSelector();
|
||||
presenterSelector.addClassPresenter(DetailsOverviewRow.class, mDetailsPresenter);
|
||||
presenterSelector.addClassPresenter(ListRow.class, new ListRowPresenter());
|
||||
final ArrayObjectAdapter adapter = new ArrayObjectAdapter(presenterSelector);
|
||||
final DetailsOverviewRow detailsOverviewRow = setupDetailsOverviewRow(event);
|
||||
recordingActionsAdapter = getRecordingActionsAdapter();
|
||||
detailsOverviewRow.setActionsAdapter(recordingActionsAdapter);
|
||||
adapter.add(detailsOverviewRow);
|
||||
setOnItemViewClickedListener(new ItemViewClickedListener(this));
|
||||
setAdapter(adapter);
|
||||
browseErrorFragment.dismiss();
|
||||
|
||||
// ((LeanbackBaseActivity) getActivity()).getApiServiceObservable()
|
||||
// .doOnError(t -> browseErrorFragment.setErrorContent(t.getMessage()))
|
||||
|
@ -166,18 +196,19 @@ public class EventsDetailsFragment extends DetailsSupportFragment {
|
|||
// detailsOverviewRow.setActionsAdapter(actionsAdapter);
|
||||
// adapter.add(detailsOverviewRow);
|
||||
// setOnItemViewClickedListener(new ItemViewClickedListener(EventsDetailsFragment.this));
|
||||
// setAdapter(adapter);
|
||||
// browseErrorFragment.dismiss();
|
||||
// setAdapter(adapter);
|
||||
// // TODO add other streams
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// new Handler().postDelayed(this::startEntranceTransition, 500);
|
||||
Log.d(TAG, "create finished");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
startEntranceTransition();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -189,7 +220,7 @@ public class EventsDetailsFragment extends DetailsSupportFragment {
|
|||
private void prepareBackgroundManager() {
|
||||
backgroundManager = BackgroundManager.getInstance(getActivity());
|
||||
backgroundManager.attach(getActivity().getWindow());
|
||||
metrics = new DisplayMetrics();
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
}
|
||||
|
||||
|
@ -241,22 +272,22 @@ public class EventsDetailsFragment extends DetailsSupportFragment {
|
|||
}
|
||||
|
||||
private FullWidthDetailsOverviewRowPresenter setupDetailsOverviewRowPresenter() {
|
||||
FullWidthDetailsOverviewRowPresenter mDetailsPresenter = new FullWidthDetailsOverviewRowPresenter(
|
||||
FullWidthDetailsOverviewRowPresenter detailsPresenter = new FullWidthDetailsOverviewRowPresenter(
|
||||
new EventDetailsDescriptionPresenter(getActivity()),
|
||||
new EventDetailsOverviewLogoPresenter());
|
||||
mDetailsPresenter.setBackgroundColor(getResources().getColor(R.color.selected_background));
|
||||
mDetailsPresenter.setInitialState(FullWidthDetailsOverviewRowPresenter.STATE_HALF);
|
||||
mDetailsPresenter.setAlignmentMode(FullWidthDetailsOverviewRowPresenter.ALIGN_MODE_START);
|
||||
detailsPresenter.setBackgroundColor(getResources().getColor(R.color.selected_background));
|
||||
detailsPresenter.setInitialState(FullWidthDetailsOverviewRowPresenter.STATE_HALF);
|
||||
detailsPresenter.setAlignmentMode(FullWidthDetailsOverviewRowPresenter.ALIGN_MODE_START);
|
||||
|
||||
FullWidthDetailsOverviewSharedElementHelper helper
|
||||
= new FullWidthDetailsOverviewSharedElementHelper();
|
||||
helper.setSharedElementEnterTransition(getActivity(),
|
||||
EventDetailsActivity.Companion.getSHARED_ELEMENT_NAME());
|
||||
mDetailsPresenter.setListener(helper);
|
||||
detailsPresenter.setListener(helper);
|
||||
prepareEntranceTransition();
|
||||
|
||||
mDetailsPresenter.setOnActionClickedListener(onActionClickedListener);
|
||||
return mDetailsPresenter;
|
||||
detailsPresenter.setOnActionClickedListener(onActionClickedListener);
|
||||
return detailsPresenter;
|
||||
}
|
||||
|
||||
private DetailsOverviewRow setupDetailsOverviewRow(Object event) {
|
||||
|
@ -274,7 +305,7 @@ public class EventsDetailsFragment extends DetailsSupportFragment {
|
|||
@Override
|
||||
public void onResourceReady(Bitmap resource,
|
||||
GlideAnimation<? super Bitmap> glideAnimation) {
|
||||
row.setImageBitmap(getActivity(), resource);
|
||||
row.setImageBitmap(requireActivity(), resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -286,25 +317,35 @@ public class EventsDetailsFragment extends DetailsSupportFragment {
|
|||
return row;
|
||||
}
|
||||
|
||||
private ArrayObjectAdapter getRecordingActionsAdapter(List<PersistentRecording> recordings) {
|
||||
private ArrayObjectAdapter getRecordingActionsAdapter() {
|
||||
ArrayObjectAdapter actionsAdapter = new ArrayObjectAdapter();
|
||||
final Action watchlistAction = new Action(ACTION_ADD_WATCHLIST, getString(R.string.add_to_watchlist));
|
||||
actionsAdapter.add(watchlistAction);
|
||||
viewModel.getBookmarkForEvent(event.getGuid()).observe(this, watchlistItem -> {
|
||||
if (watchlistItem != null) {
|
||||
actionsAdapter.add(new Action(REMOVE_WATCHLIST_ACTION,getString(R.string.remove_from_watchlist)));
|
||||
watchlistAction.setId(ACTION_REMOVE_WATCHLIST);
|
||||
watchlistAction.setLabel1(getString(R.string.remove_from_watchlist));
|
||||
} else {
|
||||
actionsAdapter.add(new Action(ADD_WATCHLIST_ACTION,getString(R.string.add_to_watchlist)));
|
||||
}
|
||||
if (recordings != null) {
|
||||
for (int i = 0; i < recordings.size(); i++) {
|
||||
PersistentRecording recording = recordings.get(i);
|
||||
if (recording.getMimeType().startsWith("video/") && !recording.getMimeType().equals("video/webm")) {
|
||||
String quality = recording.isHighQuality() ? "HD" : "SD";
|
||||
String title = quality + " (" + recording.getLanguage() + ")";
|
||||
actionsAdapter.add(new Action(recording.getId(), title, recording.getMimeType().substring(6)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
actionsAdapter.add(new Action(DUMMY_ID, "Dummy", "HLS"));
|
||||
watchlistAction.setId(ACTION_ADD_WATCHLIST);
|
||||
watchlistAction.setLabel1(getString(R.string.add_to_watchlist));
|
||||
}
|
||||
});
|
||||
|
||||
Action playAction = new Action(ACTION_PLAY, "Play");
|
||||
actionsAdapter.add(playAction);
|
||||
|
||||
// if (recordings != null) {
|
||||
// for (int i = 0; i < recordings.size(); i++) {
|
||||
// PersistentRecording recording = recordings.get(i);
|
||||
// if (recording.getMimeType().startsWith("video/") && !recording.getMimeType().equals("video/webm")) {
|
||||
// String quality = recording.isHighQuality() ? "HD" : "SD";
|
||||
// String title = quality + " (" + recording.getLanguage() + ")";
|
||||
// actionsAdapter.add(new Action(recording.getId(), title, recording.getMimeType().substring(6)));
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// actionsAdapter.add(new Action(DUMMY_ID, "Dummy", "HLS"));
|
||||
// }
|
||||
return actionsAdapter;
|
||||
}
|
||||
|
||||
|
@ -377,10 +418,10 @@ public class EventsDetailsFragment extends DetailsSupportFragment {
|
|||
@Override
|
||||
public void onActionClicked(Action action) {
|
||||
Log.d(TAG, "OnActionClicked");
|
||||
if (action.getId() == ADD_WATCHLIST_ACTION) {
|
||||
if (action.getId() == ACTION_ADD_WATCHLIST) {
|
||||
// new WatchlistItem(event.getApiID()).save();
|
||||
recordingActionsAdapter.replace(0, new Action(REMOVE_WATCHLIST_ACTION, EventsDetailsFragment.this.getString(R.string.remove_from_watchlist)));
|
||||
SharedPreferences preferences = getActivity().getSharedPreferences(getString(R.string.watchlist_preferences_key), Context.MODE_PRIVATE);
|
||||
recordingActionsAdapter.replace(0, new Action(ACTION_REMOVE_WATCHLIST, EventsDetailsFragment.this.getString(R.string.remove_from_watchlist)));
|
||||
SharedPreferences preferences = requireActivity().getSharedPreferences(getString(R.string.watchlist_preferences_key), Context.MODE_PRIVATE);
|
||||
if (preferences.getBoolean(getString(R.string.watchlist_dialog_needed), true)) { // new item
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.watchlist_message);
|
||||
|
@ -388,40 +429,29 @@ public class EventsDetailsFragment extends DetailsSupportFragment {
|
|||
Intent i = new Intent(getActivity(), ConferencesActivity.class);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(i);
|
||||
getActivity().finish();
|
||||
// getActivity().finish();
|
||||
});
|
||||
builder.setPositiveButton("OK", (dialog, which) -> {
|
||||
});
|
||||
builder.setPositiveButton("OK",(dialog, which) -> {});
|
||||
SharedPreferences.Editor edit = preferences.edit();
|
||||
edit.putBoolean(getString(R.string.watchlist_dialog_needed), false);
|
||||
edit.commit();
|
||||
edit.apply();
|
||||
|
||||
builder.create().show();
|
||||
}
|
||||
} else if (action.getId() == REMOVE_WATCHLIST_ACTION) {
|
||||
if (watchlistItem != null) {
|
||||
// watchlistItem.delete();
|
||||
}
|
||||
recordingActionsAdapter.replace(0, new Action(ADD_WATCHLIST_ACTION, EventsDetailsFragment.this.getString(R.string.add_to_watchlist)));
|
||||
} else {
|
||||
} else if (action.getId() == ACTION_REMOVE_WATCHLIST) {
|
||||
viewModel.removeBookmark(event.getGuid());
|
||||
} else if (action.getId() == ACTION_PLAY) {
|
||||
Intent i = new Intent(EventsDetailsFragment.this.getActivity(), PlayerActivity.class);
|
||||
i.putExtra(DetailsActivity.Companion.getTYPE(), eventType);
|
||||
if (eventType == DetailsActivity.Companion.getTYPE_RECORDING()) {
|
||||
i.putExtra(DetailsActivity.Companion.getEVENT(), event);
|
||||
if (action.getId() == DUMMY_ID) {
|
||||
PersistentRecording dummy = new PersistentRecording();
|
||||
dummy.setRecordingUrl("https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8");
|
||||
dummy.setMimeType("video/hls");
|
||||
dummy.setLanguage("eng");
|
||||
dummy.setHighQuality(true);
|
||||
i.putExtra(DetailsActivity.Companion.getRECORDING(), dummy);
|
||||
} else {
|
||||
for (PersistentRecording r : event.getRecordings()) {
|
||||
if (r.getId() == action.getId()) {
|
||||
i.putExtra(DetailsActivity.Companion.getRECORDING(), r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (eventType == DetailsActivity.Companion.getTYPE_STREAM()) {
|
||||
i.putExtra(DetailsActivity.Companion.getROOM(), room);
|
||||
StreamUrl streamUrl = EventsDetailsFragment.this.getStreamUrlForActionId((int) action.getId());
|
||||
|
|
|
@ -0,0 +1,179 @@
|
|||
package de.nicidienase.chaosflix.leanback.fragments
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.arch.lifecycle.Observer
|
||||
import android.arch.lifecycle.ViewModelProviders
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.support.v17.leanback.app.DetailsSupportFragment
|
||||
import android.support.v17.leanback.widget.Action
|
||||
import android.support.v17.leanback.widget.ArrayObjectAdapter
|
||||
import android.support.v17.leanback.widget.ClassPresenterSelector
|
||||
import android.support.v17.leanback.widget.DetailsOverviewRow
|
||||
import android.support.v17.leanback.widget.FullWidthDetailsOverviewRowPresenter
|
||||
import android.support.v17.leanback.widget.FullWidthDetailsOverviewSharedElementHelper
|
||||
import android.support.v17.leanback.widget.ListRow
|
||||
import android.support.v17.leanback.widget.ListRowPresenter
|
||||
import android.support.v17.leanback.widget.OnActionClickedListener
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.animation.GlideAnimation
|
||||
import com.bumptech.glide.request.target.SimpleTarget
|
||||
import de.nicidienase.chaosflix.R
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.PersistentEvent
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.streaming.Room
|
||||
import de.nicidienase.chaosflix.common.viewmodel.DetailsViewModel
|
||||
import de.nicidienase.chaosflix.common.viewmodel.ViewModelFactory
|
||||
import de.nicidienase.chaosflix.leanback.EventDetailsDescriptionPresenter
|
||||
import de.nicidienase.chaosflix.leanback.activities.ConferencesActivity
|
||||
import de.nicidienase.chaosflix.leanback.activities.DetailsActivity
|
||||
import de.nicidienase.chaosflix.leanback.activities.EventDetailsActivity
|
||||
import de.nicidienase.chaosflix.leanback.activities.PlayerActivity
|
||||
|
||||
|
||||
class NewEventsDetailsFragment : DetailsSupportFragment() {
|
||||
|
||||
private lateinit var viewModel: DetailsViewModel
|
||||
|
||||
private var eventType: Int = DetailsActivity.TYPE_RECORDING
|
||||
private var event: PersistentEvent? = null
|
||||
|
||||
private lateinit var rowsAdapter: ArrayObjectAdapter
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
viewModel = ViewModelProviders.of(this, ViewModelFactory(requireContext())).get(DetailsViewModel::class.java)
|
||||
|
||||
eventType = activity!!.intent.getIntExtra(DetailsActivity.TYPE, -1)
|
||||
event = requireActivity().intent.getParcelableExtra<PersistentEvent>(DetailsActivity.EVENT)
|
||||
|
||||
if (eventType != DetailsActivity.TYPE_RECORDING || event == null) {
|
||||
return
|
||||
}
|
||||
|
||||
title = event?.title
|
||||
|
||||
val selector = ClassPresenterSelector()
|
||||
val detailsPresenter = FullWidthDetailsOverviewRowPresenter(
|
||||
EventDetailsDescriptionPresenter(requireContext()))
|
||||
|
||||
val helper = FullWidthDetailsOverviewSharedElementHelper()
|
||||
helper.setSharedElementEnterTransition(activity,
|
||||
EventDetailsActivity.SHARED_ELEMENT_NAME)
|
||||
detailsPresenter.setListener(helper)
|
||||
prepareEntranceTransition()
|
||||
|
||||
detailsPresenter.onActionClickedListener = DetailActionClickedListener()
|
||||
|
||||
selector.addClassPresenter(DetailsOverviewRow::class.java, detailsPresenter)
|
||||
selector.addClassPresenter(ListRow::class.java,
|
||||
ListRowPresenter())
|
||||
rowsAdapter = ArrayObjectAdapter(selector)
|
||||
|
||||
val detailsOverview = DetailsOverviewRow(event)
|
||||
Glide.with(activity)
|
||||
.load(event?.thumbUrl)
|
||||
.asBitmap()
|
||||
.into(object : SimpleTarget<Bitmap>(DETAIL_THUMB_WIDTH, DETAIL_THUMB_HEIGHT) {
|
||||
override fun onResourceReady(resource: Bitmap,
|
||||
glideAnimation: GlideAnimation<in Bitmap>) {
|
||||
detailsOverview.setImageBitmap(requireActivity(), resource)
|
||||
}
|
||||
|
||||
override fun onLoadFailed(e: Exception?, errorDrawable: Drawable?) {
|
||||
// super.onLoadFailed(e, errorDrawable);
|
||||
detailsOverview.setImageDrawable(resources.getDrawable(DEFAULT_DRAWABLE))
|
||||
}
|
||||
})
|
||||
|
||||
val actionAdapter = ArrayObjectAdapter()
|
||||
|
||||
val playAction = Action(ACTION_PLAY, "Play")
|
||||
actionAdapter.add(playAction)
|
||||
|
||||
val watchlistAction = Action(ACTION_ADD_WATCHLIST, getString(R.string.add_to_watchlist))
|
||||
actionAdapter.add(watchlistAction)
|
||||
event?.guid?.let {
|
||||
viewModel.getBookmarkForEvent(it).observe(this, Observer { watchlistItem ->
|
||||
if (watchlistItem != null) {
|
||||
watchlistAction.id = ACTION_REMOVE_WATCHLIST
|
||||
watchlistAction.label1 = getString(R.string.remove_from_watchlist)
|
||||
actionAdapter.notifyItemRangeChanged(actionAdapter.indexOf(watchlistAction),1)
|
||||
} else {
|
||||
watchlistAction.id = ACTION_ADD_WATCHLIST
|
||||
watchlistAction.label1 = getString(R.string.add_to_watchlist)
|
||||
actionAdapter.notifyItemRangeChanged(actionAdapter.indexOf(watchlistAction),1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
detailsOverview.actionsAdapter = actionAdapter
|
||||
rowsAdapter.add(detailsOverview);
|
||||
|
||||
adapter = rowsAdapter
|
||||
|
||||
Handler().postDelayed(this::startEntranceTransition, 500);
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val TAG = NewEventsDetailsFragment::class.java.simpleName
|
||||
|
||||
@JvmStatic
|
||||
private val DETAIL_THUMB_WIDTH = 254
|
||||
@JvmStatic
|
||||
private val DETAIL_THUMB_HEIGHT = 143
|
||||
@JvmStatic
|
||||
val DEFAULT_DRAWABLE = R.drawable.default_background
|
||||
|
||||
|
||||
@JvmStatic
|
||||
private val ACTION_PLAY: Long = 0
|
||||
@JvmStatic
|
||||
private val ACTION_ADD_WATCHLIST: Long = 1
|
||||
@JvmStatic
|
||||
private val ACTION_REMOVE_WATCHLIST: Long = 2
|
||||
}
|
||||
|
||||
private inner class DetailActionClickedListener : OnActionClickedListener {
|
||||
override fun onActionClicked(action: Action) {
|
||||
Log.d(TAG, "OnActionClicked")
|
||||
if (action.id == ACTION_ADD_WATCHLIST) {
|
||||
event?.guid?.let { viewModel.createBookmark(it) }
|
||||
val preferences = requireActivity().getSharedPreferences(getString(R.string.watchlist_preferences_key), Context.MODE_PRIVATE)
|
||||
if (preferences.getBoolean(getString(R.string.watchlist_dialog_needed), true)) { // new item
|
||||
showWatchlistInfoDialog(preferences)
|
||||
}
|
||||
} else if (action.id == ACTION_REMOVE_WATCHLIST) {
|
||||
event?.guid?.let { viewModel.removeBookmark(it) }
|
||||
} else if (action.id == ACTION_PLAY) {
|
||||
// TODO play!
|
||||
Toast.makeText(requireContext(), "Play", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
fun showWatchlistInfoDialog(preferences: SharedPreferences) {
|
||||
val builder = AlertDialog.Builder(activity)
|
||||
builder.setTitle(R.string.watchlist_message)
|
||||
builder.setNegativeButton(R.string.return_to_homescreen) { dialog, which ->
|
||||
val i = Intent(activity, ConferencesActivity::class.java)
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
startActivity(i)
|
||||
// getActivity().finish();
|
||||
}
|
||||
builder.setPositiveButton("OK") { dialog, which -> }
|
||||
val edit = preferences.edit()
|
||||
edit.putBoolean(getString(R.string.watchlist_dialog_needed), false)
|
||||
edit.apply()
|
||||
|
||||
builder.create().show()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<fragment android:id="@+id/details_fragment"
|
||||
android:name="de.nicidienase.chaosflix.leanback.fragments.EventsDetailsFragment"
|
||||
android:name="de.nicidienase.chaosflix.leanback.fragments.NewEventsDetailsFragment"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Reference in a new issue