From ba60fca04f497d257187f6ea7052045c5969b6aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8E=E4=BF=8A?= <215613905@qq.com> Date: Fri, 7 Mar 2025 14:08:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=89=AB=E7=A0=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=85=8D=E7=BD=AE=E5=9C=B0=E5=9D=80=E6=97=B6=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E9=85=8D=E7=BD=AE=E6=9C=AA=E5=8F=98=E5=8A=A8=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98;=20=E8=A7=A3=E5=86=B3=E5=9B=A0=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E9=A2=91=E9=81=93=E8=BF=87=E5=A4=9A=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E9=A2=91=E9=81=93=E5=88=97=E8=A1=A8=E5=8D=A1=E9=A1=BF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/github/tvbox/osc/api/ApiConfig.java | 2 +- .../tvbox/osc/bean/LiveChannelItem.java | 15 +++++++ .../osc/ui/activity/LivePlayActivity.java | 45 +++++++++++++++---- .../github/tvbox/osc/ui/dialog/ApiDialog.java | 1 + gradle.properties | 2 +- 5 files changed, 55 insertions(+), 10 deletions(-) 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 babe776b..0eb13d4c 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 @@ -171,7 +171,7 @@ public class ApiConfig { String liveApiUrl = Hawk.get(HawkConfig.LIVE_API_URL, ""); String liveApiConfigUrl=configUrl(liveApiUrl); if(!liveApiUrl.isEmpty() && !liveApiUrl.equals(apiUrl)){ - if(liveApiUrl.contains(".txt") || liveApiUrl.contains(".m3u")){ + if(liveApiUrl.contains(".txt") || liveApiUrl.contains(".m3u") || liveApiUrl.contains("=txt") || liveApiUrl.contains("=m3u")){ initLiveSettings(); defaultLiveObjString = defaultLiveObjString.replace("txt_m3u_url",liveApiConfigUrl); parseLiveJson(liveApiUrl,defaultLiveObjString); diff --git a/app/src/main/java/com/github/tvbox/osc/bean/LiveChannelItem.java b/app/src/main/java/com/github/tvbox/osc/bean/LiveChannelItem.java index 504adc7c..326248dd 100644 --- a/app/src/main/java/com/github/tvbox/osc/bean/LiveChannelItem.java +++ b/app/src/main/java/com/github/tvbox/osc/bean/LiveChannelItem.java @@ -1,6 +1,7 @@ package com.github.tvbox.osc.bean; import java.util.ArrayList; +import java.util.Objects; /** * @author pj567 @@ -101,4 +102,18 @@ public class LiveChannelItem { public String getSourceName() { return channelSourceNames.get(sourceIndex); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + LiveChannelItem that = (LiveChannelItem) o; + return Objects.equals(channelName, that.channelName) + && Objects.equals(channelUrls.get(sourceIndex), that.getUrl()); + } + + @Override + public int hashCode() { + return Objects.hash(channelName, channelUrls.get(sourceIndex)); + } } \ No newline at end of file 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 df045c9e..e2bd29d0 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 @@ -676,20 +676,49 @@ public class LivePlayActivity extends BaseActivity { return; } if (tvLeftChannelListLayout.getVisibility() == View.INVISIBLE) { - //重新载入上一次状态 - liveChannelItemAdapter.setNewData(getLiveChannels(currentChannelGroupIndex)); - if (currentLiveChannelIndex > -1) + refreshChannelList(currentChannelGroupIndex); + if (currentLiveChannelIndex > -1){ mLiveChannelView.scrollToPosition(currentLiveChannelIndex); - mLiveChannelView.setSelection(currentLiveChannelIndex); - mChannelGroupView.scrollToPosition(currentChannelGroupIndex); - mChannelGroupView.setSelection(currentChannelGroupIndex); - mHandler.postDelayed(mFocusCurrentChannelAndShowChannelList, 200); + mLiveChannelView.setSelection(currentLiveChannelIndex); + } +// mChannelGroupView.scrollToPosition(currentChannelGroupIndex); +// mChannelGroupView.setSelection(currentChannelGroupIndex); + mHandler.postDelayed(mFocusCurrentChannelAndShowChannelList, 50); } else { mHandler.removeCallbacks(mHideChannelListRun); mHandler.post(mHideChannelListRun); } } + private int mLastChannelGroupIndex = -1; + private List mLastChannelList = new ArrayList<>(); + + private void refreshChannelList(int currentChannelGroupIndex) { + // 1. 获取新数据 + List newChannels = getLiveChannels(currentChannelGroupIndex); + // 2. 判断数据是否变化(相同组索引且数据内容未变) + if (currentChannelGroupIndex == mLastChannelGroupIndex + && isSameData(newChannels, mLastChannelList)) { + return; // 数据未变化,跳过刷新 解决部分直播频道过多时卡顿 + } + mLastChannelGroupIndex = currentChannelGroupIndex; + mLastChannelList = new ArrayList<>(newChannels); + liveChannelItemAdapter.setNewData(newChannels); + } + + // 对比两个列表内容是否相同 + private boolean isSameData(List list1, List list2) { +// return list1.size() == list2.size(); + if (list1 == list2) return true; + if (list1 == null || list2 == null || list1.size() != list2.size()) return false; + for (int i = 0; i < list1.size(); i++) { + if (!list1.get(i).equals(list2.get(i))) { + return false; + } + } + return true; + } + private Runnable mFocusCurrentChannelAndShowChannelList = new Runnable() { @Override public void run() { @@ -840,7 +869,7 @@ public class LivePlayActivity extends BaseActivity { selectSettingGroup(0, false); mSettingGroupView.scrollToPosition(0); mSettingItemView.scrollToPosition(currentLiveChannelItem.getSourceIndex()); - mHandler.postDelayed(mFocusAndShowSettingGroup, 200); + mHandler.postDelayed(mFocusAndShowSettingGroup, 50); } else { mHandler.removeCallbacks(mHideSettingLayoutRun); mHandler.post(mHideSettingLayoutRun); diff --git a/app/src/main/java/com/github/tvbox/osc/ui/dialog/ApiDialog.java b/app/src/main/java/com/github/tvbox/osc/ui/dialog/ApiDialog.java index 81761804..7fc5f439 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/dialog/ApiDialog.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/dialog/ApiDialog.java @@ -48,6 +48,7 @@ public class ApiDialog extends BaseDialog { public void refresh(RefreshEvent event) { if (event.type == RefreshEvent.TYPE_API_URL_CHANGE) { inputApi.setText((String) event.obj); + inputApiLive.setText((String) event.obj); } } diff --git a/gradle.properties b/gradle.properties index 2b801b14..8e1f9a6b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,4 +18,4 @@ android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true IsDebug=true -org.gradle.jvmargs=-Xmx2048m --add-opens java.base/java.io=ALL-UNNAMED +#org.gradle.jvmargs=-Xmx2048m --add-opens java.base/java.io=ALL-UNNAMED