Optimize config code

release
FongMi 3 weeks ago
parent 86f8ce9b92
commit 7c3c9b708e
  1. 10
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/CastActivity.java
  2. 48
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/HomeActivity.java
  3. 3
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/KeepActivity.java
  4. 15
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  5. 40
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/SettingActivity.java
  6. 18
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/VideoActivity.java
  7. 6
      app/src/leanback/java/com/fongmi/android/tv/ui/dialog/ConfigDialog.java
  8. 4
      app/src/leanback/java/com/fongmi/android/tv/ui/dialog/UaDialog.java
  9. 2
      app/src/mobile/java/com/fongmi/android/tv/ui/fragment/VodFragment.java

@ -286,11 +286,11 @@ public class CastActivity extends BaseActivity implements CustomKeyDownVod.Liste
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onActionEvent(ActionEvent event) { public void onActionEvent(ActionEvent event) {
if (ActionEvent.PLAY.equals(event.getAction())) { if (ActionEvent.PLAY.equals(event.action())) {
onPlay(); onPlay();
} else if (ActionEvent.PAUSE.equals(event.getAction())) { } else if (ActionEvent.PAUSE.equals(event.action())) {
onPaused(); onPaused();
} else if (ActionEvent.STOP.equals(event.getAction())) { } else if (ActionEvent.STOP.equals(event.action())) {
finish(); finish();
} }
} }
@ -303,8 +303,8 @@ public class CastActivity extends BaseActivity implements CustomKeyDownVod.Liste
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onPlayerEvent(PlayerEvent event) { public void onPlayerEvent(PlayerEvent event) {
if (!event.getTag().equals(tag)) return; if (!event.tag().equals(tag)) return;
switch (event.getState()) { switch (event.state()) {
case PlayerEvent.PREPARE: case PlayerEvent.PREPARE:
setDecode(); setDecode();
setState(RenderState.PREPARING); setState(RenderState.PREPARING);

@ -23,7 +23,6 @@ import androidx.viewbinding.ViewBinding;
import com.fongmi.android.tv.App; import com.fongmi.android.tv.App;
import com.fongmi.android.tv.Product; import com.fongmi.android.tv.Product;
import com.fongmi.android.tv.R; import com.fongmi.android.tv.R;
import com.fongmi.android.tv.Setting;
import com.fongmi.android.tv.Updater; import com.fongmi.android.tv.Updater;
import com.fongmi.android.tv.api.config.LiveConfig; import com.fongmi.android.tv.api.config.LiveConfig;
import com.fongmi.android.tv.api.config.VodConfig; import com.fongmi.android.tv.api.config.VodConfig;
@ -39,6 +38,7 @@ import com.fongmi.android.tv.bean.Vod;
import com.fongmi.android.tv.databinding.ActivityHomeBinding; import com.fongmi.android.tv.databinding.ActivityHomeBinding;
import com.fongmi.android.tv.db.AppDatabase; import com.fongmi.android.tv.db.AppDatabase;
import com.fongmi.android.tv.event.CastEvent; import com.fongmi.android.tv.event.CastEvent;
import com.fongmi.android.tv.event.ConfigEvent;
import com.fongmi.android.tv.event.RefreshEvent; import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.event.ServerEvent; import com.fongmi.android.tv.event.ServerEvent;
import com.fongmi.android.tv.impl.Callback; import com.fongmi.android.tv.impl.Callback;
@ -198,17 +198,9 @@ public class HomeActivity extends BaseActivity implements CustomTitleView.Listen
private Callback getCallback() { private Callback getCallback() {
return new Callback() { return new Callback() {
@Override
public void success(String result) {
Notify.show(result);
}
@Override @Override
public void success() { public void success() {
showContent(); showContent();
getHistory();
getVideo();
setLogo();
} }
@Override @Override
@ -223,7 +215,6 @@ public class HomeActivity extends BaseActivity implements CustomTitleView.Listen
mBinding.progressLayout.showContent(); mBinding.progressLayout.showContent();
checkAction(getIntent()); checkAction(getIntent());
setFocus(); setFocus();
setFunc();
} }
private void loadLive(String url) { private void loadLive(String url) {
@ -320,11 +311,7 @@ public class HomeActivity extends BaseActivity implements CustomTitleView.Listen
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onRefreshEvent(RefreshEvent event) { public void onRefreshEvent(RefreshEvent event) {
switch (event.getType()) { switch (event.getType()) {
case CONFIG: case HOME:
setFunc();
setLogo();
break;
case VIDEO:
getVideo(); getVideo();
break; break;
case HISTORY: case HISTORY:
@ -334,30 +321,40 @@ public class HomeActivity extends BaseActivity implements CustomTitleView.Listen
getVideo(); getVideo();
getHistory(true); getHistory(true);
break; break;
case BOOT: }
LiveActivity.start(this); }
break;
@Subscribe(threadMode = ThreadMode.MAIN)
public void onConfigEvent(ConfigEvent event) {
if (event.type() == ConfigEvent.Type.VOD) {
RefreshEvent.history();
RefreshEvent.home();
setLogo();
} else if (event.type() == ConfigEvent.Type.COMMON) {
setFunc();
} else if (event.type() == ConfigEvent.Type.BOOT) {
LiveActivity.start(this);
} }
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onServerEvent(ServerEvent event) { public void onServerEvent(ServerEvent event) {
switch (event.getType()) { switch (event.type()) {
case SEARCH: case SEARCH:
CollectActivity.start(this, event.getText()); CollectActivity.start(this, event.text());
break; break;
case PUSH: case PUSH:
VideoActivity.push(this, event.getText()); VideoActivity.push(this, event.text());
break; break;
} }
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onCastEvent(CastEvent event) { public void onCastEvent(CastEvent event) {
if (VodConfig.get().getConfig().equals(event.getConfig())) { if (VodConfig.get().getConfig().equals(event.config())) {
VideoActivity.cast(this, event.getHistory().save(VodConfig.getCid())); VideoActivity.cast(this, event.history().save(VodConfig.getCid()));
} else { } else {
VodConfig.load(event.getConfig(), getCallback(event)); VodConfig.load(event.config(), getCallback(event));
} }
} }
@ -365,9 +362,6 @@ public class HomeActivity extends BaseActivity implements CustomTitleView.Listen
return new Callback() { return new Callback() {
@Override @Override
public void success() { public void success() {
RefreshEvent.history();
RefreshEvent.config();
RefreshEvent.video();
onCastEvent(event); onCastEvent(event);
} }

@ -58,9 +58,6 @@ public class KeepActivity extends BaseActivity implements KeepAdapter.OnClickLis
@Override @Override
public void success() { public void success() {
VideoActivity.start(getActivity(), item.getSiteKey(), item.getVodId(), item.getVodName(), item.getVodPic()); VideoActivity.start(getActivity(), item.getSiteKey(), item.getVodId(), item.getVodName(), item.getVodPic());
RefreshEvent.history();
RefreshEvent.config();
RefreshEvent.video();
} }
@Override @Override

@ -699,7 +699,6 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
@Override @Override
public void success() { public void success() {
RefreshEvent.config();
setLive(getHome()); setLive(getHome());
} }
@ -746,15 +745,15 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onActionEvent(ActionEvent event) { public void onActionEvent(ActionEvent event) {
if (ActionEvent.PLAY.equals(event.getAction())) { if (ActionEvent.PLAY.equals(event.action())) {
onPlay(); onPlay();
} else if (ActionEvent.PAUSE.equals(event.getAction())) { } else if (ActionEvent.PAUSE.equals(event.action())) {
onPaused(); onPaused();
} else if (ActionEvent.NEXT.equals(event.getAction())) { } else if (ActionEvent.NEXT.equals(event.action())) {
nextChannel(); nextChannel();
} else if (ActionEvent.PREV.equals(event.getAction())) { } else if (ActionEvent.PREV.equals(event.action())) {
prevChannel(); prevChannel();
} else if (ActionEvent.STOP.equals(event.getAction())) { } else if (ActionEvent.STOP.equals(event.action())) {
finish(); finish();
} }
} }
@ -773,8 +772,8 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onPlayerEvent(PlayerEvent event) { public void onPlayerEvent(PlayerEvent event) {
if (!event.getTag().equals(tag)) return; if (!event.tag().equals(tag)) return;
switch (event.getState()) { switch (event.state()) {
case PlayerEvent.PREPARE: case PlayerEvent.PREPARE:
setDecode(); setDecode();
break; break;

@ -20,6 +20,7 @@ import com.fongmi.android.tv.bean.Live;
import com.fongmi.android.tv.bean.Site; import com.fongmi.android.tv.bean.Site;
import com.fongmi.android.tv.databinding.ActivitySettingBinding; import com.fongmi.android.tv.databinding.ActivitySettingBinding;
import com.fongmi.android.tv.db.AppDatabase; import com.fongmi.android.tv.db.AppDatabase;
import com.fongmi.android.tv.event.ConfigEvent;
import com.fongmi.android.tv.event.RefreshEvent; import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.impl.Callback; import com.fongmi.android.tv.impl.Callback;
import com.fongmi.android.tv.impl.ConfigCallback; import com.fongmi.android.tv.impl.ConfigCallback;
@ -140,56 +141,42 @@ public class SettingActivity extends BaseActivity implements ConfigCallback, Sit
private void load(Config config) { private void load(Config config) {
switch (config.getType()) { switch (config.getType()) {
case 0: case 0:
VodConfig.load(config, getCallback(0)); VodConfig.load(config, getCallback());
break; break;
case 1: case 1:
LiveConfig.load(config, getCallback(1)); LiveConfig.load(config, getCallback());
break; break;
case 2: case 2:
Setting.putWall(0); Setting.putWall(0);
WallConfig.load(config, getCallback(2)); WallConfig.load(config, getCallback());
break; break;
} }
} }
private Callback getCallback(int type) { private Callback getCallback() {
return new Callback() { return new Callback() {
@Override @Override
public void start() { public void start() {
Notify.progress(getActivity()); Notify.progress(getActivity());
} }
@Override
public void success(String result) {
Notify.show(result);
}
@Override @Override
public void success() { public void success() {
setConfig(type); Notify.dismiss();
setCacheText();
} }
@Override @Override
public void error(String msg) { public void error(String msg) {
Notify.dismiss();
Notify.show(msg); Notify.show(msg);
setConfig(type);
} }
}; };
} }
private void setConfig(int type) {
setCacheText();
Notify.dismiss();
RefreshEvent.config();
if (type != 0) return;
RefreshEvent.video();
RefreshEvent.history();
}
@Override @Override
public void setSite(Site item) { public void setSite(Site item) {
VodConfig.get().setHome(item); VodConfig.get().setHome(item);
RefreshEvent.video();
} }
@Override @Override
@ -250,12 +237,13 @@ public class SettingActivity extends BaseActivity implements ConfigCallback, Sit
private void setWallDefault(View view) { private void setWallDefault(View view) {
Setting.putWall(Setting.getWall() == 4 ? 1 : Setting.getWall() + 1); Setting.putWall(Setting.getWall() == 4 ? 1 : Setting.getWall() + 1);
RefreshEvent.wall(); Setting.putWallType(0);
ConfigEvent.wall();
} }
private void setWallRefresh(View view) { private void setWallRefresh(View view) {
Setting.putWall(0); Setting.putWall(0);
WallConfig.get().load(getCallback(2)); WallConfig.get().load(getCallback());
} }
private boolean onWallHistory(View view) { private boolean onWallHistory(View view) {
@ -326,14 +314,14 @@ public class SettingActivity extends BaseActivity implements ConfigCallback, Sit
} }
private void initConfig() { private void initConfig() {
VodConfig.get().init().load(getCallback(0)); VodConfig.get().init().load(getCallback());
LiveConfig.get().init().load(); LiveConfig.get().init().load();
WallConfig.get().init().load(); WallConfig.get().init().load();
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onRefreshEvent(RefreshEvent event) { public void onConfigEvent(ConfigEvent event) {
if (event.getType() != RefreshEvent.Type.CONFIG) return; if (event.type() != ConfigEvent.Type.COMMON) return;
mBinding.vodUrl.setText(VodConfig.getDesc()); mBinding.vodUrl.setText(VodConfig.getDesc());
mBinding.liveUrl.setText(LiveConfig.getDesc()); mBinding.liveUrl.setText(LiveConfig.getDesc());
mBinding.wallUrl.setText(WallConfig.getDesc()); mBinding.wallUrl.setText(WallConfig.getDesc());

@ -1066,19 +1066,19 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onActionEvent(ActionEvent event) { public void onActionEvent(ActionEvent event) {
if (isRedirect()) return; if (isRedirect()) return;
if (ActionEvent.PLAY.equals(event.getAction())) { if (ActionEvent.PLAY.equals(event.action())) {
onPlay(); onPlay();
} else if (ActionEvent.PAUSE.equals(event.getAction())) { } else if (ActionEvent.PAUSE.equals(event.action())) {
onPaused(); onPaused();
} else if (ActionEvent.NEXT.equals(event.getAction())) { } else if (ActionEvent.NEXT.equals(event.action())) {
checkNext(); checkNext();
} else if (ActionEvent.PREV.equals(event.getAction())) { } else if (ActionEvent.PREV.equals(event.action())) {
checkPrev(); checkPrev();
} else if (ActionEvent.LOOP.equals(event.getAction())) { } else if (ActionEvent.LOOP.equals(event.action())) {
onLoop(); onLoop();
} else if (ActionEvent.REPLAY.equals(event.getAction())) { } else if (ActionEvent.REPLAY.equals(event.action())) {
onReplay(); onReplay();
} else if (ActionEvent.STOP.equals(event.getAction())) { } else if (ActionEvent.STOP.equals(event.action())) {
finish(); finish();
} }
} }
@ -1095,8 +1095,8 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onPlayerEvent(PlayerEvent event) { public void onPlayerEvent(PlayerEvent event) {
if (!event.getTag().equals(tag)) return; if (!event.tag().equals(tag)) return;
switch (event.getState()) { switch (event.state()) {
case PlayerEvent.PREPARE: case PlayerEvent.PREPARE:
setDecode(); setDecode();
setPosition(); setPosition();

@ -159,9 +159,9 @@ public class ConfigDialog implements DialogInterface.OnDismissListener {
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onServerEvent(ServerEvent event) { public void onServerEvent(ServerEvent event) {
if (event.getType() != ServerEvent.Type.SETTING) return; if (event.type() != ServerEvent.Type.SETTING) return;
binding.name.setText(event.getName()); binding.name.setText(event.name());
binding.text.setText(event.getText()); binding.text.setText(event.text());
binding.text.setSelection(binding.text.getText().length()); binding.text.setSelection(binding.text.getText().length());
} }

@ -108,8 +108,8 @@ public class UaDialog implements DialogInterface.OnDismissListener {
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onServerEvent(ServerEvent event) { public void onServerEvent(ServerEvent event) {
if (event.getType() != ServerEvent.Type.SETTING) return; if (event.type() != ServerEvent.Type.SETTING) return;
binding.text.setText(event.getText()); binding.text.setText(event.text());
binding.positive.performClick(); binding.positive.performClick();
} }

@ -271,13 +271,11 @@ public class VodFragment extends BaseFragment implements ConfigCallback, SiteCal
showProgress(); showProgress();
hideContent(); hideContent();
setTitle(); setTitle();
setLogo();
} }
@Override @Override
public void success() { public void success() {
showContent(); showContent();
setLogo();
} }
@Override @Override

Loading…
Cancel
Save