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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save