mirror of https://github.com/FongMi/TV.git
parent
a6344e5722
commit
c794f090f7
@ -1,7 +1,26 @@ |
||||
package com.fongmi.bear.net; |
||||
|
||||
public abstract class Callback { |
||||
import androidx.annotation.NonNull; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
|
||||
import okhttp3.Call; |
||||
import okhttp3.Response; |
||||
|
||||
public abstract class Callback implements okhttp3.Callback { |
||||
|
||||
public void onResponse(String result) { |
||||
} |
||||
|
||||
public void onResponse(File file) { |
||||
} |
||||
|
||||
@Override |
||||
public void onFailure(@NonNull Call call, @NonNull IOException e) { |
||||
} |
||||
|
||||
@Override |
||||
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { |
||||
} |
||||
} |
||||
|
||||
@ -1,43 +1,80 @@ |
||||
package com.fongmi.bear.ui; |
||||
|
||||
import android.animation.Animator; |
||||
import android.animation.AnimatorListenerAdapter; |
||||
import android.annotation.SuppressLint; |
||||
import android.os.Handler; |
||||
import android.view.View; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.viewbinding.ViewBinding; |
||||
|
||||
import com.fongmi.bear.App; |
||||
import com.fongmi.bear.bean.Config; |
||||
import com.fongmi.bear.databinding.ActivitySplashBinding; |
||||
import com.fongmi.bear.net.Callback; |
||||
import com.fongmi.bear.net.Task; |
||||
import com.fongmi.bear.net.OKHttp; |
||||
import com.fongmi.bear.utils.FileUtil; |
||||
import com.fongmi.bear.utils.Prefers; |
||||
import com.github.catvod.loader.JarLoader; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
|
||||
import okhttp3.Call; |
||||
import okhttp3.Request; |
||||
import okhttp3.Response; |
||||
|
||||
@SuppressLint("CustomSplashScreen") |
||||
public class SplashActivity extends BaseActivity { |
||||
|
||||
private ActivitySplashBinding binding; |
||||
|
||||
@Override |
||||
protected ViewBinding getBinding() { |
||||
return ActivitySplashBinding.inflate(getLayoutInflater()); |
||||
return binding = ActivitySplashBinding.inflate(getLayoutInflater()); |
||||
} |
||||
|
||||
@Override |
||||
protected void initView() { |
||||
String url = Prefers.getString("url"); |
||||
if (url.isEmpty()) openHome(); |
||||
else Task.create(getCallback()).run(url); |
||||
binding.title.animate().alpha(1).setDuration(2000).setListener(onAnimationEnd()).start(); |
||||
} |
||||
|
||||
private Callback getCallback() { |
||||
return new Callback() { |
||||
private AnimatorListenerAdapter onAnimationEnd() { |
||||
return new AnimatorListenerAdapter() { |
||||
@Override |
||||
public void onResponse(String result) { |
||||
App.get().setConfig(Config.objectFrom(result)); |
||||
openHome(); |
||||
public void onAnimationEnd(Animator animation) { |
||||
binding.title.setVisibility(View.GONE); |
||||
binding.progress.animate().alpha(1).setDuration(500).start(); |
||||
binding.info.animate().alpha(1).setDuration(500).start(); |
||||
checkUrl(); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
private void openHome() { |
||||
new Handler().postDelayed(() -> HomeActivity.newInstance(this), 500); |
||||
private void checkUrl() { |
||||
String url = Prefers.getString("url"); |
||||
if (url.isEmpty()) HomeActivity.start(getActivity()); |
||||
else getConfig(url); |
||||
} |
||||
|
||||
private void getConfig(String url) { |
||||
OKHttp.get().client().newCall(new Request.Builder().url(url).build()).enqueue(new Callback() { |
||||
@Override |
||||
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { |
||||
Config config = Config.objectFrom(response.body().string()); |
||||
App.get().setConfig(config); |
||||
loadJar(config.getSpider()); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void loadJar(String url) { |
||||
FileUtil.download(url, new Callback() { |
||||
@Override |
||||
public void onResponse(File file) { |
||||
JarLoader.get().load(); |
||||
HomeActivity.start(getActivity()); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,55 @@ |
||||
package com.fongmi.bear.utils; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
|
||||
import com.fongmi.bear.App; |
||||
import com.fongmi.bear.net.Callback; |
||||
import com.fongmi.bear.net.OKHttp; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileOutputStream; |
||||
import java.io.IOException; |
||||
|
||||
import okhttp3.Call; |
||||
import okhttp3.Request; |
||||
import okhttp3.Response; |
||||
|
||||
public class FileUtil { |
||||
|
||||
public static File getCacheDir() { |
||||
return App.get().getExternalCacheDir(); |
||||
} |
||||
|
||||
public static String getCachePath() { |
||||
return getCacheDir().getAbsolutePath(); |
||||
} |
||||
|
||||
public static File getCacheFile(String fileName) { |
||||
return new File(getCacheDir(), fileName); |
||||
} |
||||
|
||||
public static File getJar() { |
||||
return getCacheFile("spider.jar"); |
||||
} |
||||
|
||||
public static String getJarPath() { |
||||
return getJar().getAbsolutePath(); |
||||
} |
||||
|
||||
public static void download(String url, Callback callback) { |
||||
Request request = new Request.Builder().url(url).build(); |
||||
OKHttp.get().client().newCall(request).enqueue(new Callback() { |
||||
@Override |
||||
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { |
||||
callback.onResponse(writeFile(response)); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private static File writeFile(Response response) throws IOException { |
||||
FileOutputStream fos = new FileOutputStream(getJar()); |
||||
fos.write(response.body().bytes()); |
||||
fos.close(); |
||||
return getJar(); |
||||
} |
||||
} |
||||
@ -0,0 +1,76 @@ |
||||
package com.github.catvod.crawler; |
||||
|
||||
import android.content.Context; |
||||
|
||||
import org.json.JSONObject; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
|
||||
public abstract class Spider { |
||||
|
||||
public static JSONObject empty = new JSONObject(); |
||||
|
||||
public void init(Context context) { |
||||
} |
||||
|
||||
public void init(Context context, String extend) { |
||||
init(context); |
||||
} |
||||
|
||||
/** |
||||
* 首頁數據內容 |
||||
*/ |
||||
public String homeContent(boolean filter) { |
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* 首頁最近更新數據 如果上面的homeContent中不包含首頁最近更新視頻的數據 可以使用這個接口返回 |
||||
*/ |
||||
public String homeVideoContent() { |
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* 分類數據 |
||||
*/ |
||||
public String categoryContent(String tid, String pg, boolean filter, HashMap<String, String> extend) { |
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* 詳情數據 |
||||
*/ |
||||
public String detailContent(List<String> ids) { |
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* 搜索數據內容 |
||||
*/ |
||||
public String searchContent(String key, boolean quick) { |
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* 播放信息 |
||||
*/ |
||||
public String playerContent(String flag, String id, List<String> vipFlags) { |
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* Webview 解析時使用 可自定義判斷當前加載的 url 是否是視頻 |
||||
*/ |
||||
public boolean isVideoFormat(String url) { |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* 是否手動檢測 Webview 中加載的 url |
||||
*/ |
||||
public boolean manualVideoCheck() { |
||||
return false; |
||||
} |
||||
} |
||||
@ -0,0 +1,4 @@ |
||||
package com.github.catvod.crawler; |
||||
|
||||
public class SpiderNull extends Spider { |
||||
} |
||||
@ -0,0 +1,65 @@ |
||||
package com.github.catvod.loader; |
||||
|
||||
import com.fongmi.bear.App; |
||||
import com.fongmi.bear.utils.FileUtil; |
||||
import com.github.catvod.crawler.Spider; |
||||
import com.github.catvod.crawler.SpiderNull; |
||||
|
||||
import java.io.FileOutputStream; |
||||
|
||||
import dalvik.system.DexClassLoader; |
||||
|
||||
public class JarLoader { |
||||
|
||||
private DexClassLoader classLoader; |
||||
|
||||
private static class Loader { |
||||
static volatile JarLoader INSTANCE = new JarLoader(); |
||||
} |
||||
|
||||
public static JarLoader get() { |
||||
return Loader.INSTANCE; |
||||
} |
||||
|
||||
public void load(byte[] jarData) { |
||||
try { |
||||
FileOutputStream fos = new FileOutputStream(FileUtil.getCacheFile("spider.jar")); |
||||
fos.write(jarData); |
||||
fos.flush(); |
||||
fos.close(); |
||||
load(); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
public void load() { |
||||
try { |
||||
classLoader = new DexClassLoader(FileUtil.getJarPath(), FileUtil.getCachePath(), null, App.get().getClassLoader()); |
||||
int count = 0; |
||||
do { |
||||
try { |
||||
if (classLoader.loadClass("com.github.catvod.spider.Init") != null) { |
||||
break; |
||||
} |
||||
Thread.sleep(200); |
||||
} catch (Throwable th) { |
||||
th.printStackTrace(); |
||||
} |
||||
count++; |
||||
} while (count < 5); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
public Spider getSpider(String key) { |
||||
if (classLoader == null) return new SpiderNull(); |
||||
try { |
||||
return (Spider) classLoader.loadClass("com.github.catvod.spider." + key).newInstance(); |
||||
} catch (Throwable th) { |
||||
th.printStackTrace(); |
||||
} |
||||
return new SpiderNull(); |
||||
} |
||||
} |
||||
@ -1,4 +1,49 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" /> |
||||
android:layout_height="match_parent"> |
||||
|
||||
<TextView |
||||
android:id="@+id/title" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_centerInParent="true" |
||||
android:alpha="0" |
||||
android:shadowColor="@color/grey_700" |
||||
android:shadowDx="2" |
||||
android:shadowDy="2" |
||||
android:shadowRadius="1" |
||||
android:text="@string/app_name" |
||||
android:textColor="@color/white" |
||||
android:textSize="32sp" |
||||
tools:alpha="1" /> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_centerInParent="true" |
||||
android:orientation="vertical"> |
||||
|
||||
<ProgressBar |
||||
android:id="@+id/progress" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center" |
||||
android:alpha="0" |
||||
tools:alpha="1" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/info" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center" |
||||
android:layout_marginTop="8dp" |
||||
android:alpha="0" |
||||
android:text="@string/splash_info" |
||||
android:textColor="@color/white" |
||||
android:textSize="18sp" |
||||
tools:alpha="1" /> |
||||
|
||||
</LinearLayout> |
||||
</RelativeLayout> |
||||
Loading…
Reference in new issue