From 18c2b25cfd9cd0bda444c1bce437ab698b41d29f Mon Sep 17 00:00:00 2001 From: haha459862 <459862@163.com> Date: Sat, 2 Jul 2022 22:30:47 +0800 Subject: [PATCH] live setting support, to be continued --- .../com/github/tvbox/osc/api/ApiConfig.java | 62 +- .../github/tvbox/osc/bean/ChannelGroup.java | 58 - .../tvbox/osc/bean/LiveChannelGroup.java | 39 + ...{LiveChannel.java => LiveChannelItem.java} | 51 +- .../tvbox/osc/bean/LiveSettingGroup.java | 33 + .../tvbox/osc/bean/LiveSettingItem.java | 36 + .../player/controller/BoxVideoController.java | 17 + .../osc/ui/activity/LivePlayActivity.java | 1044 ++++++++++------- .../osc/ui/adapter/ChannelGroupAdapter.java | 34 - .../osc/ui/adapter/LiveChannelAdapter.java | 38 - .../ui/adapter/LiveChannelGroupAdapter.java | 55 + .../ui/adapter/LiveChannelItemAdapter.java | 62 + .../ui/adapter/LiveSettingGroupAdapter.java | 59 + .../ui/adapter/LiveSettingItemAdapter.java | 70 ++ .../com/github/tvbox/osc/util/HawkConfig.java | 9 +- .../main/res/layout/activity_live_play.xml | 67 +- app/src/main/res/layout/item_live_channel.xml | 2 +- ..._group.xml => item_live_channel_group.xml} | 2 +- app/src/main/res/layout/item_live_setting.xml | 24 + .../res/layout/item_live_setting_group.xml | 24 + 20 files changed, 1154 insertions(+), 632 deletions(-) delete mode 100644 app/src/main/java/com/github/tvbox/osc/bean/ChannelGroup.java create mode 100644 app/src/main/java/com/github/tvbox/osc/bean/LiveChannelGroup.java rename app/src/main/java/com/github/tvbox/osc/bean/{LiveChannel.java => LiveChannelItem.java} (53%) create mode 100644 app/src/main/java/com/github/tvbox/osc/bean/LiveSettingGroup.java create mode 100644 app/src/main/java/com/github/tvbox/osc/bean/LiveSettingItem.java delete mode 100644 app/src/main/java/com/github/tvbox/osc/ui/adapter/ChannelGroupAdapter.java delete mode 100644 app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveChannelAdapter.java create mode 100644 app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveChannelGroupAdapter.java create mode 100644 app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveChannelItemAdapter.java create mode 100644 app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveSettingGroupAdapter.java create mode 100644 app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveSettingItemAdapter.java rename app/src/main/res/layout/{item_channel_group.xml => item_live_channel_group.xml} (92%) create mode 100644 app/src/main/res/layout/item_live_setting.xml create mode 100644 app/src/main/res/layout/item_live_setting_group.xml diff --git a/app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java b/app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java index dd42ac38..f64ad514 100644 --- a/app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java +++ b/app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java @@ -8,9 +8,9 @@ import android.util.Base64; import com.github.catvod.crawler.JarLoader; import com.github.catvod.crawler.Spider; import com.github.tvbox.osc.base.App; -import com.github.tvbox.osc.bean.ChannelGroup; +import com.github.tvbox.osc.bean.LiveChannelGroup; import com.github.tvbox.osc.bean.IJKCode; -import com.github.tvbox.osc.bean.LiveChannel; +import com.github.tvbox.osc.bean.LiveChannelItem; import com.github.tvbox.osc.bean.ParseBean; import com.github.tvbox.osc.bean.SourceBean; import com.github.tvbox.osc.server.ControlManager; @@ -50,7 +50,7 @@ public class ApiConfig { private LinkedHashMap sourceBeanList; private SourceBean mHomeSource; private ParseBean mDefaultParse; - private List channelGroupList; + private List liveChannelGroupList; private List parseBeanList; private List vipParseFlags; private List ijkCodes; @@ -63,7 +63,7 @@ public class ApiConfig { private ApiConfig() { sourceBeanList = new LinkedHashMap<>(); - channelGroupList = new ArrayList<>(); + liveChannelGroupList = new ArrayList<>(); parseBeanList = new ArrayList<>(); } @@ -279,7 +279,7 @@ public class ApiConfig { setDefaultParse(parseBeanList.get(0)); } // 直播源 - channelGroupList.clear(); //修复从后台切换重复加载频道列表 + liveChannelGroupList.clear(); //修复从后台切换重复加载频道列表 try { String lives = infoJson.get("lives").getAsJsonArray().toString(); int index = lives.indexOf("proxy://"); @@ -298,9 +298,9 @@ public class ApiConfig { url = url.replace(extUrl, extUrlFix); } } - ChannelGroup channelGroup = new ChannelGroup(); - channelGroup.setGroupName(url); - channelGroupList.add(channelGroup); + LiveChannelGroup liveChannelGroup = new LiveChannelGroup(); + liveChannelGroup.setGroupName(url); + liveChannelGroupList.add(liveChannelGroup); } else { loadLives(infoJson.get("lives").getAsJsonArray()); } @@ -343,23 +343,40 @@ public class ApiConfig { } public void loadLives(JsonArray livesArray) { + liveChannelGroupList.clear(); int groupIndex = 0; int channelIndex = 0; + int channelNum = 0; for (JsonElement groupElement : livesArray) { - ChannelGroup channelGroup = new ChannelGroup(); - channelGroup.setLiveChannels(new ArrayList()); - channelGroup.setGroupNum(groupIndex++); - channelGroup.setGroupName(((JsonObject) groupElement).get("group").getAsString().trim()); + LiveChannelGroup liveChannelGroup = new LiveChannelGroup(); + liveChannelGroup.setLiveChannels(new ArrayList()); + liveChannelGroup.setGroupIndex(groupIndex++); + liveChannelGroup.setGroupName(((JsonObject) groupElement).get("group").getAsString().trim()); + channelIndex = 0; for (JsonElement channelElement : ((JsonObject) groupElement).get("channels").getAsJsonArray()) { JsonObject obj = (JsonObject) channelElement; - LiveChannel liveChannel = new LiveChannel(); - liveChannel.setChannelName(obj.get("name").getAsString().trim()); - liveChannel.setChannelNum(channelIndex++); + LiveChannelItem liveChannelItem = new LiveChannelItem(); + liveChannelItem.setChannelName(obj.get("name").getAsString().trim()); + liveChannelItem.setChannelIndex(channelIndex++); + liveChannelItem.setChannelNum(++channelNum); ArrayList urls = DefaultConfig.safeJsonStringList(obj, "urls"); - liveChannel.setChannelUrls(urls); - channelGroup.getLiveChannels().add(liveChannel); + ArrayList sourceNames = new ArrayList<>(); + ArrayList sourceUrls = new ArrayList<>(); + int sourceIndex = 1; + for (String url : urls) { + String[] splitText = url.split("\\$", 2); + sourceUrls.add(splitText[0]); + if (splitText.length > 1) + sourceNames.add(splitText[1]); + else + sourceNames.add("源" + Integer.toString(sourceIndex)); + sourceIndex++; + } + liveChannelItem.setChannelSourceNames(sourceNames); + liveChannelItem.setChannelUrls(sourceUrls); + liveChannelGroup.getLiveChannels().add(liveChannelItem); } - channelGroupList.add(channelGroup); + liveChannelGroupList.add(liveChannelGroup); } } @@ -436,13 +453,8 @@ public class ApiConfig { return mHomeSource == null ? emptyHome : mHomeSource; } - public List getChannelGroupList() { - return channelGroupList; - } - - public void setChannelGroupList(List list) { - channelGroupList.clear(); - channelGroupList.addAll(list); + public List getChannelGroupList() { + return liveChannelGroupList; } public List getIjkCodes() { diff --git a/app/src/main/java/com/github/tvbox/osc/bean/ChannelGroup.java b/app/src/main/java/com/github/tvbox/osc/bean/ChannelGroup.java deleted file mode 100644 index 2a562aa3..00000000 --- a/app/src/main/java/com/github/tvbox/osc/bean/ChannelGroup.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.github.tvbox.osc.bean; - -import java.util.ArrayList; - -public class ChannelGroup { - /** - * num : 1 - * name : 央视频道 - * password : 频道密码 - */ - private int groupNum; - private String groupName; - private String groupPassword; - private ArrayList liveChannels; - private boolean isSelected = false; - private boolean isFocused = false; - - - public int getGroupNum() { - return groupNum; - } - - public void setGroupNum(int groupNum) { - this.groupNum = groupNum; - } - - public String getGroupName() { - return groupName; - } - - public void setGroupName(String groupName) { - this.groupName = groupName; - } - - public ArrayList getLiveChannels() { - return liveChannels; - } - - public void setLiveChannels(ArrayList liveChannels) { - this.liveChannels = liveChannels; - } - - public boolean isSelected() { - return isSelected; - } - - public void setSelected(boolean selected) { - isSelected = selected; - } - - public boolean isFocused() { - return isFocused; - } - - public void setFocused(boolean focused) { - isFocused = focused; - } -} diff --git a/app/src/main/java/com/github/tvbox/osc/bean/LiveChannelGroup.java b/app/src/main/java/com/github/tvbox/osc/bean/LiveChannelGroup.java new file mode 100644 index 00000000..81ebdaf9 --- /dev/null +++ b/app/src/main/java/com/github/tvbox/osc/bean/LiveChannelGroup.java @@ -0,0 +1,39 @@ +package com.github.tvbox.osc.bean; + +import java.util.ArrayList; + +public class LiveChannelGroup { + /** + * groupIndex : 分组索引号 + * groupName : 分组名称 + * password : 分组密码 + */ + private int groupIndex; + private String groupName; + private String groupPassword; + private ArrayList liveChannelItems; + + public int getGroupIndex() { + return groupIndex; + } + + public void setGroupIndex(int groupIndex) { + this.groupIndex = groupIndex; + } + + public String getGroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } + + public ArrayList getLiveChannels() { + return liveChannelItems; + } + + public void setLiveChannels(ArrayList liveChannelItems) { + this.liveChannelItems = liveChannelItems; + } +} diff --git a/app/src/main/java/com/github/tvbox/osc/bean/LiveChannel.java b/app/src/main/java/com/github/tvbox/osc/bean/LiveChannelItem.java similarity index 53% rename from app/src/main/java/com/github/tvbox/osc/bean/LiveChannel.java rename to app/src/main/java/com/github/tvbox/osc/bean/LiveChannelItem.java index b9718402..bb567305 100644 --- a/app/src/main/java/com/github/tvbox/osc/bean/LiveChannel.java +++ b/app/src/main/java/com/github/tvbox/osc/bean/LiveChannelItem.java @@ -7,22 +7,31 @@ import java.util.ArrayList; * @date :2021/1/12 * @description: */ -public class LiveChannel { +public class LiveChannelItem { /** - * channelNum : 1 - * channelName : CCTV-1 综合 - * channelUrl : http://117.148.187.37/PLTV/88888888/224/3221226154/index.m3u8 - * channelLogo : https://upload.wikimedia.org/wikipedia/zh/6/65/CCTV-1_Logo.png + * channelIndex : 频道索引号 + * channelNum : 频道名称 + * channelSourceNames : 频道源名称 + * channelUrls : 频道源地址 + * sourceIndex : 频道源索引 + * sourceNum : 频道源总数 */ - + private int channelIndex; private int channelNum; private String channelName; + private ArrayList channelSourceNames; private ArrayList channelUrls; - private boolean isSelected = false; - private boolean isFocused = false; public int sourceIndex = 0; public int sourceNum = 0; + public void setChannelIndex(int channelIndex) { + this.channelIndex = channelIndex; + } + + public int getChannelIndex() { + return channelIndex; + } + public void setChannelNum(int channelNum) { this.channelNum = channelNum; } @@ -39,7 +48,9 @@ public class LiveChannel { return channelName; } - public ArrayList getChannelUrls() { return channelUrls; } + public ArrayList getChannelUrls() { + return channelUrls; + } public void setChannelUrls(ArrayList channelUrls) { this.channelUrls = channelUrls; @@ -54,6 +65,10 @@ public class LiveChannel { if (sourceIndex == sourceNum) sourceIndex = 0; } + public void setSourceIndex(int sourceIndex) { + this.sourceIndex = sourceIndex; + } + public int getSourceIndex() { return sourceIndex; } @@ -62,21 +77,19 @@ public class LiveChannel { return channelUrls.get(sourceIndex); } - public boolean isSelected() { - return isSelected; + public int getSourceNum() { + return sourceNum; } - public void setSelected(boolean b) { - isSelected = b; + public ArrayList getChannelSourceNames() { + return channelSourceNames; } - public int getSourceNum() { return sourceNum; } - - public boolean isFocused() { - return isFocused; + public void setChannelSourceNames(ArrayList channelSourceNames) { + this.channelSourceNames = channelSourceNames; } - public void setFocused(boolean focused) { - isFocused = focused; + public String getSourceName() { + return channelSourceNames.get(sourceIndex); } } \ No newline at end of file diff --git a/app/src/main/java/com/github/tvbox/osc/bean/LiveSettingGroup.java b/app/src/main/java/com/github/tvbox/osc/bean/LiveSettingGroup.java new file mode 100644 index 00000000..b8b25d0e --- /dev/null +++ b/app/src/main/java/com/github/tvbox/osc/bean/LiveSettingGroup.java @@ -0,0 +1,33 @@ +package com.github.tvbox.osc.bean; + +import java.util.ArrayList; + +public class LiveSettingGroup { + private int groupIndex; + private String groupName; + private ArrayList liveSettingItems; + + public int getGroupIndex() { + return groupIndex; + } + + public void setGroupIndex(int groupIndex) { + this.groupIndex = groupIndex; + } + + public String getGroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } + + public ArrayList getLiveSettingItems() { + return liveSettingItems; + } + + public void setLiveSettingItems(ArrayList liveSettingItems) { + this.liveSettingItems = liveSettingItems; + } +} diff --git a/app/src/main/java/com/github/tvbox/osc/bean/LiveSettingItem.java b/app/src/main/java/com/github/tvbox/osc/bean/LiveSettingItem.java new file mode 100644 index 00000000..741134aa --- /dev/null +++ b/app/src/main/java/com/github/tvbox/osc/bean/LiveSettingItem.java @@ -0,0 +1,36 @@ +package com.github.tvbox.osc.bean; + +/** + * @author pj567 + * @date :2021/1/12 + * @description: + */ +public class LiveSettingItem { + private int itemIndex; + private String itemName; + private boolean itemSelected = false; + + public int getItemIndex() { + return itemIndex; + } + + public void setItemIndex(int itemIndex) { + this.itemIndex = itemIndex; + } + + public String getItemName() { + return itemName; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public boolean isItemSelected() { + return itemSelected; + } + + public void setItemSelected(boolean itemSelected) { + this.itemSelected = itemSelected; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/tvbox/osc/player/controller/BoxVideoController.java b/app/src/main/java/com/github/tvbox/osc/player/controller/BoxVideoController.java index 91d3661b..d4d6ed9d 100644 --- a/app/src/main/java/com/github/tvbox/osc/player/controller/BoxVideoController.java +++ b/app/src/main/java/com/github/tvbox/osc/player/controller/BoxVideoController.java @@ -214,4 +214,21 @@ public class BoxVideoController extends GestureVideoController implements View.O } simSeekPosition = position; } + + private OnScreenLongPressListener screenLongPressListener; + + public interface OnScreenLongPressListener { + void longPress(); + } + + public void setScreenLongPressListener(OnScreenLongPressListener screenLongPressListener) { + this.screenLongPressListener = screenLongPressListener; + } + + @Override + public void onLongPress(MotionEvent e) { + if (screenLongPressListener != null) + screenLongPressListener.longPress(); + super.onLongPress(e); + } } diff --git a/app/src/main/java/com/github/tvbox/osc/ui/activity/LivePlayActivity.java b/app/src/main/java/com/github/tvbox/osc/ui/activity/LivePlayActivity.java index ce13293a..8d22c2e4 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/activity/LivePlayActivity.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/activity/LivePlayActivity.java @@ -5,10 +5,11 @@ import android.animation.AnimatorListenerAdapter; import android.animation.IntEvaluator; import android.animation.ObjectAnimator; import android.os.Handler; -import android.text.TextUtils; +import android.view.Gravity; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; +import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; @@ -21,11 +22,15 @@ import com.github.tvbox.osc.R; import com.github.tvbox.osc.api.ApiConfig; import com.github.tvbox.osc.base.App; import com.github.tvbox.osc.base.BaseActivity; -import com.github.tvbox.osc.bean.ChannelGroup; -import com.github.tvbox.osc.bean.LiveChannel; +import com.github.tvbox.osc.bean.LiveChannelGroup; +import com.github.tvbox.osc.bean.LiveChannelItem; +import com.github.tvbox.osc.bean.LiveSettingGroup; +import com.github.tvbox.osc.bean.LiveSettingItem; import com.github.tvbox.osc.player.controller.BoxVideoController; -import com.github.tvbox.osc.ui.adapter.ChannelGroupAdapter; -import com.github.tvbox.osc.ui.adapter.LiveChannelAdapter; +import com.github.tvbox.osc.ui.adapter.LiveChannelGroupAdapter; +import com.github.tvbox.osc.ui.adapter.LiveChannelItemAdapter; +import com.github.tvbox.osc.ui.adapter.LiveSettingGroupAdapter; +import com.github.tvbox.osc.ui.adapter.LiveSettingItemAdapter; import com.github.tvbox.osc.ui.tv.widget.ViewObj; import com.github.tvbox.osc.util.DefaultConfig; import com.github.tvbox.osc.util.FastClickCheckUtil; @@ -42,7 +47,11 @@ import com.orhanobut.hawk.Hawk; import com.owen.tvrecyclerview.widget.TvRecyclerView; import com.owen.tvrecyclerview.widget.V7LinearLayoutManager; +import org.json.JSONException; +import org.json.JSONObject; + import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import xyz.doikki.videocontroller.component.GestureView; @@ -55,23 +64,27 @@ import xyz.doikki.videoplayer.player.VideoView; */ public class LivePlayActivity extends BaseActivity { private VideoView mVideoView; - private TextView tvHint; - private TextView tvChannel; - private LinearLayout tvLeftLinearLayout; - private TvRecyclerView mGroupGridView; - private TvRecyclerView mChannelGridView; - private ChannelGroupAdapter groupAdapter; - private LiveChannelAdapter channelAdapter; - private Handler mHandler = new Handler(); + private TextView tvChannelInfo; + private LinearLayout tvLeftChannelListLayout; + private TvRecyclerView mChannelGroupView; + private TvRecyclerView mLiveChannelView; + private LiveChannelGroupAdapter liveChannelGroupAdapter; + private LiveChannelItemAdapter liveChannelItemAdapter; + + private LinearLayout tvRightSettingLayout; + private TvRecyclerView mSettingGroupView; + private TvRecyclerView mSettingItemView; + private LiveSettingGroupAdapter liveSettingGroupAdapter; + private LiveSettingItemAdapter liveSettingItemAdapter; + private List liveSettingGroupList = new ArrayList<>(); - private List channelGroupList = new ArrayList<>(); - private int selectedGroupIndex = 0; - private int focusedGroupIndex = 0; - private int focusedChannelIndex = 0; - private int currentGroupIndex = 0; - private int currentChannelIndex = 0; - private LiveChannel currentChannel = null; + private Handler mHandler = new Handler(); + private List liveChannelGroupList = new ArrayList<>(); + private int selectedChannelGroupIndex = 0; + private int currentChannelGroupIndex = 0; + private int currentLiveChannelIndex = 0; + private LiveChannelItem currentLiveChannelItem = null; @Override protected int getLayoutResID() { @@ -82,18 +95,269 @@ public class LivePlayActivity extends BaseActivity { protected void init() { setLoadSir(findViewById(R.id.live_root)); mVideoView = findViewById(R.id.mVideoView); - PlayerHelper.updateCfg(mVideoView); - - tvLeftLinearLayout = findViewById(R.id.tvLeftLinearLayout); - mGroupGridView = findViewById(R.id.mGroupGridView); - mChannelGridView = findViewById(R.id.mChannelGridView); - tvChannel = findViewById(R.id.tvChannel); - tvHint = findViewById(R.id.tvHint); - - mGroupGridView.setHasFixedSize(true); - mGroupGridView.setLayoutManager(new V7LinearLayoutManager(this.mContext, 1, false)); - mChannelGridView.setHasFixedSize(true); - mChannelGridView.setLayoutManager(new V7LinearLayoutManager(this.mContext, 1, false)); + getLivePlayer(); + + tvLeftChannelListLayout = findViewById(R.id.tvLeftChannnelListLayout); + mChannelGroupView = findViewById(R.id.mGroupGridView); + mLiveChannelView = findViewById(R.id.mChannelGridView); + tvRightSettingLayout = findViewById(R.id.tvRightSettingLayout); + mSettingGroupView = findViewById(R.id.mSettingGroupView); + mSettingItemView = findViewById(R.id.mSettingItemView); + tvChannelInfo = findViewById(R.id.tvChannel); + + initVideoView(); + initChannelGroupView(); + initLiveChannelView(); + initSettingGroupView(); + initSettingItemView(); + initLiveChannelList(); + initLiveSettingGroupList(); + } + + @Override + public void onBackPressed() { + if (tvLeftChannelListLayout.getVisibility() == View.VISIBLE) { + mHandler.removeCallbacks(mHideChannelListRun); + mHandler.post(mHideChannelListRun); + } + else if (tvRightSettingLayout.getVisibility() == View.VISIBLE) { + mHandler.removeCallbacks(mHideSettingLayoutRun); + mHandler.post(mHideSettingLayoutRun); + } + else { + super.onBackPressed(); + } + } + + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + if (event.getAction() == KeyEvent.ACTION_DOWN) { + int keyCode = event.getKeyCode(); + if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && !isListOrSettingLayoutVisible()) { + playNext(); + } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP && !isListOrSettingLayoutVisible()) { + playPrevious(); + } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT && !isListOrSettingLayoutVisible()) { + preSourceUrl(); + } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && !isListOrSettingLayoutVisible()) { + nextSourceUrl(); + } else if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) && !isListOrSettingLayoutVisible()) { + showChannelList(); + } else if (keyCode == KeyEvent.KEYCODE_MENU && tvRightSettingLayout.getVisibility() == View.INVISIBLE) { + showSettingGroup(); + } + } else if (event.getAction() == KeyEvent.ACTION_UP) { + } + return super.dispatchKeyEvent(event); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (mVideoView != null) { + mVideoView.release(); + } + } + + private void showChannelList() { + if (tvRightSettingLayout.getVisibility() == View.VISIBLE) { + mHandler.removeCallbacks(mHideSettingLayoutRun); + mHandler.post(mHideSettingLayoutRun); + } + if (tvLeftChannelListLayout.getVisibility() == View.INVISIBLE) { + //重新载入上一次状态 + liveChannelItemAdapter.setNewData(liveChannelGroupList.get(currentChannelGroupIndex).getLiveChannels()); + mChannelGroupView.scrollToPosition(currentChannelGroupIndex); + mChannelGroupView.setSelection(currentChannelGroupIndex); + mLiveChannelView.scrollToPosition(currentLiveChannelIndex); + mLiveChannelView.setSelection(currentLiveChannelIndex); + mHandler.postDelayed(mFocusCurrentChannelAndShowChannelList, 200); + } + } + + private Runnable mFocusCurrentChannelAndShowChannelList = new Runnable() { + @Override + public void run() { + if (mChannelGroupView.isScrolling() || mLiveChannelView.isScrolling() || mChannelGroupView.isComputingLayout() || mLiveChannelView.isComputingLayout()) { + mHandler.postDelayed(this, 100); + } else { + liveChannelGroupAdapter.setSelectedGroupIndex(currentChannelGroupIndex); + liveChannelItemAdapter.setSelectedChannelIndex(currentLiveChannelIndex); + RecyclerView.ViewHolder holder = mLiveChannelView.findViewHolderForAdapterPosition(currentLiveChannelIndex); + if (holder != null) + holder.itemView.requestFocus(); + tvLeftChannelListLayout.setVisibility(View.VISIBLE); + ViewObj viewObj = new ViewObj(tvLeftChannelListLayout, (ViewGroup.MarginLayoutParams) tvLeftChannelListLayout.getLayoutParams()); + ObjectAnimator animator = ObjectAnimator.ofObject(viewObj, "marginLeft", new IntEvaluator(), -tvLeftChannelListLayout.getLayoutParams().width, 0); + animator.setDuration(200); + animator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + mHandler.removeCallbacks(mHideChannelListRun); + mHandler.postDelayed(mHideChannelListRun, 5000); + } + }); + animator.start(); + } + } + }; + + private Runnable mHideChannelListRun = new Runnable() { + @Override + public void run() { + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) tvLeftChannelListLayout.getLayoutParams(); + if (tvLeftChannelListLayout.getVisibility() == View.VISIBLE) { + ViewObj viewObj = new ViewObj(tvLeftChannelListLayout, params); + ObjectAnimator animator = ObjectAnimator.ofObject(viewObj, "marginLeft", new IntEvaluator(), 0, -tvLeftChannelListLayout.getLayoutParams().width); + animator.setDuration(200); + animator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + tvLeftChannelListLayout.setVisibility(View.INVISIBLE); + } + }); + animator.start(); + } + } + }; + + private void showChannelInfo() { + tvChannelInfo.setText(String.format("%d %s %s(%d/%d)", currentLiveChannelItem.getChannelNum(), + currentLiveChannelItem.getChannelName(), currentLiveChannelItem.getSourceName(), + currentLiveChannelItem.getSourceIndex() + 1, currentLiveChannelItem.getSourceNum())); + + FrameLayout.LayoutParams lParams = new FrameLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); + if (tvRightSettingLayout.getVisibility() == View.VISIBLE) { + lParams.gravity = Gravity.LEFT; + lParams.leftMargin = 60; + lParams.topMargin = 30; + } else { + lParams.gravity = Gravity.RIGHT; + lParams.rightMargin = 60; + lParams.topMargin = 30; + } + tvChannelInfo.setLayoutParams(lParams); + + tvChannelInfo.setVisibility(View.VISIBLE); + mHandler.removeCallbacks(mHideChannelInfoRun); + mHandler.postDelayed(mHideChannelInfoRun, 3000); + } + + private Runnable mHideChannelInfoRun = new Runnable() { + @Override + public void run() { + tvChannelInfo.setVisibility(View.INVISIBLE); + } + }; + + private boolean playChannel(boolean changeSource) { + if (!changeSource) { + currentLiveChannelItem = liveChannelGroupList.get(currentChannelGroupIndex).getLiveChannels().get(currentLiveChannelIndex); + Hawk.put(HawkConfig.LIVE_CHANNEL, currentLiveChannelItem.getChannelName()); + } + mVideoView.release(); + mVideoView.setUrl(currentLiveChannelItem.getUrl()); + showChannelInfo(); + mVideoView.start(); + return true; + } + + private void playNext() { + currentLiveChannelIndex++; + if (currentLiveChannelIndex >= liveChannelGroupList.get(currentChannelGroupIndex).getLiveChannels().size()) + currentLiveChannelIndex = 0; + liveChannelItemAdapter.setSelectedChannelIndex(currentLiveChannelIndex); + playChannel(false); + } + + private void playPrevious() { + currentLiveChannelIndex--; + if (currentLiveChannelIndex < 0) + currentLiveChannelIndex = liveChannelGroupList.get(currentChannelGroupIndex).getLiveChannels().size() - 1; + liveChannelItemAdapter.setSelectedChannelIndex(currentLiveChannelIndex); + playChannel(false); + } + + public void preSourceUrl() { + currentLiveChannelItem.preSource(); + playChannel(true); + } + + public void nextSourceUrl() { + currentLiveChannelItem.nextSource(); + playChannel(true); + } + + //显示设置列表 + private void showSettingGroup() { + if (tvLeftChannelListLayout.getVisibility() == View.VISIBLE) { + mHandler.removeCallbacks(mHideChannelListRun); + mHandler.post(mHideChannelListRun); + } + if (tvRightSettingLayout.getVisibility() == View.INVISIBLE) { + //重新载入默认状态 + loadCurrentSourceList(); + liveSettingGroupAdapter.setNewData(liveSettingGroupList); + liveSettingItemAdapter.setNewData(liveSettingGroupList.get(0).getLiveSettingItems()); + mSettingGroupView.scrollToPosition(0); + mSettingItemView.scrollToPosition(currentLiveChannelItem.getSourceIndex()); + liveSettingGroupAdapter.setSelectedGroupIndex(0); + liveSettingItemAdapter.selectItem(currentLiveChannelItem.getSourceIndex(), true, true); + mHandler.postDelayed(mFocusAndShowSettingGroup, 200); + } + } + + private Runnable mFocusAndShowSettingGroup = new Runnable() { + @Override + public void run() { + if (mSettingGroupView.isScrolling() || mSettingItemView.isScrolling() || mSettingGroupView.isComputingLayout() || mSettingItemView.isComputingLayout()) { + mHandler.postDelayed(this, 100); + } else { + RecyclerView.ViewHolder holder = mSettingGroupView.findViewHolderForAdapterPosition(0); + if (holder != null) + holder.itemView.requestFocus(); + tvRightSettingLayout.setVisibility(View.VISIBLE); + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) tvRightSettingLayout.getLayoutParams(); + if (tvRightSettingLayout.getVisibility() == View.VISIBLE) { + ViewObj viewObj = new ViewObj(tvRightSettingLayout, params); + ObjectAnimator animator = ObjectAnimator.ofObject(viewObj, "marginRight", new IntEvaluator(), -tvRightSettingLayout.getLayoutParams().width, 0); + animator.setDuration(200); + animator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + mHandler.postDelayed(mHideSettingLayoutRun, 5000); + } + }); + animator.start(); + } + } + } + }; + + private Runnable mHideSettingLayoutRun = new Runnable() { + @Override + public void run() { + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) tvRightSettingLayout.getLayoutParams(); + if (tvRightSettingLayout.getVisibility() == View.VISIBLE) { + ViewObj viewObj = new ViewObj(tvRightSettingLayout, params); + ObjectAnimator animator = ObjectAnimator.ofObject(viewObj, "marginRight", new IntEvaluator(), 0, -tvRightSettingLayout.getLayoutParams().width); + animator.setDuration(200); + animator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + tvRightSettingLayout.setVisibility(View.INVISIBLE); + } + }); + animator.start(); + } + } + }; + + private void initVideoView() { BoxVideoController controller = new BoxVideoController(this); controller.setScreenTapListener(new BoxVideoController.OnScreenTapListener() { @Override @@ -101,16 +365,27 @@ public class LivePlayActivity extends BaseActivity { showChannelList(); } }); + controller.setScreenLongPressListener(new BoxVideoController.OnScreenLongPressListener() { + @Override + public void longPress() { + showSettingGroup(); + } + }); controller.addControlComponent(new GestureView(this)); controller.setCanChangePosition(false); controller.setEnableInNormal(true); controller.setGestureEnabled(true); mVideoView.setVideoController(controller); mVideoView.setProgressManager(null); + } + + private void initChannelGroupView() { + mChannelGroupView.setHasFixedSize(true); + mChannelGroupView.setLayoutManager(new V7LinearLayoutManager(this.mContext, 1, false)); - groupAdapter = new ChannelGroupAdapter(); - mGroupGridView.setAdapter(groupAdapter); - mGroupGridView.addOnScrollListener(new RecyclerView.OnScrollListener() { + liveChannelGroupAdapter = new LiveChannelGroupAdapter(); + mChannelGroupView.setAdapter(liveChannelGroupAdapter); + mChannelGroupView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); @@ -120,52 +395,44 @@ public class LivePlayActivity extends BaseActivity { }); //电视 - mGroupGridView.setOnItemListener(new TvRecyclerView.OnItemListener() { + mChannelGroupView.setOnItemListener(new TvRecyclerView.OnItemListener() { @Override public void onItemPreSelected(TvRecyclerView parent, View itemView, int position) { } @Override public void onItemSelected(TvRecyclerView parent, View itemView, int position) { - focusChannelGroup(position); - if (position == selectedGroupIndex) return; - selectChannelGroup(position); - channelAdapter.setNewData(channelGroupList.get(position).getLiveChannels()); - if (position == currentGroupIndex) - mChannelGridView.scrollToPosition(currentChannelIndex); - else - mChannelGridView.scrollToPosition(0); - mHandler.removeCallbacks(mHideChannelListRun); - mHandler.postDelayed(mHideChannelListRun, 5000); + liveChannelGroupAdapter.setSelectedGroupIndex(position); + liveChannelGroupAdapter.setFocusedGroupIndex(position); + liveChannelItemAdapter.setFocusedChannelIndex(-1); + if (position == selectedChannelGroupIndex || position < -1) return; + channelGroupClick(position); } @Override public void onItemClick(TvRecyclerView parent, View itemView, int position) { - channelAdapter.setNewData(channelGroupList.get(position).getLiveChannels()); - mHandler.removeCallbacks(mHideChannelListRun); - mHandler.postDelayed(mHideChannelListRun, 5000); } }); //手机/模拟器 - groupAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { + liveChannelGroupAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { @Override public void onItemClick(BaseQuickAdapter adapter, View view, int position) { FastClickCheckUtil.check(view); - selectChannelGroup(position); - channelAdapter.setNewData(channelGroupList.get(position).getLiveChannels()); - if (position == currentGroupIndex) - mChannelGridView.scrollToPosition(currentChannelIndex); - else - mChannelGridView.scrollToPosition(0); - mHandler.removeCallbacks(mHideChannelListRun); - mHandler.postDelayed(mHideChannelListRun, 5000); + if (position == selectedChannelGroupIndex) return; + liveChannelGroupAdapter.setSelectedGroupIndex(position); + channelGroupClick(position); } }); + } + + private void initLiveChannelView() { + mLiveChannelView.setHasFixedSize(true); + mLiveChannelView.setLayoutManager(new V7LinearLayoutManager(this.mContext, 1, false)); - channelAdapter = new LiveChannelAdapter(); - mChannelGridView.setAdapter(channelAdapter); - mChannelGridView.addOnScrollListener(new RecyclerView.OnScrollListener() { + liveChannelItemAdapter = new LiveChannelItemAdapter(); + mLiveChannelView.setAdapter(liveChannelItemAdapter); + mLiveChannelView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); @@ -175,150 +442,234 @@ public class LivePlayActivity extends BaseActivity { }); //电视 - mChannelGridView.setOnItemListener(new TvRecyclerView.OnItemListener() { + mLiveChannelView.setOnItemListener(new TvRecyclerView.OnItemListener() { @Override public void onItemPreSelected(TvRecyclerView parent, View itemView, int position) { - } @Override public void onItemSelected(TvRecyclerView parent, View itemView, int position) { if (position < 0) return; - focusLiveChannel(position); + liveChannelGroupAdapter.setFocusedGroupIndex(-1); + liveChannelItemAdapter.setFocusedChannelIndex(position); mHandler.removeCallbacks(mHideChannelListRun); mHandler.postDelayed(mHideChannelListRun, 5000); } @Override public void onItemClick(TvRecyclerView parent, View itemView, int position) { - if (selectedGroupIndex == currentGroupIndex && position == currentChannelIndex) + if (selectedChannelGroupIndex == currentChannelGroupIndex && position == currentLiveChannelIndex) return; - if (playChannel(position, false)) { - mHandler.post(mHideChannelListRun); - } + liveChannelClick(position); } }); //手机/模拟器 - channelAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { + liveChannelItemAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { @Override public void onItemClick(BaseQuickAdapter adapter, View view, int position) { FastClickCheckUtil.check(view); - if (selectedGroupIndex == currentGroupIndex && position == currentChannelIndex) + if (selectedChannelGroupIndex == currentChannelGroupIndex && position == currentLiveChannelIndex) return; - if (playChannel(position, false)) { - mHandler.post(mHideChannelListRun); - } + liveChannelClick(position); } }); + } - initChannelListView(); + private void channelGroupClick(int position) { + selectedChannelGroupIndex = position; + liveChannelItemAdapter.setNewData(liveChannelGroupList.get(position).getLiveChannels()); + if (position == currentChannelGroupIndex) { + mLiveChannelView.scrollToPosition(currentLiveChannelIndex); + liveChannelItemAdapter.setSelectedChannelIndex(currentLiveChannelIndex); + } + else { + mLiveChannelView.scrollToPosition(0); + liveChannelItemAdapter.setSelectedChannelIndex(-1); + } + mHandler.removeCallbacks(mHideChannelListRun); + mHandler.postDelayed(mHideChannelListRun, 5000); } - @Override - public void onBackPressed() { - if (tvLeftLinearLayout.getVisibility() == View.VISIBLE) { + private void liveChannelClick(int position) { + currentChannelGroupIndex = selectedChannelGroupIndex; + currentLiveChannelIndex = position; + liveChannelItemAdapter.setSelectedChannelIndex(position); + if (playChannel(false)) { mHandler.post(mHideChannelListRun); - } else { - super.onBackPressed(); } } - @Override - public boolean dispatchKeyEvent(KeyEvent event) { - if (event.getAction() == KeyEvent.ACTION_DOWN) { - int keyCode = event.getKeyCode(); - if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && tvLeftLinearLayout.getVisibility() == View.INVISIBLE) { - playNext(); - } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP && tvLeftLinearLayout.getVisibility() == View.INVISIBLE) { - playPrevious(); - } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT && tvLeftLinearLayout.getVisibility() == View.INVISIBLE) { - preSourceUrl(); - } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && tvLeftLinearLayout.getVisibility() == View.INVISIBLE) { - nextSourceUrl(); - } else if (((Hawk.get(HawkConfig.DEBUG_OPEN, false) && keyCode == KeyEvent.KEYCODE_0) || keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE/* || keyCode == KeyEvent.KEYCODE_0*/) && tvLeftLinearLayout.getVisibility() == View.INVISIBLE) { - showChannelList(); - } else if (tvLeftLinearLayout.getVisibility() == View.INVISIBLE) { - switch (keyCode) { - case KeyEvent.KEYCODE_0: - inputChannelNum("0"); - break; - case KeyEvent.KEYCODE_1: - inputChannelNum("1"); - break; - case KeyEvent.KEYCODE_2: - inputChannelNum("2"); - break; - case KeyEvent.KEYCODE_3: - inputChannelNum("3"); - break; - case KeyEvent.KEYCODE_4: - inputChannelNum("4"); - break; - case KeyEvent.KEYCODE_5: - inputChannelNum("5"); - break; - case KeyEvent.KEYCODE_6: - inputChannelNum("6"); - break; - case KeyEvent.KEYCODE_7: - inputChannelNum("7"); - break; - case KeyEvent.KEYCODE_8: - inputChannelNum("8"); - break; - case KeyEvent.KEYCODE_9: - inputChannelNum("9"); - break; - } + private void initSettingGroupView() { + mSettingGroupView.setHasFixedSize(true); + mSettingGroupView.setLayoutManager(new V7LinearLayoutManager(this.mContext, 1, false)); + + liveSettingGroupAdapter = new LiveSettingGroupAdapter(); + mSettingGroupView.setAdapter(liveSettingGroupAdapter); + mSettingGroupView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { + super.onScrollStateChanged(recyclerView, newState); + mHandler.removeCallbacks(mHideSettingLayoutRun); + mHandler.postDelayed(mHideSettingLayoutRun, 5000); } - } else if (event.getAction() == KeyEvent.ACTION_UP) { - if (tvLeftLinearLayout.getVisibility() == View.VISIBLE) { -// mHandler.postDelayed(mHideChannelListRun, 5000); + }); + + //电视 + mSettingGroupView.setOnItemListener(new TvRecyclerView.OnItemListener() { + @Override + public void onItemPreSelected(TvRecyclerView parent, View itemView, int position) { } - } - return super.dispatchKeyEvent(event); + + @Override + public void onItemSelected(TvRecyclerView parent, View itemView, int position) { + liveSettingGroupAdapter.setFocusedGroupIndex(position); + liveSettingItemAdapter.setFocusedItemIndex(-1); + if (position == liveSettingGroupAdapter.getSelectedGroupIndex() || position < -1) + return; + settingGroupClick(position); + } + + @Override + public void onItemClick(TvRecyclerView parent, View itemView, int position) { + } + }); + + //手机/模拟器 + liveSettingGroupAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { + @Override + public void onItemClick(BaseQuickAdapter adapter, View view, int position) { + FastClickCheckUtil.check(view); + if (position == liveSettingGroupAdapter.getSelectedGroupIndex()) + return; + settingGroupClick(position); + } + }); } - @Override - protected void onResume() { - super.onResume(); - if (mVideoView != null) { - mVideoView.resume(); - } - if (tvLeftLinearLayout.getVisibility() == View.VISIBLE) { - mHandler.postDelayed(mHideChannelListRun, 5000); - } + private void initSettingItemView() { + mSettingItemView.setHasFixedSize(true); + mSettingItemView.setLayoutManager(new V7LinearLayoutManager(this.mContext, 1, false)); + + liveSettingItemAdapter = new LiveSettingItemAdapter(); + mSettingItemView.setAdapter(liveSettingItemAdapter); + mSettingItemView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { + super.onScrollStateChanged(recyclerView, newState); + mHandler.removeCallbacks(mHideSettingLayoutRun); + mHandler.postDelayed(mHideSettingLayoutRun, 5000); + } + }); + + //电视 + mSettingItemView.setOnItemListener(new TvRecyclerView.OnItemListener() { + @Override + public void onItemPreSelected(TvRecyclerView parent, View itemView, int position) { + } + + @Override + public void onItemSelected(TvRecyclerView parent, View itemView, int position) { + if (position < 0) return; + liveSettingGroupAdapter.setFocusedGroupIndex(-1); + liveSettingItemAdapter.setFocusedItemIndex(position); + mHandler.removeCallbacks(mHideSettingLayoutRun); + mHandler.postDelayed(mHideSettingLayoutRun, 5000); + } + + @Override + public void onItemClick(TvRecyclerView parent, View itemView, int position) { + int settingGroupIndex = liveSettingGroupAdapter.getSelectedGroupIndex(); + if (settingGroupIndex < 4) { + if (position == liveSettingItemAdapter.getSelectedItemIndex()) + return; + liveSettingItemAdapter.selectItem(position, true, true); + } + settingItemClick(settingGroupIndex, position); + } + }); + + //手机/模拟器 + liveSettingItemAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { + @Override + public void onItemClick(BaseQuickAdapter adapter, View view, int position) { + FastClickCheckUtil.check(view); + int settingGroupIndex = liveSettingGroupAdapter.getSelectedGroupIndex(); + if (settingGroupIndex < 4) { + if (position == liveSettingItemAdapter.getSelectedItemIndex()) + return; + liveSettingItemAdapter.selectItem(position, true, true); + } + settingItemClick(settingGroupIndex, position); + } + }); } - @Override - protected void onPause() { - super.onPause(); - if (mVideoView != null) { - mVideoView.pause(); - } - mHandler.removeCallbacksAndMessages(null); + private void settingGroupClick(int position) { + liveSettingGroupAdapter.setSelectedGroupIndex(position); + liveSettingItemAdapter.setNewData(liveSettingGroupList.get(position).getLiveSettingItems()); + if (position == 0) + liveSettingItemAdapter.selectItem(currentLiveChannelItem.getSourceIndex(), true, false); + int scrollToPosition = liveSettingItemAdapter.getSelectedItemIndex(); + if (scrollToPosition < 0) scrollToPosition = 0; + mSettingItemView.scrollToPosition(scrollToPosition); + mHandler.removeCallbacks(mHideSettingLayoutRun); + mHandler.postDelayed(mHideSettingLayoutRun, 5000); } - @Override - protected void onDestroy() { - super.onDestroy(); - if (mVideoView != null) { - mVideoView.release(); + private void settingItemClick(int settingGroupIndex, int position) { + switch (settingGroupIndex) { + case 0://线路切换 + currentLiveChannelItem.setSourceIndex(position); + playChannel(true); + break; + case 1://画面比例 + Hawk.put(HawkConfig.LIVE_PLAYER_SCALE, position); + mVideoView.setScreenScaleType(position); + break; + case 2://播放解码 + Hawk.put(HawkConfig.LIVE_PLAYER_TYPE, position); + getLivePlayer(); + break; + case 3://超时换源 + Hawk.put(HawkConfig.LIVE_CONNECT_TIMEOUT, position); + break; + case 4://超时换源 + switch (position) { + case 0: + Hawk.put(HawkConfig.LIVE_SHOW_TIME, false); + break; + case 1: + Hawk.put(HawkConfig.LIVE_SHOW_NET_SPEED, false); + break; + case 2: + Hawk.put(HawkConfig.LIVE_CHANNEL_REVERSE, false); + break; + case 3: + Hawk.put(HawkConfig.LIVE_CROSS_GROUP, false); + break; + } + break; } + mHandler.removeCallbacks(mHideSettingLayoutRun); + mHandler.postDelayed(mHideSettingLayoutRun, 5000); } - private void initChannelListView() { - List list = ApiConfig.get().getChannelGroupList(); - if (list.isEmpty()) + private void initLiveChannelList() { + List list = ApiConfig.get().getChannelGroupList(); + if (list.isEmpty()) { + Toast.makeText(App.getInstance(), "频道列表为空", Toast.LENGTH_SHORT).show(); + finish(); return; + } if (list.size() == 1 && list.get(0).getGroupName().startsWith("http://127.0.0.1")) { showLoading(); loadProxyLives(list.get(0).getGroupName()); - } else { - channelGroupList.clear(); - channelGroupList.addAll(list); + } + else { + liveChannelGroupList.clear(); + liveChannelGroupList.addAll(list); showSuccess(); initLiveState(); } @@ -334,14 +685,17 @@ public class LivePlayActivity extends BaseActivity { @Override public void onSuccess(Response response) { - List list = new ArrayList<>(); + List list = new ArrayList<>(); JsonArray livesArray = new Gson().fromJson(response.body(), JsonArray.class); - loadLives(livesArray); - if (channelGroupList == null || channelGroupList.size() == 0) { + ApiConfig.get().loadLives(livesArray); + liveChannelGroupList.clear(); + liveChannelGroupList.addAll(ApiConfig.get().getChannelGroupList()); + if (liveChannelGroupList == null || liveChannelGroupList.size() == 0) { Toast.makeText(App.getInstance(), "频道列表为空", Toast.LENGTH_SHORT).show(); finish(); return; } + mHandler.post(new Runnable() { @Override public void run() { @@ -353,303 +707,123 @@ public class LivePlayActivity extends BaseActivity { }); } - public void loadLives(JsonArray livesArray) { - int groupNum = 1; - int channelNum = 1; - for (JsonElement groupElement : livesArray) { - ChannelGroup channelGroup = new ChannelGroup(); - channelGroup.setLiveChannels(new ArrayList()); - channelGroup.setGroupNum(groupNum++); - channelGroup.setGroupName(((JsonObject) groupElement).get("group").getAsString().trim()); - for (JsonElement channelElement : ((JsonObject) groupElement).get("channels").getAsJsonArray()) { - JsonObject obj = (JsonObject) channelElement; - LiveChannel liveChannel = new LiveChannel(); - liveChannel.setChannelName(obj.get("name").getAsString().trim()); - liveChannel.setChannelNum(channelNum++); - ArrayList urls = DefaultConfig.safeJsonStringList(obj, "urls"); - liveChannel.setChannelUrls(urls); - channelGroup.getLiveChannels().add(liveChannel); - } - channelGroupList.add(channelGroup); - } - ApiConfig.get().setChannelGroupList(channelGroupList); - } - private void initLiveState() { String lastChannelName = Hawk.get(HawkConfig.LIVE_CHANNEL, ""); - int groupIndex = 0; - int channelIndex = 0; - boolean bFound = false; - for (ChannelGroup channelGroup : channelGroupList) { - for (LiveChannel liveChannel : channelGroup.getLiveChannels()) { - if (liveChannel.getChannelName().equals(lastChannelName)) { - bFound = true; + boolean found = false; + for (LiveChannelGroup liveChannelGroup : liveChannelGroupList) { + for (LiveChannelItem liveChannelItem : liveChannelGroup.getLiveChannels()) { + if (liveChannelItem.getChannelName().equals(lastChannelName)) { + found = true; + currentChannelGroupIndex = liveChannelGroup.getGroupIndex(); + currentLiveChannelIndex = liveChannelItem.getChannelIndex(); + selectedChannelGroupIndex = currentChannelGroupIndex; break; } - channelIndex++; - } - if (bFound) { - selectedGroupIndex = groupIndex; - currentGroupIndex = groupIndex; - currentChannelIndex = channelIndex; - focusedGroupIndex = groupIndex; - focusedChannelIndex = channelIndex; - break; } - groupIndex++; - channelIndex = 0; + if (found) break; } - tvLeftLinearLayout.setVisibility(View.INVISIBLE); - tvHint.setVisibility(View.INVISIBLE); -// tvUrl.setVisibility(Hawk.get(HawkConfig.DEBUG_OPEN, false) ? View.VISIBLE : View.INVISIBLE); + tvLeftChannelListLayout.setVisibility(View.INVISIBLE); + tvRightSettingLayout.setVisibility(View.INVISIBLE); - groupAdapter.setNewData(channelGroupList); - channelAdapter.setNewData(channelGroupList.get(currentGroupIndex).getLiveChannels()); - mGroupGridView.scrollToPosition(currentGroupIndex); - mChannelGridView.scrollToPosition(currentChannelIndex); - selectChannelGroup(currentGroupIndex); + liveChannelGroupAdapter.setNewData(liveChannelGroupList); + liveChannelItemAdapter.setNewData(liveChannelGroupList.get(currentChannelGroupIndex).getLiveChannels()); + mChannelGroupView.scrollToPosition(currentChannelGroupIndex); + mLiveChannelView.scrollToPosition(currentLiveChannelIndex); + liveChannelGroupAdapter.setSelectedGroupIndex(currentChannelGroupIndex); + liveChannelItemAdapter.setSelectedChannelIndex(currentLiveChannelIndex); - playChannel(currentChannelIndex, false); + playChannel(false); } - private void refreshTextInfo() { - tvChannel.setText(String.format("%d", currentChannel.getChannelNum())); + private boolean isListOrSettingLayoutVisible() { + return tvLeftChannelListLayout.getVisibility() == View.VISIBLE || tvRightSettingLayout.getVisibility() == View.VISIBLE; } - private Runnable mHideChannelListRun = new Runnable() { - @Override - public void run() { - ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) tvLeftLinearLayout.getLayoutParams(); - if (tvLeftLinearLayout.getVisibility() == View.VISIBLE) { - ViewObj viewObj = new ViewObj(tvLeftLinearLayout, params); - ObjectAnimator animator = ObjectAnimator.ofObject(viewObj, "marginLeft", new IntEvaluator(), 0, -tvLeftLinearLayout.getLayoutParams().width); - animator.setDuration(200); - animator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - if (channelGroupList.size() > 0) { //修复未配置接口,进入直播会导致崩溃 - deselectChannelGroup(selectedGroupIndex); - if (focusedGroupIndex > -1) { - defocusChannelGroup(focusedGroupIndex); - focusedGroupIndex = -1; - } - if (focusedChannelIndex > -1) { - defocusLiveChannel(focusedChannelIndex); - focusedChannelIndex = -1; - } - } - tvLeftLinearLayout.setVisibility(View.INVISIBLE); - tvHint.setVisibility(View.INVISIBLE); - } - }); - animator.start(); - } - } - }; - - private Runnable mPlayUserInputChannelRun = new Runnable() { - @Override - public void run() { - if (!TextUtils.isEmpty(userInputChannelNum)) { - playChannelByNum(Integer.parseInt(userInputChannelNum)); - userInputChannelNum = ""; + private void initLiveSettingGroupList() { + ArrayList groupNames = new ArrayList(Arrays.asList("线路选择", "画面比例", "播放解码", "超时换源", "偏好设置")); + ArrayList> itemsArrayList = new ArrayList<>(); + ArrayList sourceItems = new ArrayList(); + ArrayList scaleItems = new ArrayList(Arrays.asList("默认", "16:9", "4:3", "填充", "原始", "裁剪")); + ArrayList playerDecoderItems = new ArrayList(Arrays.asList("系统", "ijk硬解", "ijk软解", "exo")); + ArrayList timeoutItems = new ArrayList(Arrays.asList("5s", "10s", "15s", "20s", "25s", "30s")); + ArrayList personalSettingItems = new ArrayList(Arrays.asList("显示时间", "显示网速", "换台反转", "跨选分类")); + itemsArrayList.add(sourceItems); + itemsArrayList.add(scaleItems); + itemsArrayList.add(playerDecoderItems); + itemsArrayList.add(timeoutItems); + itemsArrayList.add(personalSettingItems); + + liveSettingGroupList.clear(); + for (int i = 0; i < groupNames.size(); i++) { + LiveSettingGroup liveSettingGroup = new LiveSettingGroup(); + ArrayList liveSettingItemList = new ArrayList<>(); + liveSettingGroup.setGroupIndex(i); + liveSettingGroup.setGroupName(groupNames.get(i)); + for (int j = 0; j < itemsArrayList.get(i).size(); j++) { + LiveSettingItem liveSettingItem = new LiveSettingItem(); + liveSettingItem.setItemIndex(j); + liveSettingItem.setItemName(itemsArrayList.get(i).get(j)); + liveSettingItemList.add(liveSettingItem); } - mHandler.postDelayed(mHideChannelNumRun, 4000); - } - }; - - private Runnable mHideChannelNumRun = new Runnable() { - @Override - public void run() { - tvChannel.setVisibility(View.INVISIBLE); - refreshTextInfo(); - } - }; - - private Runnable mFocusCurrentChannelAndShowChannelList = new Runnable() { - @Override - public void run() { - if (mGroupGridView.isScrolling() || mChannelGridView.isScrolling()) { - mHandler.postDelayed(this, 100); - } else { - RecyclerView.ViewHolder holder = mChannelGridView.findViewHolderForAdapterPosition(currentChannelIndex); - if (holder != null) - holder.itemView.requestFocus(); - ViewObj viewObj = new ViewObj(tvLeftLinearLayout, (ViewGroup.MarginLayoutParams) tvLeftLinearLayout.getLayoutParams()); - ObjectAnimator animator = ObjectAnimator.ofObject(viewObj, "marginLeft", new IntEvaluator(), -tvLeftLinearLayout.getLayoutParams().width, 0); - animator.setDuration(200); - animator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - } - }); - animator.start(); - mHandler.removeCallbacks(mHideChannelListRun); - mHandler.postDelayed(mHideChannelListRun, 5000); - } - } - }; - - private void showChannelList() { - if (tvLeftLinearLayout.getVisibility() == View.INVISIBLE) { - tvHint.setVisibility(View.VISIBLE); - tvLeftLinearLayout.setVisibility(View.VISIBLE); - - //重新载入上一次状态 - channelAdapter.setNewData(channelGroupList.get(currentGroupIndex).getLiveChannels()); - mGroupGridView.scrollToPosition(currentGroupIndex); - mChannelGridView.scrollToPosition(currentChannelIndex); - mGroupGridView.setSelection(currentGroupIndex); - mChannelGridView.setSelection(currentChannelIndex); - selectChannelGroup(currentGroupIndex); - selectLiveChannel(currentChannelIndex); - mHandler.postDelayed(mFocusCurrentChannelAndShowChannelList, 200); + liveSettingGroup.setLiveSettingItems(liveSettingItemList); + liveSettingGroupList.add(liveSettingGroup); } + liveSettingGroupList.get(1).getLiveSettingItems().get(Hawk.get(HawkConfig.LIVE_PLAYER_SCALE, 0)).setItemSelected(true); + liveSettingGroupList.get(2).getLiveSettingItems().get(Hawk.get(HawkConfig.LIVE_PLAYER_TYPE, 1)).setItemSelected(true); + liveSettingGroupList.get(3).getLiveSettingItems().get(Hawk.get(HawkConfig.LIVE_CONNECT_TIMEOUT, 1)).setItemSelected(true); + liveSettingGroupList.get(4).getLiveSettingItems().get(0).setItemSelected(Hawk.get(HawkConfig.LIVE_SHOW_TIME, false)); + liveSettingGroupList.get(4).getLiveSettingItems().get(1).setItemSelected(Hawk.get(HawkConfig.LIVE_SHOW_NET_SPEED, false)); + liveSettingGroupList.get(4).getLiveSettingItems().get(2).setItemSelected(Hawk.get(HawkConfig.LIVE_CHANNEL_REVERSE, false)); + liveSettingGroupList.get(4).getLiveSettingItems().get(3).setItemSelected(Hawk.get(HawkConfig.LIVE_CROSS_GROUP, false)); } - private String userInputChannelNum = ""; - - private void inputChannelNum(String add) { - if (userInputChannelNum.length() < 4) { - mHandler.removeCallbacks(mPlayUserInputChannelRun); - mHandler.removeCallbacks(mHideChannelNumRun); - tvChannel.setVisibility(View.VISIBLE); - userInputChannelNum = String.format("%s%s", userInputChannelNum, add); - tvChannel.setText(userInputChannelNum); - mHandler.postDelayed(mPlayUserInputChannelRun, 1000); + private void loadCurrentSourceList() { + ArrayList currentSourceNames = currentLiveChannelItem.getChannelSourceNames(); + ArrayList liveSettingItemList = new ArrayList<>(); + for (int j = 0; j < currentSourceNames.size(); j++) { + LiveSettingItem liveSettingItem = new LiveSettingItem(); + liveSettingItem.setItemIndex(j); + liveSettingItem.setItemName(currentSourceNames.get(j)); + liveSettingItemList.add(liveSettingItem); } + liveSettingGroupList.get(0).setLiveSettingItems(liveSettingItemList); } - private void showChannelNum() { - refreshTextInfo(); - tvChannel.setVisibility(View.VISIBLE); - mHandler.postDelayed(mHideChannelNumRun, 4000); - } - - private boolean playChannel(int channelIndex, boolean changeSource) { - if (!changeSource) { - selectLiveChannel(channelIndex); - currentChannel = channelGroupList.get(currentGroupIndex).getLiveChannels().get(currentChannelIndex); - showChannelNum(); - Hawk.put(HawkConfig.LIVE_CHANNEL, currentChannel.getChannelName()); - } - mVideoView.release(); - mVideoView.setUrl(currentChannel.getUrl()); - mVideoView.start(); - return true; - } - - private boolean playChannelByNum(int channelNum) { - int groupIndex = 0; - int channelIndex = 0; - boolean bFound = false; - for (ChannelGroup channelGroup : channelGroupList) { - for (LiveChannel liveChannel : channelGroup.getLiveChannels()) { - if (liveChannel.getChannelNum() == channelNum) { - if (groupIndex == currentGroupIndex && channelIndex == currentChannelIndex) - return true; - else { - selectChannelGroup(groupIndex); - return playChannel(channelIndex, false); - } + private void getLivePlayer() { + if (mVideoView != null) { + mVideoView.release(); + JSONObject mVodPlayerCfg = new JSONObject(); + try { + switch (Hawk.get(HawkConfig.LIVE_PLAYER_TYPE, 1)) { + case 0: + mVodPlayerCfg.put("pl", 0); + mVodPlayerCfg.put("ijk", "软解码"); + break; + case 1: + mVodPlayerCfg.put("pl", 1); + mVodPlayerCfg.put("ijk", "硬解码"); + break; + case 2: + mVodPlayerCfg.put("pl", 1); + mVodPlayerCfg.put("ijk", "软解码"); + break; + case 3: + mVodPlayerCfg.put("pl", 2); + mVodPlayerCfg.put("ijk", "软解码"); + break; } - channelIndex++; + mVodPlayerCfg.put("pr", Hawk.get(HawkConfig.PLAY_RENDER, 0)); + mVodPlayerCfg.put("sc", Hawk.get(HawkConfig.LIVE_PLAYER_SCALE, 0)); + } catch (JSONException e) { + e.printStackTrace(); + } + PlayerHelper.updateCfg(mVideoView, mVodPlayerCfg); + if (currentLiveChannelItem != null) { + mVideoView.setUrl(currentLiveChannelItem.getUrl()); + mVideoView.start(); } - groupIndex++; - channelIndex = 0; - } - return false; - } - - private void playNext() { - int newChannelIndex = currentChannelIndex; - newChannelIndex++; - if (newChannelIndex >= channelGroupList.get(currentGroupIndex).getLiveChannels().size()) - newChannelIndex = 0; - - playChannel(newChannelIndex, false); - } - - private void playPrevious() { - int newChannelIndex = currentChannelIndex; - newChannelIndex--; - if (newChannelIndex < 0) - newChannelIndex = channelGroupList.get(currentGroupIndex).getLiveChannels().size() - 1; - - playChannel(newChannelIndex, false); - } - - public void preSourceUrl() { - currentChannel.preSource(); - playChannel(currentChannelIndex, true); - } - - public void nextSourceUrl() { - currentChannel.nextSource(); - playChannel(currentChannelIndex, true); - } - - public void selectChannelGroup(int groupIndex) { - channelGroupList.get(selectedGroupIndex).setSelected(false); - groupAdapter.notifyItemChanged(selectedGroupIndex); - selectedGroupIndex = groupIndex; - channelGroupList.get(selectedGroupIndex).setSelected(true); - groupAdapter.notifyItemChanged(selectedGroupIndex); - } - - public void deselectChannelGroup(int groupIndex) { - channelGroupList.get(groupIndex).setSelected(false); - groupAdapter.notifyItemChanged(groupIndex); - } - - public void selectLiveChannel(int channelIndex) { - channelGroupList.get(currentGroupIndex).getLiveChannels().get(currentChannelIndex).setSelected(false); - channelAdapter.notifyItemChanged(currentChannelIndex); - currentChannelIndex = channelIndex; - currentGroupIndex = selectedGroupIndex; - channelGroupList.get(currentGroupIndex).getLiveChannels().get(currentChannelIndex).setSelected(true); - channelAdapter.notifyItemChanged(currentChannelIndex); - } - - public void focusChannelGroup(int groupIndex) { - if (focusedChannelIndex > -1) { - defocusLiveChannel(focusedChannelIndex); - focusedChannelIndex = -1; - } - if (focusedGroupIndex > -1) { - channelGroupList.get(focusedGroupIndex).setFocused(false); - groupAdapter.notifyItemChanged(focusedGroupIndex); - } - focusedGroupIndex = groupIndex; - channelGroupList.get(focusedGroupIndex).setFocused(true); - groupAdapter.notifyItemChanged(focusedGroupIndex); - } - - public void defocusChannelGroup(int groupIndex) { - channelGroupList.get(groupIndex).setFocused(false); - groupAdapter.notifyItemChanged(groupIndex); - } - - public void focusLiveChannel(int channelIndex) { - if (focusedGroupIndex > -1) { - defocusChannelGroup(focusedGroupIndex); - focusedGroupIndex = -1; - } - if (focusedChannelIndex > -1) { - channelGroupList.get(selectedGroupIndex).getLiveChannels().get(focusedChannelIndex).setFocused(false); - channelAdapter.notifyItemChanged(focusedChannelIndex); } - focusedChannelIndex = channelIndex; - channelGroupList.get(selectedGroupIndex).getLiveChannels().get(focusedChannelIndex).setFocused(true); - channelAdapter.notifyItemChanged(focusedChannelIndex); - } - - public void defocusLiveChannel(int channelIndex) { - channelGroupList.get(selectedGroupIndex).getLiveChannels().get(channelIndex).setFocused(false); - channelAdapter.notifyItemChanged(channelIndex); } } \ No newline at end of file diff --git a/app/src/main/java/com/github/tvbox/osc/ui/adapter/ChannelGroupAdapter.java b/app/src/main/java/com/github/tvbox/osc/ui/adapter/ChannelGroupAdapter.java deleted file mode 100644 index e3806ede..00000000 --- a/app/src/main/java/com/github/tvbox/osc/ui/adapter/ChannelGroupAdapter.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.tvbox.osc.ui.adapter; - -import android.graphics.Color; -import android.widget.TextView; - -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.BaseViewHolder; -import com.github.tvbox.osc.R; -import com.github.tvbox.osc.bean.ChannelGroup; - -import java.util.ArrayList; - - -/** - * @author pj567 - * @date :2021/1/12 - * @description: - */ -public class ChannelGroupAdapter extends BaseQuickAdapter { - public ChannelGroupAdapter() { - super(R.layout.item_channel_group, new ArrayList<>()); - } - - @Override - protected void convert(BaseViewHolder holder, ChannelGroup item) { - TextView tvGroupName = holder.getView(R.id.tvGroupName); - tvGroupName.setText(item.getGroupName()); - if (item.isSelected() && !item.isFocused()) { - tvGroupName.setTextColor(mContext.getResources().getColor(R.color.color_1890FF)); - } else { - tvGroupName.setTextColor(Color.WHITE); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveChannelAdapter.java b/app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveChannelAdapter.java deleted file mode 100644 index ce41f532..00000000 --- a/app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveChannelAdapter.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.tvbox.osc.ui.adapter; - -import android.graphics.Color; -import android.widget.TextView; - -import com.chad.library.adapter.base.BaseQuickAdapter; -import com.chad.library.adapter.base.BaseViewHolder; -import com.github.tvbox.osc.R; -import com.github.tvbox.osc.bean.LiveChannel; - -import java.util.ArrayList; - -/** - * @author pj567 - * @date :2021/1/12 - * @description: - */ -public class LiveChannelAdapter extends BaseQuickAdapter { - public LiveChannelAdapter() { - super(R.layout.item_live_channel, new ArrayList<>()); - } - - @Override - protected void convert(BaseViewHolder helper, LiveChannel item) { - TextView tvChannelNum = helper.getView(R.id.tvChannelNum); - TextView tvChannel = helper.getView(R.id.tvChannel); - tvChannelNum.setText(String.format("%s", item.getChannelNum())); - tvChannel.setText(item.getChannelName()); - if (item.isSelected() && !item.isFocused()) { - tvChannelNum.setTextColor(mContext.getResources().getColor(R.color.color_1890FF)); - tvChannel.setTextColor(mContext.getResources().getColor(R.color.color_1890FF)); - } - else{ - tvChannelNum.setTextColor(Color.WHITE); - tvChannel.setTextColor(Color.WHITE); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveChannelGroupAdapter.java b/app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveChannelGroupAdapter.java new file mode 100644 index 00000000..14c8f1a1 --- /dev/null +++ b/app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveChannelGroupAdapter.java @@ -0,0 +1,55 @@ +package com.github.tvbox.osc.ui.adapter; + +import android.graphics.Color; +import android.widget.TextView; + +import com.chad.library.adapter.base.BaseQuickAdapter; +import com.chad.library.adapter.base.BaseViewHolder; +import com.github.tvbox.osc.R; +import com.github.tvbox.osc.bean.LiveChannelGroup; + +import java.util.ArrayList; + + +/** + * @author pj567 + * @date :2021/1/12 + * @description: + */ +public class LiveChannelGroupAdapter extends BaseQuickAdapter { + private int selectedGroupIndex = -1; + private int focusedGroupIndex = -1; + + public LiveChannelGroupAdapter() { + super(R.layout.item_live_channel_group, new ArrayList<>()); + } + + @Override + protected void convert(BaseViewHolder holder, LiveChannelGroup item) { + TextView tvGroupName = holder.getView(R.id.tvChannelGroupName); + tvGroupName.setText(item.getGroupName()); + int groupIndex = item.getGroupIndex(); + if (groupIndex == selectedGroupIndex && groupIndex != focusedGroupIndex) { + tvGroupName.setTextColor(mContext.getResources().getColor(R.color.color_1890FF)); + } else { + tvGroupName.setTextColor(Color.WHITE); + } + } + + public void setSelectedGroupIndex(int selectedGroupIndex) { + int preSelectedGroupIndex = this.selectedGroupIndex; + this.selectedGroupIndex = selectedGroupIndex; + if (preSelectedGroupIndex != -1) + notifyItemChanged(preSelectedGroupIndex); + if (this.selectedGroupIndex != -1) + notifyItemChanged(this.selectedGroupIndex); + } + + public void setFocusedGroupIndex(int focusedGroupIndex) { + this.focusedGroupIndex = focusedGroupIndex; + if (this.focusedGroupIndex != -1) + notifyItemChanged(this.focusedGroupIndex); + else if (this.selectedGroupIndex != -1) + notifyItemChanged(this.selectedGroupIndex); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveChannelItemAdapter.java b/app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveChannelItemAdapter.java new file mode 100644 index 00000000..4f7380c2 --- /dev/null +++ b/app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveChannelItemAdapter.java @@ -0,0 +1,62 @@ +package com.github.tvbox.osc.ui.adapter; + +import android.graphics.Color; +import android.widget.TextView; + +import com.chad.library.adapter.base.BaseQuickAdapter; +import com.chad.library.adapter.base.BaseViewHolder; +import com.github.tvbox.osc.R; +import com.github.tvbox.osc.bean.LiveChannelItem; + +import java.util.ArrayList; + +/** + * @author pj567 + * @date :2021/1/12 + * @description: + */ +public class LiveChannelItemAdapter extends BaseQuickAdapter { + private int selectedChannelIndex = -1; + private int focusedChannelIndex = -1; + + public LiveChannelItemAdapter() { + super(R.layout.item_live_channel, new ArrayList<>()); + } + + @Override + protected void convert(BaseViewHolder holder, LiveChannelItem item) { + TextView tvChannelNum = holder.getView(R.id.tvChannelNum); + TextView tvChannel = holder.getView(R.id.tvChannelName); + tvChannelNum.setText(String.format("%s", item.getChannelNum())); + tvChannel.setText(item.getChannelName()); + int channelIndex = item.getChannelIndex(); + if (channelIndex == selectedChannelIndex && channelIndex != focusedChannelIndex) { + tvChannelNum.setTextColor(mContext.getResources().getColor(R.color.color_1890FF)); + tvChannel.setTextColor(mContext.getResources().getColor(R.color.color_1890FF)); + } + else{ + tvChannelNum.setTextColor(Color.WHITE); + tvChannel.setTextColor(Color.WHITE); + } + } + + public void setSelectedChannelIndex(int selectedChannelIndex) { + int preSelectedChannelIndex = this.selectedChannelIndex; + this.selectedChannelIndex = selectedChannelIndex; + if (preSelectedChannelIndex != -1) + notifyItemChanged(preSelectedChannelIndex); + if (this.selectedChannelIndex != -1) + notifyItemChanged(this.selectedChannelIndex); + } + + public void setFocusedChannelIndex(int focusedChannelIndex) { + int preFocusedChannelIndex = this.focusedChannelIndex; + this.focusedChannelIndex = focusedChannelIndex; + if (preFocusedChannelIndex != -1) + notifyItemChanged(preFocusedChannelIndex); + if (this.focusedChannelIndex != -1) + notifyItemChanged(this.focusedChannelIndex); + else if (this.selectedChannelIndex != -1) + notifyItemChanged(this.selectedChannelIndex); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveSettingGroupAdapter.java b/app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveSettingGroupAdapter.java new file mode 100644 index 00000000..134df48e --- /dev/null +++ b/app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveSettingGroupAdapter.java @@ -0,0 +1,59 @@ +package com.github.tvbox.osc.ui.adapter; + +import android.graphics.Color; +import android.widget.TextView; + +import com.chad.library.adapter.base.BaseQuickAdapter; +import com.chad.library.adapter.base.BaseViewHolder; +import com.github.tvbox.osc.R; +import com.github.tvbox.osc.bean.LiveSettingGroup; + +import java.util.ArrayList; + + +/** + * @author pj567 + * @date :2021/1/12 + * @description: + */ +public class LiveSettingGroupAdapter extends BaseQuickAdapter { + private int selectedGroupIndex = -1; + private int focusedGroupIndex = -1; + + public LiveSettingGroupAdapter() { + super(R.layout.item_live_setting_group, new ArrayList<>()); + } + + @Override + protected void convert(BaseViewHolder holder, LiveSettingGroup group) { + TextView tvGroupName = holder.getView(R.id.tvSettingGroupName); + tvGroupName.setText(group.getGroupName()); + int groupIndex = group.getGroupIndex(); + if (groupIndex == selectedGroupIndex && groupIndex != focusedGroupIndex) { + tvGroupName.setTextColor(mContext.getResources().getColor(R.color.color_1890FF)); + } else { + tvGroupName.setTextColor(Color.WHITE); + } + } + + public void setSelectedGroupIndex(int selectedGroupIndex) { + int preSelectedGroupIndex = this.selectedGroupIndex; + this.selectedGroupIndex = selectedGroupIndex; + if (preSelectedGroupIndex != -1) + notifyItemChanged(preSelectedGroupIndex); + if (this.selectedGroupIndex != -1) + notifyItemChanged(this.selectedGroupIndex); + } + + public int getSelectedGroupIndex() { + return selectedGroupIndex; + } + + public void setFocusedGroupIndex(int focusedGroupIndex) { + this.focusedGroupIndex = focusedGroupIndex; + if (this.focusedGroupIndex != -1) + notifyItemChanged(this.focusedGroupIndex); + else if (this.selectedGroupIndex != -1) + notifyItemChanged(this.selectedGroupIndex); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveSettingItemAdapter.java b/app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveSettingItemAdapter.java new file mode 100644 index 00000000..d7818e3e --- /dev/null +++ b/app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveSettingItemAdapter.java @@ -0,0 +1,70 @@ +package com.github.tvbox.osc.ui.adapter; + +import android.graphics.Color; +import android.widget.TextView; + +import com.chad.library.adapter.base.BaseQuickAdapter; +import com.chad.library.adapter.base.BaseViewHolder; +import com.github.tvbox.osc.R; +import com.github.tvbox.osc.bean.LiveSettingItem; + +import java.util.ArrayList; + + +/** + * @author pj567 + * @date :2021/1/12 + * @description: + */ +public class LiveSettingItemAdapter extends BaseQuickAdapter { + private int focusedItemIndex = -1; + + public LiveSettingItemAdapter() { + super(R.layout.item_live_setting, new ArrayList<>()); + } + + @Override + protected void convert(BaseViewHolder holder, LiveSettingItem item) { + TextView tvItemName = holder.getView(R.id.tvSettingItemName); + tvItemName.setText(item.getItemName()); + int itemIndex = item.getItemIndex(); + if (item.isItemSelected() && itemIndex != focusedItemIndex) { + tvItemName.setTextColor(mContext.getResources().getColor(R.color.color_1890FF)); + } else { + tvItemName.setTextColor(Color.WHITE); + } + } + + public void selectItem(int selectedItemIndex, boolean select, boolean unselectPreItemIndex) { + if (unselectPreItemIndex) { + int preSelectedItemIndex = getSelectedItemIndex(); + if (preSelectedItemIndex != -1) { + getData().get(preSelectedItemIndex).setItemSelected(false); + notifyItemChanged(preSelectedItemIndex); + } + } + if (selectedItemIndex != -1) { + getData().get(selectedItemIndex).setItemSelected(select); + notifyItemChanged(selectedItemIndex); + } + } + + public void setFocusedItemIndex(int focusedItemIndex) { + int preFocusItemIndex = this.focusedItemIndex; + this.focusedItemIndex = focusedItemIndex; + if (preFocusItemIndex != -1) + notifyItemChanged(preFocusItemIndex); + if (this.focusedItemIndex != -1) + notifyItemChanged(this.focusedItemIndex); + else + notifyDataSetChanged(); + } + + public int getSelectedItemIndex() { + for (LiveSettingItem item : getData()) { + if (item.isItemSelected()) + return item.getItemIndex(); + } + return -1; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/tvbox/osc/util/HawkConfig.java b/app/src/main/java/com/github/tvbox/osc/util/HawkConfig.java index 1a1ffc11..edc80c3f 100644 --- a/app/src/main/java/com/github/tvbox/osc/util/HawkConfig.java +++ b/app/src/main/java/com/github/tvbox/osc/util/HawkConfig.java @@ -13,7 +13,6 @@ public class HawkConfig { public static final String DEBUG_OPEN = "debug_open"; public static final String PARSE_WEBVIEW = "parse_webview"; // true 系统 false xwalk public static final String IJK_CODEC = "ijk_codec"; - public static final String LIVE_CHANNEL = "last_live_channel_name"; public static final String PLAY_TYPE = "play_type";//0 系统;1 ijk;2 exo public static final String PLAY_RENDER = "play_render"; //0 texture 2 public static final String PLAY_SCALE = "play_scale"; //0 texture 2 @@ -21,4 +20,12 @@ public class HawkConfig { public static final String DOH_URL = "doh_url"; public static final String HOME_REC = "home_rec"; // 0 豆瓣热播 1 数据源推荐 2 历史 public static final String SEARCH_VIEW = "search_view"; // 0 列表 1 缩略图 + public static final String LIVE_CHANNEL = "last_live_channel_name"; + public static final String LIVE_PLAYER_TYPE = "live_player_type"; + public static final String LIVE_PLAYER_SCALE = "live_player_scale"; + public static final String LIVE_CHANNEL_REVERSE = "live_channel_reverse"; + public static final String LIVE_CROSS_GROUP = "live_cross_group"; + public static final String LIVE_CONNECT_TIMEOUT = "live_connect_timeout"; + public static final String LIVE_SHOW_NET_SPEED = "live_show_net_speed"; + public static final String LIVE_SHOW_TIME = "live_show_time"; } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_live_play.xml b/app/src/main/res/layout/activity_live_play.xml index 2bb4b56f..7224e4e8 100644 --- a/app/src/main/res/layout/activity_live_play.xml +++ b/app/src/main/res/layout/activity_live_play.xml @@ -10,7 +10,7 @@ android:layout_height="match_parent" /> + + + + + + + + + - - \ No newline at end of file diff --git a/app/src/main/res/layout/item_live_channel.xml b/app/src/main/res/layout/item_live_channel.xml index b9e81ba3..5b11ff5f 100644 --- a/app/src/main/res/layout/item_live_channel.xml +++ b/app/src/main/res/layout/item_live_channel.xml @@ -23,7 +23,7 @@ android:textSize="22mm" /> + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_live_setting_group.xml b/app/src/main/res/layout/item_live_setting_group.xml new file mode 100644 index 00000000..95d01e16 --- /dev/null +++ b/app/src/main/res/layout/item_live_setting_group.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file