123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726 |
- package com.github.tvbox.osc.ui.activity;
- import android.Manifest;
- import android.animation.Animator;
- import android.animation.AnimatorSet;
- import android.animation.IntEvaluator;
- import android.animation.ObjectAnimator;
- import android.annotation.SuppressLint;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.res.Resources;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
- import android.net.Uri;
- import android.os.Bundle;
- import android.os.Handler;
- import android.provider.Settings;
- import android.view.KeyEvent;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.animation.AccelerateInterpolator;
- import android.view.animation.BounceInterpolator;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- import androidx.annotation.NonNull;
- import androidx.lifecycle.Observer;
- import androidx.lifecycle.ViewModelProvider;
- import androidx.recyclerview.widget.DiffUtil;
- import androidx.viewpager.widget.ViewPager;
- import com.github.tvbox.osc.R;
- import com.github.tvbox.osc.api.ApiConfig;
- import com.github.tvbox.osc.base.BaseActivity;
- import com.github.tvbox.osc.base.BaseLazyFragment;
- import com.github.tvbox.osc.bean.AbsSortXml;
- import com.github.tvbox.osc.bean.MovieSort;
- import com.github.tvbox.osc.bean.SourceBean;
- import com.github.tvbox.osc.event.RefreshEvent;
- import com.github.tvbox.osc.server.ControlManager;
- import com.github.tvbox.osc.ui.adapter.HomePageAdapter;
- import com.github.tvbox.osc.ui.adapter.SelectDialogAdapter;
- import com.github.tvbox.osc.ui.adapter.SortAdapter;
- import com.github.tvbox.osc.ui.dialog.SelectDialog;
- import com.github.tvbox.osc.ui.dialog.TipDialog;
- import com.github.tvbox.osc.ui.fragment.GridFragment;
- import com.github.tvbox.osc.ui.fragment.UserFragment;
- import com.github.tvbox.osc.ui.tv.widget.DefaultTransformer;
- import com.github.tvbox.osc.ui.tv.widget.FixedSpeedScroller;
- import com.github.tvbox.osc.ui.tv.widget.NoScrollViewPager;
- import com.github.tvbox.osc.ui.tv.widget.ViewObj;
- import com.github.tvbox.osc.util.AppManager;
- import com.github.tvbox.osc.util.DefaultConfig;
- import com.github.tvbox.osc.util.FileUtils;
- import com.github.tvbox.osc.util.HawkConfig;
- import com.github.tvbox.osc.util.LOG;
- import com.github.tvbox.osc.viewmodel.SourceViewModel;
- import com.orhanobut.hawk.Hawk;
- import com.owen.tvrecyclerview.widget.TvRecyclerView;
- import com.owen.tvrecyclerview.widget.V7LinearLayoutManager;
- import org.greenrobot.eventbus.EventBus;
- import org.greenrobot.eventbus.Subscribe;
- import org.greenrobot.eventbus.ThreadMode;
- import org.jetbrains.annotations.NotNull;
- import java.io.File;
- import java.lang.reflect.Field;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import me.jessyan.autosize.utils.AutoSizeUtils;
- import androidx.constraintlayout.widget.ConstraintLayout;
- import com.owen.tvrecyclerview.widget.V7GridLayoutManager;
- public class HomeActivity extends BaseActivity {
- // takagen99: Added to allow read string
- private static Resources res;
- private LinearLayout topLayout;
- private LinearLayout contentLayout;
- private TextView tvName;
- private ImageView tvWifi;
- private ImageView tvFind;
- private ImageView tvMenu;
- private TextView tvDate;
- private TvRecyclerView mGridView;
- private NoScrollViewPager mViewPager;
- private SourceViewModel sourceViewModel;
- private SortAdapter sortAdapter;
- private HomePageAdapter pageAdapter;
- private final List<BaseLazyFragment> fragments = new ArrayList<>();
- private boolean isDownOrUp = false;
- private boolean sortChange = false;
- private int currentSelected = 0;
- private int sortFocused = 0;
- public View sortFocusView = null;
- private final Handler mHandler = new Handler();
- private long mExitTime = 0;
- private final Runnable mRunnable = new Runnable() {
- @SuppressLint({"DefaultLocale", "SetTextI18n"})
- @Override
- public void run() {
- Date date = new Date();
- @SuppressLint("SimpleDateFormat")
- SimpleDateFormat timeFormat = new SimpleDateFormat(getString(R.string.hm_date1) + ", " + getString(R.string.hm_date2));
- tvDate.setText(timeFormat.format(date));
- mHandler.postDelayed(this, 1000);
- }
- };
- @Override
- protected int getLayoutResID() {
- return R.layout.activity_home;
- }
- boolean useCacheConfig = false;
- @Override
- protected void init() {
- // takagen99: Added to allow read string
- res = getResources();
- EventBus.getDefault().register(this);
- ControlManager.get().startServer();
- initView();
- initViewModel();
- useCacheConfig = false;
- Intent intent = getIntent();
- if (intent != null && intent.getExtras() != null) {
- Bundle bundle = intent.getExtras();
- useCacheConfig = bundle.getBoolean("useCache", false);
- }
- initData();
- }
- // takagen99: Added to allow read string
- public static Resources getRes() {
- return res;
- }
- private void initView() {
- this.topLayout = findViewById(R.id.topLayout);
- this.tvName = findViewById(R.id.tvName);
- this.tvWifi = findViewById(R.id.tvWifi);
- this.tvFind = findViewById(R.id.tvFind);
- this.tvMenu = findViewById(R.id.tvMenu);
- this.tvDate = findViewById(R.id.tvDate);
- this.contentLayout = findViewById(R.id.contentLayout);
- this.mGridView = findViewById(R.id.mGridView);
- this.mViewPager = findViewById(R.id.mViewPager);
- this.sortAdapter = new SortAdapter();
- this.mGridView.setLayoutManager(new V7LinearLayoutManager(this.mContext, 0, false));
- this.mGridView.setSpacingWithMargins(0, AutoSizeUtils.dp2px(this.mContext, 10.0f));
- this.mGridView.setAdapter(this.sortAdapter);
- this.mGridView.setOnItemListener(new TvRecyclerView.OnItemListener() {
- public void onItemPreSelected(TvRecyclerView tvRecyclerView, View view, int position) {
- if (view != null && !HomeActivity.this.isDownOrUp) {
- view.animate().scaleX(1.0f).scaleY(1.0f).setDuration(250).start();
- TextView textView = view.findViewById(R.id.tvTitle);
- textView.getPaint().setFakeBoldText(false);
- textView.setTextColor(HomeActivity.this.getResources().getColor(R.color.color_FFFFFF_70));
- textView.invalidate();
- view.findViewById(R.id.tvFilter).setVisibility(View.GONE);
- }
- }
- public void onItemSelected(TvRecyclerView tvRecyclerView, View view, int position) {
- if (view != null) {
- HomeActivity.this.isDownOrUp = false;
- HomeActivity.this.sortChange = true;
- view.animate().scaleX(1.1f).scaleY(1.1f).setInterpolator(new BounceInterpolator()).setDuration(250).start();
- TextView textView = view.findViewById(R.id.tvTitle);
- textView.getPaint().setFakeBoldText(true);
- textView.setTextColor(HomeActivity.this.getResources().getColor(R.color.color_FFFFFF));
- textView.invalidate();
- if (!sortAdapter.getItem(position).filters.isEmpty())
- view.findViewById(R.id.tvFilter).setVisibility(View.VISIBLE);
- HomeActivity.this.sortFocusView = view;
- HomeActivity.this.sortFocused = position;
- mHandler.removeCallbacks(mDataRunnable);
- mHandler.postDelayed(mDataRunnable, 200);
- }
- }
- @Override
- public void onItemClick(TvRecyclerView parent, View itemView, int position) {
- if (itemView != null && currentSelected == position) {
- BaseLazyFragment baseLazyFragment = fragments.get(currentSelected);
- if ((baseLazyFragment instanceof GridFragment) && !sortAdapter.getItem(position).filters.isEmpty()) {// 弹出筛选
- ((GridFragment) baseLazyFragment).showFilter();
- } else if (baseLazyFragment instanceof UserFragment) {
- showSiteSwitch();
- }
- }
- }
- });
- this.mGridView.setOnInBorderKeyEventListener(new TvRecyclerView.OnInBorderKeyEventListener() {
- public final boolean onInBorderKeyEvent(int direction, View view) {
- if(direction == View.FOCUS_UP){
- BaseLazyFragment baseLazyFragment = fragments.get(sortFocused);
- if ((baseLazyFragment instanceof GridFragment) ) {// 弹出筛选
- ((GridFragment) baseLazyFragment).forceRefresh();
- }
- }
- if (direction != View.FOCUS_DOWN) {
- return false;
- }
- BaseLazyFragment baseLazyFragment = fragments.get(sortFocused);
- if (!(baseLazyFragment instanceof GridFragment)) {
- return false;
- }
- return !((GridFragment) baseLazyFragment).isLoad();
- }
- });
- // Button : TVBOX >> Go into Source Select / Longclick to delete Cache --
- tvName.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- dataInitOk = false;
- jarInitOk = true;
- showSiteSwitch();
- }
- });
- tvName.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- File dir = mContext.getCacheDir();
- FileUtils.recursiveDelete(dir);
- Toast.makeText(HomeActivity.this, getString(R.string.hm_cache_del), Toast.LENGTH_SHORT).show();
- return true;
- }
- });
- // Button : Wifi >> Go into Android Wifi Settings -------------
- tvWifi.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
- }
- });
- // Button : Search --------------------------------------------
- tvFind.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- jumpActivity(SearchActivity.class);
- }
- });
- // Button : Settings >> To go into Settings --------------------
- tvMenu.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- jumpActivity(SettingActivity.class);
- }
- });
- // Button : Settings >> To go into App Settings ----------------
- tvMenu.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View view) {
- startActivity(new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", getPackageName(), null)));
- return true;
- }
- });
- // Button : Date >> Go into Android Date Settings --------------
- tvDate.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- startActivity(new Intent(Settings.ACTION_DATE_SETTINGS));
- }
- });
- setLoadSir(this.contentLayout);
- //mHandler.postDelayed(mFindFocus, 250);
- }
- private void initViewModel() {
- sourceViewModel = new ViewModelProvider(this).get(SourceViewModel.class);
- sourceViewModel.sortResult.observe(this, new Observer<AbsSortXml>() {
- @Override
- public void onChanged(AbsSortXml absXml) {
- showSuccess();
- if (absXml != null && absXml.classes != null && absXml.classes.sortList != null) {
- sortAdapter.setNewData(DefaultConfig.adjustSort(ApiConfig.get().getHomeSourceBean().getKey(), absXml.classes.sortList, true));
- } else {
- sortAdapter.setNewData(DefaultConfig.adjustSort(ApiConfig.get().getHomeSourceBean().getKey(), new ArrayList<>(), true));
- }
- initViewPager(absXml);
- }
- });
- }
- private boolean dataInitOk = false;
- private boolean jarInitOk = false;
- // takagen99 : Switch to show / hide source title
- boolean HomeShow = Hawk.get(HawkConfig.HOME_SHOW_SOURCE, false);
- // takagen99 : Check if network is available
- boolean isNetworkAvailable() {
- ConnectivityManager cm
- = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
- NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
- return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
- }
- private void initData() {
- SourceBean home = ApiConfig.get().getHomeSourceBean();
- // takagen99 : Switch to show / hide source title
- if (HomeShow) {
- if (home != null && home.getName() != null && !home.getName().isEmpty())
- tvName.setText(home.getName());
- }
- // takagen99: If network available, check connected Wifi or Lan
- if (isNetworkAvailable()) {
- ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
- if (cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI) {
- tvWifi.setImageDrawable(res.getDrawable(R.drawable.hm_wifi));
- } else if (cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_MOBILE) {
- tvWifi.setImageDrawable(res.getDrawable(R.drawable.hm_mobile));
- } else if (cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_ETHERNET) {
- tvWifi.setImageDrawable(res.getDrawable(R.drawable.hm_lan));
- }
- }
- mGridView.requestFocus();
- if (dataInitOk && jarInitOk) {
- showLoading();
- sourceViewModel.getSort(ApiConfig.get().getHomeSourceBean().getKey());
- if (hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
- LOG.e("有");
- } else {
- LOG.e("无");
- }
- return;
- }
- showLoading();
- if (dataInitOk && !jarInitOk) {
- if (!ApiConfig.get().getSpider().isEmpty()) {
- ApiConfig.get().loadJar(useCacheConfig, ApiConfig.get().getSpider(), new ApiConfig.LoadConfigCallback() {
- @Override
- public void success() {
- jarInitOk = true;
- mHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- if (!useCacheConfig)
- Toast.makeText(HomeActivity.this, getString(R.string.hm_ok), Toast.LENGTH_SHORT).show();
- initData();
- }
- }, 50);
- }
- @Override
- public void retry() {
- }
- @Override
- public void error(String msg) {
- jarInitOk = true;
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(HomeActivity.this, getString(R.string.hm_notok), Toast.LENGTH_SHORT).show();
- initData();
- }
- });
- }
- });
- }
- return;
- }
- ApiConfig.get().loadConfig(useCacheConfig, new ApiConfig.LoadConfigCallback() {
- TipDialog dialog = null;
- @Override
- public void retry() {
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- initData();
- }
- });
- }
- @Override
- public void success() {
- dataInitOk = true;
- if (ApiConfig.get().getSpider().isEmpty()) {
- jarInitOk = true;
- }
- mHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- initData();
- }
- }, 50);
- }
- @Override
- public void error(String msg) {
- if (msg.equalsIgnoreCase("-1")) {
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- dataInitOk = true;
- jarInitOk = true;
- initData();
- }
- });
- return;
- }
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- if (dialog == null)
- dialog = new TipDialog(HomeActivity.this, msg, getString(R.string.hm_retry), getString(R.string.hm_cancel), new TipDialog.OnListener() {
- @Override
- public void left() {
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- initData();
- dialog.hide();
- }
- });
- }
- @Override
- public void right() {
- dataInitOk = true;
- jarInitOk = true;
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- initData();
- dialog.hide();
- }
- });
- }
- @Override
- public void cancel() {
- dataInitOk = true;
- jarInitOk = true;
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- initData();
- dialog.hide();
- }
- });
- }
- });
- if (!dialog.isShowing())
- dialog.show();
- }
- });
- }
- }, this);
- }
- private void initViewPager(AbsSortXml absXml) {
- if (sortAdapter.getData().size() > 0) {
- for (MovieSort.SortData data : sortAdapter.getData()) {
- if (data.id.equals("my0")) {
- if (Hawk.get(HawkConfig.HOME_REC, 0) == 1 && absXml != null && absXml.videoList != null && absXml.videoList.size() > 0) {
- fragments.add(UserFragment.newInstance(absXml.videoList));
- } else {
- fragments.add(UserFragment.newInstance(null));
- }
- } else {
- fragments.add(GridFragment.newInstance(data));
- }
- }
- pageAdapter = new HomePageAdapter(getSupportFragmentManager(), fragments);
- try {
- Field field = ViewPager.class.getDeclaredField("mScroller");
- field.setAccessible(true);
- FixedSpeedScroller scroller = new FixedSpeedScroller(mContext, new AccelerateInterpolator());
- field.set(mViewPager, scroller);
- scroller.setmDuration(300);
- } catch (Exception e) {
- }
- mViewPager.setPageTransformer(true, new DefaultTransformer());
- mViewPager.setAdapter(pageAdapter);
- mViewPager.setCurrentItem(currentSelected, false);
- }
- }
- @Override
- public void onBackPressed() {
- int i;
- if (this.fragments.size() <= 0 || this.sortFocused >= this.fragments.size() || (i = this.sortFocused) < 0) {
- exit();
- return;
- }
- BaseLazyFragment baseLazyFragment = this.fragments.get(i);
- if (baseLazyFragment instanceof GridFragment) {
- View view = this.sortFocusView;
- GridFragment grid = (GridFragment) baseLazyFragment;
- if (grid.restoreView()) {
- return;
- }// 还原上次保存的UI内容
- if (view != null && !view.isFocused()) {
- this.sortFocusView.requestFocus();
- } else if (this.sortFocused != 0) {
- this.mGridView.setSelection(0);
- } else {
- exit();
- }
- } else {
- exit();
- }
- }
- private void exit() {
- if (System.currentTimeMillis() - mExitTime < 2000) {
- //这一段借鉴来自 q群老哥 IDCardWeb
- EventBus.getDefault().unregister(this);
- AppManager.getInstance().appExit(0);
- ControlManager.get().stopServer();
- finish();
- super.onBackPressed();
- } else {
- mExitTime = System.currentTimeMillis();
- Toast.makeText(mContext, getString(R.string.hm_exit), Toast.LENGTH_SHORT).show();
- }
- }
- @Override
- protected void onResume() {
- super.onResume();
- mHandler.post(mRunnable);
- }
- @Override
- protected void onPause() {
- super.onPause();
- mHandler.removeCallbacksAndMessages(null);
- }
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void refresh(RefreshEvent event) {
- if (event.type == RefreshEvent.TYPE_PUSH_URL) {
- if (ApiConfig.get().getSource("push_agent") != null) {
- Intent newIntent = new Intent(mContext, DetailActivity.class);
- newIntent.putExtra("id", (String) event.obj);
- newIntent.putExtra("sourceKey", "push_agent");
- newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- HomeActivity.this.startActivity(newIntent);
- }
- }
- }
- private final Runnable mDataRunnable = new Runnable() {
- @Override
- public void run() {
- if (sortChange) {
- sortChange = false;
- if (sortFocused != currentSelected) {
- currentSelected = sortFocused;
- mViewPager.setCurrentItem(sortFocused, false);
- changeTop(sortFocused != 0);
- }
- }
- }
- };
- @Override
- public boolean dispatchKeyEvent(KeyEvent event) {
- if (topHide < 0)
- return false;
- if (event.getAction() == KeyEvent.ACTION_DOWN) {
- if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
- showSiteSwitch();
- }
- } else if (event.getAction() == KeyEvent.ACTION_UP) {
- }
- return super.dispatchKeyEvent(event);
- }
- byte topHide = 0;
- private void changeTop(boolean hide) {
- ViewObj viewObj = new ViewObj(topLayout, (ViewGroup.MarginLayoutParams) topLayout.getLayoutParams());
- AnimatorSet animatorSet = new AnimatorSet();
- animatorSet.addListener(new Animator.AnimatorListener() {
- @Override
- public void onAnimationStart(Animator animation) {
- }
- @Override
- public void onAnimationEnd(Animator animation) {
- topHide = (byte) (hide ? 1 : 0);
- }
- @Override
- public void onAnimationCancel(Animator animation) {
- }
- @Override
- public void onAnimationRepeat(Animator animation) {
- }
- });
- // Hide Top =======================================================
- if (hide && topHide == 0) {
- animatorSet.playTogether(ObjectAnimator.ofObject(viewObj, "marginTop", new IntEvaluator(),
- Integer.valueOf(AutoSizeUtils.mm2px(this.mContext, 20.0f)),
- Integer.valueOf(AutoSizeUtils.mm2px(this.mContext, 0.0f))),
- ObjectAnimator.ofObject(viewObj, "height", new IntEvaluator(),
- Integer.valueOf(AutoSizeUtils.mm2px(this.mContext, 50.0f)),
- Integer.valueOf(AutoSizeUtils.mm2px(this.mContext, 1.0f))),
- ObjectAnimator.ofFloat(this.topLayout, "alpha", 1.0f, 0.0f));
- animatorSet.setDuration(250);
- animatorSet.start();
- tvWifi.setFocusable(false);
- tvFind.setFocusable(false);
- tvMenu.setFocusable(false);
- return;
- }
- // Show Top =======================================================
- if (!hide && topHide == 1) {
- animatorSet.playTogether(ObjectAnimator.ofObject(viewObj, "marginTop", new IntEvaluator(),
- Integer.valueOf(AutoSizeUtils.mm2px(this.mContext, 0.0f)),
- Integer.valueOf(AutoSizeUtils.mm2px(this.mContext, 20.0f))),
- ObjectAnimator.ofObject(viewObj, "height", new IntEvaluator(),
- Integer.valueOf(AutoSizeUtils.mm2px(this.mContext, 1.0f)),
- Integer.valueOf(AutoSizeUtils.mm2px(this.mContext, 50.0f))),
- ObjectAnimator.ofFloat(this.topLayout, "alpha", 0.0f, 1.0f));
- animatorSet.setDuration(250);
- animatorSet.start();
- tvWifi.setFocusable(true);
- tvFind.setFocusable(true);
- tvMenu.setFocusable(true);
- return;
- }
- }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- EventBus.getDefault().unregister(this);
- AppManager.getInstance().appExit(0);
- ControlManager.get().stopServer();
- }
- // Site Switch on Home Button
- void showSiteSwitch() {
- List<SourceBean> sites = ApiConfig.get().getSourceBeanList();
- if (sites.size() > 0) {
- String homeSourceKey = ApiConfig.get().getHomeSourceBean().getKey();
- SelectDialog<SourceBean> dialog = new SelectDialog<>(HomeActivity.this);
-
- TvRecyclerView tvRecyclerView = dialog.findViewById(R.id.list);
- int spanCount;
- spanCount = (int)Math.floor(sites.size()/4);
- spanCount = Math.min(spanCount, 2);
- tvRecyclerView.setLayoutManager(new V7GridLayoutManager(dialog.getContext(), spanCount));
- ConstraintLayout cl_root = dialog.findViewById(R.id.cl_root);
- ViewGroup.LayoutParams clp = cl_root.getLayoutParams();
- clp.width = AutoSizeUtils.mm2px(dialog.getContext(), 300+140*spanCount);
- dialog.setTip(getString(R.string.dia_source));
- dialog.setAdapter(new SelectDialogAdapter.SelectDialogInterface<SourceBean>() {
- @Override
- public void click(SourceBean value, int pos) {
- ApiConfig.get().setSourceBean(value);
- Intent intent = new Intent(getApplicationContext(), HomeActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
- Bundle bundle = new Bundle();
- bundle.putBoolean("useCache", true);
- intent.putExtras(bundle);
- HomeActivity.this.startActivity(intent);
- }
- @Override
- public String getDisplay(SourceBean val) {
- return val.getName();
- }
- }, new DiffUtil.ItemCallback<SourceBean>() {
- @Override
- public boolean areItemsTheSame(@NonNull @NotNull SourceBean oldItem, @NonNull @NotNull SourceBean newItem) {
- return oldItem == newItem;
- }
- @Override
- public boolean areContentsTheSame(@NonNull @NotNull SourceBean oldItem, @NonNull @NotNull SourceBean newItem) {
- return oldItem.getKey().equals(newItem.getKey());
- }
- }, sites, sites.indexOf(ApiConfig.get().getHomeSourceBean()));
- dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialog) {
- // if (homeSourceKey != null && !homeSourceKey.equals(Hawk.get(HawkConfig.HOME_API, ""))) {
- // Intent intent = new Intent(getApplicationContext(), HomeActivity.class);
- // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
- // Bundle bundle = new Bundle();
- // bundle.putBoolean("useCache", true);
- // intent.putExtras(bundle);
- // HomeActivity.this.startActivity(intent);
- // }
- }
- });
- dialog.show();
- }
- }
- // public void onClick(View v) {
- // FastClickCheckUtil.check(v);
- // if (v.getId() == R.id.tvFind) {
- // jumpActivity(SearchActivity.class);
- // } else if (v.getId() == R.id.tvMenu) {
- // jumpActivity(SettingActivity.class);
- // }
- // }
- }
|