pull/21/head
FongMi 4 years ago
parent dd3464b589
commit 45206b256f
  1. 51
      app/src/main/java/com/fongmi/bear/ApiConfig.java
  2. 4
      app/src/main/java/com/fongmi/bear/ui/activity/HomeActivity.java
  3. 3
      app/src/main/java/com/fongmi/bear/ui/activity/SettingActivity.java
  4. 2
      app/src/main/java/com/fongmi/bear/ui/activity/SplashActivity.java
  5. 17
      app/src/main/java/com/fongmi/bear/utils/Clock.java

@ -35,13 +35,13 @@ import okhttp3.Response;
public class ApiConfig {
private final List<String> ads;
private final List<String> flags;
private final List<Parse> parses;
private final List<Live> lives;
private final List<Site> sites;
private final JarLoader loader;
private final Handler handler;
private List<String> ads;
private List<String> flags;
private List<Parse> parses;
private List<Live> lives;
private List<Site> sites;
private JarLoader loader;
private Handler handler;
private Parse parse;
private Site home;
@ -53,23 +53,15 @@ public class ApiConfig {
return Loader.INSTANCE;
}
public ApiConfig() {
public ApiConfig init() {
this.ads = new ArrayList<>();
this.sites = new ArrayList<>();
this.lives = new ArrayList<>();
this.flags = new ArrayList<>();
this.parses = new ArrayList<>();
this.lives = new ArrayList<>();
this.sites = new ArrayList<>();
this.loader = new JarLoader();
this.handler = new Handler(Looper.getMainLooper());
}
public void clear() {
this.ads.clear();
this.flags.clear();
this.parses.clear();
this.lives.clear();
this.sites.clear();
this.home = null;
return this;
}
public void loadConfig(Callback callback) {
@ -189,4 +181,25 @@ public class ApiConfig {
this.home.setHome(true);
Prefers.putHome(home.getKey());
}
public ApiConfig clear() {
this.ads.clear();
this.sites.clear();
this.lives.clear();
this.flags.clear();
this.parses.clear();
this.home = null;
return this;
}
public void release() {
this.ads = null;
this.home = null;
this.sites = null;
this.lives = null;
this.flags = null;
this.parses = null;
this.loader = null;
this.handler = null;
}
}

@ -162,10 +162,10 @@ public class HomeActivity extends BaseActivity implements VodPresenter.OnClickLi
@Override
protected void onDestroy() {
ApiConfig.get().clear();
ApiConfig.get().release();
Players.get().release();
Clock.get().release();
Server.get().stop();
super.onDestroy();
Clock.destroy();
}
}

@ -70,7 +70,6 @@ public class SettingActivity extends BaseActivity {
Prefers.putUrl(bindingDialog.text.getText().toString().trim());
mBinding.url.setText(Prefers.getUrl());
Notify.progress(this);
ApiConfig.get().clear();
checkUrl();
});
bindingDialog.text.setOnEditorActionListener((textView, actionId, event) -> {
@ -90,7 +89,7 @@ public class SettingActivity extends BaseActivity {
}
private void loadConfig() {
ApiConfig.get().loadConfig(new Callback() {
ApiConfig.get().clear().loadConfig(new Callback() {
@Override
public void success() {
mBinding.home.setText(ApiConfig.get().getHome().getName());

@ -39,7 +39,7 @@ public class SplashActivity extends BaseActivity {
}
private void loadConfig() {
ApiConfig.get().loadConfig(new Callback() {
ApiConfig.get().init().loadConfig(new Callback() {
@Override
public void success() {
HomeActivity.start(getActivity());

@ -12,8 +12,8 @@ import java.util.TimerTask;
public class Clock {
private final SimpleDateFormat formatter;
private final Handler handler;
private SimpleDateFormat formatter;
private Handler handler;
private Timer timer;
private static class Loader {
@ -24,20 +24,16 @@ public class Clock {
return Loader.INSTANCE;
}
public Clock() {
public void init() {
this.formatter = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault());
this.handler = new Handler(Looper.getMainLooper());
}
public static void start(TextView view) {
get().cancel();
get().init();
get().run(view);
}
public static void destroy() {
get().cancel();
}
private void run(TextView view) {
timer = new Timer();
timer.schedule(new TimerTask() {
@ -48,7 +44,10 @@ public class Clock {
}, 0, 1000);
}
private void cancel() {
public void release() {
if (timer != null) timer.cancel();
formatter = null;
handler = null;
timer = null;
}
}

Loading…
Cancel
Save