mirror of
https://github.com/mediathekview/zapp.git
synced 2024-09-20 20:23:04 +02:00
Use view binding for ChannelDetailActivity
This commit is contained in:
parent
fad862aa62
commit
524b7e9997
@ -7,7 +7,6 @@ import android.content.Intent;
|
|||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -15,6 +14,7 @@ import android.os.IBinder;
|
|||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
@ -23,10 +23,6 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.viewpager.widget.ViewPager;
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
import butterknife.BindDrawable;
|
|
||||||
import butterknife.BindInt;
|
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.OnTouch;
|
|
||||||
import de.christinecoenen.code.zapp.R;
|
import de.christinecoenen.code.zapp.R;
|
||||||
import de.christinecoenen.code.zapp.app.ZappApplicationBase;
|
import de.christinecoenen.code.zapp.app.ZappApplicationBase;
|
||||||
import de.christinecoenen.code.zapp.app.livestream.ui.views.ProgramInfoViewBase;
|
import de.christinecoenen.code.zapp.app.livestream.ui.views.ProgramInfoViewBase;
|
||||||
@ -34,6 +30,7 @@ import de.christinecoenen.code.zapp.app.player.BackgroundPlayerService;
|
|||||||
import de.christinecoenen.code.zapp.app.player.Player;
|
import de.christinecoenen.code.zapp.app.player.Player;
|
||||||
import de.christinecoenen.code.zapp.app.player.VideoInfo;
|
import de.christinecoenen.code.zapp.app.player.VideoInfo;
|
||||||
import de.christinecoenen.code.zapp.app.settings.repository.SettingsRepository;
|
import de.christinecoenen.code.zapp.app.settings.repository.SettingsRepository;
|
||||||
|
import de.christinecoenen.code.zapp.databinding.ActivityChannelDetailBinding;
|
||||||
import de.christinecoenen.code.zapp.model.ChannelModel;
|
import de.christinecoenen.code.zapp.model.ChannelModel;
|
||||||
import de.christinecoenen.code.zapp.model.IChannelList;
|
import de.christinecoenen.code.zapp.model.IChannelList;
|
||||||
import de.christinecoenen.code.zapp.utils.system.MultiWindowHelper;
|
import de.christinecoenen.code.zapp.utils.system.MultiWindowHelper;
|
||||||
@ -50,31 +47,13 @@ public class ChannelDetailActivity extends FullscreenActivity implements StreamP
|
|||||||
|
|
||||||
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";
|
||||||
|
|
||||||
|
private Toolbar toolbar;
|
||||||
|
private ClickableViewPager viewPager;
|
||||||
|
private SwipeablePlayerView videoView;
|
||||||
|
private ProgressBar progressView;
|
||||||
|
private ProgramInfoViewBase programInfoView;
|
||||||
|
|
||||||
@BindView(R.id.toolbar)
|
private int playStreamDelayMillis;
|
||||||
protected Toolbar toolbar;
|
|
||||||
|
|
||||||
@BindView(R.id.viewpager_channels)
|
|
||||||
protected ClickableViewPager viewPager;
|
|
||||||
|
|
||||||
@BindView(R.id.video)
|
|
||||||
protected SwipeablePlayerView videoView;
|
|
||||||
|
|
||||||
@BindView(R.id.progressbar_video)
|
|
||||||
protected ProgressBar progressView;
|
|
||||||
|
|
||||||
@BindView(R.id.program_info)
|
|
||||||
protected ProgramInfoViewBase programInfoView;
|
|
||||||
|
|
||||||
|
|
||||||
@BindDrawable(android.R.drawable.ic_media_pause)
|
|
||||||
protected Drawable pauseIcon;
|
|
||||||
|
|
||||||
@BindDrawable(android.R.drawable.ic_media_play)
|
|
||||||
protected Drawable playIcon;
|
|
||||||
|
|
||||||
@BindInt(R.integer.activity_channel_detail_play_stream_delay_millis)
|
|
||||||
protected int playStreamDelayMillis;
|
|
||||||
|
|
||||||
private final Handler playHandler = new Handler();
|
private final Handler playHandler = new Handler();
|
||||||
private ChannelDetailAdapter channelDetailAdapter;
|
private ChannelDetailAdapter channelDetailAdapter;
|
||||||
@ -155,6 +134,17 @@ public class ChannelDetailActivity extends FullscreenActivity implements StreamP
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
ActivityChannelDetailBinding binding = ActivityChannelDetailBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(binding.getRoot());
|
||||||
|
|
||||||
|
toolbar = binding.toolbar;
|
||||||
|
viewPager = binding.viewpagerChannels;
|
||||||
|
videoView = binding.video;
|
||||||
|
programInfoView = binding.programInfo;
|
||||||
|
progressView = binding.progressbarVideo;
|
||||||
|
|
||||||
|
playStreamDelayMillis = getResources().getInteger(R.integer.activity_channel_detail_play_stream_delay_millis);
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
window = getWindow();
|
window = getWindow();
|
||||||
|
|
||||||
@ -170,7 +160,8 @@ public class ChannelDetailActivity extends FullscreenActivity implements StreamP
|
|||||||
getSupportFragmentManager(), channelList, channelDetailListener);
|
getSupportFragmentManager(), channelList, channelDetailListener);
|
||||||
viewPager.setAdapter(channelDetailAdapter);
|
viewPager.setAdapter(channelDetailAdapter);
|
||||||
viewPager.addOnPageChangeListener(onPageChangeListener);
|
viewPager.addOnPageChangeListener(onPageChangeListener);
|
||||||
viewPager.setOnClickListener(view -> mContentView.performClick());
|
viewPager.setOnClickListener(view -> contentView.performClick());
|
||||||
|
viewPager.setOnTouchListener(this::onPagerTouch);
|
||||||
videoView.setTouchOverlay(viewPager);
|
videoView.setTouchOverlay(viewPager);
|
||||||
|
|
||||||
parseIntent(getIntent());
|
parseIntent(getIntent());
|
||||||
@ -300,24 +291,17 @@ public class ChannelDetailActivity extends FullscreenActivity implements StreamP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getViewId() {
|
|
||||||
return R.layout.activity_channel_detail;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("SameReturnValue")
|
|
||||||
@OnTouch(R.id.viewpager_channels)
|
|
||||||
public boolean onPagerTouch() {
|
|
||||||
delayHide();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onErrorViewClicked() {
|
public void onErrorViewClicked() {
|
||||||
player.recreate();
|
player.recreate();
|
||||||
player.resume();
|
player.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean onPagerTouch(View view, MotionEvent motionEvent) {
|
||||||
|
delayHide();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void parseIntent(Intent intent) {
|
private void parseIntent(Intent intent) {
|
||||||
Bundle extras = intent.getExtras();
|
Bundle extras = intent.getExtras();
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
@ -397,6 +381,6 @@ public class ChannelDetailActivity extends FullscreenActivity implements StreamP
|
|||||||
window.setStatusBarColor(colorDarker);
|
window.setStatusBarColor(colorDarker);
|
||||||
|
|
||||||
int colorAlpha = ColorHelper.darker(ColorHelper.withAlpha(color, 150), 0.25f);
|
int colorAlpha = ColorHelper.darker(ColorHelper.withAlpha(color, 150), 0.25f);
|
||||||
mControlsView.setBackgroundColor(colorAlpha);
|
controlsView.setBackgroundColor(colorAlpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,13 @@
|
|||||||
package de.christinecoenen.code.zapp.utils.view;
|
package de.christinecoenen.code.zapp.utils.view;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import androidx.appcompat.app.ActionBar;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import butterknife.BindBool;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import butterknife.BindInt;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import butterknife.OnClick;
|
|
||||||
import de.christinecoenen.code.zapp.R;
|
import de.christinecoenen.code.zapp.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,35 +16,29 @@ import de.christinecoenen.code.zapp.R;
|
|||||||
*/
|
*/
|
||||||
public abstract class FullscreenActivity extends AppCompatActivity {
|
public abstract class FullscreenActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@BindView(R.id.fullscreen_content)
|
|
||||||
protected View mContentView;
|
|
||||||
|
|
||||||
@BindView(R.id.fullscreen_content_controls)
|
|
||||||
protected View mControlsView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the system UI should be auto-hidden after
|
* Whether or not the system UI should be auto-hidden after
|
||||||
* {@link #autoHideUiMillis} milliseconds.
|
* {@link #autoHideUiMillis} milliseconds.
|
||||||
*/
|
*/
|
||||||
@BindBool(R.bool.activity_fullscreen_auto_hide_ui)
|
private boolean autoHideUi;
|
||||||
protected boolean autoHideUi;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If {@link #autoHideUi} is set, the number of milliseconds to wait after
|
* If {@link #autoHideUi} is set, the number of milliseconds to wait after
|
||||||
* user interaction before hiding the system UI.
|
* user interaction before hiding the system UI.
|
||||||
*/
|
*/
|
||||||
@BindInt(R.integer.activity_fullscreen_auto_hide_ui_millis)
|
private int autoHideUiMillis;
|
||||||
protected int autoHideUiMillis;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some older devices needs a small delay between UI widget updates
|
* Some older devices needs a small delay between UI widget updates
|
||||||
* and a change of the status and navigation bar.
|
* and a change of the status and navigation bar.
|
||||||
*/
|
*/
|
||||||
@BindInt(R.integer.activity_fullscreen_ui_animation_delay)
|
private int uiAnimationDelay;
|
||||||
protected int uiAnimationDelay;
|
|
||||||
|
|
||||||
private final Handler mHideHandler = new Handler();
|
protected View contentView;
|
||||||
private final Runnable mHidePart2Runnable = new Runnable() {
|
protected View controlsView;
|
||||||
|
|
||||||
|
private final Handler hideHandler = new Handler();
|
||||||
|
private final Runnable hidePart2Runnable = new Runnable() {
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -58,15 +47,15 @@ public abstract class FullscreenActivity extends AppCompatActivity {
|
|||||||
// Note that some of these constants are new as of API 16 (Jelly Bean)
|
// Note that some of these constants are new as of API 16 (Jelly Bean)
|
||||||
// and API 19 (KitKat). It is safe to use them, as they are inlined
|
// and API 19 (KitKat). It is safe to use them, as they are inlined
|
||||||
// at compile-time and do nothing on earlier devices.
|
// at compile-time and do nothing on earlier devices.
|
||||||
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
|
contentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
|
||||||
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||||
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private final Runnable mShowPart2Runnable = new Runnable() {
|
private final Runnable showPart2Runnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Delayed display of UI elements
|
// Delayed display of UI elements
|
||||||
@ -74,35 +63,31 @@ public abstract class FullscreenActivity extends AppCompatActivity {
|
|||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
actionBar.show();
|
actionBar.show();
|
||||||
}
|
}
|
||||||
mControlsView.setVisibility(View.VISIBLE);
|
controlsView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private boolean mVisible;
|
|
||||||
private final Runnable mHideRunnable = this::hide;
|
|
||||||
|
|
||||||
@SuppressWarnings("SameReturnValue")
|
private boolean isVisible;
|
||||||
protected abstract int getViewId();
|
private final Runnable hideRunnable = this::hide;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
public void setContentView(View rootView) {
|
||||||
super.onCreate(savedInstanceState);
|
contentView = rootView.findViewById(R.id.fullscreen_content);
|
||||||
|
contentView.setOnClickListener(this::onFullscreenContentClick);
|
||||||
|
controlsView = rootView.findViewById(R.id.fullscreen_content_controls);
|
||||||
|
|
||||||
setContentView(getViewId());
|
autoHideUi = getResources().getBoolean(R.bool.activity_fullscreen_auto_hide_ui);
|
||||||
|
autoHideUiMillis = getResources().getInteger(R.integer.activity_fullscreen_auto_hide_ui_millis);
|
||||||
|
uiAnimationDelay = getResources().getInteger(R.integer.activity_fullscreen_ui_animation_delay);
|
||||||
|
|
||||||
ButterKnife.bind(this);
|
super.setContentView(rootView);
|
||||||
}
|
|
||||||
|
|
||||||
@OnClick(R.id.fullscreen_content)
|
|
||||||
public void onFullscreenContentClick () {
|
|
||||||
// Set up the user interaction to manually show or hide the system UI.
|
|
||||||
toggle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
mVisible = true;
|
isVisible = true;
|
||||||
|
|
||||||
// Trigger the initial hide() shortly after the activity has been
|
// Trigger the initial hide() shortly after the activity has been
|
||||||
// created, to briefly hint to the user that UI controls
|
// created, to briefly hint to the user that UI controls
|
||||||
@ -129,7 +114,7 @@ public abstract class FullscreenActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void toggle() {
|
private void toggle() {
|
||||||
if (mVisible) {
|
if (isVisible) {
|
||||||
hide();
|
hide();
|
||||||
} else {
|
} else {
|
||||||
show();
|
show();
|
||||||
@ -142,34 +127,39 @@ public abstract class FullscreenActivity extends AppCompatActivity {
|
|||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
actionBar.hide();
|
actionBar.hide();
|
||||||
}
|
}
|
||||||
mControlsView.setVisibility(View.GONE);
|
controlsView.setVisibility(View.GONE);
|
||||||
mVisible = false;
|
isVisible = false;
|
||||||
|
|
||||||
// Schedule a runnable to remove the status and navigation bar after a delay
|
// Schedule a runnable to remove the status and navigation bar after a delay
|
||||||
mHideHandler.removeCallbacks(mShowPart2Runnable);
|
hideHandler.removeCallbacks(showPart2Runnable);
|
||||||
mHideHandler.postDelayed(mHidePart2Runnable, uiAnimationDelay);
|
hideHandler.postDelayed(hidePart2Runnable, uiAnimationDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
protected void show() {
|
protected void show() {
|
||||||
// Show the system bar
|
// Show the system bar
|
||||||
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
contentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
||||||
mVisible = true;
|
isVisible = true;
|
||||||
|
|
||||||
// Schedule a runnable to display UI elements after a delay
|
// Schedule a runnable to display UI elements after a delay
|
||||||
mHideHandler.removeCallbacks(mHidePart2Runnable);
|
hideHandler.removeCallbacks(hidePart2Runnable);
|
||||||
mHideHandler.postDelayed(mShowPart2Runnable, uiAnimationDelay);
|
hideHandler.postDelayed(showPart2Runnable, uiAnimationDelay);
|
||||||
delayHide();
|
delayHide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onFullscreenContentClick(View view) {
|
||||||
|
// Set up the user interaction to manually show or hide the system UI.
|
||||||
|
toggle();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedules a call to hide() in [delay] milliseconds, canceling any
|
* Schedules a call to hide() in [delay] milliseconds, canceling any
|
||||||
* previously scheduled calls.
|
* previously scheduled calls.
|
||||||
*/
|
*/
|
||||||
private void delayedHide(int delayMillis) {
|
private void delayedHide(int delayMillis) {
|
||||||
mHideHandler.removeCallbacks(mHideRunnable);
|
hideHandler.removeCallbacks(hideRunnable);
|
||||||
mHideHandler.postDelayed(mHideRunnable, delayMillis);
|
hideHandler.postDelayed(hideRunnable, delayMillis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user