live channel group password support

pull/1/head
haha459862 4 years ago
parent 72bfa622fd
commit ad274608b0
  1. 8
      app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java
  2. 8
      app/src/main/java/com/github/tvbox/osc/bean/LiveChannelGroup.java
  3. 4
      app/src/main/java/com/github/tvbox/osc/bean/LivePlayerManager.java
  4. 483
      app/src/main/java/com/github/tvbox/osc/ui/activity/LivePlayActivity.java
  5. 5
      app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveChannelGroupAdapter.java
  6. 1
      app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveChannelItemAdapter.java
  7. 62
      app/src/main/java/com/github/tvbox/osc/ui/dialog/LivePasswordDialog.java
  8. 48
      app/src/main/res/layout/dialog_live_password.xml

@ -351,7 +351,13 @@ public class ApiConfig {
LiveChannelGroup liveChannelGroup = new LiveChannelGroup();
liveChannelGroup.setLiveChannels(new ArrayList<LiveChannelItem>());
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;

@ -36,4 +36,12 @@ public class LiveChannelGroup {
public void setLiveChannels(ArrayList<LiveChannelItem> liveChannelItems) {
this.liveChannelItems = liveChannelItems;
}
public String getGroupPassword() {
return groupPassword;
}
public void setGroupPassword(String groupPassword) {
this.groupPassword = groupPassword;
}
}

@ -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) {

@ -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<LiveChannelGroup> 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<Integer> 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<String> response) {
List<LiveChannelItem> 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<LiveChannelGroup> 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<String> groupNames = new ArrayList<String>(Arrays.asList("线路选择", "画面比例", "播放解码", "超时换源", "偏好设置"));
ArrayList<String> groupNames = new ArrayList<>(Arrays.asList("线路选择", "画面比例", "播放解码", "超时换源", "偏好设置"));
ArrayList<ArrayList<String>> itemsArrayList = new ArrayList<>();
ArrayList<String> sourceItems = new ArrayList<String>();
ArrayList<String> scaleItems = new ArrayList<String>(Arrays.asList("默认", "16:9", "4:3", "填充", "原始", "裁剪"));
ArrayList<String> playerDecoderItems = new ArrayList<String>(Arrays.asList("系统", "ijk硬解", "ijk软解", "exo"));
ArrayList<String> timeoutItems = new ArrayList<String>(Arrays.asList("5s", "10s", "15s", "20s", "25s", "30s"));
ArrayList<String> personalSettingItems = new ArrayList<String>(Arrays.asList("显示时间", "显示网速", "换台反转", "跨选分类"));
ArrayList<String> sourceItems = new ArrayList<>();
ArrayList<String> scaleItems = new ArrayList<>(Arrays.asList("默认", "16:9", "4:3", "填充", "原始", "裁剪"));
ArrayList<String> playerDecoderItems = new ArrayList<>(Arrays.asList("系统", "ijk硬解", "ijk软解", "exo"));
ArrayList<String> timeoutItems = new ArrayList<>(Arrays.asList("5s", "10s", "15s", "20s", "25s", "30s"));
ArrayList<String> 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<LiveChannelItem> 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;
}
}

@ -37,6 +37,7 @@ public class LiveChannelGroupAdapter extends BaseQuickAdapter<LiveChannelGroup,
}
public void setSelectedGroupIndex(int selectedGroupIndex) {
if (selectedGroupIndex == this.selectedGroupIndex) return;
int preSelectedGroupIndex = this.selectedGroupIndex;
this.selectedGroupIndex = selectedGroupIndex;
if (preSelectedGroupIndex != -1)
@ -45,6 +46,10 @@ public class LiveChannelGroupAdapter extends BaseQuickAdapter<LiveChannelGroup,
notifyItemChanged(this.selectedGroupIndex);
}
public int getSelectedGroupIndex() {
return selectedGroupIndex;
}
public void setFocusedGroupIndex(int focusedGroupIndex) {
this.focusedGroupIndex = focusedGroupIndex;
if (this.focusedGroupIndex != -1)

@ -41,6 +41,7 @@ public class LiveChannelItemAdapter extends BaseQuickAdapter<LiveChannelItem, Ba
}
public void setSelectedChannelIndex(int selectedChannelIndex) {
if (selectedChannelIndex == this.selectedChannelIndex) return;
int preSelectedChannelIndex = this.selectedChannelIndex;
this.selectedChannelIndex = selectedChannelIndex;
if (preSelectedChannelIndex != -1)

@ -0,0 +1,62 @@
package com.github.tvbox.osc.ui.dialog;
import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.widget.EditText;
import androidx.annotation.NonNull;
import com.github.tvbox.osc.R;
import org.jetbrains.annotations.NotNull;
/**
* 描述
*
* @author pj567
* @since 2020/12/27
*/
public class LivePasswordDialog extends BaseDialog {
private EditText inputPassword;
public LivePasswordDialog(@NonNull @NotNull Context context) {
super(context);
setOwnerActivity((Activity) context);
setContentView(R.layout.dialog_live_password);
inputPassword = findViewById(R.id.input);
findViewById(R.id.inputSubmit).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String password = inputPassword.getText().toString().trim();
if (!password.isEmpty()) {
listener.onChange(password);
dismiss();
}
}
});
}
@Override
public void onBackPressed() {
super.onBackPressed();
listener.onCancel();
dismiss();
}
public void setOnListener(OnListener listener) {
this.listener = listener;
}
OnListener listener = null;
public interface OnListener {
void onChange(String password);
void onCancel();
}
}

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="@dimen/vs_400"
android:layout_height="@dimen/vs_150"
android:layout_gravity="center"
android:background="@drawable/shape_dialog_bg_main"
android:orientation="horizontal"
android:padding="@dimen/vs_30">
<EditText
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/input_dialog_api_input"
android:hint="请输入密码"
android:inputType="textPassword"
android:maxLines="1"
android:paddingLeft="2mm"
android:paddingTop="@dimen/vs_10"
android:paddingRight="@dimen/vs_2"
android:paddingBottom="@dimen/vs_10"
android:textColor="@color/color_CC000000"
android:textColorHint="@color/color_6C3D3D3D"
android:textSize="@dimen/ts_26" />
<TextView
android:id="@+id/inputSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/vs_5"
android:background="@drawable/button_dialog_main"
android:focusable="true"
android:gravity="center"
android:padding="@dimen/vs_10"
android:text="确定"
android:textColor="@color/color_FFFFFF"
android:textSize="@dimen/ts_22" />
</LinearLayout>
</FrameLayout>
Loading…
Cancel
Save