Now can open app

pull/1/head
FongMi 4 years ago
parent 8c89837042
commit 5392e208a6
  1. 13
      app/src/main/java/com/fongmi/bear/ApiConfig.java
  2. 4
      app/src/main/java/com/fongmi/bear/bean/Site.java
  3. 1
      app/src/main/java/com/fongmi/bear/ui/activity/SettingActivity.java
  4. 2
      app/src/main/java/com/fongmi/bear/utils/Notify.java
  5. 9
      app/src/main/java/com/github/catvod/crawler/JarLoader.java

@ -66,6 +66,10 @@ public class ApiConfig {
}
public void loadConfig(Callback callback) {
if (Prefers.getUrl().isEmpty()) {
handler.post(() -> callback.error(""));
return;
}
OKHttp.get().client().newCall(new Request.Builder().url(Prefers.getUrl()).build()).enqueue(new Callback() {
@Override
public void onResponse(@NonNull Call call, @NonNull Response response) {
@ -103,7 +107,7 @@ public class ApiConfig {
if (site.getKey().equals(Prefers.getHome())) setHome(site);
sites.add(site);
}
if (getHome() == null) {
if (home == null) {
setHome(sites.isEmpty() ? new Site() : sites.get(0));
}
}
@ -115,7 +119,7 @@ public class ApiConfig {
}
public Spider getCSP(Site site) {
return jarLoader.getSpider(site.getApi(), site.getExt());
return jarLoader.getSpider(site.getKey(), site.getApi(), site.getExt());
}
public Object[] proxyLocal(Map<?, ?> param) {
@ -131,7 +135,8 @@ public class ApiConfig {
}
public Site getSite(String key) {
return sites.get(Math.max(sites.indexOf(Site.get(key)), 0));
int index = sites.indexOf(Site.get(key));
return index == -1 ? new Site() : sites.get(index);
}
public List<Site> getSites() {
@ -139,7 +144,7 @@ public class ApiConfig {
}
public Site getHome() {
return home;
return home == null ? new Site() : home;
}
public void setHome(Site home) {

@ -1,5 +1,7 @@
package com.fongmi.bear.bean;
import android.text.TextUtils;
import com.google.gson.annotations.SerializedName;
public class Site {
@ -30,7 +32,7 @@ public class Site {
}
public String getKey() {
return key;
return TextUtils.isEmpty(key) ? "" : key;
}
public void setKey(String key) {

@ -75,6 +75,7 @@ public class SettingActivity extends BaseActivity {
}
private void showSite(View view) {
if (ApiConfig.get().getSites().isEmpty()) return;
int position = ApiConfig.get().getSites().indexOf(ApiConfig.get().getHome());
DialogSiteBinding bindingDialog = DialogSiteBinding.inflate(LayoutInflater.from(this));
bindingDialog.site.setLayoutManager(new LinearLayoutManager(this));

@ -2,6 +2,7 @@ package com.fongmi.bear.utils;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;
@ -59,6 +60,7 @@ public class Notify {
private void makeText(String message) {
if (mToast != null) mToast.cancel();
if (TextUtils.isEmpty(message)) return;
mToast = Toast.makeText(App.get(), message, Toast.LENGTH_LONG);
mToast.show();
dismiss();

@ -71,13 +71,14 @@ public class JarLoader {
}
}
public Spider getSpider(String key, String ext) {
public Spider getSpider(String key, String api, String ext) {
try {
String clsKey = key.replace("csp_", "");
api = api.replace("csp_", "");
if (spiders.containsKey(key)) return spiders.get(key);
if (classLoader == null) return new SpiderNull();
Spider spider = spiders.containsKey(clsKey) ? spiders.get(clsKey) : (Spider) classLoader.loadClass("com.github.catvod.spider." + clsKey).newInstance();
Spider spider = (Spider) classLoader.loadClass("com.github.catvod.spider." + api).newInstance();
spider.init(App.get(), ext);
spiders.put(clsKey, spider);
spiders.put(key, spider);
return spider;
} catch (Exception e) {
e.printStackTrace();

Loading…
Cancel
Save