0
0
mirror of https://github.com/mediathekview/zapp.git synced 2024-09-20 04:12:14 +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"> <project version="4">
<component name="NullableNotNullManager"> <component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" /> <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"> <option name="myNullables">
<value> <value>
<list size="10"> <list size="10">

View File

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

View File

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

View File

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

View File

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