Support doh - part 3

pull/123/head
FongMi 3 years ago
parent 6173c85d34
commit d259aa0766
  1. 3
      app/src/main/java/com/fongmi/android/tv/App.java
  2. 6
      app/src/main/java/com/fongmi/android/tv/api/ApiConfig.java
  3. 25
      app/src/mobile/java/com/fongmi/android/tv/ui/fragment/SettingFragment.java
  4. 6
      catvod/src/main/java/com/github/catvod/bean/Doh.java

@ -79,8 +79,7 @@ public class App extends Application {
public static void restart(Class<?> clz) {
App.activity().startActivity(Intent.makeRestartActivityTask(new Intent(get(), clz).getComponent()));
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(10);
System.exit(0);
}
private void setDoh(Context context) {

@ -257,12 +257,14 @@ public class ApiConfig {
}
public List<Doh> getDoh() {
return doh == null ? Collections.emptyList() : doh;
List<Doh> items = new ArrayList<>();
items.add(Doh.create(App.get()));
items.addAll(doh);
return items;
}
public void setDoh(List<Doh> doh) {
this.doh = doh;
this.doh.add(0, Doh.create(App.get()));
}
public List<Rule> getRules() {

@ -54,7 +54,6 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
private String[] player;
private String[] scale;
private String[] size;
private String[] doh;
private int type;
public static SettingFragment newInstance() {
@ -62,7 +61,13 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
}
private int getDohIndex() {
return ApiConfig.get().getDoh().indexOf(Doh.objectFrom(Prefers.getDoh()));
return Math.max(0, ApiConfig.get().getDoh().indexOf(Doh.objectFrom(Prefers.getDoh())));
}
private String[] getDohList() {
List<String> list = new ArrayList<>();
for (Doh item : ApiConfig.get().getDoh()) list.add(item.getName());
return list.toArray(new String[0]);
}
@Override
@ -75,6 +80,7 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
mBinding.vodUrl.setText(ApiConfig.getDesc());
mBinding.liveUrl.setText(LiveConfig.getDesc());
mBinding.wallUrl.setText(WallConfig.getDesc());
mBinding.dohText.setText(getDohList()[getDohIndex()]);
mBinding.versionText.setText(BuildConfig.VERSION_NAME);
mBinding.sizeText.setText((size = ResUtil.getStringArray(R.array.select_size))[Prefers.getSize()]);
mBinding.scaleText.setText((scale = ResUtil.getStringArray(R.array.select_scale))[Prefers.getScale()]);
@ -82,7 +88,6 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
mBinding.decodeText.setText((decode = ResUtil.getStringArray(R.array.select_decode))[Prefers.getDecode()]);
mBinding.renderText.setText((render = ResUtil.getStringArray(R.array.select_render))[Prefers.getRender()]);
setCacheText();
setDohText();
}
private void setCacheText() {
@ -94,14 +99,6 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
});
}
private void setDohText() {
List<String> list = new ArrayList<>();
List<Doh> dohList = ApiConfig.get().getDoh();
for (Doh doh : dohList) list.add(doh.getName());
list.toArray(doh = new String[list.size()]);
mBinding.dohText.setText(doh[getDohIndex()]);
}
@Override
protected void initEvent() {
mBinding.vod.setOnClickListener(this::onVod);
@ -297,9 +294,10 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
}
private void setDoh(View view) {
new MaterialAlertDialogBuilder(getActivity()).setTitle(R.string.setting_doh).setNegativeButton(R.string.dialog_negative, null).setSingleChoiceItems(doh, getDohIndex(), (dialog, which) -> {
String[] items = getDohList();
new MaterialAlertDialogBuilder(getActivity()).setTitle(R.string.setting_doh).setNegativeButton(R.string.dialog_negative, null).setSingleChoiceItems(items, getDohIndex(), (dialog, which) -> {
Prefers.putDoh(ApiConfig.get().getDoh().get(which).toString());
mBinding.dohText.setText(doh[which]);
mBinding.dohText.setText(items[which]);
App.restart(MainActivity.class);
}).show();
}
@ -319,6 +317,7 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
mBinding.vodUrl.setText(ApiConfig.getDesc());
mBinding.liveUrl.setText(LiveConfig.getDesc());
mBinding.wallUrl.setText(WallConfig.getDesc());
mBinding.dohText.setText(getDohList()[getDohIndex()]);
mBinding.playerText.setText(player[Prefers.getPlayer()]);
mBinding.decodeText.setText(decode[Prefers.getDecode()]);
setCacheText();

@ -36,7 +36,8 @@ public class Doh {
}
public static List<Doh> arrayFrom(JsonElement element) {
Type listType = new TypeToken<List<Doh>>() {}.getType();
Type listType = new TypeToken<List<Doh>>() {
}.getType();
List<Doh> items = new Gson().fromJson(element, listType);
return items == null ? new ArrayList<>() : items;
}
@ -60,11 +61,12 @@ public class Doh {
public List<InetAddress> getHosts() {
try {
if (getIps().isEmpty()) return null;
List<InetAddress> list = new ArrayList<>();
for (String ip : getIps()) list.add(InetAddress.getByName(ip));
return list;
} catch (Exception ignored) {
return Collections.emptyList();
return null;
}
}

Loading…
Cancel
Save