0
0
mirror of https://github.com/mediathekview/zapp.git synced 2024-09-19 20:02:17 +02:00

Make live stream reloadable by clicking error message

This commit is contained in:
Christine Emrich 2019-06-10 17:44:52 +02:00
parent e69136ba35
commit b43f9bcaed
5 changed files with 73 additions and 34 deletions

View File

@ -2,7 +2,7 @@
<project version="4">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myDefaultNotNull" value="androidx.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="10">

View File

@ -43,7 +43,7 @@ import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import timber.log.Timber;
public class ChannelDetailActivity extends FullscreenActivity {
public class ChannelDetailActivity extends FullscreenActivity implements StreamPageFragment.Listener {
private static final String EXTRA_CHANNEL_ID = "de.christinecoenen.code.zapp.EXTRA_CHANNEL_ID";
@ -85,10 +85,10 @@ public class ChannelDetailActivity extends FullscreenActivity {
private final Runnable playRunnable = this::play;
private final ChannelDetailAdapter.OnItemChangedListener onItemChangedListener =
new ChannelDetailAdapter.OnItemChangedListener() {
private final ChannelDetailAdapter.Listener channelDetailListener =
new ChannelDetailAdapter.Listener() {
@Override
public void OnItemSelected(ChannelModel channel) {
public void onItemSelected(ChannelModel channel) {
currentChannel = channel;
setTitle(channel.getName());
setColor(channel.getColor());
@ -129,7 +129,7 @@ public class ChannelDetailActivity extends FullscreenActivity {
.subscribe(ChannelDetailActivity.this::onVideoError, Timber::e);
disposable.addAll(bufferingDisposable, errorDisposable);
onItemChangedListener.OnItemSelected(currentChannel);
channelDetailListener.onItemSelected(currentChannel);
binder.movePlaybackToForeground();
}
@ -163,7 +163,7 @@ public class ChannelDetailActivity extends FullscreenActivity {
// pager
channelDetailAdapter = new ChannelDetailAdapter(
getSupportFragmentManager(), channelList, onItemChangedListener);
getSupportFragmentManager(), channelList, channelDetailListener);
viewPager.setAdapter(channelDetailAdapter);
viewPager.addOnPageChangeListener(onPageChangeListener);
viewPager.setOnClickListener(view -> mContentView.performClick());
@ -299,6 +299,12 @@ public class ChannelDetailActivity extends FullscreenActivity {
return false;
}
@Override
public void onErrorViewClicked() {
player.recreate();
player.resume();
}
private void parseIntent(Intent intent) {
Bundle extras = intent.getExtras();
//noinspection ConstantConditions

View File

@ -1,5 +1,6 @@
package de.christinecoenen.code.zapp.app.livestream.ui.detail;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
@ -12,12 +13,12 @@ import de.christinecoenen.code.zapp.model.IChannelList;
class ChannelDetailAdapter extends FragmentStatePagerAdapter {
private final IChannelList channelList;
private final OnItemChangedListener listener;
private final Listener listener;
private StreamPageFragment currentFragment;
ChannelDetailAdapter(FragmentManager fragmentManager, IChannelList channelList,
OnItemChangedListener listener) {
super(fragmentManager);
Listener listener) {
super(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
this.channelList = channelList;
this.listener = listener;
}
@ -30,6 +31,7 @@ class ChannelDetailAdapter extends FragmentStatePagerAdapter {
return channelList.get(index);
}
@NonNull
@Override
public Fragment getItem(int position) {
ChannelModel channelModel = channelList.get(position);
@ -47,7 +49,7 @@ class ChannelDetailAdapter extends FragmentStatePagerAdapter {
}
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
if (currentFragment != object) {
if (currentFragment != null) {
// tell old fragment it's no longer visible
@ -55,13 +57,13 @@ class ChannelDetailAdapter extends FragmentStatePagerAdapter {
}
currentFragment = ((StreamPageFragment) object);
listener.OnItemSelected(channelList.get(position));
listener.onItemSelected(channelList.get(position));
}
super.setPrimaryItem(container, position, object);
}
interface OnItemChangedListener {
void OnItemSelected(ChannelModel model);
interface Listener {
void onItemSelected(ChannelModel model);
}
}

View File

@ -1,6 +1,7 @@
package de.christinecoenen.code.zapp.app.livestream.ui.detail;
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
@ -32,6 +33,7 @@ public class StreamPageFragment extends Fragment {
protected TextView errorText;
private View rootView;
private Listener listener;
public static StreamPageFragment newInstance(ChannelModel channelModel) {
StreamPageFragment fragment = new StreamPageFragment();
@ -54,6 +56,8 @@ public class StreamPageFragment extends Fragment {
logoView.setContentDescription(channel.getName());
errorText.setBackgroundColor(channel.getColor());
errorText.setOnClickListener(view -> onErrorViewClick());
if (channel.getSubtitle() != null) {
subtitleText.setText(channel.getSubtitle());
}
@ -64,6 +68,23 @@ public class StreamPageFragment extends Fragment {
return rootView;
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
if (context instanceof Listener) {
listener = (Listener) context;
} else {
throw new RuntimeException("Activity must implement StreamPageFragment.Listener.");
}
}
@Override
public void onDetach() {
super.onDetach();
listener = null;
}
@Override
public void onStop() {
super.onStop();
@ -87,6 +108,11 @@ public class StreamPageFragment extends Fragment {
errorText.setText(message);
}
private void onErrorViewClick() {
listener.onErrorViewClicked();
onHide();
}
private void fadeOutLogo() {
if (rootView.getVisibility() == View.VISIBLE) {
Animation fadeOutAnimation = AnimationUtils.
@ -109,4 +135,8 @@ public class StreamPageFragment extends Fragment {
rootView.startAnimation(fadeOutAnimation);
}
}
public interface Listener {
void onErrorViewClicked();
}
}

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -11,49 +10,51 @@
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:padding="80dip"
android:layout_gravity="center">
android:padding="80dip">
<ImageView
android:id="@+id/image_channel_logo"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_gravity="center"
android:layout_weight="5"
android:adjustViewBounds="true"
android:maxWidth="500dip"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:layout_weight="5"
android:src="@drawable/channel_logo_rbb"
tools:ignore="ContentDescription"/>
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/text_channel_subtitle"
style="@style/Base.TextAppearance.AppCompat.Medium"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_gravity="center"
android:gravity="center|top"
android:layout_weight="1"
android:layout_marginTop="@dimen/activity_vertical_margin"
style="@style/Base.TextAppearance.AppCompat.Medium"
tools:text="Some Channel Subtitle"/>
android:layout_weight="1"
android:gravity="center|top"
tools:text="Some Channel Subtitle" />
</LinearLayout>
<TextView
android:id="@+id/text_error"
style="@style/Base.TextAppearance.AppCompat.Small.Inverse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingEnd="@dimen/activity_horizontal_margin"
style="@style/Base.TextAppearance.AppCompat.Small.Inverse"
android:background="@color/colorPrimary"
android:drawableEnd="@drawable/ic_refresh_white_24dp"
android:drawablePadding="@dimen/activity_horizontal_margin"
android:gravity="center"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:visibility="gone"
tools:visibility="visible"
tools:text="@string/error_stream_io"/>
tools:text="@string/error_stream_io"
tools:visibility="visible" />
</FrameLayout >
</FrameLayout>