🐛 Fix source switching crash & enhance stability (v3.0.4)

### 🐛 Bug Fixes
- Fix random crashes when switching video sources in settings management
- Enhanced VodConfig.setHome() null pointer exception handling
- Improved Fragment lifecycle checks to prevent crashes
- Optimized HistoryDialog source switching safety
- Enhanced thread safety for concurrent loading

###  Performance Improvements
- Added automatic cache cleaning functionality
- Improved memory usage optimization
- Enhanced network request stability

### 🆕 New Features
- Added comprehensive error handling mechanisms
- Enhanced crash protection functionality
- Improved Fragment state validation

### 📱 Build Improvements
- Updated README with professional documentation
- Enhanced build configuration for ARM64-V8A and ARM V7A
- Improved APK packaging and signing process
This commit is contained in:
您的名字
2025-07-30 21:25:10 +08:00
parent 0d7b25710c
commit dab1425dea
345 changed files with 40300 additions and 754 deletions
+5
View File
@@ -106,6 +106,11 @@
android:configChanges="screenSize|smallestScreenSize|screenLayout|uiMode"
android:screenOrientation="fullUser" />
<activity
android:name=".ui.activity.SettingPlayerActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|uiMode"
android:screenOrientation="fullUser" />
<activity
android:name=".ui.activity.VideoActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|uiMode|orientation"
@@ -85,7 +85,36 @@ public class Updater implements Download.Callback {
Logger.d("Current version: " + BuildConfig.VERSION_NAME);
Logger.d("Latest version: " + tagName);
if (tagName.startsWith("v")) tagName = tagName.substring(1);
return Setting.getUpdate() && !tagName.equals(BuildConfig.VERSION_NAME);
// 版本比较逻辑
try {
String[] currentParts = BuildConfig.VERSION_NAME.split("\\.");
String[] remoteParts = tagName.split("\\.");
// 比较主版本号
for (int i = 0; i < Math.min(currentParts.length, remoteParts.length); i++) {
int current = Integer.parseInt(currentParts[i]);
int remote = Integer.parseInt(remoteParts[i]);
if (remote > current) {
return Setting.getUpdate(); // 远程版本高于当前版本,需要更新
} else if (remote < current) {
return false; // 远程版本低于当前版本,不需要更新
}
// 如果相等,继续比较下一级版本号
}
// 如果前面的版本号都相等,但远程版本有更多的版本号,视为更新
if (remoteParts.length > currentParts.length) {
return Setting.getUpdate();
}
return false; // 版本相同或远程版本较低,不需要更新
} catch (NumberFormatException e) {
// 如果版本号解析失败,退回到简单字符串比较
Logger.e("Version parsing failed", e);
return Setting.getUpdate() && !tagName.equals(BuildConfig.VERSION_NAME);
}
}
private void doInBackground(Activity activity) {
@@ -0,0 +1,56 @@
package com.fongmi.android.tv.ui.activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.viewbinding.ViewBinding;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.databinding.ActivityCrashBinding;
import com.fongmi.android.tv.ui.base.BaseActivity;
import java.util.Objects;
import cat.ereza.customactivityoncrash.CustomActivityOnCrash;
public class CrashActivity extends BaseActivity {
private ActivityCrashBinding mBinding;
private String errorDetails;
@Override
protected ViewBinding getBinding() {
return mBinding = ActivityCrashBinding.inflate(getLayoutInflater());
}
@Override
protected void initView(Bundle savedInstanceState) {
errorDetails = CustomActivityOnCrash.getAllErrorDetailsFromIntent(this, getIntent());
mBinding.error.setText(errorDetails);
}
@Override
protected void initEvent() {
mBinding.copy.setOnClickListener(v -> copyErrorToClipboard());
mBinding.restart.setOnClickListener(v -> CustomActivityOnCrash.restartApplication(this, Objects.requireNonNull(CustomActivityOnCrash.getConfigFromIntent(getIntent()))));
}
private void copyErrorToClipboard() {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(getString(R.string.crash_details_title), errorDetails);
clipboard.setPrimaryClip(clip);
Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
showError();
}
private void showError() {
new AlertDialog.Builder(this)
.setTitle(R.string.crash_details_title)
.setMessage(errorDetails)
.setPositiveButton(R.string.crash_details_close, null)
.show();
}
}
@@ -33,7 +33,6 @@ import com.fongmi.android.tv.server.Server;
import com.fongmi.android.tv.ui.base.BaseActivity;
import com.fongmi.android.tv.ui.custom.FragmentStateManager;
import com.fongmi.android.tv.ui.fragment.SettingFragment;
import com.fongmi.android.tv.ui.fragment.SettingPlayerFragment;
import com.fongmi.android.tv.ui.fragment.VodFragment;
import com.fongmi.android.tv.utils.FileChooser;
import com.fongmi.android.tv.utils.Notify;
@@ -95,7 +94,6 @@ public class HomeActivity extends BaseActivity implements NavigationBarView.OnIt
public Fragment getItem(int position) {
if (position == 0) return VodFragment.newInstance();
if (position == 1) return SettingFragment.newInstance();
if (position == 2) return SettingPlayerFragment.newInstance();
return null;
}
};
@@ -210,8 +208,6 @@ public class HomeActivity extends BaseActivity implements NavigationBarView.OnIt
protected void onBackPress() {
if (!mBinding.navigation.getMenu().findItem(R.id.vod).isVisible()) {
setNavigation();
} else if (mManager.isVisible(2)) {
change(1);
} else if (mManager.isVisible(1)) {
mBinding.navigation.setSelectedItemId(R.id.vod);
} else if (mManager.canBack(0)) {
@@ -1,41 +1,38 @@
package com.fongmi.android.tv.ui.fragment;
package com.fongmi.android.tv.ui.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewbinding.ViewBinding;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.Setting;
import com.fongmi.android.tv.databinding.FragmentSettingPlayerBinding;
import com.fongmi.android.tv.databinding.ActivitySettingPlayerBinding;
import com.fongmi.android.tv.impl.BufferCallback;
import com.fongmi.android.tv.impl.SpeedCallback;
import com.fongmi.android.tv.impl.UaCallback;
import com.fongmi.android.tv.ui.base.BaseFragment;
import com.fongmi.android.tv.ui.base.BaseActivity;
import com.fongmi.android.tv.ui.dialog.BufferDialog;
import com.fongmi.android.tv.ui.dialog.SpeedDialog;
import com.fongmi.android.tv.ui.dialog.UaDialog;
import com.fongmi.android.tv.utils.ResUtil;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.text.DecimalFormat;
public class SettingPlayerFragment extends BaseFragment implements UaCallback, BufferCallback, SpeedCallback {
public class SettingPlayerActivity extends BaseActivity implements UaCallback, BufferCallback, SpeedCallback {
private FragmentSettingPlayerBinding mBinding;
private ActivitySettingPlayerBinding mBinding;
private DecimalFormat format;
private String[] background;
private String[] caption;
private String[] render;
private String[] scale;
public static SettingPlayerFragment newInstance() {
return new SettingPlayerFragment();
public static void start(Activity activity) {
activity.startActivity(new Intent(activity, SettingPlayerActivity.class));
}
private String getSwitch(boolean value) {
@@ -43,14 +40,13 @@ public class SettingPlayerFragment extends BaseFragment implements UaCallback, B
}
@Override
protected ViewBinding getBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup container) {
return mBinding = FragmentSettingPlayerBinding.inflate(inflater, container, false);
protected ViewBinding getBinding() {
return mBinding = ActivitySettingPlayerBinding.inflate(getLayoutInflater());
}
@Override
protected void initView() {
protected void initView(Bundle savedInstanceState) {
format = new DecimalFormat("0.#");
mBinding.back.setOnClickListener(v -> requireActivity().onBackPressed());
mBinding.uaText.setText(Setting.getUa());
mBinding.tunnelSwitch.setChecked(Setting.isTunnel());
mBinding.audioDecodeSwitch.setChecked(Setting.isAudioPrefer());
@@ -89,6 +85,7 @@ public class SettingPlayerFragment extends BaseFragment implements UaCallback, B
@Override
protected void initEvent() {
mBinding.back.setOnClickListener(v -> finish());
mBinding.ua.setOnClickListener(this::onUa);
mBinding.aac.setOnClickListener(this::setAAC);
mBinding.scale.setOnClickListener(this::onScale);
@@ -120,7 +117,7 @@ public class SettingPlayerFragment extends BaseFragment implements UaCallback, B
}
private void onScale(View view) {
new MaterialAlertDialogBuilder(getActivity()).setTitle(R.string.player_scale).setNegativeButton(R.string.dialog_negative, null).setSingleChoiceItems(scale, Setting.getScale(), (dialog, which) -> {
new com.google.android.material.dialog.MaterialAlertDialogBuilder(this).setTitle(R.string.player_scale).setNegativeButton(R.string.dialog_negative, null).setSingleChoiceItems(scale, Setting.getScale(), (dialog, which) -> {
mBinding.scaleText.setText(scale[which]);
Setting.putScale(which);
dialog.dismiss();
@@ -172,7 +169,7 @@ public class SettingPlayerFragment extends BaseFragment implements UaCallback, B
}
private void onBackground(View view) {
new MaterialAlertDialogBuilder(getActivity()).setTitle(R.string.player_background).setNegativeButton(R.string.dialog_negative, null).setSingleChoiceItems(background, Setting.getBackground(), (dialog, which) -> {
new com.google.android.material.dialog.MaterialAlertDialogBuilder(this).setTitle(R.string.player_background).setNegativeButton(R.string.dialog_negative, null).setSingleChoiceItems(background, Setting.getBackground(), (dialog, which) -> {
mBinding.backgroundText.setText(background[which]);
Setting.putBackground(which);
dialog.dismiss();
@@ -190,9 +187,4 @@ public class SettingPlayerFragment extends BaseFragment implements UaCallback, B
Setting.putDanmakuLoad(isChecked);
mBinding.danmakuLoadSwitch.setChecked(isChecked);
}
@Override
public void onHiddenChanged(boolean hidden) {
if (!hidden) initView();
}
}
}
@@ -513,7 +513,10 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
mBinding.swipeLayout.setRefreshing(false);
if (result.getList().isEmpty()) setEmpty(result.hasMsg());
else setDetail(result.getList().get(0));
Notify.show(result.getMsg());
// 只在有错误或重要消息时显示提示
if (result.hasMsg() && result.getList().isEmpty()) {
Notify.show(result.getMsg());
}
}
private void setEmpty(boolean finish) {
@@ -1,5 +1,6 @@
package com.fongmi.android.tv.ui.dialog;
import android.app.Activity;
import android.content.DialogInterface;
import android.view.LayoutInflater;
@@ -22,11 +23,20 @@ public class BufferDialog {
return new BufferDialog(fragment);
}
public static BufferDialog create(Activity activity) {
return new BufferDialog(activity);
}
public BufferDialog(Fragment fragment) {
this.callback = (BufferCallback) fragment;
this.binding = DialogBufferBinding.inflate(LayoutInflater.from(fragment.getContext()));
}
public BufferDialog(Activity activity) {
this.callback = (BufferCallback) activity;
this.binding = DialogBufferBinding.inflate(LayoutInflater.from(activity));
}
public void show() {
initDialog();
initView();
@@ -60,8 +60,35 @@ public class HistoryDialog implements ConfigAdapter.OnClickListener {
@Override
public void onTextClick(Config item) {
callback.setConfig(item);
// 防止重复点击和空值
if (!dialog.isShowing() || item == null) return;
// 检查callback是否有效
if (callback == null) {
dialog.dismiss();
return;
}
// 先关闭对话框,避免时序冲突
dialog.dismiss();
// 延迟执行配置设置,确保对话框完全关闭
App.post(() -> {
try {
// 双重检查callback和item是否仍然有效
if (callback != null && item != null && !item.isEmpty()) {
callback.setConfig(item);
}
} catch (Exception e) {
e.printStackTrace();
// 如果出现异常,显示错误提示
try {
Notify.show("配置切换失败: " + e.getMessage());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}, 150); // 增加延迟到150毫秒
}
@Override
@@ -1,5 +1,6 @@
package com.fongmi.android.tv.ui.dialog;
import android.app.Activity;
import android.content.DialogInterface;
import android.view.LayoutInflater;
@@ -22,11 +23,20 @@ public class SpeedDialog {
return new SpeedDialog(fragment);
}
public static SpeedDialog create(Activity activity) {
return new SpeedDialog(activity);
}
public SpeedDialog(Fragment fragment) {
this.callback = (SpeedCallback) fragment;
this.binding = DialogSpeedBinding.inflate(LayoutInflater.from(fragment.getContext()));
}
public SpeedDialog(Activity activity) {
this.callback = (SpeedCallback) activity;
this.binding = DialogSpeedBinding.inflate(LayoutInflater.from(activity));
}
public void show() {
initDialog();
initView();
@@ -1,5 +1,6 @@
package com.fongmi.android.tv.ui.dialog;
import android.app.Activity;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.view.LayoutInflater;
@@ -27,12 +28,22 @@ public class UaDialog {
return new UaDialog(fragment);
}
public static UaDialog create(Activity activity) {
return new UaDialog(activity);
}
public UaDialog(Fragment fragment) {
this.callback = (UaCallback) fragment;
this.binding = DialogUaBinding.inflate(LayoutInflater.from(fragment.getContext()));
this.append = true;
}
public UaDialog(Activity activity) {
this.callback = (UaCallback) activity;
this.binding = DialogUaBinding.inflate(LayoutInflater.from(activity));
this.append = true;
}
public void show() {
initDialog();
initView();
@@ -37,6 +37,7 @@ import com.fongmi.android.tv.impl.ProxyCallback;
import com.fongmi.android.tv.impl.SiteCallback;
import com.fongmi.android.tv.player.Source;
import com.fongmi.android.tv.ui.activity.HomeActivity;
import com.fongmi.android.tv.ui.activity.SettingPlayerActivity;
import com.fongmi.android.tv.ui.base.BaseFragment;
import com.fongmi.android.tv.ui.dialog.AboutDialog;
import com.fongmi.android.tv.ui.dialog.ConfigDialog;
@@ -98,10 +99,10 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
@Override
protected void initView() {
setSourceHintText(mBinding.vodUrl, VodConfig.getDesc());
setSourceHintText(mBinding.liveUrl, LiveConfig.getDesc());
setSourceHintText(mBinding.wallUrl, WallConfig.getDesc());
mBinding.versionText.setText(BuildConfig.VERSION_NAME);
setSourceHintText(mBinding.vodUrl, VodConfig.getDesc(), R.string.source_hint_setting);
setSourceHintText(mBinding.liveUrl, LiveConfig.getDesc(), R.string.source_hint_live);
setSourceHintText(mBinding.wallUrl, WallConfig.getDesc(), R.string.source_hint_wall);
mBinding.versionText.setText(getString(R.string.setting_version) + " " + BuildConfig.VERSION_NAME);
// 设置开关的颜色为黄色
int accentColor = getResources().getColor(R.color.accent);
@@ -170,33 +171,58 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
@Override
public void setConfig(Config config) {
// 如果URL为空,不进行任何操作
if (config.isEmpty()) return;
// 添加Fragment状态检查,防止在无效状态下执行
if (getActivity() == null || !isAdded() || isDetached()) return;
if (config.getUrl().startsWith("file") && !PermissionX.isGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
PermissionX.init(this).permissions(Manifest.permission.WRITE_EXTERNAL_STORAGE).request((allGranted, grantedList, deniedList) -> load(config));
} else {
load(config);
// 如果URL为空,不进行任何操作
if (config == null || config.isEmpty()) return;
try {
if (config.getUrl().startsWith("file") && !PermissionX.isGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
PermissionX.init(this).permissions(Manifest.permission.WRITE_EXTERNAL_STORAGE).request((allGranted, grantedList, deniedList) -> {
if (getActivity() != null && isAdded()) {
load(config);
}
});
} else {
load(config);
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void load(Config config) {
switch (config.getType()) {
case 0:
Notify.progress(getActivity());
VodConfig.load(config, getCallback(0));
mBinding.vodUrl.setText(config.getDesc());
break;
case 1:
Notify.progress(getActivity());
LiveConfig.load(config, getCallback(1));
mBinding.liveUrl.setText(config.getDesc());
break;
case 2:
Notify.progress(getActivity());
WallConfig.load(config, getCallback(2));
mBinding.wallUrl.setText(config.getDesc());
break;
// 再次检查Fragment状态,防止在异步回调中执行
if (getActivity() == null || !isAdded() || isDetached()) return;
try {
switch (config.getType()) {
case 0:
Notify.progress(getActivity());
VodConfig.load(config, getCallback(0));
if (mBinding != null && mBinding.vodUrl != null) {
mBinding.vodUrl.setText(config.getDesc());
}
break;
case 1:
Notify.progress(getActivity());
LiveConfig.load(config, getCallback(1));
if (mBinding != null && mBinding.liveUrl != null) {
mBinding.liveUrl.setText(config.getDesc());
}
break;
case 2:
Notify.progress(getActivity());
WallConfig.load(config, getCallback(2));
if (mBinding != null && mBinding.wallUrl != null) {
mBinding.wallUrl.setText(config.getDesc());
}
break;
}
} catch (Exception e) {
e.printStackTrace();
Notify.dismiss();
}
}
@@ -204,27 +230,33 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
return new Callback() {
@Override
public void success(String result) {
// 检查Fragment是否还在活动状态
if (getActivity() == null || !isAdded()) return;
Notify.show(result);
}
@Override
public void success() {
// 检查Fragment是否还在活动状态
if (getActivity() == null || !isAdded()) return;
setConfig(type);
}
@Override
public void error(String msg) {
// 检查Fragment是否还在活动状态
if (getActivity() == null || !isAdded()) return;
Notify.show(msg);
Notify.dismiss();
switch (type) {
case 0:
setSourceHintText(mBinding.vodUrl, VodConfig.getDesc());
setSourceHintText(mBinding.vodUrl, VodConfig.getDesc(), R.string.source_hint_setting);
break;
case 1:
setSourceHintText(mBinding.liveUrl, LiveConfig.getDesc());
setSourceHintText(mBinding.liveUrl, LiveConfig.getDesc(), R.string.source_hint_live);
break;
case 2:
setSourceHintText(mBinding.wallUrl, WallConfig.getDesc());
setSourceHintText(mBinding.wallUrl, WallConfig.getDesc(), R.string.source_hint_wall);
break;
}
}
@@ -238,27 +270,27 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
Notify.dismiss();
RefreshEvent.video();
RefreshEvent.config();
setSourceHintText(mBinding.vodUrl, VodConfig.getDesc());
setSourceHintText(mBinding.liveUrl, LiveConfig.getDesc());
setSourceHintText(mBinding.wallUrl, WallConfig.getDesc());
setSourceHintText(mBinding.vodUrl, VodConfig.getDesc(), R.string.source_hint_setting);
setSourceHintText(mBinding.liveUrl, LiveConfig.getDesc(), R.string.source_hint_live);
setSourceHintText(mBinding.wallUrl, WallConfig.getDesc(), R.string.source_hint_wall);
break;
case 1:
setCacheText();
Notify.dismiss();
RefreshEvent.config();
setSourceHintText(mBinding.liveUrl, LiveConfig.getDesc());
setSourceHintText(mBinding.liveUrl, LiveConfig.getDesc(), R.string.source_hint_live);
break;
case 2:
setCacheText();
Notify.dismiss();
setSourceHintText(mBinding.wallUrl, WallConfig.getDesc());
setSourceHintText(mBinding.wallUrl, WallConfig.getDesc(), R.string.source_hint_wall);
break;
}
}
private void setSourceHintText(TextView textView, String desc) {
private void setSourceHintText(TextView textView, String desc, int hintStringRes) {
if (TextUtils.isEmpty(desc)) {
SpannableString spannable = new SpannableString(getString(R.string.source_hint));
SpannableString spannable = new SpannableString(getString(hintStringRes));
spannable.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.white)), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new RelativeSizeSpan(0.8f), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
int alpha = (int)(255 * 0.5f);
@@ -328,7 +360,7 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
}
private void onPlayer(View view) {
getRoot().change(2);
SettingPlayerActivity.start(requireActivity());
}
private void onVersion(View view) {
@@ -454,9 +486,9 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
@Override
public void onHiddenChanged(boolean hidden) {
if (hidden) return;
setSourceHintText(mBinding.vodUrl, VodConfig.getDesc());
setSourceHintText(mBinding.liveUrl, LiveConfig.getDesc());
setSourceHintText(mBinding.wallUrl, WallConfig.getDesc());
setSourceHintText(mBinding.vodUrl, VodConfig.getDesc(), R.string.source_hint_setting);
setSourceHintText(mBinding.liveUrl, LiveConfig.getDesc(), R.string.source_hint_live);
setSourceHintText(mBinding.wallUrl, WallConfig.getDesc(), R.string.source_hint_wall);
setCacheText();
}
@@ -26,6 +26,8 @@ import com.fongmi.android.tv.R;
import com.fongmi.android.tv.Setting;
import com.fongmi.android.tv.api.config.VodConfig;
import com.fongmi.android.tv.bean.Class;
import com.fongmi.android.tv.bean.Config;
import com.fongmi.android.tv.bean.History;
import com.fongmi.android.tv.bean.Hot;
import com.fongmi.android.tv.bean.Result;
import com.fongmi.android.tv.bean.Site;
@@ -35,6 +37,7 @@ import com.fongmi.android.tv.event.CastEvent;
import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.event.StateEvent;
import com.fongmi.android.tv.impl.Callback;
import com.fongmi.android.tv.impl.ConfigCallback;
import com.fongmi.android.tv.impl.FilterCallback;
import com.fongmi.android.tv.impl.SiteCallback;
import com.fongmi.android.tv.model.SiteViewModel;
@@ -44,11 +47,14 @@ import com.fongmi.android.tv.ui.activity.KeepActivity;
import com.fongmi.android.tv.ui.activity.VideoActivity;
import com.fongmi.android.tv.ui.adapter.TypeAdapter;
import com.fongmi.android.tv.ui.base.BaseFragment;
import com.fongmi.android.tv.ui.dialog.ConfigDialog;
import com.fongmi.android.tv.ui.dialog.FilterDialog;
import com.fongmi.android.tv.ui.dialog.LastWatchToast;
import com.fongmi.android.tv.ui.dialog.LinkDialog;
import com.fongmi.android.tv.ui.dialog.ReceiveDialog;
import com.fongmi.android.tv.ui.dialog.SiteDialog;
import com.fongmi.android.tv.utils.FileChooser;
import com.fongmi.android.tv.utils.Notify;
import com.fongmi.android.tv.utils.ResUtil;
import com.fongmi.android.tv.utils.UrlUtil;
import com.github.catvod.net.OkHttp;
@@ -68,7 +74,7 @@ import okhttp3.Call;
import okhttp3.Headers;
import okhttp3.Response;
public class VodFragment extends BaseFragment implements SiteCallback, FilterCallback, TypeAdapter.OnClickListener {
public class VodFragment extends BaseFragment implements SiteCallback, FilterCallback, TypeAdapter.OnClickListener, ConfigCallback {
private FragmentVodBinding mBinding;
private SiteViewModel mViewModel;
@@ -99,10 +105,37 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal
EventBus.getDefault().register(this);
setRecyclerView();
setViewModel();
showProgress();
initStartupState(); // 根据是否已有配置来设置初始状态
setLogo();
initHot();
getHot();
// 检查是否需要显示上次播放弹窗
checkLastWatchDialog();
}
// 初始化启动状态:区分已有配置和无配置的情况
private void initStartupState() {
// 检查是否已经有保存的配置,添加空值检查
boolean hasExistingConfig = false;
try {
Config config = VodConfig.get().getConfig();
hasExistingConfig = config != null &&
config.getUrl() != null &&
!config.getUrl().isEmpty();
} catch (Exception e) {
// 如果获取配置时出错,认为没有配置
hasExistingConfig = false;
}
if (hasExistingConfig) {
// 已有配置:显示加载状态,确保不显示添加源提示
showProgress();
mBinding.emptySourceHint.setVisibility(View.GONE);
} else {
// 无配置:立即显示空源提示,不显示加载状态
hideProgress();
checkEmptySource();
}
}
@Override
@@ -127,6 +160,23 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal
});
}
// 添加检查上次播放历史并显示弹窗的方法
private void checkLastWatchDialog() {
if (App.isAppJustLaunched()) {
List<History> histories = History.get();
if (!histories.isEmpty()) {
App.setAppLaunched();
App.post(() -> {
if (getActivity() != null) {
LastWatchToast.create(getActivity(), histories.get(0)).show();
}
}, 1000);
} else {
App.setAppLaunched();
}
}
}
private void setRecyclerView() {
mBinding.type.setHasFixedSize(true);
mBinding.type.setItemAnimator(null);
@@ -173,10 +223,148 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal
setFabVisible(0);
hideProgress();
checkRetry();
checkEmptySource(); // 添加检查是否显示空源提示
}
// 修改checkEmptySource方法,增强鲁棒性
private void checkEmptySource() {
// 检查是否有基础配置文件,添加空值检查
boolean hasBaseConfig = false;
try {
Config config = VodConfig.get().getConfig();
hasBaseConfig = config != null &&
config.getUrl() != null &&
!config.getUrl().isEmpty();
} catch (Exception e) {
hasBaseConfig = false;
}
// 检查是否有有效的站点配置
boolean hasValidSites = false;
boolean hasValidHome = false;
try {
hasValidSites = VodConfig.get().getSites().size() > 0;
Site site = getSite();
hasValidHome = site != null && site.getKey() != null && !site.getKey().isEmpty();
} catch (Exception e) {
hasValidSites = false;
hasValidHome = false;
}
// 只有在完全没有配置文件或配置文件无效时才显示空源提示
boolean isEmpty = !hasBaseConfig || (!hasValidSites || !hasValidHome);
if (mBinding.emptySourceHint != null) {
mBinding.emptySourceHint.setVisibility(isEmpty ? View.VISIBLE : View.GONE);
if (isEmpty) {
// 设置整个布局的点击事件
mBinding.emptySourceHint.setOnClickListener(this::onAddSource);
// 设置按钮的点击事件
if (mBinding.addSourceBtn != null) {
mBinding.addSourceBtn.setOnClickListener(this::onAddSource);
}
// 空源状态下隐藏所有悬浮按钮
hideFabButtons();
}
}
}
// 添加源按钮点击事件处理
private void onAddSource(View view) {
ConfigDialog.create(this).type(0).show();
}
// 实现ConfigCallback接口
@Override
public void setConfig(Config config) {
if (config == null || config.isEmpty()) return;
// 检查Fragment是否还在活动状态,增强检查
if (!isValidFragmentState()) return;
// 安全地隐藏空源提示
try {
if (mBinding != null && mBinding.emptySourceHint != null) {
mBinding.emptySourceHint.setVisibility(View.GONE);
}
} catch (Exception e) {
e.printStackTrace();
}
Notify.progress(getActivity());
VodConfig.load(config, new Callback() {
@Override
public void success() {
// 双重检查Fragment是否还在活动状态
if (!isValidFragmentState()) return;
try {
Notify.dismiss();
RefreshEvent.config();
RefreshEvent.video();
homeContent();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void error(String msg) {
// 双重检查Fragment是否还在活动状态
if (!isValidFragmentState()) return;
try {
Notify.dismiss();
Notify.show(msg);
// 加载失败时重新显示空源提示
checkEmptySource();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
// 添加Fragment状态检查方法
private boolean isValidFragmentState() {
return getActivity() != null &&
!getActivity().isFinishing() &&
!getActivity().isDestroyed() &&
isAdded() &&
!isDetached() &&
!isRemoving() &&
getView() != null &&
mBinding != null;
}
private void setFabVisible(int position) {
if (mAdapter.getItemCount() == 0) {
// 检查是否为空源状态 - 使用与checkEmptySource相同的逻辑,添加空值检查
boolean hasBaseConfig = false;
boolean hasValidSites = false;
boolean hasValidHome = false;
try {
Config config = VodConfig.get().getConfig();
hasBaseConfig = config != null &&
config.getUrl() != null &&
!config.getUrl().isEmpty();
hasValidSites = VodConfig.get().getSites().size() > 0;
Site site = getSite();
hasValidHome = site != null && site.getKey() != null && !site.getKey().isEmpty();
} catch (Exception e) {
hasBaseConfig = false;
hasValidSites = false;
hasValidHome = false;
}
boolean isEmpty = !hasBaseConfig || (!hasValidSites || !hasValidHome);
if (isEmpty) {
// 空源状态下隐藏所有悬浮按钮
hideFabButtons();
} else if (mAdapter.getItemCount() == 0) {
mBinding.top.setVisibility(View.INVISIBLE);
mBinding.link.setVisibility(View.VISIBLE);
mBinding.filter.setVisibility(View.GONE);
@@ -190,6 +378,13 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal
mBinding.link.show();
}
}
// 隐藏所有悬浮按钮的方法
private void hideFabButtons() {
mBinding.top.setVisibility(View.GONE);
mBinding.link.setVisibility(View.GONE);
mBinding.filter.setVisibility(View.GONE);
}
private void checkRetry() {
mBinding.retry.setVisibility(mAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
@@ -247,6 +442,14 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal
private void homeContent() {
showProgress();
setFabVisible(0);
// 安全地隐藏空源提示
try {
if (mBinding != null && mBinding.emptySourceHint != null) {
mBinding.emptySourceHint.setVisibility(View.GONE);
}
} catch (Exception e) {
e.printStackTrace();
}
mAdapter.clear();
mViewModel.homeContent();
mBinding.pager.setAdapter(new PageAdapter(getChildFragmentManager()));
@@ -296,6 +499,7 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal
switch (event.getType()) {
case EMPTY:
hideProgress();
checkEmptySource(); // 添加检查是否显示空源提示
break;
case PROGRESS:
showProgress();
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M3,17v2h6v-2H3zM3,5v2h10V5H3zM13,21v-2h8v-2h-8v-2h-2v6H13zM7,9v2H3v2h4v2h2V9H7zM21,13v-2H11v2H21zM15,9h2V7h4V5h-4V3h-2V9z" />
</vector>
@@ -0,0 +1,371 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_back" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/setting_player"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical"
android:paddingStart="24dp"
android:paddingTop="8dp"
android:paddingEnd="24dp"
android:paddingBottom="16dp">
<LinearLayout
android:id="@+id/render"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_item"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_render"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/renderText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="Surface" />
</LinearLayout>
<LinearLayout
android:id="@+id/scale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_scale"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/scaleText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="預設" />
</LinearLayout>
<LinearLayout
android:id="@+id/caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_caption"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/captionText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:gravity="end"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="預設" />
</LinearLayout>
<LinearLayout
android:id="@+id/buffer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_buffer"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/bufferText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="@string/times"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/speed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_speed"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/speedText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="@string/times"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/tunnel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/player_tunnel"
android:textColor="@color/white"
android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/tunnelSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/M3SwitchStyle" />
</LinearLayout>
<LinearLayout
android:id="@+id/audioDecode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/player_audio_decode"
android:textColor="@color/white"
android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/audioDecodeSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/M3SwitchStyle" />
</LinearLayout>
<LinearLayout
android:id="@+id/aac"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/player_aac"
android:textColor="@color/white"
android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/aacSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/M3SwitchStyle" />
</LinearLayout>
<LinearLayout
android:id="@+id/danmakuLoad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/player_danmaku_load"
android:textColor="@color/white"
android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/danmakuLoadSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/M3SwitchStyle" />
</LinearLayout>
<LinearLayout
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_background"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/backgroundText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="畫中畫" />
</LinearLayout>
<LinearLayout
android:id="@+id/ua"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_ua"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/uaText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:gravity="end"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="okhttp/4.11.0" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
+165 -150
View File
@@ -93,10 +93,11 @@
<LinearLayout
android:id="@+id/vod"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="56dp"
android:layout_marginEnd="12dp"
android:layout_weight="1"
android:background="@drawable/shape_item"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
@@ -151,10 +152,11 @@
<LinearLayout
android:id="@+id/live"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="56dp"
android:layout_marginEnd="12dp"
android:layout_weight="1"
android:background="@drawable/shape_item"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
@@ -209,10 +211,11 @@
<LinearLayout
android:id="@+id/wall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="56dp"
android:layout_marginEnd="12dp"
android:layout_weight="1"
android:background="@drawable/shape_item"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
@@ -269,35 +272,43 @@
android:textSize="14sp"
android:alpha="0.7" />
<!-- 将三个设置项放在一个共同的背景容器中 -->
<LinearLayout
android:id="@+id/player"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_item"
android:orientation="horizontal">
android:orientation="vertical">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_control_setting"
android:tint="@color/white" />
<TextView
android:layout_width="wrap_content"
<!-- 播放器设置 -->
<LinearLayout
android:id="@+id/player"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/setting_player"
android:textColor="@color/white"
android:textSize="16sp" />
android:orientation="horizontal"
android:paddingTop="16dp"
android:paddingBottom="12dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_setting_player"
android:tint="@color/white" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/setting_player"
android:textColor="@color/white"
android:textSize="16sp" />
<LinearLayout
</LinearLayout>
<!-- 无痕模式 -->
<LinearLayout
android:id="@+id/incognito"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:background="@drawable/shape_item"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingTop="16dp"
@@ -318,46 +329,48 @@
android:textColor="@color/white"
android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/incognitoSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/M3SwitchStyle" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/incognitoSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/M3SwitchStyle" />
</LinearLayout>
<LinearLayout
android:id="@+id/size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:background="@drawable/shape_item"
android:orientation="horizontal">
</LinearLayout>
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_setting_size"
android:tint="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/setting_size"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/sizeText"
<!-- 图片尺寸 -->
<LinearLayout
android:id="@+id/size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="Medium" />
android:orientation="horizontal"
android:paddingTop="12dp"
android:paddingBottom="16dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_setting_size"
android:tint="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/setting_size"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/sizeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="Medium" />
</LinearLayout>
</LinearLayout>
<!-- 网络设置分组 -->
@@ -372,105 +385,117 @@
android:textSize="14sp"
android:alpha="0.7" />
<!-- 将三个网络设置项放在一个共同的背景容器中 -->
<LinearLayout
android:id="@+id/doh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_item"
android:orientation="horizontal">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_setting_doh"
android:tint="@color/white" />
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/setting_doh"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/dohText"
<!-- DoH设置 -->
<LinearLayout
android:id="@+id/doh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="Google" />
android:orientation="horizontal"
android:paddingTop="16dp"
android:paddingBottom="16dp">
</LinearLayout>
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_setting_doh"
android:tint="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/setting_doh"
android:textColor="@color/white"
android:textSize="16sp" />
<LinearLayout
android:id="@+id/proxy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:background="@drawable/shape_item"
android:orientation="horizontal">
<TextView
android:id="@+id/dohText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="Google" />
</LinearLayout>
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_fab_link"
android:tint="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/setting_proxy"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/proxyText"
<!-- 代理设置 -->
<LinearLayout
android:id="@+id/proxy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="http" />
android:orientation="horizontal"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_fab_link"
android:tint="@color/white" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/setting_proxy"
android:textColor="@color/white"
android:textSize="16sp" />
<LinearLayout
android:id="@+id/cache"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:background="@drawable/shape_item"
android:orientation="horizontal">
<TextView
android:id="@+id/proxyText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="http" />
</LinearLayout>
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_folder"
android:tint="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/setting_cache"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/cacheText"
<!-- 缓存设置 -->
<LinearLayout
android:id="@+id/cache"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="1.0 MB" />
android:orientation="horizontal"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_folder"
android:tint="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/setting_cache"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/cacheText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="1.0 MB" />
</LinearLayout>
</LinearLayout>
<!-- 备份与恢复分组 -->
@@ -511,7 +536,6 @@
android:id="@+id/backup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:text="@string/setting_backup"
@@ -530,7 +554,6 @@
android:id="@+id/restore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:gravity="end"
android:paddingTop="16dp"
android:paddingEnd="16dp"
@@ -545,7 +568,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginTop="12dp"
android:orientation="horizontal">
<LinearLayout
@@ -564,22 +587,14 @@
android:src="@drawable/ic_setting_github"
android:tint="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/setting_version"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/versionText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:text="@string/setting_version"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="1.2.1" />
tools:text="版本 3.0.3" />
</LinearLayout>
@@ -60,322 +60,406 @@
android:paddingEnd="24dp"
android:paddingBottom="16dp">
<!-- 播放器基本设置模块 -->
<LinearLayout
android:id="@+id/render"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_item"
android:orientation="horizontal">
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_render"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/renderText"
<!-- 渲染方式 -->
<LinearLayout
android:id="@+id/render"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="Surface" />
android:orientation="horizontal"
android:padding="16dp"
android:background="?attr/selectableItemBackground">
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_render"
android:textColor="@color/white"
android:textSize="16sp" />
<LinearLayout
android:id="@+id/scale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal">
<TextView
android:id="@+id/renderText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="Surface" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_scale"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
<!-- 分隔线 -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:background="#22FFFFFF" />
<TextView
android:id="@+id/scaleText"
<!-- 缩放比例 -->
<LinearLayout
android:id="@+id/scale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="預設" />
android:orientation="horizontal"
android:padding="16dp"
android:background="?attr/selectableItemBackground">
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_scale"
android:textColor="@color/white"
android:textSize="16sp" />
<LinearLayout
android:id="@+id/caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal">
<TextView
android:id="@+id/scaleText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="預設" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_caption"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
<!-- 分隔线 -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:background="#22FFFFFF" />
<TextView
android:id="@+id/captionText"
<!-- 字幕样式 -->
<LinearLayout
android:id="@+id/caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:gravity="end"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="預設" />
android:orientation="horizontal"
android:padding="16dp"
android:background="?attr/selectableItemBackground">
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_caption"
android:textColor="@color/white"
android:textSize="16sp" />
<LinearLayout
android:id="@+id/buffer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal">
<TextView
android:id="@+id/captionText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:gravity="end"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="預設" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_buffer"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
<!-- 分隔线 -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:background="#22FFFFFF" />
<TextView
android:id="@+id/bufferText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="@string/times"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/speed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_speed"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/speedText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="@string/times"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/tunnel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/player_tunnel"
android:textColor="@color/white"
android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/tunnelSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/M3SwitchStyle" />
</LinearLayout>
<LinearLayout
android:id="@+id/audioDecode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/player_audio_decode"
android:textColor="@color/white"
android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/audioDecodeSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/M3SwitchStyle" />
</LinearLayout>
<LinearLayout
android:id="@+id/aac"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/player_aac"
android:textColor="@color/white"
android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/aacSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/M3SwitchStyle" />
</LinearLayout>
<LinearLayout
android:id="@+id/danmakuLoad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/player_danmaku_load"
android:textColor="@color/white"
android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/danmakuLoadSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/M3SwitchStyle" />
</LinearLayout>
<LinearLayout
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_background"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/backgroundText"
<!-- 缓冲时间 -->
<LinearLayout
android:id="@+id/buffer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="畫中畫" />
android:orientation="horizontal"
android:padding="16dp"
android:background="?attr/selectableItemBackground">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_buffer"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/bufferText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="@string/times"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
<!-- 分隔线 -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:background="#22FFFFFF" />
<!-- 长按倍速 -->
<LinearLayout
android:id="@+id/speed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="16dp"
android:background="?attr/selectableItemBackground">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_speed"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/speedText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="@string/times"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
<!-- 分隔线 -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:background="#22FFFFFF" />
<!-- 后台播放 -->
<LinearLayout
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="16dp"
android:background="?attr/selectableItemBackground">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_background"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/backgroundText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="畫中畫" />
</LinearLayout>
<!-- 分隔线 -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:background="#22FFFFFF" />
<!-- User-Agent -->
<LinearLayout
android:id="@+id/ua"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="16dp"
android:background="?attr/selectableItemBackground">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_ua"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/uaText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:gravity="end"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="okhttp/4.11.0" />
</LinearLayout>
</LinearLayout>
<!-- 开关设置模块 -->
<LinearLayout
android:id="@+id/ua"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/shape_item"
android:orientation="horizontal">
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/player_ua"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/uaText"
<!-- 隧道模式 -->
<LinearLayout
android:id="@+id/tunnel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:gravity="end"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="okhttp/4.11.0" />
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="16dp"
android:background="?attr/selectableItemBackground">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/player_tunnel"
android:textColor="@color/white"
android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/tunnelSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/M3SwitchStyle" />
</LinearLayout>
<!-- 分隔线 -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:background="#22FFFFFF" />
<!-- 音频软解 -->
<LinearLayout
android:id="@+id/audioDecode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="16dp"
android:background="?attr/selectableItemBackground">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/player_audio_decode"
android:textColor="@color/white"
android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/audioDecodeSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/M3SwitchStyle" />
</LinearLayout>
<!-- 分隔线 -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:background="#22FFFFFF" />
<!-- AAC优化 -->
<LinearLayout
android:id="@+id/aac"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="16dp"
android:background="?attr/selectableItemBackground">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/player_aac"
android:textColor="@color/white"
android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/aacSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/M3SwitchStyle" />
</LinearLayout>
<!-- 分隔线 -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:background="#22FFFFFF" />
<!-- 弹幕加载 -->
<LinearLayout
android:id="@+id/danmakuLoad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="16dp"
android:background="?attr/selectableItemBackground">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/player_danmaku_load"
android:textColor="@color/white"
android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/danmakuLoadSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/M3SwitchStyle" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
@@ -100,6 +100,42 @@
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<!-- 新增空源提示文本 -->
<LinearLayout
android:id="@+id/empty_source_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp"
android:visibility="gone"
tools:visibility="visible">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_logo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/source_hint"
android:textColor="@color/white"
android:textSize="16sp" />
<Button
android:id="@+id/add_source_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:backgroundTint="@color/primary"
android:text="@string/add_source"
android:textColor="@color/black" />
</LinearLayout>
<ImageView
android:id="@+id/retry"
android:layout_width="56dp"