Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
FongMi committed Jul 26, 2023
1 parent 5039ac4 commit c4d1497
Show file tree
Hide file tree
Showing 24 changed files with 117 additions and 78 deletions.
6 changes: 3 additions & 3 deletions app/src/leanback/java/com/fongmi/android/tv/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.fongmi.android.tv.databinding.DialogUpdateBinding;
import com.fongmi.android.tv.utils.Download;
import com.fongmi.android.tv.utils.FileUtil;
import com.fongmi.android.tv.utils.Github;
import com.github.catvod.utils.Github;
import com.fongmi.android.tv.utils.Notify;
import com.fongmi.android.tv.utils.Prefers;
import com.fongmi.android.tv.utils.ResUtil;
Expand Down Expand Up @@ -41,11 +41,11 @@ private File getFile() {
}

private String getJson() {
return Github.get().getBranchPath(branch, "/release/" + BuildConfig.FLAVOR_mode + ".json");
return Github.getBranchPath(branch, "/release/" + BuildConfig.FLAVOR_mode + ".json");
}

private String getApk() {
return Github.get().getBranchPath(branch, "/release/" + BuildConfig.FLAVOR_mode + "-" + BuildConfig.FLAVOR_api + "-" + BuildConfig.FLAVOR_abi + ".apk");
return Github.getBranchPath(branch, "/release/" + BuildConfig.FLAVOR_mode + "-" + BuildConfig.FLAVOR_api + "-" + BuildConfig.FLAVOR_abi + ".apk");
}

private Updater() {
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/fongmi/android/tv/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public class Constant {
public static final int TIMEOUT_PARSE_WEB = 15 * 1000;
//直播解析時間
public static final int TIMEOUT_PARSE_LIVE = 10 * 1000;
//代理超時時間
public static final int TIMEOUT_GITHUB = 5 * 1000;
//同步超時時間
public static final int TIMEOUT_SYNC = 2 * 1000;
//搜尋線程數量
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/fongmi/android/tv/bean/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.fongmi.android.tv.Product;
import com.fongmi.android.tv.db.AppDatabase;
import com.fongmi.android.tv.server.Server;
import com.fongmi.android.tv.utils.Utils;
import com.github.catvod.utils.Util;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
Expand All @@ -34,8 +33,8 @@ public class Device {

public static Device get() {
Device device = new Device();
device.setUuid(Utils.getDeviceId());
device.setName(Utils.getDeviceName());
device.setUuid(Util.getDeviceId());
device.setName(Util.getDeviceName());
device.setIp(Server.get().getAddress());
device.setType(Product.getDeviceType());
return device;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@

import com.fongmi.android.tv.App;
import com.fongmi.android.tv.player.Source;
import com.fongmi.android.tv.utils.Github;
import com.forcetech.Util;
import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Path;

import java.io.File;
import java.util.HashSet;

import okhttp3.Headers;
Expand All @@ -28,11 +25,8 @@ public boolean match(String scheme, String host) {
return scheme.startsWith("p") || scheme.equals("mitv");
}

private void init(String scheme) throws Exception {
File file = Path.so(scheme);
String path = Github.get().getReleasePath("/other/jniLibs/" + file.getName());
if (!file.exists()) Path.write(file, OkHttp.newCall(path).execute().body().bytes());
App.get().bindService(Util.intent(App.get(), scheme, file), mConn, Context.BIND_AUTO_CREATE);
private void init(String scheme) {
App.get().bindService(Util.intent(App.get(), scheme), mConn, Context.BIND_AUTO_CREATE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

import android.net.Uri;

import com.fongmi.android.tv.BuildConfig;
import com.fongmi.android.tv.player.Source;
import com.fongmi.android.tv.utils.Github;
import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Path;
import com.p2p.P2PClass;

import java.io.File;
import java.net.URLDecoder;
import java.net.URLEncoder;

Expand All @@ -23,12 +18,8 @@ public boolean match(String scheme, String host) {
return scheme.equals("tvbox-xg");
}

private void init() throws Exception {
if (p2p != null) return;
File file = Path.so("jpa_" + BuildConfig.FLAVOR_abi);
String path = Github.get().getReleasePath("/other/jniLibs/" + file.getName());
if (!file.exists()) Path.write(file, OkHttp.newCall(path).execute().body().bytes());
p2p = new P2PClass(file.getAbsolutePath());
private void init() {
if (p2p == null) p2p = new P2PClass();
}

@Override
Expand Down
16 changes: 2 additions & 14 deletions app/src/main/java/com/fongmi/android/tv/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.app.Activity;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Build;
import android.os.IBinder;
import android.provider.Settings;
import android.text.TextUtils;
Expand All @@ -18,7 +17,6 @@

import com.fongmi.android.tv.App;
import com.fongmi.android.tv.server.Server;
import com.github.catvod.Init;
import com.github.catvod.utils.Util;
import com.google.common.net.HttpHeaders;
import com.permissionx.guolindev.PermissionX;
Expand Down Expand Up @@ -61,8 +59,8 @@ public static boolean isMenuKey(KeyEvent event) {
}

public static void toggleFullscreen(Activity activity, boolean fullscreen) {
if (fullscreen) Utils.hideSystemUI(activity);
else Utils.showSystemUI(activity);
if (fullscreen) hideSystemUI(activity);
else showSystemUI(activity);
}

public static void showSystemUI(Activity activity) {
Expand Down Expand Up @@ -103,16 +101,6 @@ public static Map<String, String> checkHeaders(Map<String, String> headers) {
return headers;
}

public static String getDeviceId() {
return Settings.Secure.getString(Init.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
}

public static String getDeviceName() {
String model = Build.MODEL;
String manufacturer = Build.MANUFACTURER;
return model.startsWith(manufacturer) ? model : manufacturer + " " + model;
}

public static String checkClan(String text) {
if (text.contains("/localhost/")) text = text.replace("/localhost/", "/");
if (text.startsWith("clan")) text = text.replace("clan", "file");
Expand Down
4 changes: 2 additions & 2 deletions app/src/mobile/java/com/fongmi/android/tv/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ private File getFile() {
}

private String getJson() {
return Github.get().getBranchPath(branch, "/release/" + BuildConfig.FLAVOR_mode + ".json");
return Github.getBranchPath(branch, "/release/" + BuildConfig.FLAVOR_mode + ".json");
}

private String getApk() {
return Github.get().getBranchPath(branch, "/release/" + BuildConfig.FLAVOR_mode + "-" + BuildConfig.FLAVOR_api + "-" + BuildConfig.FLAVOR_abi + ".apk");
return Github.getBranchPath(branch, "/release/" + BuildConfig.FLAVOR_mode + "-" + BuildConfig.FLAVOR_api + "-" + BuildConfig.FLAVOR_abi + ".apk");
}

private Updater() {
Expand Down
2 changes: 1 addition & 1 deletion catvod/src/main/java/com/github/catvod/net/OkHttp.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class OkHttp {

public static final int TIMEOUT = 30 * 1000;
private static final int TIMEOUT = 30 * 1000;
private static final int CACHE = 50 * 1024 * 1024;

private DnsOverHttps dns;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.fongmi.android.tv.utils;
package com.github.catvod.utils;

import android.text.TextUtils;

import com.fongmi.android.tv.Constant;
import com.github.catvod.net.OkHttp;

import java.io.File;
import java.io.IOException;

import okhttp3.OkHttpClient;
import okhttp3.Response;

public class Github {

public static final int TIMEOUT = 5 * 1000;
public static final String A = "https://raw.githubusercontent.com/";
public static final String B = "https://fongmi.cachefly.net/";
public static final String C = "https://ghproxy.com/";
Expand All @@ -26,12 +27,12 @@ private static class Loader {
static volatile Github INSTANCE = new Github();
}

public static Github get() {
private static Github get() {
return Loader.INSTANCE;
}

public Github() {
client = OkHttp.client(Constant.TIMEOUT_GITHUB);
private Github() {
client = OkHttp.client(TIMEOUT);
check(A);
check(B);
check(C);
Expand All @@ -54,11 +55,22 @@ private String getProxy() {
return TextUtils.isEmpty(proxy) ? "" : proxy;
}

public String getReleasePath(String path) {
return getProxy() + RELEASE + path;
public static String getReleasePath(String path) {
return get().getProxy() + RELEASE + path;
}

public String getBranchPath(String branch, String path) {
return getProxy() + branch + path;
public static String getBranchPath(String branch, String path) {
return get().getProxy() + branch + path;
}

public static String getSo(String name) {
try {
File file = Path.so(name);
String path = getReleasePath("/other/jniLibs/" + file.getName());
if (!file.exists() || file.length() == 0) Path.write(file, OkHttp.newCall(path).execute().body().bytes());
return file.getAbsolutePath();
} catch (Exception e) {
return "";
}
}
}
5 changes: 2 additions & 3 deletions catvod/src/main/java/com/github/catvod/utils/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ public static File thunder(String name) {
}

public static File local(String path) {
String root = root().getAbsolutePath();
if (path.contains(root)) return new File(path);
return new File(path.replace("file:/", root));
if (path.contains(rootPath())) return new File(path);
return new File(path.replace("file:/", rootPath()));
}

public static String asset(String fileName) {
Expand Down
14 changes: 14 additions & 0 deletions catvod/src/main/java/com/github/catvod/utils/Util.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.github.catvod.utils;

import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Base64;

import com.github.catvod.Init;

import java.io.File;
import java.io.FileInputStream;
import java.math.BigInteger;
Expand All @@ -12,6 +16,16 @@

public class Util {

public static String getDeviceId() {
return Settings.Secure.getString(Init.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
}

public static String getDeviceName() {
String model = Build.MODEL;
String manufacturer = Build.MANUFACTURER;
return model.startsWith(manufacturer) ? model : manufacturer + " " + model;
}

public static String base64(String ext) {
return base64(ext.getBytes());
}
Expand Down
4 changes: 4 additions & 0 deletions forcetech/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ android {
//noinspection ChromeOsAbiSupport
ndk { abiFilters "armeabi-v7a" }
}
}

dependencies {
implementation project(':catvod')
}
6 changes: 2 additions & 4 deletions forcetech/src/main/java/com/forcetech/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import com.forcetech.service.P9PService;
import com.gsoft.mitv.MainActivity;

import java.io.File;

public class Util {

public static int MTV = 9002;
Expand All @@ -43,9 +41,9 @@ public static String trans(ComponentName o) {
return name.toLowerCase();
}

public static Intent intent(Context context, String scheme, File file) {
public static Intent intent(Context context, String scheme) {
Intent intent = new Intent(context, clz(scheme));
intent.putExtra("path", file.getAbsolutePath());
intent.putExtra("scheme", scheme);
return intent;
}

Expand Down
4 changes: 3 additions & 1 deletion forcetech/src/main/java/com/forcetech/android/ForceTV.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.forcetech.android;

import com.github.catvod.utils.Github;

public class ForceTV {

public void start(String lib, int port) {
try {
System.load(lib);
System.load(Github.getSo(lib));
start(port, 20 * 1024 * 1024);
} catch (Throwable ignored) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void onCreate() {
@Override
public IBinder onBind(Intent intent) {
forceTV = new ForceTV();
forceTV.start(intent.getStringExtra("path"), getPort());
forceTV.start(intent.getStringExtra("scheme"), getPort());
return binder;
}

Expand Down
14 changes: 14 additions & 0 deletions jianpian/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@ plugins {

android {
compileSdk 33
flavorDimensions "abi"

defaultConfig {
minSdk 21
targetSdk 28
//noinspection ChromeOsAbiSupport
ndk { abiFilters "armeabi-v7a" }
}

productFlavors {
armeabi_v7a {
dimension "abi"
//noinspection ChromeOsAbiSupport
ndk { abiFilters "armeabi-v7a" }
}
arm64_v8a {
dimension "abi"
//noinspection ChromeOsAbiSupport
ndk { abiFilters "arm64-v8a" }
}
}
}

dependencies {
Expand Down
5 changes: 3 additions & 2 deletions jianpian/src/main/java/com/p2p/P2PClass.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.p2p;

import com.github.catvod.utils.Github;
import com.github.catvod.utils.Path;

public class P2PClass {

public int port;

public P2PClass(String lib) {
System.load(lib);
public P2PClass() {
System.load(Github.getSo("jpa_" + BuildConfig.FLAVOR));
this.port = P2Pdoxstarthttpd("TEST3E63BAAECDAA79BEAA91853490A69F08".getBytes(), Path.jpa().getAbsolutePath().getBytes());
}

Expand Down
Loading

0 comments on commit c4d1497

Please sign in to comment.