add live channel group support

pull/1/head
haha459862 4 years ago
parent a85ee4f5fc
commit a78e2e4bab
  1. 10
      .idea/jarRepositories.xml
  2. 3
      .idea/misc.xml
  3. 13
      .idea/runConfigurations.xml
  4. 78
      app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java
  5. 49
      app/src/main/java/com/github/tvbox/osc/bean/ChannelGroup.java
  6. 10
      app/src/main/java/com/github/tvbox/osc/bean/LiveChannel.java
  7. 349
      app/src/main/java/com/github/tvbox/osc/ui/activity/LivePlayActivity.java
  8. 35
      app/src/main/java/com/github/tvbox/osc/ui/adapter/ChannelGroupAdapter.java
  9. 6
      app/src/main/java/com/github/tvbox/osc/ui/adapter/LiveChannelAdapter.java
  10. 58
      app/src/main/res/layout/activity_live_play.xml
  11. 23
      app/src/main/res/layout/item_channel_group_layout.xml

@ -31,5 +31,15 @@
<option name="name" value="maven2" />
<option name="url" value="https://download.01.org/crosswalk/releases/crosswalk/android/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="MavenRepo" />
<option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="Gradle Central Plugin Repository" />
<option name="name" value="Gradle Central Plugin Repository" />
<option name="url" value="https://plugins.gradle.org/m2" />
</remote-repository>
</component>
</project>

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>

@ -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<SourceBean> sourceBeanList;
private SourceBean mHomeSource;
private ParseBean mDefaultParse;
private List<LiveChannel> channelList;
private List<ChannelGroup> channelGroupList;
private List<ParseBean> parseBeanList;
private List<String> vipParseFlags;
private List<IJKCode> 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<String> 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<String> 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<LiveChannel> getChannelList() {
return channelList;
public List<ChannelGroup> getChannelGroupList() {
return channelGroupList;
}
public List<IJKCode> getIjkCodes() {

@ -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<LiveChannel> 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<LiveChannel> getLiveChannels() {
return liveChannels;
}
public void setLiveChannels(ArrayList<LiveChannel> liveChannels) {
this.liveChannels = liveChannels;
}
public boolean isDefault() {
return isDefault;
}
public void setDefault(boolean aDefault) {
isDefault = aDefault;
}
}

@ -16,7 +16,7 @@ public class LiveChannel {
*/
private int channelNum;
private String name;
private String channelName;
private ArrayList<String> 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() {

@ -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<ChannelGroup> 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<LiveChannel> channelList = new ArrayList<>();
private LiveChannel currentChannel = null;
private void initChannelListView() {
List<ChannelGroup> 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.<String>get(url).execute(new AbsCallback<String>() {
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<String> response) {
List<LiveChannel> 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<LiveChannel> 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.<String>get(url).execute(new AbsCallback<String>() {
@Override
public String convertResponse(okhttp3.Response response) throws Throwable {
return response.body().string();
}
}
@Override
public void onSuccess(Response<String> response) {
List<LiveChannel> 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<LiveChannel>());
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<String> urls = DefaultConfig.safeJsonStringList(obj, "urls");
liveChannel.setUrls(urls);
channelGroup.getLiveChannels().add(liveChannel);
}
channelGroupList.add(channelGroup);
}
}
private void initList(List<LiveChannel> 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);
}
}

@ -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<ChannelGroup, BaseViewHolder> {
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);
}
}
}

@ -25,10 +25,10 @@ public class LiveChannelAdapter extends BaseQuickAdapter<LiveChannel, BaseViewHo
TextView tvChannelNum = helper.getView(R.id.tvChannelNum);
TextView tvChannel = helper.getView(R.id.tvChannel);
tvChannelNum.setText(String.format("%s", item.getChannelNum()));
tvChannel.setText(String.format("%s", item.getName()));
tvChannel.setText(item.getChannelName());
if (item.isDefault()) {
tvChannelNum.setTextColor(mContext.getResources().getColor(R.color.color_02F8E1));
tvChannel.setTextColor(mContext.getResources().getColor(R.color.color_02F8E1));
tvChannelNum.setTextColor(mContext.getResources().getColor(R.color.color_1890FF));
tvChannel.setTextColor(mContext.getResources().getColor(R.color.color_1890FF));
} else {
tvChannelNum.setTextColor(Color.WHITE);
tvChannel.setTextColor(Color.WHITE);

@ -9,19 +9,47 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.owen.tvrecyclerview.widget.TvRecyclerView
android:id="@+id/mGridView"
android:layout_width="220mm"
<LinearLayout
android:id="@+id/tvLeftlinearLayout"
android:layout_width="421mm"
android:layout_height="match_parent"
android:layout_marginLeft="0mm"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="visible" >
<com.owen.tvrecyclerview.widget.TvRecyclerView
android:id="@+id/mGroupGridView"
android:layout_width="180mm"
android:layout_height="match_parent"
android:background="@color/color_66000000"
android:paddingLeft="10mm"
android:paddingTop="20mm"
android:paddingRight="10mm"
android:paddingBottom="20mm"
android:visibility="visible"
app:tv_selectedItemIsCentered="true"
app:tv_verticalSpacingWithMargins="10mm" />
<View
android:layout_width="1mm"
android:layout_height="match_parent"
android:background="@color/color_FFFFFF"
android:layout_gravity="center_horizontal" />
<com.owen.tvrecyclerview.widget.TvRecyclerView
android:id="@+id/mChannelGridView"
android:layout_width="240mm"
android:layout_height="match_parent"
android:layout_marginLeft="-220mm"
android:background="@color/color_66000000"
android:paddingLeft="10mm"
android:paddingTop="20mm"
android:paddingRight="10mm"
android:paddingBottom="20mm"
android:visibility="gone"
android:visibility="visible"
app:tv_selectedItemIsCentered="true"
app:tv_verticalSpacingWithMargins="20mm" />
app:tv_verticalSpacingWithMargins="10mm" />
</LinearLayout>
<TextView
android:id="@+id/tvChannel"
@ -39,24 +67,6 @@
android:textStyle="bold"
android:visibility="gone" />
<TextView
android:id="@+id/tvUrl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_marginRight="30mm"
android:layout_marginBottom="90mm"
android:background="@drawable/channel_num_shape"
android:gravity="center"
android:paddingLeft="10mm"
android:paddingTop="5mm"
android:paddingRight="10mm"
android:paddingBottom="5mm"
android:singleLine="true"
android:text="http://"
android:textColor="@android:color/white"
android:textSize="24mm" />
<TextView
android:id="@+id/tvHint"
android:layout_width="wrap_content"

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10mm"
android:layout_marginBottom="10mm"
android:background="@drawable/live_focus"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal">
<TextView
android:id="@+id/tvGroupName"
android:layout_width="0mm"
android:layout_height="60mm"
android:layout_weight="1"
android:ellipsize="marquee"
android:gravity="center"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="22mm" />
</LinearLayout>
Loading…
Cancel
Save