[mobile] clean code

release
FongMi 2 years ago
parent 279407a53d
commit 7da8869a81
  1. 10
      app/src/main/java/com/fongmi/android/tv/event/RefreshEvent.java
  2. 32
      app/src/main/java/com/fongmi/android/tv/event/StateEvent.java
  3. 5
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/MainActivity.java
  4. 19
      app/src/mobile/java/com/fongmi/android/tv/ui/fragment/VodFragment.java

@ -7,14 +7,6 @@ public class RefreshEvent {
private final Type type;
private String path;
public static void empty() {
EventBus.getDefault().post(new RefreshEvent(Type.EMPTY));
}
public static void restore() {
EventBus.getDefault().post(new RefreshEvent(Type.RESTORE));
}
public static void config() {
EventBus.getDefault().post(new RefreshEvent(Type.CONFIG));
}
@ -73,6 +65,6 @@ public class RefreshEvent {
}
public enum Type {
EMPTY, RESTORE, CONFIG, IMAGE, VIDEO, HISTORY, KEEP, SIZE, WALL, DETAIL, PLAYER, SUBTITLE
CONFIG, IMAGE, VIDEO, HISTORY, KEEP, SIZE, WALL, DETAIL, PLAYER, SUBTITLE
}
}

@ -0,0 +1,32 @@
package com.fongmi.android.tv.event;
import org.greenrobot.eventbus.EventBus;
public class StateEvent {
private final Type type;
public static void empty() {
EventBus.getDefault().post(new StateEvent(Type.EMPTY));
}
public static void progress() {
EventBus.getDefault().post(new StateEvent(Type.PROGRESS));
}
public static void content() {
EventBus.getDefault().post(new StateEvent(Type.CONTENT));
}
private StateEvent(Type type) {
this.type = type;
}
public Type getType() {
return type;
}
public enum Type {
EMPTY, PROGRESS, CONTENT
}
}

@ -26,6 +26,7 @@ import com.fongmi.android.tv.databinding.ActivityMainBinding;
import com.fongmi.android.tv.db.AppDatabase;
import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.event.ServerEvent;
import com.fongmi.android.tv.event.StateEvent;
import com.fongmi.android.tv.impl.Callback;
import com.fongmi.android.tv.player.Source;
import com.fongmi.android.tv.receiver.ShortcutReceiver;
@ -119,7 +120,7 @@ public class MainActivity extends BaseActivity implements NavigationBarView.OnIt
public void error(String msg) {
if (TextUtils.isEmpty(msg) && AppDatabase.getBackup().exists()) showDialog();
RefreshEvent.config();
RefreshEvent.empty();
StateEvent.empty();
Notify.show(msg);
}
};
@ -133,7 +134,7 @@ public class MainActivity extends BaseActivity implements NavigationBarView.OnIt
PermissionX.init(this).permissions(Manifest.permission.WRITE_EXTERNAL_STORAGE).request((allGranted, grantedList, deniedList) -> AppDatabase.restore(new Callback() {
@Override
public void success() {
if (allGranted) RefreshEvent.restore();
if (allGranted) StateEvent.progress();
if (allGranted) initConfig();
}
}));

@ -31,6 +31,7 @@ import com.fongmi.android.tv.bean.Value;
import com.fongmi.android.tv.databinding.FragmentVodBinding;
import com.fongmi.android.tv.event.CastEvent;
import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.event.StateEvent;
import com.fongmi.android.tv.impl.Callback;
import com.fongmi.android.tv.impl.FilterCallback;
import com.fongmi.android.tv.impl.SiteCallback;
@ -276,12 +277,6 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal
@Subscribe(threadMode = ThreadMode.MAIN)
public void onRefreshEvent(RefreshEvent event) {
switch (event.getType()) {
case EMPTY:
hideProgress();
break;
case RESTORE:
showProgress();
break;
case CONFIG:
setLogo();
break;
@ -292,6 +287,18 @@ public class VodFragment extends BaseFragment implements SiteCallback, FilterCal
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onStateEvent(StateEvent event) {
switch (event.getType()) {
case EMPTY:
hideProgress();
break;
case PROGRESS:
showProgress();
break;
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onCastEvent(CastEvent event) {
ReceiveDialog.create().event(event).show(this);

Loading…
Cancel
Save