mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-23 04:43:07 +00:00
Leanback: convert some Activities to Kotlin
This commit is contained in:
parent
ee1ed6603f
commit
639637a125
10 changed files with 124 additions and 129 deletions
|
@ -37,32 +37,32 @@ public class ItemViewClickedListener implements OnItemViewClickedListener {
|
|||
PersistentConference conference = (PersistentConference) item;
|
||||
// Start EventsActivity for this conference
|
||||
Intent i = new Intent(fragment.getActivity(), EventsActivity.class);
|
||||
i.putExtra(EventsActivity.CONFERENCE, conference);
|
||||
i.putExtra(EventsActivity.CONFERENCE_ACRONYM, conference.getAcronym());
|
||||
i.putExtra(EventsActivity.Companion.getCONFERENCE(), conference);
|
||||
i.putExtra(EventsActivity.Companion.getCONFERENCE_ACRONYM(), conference.getAcronym());
|
||||
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||
activity,
|
||||
((ImageCardView) itemViewHolder.view).getMainImageView(),
|
||||
EventsActivity.SHARED_ELEMENT_NAME).toBundle();
|
||||
EventsActivity.Companion.getSHARED_ELEMENT_NAME()).toBundle();
|
||||
fragment.startActivity(i, bundle);
|
||||
} else if (item instanceof PersistentEvent) {
|
||||
PersistentEvent event = (PersistentEvent) item;
|
||||
Intent i = new Intent(fragment.getActivity(), DetailsActivity.class);
|
||||
i.putExtra(DetailsActivity.TYPE, DetailsActivity.TYPE_RECORDING);
|
||||
i.putExtra(DetailsActivity.EVENT, event);
|
||||
i.putExtra(DetailsActivity.Companion.getTYPE(), DetailsActivity.Companion.getTYPE_RECORDING());
|
||||
i.putExtra(DetailsActivity.Companion.getEVENT(), event);
|
||||
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||
activity,
|
||||
((ImageCardView) itemViewHolder.view).getMainImageView(),
|
||||
EventDetailsActivity.SHARED_ELEMENT_NAME).toBundle();
|
||||
EventDetailsActivity.Companion.getSHARED_ELEMENT_NAME()).toBundle();
|
||||
activity.startActivity(i, bundle);
|
||||
} else if (item instanceof Room) {
|
||||
Room room = (Room) item;
|
||||
Intent i = new Intent(fragment.getActivity(), DetailsActivity.class);
|
||||
i.putExtra(DetailsActivity.TYPE, DetailsActivity.TYPE_STREAM);
|
||||
i.putExtra(DetailsActivity.ROOM, room);
|
||||
i.putExtra(DetailsActivity.Companion.getTYPE(), DetailsActivity.Companion.getTYPE_STREAM());
|
||||
i.putExtra(DetailsActivity.Companion.getROOM(), room);
|
||||
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||
activity,
|
||||
((ImageCardView) itemViewHolder.view).getMainImageView(),
|
||||
EventDetailsActivity.SHARED_ELEMENT_NAME).toBundle();
|
||||
EventDetailsActivity.Companion.getSHARED_ELEMENT_NAME()).toBundle();
|
||||
activity.startActivity(i, bundle);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
* or implied. See the License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package de.nicidienase.chaosflix.leanback.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import de.nicidienase.chaosflix.R;
|
||||
|
||||
/*
|
||||
* Details activity class that loads LeanbackDetailsFragment class
|
||||
*/
|
||||
public class DetailsActivity extends AppCompatActivity {
|
||||
|
||||
public static final String SHARED_ELEMENT_NAME = "hero";
|
||||
public static final String EVENT = "event";
|
||||
public static final String ROOM = "room";
|
||||
public static final String STREAM_URL = "stream_url";
|
||||
public static final String RECORDING = "recording";
|
||||
public static final String TYPE = "event_type";
|
||||
public static final int TYPE_RECORDING = 0;
|
||||
public static final int TYPE_STREAM = 1;
|
||||
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_event_details);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package de.nicidienase.chaosflix.leanback.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
|
||||
import de.nicidienase.chaosflix.R
|
||||
|
||||
/*
|
||||
* Details activity class that loads LeanbackDetailsFragment class
|
||||
*/
|
||||
class DetailsActivity : AppCompatActivity() {
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_event_details)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val SHARED_ELEMENT_NAME = "hero"
|
||||
@JvmStatic
|
||||
val EVENT = "event"
|
||||
@JvmStatic
|
||||
val ROOM = "room"
|
||||
@JvmStatic
|
||||
val STREAM_URL = "stream_url"
|
||||
@JvmStatic
|
||||
val RECORDING = "recording"
|
||||
@JvmStatic
|
||||
val TYPE = "event_type"
|
||||
@JvmStatic
|
||||
val TYPE_RECORDING = 0
|
||||
@JvmStatic
|
||||
val TYPE_STREAM = 1
|
||||
}
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package de.nicidienase.chaosflix.leanback.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.PersistableBundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import de.nicidienase.chaosflix.R;
|
||||
|
||||
/**
|
||||
* Created by felix on 18.03.17.
|
||||
*/
|
||||
|
||||
public class EventDetailsActivity extends AppCompatActivity {
|
||||
|
||||
public static final String EVENT = "event";
|
||||
public static final String SHARED_ELEMENT_NAME = "transision_element";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
|
||||
super.onCreate(savedInstanceState, persistentState);
|
||||
setContentView(R.layout.activity_event_details);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package de.nicidienase.chaosflix.leanback.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.PersistableBundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
|
||||
import de.nicidienase.chaosflix.R
|
||||
|
||||
|
||||
class EventDetailsActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
|
||||
super.onCreate(savedInstanceState, persistentState)
|
||||
setContentView(R.layout.activity_event_details)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
val EVENT = "event"
|
||||
val SHARED_ELEMENT_NAME = "transision_element"
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package de.nicidienase.chaosflix.leanback.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import de.nicidienase.chaosflix.R;
|
||||
|
||||
public class EventsActivity extends AppCompatActivity {
|
||||
|
||||
public static final String CONFERENCE_ACRONYM = "conference_acronym";
|
||||
public static final String CONFERENCE = "conference";
|
||||
public static final String SHARED_ELEMENT_NAME = "shared_element";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// TODO determin if we should use a Browse or a Grid layout
|
||||
setContentView(R.layout.activity_events_browse);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package de.nicidienase.chaosflix.leanback.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
|
||||
import de.nicidienase.chaosflix.R
|
||||
|
||||
class EventsActivity : AppCompatActivity() {
|
||||
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
// TODO determin if we should use a Browse or a Grid layout
|
||||
setContentView(R.layout.activity_events_browse)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
val CONFERENCE_ACRONYM = "conference_acronym"
|
||||
val CONFERENCE = "conference"
|
||||
val SHARED_ELEMENT_NAME = "shared_element"
|
||||
}
|
||||
}
|
|
@ -77,8 +77,8 @@ public class EventsBrowseFragment extends BrowseFragment {
|
|||
super.onActivityCreated(savedInstanceState);
|
||||
final BrowseErrorFragment errorFragment =
|
||||
BrowseErrorFragment.showErrorFragment(getFragmentManager(), FRAGMENT);
|
||||
conferenceId = this.getActivity().getIntent().getIntExtra(EventsActivity.CONFERENCE_ACRONYM, 0);
|
||||
mConference = this.getActivity().getIntent().getParcelableExtra(EventsActivity.CONFERENCE);
|
||||
conferenceId = this.getActivity().getIntent().getIntExtra(EventsActivity.Companion.getCONFERENCE_ACRONYM(), 0);
|
||||
mConference = this.getActivity().getIntent().getParcelableExtra(EventsActivity.Companion.getCONFERENCE());
|
||||
|
||||
((LeanbackBaseActivity) getActivity()).getApiServiceObservable()
|
||||
.subscribe(mediaApiService -> {
|
||||
|
|
|
@ -115,29 +115,29 @@ public class EventsDetailsFragment extends DetailsFragment {
|
|||
mRecordingActionsAdapter.replace(0, new Action(ADD_WATCHLIST_ACTION, EventsDetailsFragment.this.getString(R.string.add_to_watchlist)));
|
||||
} else {
|
||||
Intent i = new Intent(EventsDetailsFragment.this.getActivity(), PlayerActivity.class);
|
||||
i.putExtra(DetailsActivity.TYPE, eventType);
|
||||
if (eventType == DetailsActivity.TYPE_RECORDING) {
|
||||
i.putExtra(DetailsActivity.EVENT, mSelectedEvent);
|
||||
i.putExtra(DetailsActivity.Companion.getTYPE(), eventType);
|
||||
if (eventType == DetailsActivity.Companion.getTYPE_RECORDING()) {
|
||||
i.putExtra(DetailsActivity.Companion.getEVENT(), mSelectedEvent);
|
||||
if (action.getId() == DUMMY_ID) {
|
||||
Recording dummy = new Recording();
|
||||
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.RECORDING, dummy);
|
||||
i.putExtra(DetailsActivity.Companion.getRECORDING(), dummy);
|
||||
} else {
|
||||
for (Recording r : mSelectedEvent.getRecordings()) {
|
||||
if (r.getApiID() == action.getId()) {
|
||||
i.putExtra(DetailsActivity.RECORDING, r);
|
||||
i.putExtra(DetailsActivity.Companion.getRECORDING(), r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (eventType == DetailsActivity.TYPE_STREAM) {
|
||||
i.putExtra(DetailsActivity.ROOM, mRoom);
|
||||
} else if (eventType == DetailsActivity.Companion.getTYPE_STREAM()) {
|
||||
i.putExtra(DetailsActivity.Companion.getROOM(), mRoom);
|
||||
StreamUrl streamUrl = EventsDetailsFragment.this.getStreamUrlForActionId((int) action.getId());
|
||||
if (streamUrl != null) {
|
||||
i.putExtra(DetailsActivity.STREAM_URL, streamUrl);
|
||||
i.putExtra(DetailsActivity.Companion.getSTREAM_URL(), streamUrl);
|
||||
} else {
|
||||
// TODO handle missing Stream
|
||||
return;
|
||||
|
@ -156,15 +156,15 @@ public class EventsDetailsFragment extends DetailsFragment {
|
|||
prepareBackgroundManager();
|
||||
final BrowseErrorFragment browseErrorFragment =
|
||||
BrowseErrorFragment.showErrorFragment(getFragmentManager(), FRAGMENT);
|
||||
eventType = getActivity().getIntent().getIntExtra(DetailsActivity.TYPE, -1);
|
||||
eventType = getActivity().getIntent().getIntExtra(DetailsActivity.Companion.getTYPE(), -1);
|
||||
|
||||
if (eventType == DetailsActivity.TYPE_RECORDING) {
|
||||
if (eventType == DetailsActivity.Companion.getTYPE_RECORDING()) {
|
||||
mSelectedEvent = getActivity().getIntent()
|
||||
.getParcelableExtra(DetailsActivity.EVENT);
|
||||
.getParcelableExtra(DetailsActivity.Companion.getEVENT());
|
||||
mWatchlistItem = WatchlistItem.findById(WatchlistItem.class, mSelectedEvent.getApiID());
|
||||
} else if (eventType == DetailsActivity.TYPE_STREAM) {
|
||||
} else if (eventType == DetailsActivity.Companion.getTYPE_STREAM()) {
|
||||
mRoom = getActivity().getIntent()
|
||||
.getParcelableExtra(DetailsActivity.ROOM);
|
||||
.getParcelableExtra(DetailsActivity.Companion.getROOM());
|
||||
}
|
||||
|
||||
FullWidthDetailsOverviewRowPresenter mDetailsPresenter
|
||||
|
@ -178,7 +178,7 @@ public class EventsDetailsFragment extends DetailsFragment {
|
|||
.doOnError(t -> browseErrorFragment.setErrorContent(t.getMessage()))
|
||||
.subscribe(mediaApiService -> {
|
||||
mMediaApiService = mediaApiService;
|
||||
if (eventType == DetailsActivity.TYPE_RECORDING) {
|
||||
if (eventType == DetailsActivity.Companion.getTYPE_RECORDING()) {
|
||||
final DetailsOverviewRow detailsOverviewRow = setupDetailsOverviewRow(mSelectedEvent);
|
||||
mediaApiService.getEvent(mSelectedEvent.getApiID())
|
||||
.doOnError(t -> browseErrorFragment.setErrorContent(t.getMessage()))
|
||||
|
@ -222,7 +222,7 @@ public class EventsDetailsFragment extends DetailsFragment {
|
|||
browseErrorFragment.dismiss();
|
||||
});
|
||||
});
|
||||
} else if (eventType == DetailsActivity.TYPE_STREAM) {
|
||||
} else if (eventType == DetailsActivity.Companion.getTYPE_STREAM()) {
|
||||
mediaApiService.getStreamingConferences()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(liveConferences -> {
|
||||
|
@ -319,7 +319,7 @@ public class EventsDetailsFragment extends DetailsFragment {
|
|||
FullWidthDetailsOverviewSharedElementHelper helper
|
||||
= new FullWidthDetailsOverviewSharedElementHelper();
|
||||
helper.setSharedElementEnterTransition(getActivity(),
|
||||
EventDetailsActivity.SHARED_ELEMENT_NAME);
|
||||
EventDetailsActivity.Companion.getSHARED_ELEMENT_NAME());
|
||||
mDetailsPresenter.setListener(helper);
|
||||
prepareEntranceTransition();
|
||||
|
||||
|
|
|
@ -136,19 +136,19 @@ public class OverlayFragment extends PlaybackFragment {
|
|||
|
||||
Intent intent = getActivity()
|
||||
.getIntent();
|
||||
eventType = intent.getIntExtra(DetailsActivity.TYPE, -1);
|
||||
if (eventType == DetailsActivity.TYPE_RECORDING) {
|
||||
mSelectedEvent = intent.getParcelableExtra(DetailsActivity.EVENT);
|
||||
mSelectedRecording = intent.getParcelableExtra(DetailsActivity.RECORDING);
|
||||
eventType = intent.getIntExtra(DetailsActivity.Companion.getTYPE(), -1);
|
||||
if (eventType == DetailsActivity.Companion.getTYPE_RECORDING()) {
|
||||
mSelectedEvent = intent.getParcelableExtra(DetailsActivity.Companion.getEVENT());
|
||||
mSelectedRecording = intent.getParcelableExtra(DetailsActivity.Companion.getRECORDING());
|
||||
mHelper = new PlaybackHelper(getActivity(), this, mSelectedEvent, mSelectedRecording);
|
||||
|
||||
List<PlaybackProgress> progressList = PlaybackProgress.find(PlaybackProgress.class, "event_id = ?", String.valueOf(mSelectedEvent.getApiID()));
|
||||
if (progressList.size() > 0) {
|
||||
mPlaybackProgress = progressList.get(0);
|
||||
}
|
||||
} else if (eventType == DetailsActivity.TYPE_STREAM) {
|
||||
mSelectedRoom = intent.getParcelableExtra(DetailsActivity.ROOM);
|
||||
mSelectedStream = intent.getParcelableExtra(DetailsActivity.STREAM_URL);
|
||||
} else if (eventType == DetailsActivity.Companion.getTYPE_STREAM()) {
|
||||
mSelectedRoom = intent.getParcelableExtra(DetailsActivity.Companion.getROOM());
|
||||
mSelectedStream = intent.getParcelableExtra(DetailsActivity.Companion.getSTREAM_URL());
|
||||
mHelper = new PlaybackHelper(getActivity(), this, mSelectedRoom, mSelectedStream);
|
||||
} else {
|
||||
Log.d(TAG, "No Media found, finishing");
|
||||
|
@ -181,19 +181,19 @@ public class OverlayFragment extends PlaybackFragment {
|
|||
ps.addClassPresenter(ListRow.class, new ListRowPresenter());
|
||||
mRowsAdapter = new ArrayObjectAdapter(ps);
|
||||
mRowsAdapter.add(controlsRow);
|
||||
if (eventType == DetailsActivity.TYPE_RECORDING) {
|
||||
if (eventType == DetailsActivity.Companion.getTYPE_RECORDING()) {
|
||||
if (mSelectedEvent.getMetadata() != null && mSelectedEvent.getMetadata().getRelated() != null) {
|
||||
mRowsAdapter.add(getRelatedItems());
|
||||
setOnItemViewClickedListener(new ItemViewClickedListener(this));
|
||||
}
|
||||
} else if (eventType == DetailsActivity.TYPE_STREAM) {
|
||||
} else if (eventType == DetailsActivity.Companion.getTYPE_STREAM()) {
|
||||
// TODO add other streams as related events
|
||||
}
|
||||
setAdapter(mRowsAdapter);
|
||||
|
||||
if (mCallback != null && eventType == DetailsActivity.TYPE_STREAM) {
|
||||
if (mCallback != null && eventType == DetailsActivity.Companion.getTYPE_STREAM()) {
|
||||
mCallback.setVideoSource(mSelectedStream.getUrl());
|
||||
} else if (mCallback != null && eventType == DetailsActivity.TYPE_RECORDING) {
|
||||
} else if (mCallback != null && eventType == DetailsActivity.Companion.getTYPE_RECORDING()) {
|
||||
mCallback.setVideoSource(mSelectedRecording.getRecordingUrl());
|
||||
} else {
|
||||
Log.d(TAG, "Callback not set or not event/stream");
|
||||
|
@ -255,7 +255,7 @@ public class OverlayFragment extends PlaybackFragment {
|
|||
}
|
||||
|
||||
public int getCurrentPosition() {
|
||||
if (eventType == DetailsActivity.TYPE_RECORDING) {
|
||||
if (eventType == DetailsActivity.Companion.getTYPE_RECORDING()) {
|
||||
if (mCallback != null) {
|
||||
return (int) mCallback.getCurrentPosition();
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ public class OverlayFragment extends PlaybackFragment {
|
|||
}
|
||||
|
||||
private long getCurrentPositionLong() {
|
||||
if (eventType == DetailsActivity.TYPE_RECORDING) {
|
||||
if (eventType == DetailsActivity.Companion.getTYPE_RECORDING()) {
|
||||
if (mCallback != null) {
|
||||
return mCallback.getCurrentPosition();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue