mirror of https://github.com/FongMi/TV.git
commit
da4fa69e36
@ -0,0 +1,84 @@ |
||||
package com.fongmi.android.tv.ui.dialog; |
||||
|
||||
import android.app.Activity; |
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
|
||||
import androidx.appcompat.app.AlertDialog; |
||||
|
||||
import com.fongmi.android.tv.Setting; |
||||
import com.fongmi.android.tv.databinding.DialogX5webviewBinding; |
||||
import com.fongmi.android.tv.utils.Download; |
||||
import com.fongmi.android.tv.utils.Notify; |
||||
import com.fongmi.android.tv.utils.Tbs; |
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
||||
import java.io.File; |
||||
import java.util.Locale; |
||||
|
||||
public class X5WebViewDialog implements Download.Callback { |
||||
|
||||
private DialogX5webviewBinding binding; |
||||
private AlertDialog dialog; |
||||
private Activity activity; |
||||
|
||||
public X5WebViewDialog(Activity activity) { |
||||
this.activity = activity; |
||||
} |
||||
|
||||
public void show() { |
||||
binding = DialogX5webviewBinding.inflate(LayoutInflater.from(activity)); |
||||
binding.confirm.setOnClickListener(this::confirm); |
||||
binding.cancel.setOnClickListener(this::cancel); |
||||
dialog = new MaterialAlertDialogBuilder(activity).setView(binding.getRoot()).setCancelable(false).create(); |
||||
dialog.show(); |
||||
} |
||||
|
||||
public static X5WebViewDialog create(Activity activity) { |
||||
return new X5WebViewDialog(activity); |
||||
} |
||||
|
||||
private String getTbs() { |
||||
return Tbs.url(); |
||||
} |
||||
|
||||
private File getFile() { |
||||
return Tbs.file(); |
||||
} |
||||
|
||||
private void cancel(View view) { |
||||
dismiss(); |
||||
} |
||||
|
||||
private void confirm(View view) { |
||||
binding.confirm.setEnabled(false); |
||||
Download.create(getTbs(), getFile(), this).start(); |
||||
} |
||||
|
||||
private void dismiss() { |
||||
try { |
||||
if (dialog != null) dialog.dismiss(); |
||||
} catch (Exception ignored) { |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void progress(int progress) { |
||||
binding.confirm.setText(String.format(Locale.getDefault(), "%1$d%%", progress)); |
||||
} |
||||
|
||||
@Override |
||||
public void error(String msg) { |
||||
Notify.show(msg); |
||||
Setting.putParseWebView(0); |
||||
dismiss(); |
||||
} |
||||
|
||||
@Override |
||||
public void success(File file) { |
||||
dismiss(); |
||||
Tbs.download(); |
||||
Setting.putParseWebView(1); |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,65 @@ |
||||
<?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:orientation="vertical" |
||||
android:padding="24dp"> |
||||
|
||||
<TextView |
||||
android:id="@+id/title" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:letterSpacing="0.02" |
||||
android:textColor="@color/grey_900" |
||||
android:textSize="18sp" |
||||
android:text="@string/x5webview_title" /> |
||||
|
||||
<View |
||||
android:layout_width="match_parent" |
||||
android:layout_height="1dp" |
||||
android:layout_marginTop="16dp" |
||||
android:layout_marginBottom="16dp" |
||||
android:background="@color/grey_300" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/desc" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:letterSpacing="0.02" |
||||
android:textColor="@color/grey_900" |
||||
android:textSize="18sp" |
||||
android:layout_marginBottom="16dp" |
||||
android:text="@string/x5webview_download_enable" /> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:id="@+id/confirm" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginEnd="16dp" |
||||
android:layout_weight="1" |
||||
android:background="@drawable/selector_text" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:gravity="center" |
||||
android:text="@string/dialog_positive" |
||||
android:textColor="@color/white" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/cancel" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
||||
android:background="@drawable/selector_text" |
||||
android:focusable="true" |
||||
android:focusableInTouchMode="true" |
||||
android:gravity="center" |
||||
android:text="@string/dialog_negative" |
||||
android:textColor="@color/white" /> |
||||
|
||||
</LinearLayout> |
||||
</LinearLayout> |
||||
@ -0,0 +1,106 @@ |
||||
package com.fongmi.android.tv.utils; |
||||
|
||||
import android.os.Build; |
||||
|
||||
import com.fongmi.android.tv.App; |
||||
import com.fongmi.android.tv.R; |
||||
import com.fongmi.android.tv.Setting; |
||||
import com.github.catvod.utils.Path; |
||||
import com.orhanobut.logger.Logger; |
||||
import com.tencent.smtt.sdk.QbSdk; |
||||
import com.tencent.smtt.sdk.TbsListener; |
||||
import com.tencent.smtt.export.external.TbsCoreSettings; |
||||
|
||||
import java.io.File; |
||||
import java.util.HashMap; |
||||
|
||||
public class Tbs { |
||||
private static final String TAG = Tbs.class.getSimpleName(); |
||||
|
||||
public static final String URL64 = "https://tmf-pkg-1314481471.cos.ap-shanghai.myqcloud.com/x5/64/46471/tbs_core_046471_20230809100104_nolog_fs_obfs_arm64-v8a_release.tbs"; |
||||
public static final String URL32 = "https://tmf-pkg-1314481471.cos.ap-shanghai.myqcloud.com/x5/32/46471/tbs_core_046471_20230809095840_nolog_fs_obfs_armeabi_release.tbs"; |
||||
|
||||
private static boolean isCpu64Bit() { |
||||
for (String abi : Build.SUPPORTED_ABIS) { |
||||
if (abi.contains("64")) return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public static String getUrl() { |
||||
return isCpu64Bit() ? URL64 : URL32; |
||||
} |
||||
|
||||
private static void tbsInit() { |
||||
HashMap map = new HashMap(); |
||||
map.put(TbsCoreSettings.TBS_SETTINGS_USE_PRIVATE_CLASSLOADER, true); |
||||
QbSdk.initTbsSettings(map); |
||||
QbSdk.setDownloadWithoutWifi(false); |
||||
QbSdk.setCoreMinVersion(QbSdk.CORE_VER_ENABLE_202207); |
||||
TbsListener tbsListener = new TbsListener() { |
||||
|
||||
/** |
||||
* @param stateCode 用户可处理错误码请参考{@link com.tencent.smtt.sdk.TbsCommonCode} |
||||
*/ |
||||
@Override |
||||
public void onDownloadFinish(int stateCode) { |
||||
Logger.t(TAG).d("onDownloadFinish:" + stateCode); |
||||
} |
||||
|
||||
/** |
||||
* @param stateCode 用户可处理错误码请参考{@link com.tencent.smtt.sdk.TbsCommonCode} |
||||
*/ |
||||
@Override |
||||
public void onInstallFinish(int stateCode) { |
||||
Logger.t(TAG).d("onInstallFinish:" + stateCode); |
||||
} |
||||
|
||||
/** |
||||
* 首次安装应用,会触发内核下载,此时会有内核下载的进度回调。 |
||||
* @param progress 0 - 100 |
||||
*/ |
||||
@Override |
||||
public void onDownloadProgress(int progress) { |
||||
Logger.t(TAG).d("onDownloadProgress:" + progress); |
||||
} |
||||
}; |
||||
QbSdk.PreInitCallback callback = new QbSdk.PreInitCallback() { |
||||
@Override |
||||
public void onViewInitFinished(boolean finished) { |
||||
if (finished) Notify.show(R.string.x5webview_enabled); |
||||
} |
||||
|
||||
@Override |
||||
public void onCoreInitFinished() { |
||||
} |
||||
}; |
||||
QbSdk.setTbsListener(tbsListener); |
||||
QbSdk.initX5Environment(App.get(), callback); |
||||
} |
||||
|
||||
public static void init() { |
||||
if (Setting.getParseWebView() == 0) return; |
||||
App.post(() -> tbsInit()); |
||||
} |
||||
|
||||
public static String url() { |
||||
return getUrl(); |
||||
} |
||||
|
||||
private static File tbs() { |
||||
File tbsDir = Path.files("tbs"); |
||||
return tbsDir; |
||||
} |
||||
|
||||
public static File file() { |
||||
File tbsDir = tbs(); |
||||
if (!tbsDir.exists()) tbsDir.mkdirs(); |
||||
File x5 = new File(tbsDir, "x5.apk"); |
||||
return x5; |
||||
} |
||||
|
||||
public static void download() { |
||||
QbSdk.installLocalQbApk(App.get(), "46471", file().getAbsolutePath(), null); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue