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 f64ad514..143e6180 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 @@ -351,7 +351,13 @@ public class ApiConfig { LiveChannelGroup liveChannelGroup = new LiveChannelGroup(); liveChannelGroup.setLiveChannels(new ArrayList()); liveChannelGroup.setGroupIndex(groupIndex++); - liveChannelGroup.setGroupName(((JsonObject) groupElement).get("group").getAsString().trim()); + String groupName = ((JsonObject) groupElement).get("group").getAsString().trim(); + String[] splitGroupName = groupName.split("_", 2); + liveChannelGroup.setGroupName(splitGroupName[0]); + if (splitGroupName.length > 1) + liveChannelGroup.setGroupPassword(splitGroupName[1]); + else + liveChannelGroup.setGroupPassword(""); channelIndex = 0; for (JsonElement channelElement : ((JsonObject) groupElement).get("channels").getAsJsonArray()) { JsonObject obj = (JsonObject) channelElement; 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 index 81ebdaf9..44b8ff77 100644 --- a/app/src/main/java/com/github/tvbox/osc/bean/LiveChannelGroup.java +++ b/app/src/main/java/com/github/tvbox/osc/bean/LiveChannelGroup.java @@ -36,4 +36,12 @@ public class LiveChannelGroup { public void setLiveChannels(ArrayList liveChannelItems) { this.liveChannelItems = liveChannelItems; } + + public String getGroupPassword() { + return groupPassword; + } + + public void setGroupPassword(String groupPassword) { + this.groupPassword = groupPassword; + } } diff --git a/app/src/main/java/com/github/tvbox/osc/bean/LivePlayerManage.java b/app/src/main/java/com/github/tvbox/osc/bean/LivePlayerManager.java similarity index 98% rename from app/src/main/java/com/github/tvbox/osc/bean/LivePlayerManage.java rename to app/src/main/java/com/github/tvbox/osc/bean/LivePlayerManager.java index 1f83df23..1c4b23e4 100644 --- a/app/src/main/java/com/github/tvbox/osc/bean/LivePlayerManage.java +++ b/app/src/main/java/com/github/tvbox/osc/bean/LivePlayerManager.java @@ -16,7 +16,7 @@ import java.util.Objects; import xyz.doikki.videoplayer.player.VideoView; -public class LivePlayerManage { +public class LivePlayerManager { JSONObject defaultPlayerConfig = new JSONObject(); JSONObject currentPlayerConfig; @@ -33,7 +33,7 @@ public class LivePlayerManage { } public void getDefaultLiveChannelPlayer(VideoView videoView) { - PlayerHelper.updateCfg(videoView); + PlayerHelper.updateCfg(videoView, defaultPlayerConfig); try { currentPlayerConfig = new JSONObject(defaultPlayerConfig.toString()); } catch (JSONException 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 1e8ee067..74cdf44c 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 @@ -14,6 +14,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; +import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; @@ -24,7 +25,7 @@ import com.github.tvbox.osc.base.App; import com.github.tvbox.osc.base.BaseActivity; import com.github.tvbox.osc.bean.LiveChannelGroup; import com.github.tvbox.osc.bean.LiveChannelItem; -import com.github.tvbox.osc.bean.LivePlayerManage; +import com.github.tvbox.osc.bean.LivePlayerManager; import com.github.tvbox.osc.bean.LiveSettingGroup; import com.github.tvbox.osc.bean.LiveSettingItem; import com.github.tvbox.osc.player.controller.LiveController; @@ -32,10 +33,10 @@ 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.dialog.LivePasswordDialog; import com.github.tvbox.osc.ui.tv.widget.ViewObj; import com.github.tvbox.osc.util.FastClickCheckUtil; import com.github.tvbox.osc.util.HawkConfig; -import com.github.tvbox.osc.util.PlayerHelper; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.lzy.okgo.OkGo; @@ -45,16 +46,13 @@ 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.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.Locale; -import xyz.doikki.videocontroller.component.GestureView; import xyz.doikki.videoplayer.player.VideoView; /** @@ -83,12 +81,12 @@ public class LivePlayActivity extends BaseActivity { private Handler mHandler = new Handler(); private List liveChannelGroupList = new ArrayList<>(); - private int selectedChannelGroupIndex = 0; private int currentChannelGroupIndex = 0; - private int currentLiveChannelIndex = 0; + private int currentLiveChannelIndex = -1; private int currentLiveChangeSourceTimes = 0; private LiveChannelItem currentLiveChannelItem = null; - private LivePlayerManage livePlayerManage = new LivePlayerManage(); + private LivePlayerManager livePlayerManager = new LivePlayerManager(); + private ArrayList channelGroupPasswordConfirmed = new ArrayList<>(); @Override protected int getLayoutResID() { @@ -99,7 +97,7 @@ public class LivePlayActivity extends BaseActivity { protected void init() { setLoadSir(findViewById(R.id.live_root)); mVideoView = findViewById(R.id.mVideoView); - livePlayerManage.init(mVideoView); + livePlayerManager.init(mVideoView); tvLeftChannelListLayout = findViewById(R.id.tvLeftChannnelListLayout); mChannelGroupView = findViewById(R.id.mGroupGridView); @@ -141,24 +139,34 @@ public class LivePlayActivity extends BaseActivity { public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { int keyCode = event.getKeyCode(); - if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && !isListOrSettingLayoutVisible()) { - if (Hawk.get(HawkConfig.LIVE_CHANNEL_REVERSE, false)) - playPrevious(); - else - playNext(); - } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP && !isListOrSettingLayoutVisible()) { - if (Hawk.get(HawkConfig.LIVE_CHANNEL_REVERSE, false)) - playNext(); - else - playPrevious(); - } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT && !isListOrSettingLayoutVisible()) { - playPreSource(); - } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && !isListOrSettingLayoutVisible()) { - playNextSource(); - } else if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) && !isListOrSettingLayoutVisible()) { - showChannelList(); - } else if (keyCode == KeyEvent.KEYCODE_MENU && tvRightSettingLayout.getVisibility() == View.INVISIBLE) { + if (keyCode == KeyEvent.KEYCODE_MENU) { showSettingGroup(); + } else if (!isListOrSettingLayoutVisible()) { + switch (keyCode) { + case KeyEvent.KEYCODE_DPAD_UP: + if (Hawk.get(HawkConfig.LIVE_CHANNEL_REVERSE, false)) + playNext(); + else + playPrevious(); + break; + case KeyEvent.KEYCODE_DPAD_DOWN: + if (Hawk.get(HawkConfig.LIVE_CHANNEL_REVERSE, false)) + playPrevious(); + else + playNext(); + break; + case KeyEvent.KEYCODE_DPAD_LEFT: + playPreSource(); + break; + case KeyEvent.KEYCODE_DPAD_RIGHT: + playNextSource(); + break; + case KeyEvent.KEYCODE_DPAD_CENTER: + case KeyEvent.KEYCODE_ENTER: + case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: + showChannelList(); + break; + } } } else if (event.getAction() == KeyEvent.ACTION_UP) { } @@ -170,6 +178,7 @@ public class LivePlayActivity extends BaseActivity { super.onDestroy(); if (mVideoView != null) { mVideoView.release(); + mVideoView = null; } } @@ -180,12 +189,16 @@ public class LivePlayActivity extends BaseActivity { } if (tvLeftChannelListLayout.getVisibility() == View.INVISIBLE) { //重新载入上一次状态 - liveChannelItemAdapter.setNewData(liveChannelGroupList.get(currentChannelGroupIndex).getLiveChannels()); + liveChannelItemAdapter.setNewData(getLiveChannels(currentChannelGroupIndex)); + if (currentLiveChannelIndex > -1) + mLiveChannelView.scrollToPosition(currentLiveChannelIndex); + mLiveChannelView.setSelection(currentLiveChannelIndex); mChannelGroupView.scrollToPosition(currentChannelGroupIndex); mChannelGroupView.setSelection(currentChannelGroupIndex); - mLiveChannelView.scrollToPosition(currentLiveChannelIndex); - mLiveChannelView.setSelection(currentLiveChannelIndex); mHandler.postDelayed(mFocusCurrentChannelAndShowChannelList, 200); + } else { + mHandler.removeCallbacks(mHideChannelListRun); + mHandler.post(mHideChannelListRun); } } @@ -238,7 +251,7 @@ public class LivePlayActivity extends BaseActivity { }; private void showChannelInfo() { - tvChannelInfo.setText(String.format("%d %s %s(%d/%d)", currentLiveChannelItem.getChannelNum(), + tvChannelInfo.setText(String.format(Locale.getDefault(), "%d %s %s(%d/%d)", currentLiveChannelItem.getChannelNum(), currentLiveChannelItem.getChannelName(), currentLiveChannelItem.getSourceName(), currentLiveChannelItem.getSourceIndex() + 1, currentLiveChannelItem.getSourceNum())); @@ -266,12 +279,19 @@ public class LivePlayActivity extends BaseActivity { } }; - private boolean playChannel(boolean changeSource) { + private boolean playChannel(int channelGroupIndex, int liveChannelIndex, boolean changeSource) { + if ((channelGroupIndex == currentChannelGroupIndex && liveChannelIndex == currentLiveChannelIndex && !changeSource) + || (changeSource && currentLiveChannelItem.getSourceNum() == 1)) { + showChannelInfo(); + return true; + } mVideoView.release(); if (!changeSource) { - currentLiveChannelItem = liveChannelGroupList.get(currentChannelGroupIndex).getLiveChannels().get(currentLiveChannelIndex); + currentChannelGroupIndex = channelGroupIndex; + currentLiveChannelIndex = liveChannelIndex; + currentLiveChannelItem = getLiveChannels(currentChannelGroupIndex).get(currentLiveChannelIndex); Hawk.put(HawkConfig.LIVE_CHANNEL, currentLiveChannelItem.getChannelName()); - livePlayerManage.getLiveChannelPlayer(mVideoView, currentLiveChannelItem.getChannelName()); + livePlayerManager.getLiveChannelPlayer(mVideoView, currentLiveChannelItem.getChannelName()); } mVideoView.setUrl(currentLiveChannelItem.getUrl()); showChannelInfo(); @@ -280,47 +300,27 @@ public class LivePlayActivity extends BaseActivity { } private void playNext() { - currentLiveChannelIndex++; - if (currentLiveChannelIndex >= liveChannelGroupList.get(currentChannelGroupIndex).getLiveChannels().size()) { - currentLiveChannelIndex = 0; - if (Hawk.get(HawkConfig.LIVE_CROSS_GROUP, false)) { - currentChannelGroupIndex++; - if (currentChannelGroupIndex >= liveChannelGroupList.size()) - currentChannelGroupIndex = 0; - } - } - playChannel(false); + if (!isCurrentLiveChannelValid()) return; + Integer[] groupChannelIndex = getNextChannel(1); + playChannel(groupChannelIndex[0], groupChannelIndex[1], false); } private void playPrevious() { - currentLiveChannelIndex--; - if (currentLiveChannelIndex < 0) { - if (Hawk.get(HawkConfig.LIVE_CROSS_GROUP, false)) { - currentChannelGroupIndex--; - if (currentChannelGroupIndex < 0) - currentChannelGroupIndex = liveChannelGroupList.size() - 1; - } - currentLiveChannelIndex = liveChannelGroupList.get(currentChannelGroupIndex).getLiveChannels().size() - 1; - } - playChannel(false); + if (!isCurrentLiveChannelValid()) return; + Integer[] groupChannelIndex = getNextChannel(-1); + playChannel(groupChannelIndex[0], groupChannelIndex[1], false); } public void playPreSource() { - if (currentLiveChannelItem.getSourceNum() == 1) { - showChannelInfo(); - return; - } + if (!isCurrentLiveChannelValid()) return; currentLiveChannelItem.preSource(); - playChannel(true); + playChannel(currentChannelGroupIndex, currentLiveChannelIndex, true); } public void playNextSource() { - if (currentLiveChannelItem.getSourceNum() == 1) { - showChannelInfo(); - return; - } + if (!isCurrentLiveChannelValid()) return; currentLiveChannelItem.nextSource(); - playChannel(true); + playChannel(currentChannelGroupIndex, currentLiveChannelIndex, true); } //显示设置列表 @@ -330,15 +330,17 @@ public class LivePlayActivity extends BaseActivity { mHandler.post(mHideChannelListRun); } if (tvRightSettingLayout.getVisibility() == View.INVISIBLE) { + if (!isCurrentLiveChannelValid()) return; //重新载入默认状态 loadCurrentSourceList(); liveSettingGroupAdapter.setNewData(liveSettingGroupList); - liveSettingItemAdapter.setNewData(liveSettingGroupList.get(0).getLiveSettingItems()); + selectSettingGroup(0, false); mSettingGroupView.scrollToPosition(0); mSettingItemView.scrollToPosition(currentLiveChannelItem.getSourceIndex()); - liveSettingGroupAdapter.setSelectedGroupIndex(0); - liveSettingItemAdapter.selectItem(currentLiveChannelItem.getSourceIndex(), true, true); mHandler.postDelayed(mFocusAndShowSettingGroup, 200); + } else { + mHandler.removeCallbacks(mHideSettingLayoutRun); + mHandler.post(mHideSettingLayoutRun); } } @@ -395,44 +397,35 @@ public class LivePlayActivity extends BaseActivity { controller.setListener(new LiveController.LiveControlListener() { @Override public boolean singleTap() { - if (tvLeftChannelListLayout.getVisibility() == View.VISIBLE) { - mHandler.removeCallbacks(mHideChannelListRun); - mHandler.post(mHideChannelListRun); - } else { - showChannelList(); - } + showChannelList(); return true; } @Override public void longPress() { - if (tvRightSettingLayout.getVisibility() == View.VISIBLE) { - mHandler.removeCallbacks(mHideSettingLayoutRun); - mHandler.post(mHideSettingLayoutRun); - } else { - showSettingGroup(); - } + showSettingGroup(); } @Override public void playStateChanged(int playState) { switch (playState) { case VideoView.STATE_IDLE: - case VideoView.STATE_PLAYING: case VideoView.STATE_PAUSED: + break; case VideoView.STATE_PREPARED: case VideoView.STATE_BUFFERED: - case VideoView.STATE_PLAYBACK_COMPLETED: + case VideoView.STATE_PLAYING: currentLiveChangeSourceTimes = 0; mHandler.removeCallbacks(mConnectTimeoutChangeSourceRun); break; case VideoView.STATE_ERROR: - currentLiveChangeSourceTimes++; + case VideoView.STATE_PLAYBACK_COMPLETED: mHandler.removeCallbacks(mConnectTimeoutChangeSourceRun); mHandler.post(mConnectTimeoutChangeSourceRun); break; case VideoView.STATE_PREPARING: case VideoView.STATE_BUFFERING: + mHandler.removeCallbacks(mConnectTimeoutChangeSourceRun); mHandler.postDelayed(mConnectTimeoutChangeSourceRun, (Hawk.get(HawkConfig.LIVE_CONNECT_TIMEOUT, 1) + 1) * 5000); break; } @@ -457,12 +450,11 @@ public class LivePlayActivity extends BaseActivity { private Runnable mConnectTimeoutChangeSourceRun = new Runnable() { @Override public void run() { + currentLiveChangeSourceTimes++; if (currentLiveChannelItem.getSourceNum() == currentLiveChangeSourceTimes) { currentLiveChangeSourceTimes = 0; - if (Hawk.get(HawkConfig.LIVE_CHANNEL_REVERSE, false)) - playPrevious(); - else - playNext(); + Integer[] groupChannelIndex = getNextChannel(Hawk.get(HawkConfig.LIVE_CHANNEL_REVERSE, false) ? -1 : 1); + playChannel(groupChannelIndex[0], groupChannelIndex[1], false); } else { playNextSource(); } @@ -492,15 +484,14 @@ public class LivePlayActivity extends BaseActivity { @Override public void onItemSelected(TvRecyclerView parent, View itemView, int position) { - liveChannelGroupAdapter.setSelectedGroupIndex(position); - liveChannelGroupAdapter.setFocusedGroupIndex(position); - liveChannelItemAdapter.setFocusedChannelIndex(-1); - if (position == selectedChannelGroupIndex || position < -1) return; - clickChannelGroup(position); + selectChannelGroup(position, true, -1); } @Override public void onItemClick(TvRecyclerView parent, View itemView, int position) { + if (isNeedInputPassword(position)) { + showPasswordDialog(position, -1); + } } }); @@ -509,13 +500,30 @@ public class LivePlayActivity extends BaseActivity { @Override public void onItemClick(BaseQuickAdapter adapter, View view, int position) { FastClickCheckUtil.check(view); - if (position == selectedChannelGroupIndex) return; - liveChannelGroupAdapter.setSelectedGroupIndex(position); - clickChannelGroup(position); + selectChannelGroup(position, false, -1); } }); } + private void selectChannelGroup(int groupIndex, boolean focus, int liveChannelIndex) { + if (focus) { + liveChannelGroupAdapter.setFocusedGroupIndex(groupIndex); + liveChannelItemAdapter.setFocusedChannelIndex(-1); + } + if ((groupIndex > -1 && groupIndex != liveChannelGroupAdapter.getSelectedGroupIndex()) || isNeedInputPassword(groupIndex)) { + liveChannelGroupAdapter.setSelectedGroupIndex(groupIndex); + if (isNeedInputPassword(groupIndex)) { + showPasswordDialog(groupIndex, liveChannelIndex); + return; + } + loadChannelGroupDataAndPlay(groupIndex, liveChannelIndex); + } + if (tvLeftChannelListLayout.getVisibility() == View.VISIBLE) { + mHandler.removeCallbacks(mHideChannelListRun); + mHandler.postDelayed(mHideChannelListRun, 5000); + } + } + private void initLiveChannelView() { mLiveChannelView.setHasFixedSize(true); mLiveChannelView.setLayoutManager(new V7LinearLayoutManager(this.mContext, 1, false)); @@ -548,8 +556,6 @@ public class LivePlayActivity extends BaseActivity { @Override public void onItemClick(TvRecyclerView parent, View itemView, int position) { - if (selectedChannelGroupIndex == currentChannelGroupIndex && position == currentLiveChannelIndex) - return; clickLiveChannel(position); } }); @@ -559,34 +565,17 @@ public class LivePlayActivity extends BaseActivity { @Override public void onItemClick(BaseQuickAdapter adapter, View view, int position) { FastClickCheckUtil.check(view); - if (selectedChannelGroupIndex == currentChannelGroupIndex && position == currentLiveChannelIndex) - return; clickLiveChannel(position); } }); } - private void clickChannelGroup(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); - } - private void clickLiveChannel(int position) { - currentChannelGroupIndex = selectedChannelGroupIndex; - currentLiveChannelIndex = position; liveChannelItemAdapter.setSelectedChannelIndex(position); - if (playChannel(false)) { - mHandler.post(mHideChannelListRun); + playChannel(liveChannelGroupAdapter.getSelectedGroupIndex(), position, false); + if (tvLeftChannelListLayout.getVisibility() == View.VISIBLE) { + mHandler.removeCallbacks(mHideChannelListRun); + mHandler.postDelayed(mHideChannelListRun, 5000); } } @@ -613,11 +602,7 @@ public class LivePlayActivity extends BaseActivity { @Override public void onItemSelected(TvRecyclerView parent, View itemView, int position) { - liveSettingGroupAdapter.setFocusedGroupIndex(position); - liveSettingItemAdapter.setFocusedItemIndex(-1); - if (position == liveSettingGroupAdapter.getSelectedGroupIndex() || position < -1) - return; - clickSettingGroup(position); + selectSettingGroup(position, true); } @Override @@ -630,13 +615,41 @@ public class LivePlayActivity extends BaseActivity { @Override public void onItemClick(BaseQuickAdapter adapter, View view, int position) { FastClickCheckUtil.check(view); - if (position == liveSettingGroupAdapter.getSelectedGroupIndex()) - return; - clickSettingGroup(position); + selectSettingGroup(position, false); } }); } + private void selectSettingGroup(int position, boolean focus) { + if (!isCurrentLiveChannelValid()) return; + if (focus) { + liveSettingGroupAdapter.setFocusedGroupIndex(position); + liveSettingItemAdapter.setFocusedItemIndex(-1); + } + if (position == liveSettingGroupAdapter.getSelectedGroupIndex() || position < -1) + return; + + liveSettingGroupAdapter.setSelectedGroupIndex(position); + liveSettingItemAdapter.setNewData(liveSettingGroupList.get(position).getLiveSettingItems()); + + switch (position) { + case 0: + liveSettingItemAdapter.selectItem(currentLiveChannelItem.getSourceIndex(), true, false); + break; + case 1: + liveSettingItemAdapter.selectItem(livePlayerManager.getLivePlayerScale(), true, true); + break; + case 2: + liveSettingItemAdapter.selectItem(livePlayerManager.getLivePlayerType(), true, true); + break; + } + int scrollToPosition = liveSettingItemAdapter.getSelectedItemIndex(); + if (scrollToPosition < 0) scrollToPosition = 0; + mSettingItemView.scrollToPosition(scrollToPosition); + mHandler.removeCallbacks(mHideSettingLayoutRun); + mHandler.postDelayed(mHideSettingLayoutRun, 5000); + } + private void initSettingItemView() { mSettingItemView.setHasFixedSize(true); mSettingItemView.setLayoutManager(new V7LinearLayoutManager(this.mContext, 1, false)); @@ -669,13 +682,7 @@ public class LivePlayActivity extends BaseActivity { @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); - } - clickSettingItem(settingGroupIndex, position); + clickSettingItem(position); } }); @@ -684,51 +691,29 @@ public class LivePlayActivity extends BaseActivity { @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); - } - clickSettingItem(settingGroupIndex, position); + clickSettingItem(position); } }); } - private void clickSettingGroup(int position) { - liveSettingGroupAdapter.setSelectedGroupIndex(position); - liveSettingItemAdapter.setNewData(liveSettingGroupList.get(position).getLiveSettingItems()); - - switch (position) { - case 0: - liveSettingItemAdapter.selectItem(currentLiveChannelItem.getSourceIndex(), true, false); - break; - case 1: - liveSettingItemAdapter.selectItem(livePlayerManage.getLivePlayerScale(), true, true); - break; - case 2: - liveSettingItemAdapter.selectItem(livePlayerManage.getLivePlayerType(), true, true); - break; + private void clickSettingItem(int position) { + int settingGroupIndex = liveSettingGroupAdapter.getSelectedGroupIndex(); + if (settingGroupIndex < 4) { + if (position == liveSettingItemAdapter.getSelectedItemIndex()) + return; + liveSettingItemAdapter.selectItem(position, true, true); } - int scrollToPosition = liveSettingItemAdapter.getSelectedItemIndex(); - if (scrollToPosition < 0) scrollToPosition = 0; - mSettingItemView.scrollToPosition(scrollToPosition); - mHandler.removeCallbacks(mHideSettingLayoutRun); - mHandler.postDelayed(mHideSettingLayoutRun, 5000); - } - - private void clickSettingItem(int settingGroupIndex, int position) { switch (settingGroupIndex) { case 0://线路切换 currentLiveChannelItem.setSourceIndex(position); - playChannel(true); + playChannel(currentChannelGroupIndex, currentLiveChannelIndex,true); break; case 1://画面比例 - livePlayerManage.changeLivePlayerScale(mVideoView, position, currentLiveChannelItem.getChannelName()); + livePlayerManager.changeLivePlayerScale(mVideoView, position, currentLiveChannelItem.getChannelName()); break; case 2://播放解码 mVideoView.release(); - livePlayerManage.changeLivePlayerType(mVideoView, position, currentLiveChannelItem.getChannelName()); + livePlayerManager.changeLivePlayerType(mVideoView, position, currentLiveChannelItem.getChannelName()); mVideoView.setUrl(currentLiveChannelItem.getUrl()); mVideoView.start(); break; @@ -794,16 +779,16 @@ public class LivePlayActivity extends BaseActivity { @Override public void onSuccess(Response response) { - List list = new ArrayList<>(); JsonArray livesArray = new Gson().fromJson(response.body(), JsonArray.class); ApiConfig.get().loadLives(livesArray); - liveChannelGroupList.clear(); - liveChannelGroupList.addAll(ApiConfig.get().getChannelGroupList()); - if (liveChannelGroupList == null || liveChannelGroupList.size() == 0) { + List list = ApiConfig.get().getChannelGroupList(); + if (list.isEmpty()) { Toast.makeText(App.getInstance(), "频道列表为空", Toast.LENGTH_SHORT).show(); finish(); return; } + liveChannelGroupList.clear(); + liveChannelGroupList.addAll(list); mHandler.post(new Runnable() { @Override @@ -819,31 +804,30 @@ public class LivePlayActivity extends BaseActivity { private void initLiveState() { String lastChannelName = Hawk.get(HawkConfig.LIVE_CHANNEL, ""); - boolean found = false; + int lastChannelGroupIndex = -1; + int lastLiveChannelIndex = -1; for (LiveChannelGroup liveChannelGroup : liveChannelGroupList) { for (LiveChannelItem liveChannelItem : liveChannelGroup.getLiveChannels()) { if (liveChannelItem.getChannelName().equals(lastChannelName)) { - found = true; - currentChannelGroupIndex = liveChannelGroup.getGroupIndex(); - currentLiveChannelIndex = liveChannelItem.getChannelIndex(); - selectedChannelGroupIndex = currentChannelGroupIndex; + lastChannelGroupIndex = liveChannelGroup.getGroupIndex(); + lastLiveChannelIndex = liveChannelItem.getChannelIndex(); break; } } - if (found) break; + if (lastChannelGroupIndex != -1) break; + } + if (lastChannelGroupIndex == -1) { + lastChannelGroupIndex = getFirstNoPasswordChannelGroup(); + if (lastChannelGroupIndex == -1) + lastChannelGroupIndex = 0; + lastLiveChannelIndex = 0; } tvLeftChannelListLayout.setVisibility(View.INVISIBLE); tvRightSettingLayout.setVisibility(View.INVISIBLE); liveChannelGroupAdapter.setNewData(liveChannelGroupList); - liveChannelItemAdapter.setNewData(liveChannelGroupList.get(currentChannelGroupIndex).getLiveChannels()); - mChannelGroupView.scrollToPosition(currentChannelGroupIndex); - mLiveChannelView.scrollToPosition(currentLiveChannelIndex); - liveChannelGroupAdapter.setSelectedGroupIndex(currentChannelGroupIndex); - liveChannelItemAdapter.setSelectedChannelIndex(currentLiveChannelIndex); - - playChannel(false); + selectChannelGroup(lastChannelGroupIndex, false, lastLiveChannelIndex); } private boolean isListOrSettingLayoutVisible() { @@ -851,13 +835,13 @@ public class LivePlayActivity extends BaseActivity { } private void initLiveSettingGroupList() { - ArrayList groupNames = new ArrayList(Arrays.asList("线路选择", "画面比例", "播放解码", "超时换源", "偏好设置")); + 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("显示时间", "显示网速", "换台反转", "跨选分类")); + 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); @@ -935,4 +919,129 @@ public class LivePlayActivity extends BaseActivity { mHandler.postDelayed(this, 1000); } }; + + private void showPasswordDialog(int groupIndex, int liveChannelIndex) { + if (tvLeftChannelListLayout.getVisibility() == View.VISIBLE) + mHandler.removeCallbacks(mHideChannelListRun); + + LivePasswordDialog dialog = new LivePasswordDialog(this); + dialog.setOnListener(new LivePasswordDialog.OnListener() { + @Override + public void onChange(String password) { + if (password.equals(liveChannelGroupList.get(groupIndex).getGroupPassword())) { + channelGroupPasswordConfirmed.add(groupIndex); + loadChannelGroupDataAndPlay(groupIndex, liveChannelIndex); + } else { + Toast.makeText(App.getInstance(), "密码错误", Toast.LENGTH_SHORT).show(); + } + + if (tvLeftChannelListLayout.getVisibility() == View.VISIBLE) + mHandler.postDelayed(mHideChannelListRun, 5000); + } + + @Override + public void onCancel() { + if (tvLeftChannelListLayout.getVisibility() == View.VISIBLE) { + int groupIndex = liveChannelGroupAdapter.getSelectedGroupIndex(); + liveChannelItemAdapter.setNewData(getLiveChannels(groupIndex)); + } + } + }); + dialog.show(); + } + + private void loadChannelGroupDataAndPlay(int groupIndex, int liveChannelIndex) { + liveChannelItemAdapter.setNewData(getLiveChannels(groupIndex)); + if (groupIndex == currentChannelGroupIndex) { + if (currentLiveChannelIndex > -1) + mLiveChannelView.scrollToPosition(currentLiveChannelIndex); + liveChannelItemAdapter.setSelectedChannelIndex(currentLiveChannelIndex); + } + else { + mLiveChannelView.scrollToPosition(0); + liveChannelItemAdapter.setSelectedChannelIndex(-1); + } + + if (liveChannelIndex > -1) { + clickLiveChannel(liveChannelIndex); + mChannelGroupView.scrollToPosition(groupIndex); + mLiveChannelView.scrollToPosition(liveChannelIndex); + playChannel(groupIndex, liveChannelIndex, false); + } + } + + private boolean isNeedInputPassword(int groupIndex) { + return !liveChannelGroupList.get(groupIndex).getGroupPassword().isEmpty() + && !isPasswordConfirmed(groupIndex); + } + + private boolean isPasswordConfirmed(int groupIndex) { + for (Integer confirmedNum : channelGroupPasswordConfirmed) { + if (confirmedNum == groupIndex) + return true; + } + return false; + } + + private ArrayList getLiveChannels(int groupIndex) { + if (!isNeedInputPassword(groupIndex)) { + return liveChannelGroupList.get(groupIndex).getLiveChannels(); + } else { + return new ArrayList<>(); + } + } + + private Integer[] getNextChannel(int direction) { + int channelGroupIndex = currentChannelGroupIndex; + int liveChannelIndex = currentLiveChannelIndex; + + //跨选分组模式下跳过加密频道分组(遥控器上下键换台/超时换源) + if (direction > 0) { + liveChannelIndex++; + if (liveChannelIndex >= getLiveChannels(channelGroupIndex).size()) { + liveChannelIndex = 0; + if (Hawk.get(HawkConfig.LIVE_CROSS_GROUP, false)) { + do { + channelGroupIndex++; + if (channelGroupIndex >= liveChannelGroupList.size()) + channelGroupIndex = 0; + } while (!liveChannelGroupList.get(channelGroupIndex).getGroupPassword().isEmpty() || channelGroupIndex == currentChannelGroupIndex); + } + } + } else { + liveChannelIndex--; + if (liveChannelIndex < 0) { + if (Hawk.get(HawkConfig.LIVE_CROSS_GROUP, false)) { + do { + channelGroupIndex--; + if (channelGroupIndex < 0) + channelGroupIndex = liveChannelGroupList.size() - 1; + } while (!liveChannelGroupList.get(channelGroupIndex).getGroupPassword().isEmpty() || channelGroupIndex == currentChannelGroupIndex); + } + liveChannelIndex = getLiveChannels(channelGroupIndex).size() - 1; + } + } + + Integer[] groupChannelIndex = new Integer[2]; + groupChannelIndex[0] = channelGroupIndex; + groupChannelIndex[1] = liveChannelIndex; + + return groupChannelIndex; + } + + private int getFirstNoPasswordChannelGroup() { + for (LiveChannelGroup liveChannelGroup : liveChannelGroupList) { + if (liveChannelGroup.getGroupPassword().isEmpty()) + return liveChannelGroup.getGroupIndex(); + } + return -1; + } + + private boolean isCurrentLiveChannelValid() { + if (currentLiveChannelItem == null) { + Toast.makeText(App.getInstance(), "请先选择频道", Toast.LENGTH_SHORT).show(); + return false; + } + return true; + } } \ 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 index 14c8f1a1..c52f79c5 100644 --- 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 @@ -37,6 +37,7 @@ public class LiveChannelGroupAdapter extends BaseQuickAdapter + + + + + + + + + + \ No newline at end of file