From a78e2e4babb26d9e6cbc3dd5b89c8c79d00f9cff Mon Sep 17 00:00:00 2001
From: haha459862 <459862@163.com>
Date: Sat, 25 Jun 2022 13:43:49 +0800
Subject: [PATCH] add live channel group support
---
.idea/jarRepositories.xml | 10 +
.idea/misc.xml | 3 +-
.idea/runConfigurations.xml | 13 -
.../com/github/tvbox/osc/api/ApiConfig.java | 78 ++--
.../github/tvbox/osc/bean/ChannelGroup.java | 49 +++
.../github/tvbox/osc/bean/LiveChannel.java | 10 +-
.../osc/ui/activity/LivePlayActivity.java | 349 +++++++++++-------
.../osc/ui/adapter/ChannelGroupAdapter.java | 35 ++
.../osc/ui/adapter/LiveChannelAdapter.java | 6 +-
.../main/res/layout/activity_live_play.xml | 58 +--
.../res/layout/item_channel_group_layout.xml | 23 ++
11 files changed, 426 insertions(+), 208 deletions(-)
delete mode 100644 .idea/runConfigurations.xml
create mode 100644 app/src/main/java/com/github/tvbox/osc/bean/ChannelGroup.java
create mode 100644 app/src/main/java/com/github/tvbox/osc/ui/adapter/ChannelGroupAdapter.java
create mode 100644 app/src/main/res/layout/item_channel_group_layout.xml
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index 14164b64..047baf83 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -31,5 +31,15 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 860da66a..5c9f89fe 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,7 @@
-
+
+
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
deleted file mode 100644
index e497da99..00000000
--- a/.idea/runConfigurations.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
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 81bd216f..c3789c17 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
@@ -7,6 +7,7 @@ import android.util.Base64;
import com.github.catvod.crawler.JarLoader;
import com.github.catvod.crawler.Spider;
+import com.github.tvbox.osc.bean.ChannelGroup;
import com.github.tvbox.osc.base.App;
import com.github.tvbox.osc.bean.IJKCode;
import com.github.tvbox.osc.bean.LiveChannel;
@@ -20,6 +21,7 @@ import com.github.tvbox.osc.util.DefaultConfig;
import com.github.tvbox.osc.util.HawkConfig;
import com.github.tvbox.osc.util.MD5;
import com.google.gson.Gson;
+import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.lzy.okgo.OkGo;
@@ -50,7 +52,7 @@ public class ApiConfig {
private List sourceBeanList;
private SourceBean mHomeSource;
private ParseBean mDefaultParse;
- private List channelList;
+ private List channelGroupList;
private List parseBeanList;
private List vipParseFlags;
private List ijkCodes;
@@ -63,7 +65,7 @@ public class ApiConfig {
private ApiConfig() {
sourceBeanList = new ArrayList<>();
- channelList = new ArrayList<>();
+ channelGroupList = new ArrayList<>();
parseBeanList = new ArrayList<>();
}
@@ -274,34 +276,29 @@ public class ApiConfig {
}
// 直播源
try {
- int lcIdx = 0;
- for (JsonElement opt : infoJson.get("lives").getAsJsonArray()) {
- for (JsonElement optChl : ((JsonObject) opt).get("channels").getAsJsonArray()) {
- JsonObject obj = (JsonObject) optChl;
- LiveChannel lc = new LiveChannel();
- lc.setName(obj.get("name").getAsString().trim());
- ArrayList urls = DefaultConfig.safeJsonStringList(obj, "urls");
- if (urls.size() > 0) {
- String url = urls.get(0);
- if (url.startsWith("proxy://")) {
- String fix = url.replace("proxy://", "http://0.0.0.0/?");
- String extUrl = Uri.parse(fix).getQueryParameter("ext");
- if (extUrl != null && !extUrl.isEmpty()) {
- String extUrlFix = new String(Base64.decode(extUrl, Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP), "UTF-8");
- if (extUrlFix.startsWith("clan://")) {
- extUrlFix = clanContentFix(clanToAddress(apiUrl), extUrlFix);
- extUrlFix = Base64.encodeToString(extUrlFix.getBytes("UTF-8"), Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP);
- fix = url.replace(extUrl, extUrlFix);
- urls.set(0, fix);
- }
- }
- }
+ String lives = infoJson.get("lives").getAsJsonArray().toString();
+ int index = lives.indexOf("proxy://");
+ if (index != -1) {
+ int endIndex = lives.lastIndexOf("\"");
+ String url = lives.substring(index, endIndex);
+ url = DefaultConfig.checkReplaceProxy(url);
+
+ //clan
+ String extUrl = Uri.parse(url).getQueryParameter("ext");
+ if (extUrl != null && !extUrl.isEmpty()) {
+ String extUrlFix = new String(Base64.decode(extUrl, Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP), "UTF-8");
+ if (extUrlFix.startsWith("clan://")) {
+ extUrlFix = clanContentFix(clanToAddress(apiUrl), extUrlFix);
+ extUrlFix = Base64.encodeToString(extUrlFix.getBytes("UTF-8"), Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP);
+ url = url.replace(extUrl, extUrlFix);
}
- lc.setUrls(urls);
- // 暂时不考虑分组问题
- lc.setChannelNum(lcIdx++);
- channelList.add(lc);
}
+ ChannelGroup channelGroup = new ChannelGroup();
+ channelGroup.setGroupName(url);
+ channelGroupList.add(channelGroup);
+ }
+ else{
+ loadLives(infoJson.get("lives").getAsJsonArray());
}
} catch (Throwable th) {
th.printStackTrace();
@@ -341,6 +338,27 @@ public class ApiConfig {
}
}
+ public void loadLives(JsonArray livesArray)
+ {
+ int groupIndex = 0;
+ int channelIndex = 0;
+ for (JsonElement groupElement : livesArray) {
+ ChannelGroup channelGroup = new ChannelGroup();
+ channelGroup.setGroupNum(groupIndex++);
+ 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(channelIndex++);
+ ArrayList urls = DefaultConfig.safeJsonStringList(obj, "urls");
+ liveChannel.setUrls(urls);
+ channelGroup.getLiveChannels().add(liveChannel);
+ }
+ channelGroupList.add(channelGroup);
+ }
+ }
+
public String getSpider() {
return spider;
}
@@ -418,8 +436,8 @@ public class ApiConfig {
return mHomeSource == null ? emptyHome : mHomeSource;
}
- public List getChannelList() {
- return channelList;
+ public List getChannelGroupList() {
+ return channelGroupList;
}
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
new file mode 100644
index 00000000..6ad64299
--- /dev/null
+++ b/app/src/main/java/com/github/tvbox/osc/bean/ChannelGroup.java
@@ -0,0 +1,49 @@
+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 isDefault;
+
+
+ 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 isDefault() {
+ return isDefault;
+ }
+
+ public void setDefault(boolean aDefault) {
+ isDefault = aDefault;
+ }
+}
diff --git a/app/src/main/java/com/github/tvbox/osc/bean/LiveChannel.java b/app/src/main/java/com/github/tvbox/osc/bean/LiveChannel.java
index bd06c2e0..949e0cb9 100644
--- a/app/src/main/java/com/github/tvbox/osc/bean/LiveChannel.java
+++ b/app/src/main/java/com/github/tvbox/osc/bean/LiveChannel.java
@@ -16,7 +16,7 @@ public class LiveChannel {
*/
private int channelNum;
- private String name;
+ private String channelName;
private ArrayList urls;
private boolean isDefault;
public int sourceIdx = 0;
@@ -29,12 +29,12 @@ public class LiveChannel {
return channelNum;
}
- public void setName(String name) {
- this.name = name;
+ public void setChannelName(String channelName) {
+ this.channelName = channelName;
}
- public String getName() {
- return name;
+ public String getChannelName() {
+ return channelName;
}
public String getUrls() {
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 935a3fe5..c56b4003 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
@@ -9,6 +9,7 @@ import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
@@ -20,9 +21,11 @@ import com.dueeeke.videoplayer.player.VideoView;
import com.github.tvbox.osc.R;
import com.github.tvbox.osc.api.ApiConfig;
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.player.controller.BoxVideoController;
import com.github.tvbox.osc.ui.adapter.LiveChannelAdapter;
+import com.github.tvbox.osc.ui.adapter.ChannelGroupAdapter;
import com.github.tvbox.osc.ui.tv.widget.ViewObj;
import com.github.tvbox.osc.util.DefaultConfig;
import com.github.tvbox.osc.util.FastClickCheckUtil;
@@ -50,12 +53,21 @@ import java.util.List;
public class LivePlayActivity extends BaseActivity {
private VideoView mVideoView;
private TextView tvHint;
- private TextView tvUrl;
private TextView tvChannel;
- private TvRecyclerView mGridView;
+ private LinearLayout tvLeftLinearLayout;
+ private TvRecyclerView mGroupGridView;
+ private TvRecyclerView mChannelGridView;
+ private ChannelGroupAdapter groupAdapter;
private LiveChannelAdapter channelAdapter;
private Handler mHandler = new Handler();
+ private List channelGroupList = new ArrayList<>();
+ private int selectedGroupIndex = 0;
+ private int currentGroupIndex = 0;
+ private int currentChannelIndex = 0;
+ private LiveChannel currentChannel = null;
+
+
@Override
protected int getLayoutResID() {
return R.layout.activity_live_play;
@@ -70,13 +82,16 @@ public class LivePlayActivity extends BaseActivity {
// layoutParams.width = 100;
// layoutParams.height = 50;
// mVideoView.setLayoutParams(layoutParams);
- mGridView = findViewById(R.id.mGridView);
+ 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);
- tvUrl = findViewById(R.id.tvUrl);
- mGridView.setHasFixedSize(true);
- mGridView.setLayoutManager(new V7LinearLayoutManager(this.mContext, 1, false));
+ mGroupGridView.setHasFixedSize(true);
+ mGroupGridView.setLayoutManager(new V7LinearLayoutManager(this.mContext, 1, false));
+ mChannelGridView.setHasFixedSize(true);
+ mChannelGridView.setLayoutManager(new V7LinearLayoutManager(this.mContext, 1, false));
BoxVideoController controller = new BoxVideoController(this);
controller.setScreenTapListener(new BoxVideoController.OnScreenTapListener() {
@Override
@@ -91,12 +106,55 @@ public class LivePlayActivity extends BaseActivity {
mVideoView.setVideoController(controller);
mVideoView.setProgressManager(null);
- initChannelList();
+ groupAdapter = new ChannelGroupAdapter();
+ mGroupGridView.setAdapter(groupAdapter);
+ mGroupGridView.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
+ super.onScrollStateChanged(recyclerView, newState);
+ mHandler.removeCallbacks(mHideChannelListRun);
+ mHandler.postDelayed(mHideChannelListRun, 5000);
+ }
+ });
+ groupAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
+ @Override
+ public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
+ FastClickCheckUtil.check(view);
+ channelGroupList.get(selectedGroupIndex).setDefault(false);
+ groupAdapter.notifyItemChanged(selectedGroupIndex);
+ selectedGroupIndex = position;
+ channelGroupList.get(selectedGroupIndex).setDefault(true);
+ groupAdapter.notifyItemChanged(selectedGroupIndex);
+ channelAdapter.setNewData(channelGroupList.get(position).getLiveChannels());
+ }
+ });
+
+ channelAdapter = new LiveChannelAdapter();
+ mChannelGridView.setAdapter(channelAdapter);
+ mChannelGridView.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
+ super.onScrollStateChanged(recyclerView, newState);
+ mHandler.removeCallbacks(mHideChannelListRun);
+ mHandler.postDelayed(mHideChannelListRun, 5000);
+ }
+ });
+ channelAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
+ @Override
+ public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
+ FastClickCheckUtil.check(view);
+ if (playChannel(selectedGroupIndex, position, false)) {
+ mHandler.post(mHideChannelListRun);
+ }
+ }
+ });
+
+ initChannelListView();
}
@Override
public void onBackPressed() {
- if (mGridView.getVisibility() == View.VISIBLE) {
+ if (tvLeftLinearLayout.getVisibility() == View.VISIBLE) {
mHandler.post(mHideChannelListRun);
} else {
super.onBackPressed();
@@ -107,17 +165,17 @@ 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 && mGridView.getVisibility() == View.INVISIBLE) {
+ if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && tvLeftLinearLayout.getVisibility() == View.INVISIBLE) {
playNext();
- } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP && mGridView.getVisibility() == View.INVISIBLE) {
+ } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP && tvLeftLinearLayout.getVisibility() == View.INVISIBLE) {
playPrevious();
- } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT && mGridView.getVisibility() == View.INVISIBLE) {
+ } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT && tvLeftLinearLayout.getVisibility() == View.INVISIBLE) {
preSourceUrl();
- } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && mGridView.getVisibility() == View.INVISIBLE) {
+ } 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*/) && mGridView.getVisibility() == View.INVISIBLE) {
+ } 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 (mGridView.getVisibility() == View.INVISIBLE) {
+ } else if (tvLeftLinearLayout.getVisibility() == View.INVISIBLE) {
switch (keyCode) {
case KeyEvent.KEYCODE_0:
inputChannelNum("0");
@@ -152,7 +210,7 @@ public class LivePlayActivity extends BaseActivity {
}
}
} else if (event.getAction() == KeyEvent.ACTION_UP) {
- if (mGridView.getVisibility() == View.VISIBLE) {
+ if (tvLeftLinearLayout.getVisibility() == View.VISIBLE) {
mHandler.postDelayed(mHideChannelListRun, 5000);
}
}
@@ -165,7 +223,7 @@ public class LivePlayActivity extends BaseActivity {
if (mVideoView != null) {
mVideoView.resume();
}
- if (mGridView.getVisibility() == View.VISIBLE) {
+ if (tvLeftLinearLayout.getVisibility() == View.VISIBLE) {
mHandler.postDelayed(mHideChannelListRun, 5000);
}
}
@@ -187,115 +245,119 @@ public class LivePlayActivity extends BaseActivity {
}
}
- private List channelList = new ArrayList<>();
- private LiveChannel currentChannel = null;
+ private void initChannelListView() {
+ List list = ApiConfig.get().getChannelGroupList();
+ if (list.isEmpty())
+ 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);
+ showSuccess();
+ initLiveState();
+ }
+ }
+
+ public void loadProxyLives(String url) {
+ OkGo.get(url).execute(new AbsCallback() {
- private void initChannelList() {
- channelAdapter = new LiveChannelAdapter();
- mGridView.setAdapter(channelAdapter);
- mGridView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
- public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
- super.onScrollStateChanged(recyclerView, newState);
- mHandler.removeCallbacks(mHideChannelListRun);
- mHandler.postDelayed(mHideChannelListRun, 5000);
+ public String convertResponse(okhttp3.Response response) throws Throwable {
+ return response.body().string();
}
- });
- channelAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
+
@Override
- public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
- FastClickCheckUtil.check(view);
- if (playChannel(channelList.get(position), false)) {
- mHandler.post(mHideChannelListRun);
- }
+ public void onSuccess(Response response) {
+ List list = new ArrayList<>();
+ JsonArray livesArray = new Gson().fromJson(response.body(), JsonArray.class);
+ loadLives(livesArray);
+
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ LivePlayActivity.this.showSuccess();
+ initLiveState();
+ }
+ });
}
});
- List list = ApiConfig.get().getChannelList();
- if (list.isEmpty())
- return;
- if (list.size() > 0 && list.get(0).getUrls().startsWith("proxy://")) {
- showLoading();
- String url = DefaultConfig.checkReplaceProxy(list.get(0).getUrls());
- OkGo.get(url).execute(new AbsCallback() {
-
- @Override
- public String convertResponse(okhttp3.Response response) throws Throwable {
- return response.body().string();
- }
+ }
- @Override
- public void onSuccess(Response response) {
- List list = new ArrayList<>();
- JsonArray lives = new Gson().fromJson(response.body(), JsonArray.class);
- int lcIdx = 0;
- for (JsonElement opt : lives) {
- for (JsonElement optChl : ((JsonObject) opt).get("channels").getAsJsonArray()) {
- JsonObject obj = (JsonObject) optChl;
- LiveChannel lc = new LiveChannel();
- lc.setName(obj.get("name").getAsString().trim());
- lc.setUrls(DefaultConfig.safeJsonStringList(obj, "urls"));
- // 暂时不考虑分组问题
- lc.setChannelNum(lcIdx++);
- list.add(lc);
- }
- }
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- LivePlayActivity.this.showSuccess();
- initList(list);
- }
- });
- }
- });
- } else {
- showSuccess();
- initList(list);
+ 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.setUrls(urls);
+ channelGroup.getLiveChannels().add(liveChannel);
+ }
+ channelGroupList.add(channelGroup);
}
}
- private void initList(List list) {
- if (list.isEmpty())
- return;
- LiveChannel lastChannel = null;
+ private void initLiveState() {
String lastChannelName = Hawk.get(HawkConfig.LIVE_CHANNEL, "");
- channelList.clear();
- channelList.addAll(list);
- for (LiveChannel lc : channelList) {
- if (lc.getName().equals(lastChannelName)) {
- lastChannel = lc;
+
+ 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;
+ break;
+ }
+ channelIndex++;
+ }
+ if (bFound) {
+ selectedGroupIndex = groupIndex;
+ currentGroupIndex = groupIndex;
+ currentChannelIndex = channelIndex;
break;
}
+ groupIndex++;
+ channelIndex = 0;
}
- if (lastChannel == null)
- lastChannel = channelList.get(0);
- mGridView.setVisibility(View.INVISIBLE);
+ tvLeftLinearLayout.setVisibility(View.INVISIBLE);
tvHint.setVisibility(View.INVISIBLE);
- tvUrl.setVisibility(Hawk.get(HawkConfig.DEBUG_OPEN, false) ? View.VISIBLE : View.INVISIBLE);
+// tvUrl.setVisibility(Hawk.get(HawkConfig.DEBUG_OPEN, false) ? View.VISIBLE : View.INVISIBLE);
- channelAdapter.setNewData(channelList);
- playChannel(lastChannel, false);
+ groupAdapter.setNewData(channelGroupList);
+ channelAdapter.setNewData(channelGroupList.get(currentGroupIndex).getLiveChannels());
+ playChannel(currentGroupIndex, currentChannelIndex, false);
}
private void refreshTextInfo() {
- tvUrl.setText(currentChannel.getUrls());
tvChannel.setText(String.format("%d", currentChannel.getChannelNum()));
}
private Runnable mHideChannelListRun = new Runnable() {
@Override
public void run() {
- ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) mGridView.getLayoutParams();
- if (mGridView.getVisibility() == View.VISIBLE) {
- ViewObj viewObj = new ViewObj(mGridView, params);
- ObjectAnimator animator = ObjectAnimator.ofObject(viewObj, "marginLeft", new IntEvaluator(), 0, -mGridView.getLayoutParams().width);
+ 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);
- mGridView.setVisibility(View.INVISIBLE);
+ tvLeftLinearLayout.setVisibility(View.INVISIBLE);
tvHint.setVisibility(View.INVISIBLE);
}
});
@@ -326,11 +388,11 @@ public class LivePlayActivity extends BaseActivity {
private Runnable showListAfterScrollOk = new Runnable() {
@Override
public void run() {
- if (mGridView.isScrolling()) {
+ if (mGroupGridView.isScrolling()) {
mHandler.postDelayed(this, 100);
} else {
- ViewObj viewObj = new ViewObj(mGridView, (ViewGroup.MarginLayoutParams) mGridView.getLayoutParams());
- ObjectAnimator animator = ObjectAnimator.ofObject(viewObj, "marginLeft", new IntEvaluator(), -mGridView.getLayoutParams().width, 0);
+ 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.start();
animator.addListener(new AnimatorListenerAdapter() {
@@ -346,10 +408,12 @@ public class LivePlayActivity extends BaseActivity {
};
private void showChannelList() {
- if (mGridView.getVisibility() == View.INVISIBLE) {
+ if (tvLeftLinearLayout.getVisibility() == View.INVISIBLE) {
tvHint.setVisibility(View.VISIBLE);
- mGridView.setVisibility(View.VISIBLE);
- mGridView.setSelection(channelList.indexOf(currentChannel));
+ tvLeftLinearLayout.setVisibility(View.VISIBLE);
+ channelAdapter.setNewData(channelGroupList.get(currentGroupIndex).getLiveChannels());
+ mGroupGridView.setSelection(currentGroupIndex);
+ mChannelGridView.setSelection(currentChannelIndex);
mHandler.postDelayed(showListAfterScrollOk, 100);
}
}
@@ -373,62 +437,83 @@ public class LivePlayActivity extends BaseActivity {
mHandler.postDelayed(mHideChannelNumRun, 4000);
}
- private boolean playChannel(LiveChannel channel, boolean changeSource) {
- if ((channel == currentChannel && !changeSource) || channel == null)
+ private boolean playChannel(int groupIndex, int channelIndex, boolean changeSource) {
+ if (groupIndex < 0 || groupIndex >= channelGroupList.size()
+ || channelIndex < 0 || channelIndex >= channelGroupList.get(groupIndex).getLiveChannels().size())
return false;
- if (currentChannel != null)
- currentChannel.setDefault(false);
- channelAdapter.notifyItemChanged(channelList.indexOf(currentChannel));
- currentChannel = channel;
- currentChannel.setDefault(true);
- channelAdapter.notifyItemChanged(channelList.indexOf(currentChannel));
- showChannelNum();
- Hawk.put(HawkConfig.LIVE_CHANNEL, channel.getName());
+
+ if (groupIndex != currentGroupIndex) {
+ channelGroupList.get(currentGroupIndex).setDefault(false);
+ groupAdapter.notifyItemChanged(currentGroupIndex);
+ }
+ if (channelIndex != currentChannelIndex) {
+ channelGroupList.get(currentGroupIndex).getLiveChannels().get(currentChannelIndex).setDefault(false);
+ channelAdapter.notifyItemChanged(currentChannelIndex);
+ }
+
+ if (!changeSource) {
+ LiveChannel liveChannel = channelGroupList.get(groupIndex).getLiveChannels().get(channelIndex);
+ if ((liveChannel == currentChannel))
+ return false;
+
+ currentGroupIndex = groupIndex;
+ currentChannelIndex = channelIndex;
+ currentChannel = liveChannel;
+ channelGroupList.get(currentGroupIndex).setDefault(true);
+ groupAdapter.notifyItemChanged(currentGroupIndex);
+ channelGroupList.get(currentGroupIndex).getLiveChannels().get(currentChannelIndex).setDefault(true);
+ channelAdapter.notifyItemChanged(currentChannelIndex);
+
+ showChannelNum();
+ Hawk.put(HawkConfig.LIVE_CHANNEL, currentChannel.getChannelName());
+ }
mVideoView.release();
- mVideoView.setUrl(channel.getUrls());
+ mVideoView.setUrl(currentChannel.getUrls());
mVideoView.start();
return true;
}
private boolean playChannelByNum(int channelNum) {
- LiveChannel tempChannel = null;
- for (int i = 0; i < channelList.size(); i++) {
- LiveChannel channel = channelList.get(i);
- if (channel.getChannelNum() == channelNum) {
- tempChannel = channel;
- break;
+ int groupIndex = 0;
+ int channelIndex = 0;
+ boolean bFound = false;
+ for (ChannelGroup channelGroup : channelGroupList) {
+ for (LiveChannel liveChannel : channelGroup.getLiveChannels()) {
+ if (liveChannel.getChannelNum() == channelNum) {
+ return playChannel(groupIndex, channelIndex, false);
+ }
+ channelIndex++;
}
+ groupIndex++;
+ channelIndex = 0;
}
- if (tempChannel == null)
- return false;
- return playChannel(tempChannel, false);
+ return false;
}
private void playNext() {
- int playIndex = channelList.indexOf(currentChannel);
- playIndex++;
- if (playIndex >= channelList.size()) {
- playIndex = 0;
+ currentChannelIndex++;
+ if (currentChannelIndex >= channelGroupList.get(currentGroupIndex).getLiveChannels().size()) {
+ currentChannelIndex = 0;
}
- playChannel(channelList.get(playIndex), false);
+ playChannel(currentGroupIndex, currentChannelIndex, false);
}
private void playPrevious() {
- int playIndex = channelList.indexOf(currentChannel);
- playIndex--;
- if (playIndex < 0) {
- playIndex = channelList.size() - 1;
+ int playIndex = channelGroupList.indexOf(currentChannel);
+ currentChannelIndex--;
+ if (currentChannelIndex < 0) {
+ currentChannelIndex = channelGroupList.get(currentGroupIndex).getLiveChannels().size() - 1;
}
- playChannel(channelList.get(playIndex), false);
+ playChannel(currentGroupIndex, currentChannelIndex, false);
}
public void preSourceUrl() {
currentChannel.sourceIdx--;
- playChannel(currentChannel, true);
+ playChannel(currentGroupIndex, currentChannelIndex, true);
}
public void nextSourceUrl() {
currentChannel.sourceIdx++;
- playChannel(currentChannel, true);
+ playChannel(currentGroupIndex, currentChannelIndex, true);
}
}
\ 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
new file mode 100644
index 00000000..3588036d
--- /dev/null
+++ b/app/src/main/java/com/github/tvbox/osc/ui/adapter/ChannelGroupAdapter.java
@@ -0,0 +1,35 @@
+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_layout, new ArrayList<>());
+ }
+
+ @Override
+ protected void convert(BaseViewHolder helper, ChannelGroup item) {
+ TextView tvGroupName = helper.getView(R.id.tvGroupName);
+ tvGroupName.setText(item.getGroupName());
+ if (item.isDefault()) {
+ 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
index 96e59e12..7ae6076c 100644
--- 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
@@ -25,10 +25,10 @@ public class LiveChannelAdapter extends BaseQuickAdapter
-
+
+
+
+
+
+
+ app:tv_verticalSpacingWithMargins="10mm" />
+
-
-
+
+
+
+
\ No newline at end of file