|
|
|
|
@ -12,15 +12,10 @@ import androidx.appcompat.widget.AppCompatTextView; |
|
|
|
|
|
|
|
|
|
import com.fongmi.android.tv.App; |
|
|
|
|
import com.fongmi.android.tv.R; |
|
|
|
|
import com.fongmi.android.tv.Setting; |
|
|
|
|
import com.fongmi.android.tv.api.config.VodConfig; |
|
|
|
|
import com.fongmi.android.tv.bean.Site; |
|
|
|
|
import com.fongmi.android.tv.impl.SiteCallback; |
|
|
|
|
import com.fongmi.android.tv.utils.KeyUtil; |
|
|
|
|
import com.fongmi.android.tv.utils.ResUtil; |
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
public class CustomTitleView extends AppCompatTextView { |
|
|
|
|
|
|
|
|
|
private Listener listener; |
|
|
|
|
@ -42,7 +37,7 @@ public class CustomTitleView extends AppCompatTextView { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean hasEvent(KeyEvent event) { |
|
|
|
|
return KeyUtil.isEnterKey(event) || KeyUtil.isLeftKey(event) || KeyUtil.isRightKey(event) || (KeyUtil.isUpKey(event) && !coolDown) || (KeyUtil.isDownKey(event) && !coolDown); |
|
|
|
|
return KeyUtil.isEnterKey(event) || (KeyUtil.isUpKey(event) && !coolDown); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@ -54,8 +49,6 @@ public class CustomTitleView extends AppCompatTextView { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean dispatchKeyEvent(KeyEvent event) { |
|
|
|
|
if (Setting.isHomeSiteLock()) return false; |
|
|
|
|
if (VodConfig.get().getSites().isEmpty()) return false; |
|
|
|
|
if (hasEvent(event)) return onKeyDown(event); |
|
|
|
|
else return super.dispatchKeyEvent(event); |
|
|
|
|
} |
|
|
|
|
@ -63,14 +56,8 @@ public class CustomTitleView extends AppCompatTextView { |
|
|
|
|
private boolean onKeyDown(KeyEvent event) { |
|
|
|
|
if (event.getAction() == KeyEvent.ACTION_UP && KeyUtil.isEnterKey(event)) { |
|
|
|
|
listener.showDialog(); |
|
|
|
|
} else if (event.getAction() == KeyEvent.ACTION_DOWN && KeyUtil.isLeftKey(event)) { |
|
|
|
|
listener.setSite(getSite(true)); |
|
|
|
|
} else if (event.getAction() == KeyEvent.ACTION_DOWN && KeyUtil.isRightKey(event)) { |
|
|
|
|
listener.setSite(getSite(false)); |
|
|
|
|
} else if (event.getAction() == KeyEvent.ACTION_DOWN && KeyUtil.isUpKey(event)) { |
|
|
|
|
onKeyUp(); |
|
|
|
|
} else if (event.getAction() == KeyEvent.ACTION_DOWN && KeyUtil.isDownKey(event)) { |
|
|
|
|
onKeyDown(); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
@ -81,26 +68,10 @@ public class CustomTitleView extends AppCompatTextView { |
|
|
|
|
coolDown = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onKeyDown() { |
|
|
|
|
App.post(() -> coolDown = false, 3000); |
|
|
|
|
listener.onSettingVodHistory(); |
|
|
|
|
coolDown = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Site getSite(boolean next) { |
|
|
|
|
List<Site> items = VodConfig.get().getSites(); |
|
|
|
|
int position = VodConfig.getHomeIndex(); |
|
|
|
|
if (next) position = position > 0 ? --position : items.size() - 1; |
|
|
|
|
else position = position < items.size() - 1 ? ++position : 0; |
|
|
|
|
return items.get(position); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public interface Listener extends SiteCallback { |
|
|
|
|
|
|
|
|
|
void showDialog(); |
|
|
|
|
|
|
|
|
|
void onRefresh(); |
|
|
|
|
|
|
|
|
|
void onSettingVodHistory(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|